
// functions section
/* parameter description:
1. layerName:
 format:
	leftBar, layerOne - s[a]
	layerTwo - s[a].[b]
	layerThree - s[a].[b].[c]
	where a = item order of leftBar
		b = item order of layerOne
		c = item order of layerTwo
2. type
	- possible values: "leftBar", "layerOne" and "layerTwo"
*/

/* structure for each menu item */
function cMenuItem (itemName, hasChild, itemUrl, code) {
	this.itemName = itemName
	this.hasChild = hasChild
	this.itemUrl = itemUrl
	this.code = code
}


/* get [a] from layerName */
function getParentId(layerName) {
	var id = "";
	if (layerName.indexOf(".") == -1)
		id = layerName.substring(1, layerName.length);
	else
		id = layerName.substring(1, layerName.indexOf("."));

	return id;
}

/*	get [b] from layerName */
function getChildId(layerName) {
	var id ="";
	if (layerName.indexOf(".")==layerName.lastIndexOf(".")){
		id = layerName.substring(layerName.indexOf(".")+1, layerName.length);
	}else{
		id = layerName.substring(layerName.indexOf(".")+1, layerName.lastIndexOf("."));
	}
	return id;
}

/*	get [c] from layerName	*/
function getLastId(layerName) {
	var id = layerName.substring(layerName.lastIndexOf(".")+1, layerName.length);
	return id;
}

// check for "leftBar"
function isLeftBar(layerName) {
	if (layerName.indexOf(".") == -1)
		return true;
	else
		return false;
}

// check for "layerOne"
function isLayerOne(layerName) {
	if (layerName.indexOf(".")==layerName.lastIndexOf(".") && (!(layerName.indexOf(".") == -1))){
		return true;}
	else
		return false;
}

// change background color and font color of menu item
function changeColor(type, layerName, parentid, childid) {
	var sectionIndex = parseInt(layerName.substring(1, layerName.length));
	if (is_ie&&is_all){
		switch (type) {
			case 'leftBar':
		    	id = "mi" + layerName.substring(1, layerName.length);
				/*document.all["ma" + layerName.substring(1, layerName.length)].style.color = fontOn;
				bulletin_id = "mi_bulletin_" + layerName.substring(1, layerName.length);
				/*document.all[id].style.backgroundImage = "url(" + bg_sectionArray[sectionIndex-1].src + ")";
				document.all[bulletin_id].src = bulletin_sectionArray[sectionIndex-1].src;				*/
				document.all[id].className = l1on[sectionIndex-1];
				break;
			case 'layerOne':
				id = "si" + layerName.substring(1, layerName.length);
				/*document.all["sa" + parentid + "." + childid].style.color = fontOn;
			    document.all[id].style.background = color_sectionArray[sectionIndex-1]/*bgOn*/
			    document.all[id].className = l2on[sectionIndex-1];
				break;
			case 'layerTwo':
				id = "si" + layerName.substring(1, layerName.length);
				/*document.all["sa" + parentid + "." + childid + "." + getLastId(layerName)].style.color = fontOn;
			    document.all[id].style.background = color_sectionArray[sectionIndex-1]/*bgOn*/
			    document.all[id].className = l2on[sectionIndex-1];
				break;
		}
//	    document.all[id].style.background = color_sectionArray[sectionIndex-1]/*bgOn*/;


    } else if (is_getElementById){
		switch (type) {
			case 'leftBar':
		    	id = "mi" + layerName.substring(1, layerName.length);
				/*document.getElementById("ma" + layerName.substring(1, layerName.length)).style.color = fontOn;
				bulletin_id = "mi_bulletin_" + layerName.substring(1, layerName.length);
				/*document.getElementById(id).style.backgroundImage = "url(" + bg_sectionArray[sectionIndex-1].src + ")";
				document.getElementById(bulletin_id).src = bulletin_sectionArray[sectionIndex-1].src;*/
				document.getElementById(id).className = l1on[sectionIndex-1];
				
				break;
			case 'layerOne':
				id = "si" + layerName.substring(1, layerName.length);
				/*document.getElementById("sa" + parentid + "." + childid).style.color = fontOn;
				 document.getElementById(id).style.background = color_sectionArray[sectionIndex-1]/*bgOn*/
				document.getElementById(id).className = l2on[sectionIndex-1];
				break;
			case 'layerTwo':
				id = "si" + layerName.substring(1, layerName.length);
				/*document.getElementById("sa" + parentid + "." + childid + "." + getLastId(layerName)).style.color = fontOn;
				document.getElementById(id).style.background = color_sectionArray[sectionIndex-1]/*bgOn*/
				document.getElementById(id).className = l2on[sectionIndex-1];
				break;
		}
	    //document.getElementById(id).style.backgroundColor = color_sectionArray[sectionIndex-1]/*bgOn*/;
    }
}

