var TotalNavTop = 6; //total number of top nav bars
var TopNavTimer = "";
var openMenu = null;
var canMenuBeClosed = true;

/* top nav rollover handler */
function fncNAV_TOP_ROLLOVER(THIS_NAV, objPos) {
	fncSHOWHIDE_SELECT_ITEMS(1);
	fncNAV_TOP_TURN_OFF_ALL_OVER();
	fncNAV_TOP_SHOW('DIV_NAV_TOP_DROP_'+THIS_NAV, objPos)
	
	//turn on images
	document['nav_top_bar_side_'+(THIS_NAV-1)].src = '/images/global/pix/ffffff.gif';
	document['nav_top_bar_'+THIS_NAV].src = '/images/global/nav/nav_top_spacer_on.gif';
	document['nav_top_bar_side_'+THIS_NAV].src = '/images/global/pix/ffffff.gif';
}

/* top nav rolloff handler */
function fncNAV_TOP_ROLLOUT(){
	var funcToCall = "fncNAV_TOP_CLOSE_ALL();fncNAV_TOP_TURN_OFF_ALL_OVER();fncSHOWHIDE_SELECT_ITEMS(0);"
	TopNavTimer = window.setTimeout(funcToCall, 500);
}

/* show top nav drop downs */
function fncNAV_TOP_SHOW(id, objPos){
	if(document.getElementById){
		fncNAV_TOP_TIMER_STOP();
		for (var i = 1;i<=TotalNavTop;i++) {
			setElementProperty('DIV_NAV_TOP_DROP_'+i, 'display', 'none');
		}
		openMenu = id;
		canMenuBeClosed = false

		var x = 0;
		var y = 0;
		
		x = getElementLeft(objPos)-1;
		y = getElementBottom(objPos);
		
		setElementProperty(id, 'display', 'block');
		setElementProperty(id, 'left', x + "px");
		setElementProperty(id, 'top', y + "px");
	}
}

/* turn off all top images */
function fncNAV_TOP_TURN_OFF_ALL_OVER() {
	var PAGE_NAV_SELECTED;
	PAGE_NAV_SELECTED = (document.MC_PAGE_VALUES_HIDDEN.NAV_TOP_ID.value-0)
	for (var THIS_NAV = 1;THIS_NAV<=TotalNavTop;THIS_NAV++) {
		if (PAGE_NAV_SELECTED!=THIS_NAV) {
			document['nav_top_bar_side_'+(THIS_NAV-1)].src = '/images/global/pix/cccccc.gif';
			document['nav_top_bar_'+THIS_NAV].src = '/images/global/nav/nav_top_spacer_off.gif';
			document['nav_top_bar_side_'+THIS_NAV].src = '/images/global/pix/cccccc.gif';
		}
	}
}

/* turn on top image on page load */
function fncNAV_TOP_PAGELOAD() {
	var THIS_NAV;
	THIS_NAV = (document.MC_PAGE_VALUES_HIDDEN.NAV_TOP_ID.value-0)
	
	//turn on images
	if (THIS_NAV>0) {
		document['nav_top_bar_side_'+(THIS_NAV-1)].src = '/images/global/pix/ffffff.gif';
		document['nav_top_bar_'+THIS_NAV].src = '/images/global/nav/nav_top_spacer_on.gif';
		document['nav_top_bar_side_'+THIS_NAV].src = '/images/global/pix/ffffff.gif';
	}
}

function fncNAV_TOP_TIMER_STOP(){
	window.clearTimeout(TopNavTimer);
}

/* turn off one top nav */
function fncNAV_TOP_CLOSE(id){
	setElementProperty(id, 'display', 'none');
	openMenu = null;
}

/* turn off all top nav */
function fncNAV_TOP_CLOSE_ALL(){
	for (var i = 1;i<=TotalNavTop;i++) {
		setElementProperty('DIV_NAV_TOP_DROP_'+i, 'display', 'none');
	}
	openMenu = null;
}

/* top nav - hide/show form select items in ie */
function fncSHOWHIDE_SELECT_ITEMS(THIS_STATE) {
	if (isIE==1) {
		var VisibState = (THIS_STATE==1) ? "hidden" : "visible";
		var AllSelect = document.getElementsByTagName("select");
		for (var i = 0;i<=AllSelect.length-1;i++) {
			AllSelect[i].style.visibility=VisibState;
		}
	}
}

