
/***************************************
 *
 *	Global Variables for use with the menu.
 *
 ***************************************/

	var z=0,x=1,c=1,checkOneID,checkTwoID,checkThreeID,iM,R=rootElementList,firstLvlObj,secondLvlObj,userLocExists=(userLoc=="")?true:false;

	var goldNode="", goldClubText="Hertz #1 Club Gold".toLowerCase(), upgradeText="Upgrade Now".toLowerCase();

	while ((z<=R.length-1)&&(!userLocExists)&&(userLoc!="")&&(userLoc!=null)){
		checkOneID=R[z]; firstLvlObj=eval(checkOneID); userLocExists=((userLoc==checkOneID)||(userLocExists))?true:false;
		if ((firstLvlObj[2]>0)&&(!userLocExists)){x=1;
			while ((x<=firstLvlObj[2])&&(!userLocExists)){
				checkTwoID=checkOneID+'_'+x; secondLvlObj=eval(checkTwoID); userLocExists=((userLoc==checkTwoID)||(userLocExists))?true:false;
				if ((secondLvlObj[2]>0)&&(!userLocExists)){c=1;
					while ((c<=secondLvlObj[2])&&(!userLocExists)){
						checkThreeID=checkTwoID+'_'+c; userLocExists=((userLoc==checkThreeID)||(userLocExists))?true:false;
						c++;
					}
				}
				x++;
			}
		}
		z++;
	}

	var lastSelected='',lastRoot='',memberBorderItem='',bubbleAndTitle='';
	var menuWidth="180";
	var foundLocationToOpen=((userLastPageAction!="")&&(userLastPageAction!="null")&&(userLastPageAction!=null))?true:false;
	var currentUserURL=window.location.pathname+window.location.search+window.location.hash;
	
	var userPathAndFile=window.location.pathname;
	var userQueryString=window.location.search+window.location.hash;

	var highestMatchLvl=0,highestMatchNode="",rootCounter=0,userLocRoot=(userLoc.indexOf("_",userLoc.indexOf("_",0)+1)!=-1)?userLoc.substring(0,userLoc.indexOf("_",userLoc.indexOf("_",0)+1)):userLoc;
	var userLocRootExists=false;
	while ((!userLocRootExists) && (rootCounter<rootElementList.length)) {
		if (userLocRoot==rootElementList[rootCounter]){userLocRootExists=true;}
		rootCounter++;
	}
	if (!userLocRootExists)	{userLoc="";}	
	
//	alert(userLocRootExists);
//	alert("currentUserURL = "+currentUserURL +"\nuserLastPageAction = "+userLastPageAction);
//	alert('((userLastPageAction=="")||(userLastPageAction=="null")) = '+((userLastPageAction=="")||(userLastPageAction==null)));
 
	var arr1=new Image();
	arr1.src='img/nav_arrow.gif';
	var arr1d=new Image();
	arr1d.src='img/nav_arrow_down.gif';
	
	var pixG=new Image();
	pixG.src='img/nav_pixel_gray.gif'
	var pixO=new Image();
	pixO.src='img/nav_pixel_orange.gif';

	var bottomIMGa=new Image();
	bottomIMGa.src='img/nav_bg_btm.gif';
	var bottomIMGb=new Image();
	bottomIMGb.src='img/nav_bg_btm2.gif';

	var partialMatchArray=getPartialMatchArray(userPathAndFile,userQueryString);


/***************************************  End of global variables for menu ***************************************/

function getTableClass(l,s){
var tableClass;
	switch(l){
		case 1:	tableClass=(s=='off')?'bg1off':'bg1on';break;
		case 2:	tableClass=(s=='off')?'bg2off':'bg2on';break;
		case 3:	tableClass=(s=='off')?'bg3off':'bg3on';break;	
	}
	return tableClass;
}

function getTDClass(l,s){
var tdClass;
	switch(l){
		case 1:	tdClass=(s=='off')?'firstMenuContentTDOff':'firstMenuContentTDOn';break;
		case 2:	tdClass=(s=='off')?'secondMenuContentTDOff':'secondMenuContentTDOn';break;
		case 3:	tdClass=(s=='off')?'thirdMenuContentTDOff':'thirdMenuContentTDOn';break;	
	}
	return tdClass;
}

function getFontClass(l,s){
var fClass;
	switch(l){
		case 1:	fClass=(s=='off')?'firstoff':'firston';break;
		case 2:	fClass=(s=='off')?'secondoff':'secondon';break;
		case 3:	fClass=(s=='off')?'thirdoff':'thirdon';break;	
	}
	return fClass;
}