// restore background color and font color of menu item
function restoreColor(type, layerName) {
	if (layerName=="")
		return;

	var parentId = getParentId(layerName);
	var childId = getChildId(layerName);
	var bcolor = "";
	var fcolor = "";

	if (isLeftBar(layerName)){
		if (layerName==currentSectionLayer) {			
		   	bcolor = sectionbgOff;
			fcolor = sectionfontOff;
		} else {
		   	bcolor = menubgOff;
			fcolor = fontOff;
		}
	   	id = "mi" + layerName.substring(1, layerName.length);
		if (is_ie&&is_all){
			//document.all["ma" + layerName.substring(1, layerName.length)].style.color = fcolor;			
			if (sectionArray[layerName.substring(1, layerName.length)-1].code != currentSection) {
				bulletin_id = "mi_bulletin_" + layerName.substring(1, layerName.length);
				/*document.all[id].style.backgroundImage = "none";				
				document.all[bulletin_id].src = bulletOff.src;
				//document.all[id].style.background = bcolor;*/
				document.all[id].className = l1off;
				
			}
		}else if (is_getElementById){
			//document.getElementById("ma" + layerName.substring(1, layerName.length)).style.color = fcolor;
			if (sectionArray[layerName.substring(1, layerName.length)-1].code != currentSection) {
				bulletin_id = "mi_bulletin_" + layerName.substring(1, layerName.length);
				/*document.getElementById(bulletin_id).src = bulletOff.src;
				//document.getElementById(id).style.backgroundColor = bcolor;
				document.getElementById(id).style.backgroundImage = "none";*/
				document.getElementById(id).className = l1off;
			}
			
		}
    } else if (isLayerOne(layerName)) {
    	bcolor = smenubgOff;
		fcolor = fontOff;
    	id = "si" + parentId + "." + childId;
    	//alert("isLayerOne");
		if (is_ie&&is_all){			
			/*document.all["sa" + parentId + "." + childId].style.color = fcolor;
			document.all[id].style.background = bcolor;*/
			document.all[id].className = l2off;
		}else if (is_getElementById){
			/*document.getElementById("sa" + parentId + "." + childId).style.color = fcolor;
			document.getElementById(id).style.backgroundColor = bcolor;*/
			document.getElementById(id).className = l2off;
		}
	} else {
    	bcolor = smenubgOff;
		fcolor = fontOff;
    	id = "si" + layerName.substring(1, layerName.length);
		if (is_ie&&is_all){
			/*document.all["sa" + layerName.substring(1, layerName.length)].style.color = fcolor;
			document.all[id].style.background = bcolor;*/
			document.all[id].className = l2off;
		}else if (is_getElementById){
			/*document.getElementById("sa" + layerName.substring(1, layerName.length)).style.color = fcolor;
			document.getElementById(id).style.backgroundColor = bcolor;*/
			document.getElementById(id).className = l2off;
		}
	}
	//alert(bcolor);
	
	
}

// show layerOne or layerTwo if layer exists
// close previous visible layers
function showLayer(type, hasChild, layerName) {
	//var vTop = headerHeight;
	var parentId = getParentId(layerName);
	var childId = getChildId(layerName);

	clearMenuTimer();

	changeColor(type, layerName, parentId, childId);

	if (is_ie&&is_all) {
	   vTop = document.all["leftBar"].offsetTop;
    	switch(type)
        {
			case 'leftBar':
				/* set top position of layerOne */
				currLayer1=layerName;
				vTop += document.all["mi"+ parseInt(layerName.substring(1, layerName.length))].offsetTop;
				break;

	        case 'layerOne':
				/* set top position of layerTwo */
				if (hasChild == "Y"){
					//eval("document.images."+layerName.replace(".", "_")+".src=arrowOn.src");
					currLayer2=layerName;
					vTop += document.all["mi"+ parseInt(layerName.substring(1, layerName.length))].offsetTop;
					vTop += document.all["si"+parentId+"."+childId].offsetTop - 1
				} else {
					currLayer2="";
				}
				currLayer1=prevLayer1;
				break;

			case 'layerTwo':
				currLayer2=prevLayer2;
				break;
        }

		/* show menu layer */
		if (document.all[layerName] != null) {
			document.all[layerName].style.top = vTop;
			document.all[layerName].style.visibility = "visible";
		}

	} else if (is_getElementById) {
	   	vTop = document.getElementById("leftBar").offsetTop;
	   	switch(type)
        {
			case 'leftBar':
				/* set top position of layerOne */
				currLayer1=layerName;
				//if (parseInt(layerName.substring(1, layerName.length)) > 1) {
					vTop += document.getElementById("mi"+( parseInt(layerName.substring(1, layerName.length)) )).offsetTop;
				//}

				break;

	        case 'layerOne':
				/* set top position of layerTwo */
				if (hasChild == "Y") {
					//eval("document.images."+layerName.replace(".", "_")+".src=arrowOn.src");
					currLayer2=layerName;
					vTop += document.getElementById("si"+parentId+"."+childId).offsetTop;
					vTop += document.getElementById("mi"+(parseInt(parentId))).offsetTop - 1;
				} else {
					currLayer2="";
				}
				currLayer1=prevLayer1;
				break;

			case 'layerTwo':
				currLayer2=prevLayer2;
				break;
        }

		/* show menu layer */
		if (document.getElementById(layerName) != null) {
			document.getElementById(layerName).style.top = vTop;
			document.getElementById(layerName).style.visibility = "visible";
		}
	}

	/* hide irrelevant layers */
	switch(type)
    {
  	   	case 'leftBar':
			if (prevLayer1 != currLayer1){
				hideLayer("layerOne", "", prevLayer1);
			}
			if (prevLayer2 != "") {
				hideLayer("layerTwo", "", prevLayer2);
			}
			break;
  	   	case 'layerOne':
			if (prevLayer2!=currLayer2 && prevLayer2!="") {
				hideLayer("layerOne", "", prevLayer2);
			}
			break;
		default:
	}
}

