function openDeas() {
   wWidth = 675;	// popup window width and height
   wHeight = 550;
   wLeft = (screen.width-wWidth)/2;	// popup window centering
   wTop = (screen.height-wHeight)/2;

	open("https://onlinebusiness.icbc.com/deas/school/index.html", "deasOpeningWindow",
         "width="+wWidth+",height="+wHeight+",left="+wLeft+",top="+
		 wTop+"screenX="+wLeft+",screenY="+wTop+"," +
         "status=yes,toolbar=no,menubar=no,resizable=no,scrollbars=yes");	
}

function openEForm(url) {
   wWidth = 650;	// popup window width and height
   wHeight = 500;
   wLeft = (screen.width-wWidth)/2;	// popup window centering
   wTop = (screen.height-wHeight)/2;

	open(url, "renhoek_31",
         "width="+wWidth+",height="+wHeight+",left="+wLeft+",top="+
		 wTop+"screenX="+wLeft+",screenY="+wTop+"," +
         "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes");	
}

function openCpay() {
  wWidth = 800;	// popup window width and height
  wHeight = 600;
  wLeft = (screen.width-wWidth)/2;	// popup window centering
  wTop = (screen.height-wHeight)/2;

	open("https://onlinebusiness.icbc.com/CPay/jsp/LogIn.jsp", "firstWindow",
         "width="+wWidth+",height="+wHeight+",left="+wLeft+",top="+
		 wTop+"screenX="+wLeft+",screenY="+wTop+"," +
         "status=yes,toolbar=no,menubar=no,resizable=yes,scrollbars=yes");
    window.showModalDialog;
}

function overDiv(divObj, divClass){
	divObj.className = divClass;
}

var subFlag = null;
function swapSub(subElem){
	var subElem = document.getElementById(subElem);
	subElem.style.display = (subElem.style.display=="none") ? showSub(subElem) : hideSub(subElem);
}

function showSub(subElem){
	subFlag = subElem;
	return "block";
}

function hideSub(subElem){
	subFlag = null;
	return "none";
}

function checkSub(){
	if(subFlag != null){
		swapSub(subFlag.id)
	};
}

// used to make divs clickable links
function jumpTo(linkhref, linktarget){
	if(linktarget=="_top"){
		top.location.href = linkhref;
		return true;
	}
	else if(linktarget=="_blank"){
		window.open(linkhref,"newWin","");
		return true;
	}
	if(top[linktarget]){
		top[linktarget].location.href = linkhref;
		return true;
	}
}

function showNav(){
	var qString = new String(location.search);
	if(qString!=""){
		qString = qString.substring(1);
		var qualPos = qString.indexOf("navQual");
		var qualInt = parseInt(qString.substring(qualPos+8,qString.indexOf("&")));
		var invalidQual = isNaN(qualInt);
		var valPos = qString.indexOf("qualVal");
		var qualVal = qString.substring(valPos+8,qString.indexOf(";",valPos));
		var useQual = (qString.indexOf(";",valPos)>valPos);
		if(!(invalidQual)&&(qualInt==1)&&(useQual)&&(qualVal!="")){
			if(document.getElementById(qualVal)){
				checkSub();
				swapSub(qualVal);
			}
		}
	}	
}

function setMenuWidths(){
	var objStyleSheet = document.styleSheets[0];
	var browName = navigator.appName;

	var rulesColl = (browName!="Netscape")? objStyleSheet.rules : objStyleSheet.cssRules;
	var rulesList = "|tier1|tier1on|tier2|tier2on|";
	var nsTier1Width = 0;
	var nsTier2Width = 0;

	// determine width for tier1 and tier2
	if(browName=="Netscape"){
		for(i=0;i<rulesColl.length;i++){
			if(rulesColl.item(i).selectorText=="#menuTable"){
				nsTier1Width += parseInt(rulesColl.item(i).style.width);
				nsTier2Width += parseInt(rulesColl.item(i).style.width);
			}
			if(rulesColl.item(i).selectorText==".tier1"){
				nsTier1Width -= parseInt(rulesColl.item(i).style.paddingLeft);
				nsTier1Width -= parseInt(rulesColl.item(i).style.paddingRight);
				nsTier1Width -= parseInt(rulesColl.item(i).style.borderRightWidth);
				nsTier1Width -= parseInt(rulesColl.item(i).style.borderLeftWidth);
			}
			if(rulesColl.item(i).selectorText==".tier2"){
				nsTier2Width -= parseInt(rulesColl.item(i).style.paddingLeft);
				nsTier2Width -= parseInt(rulesColl.item(i).style.paddingRight);
				nsTier2Width -= parseInt(rulesColl.item(i).style.borderRightWidth);
				nsTier2Width -= parseInt(rulesColl.item(i).style.borderLeftWidth);
				break;
			}
		}
	}

	for(i=0;i<rulesColl.length;i++){
		if(rulesColl.item(i).selectorText.indexOf(".tier1")==0){
			rulesColl.item(i).style.width = (browName!="Netscape")?"100%":nsTier1Width;
		}
		if(rulesColl.item(i).selectorText.indexOf(".tier2")==0){
			rulesColl.item(i).style.width = (browName!="Netscape")?"100%":nsTier2Width;
		}
	}
}

function initMenu(){
	setMenuWidths();
	showNav();
}