function nodeExists(searchString){

	for (var count=0; count<nodeCollection.length; count++){
		if (nodeCollection[count] == searchString) {return true;}
	}
	return false;
}

function openMenuURL(mURL,userMenuSelection,nodeText) {
//alert(nodeText.toLowerCase() + "\n" + upgradeText + "\n" + goldNode);

	if (nodeText.toLowerCase() == upgradeText){ 
		if (mURL.indexOf('?')!=-1) document.location.href=mURL+'&leftNavUserSelection='+goldNode;
		else document.location.href=mURL+'?leftNavUserSelection='+goldNode;	
	}
	else {
		if (mURL.indexOf('?')!=-1) document.location.href=mURL+'&leftNavUserSelection='+userMenuSelection;
		else document.location.href=mURL+'?leftNavUserSelection='+userMenuSelection;
	}
}

function changeAppearance(mObj,mID) {
var m=mObj,docEl=document.getElementById(mID),botObj,lItem=eval(lastRoot);
	botObj=document.getElementById('bottomMenuImage'); botObj.src=(lItem[lItem.length-1]=='off')?bottomIMGa.src:bottomIMGb.src;
	docEl.innerHTML=(mID!=memberBorderItem)?createInnerHTML(m,mID):createMemberBorderHTML(m,mID);
}

function setBubbleAndTitle(menuTextID){
var extraTitle=menuTextID,bubbleObj,menuObj,m='',baseTitle;

	menuObj=(lastSelected!='')?eval(lastSelected):'';
	if ((menuObj!="")&&(menuObj[3]==3)){m=eval(getParentLevel(lastSelected))[0];}
	else {m=(lastSelected!='')?menuObj[0]:'';}
	baseTitle=(m!='')?'Hertz - '+m:'Hertz';
	if (((document.getElementById('bubbleTextDiv'))!=null)&&(lastSelected!='')){
		bubbleObj=document.getElementById('bubbleTextDiv');
		bubbleObj.innerHTML=m;
	}
	window.document.title=(extraTitle=='')?baseTitle:baseTitle+' - '+extraTitle;
}

function openTo(openToID) {//alert("openToID = "+openToID);
var m=openToID,m1,m2,evalM=eval(m),mL=5,mLvl=((openToID=="")||(openToID==null))?-1:evalM[3],oArray=(mLvl==-1)?"":new Array(mLvl),i;

	if (lastSelected!=''){resetAll('all');}
	lastSelected=m;
	if (mLvl!=-1){
		while (mL>1){
			m=m.substring(0,m.lastIndexOf('_'));
			evalM=eval(m);  mL=evalM[3];
			if (m.indexOf('_')!=-1){oArray[mL-1]=m;}
		}
		oArray[oArray.length-1]=openToID;
		for(i=0;i<oArray.length;i++){
			if(i==1){bubbleAndTitle=oArray[i];}
			takeAction(oArray[i],'o');
		}
	}
}

function resetAll(mItem){
var m=mItem,i,j,k,mName='',mObj,lvl,rootObj,rootItemID;

	if (mItem=='all'){
		for (i=0;i<=rootElementList.length-1;i++){mName=rootElementList[i];mObj=eval(mName);if (mObj[mObj.length-1]=='on'){takeAction(mName,'o');}}
	}
	else { //Check for any other open items in same level
		mObj=eval(m); lvl=mObj[3];
		if (lvl==1){//code for level 1 items
			for (i=0;i<=rootElementList.length-1;i++){mName=rootElementList[i];if(mName!=m){mObj=eval(mName);if (mObj[mObj.length-1]=='on'){takeAction(mName,'o');}}}
		}
		else if (lvl==2){ //code for level 2 items
			rootItemID=m.substring(0,m.indexOf('_',m.indexOf('_',0)+1));	rootObj=eval(rootItemID);
			for (i=1;i<=rootObj[2];i++){mName=rootItemID+'_'+i;if(mName!=m){mObj=eval(mName);if (mObj[mObj.length-1]=='on'){takeAction(mName,'o');}}}
		}
		else if (lvl==3){ //code for level 3 items
			rootItemID=m.substring(0,m.lastIndexOf('_')); rootObj=eval(rootItemID);
			for (i=1;i<=rootObj[2];i++){mName=rootItemID+'_'+i;if(mName!=m){mObj=eval(mName);if (mObj[mObj.length-1]=='on'){takeAction(mName,'o');}}}
		}
	}
}

