// ****************** Variables ******************
var head = "display:''"

//Generic popup window
function OpenPopWindow(strURL,intHeight,intWidth,strTitle,intTools) {

	var winExtProps = "scrollbars=no,menubars=no,toolbars=no,resizable=no"

	if (intTools == 1) {winExtProps = "scrollbars=yes,menubars=no,toolbars=no,resizable=yes";}
	if (intTools == 2) {winExtProps = "scrollbars=yes,menubars=yes,toolbars=yes,resizable=yes";}
	
	var page = strURL
	windowprops = "height=" + intHeight + ",width=" + intWidth + ",location=no,"+ winExtProps;
	window.open(page, "OpenWindow", windowprops);
}

function OpenExtranetPopWindow(strURL,intHeight,intWidth,strTitle,intTools) {

	var winExtProps = "scrollbars=no,menubars=no,toolbars=no,resizable=no"

	if (intTools == 1) {winExtProps = "scrollbars=yes,menubars=no,toolbars=no,resizable=yes";}
	if (intTools == 2) {winExtProps = "scrollbars=yes,menubars=yes,toolbars=yes,resizable=yes";}
	
	var page = strURL
	windowprops = "height=" + intHeight + ",width=" + intWidth + ",location=no,"+ winExtProps;
	window.open(page, "NemoGroup", windowprops);
}

//To test whether a tag with the name/id exists in the current document
function jsObjectExists(strName) {

	try {
		var oObject = document.all.namedItem(strName);
	}
	catch(er) {
		var oObject = document.all(strName);
	}
	
	if (oObject != null){
		return 1;
	}else{
		return 0;
	}
}

//toggle navigation selection
function Nav_Vis(Id_Toggle,headername,strURL) {
	
	//shrink all main headings and reset colours AND sub nav
	var strCurStatus = document.all("nav_div_" + Id_Toggle).style.display;
	var rHName = "nav_div_" + Id_Toggle
	for (var i=1; i < 9; i++) {
		document.all("nav_div_" + i).style.display = "none";
		document.all("nav_ctrl_" + i).className = "closed_nav";
		if (jsObjectExists("nav_img_" + i) == 1) {document.all("nav_img_" + i).src = "../../img/generic/warrow_down.gif";}
		if (jsObjectExists("nav_imgr_" + i) == 1) {document.all("nav_imgr_" + i).className = "closed_nav";}
		if(i ==7) {
			document.all("nav_div_" + i).style.display = "none";
			document.all("nav_ctrl_" + i).className = "closed_nav_eos";
		}
		if(i ==8) {
			document.all("nav_div_" + i).style.display = "none";
			document.all("nav_ctrl_" + i).className = "closed_nav_eos";
		}
		var hname = "nav_div_" + i;
		new cookie(hname, "closed", 0, "/").set();
	}
	
	//sub nav cookie value
	new cookie("snav_", null, 7, '/').set();
	
	//expose selected sub headings + change bg color of main heading
	//IF it's not being closed
	if (strCurStatus == "none") {
		document.all("nav_ctrl_" + Id_Toggle).className = "open_nav";
		document.all("nav_div_" + Id_Toggle).style.display = "" ;
		if (jsObjectExists("nav_img_" + Id_Toggle) == 1) {document.all("nav_img_" + Id_Toggle).src = "../../img/generic/warrow_up.gif";}
		if (jsObjectExists("nav_imgr_" + Id_Toggle) == 1) {document.all("nav_imgr_" + Id_Toggle).className = "open_nav";}
		new cookie(rHName, "open", 0, "/").set();
		if (strURL != "nolink") {document.location.href = strURL}
	}
}

