/* Switch Menu version 1.0 - Customized to Smart Meter
   Date: Dec 05-06
   Developer: Marcos Abreu
   Company: Trapeze
*/

var navIdBase = "menuItem";

//hide all subItems that are visible and then shows the subitems of the topItem(menu item) choosed
function SwitchMenu(pObj){
	if(document.getElementById){ // DOM Level 1 check
		var ddMenuNav = GetDropDown(pObj);
		var i = 1;

		var menuNav = document.getElementById(navIdBase+i);
		while(menuNav!=null){ //Remove all the sub menus from the screen
			var ddMenuNavTemp = GetDropDown(menuNav);
			HideDDMenu(ddMenuNavTemp);
			i++;
			menuNav = document.getElementById(navIdBase+i)
		}
		ShowDDMenu(ddMenuNav);
	}
}

//The same functionality as the SwitchMenu() function but receiving a string representing the id of the object
function SwitchMenuById(pObjID){
	var menuNav = document.getElementById(pObjID);
	SwitchMenu(menuNav);
}

//get the dropdown div following the topMenu sent as parameter
function GetDropDown(pObj){
	var ddNavObjID = "dd" + pObj.id.charAt(0).toUpperCase() + pObj.id.substr(1);
	var ddNavObj = document.getElementById(ddNavObjID);
	return ddNavObj;
}

function HideDDMenu(pNavObj){
	pNavObj.style.display = 'none';
}

function ShowDDMenu(pNavObj){
	pNavObj.style.display = 'block';
}

function OpenMenu(pMenuID){
		var menuNav = document.getElementById(pMenuID);
		ShowDDMenu(menuNav);
}

function Init(){
	var i=1;
	var menuNav = document.getElementById(navIdBase+i);
	while(menuNav!=null){ //Remove all the sub menus from the screen
		var ddMenuNavTemp = GetDropDown(menuNav);
		HideDDMenu(ddMenuNavTemp);
		i++;
		menuNav = document.getElementById(navIdBase+i)
	}
}

//Smart Meter Lane script from IESO


function popWin(event, winw, winh, scrollyn, toolyn, menuyn){
 if(!scrollyn){
  scrollyn = "no";
 }
 if(!toolyn){
  toolyn = "no";
 }
 if(!menuyn){
  menuyn = "no";
 }
 var screenh = (screen.height)/2;
 var screenw = (screen.width)/2;
 var wint = screenh - (winh/2);
 var winl = screenw - (winw/2);
 window.open(event, '_blank', 'toolbar=' + toolyn + ',directories=no,status=no,menubar=' + menuyn + ',scrollbars=' + scrollyn + ',resizable=no,copyhistory=no,width=' + winw + ',height=' + winh + ',top=' + wint + ',left=' + winl);
}