function takeAction(mItem,lock) {
var mE=mItem,m=eval(mE),subs=m[2],i,j,newID='',newObj,docEl,twoID,secEl,tR='',mEX=mE+'_',secondLock=false,newURL=m[1],userNavNodeSelection='';

	openToCondition=((lastSelected.indexOf(mEX)!=-1)&&(m[m.length-1]!='on'));
	if (lock==''){
		if (openToCondition){openTo(lastSelected);secondLock=true;}
		else {resetAll(mE); if (m[1]!=""){openMenuURL(newURL,mE,m[0]);secondLock=true;}/*if statement and openMenuURL command added for CR229 - BVaughn 9/19/05*/}
	}
	if (!secondLock){
		if ((m[1]!='')&&(m[m.length-1]=='off')&&((lastSelected!=mItem)&&(lastSelected.indexOf(mItem)==-1))||((lock=='')&&(lastSelected==mItem))){userNavNodeSelection=mE;openMenuURL(newURL,userNavNodeSelection,m[0]);}
		else{
			m[m.length-1]=(m[m.length-1]=='off')?'on':'off';
			changeAppearance(m,mE);
			for (i=1;i<=m[2];i++){
				newID=mE+'_'+i;
				if (nodeExists(newID)){	//check for existence
					docEl=document.getElementById(newID);
					docEl.style.display=(docEl.style.display=='block')?'none':'block';
					newObj=eval(newID); if (newObj[m.length-1]=='on'){newObj[m.length-1]='off';changeAppearance(newObj,newID);}
					if ((newObj[2]>0)&&(docEl.style.display=='none')){
						for (j=1;j<=newObj[2];j++){
							twoID=newID+'_'+j;
							if (nodeExists(twoID)){	//check for existence
								secEl=document.getElementById(twoID);
								if (secEl.style.display=='block'){secEl.style.display='none';}
							}
						}
					}
				}
			}
		}
	}
}

function createTBorW(TorB,oi){
var duh,x=oi,iD='menu_'+x,lN=document.getElementById('leftNavMenu'),iM=isMember,awardsStr='';

	d=document.createElement('div');
	d.style.position='relative'; d.className='relDiv'; d.style.display='block';
	lN.appendChild(d);
	if (TorB=='w'){
		iD='menu_0welcome'; x=eval(iD); d.id=iD;awardsStr=(x[2]=='')?'':x[3]+' '+x[2]+'<br>';
		duh='<table class="menutable" width="'+menuWidth+'" border="0" cellpadding="0" cellspacing="0"><tr><td width="17" colspan="1">&nbsp;</td>';
		duh+="<td width=\"140\" border=\"0\" align=\"left\" valign=\"center\" colspan=\"1\"><span class=\"welcometext\">" + welcomeText + " "+x[0]+"<br/>"+x[1]+" " + memberText + "<br>"+awardsStr+"</span></td>";
		duh+='<td width="23" colspan="1">&nbsp;</td></tr><tr class="onePixelHigh"><td width="17" colspan="1">&nbsp;</td><td colspan="2" width="163" align="right" valign="bottom">';
		duh+='<img src="img/divider.gif" border="0" width="163" height="1"></td></table>';}
	else{
		iD+=(TorB=='t')?'bordertop':'borderbottom'; d.id=iD;
		duh='<img border="0" width="180" height="11"'; //>
		if (TorB=='t'){duh+=(iM=='yes')?'src="img/nav_bg_top.gif">':'src="img/nav_bg_top.gif">';}
		else {duh+='src="'+bottomIMGa.src+'" id="bottomMenuImage">';}
	}
	d.innerHTML=duh;
}

function createMemberBorderHTML(menuElement,theID){
var m=menuElement,x=theID,contents='',suffix=x.slice(4),fClass=getFontClass(m[3],m[m.length-1]),tdClass=getTDClass(m[3],m[m.length-1]),tableClass,arrowSrc='',pxlSRC='';

	tableClass=(m[m.length-1]=='off')?'bottomtableOff':'bottomtableOn';
	memberBorderItem=theID;
	arrowSRC=(m[m.length-1]=='off')?arr1.src:arr1d.src;pxlSRC=(m[m.length-1]=='off')?pixG.src:pixO.src;
	var mHref='javascript:takeAction(\'';mHref=mHref+x;mHref=mHref+'\',\'\');';
	var thTD=(m[3]==1)?'<td width="16" valign="middle" align="right" bgcolor=""><a class="menu" href="'+mHref+'"><img src="'+arrowSRC+'" id="arrow'+suffix+'" name="arrow'+suffix+'" border="0"/></a></td>':'<td width="17" valign="middle" align="right" bgcolor="#fff392">&nbsp;</td>';
	var secTD=(m[3]==2)?'<img src="'+pxlSRC+'" border="0" height="4" width="4" id="arrow'+suffix+'" name="arrow'+suffix+'"/>':'&nbsp;';
	contents='<table class="'+tableClass+'" width="'+menuWidth+'" border="0" cellpadding="0" cellspacing="0">';
	contents+='<tr class="elementHeight12">';
	contents+='<td class="'+tdClass+'">';
	contents+='<a class="menu" href="'+mHref+'"><div id="'+x+'text" class="'+fClass+'">'
	contents+=menuElement[0];
	contents+='</div></a></td><td class="secTDgeneric">'+secTD+'</td>'+thTD+'</tr></table>';
	return contents;
}