/* show/hide top nav based on mouse position */
function getMousePos(event){
	var x, y;
	if(window.event){
		x = window.event.clientX;
		y = window.event.clientY;
		if (document.documentElement && document.documentElement.scrollTop){
			y+=document.documentElement.scrollTop;
			
		} else {
			y+=document.body.scrollTop;
			
		}
	} else {
		x = event.pageX;
		y = event.pageY;
	}

	if(openMenu != null){
		var testInside = isInside(x, y, openMenu);
		if(!testInside && canMenuBeClosed == true){
			fncNAV_TOP_CLOSE(openMenu);
		}
		if(testInside){
			canMenuBeClosed = true;
			fncNAV_TOP_TIMER_STOP();
		}
	}
}

function isInside(xMouse, yMouse, id){
	if( (id != null) && (xMouse >= getElementLeft(id)) && (xMouse <=getElementRight(id)) && (yMouse >= (getElementTop(id))-25) && (yMouse <= getElementBottom(id)) ){
		return true;
	} else {
		return false;
	}
}

function switchDisplay(elm){
	var elm = elm.parentNode.nextSibling;
	while(elm.nodeType == 3){
		elm = elm.nextSibling;
	}
	
	var elmStyle = getElementProperty(elm, "display")

	if((elmStyle == "none") || (elmStyle == "") || (elmStyle == null)){
		setElementProperty(elm, "display", "block");
		return;
	}
	if(elmStyle == "block"){
		setElementProperty(elm, "display", "none");
		return;
	}
}

/*
LEFT NAV FUNCTIONS -
	uses JavaScript to expand/collapse visible menus/sub menus
*/
function fncNAV_LEFT_PAGELOAD() {
	var ColorRevert;
	var A_ID = (document.MC_PAGE_VALUES_HIDDEN.NAV_LEFT_A_ID.value-0);
	var B_ID = (document.MC_PAGE_VALUES_HIDDEN.NAV_LEFT_B_ID.value-0);
	var C_ID = (document.MC_PAGE_VALUES_HIDDEN.NAV_LEFT_C_ID.value-0);
	
	if (A_ID!=0 && document.getElementById('TR_NAV_A_'+A_ID)!=null) {
		fncROLL_CSS_BG('TR_NAV_A_'+A_ID,'#E9E9E9');
		fncROLL_CSS_CLASS('LINK_NAV_A_'+A_ID,'nav_lvl_a_on');
		document['IMG_NAV_A_'+A_ID].src = '/images/global/elm/arrow_orange_on_gray_down.gif';
		fncDIV_ShowHide('DIV_NAV_A_'+A_ID);
		
		if (B_ID!=0 && document.getElementById('TR_NAV_B_'+A_ID+'_'+B_ID)!=null) {
			
			fncROLL_CSS_CLASS('LINK_NAV_B_'+A_ID+'_'+B_ID,'nav_lvl_b_on');
			document['IMG_NAV_B_'+A_ID+'_'+B_ID].src = '/images/global/elm/bullet_orange_on_gray.gif';
			fncDIV_ShowHide('DIV_NAV_B_'+A_ID+'_'+B_ID);
			
			if (C_ID!=0 && document.getElementById('TR_NAV_C_'+A_ID+'_'+B_ID+'_'+C_ID)!=null) {
				
				fncROLL_CSS_CLASS('LINK_NAV_C_'+A_ID+'_'+B_ID+'_'+C_ID,'nav_lvl_c_on');
				document['IMG_NAV_C_'+A_ID+'_'+B_ID+'_'+C_ID].src = '/images/global/elm/dash_orange_on_gray.gif';
			} // if (C_ID!=0...
		} // if (B_ID!=0...
	} // if (A_ID!=0...
	
}