// change layer from visible to hidden
function hideLayer(type, hasChild, layerName){
	/* restore background and font color of menu item */
	restoreColor(type, layerName)
	var parentId = getParentId(layerName);
	var childId = getChildId(layerName);

	if (is_ie&&is_all) {
		if (document.all[layerName] != null) {
			document.all[layerName].style.visibility = "hidden";
			if (isLayerOne(layerName)){
				/* if layerOne has child layer, change arrow color */
				if (eval("s" + parentId +"Array"+"\133"+(childId-1)+"\135").hasChild > 0){
					//eval("document.images."+layerName.replace(".", "_")+".src=arrowOff.src");
				}
			}
		}
	} else if (is_getElementById) {
		if (document.getElementById(layerName) != null) {
			document.getElementById(layerName).style.visibility = "hidden";
			if (isLayerOne(layerName)){
				/* if layerOne has child layer, change arrow color */
				if (eval("s" + parentId +"Array"+"\133"+(childId-1)+"\135").hasChild > 0){
					//eval("document.images."+layerName.replace(".", "_")+".src=arrowOff.src");
				}
			}
		}
	}
}

// set a timer for hiding dhtml layers
function menuTimer(type, hasChild, layerName){

	var parentId = getParentId(layerName);
	var childId = getChildId(layerName);

	clearMenuTimer();
	
	switch(type)
    {
		case 'leftBar':
			mt1 = setTimeout("hideLayer(\"" + type + "\"," + "\"" + hasChild + "\"," + "\""+layerName+"\")", mtimeout);
			mt2 = 1;
			mt3 = setTimeout("resetStates()", mtimeout);
			prevLayer1 = currLayer1;
			currLayer1 = "";
			break;

        case 'layerOne':
			mt1 = setTimeout("hideLayer(\"" + type + "\"," + "\"" + hasChild + "\"," + "\"s" + parentId + "\")", mtimeout);
			if (hasChild == "N") {
				mt2 = 1;
				restoreColor(type, layerName);
			} else {
				mt2 = setTimeout("hideLayer(\"" + type + "\"," + "\"" + hasChild + "\"," + "\"s" + parentId + "." + childId + "\")", mtimeout);
			}
			mt3 = setTimeout("resetStates()", mtimeout);
			prevLayer2 = currLayer2;
			currLayer2 = "";
			break;

		case 'layerTwo':
			mt1 = setTimeout("hideLayer(\"" + type + "\"," + "\"" + hasChild + "\"," + "\"s" + parentId + "\")", mtimeout);
			mt2 = setTimeout("hideLayer(\"" + type + "\"," + "\"" + hasChild + "\"," + "\"s" + parentId + "." + childId + "\")", mtimeout);
			mt3 = setTimeout("resetStates()", mtimeout);
			restoreColor(type, layerName);
			break;
	}
	
	
	menuTimerRunning = true;

}

// clear menu timer
function clearMenuTimer(){
	if (menuTimerRunning){
		clearTimeout(mt1);
		clearTimeout(mt2);
		clearTimeout(mt3);
		menuTimerRunning = false;
	}
}

// reset state variables
function resetStates() {
	prevLayer1 = "";
	prevLayer2 = "";
	currLayer1 = "";
	currLayer2 = "";
	menuTimerRunning = false;
}
function leftBarBox1_onclick(url){
	//alert(url);
	window.location=url;
}

// end functions section


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->