function createInnerHTML(menuElement,theID){
var m=menuElement,x=theID,contents='',suffix=x.slice(4),fClass=getFontClass(m[3],m[m.length-1]),tdClass=getTDClass(m[3],m[m.length-1]),tableClass=getTableClass(m[3],m[m.length-1]),arrowSrc='',pxlSRC='';

	arrowSRC=(m[m.length-1]=='off')?arr1.src:arr1d.src;pxlSRC=(m[m.length-1]=='off')?pixG.src:pixO.src;
	var mHref='javascript:takeAction(\'';mHref=mHref+x;mHref=mHref+'\',\'\');';
	var thTD=(m[3]==1)?'<td width="16" valign="middle" align="right" bgcolor=""><a class="menu" href="'+mHref+'"><img src="'+arrowSRC+'" id="arrow'+suffix+'" name="arrow'+suffix+'" border="0"/></a></td>':'<td width="17" valign="middle" align="right" bgcolor="#fff392">&nbsp;</td>';
	var secTD=(m[3]==2)?'<img src="'+pxlSRC+'" border="0" height="4" width="4" id="arrow'+suffix+'" name="arrow'+suffix+'"/>':'&nbsp;';
	contents='<table class="'+tableClass+'" width="'+menuWidth+'" border="0" cellpadding="0" cellspacing="0">';
	contents+='<tr class="elementHeight12">';
	contents+='<td class="'+tdClass+'">';
	contents+='<a class="menu" href="'+mHref+'"><div id="'+x+'text" class="'+fClass+'">'
	contents+=menuElement[0];
	contents+='</div></a></td><td class="secTDgeneric">'+secTD+'</td>'+thTD+'</tr></table>';
	return contents;
}

function getPartialMatchArray(userPathAndFile, userQS){
var u=userPathAndFile,pathArray=u.split("/"),i;
var v=userQS,userQueryArray,userQSisString;

	if (v.indexOf("&")==-1){userQueryArray=v;userQSisString=true;}
	else{userQueryArray=v.split("&");userQSisString=false;}
	
	for (i=0;i<pathArray.length;i++){
		if (i>0){pathArray[i]="/"+pathArray[i];}
	}
	if(!userQSisString){
		for (i=1;i<userQueryArray.length;i++){
			userQueryArray[i]="&"+userQueryArray[i];
		}
	}

	urlArray=pathArray.concat(userQueryArray);
	return urlArray;
}

function elementCreate(theID,secondID,thirdID,menuElement){
var m=menuElement,x=theID,y=secondID,z=thirdID,d,lN=document.getElementById('leftNavMenu'),userLocURL,partialMatchString="",currentMatchLvl=0;
var newID=(thirdID!="")?thirdID:(secondID!="")?secondID:theID;

	userLocURL=((userLoc!=null)&&(userLoc!="")&&(userLocRootExists)&&(userLocExists))?eval(userLoc)[1]:"";
	
	if (!foundLocationToOpen){
		if((userLastPageAction==userLoc)&&(userLoc!=null)&&(userLoc!="")){
			foundLocationToOpen=true;
		}
		else if(((userLastPageAction=="")||(userLastPageAction=="null")||(userLastPageAction==null))&&((userLoc!="")&&(userLoc!=null))) {
			if (currentUserURL==m[1]){userLoc=newID;foundLocationToOpen=true;}
			else if (currentUserURL==userLocURL){foundLocationToOpen=true;}
			else{
				currentMatchLvl=0;
				for (i=1;i<partialMatchArray.length;i++){
					partialMatchString+=partialMatchArray[i];
					if (m[1].indexOf(partialMatchString)!=-1){
						currentMatchLvl++;
					}
				}
				if(currentMatchLvl>highestMatchLvl){highestMatchLvl=currentMatchLvl;highestMatchNode=newID;}
			}
			if ((userLoc!="")&&(userLoc!=null)&&(highestMatchLvl<=1)){
				highestMatchLvl=0;highestMatchNode="";
			}
		}
		else if(((userLastPageAction=="")||(userLastPageAction==null)||(userLastPageAction=="null"))&&((userLoc=="")||(userLoc==null)||(userLoc=="null"))){
			if (currentUserURL==m[1]){
				userLoc=newID;
				foundLocationToOpen=true;
			}
			else {
				currentMatchLvl=0;
				for (i=1;i<partialMatchArray.length;i++){
					partialMatchString+=partialMatchArray[i];
					if (m[1].indexOf(partialMatchString)!=-1){
						currentMatchLvl++;
					}
					if(currentMatchLvl>highestMatchLvl){highestMatchLvl=currentMatchLvl;highestMatchNode=newID;}
				}
			}
			if (highestMatchLvl<=1){
				highestMatchLvl=0;highestMatchNode="";
			}
		}
	}
	
	if (m[0].toLowerCase() == goldClubText){goldNode=newID;}
	
	m[m.length]="off";		//set the state of the element
	d=document.createElement('div');
	d.style.position='relative'; d.className='relDiv';
	switch(m[3]) {
		case 1:			//element is a root level menu element
			lN.appendChild(d); d.id=x; d.style.display='block';	break;
		case 2:			//element is a branch level menu element
			lN.appendChild(d); d.id=y; d.style.display='none'; break;
		case 3:			//element is a leaf level menu element
			lN.appendChild(d); d.id=z; d.style.display='none'; break;
		default:
			break;
	}
	d.innerHTML=(y=='border')?createMemberBorderHTML(m,d.id):createInnerHTML(m,d.id);
}