function fncNAV_ROLLOVER(THIS_LVL) {
	var A_ID = fncNAV_ROLLOVER.arguments[1];
	var B_ID = fncNAV_ROLLOVER.arguments[2];
	var C_ID = fncNAV_ROLLOVER.arguments[3];
	
	if (THIS_LVL=='A') {
		THIS_ROW=fncNAV_ROLLOVER.arguments[1];
		document['IMG_NAV_'+THIS_LVL+'_'+A_ID].src = '/images/global/elm/arrow_orange_on_blue_down.gif';
		fncROLL_CSS_BG('TR_NAV_'+THIS_LVL+'_'+A_ID,'#1B0069');
	}
	
	if (THIS_LVL=='B') {
		THIS_ROW=fncNAV_ROLLOVER.arguments[2];
		document['IMG_NAV_'+THIS_LVL+'_'+A_ID+'_'+B_ID].src = '/images/global/elm/bullet_gray_on_blue.gif';
		fncROLL_CSS_BG('TR_NAV_'+THIS_LVL+'_'+A_ID+'_'+B_ID,'#1B0069');
	}
	
	if (THIS_LVL=='C') {
		THIS_ROW=fncNAV_ROLLOVER.arguments[3];
		document['IMG_NAV_'+THIS_LVL+'_'+A_ID+'_'+B_ID+'_'+C_ID].src = '/images/global/elm/dash_gray_on_blue.gif';
		fncROLL_CSS_BG('TR_NAV_'+THIS_LVL+'_'+A_ID+'_'+B_ID+'_'+C_ID,'#1B0069');
	}
}

function fncNAV_ROLLOUT(THIS_LVL,THIS_ROW) {
	var ColorRevert;
	var A_ID = (document.MC_PAGE_VALUES_HIDDEN.NAV_LEFT_A_ID.value-0);
	var B_ID = (document.MC_PAGE_VALUES_HIDDEN.NAV_LEFT_B_ID.value-0);
	var C_ID = (document.MC_PAGE_VALUES_HIDDEN.NAV_LEFT_C_ID.value-0);
	
	var A_ID_Out = fncNAV_ROLLOUT.arguments[1];
	var B_ID_Out = fncNAV_ROLLOUT.arguments[2];
	var C_ID_Out = fncNAV_ROLLOUT.arguments[3];
	
	if (THIS_LVL=='A') {
		THIS_ROW=fncNAV_ROLLOUT.arguments[1];
		if (A_ID!=THIS_ROW) {
			ColorRevert='#F1FBFF';
			document['IMG_NAV_'+THIS_LVL+'_'+A_ID_Out].src = '/images/global/elm/arrow_blue_on_light_blue_rt.gif';
			fncROLL_CSS_BG('TR_NAV_'+THIS_LVL+'_'+A_ID_Out,ColorRevert);
		} else {
			document['IMG_NAV_'+THIS_LVL+'_'+A_ID_Out].src = '/images/global/elm/arrow_orange_on_gray_down.gif';
			ColorRevert='#E9E9E9';
		}
		fncROLL_CSS_BG('TR_NAV_'+THIS_LVL+'_'+A_ID_Out,ColorRevert);
	}
	
	if (THIS_LVL=='B') {
		THIS_ROW=fncNAV_ROLLOUT.arguments[2];
		if (B_ID!=THIS_ROW) {
			ColorRevert='#E9E9E9';
			document['IMG_NAV_'+THIS_LVL+'_'+A_ID_Out+'_'+B_ID_Out].src = '/images/global/elm/bullet_blue_on_gray.gif';
		} else {
			document['IMG_NAV_'+THIS_LVL+'_'+A_ID_Out+'_'+B_ID_Out].src = '/images/global/elm/bullet_orange_on_gray.gif';
			ColorRevert='#E9E9E9';
		}
		fncROLL_CSS_BG('TR_NAV_'+THIS_LVL+'_'+A_ID_Out+'_'+B_ID_Out,ColorRevert);
	}
	
	if (THIS_LVL=='C') {
		THIS_ROW=fncNAV_ROLLOUT.arguments[3];
		if (C_ID!=THIS_ROW) {
			ColorRevert='#E9E9E9';
			document['IMG_NAV_'+THIS_LVL+'_'+A_ID_Out+'_'+B_ID_Out+'_'+C_ID_Out].src = '/images/global/elm/dash_blue_on_gray.gif';
		} else {
			document['IMG_NAV_'+THIS_LVL+'_'+A_ID_Out+'_'+B_ID_Out+'_'+C_ID_Out].src = '/images/global/elm/dash_orange_on_gray.gif';
			ColorRevert='#E9E9E9';
		}
		fncROLL_CSS_BG('TR_NAV_'+THIS_LVL+'_'+A_ID_Out+'_'+B_ID_Out+'_'+C_ID_Out,ColorRevert);
	}
	
}