//onload dropdown for navigation
function navDrop(strPage) {

	//descriptive and literal names for nav df
	var Ary = new Array ("nav_div_1",nav_div_1,"nav_div_2",nav_div_2,"nav_div_3",nav_div_3,"nav_div_4",nav_div_4,"nav_div_5",nav_div_5,"nav_div_6",nav_div_6,"nav_div_7",nav_div_7);

	var iCntr = 0;
	
	//loop through all the possible cookie names
	for (i=0; i<14; i++) {
		
		//check for the cookies
		var checkit = new cookie(Ary[i]).read();
		
		//nothing to do except to jump to the next name in the array
		if (checkit == null || checkit == "closed") {i++}
		else {

			//move to the literal name in the array
			//and then open the div please
			i ++;
			if (i == 1) {iCntr = 1}
			if (i == 3) {iCntr = 2}
			if (i == 5) {iCntr = 3}
			if (i == 7) {iCntr = 4}
			if (i == 9) {iCntr = 5}
			if (i == 11) {iCntr = 6}
			if (i == 13) {iCntr = 7}
			
			//ignore all for home page
			if (strPage != "NODROP") {
				if (i < 14) {
					//sub nav
					var check_snav = new cookie("snav_").read();
					if (check_snav != null) {
						if (jsObjectExists("snav_" + check_snav) == 1) {
							document.all("snav_" + check_snav).className = "high_snav";
						}
					}
					document.all("nav_ctrl_" + iCntr).className = "open_nav";
					if (jsObjectExists("nav_imgr_" + iCntr) == 1) {document.all("nav_imgr_" + iCntr).className = "open_nav";}
					if (jsObjectExists("nav_img_" + iCntr) == 1) {document.all("nav_img_" + iCntr).src = "../../img/generic/warrow_up.gif";}
				}
				//Legal info
				if (iCntr = 7) {
					document.all("nav_ctrl_" + iCntr).className = "open_nav_eos";
					document.all("nav_div_" + iCntr).style.display = "" ;
				}
				var head = "display:''"
				head = Ary[i].style
				head.display = ""
			}
		}
	}
}


//Navigation jumping
function NavLink(str_SURL,int_SNId,int_NId) {
	//expose selected sub headings + change bg color
	var snavHName = "snav_"
	document.all("snav_" + int_NId + "_" + int_SNId).className = "high_snav";
	new cookie(snavHName, int_NId + "_" + int_SNId, 7, '/').set();
	document.location.href = str_SURL;
}


//Home from breadcrumb route
function ReturnHome() {
	//reset all navigation
	Nav_Reset()
	document.location.href = "/home.asp"
}

//Populte dealer dropdown
function PopulateDealerNames(inForm,selected,DGId) {

	/*get the array that's been selected*/
	var selectedArray = eval("Array" + selected);
	var flgSel = false
	var str_HTML = "";

	/*clear out the options*/
	document.all.dealer_name_div.innerHTML = "";
	str_HTML = "<font class='content'>"
	str_Area = document.all.dealer_area.value;
	
	/*build the new option boxes*/
	for (var i=0; i < selectedArray.length; i++) {

		var s = DGId
		/*select the first option*/
		if (i == 0) {
			str_HTML = str_HTML + "<a href='wherecanibuy.asp?finddealer=finddealer&dealer_name=" + selectedArray[i] + "&dealer_area=" + str_Area + "'>" + selectedArray[i] + "</a><br>";
		}
		else {
			/*if there's already been a selection hold it*/
			if ((selectedArray[i].search(s) > 0) && (flgSel == false)) {
				flgSel = true
				str_HTML = str_HTML + "<a href='wherecanibuy.asp?finddealer=finddealer&dealer_name=" + selectedArray[i] + "&dealer_area=" + str_Area + "'>" + selectedArray[i] + "</a><br>";
			}
			else {
				str_HTML = str_HTML + "<a href='wherecanibuy.asp?finddealer=finddealer&dealer_name=" + selectedArray[i] + "&dealer_area=" + str_Area + "'>" + selectedArray[i] + "</a><br>";
			}
		}
	}
	
	str_HTML = str_HTML + "</font>";
	
	document.all.dealer_name_div.innerHTML = str_HTML;
}

//Display Key Help explaining
function DisplayKeyHelp(int_Toggle) {
	//open it
	//if (int_Toggle == 1) {document.all.Key.className = "KeyHelp_On";}
	//close it
	//if (int_Toggle == 0) {document.all.Key.className = "KeyHelp_Off";}
}