function getParentLevel(nodeID){return(nodeID.substring(0,nodeID.lastIndexOf("_")));}

function startMenu(){
var m,z=rootElementList.length-1,i,j,k,oneID,twoID,threeID,oneObj,twoObj,threeObj,lN=document.getElementById('leftNavMenu'),d,f=0,iM,q,lastMem='',R=rootElementList;
	if ((document.getElementById('bordertop')==null)&&(document.getElementById('menu_0welcome')==null)){
		iM=isMember;
		createTBorW('t',f);
		f++;
		//Condition for Welcome statement.
		if (iM=='yes'){createTBorW('w',f);}
	}

	for (i=0;i<=z;i++){
//		alert(R[i]+'\n'+oneObj.length);
		oneID=R[i];oneObj=eval(oneID);if (oneObj[4]=='yes'){lastMem=oneID;}if ((lastMem!=oneID)&&(lastMem!='')&&(oneObj[4]!='yes')){q='border';lastMem='';}elementCreate(oneID,q,'',oneObj);f++;q='';
		if (oneObj[2]>0){
			for (j=1;j<=oneObj[2];j++){
				twoID=oneID+'_'+j;
				if (nodeExists(twoID)){	//check for existence
					twoObj=eval(twoID);elementCreate(oneID,twoID,'',twoObj);
					if (twoObj[2]>0){
						for (k=1;k<=twoObj[2];k++){
							threeID=twoID+'_'+k;
							if (nodeExists(threeID)){	//check for existence
								threeObj=eval(threeID);elementCreate(oneID,twoID,threeID,threeObj);}}}
				}
			}
	}}
	lastRoot=oneID;
	createTBorW('b',f);	
	f++;

//	alert("userLocExists = " + userLocExists + "\nuserLoc = " + userLoc);
//	alert("userLoc = "+userLoc+"\nhighestMatchNode = "+highestMatchNode+"\nfoundLocationToOpen = "+foundLocationToOpen+"\nhighestMatchLvl = "+highestMatchLvl+"\n((foundLocationToOpen)||((highestMatchNode=='')&&(highestMatchNode==null))) = "+((foundLocationToOpen)||((highestMatchNode=="")&&(highestMatchNode==null))));

	if((userLocExists)&&(highestMatchNode!="")&&(highestMatchNode!=null)&&(highestMatchNode!=undefined)&&(highestMatchNode!="null")){//alert(userLoc+"\n"+highestMatchNode);
		if (getParentLevel(userLoc)==getParentLevel(highestMatchNode)){//alert("They have the same parent\n"+userLoc+"\n"+highestMatchNode+"\n"+userLocExists);
		highestMatchNode=userLoc;
		}
	}

	if ((foundLocationToOpen)&&(userLocExists)&&((highestMatchNode=="")||(highestMatchNode==null)||(highestMatchNode==undefined)||(highestMatchNode!="null"))){openTo(userLoc);/*alert("userLoc = " + userLoc + "\nhighestMatchNode = " + highestMatchNode);*/}
	else {openTo(highestMatchNode);}
}