
window.onerror = null;

//initialise all variables

var olddiv = new Array();    //this will become a reference to the objects that are being shown or were last shown

function getRefToDivNest( divID, oDoc ) {
	if( !oDoc ) { oDoc = document; }
	if( document.layers ) {
		if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {
			for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
				y = getRefToDivNest(divID,oDoc.layers[x].document); }
			return y; } }
	if( document.getElementById ) { return document.getElementById(divID); }
	if( document.all ) { return document.all[divID]; }
	return document[divID];
}

function showdiv(thisdiv,mylevel, x, y) {
	//this function shows the div and sets the level that the div exists at to 'mylevel'
	hideDivsToLevel(mylevel); //first, hide the last one
	olddiv[mylevel] = getRefToDivNest(thisdiv);
	//Make the object visible
	if( olddiv[mylevel].style ) {
		//DOM compliant
		olddiv[mylevel].style.visibility = 'visible';
		if( x ) olddiv[mylevel].style.left = x;
		if( y ) olddiv[mylevel].style.top = y;
	} else {
		if( olddiv[mylevel].visibility ) {
			//Netscape and old versions of Mozilla compliant
			olddiv[mylevel].visibility = 'show';
		} else {
			//Nothing found, no known way of changing the style
			olddiv[mylevel] = false;
			notifyFail();
			return;
		}
	}
}

function hideDivsToLevel(mylevel) {
	//hide all the divs that are showing this level and higher
	if( olddiv[mylevel] ) {
		//try the next level up first
		hideDivsToLevel(mylevel+1);
		//hide the last hidden object that was shown in the current level
		if( olddiv[mylevel].style ) {
			//DOM compliant
			olddiv[mylevel].style.visibility = 'hidden';
		} else {
			//Netscape and old versions of Mozilla compliant
			olddiv[mylevel].visibility = 'hide';
		}
		//No need for else notifyFail()
		//If it was going to fail, it would have failed while it was being shown
	}
	olddiv[mylevel] = false;
}

function hideDivSpecial(specialDiv) { //hide a div, bypassing levels
	specialDiv = getRefToDivNest(specialDiv);
	if( specialDiv.style ) {
		//DOM compliant
		specialDiv.style.visibility = 'hidden';
	} else {
		if( specialDiv.visibility ) {
			//Netscape and old versions of Mozilla compliant
			specialDiv.visibility = 'hide';
		} else {
			//Nothing found, no known way of changing the style
			notifyFail();
			return;
		}
	}
}

function notifyFail() {
	//oops, I guess nothing works in this browser
	if( window.myalternative ) {
		if( window.confirm( "You are having problems displaying some components of this page.\n"+
			"\nWould you like to try the other page design?" ) ) { location.href = myalternative; }
	} else {
		window.alert( "You are having problems displaying some components of this page.\n\n"+
			"Sorry, but there is not yet an alternative page." );
	}
}


// refer to:  http://www.howtocreate.co.uk/jslibs/htmlhigh/showhidelevels.html





function showHideLayers() { //v3.0
  	var i,p,v,obj,args=showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { 
		v=args[i+2];
		if (obj.style) { 
			obj=obj.style; 
			v=(v=='show')?'visible':(v='hide')?'hidden':v;
		}
    		obj.visibility=v;
	}
}

var hidecheck = null;
function nav_show(selection){
	var imgName = selection.substring(4,selection.length);
	//imgOver(imgName);
    showHideLayers(selection,'','show');
    
    //add offset
    obj=findObj(selection);	//drop down menu
    if (obj.style) obj=obj.style;
    //Find abs pos of company label and subtract company label's relative pos -> offset.  Then add that to relative pos 'loc'
    menu = document.getElementById("menu_"+imgName);	//menu label
	loc = parseInt(menu.offsetLeft);
	firstElem = document.getElementById(FIRST_MENU);
	pos = loc + findPos(firstElem) - parseInt(firstElem.offsetLeft);
    obj.left = pos;
    
    menu.className = "topNavMenu_hover";
    
    if (hidecheck) {
		hidecheck = null;
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		//curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			//curtop += obj.offsetTop
		}
	}
	return curleft;//[curleft,curtop];
}

//showing and hiding the layers/divs
function findObj(n, d) { 
	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=findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function nav_hide(selection){
	var imgName = selection.substring(4,selection.length);
	//imgOut(imgName);
	hidecheck = showHideLayers(selection,'','hide');
	
	menu = document.getElementById("menu_"+imgName);	//menu label
	menu.className = "topNavMenu";	//not _hover
}
	//debugdoc = window.open('','debug', 'width=300, height=500');
	/*debugdoc.document.write('<html><body><form name=debugform><input type=text name=debug></form></body></html>'); */
function debug(content){
	debugdoc.document.debugform.debug.value = content;
}

function bgover(obj){
	obj.style.background='#CC0000';
	obj.style.cursor = 'pointer';
}

function bghover(obj){
	obj.style.background='#CCCCCC';
	obj.style.cursor = 'pointer';
}

function bgrestore(obj){
	obj.style.background='#FFFFFF';
}

function bgout(obj){
	obj.style.background='#868686';
}

function cellclick(url){
	document.location.href = url;
}


