// Full URL"s are required in production for the Search pages to work properly
var domain = "http://www.serviceguard.com"; // PROD: No trailing slash
// var domain = ""; // DEV

var navimagepath = domain + "/images/nav/";

function roll(imgid,imgevent,imgsrc) {
	if(imgsrc == "1") {
		navimagepath = domain + "/images/nav/";
	} else if (imgsrc == "2") {
		navimagepath = domain + "/images/contracts/";
	}
	// if section is not active then roll(over|out)
	if (document.getElementById(imgid).src.search("_up.gif") == -1) {
		if(imgevent == "over") {
			document.getElementById(imgid).src = navimagepath + imgid + "_over.gif";
			return true;
		} else if (imgevent == "out") {
			document.getElementById(imgid).src = navimagepath + imgid + ".gif";
			return true;
		} else {
			return false;
		}
	}
}

function setsection() {
	// search url string for section folder
	var strLocation = window.location.toString();
	if (strLocation.search("/hvac/") != -1) {
		var section = "hvac";
		var imgid = "tp_heat";
	} else if (strLocation.search("/repair/") != -1) {
		var section = "repair";
		var imgid = "tp_appliance";
	} else if (strLocation.search("/contracts/") != -1) {
		var section = "contracts";
		var imgid = "tp_contract";
	} else if (strLocation.search("/selfhelp/") != -1) {
		var section = "selfhelp";
		var imgid = "tp_help";
	} else if (strLocation.search("/recipes/") != -1) {
		var section = "recipes";
		var imgid = "tp_recipe";
	} else {
		return false;
	}
	
	// set "up" image for current section
	switch (section) {
		case "hvac": document.getElementById(imgid).src = navimagepath + imgid + "_up.gif"; break;
		case "repair": document.getElementById(imgid).src = navimagepath + imgid + "_up.gif"; break;
		case "contracts": document.getElementById(imgid).src = navimagepath + imgid + "_up.gif"; break;
		case "selfhelp": document.getElementById(imgid).src = navimagepath + imgid + "_up.gif"; break;
		case "recipes": document.getElementById(imgid).src = navimagepath + imgid + "_up.gif"; break;
		default: return false;
	}
}

function helpWindow() {
	var leftPos = 0
	if (screen) { leftPos = screen.width-800 }
	wSelfHelp = window.open(domain + '/selfhelp/','wSelfHelp','resizable=yes,scrollbars=auto,width=600,height=540,left='+leftPos+', top=0');
	wSelfHelp.focus();
}
function recipeCorner() {
	var leftPos = 0
	if (screen) { leftPos = screen.width-800 }
	wRecipeCorner = window.open(domain + '/recipes/','wRecipeCorner','resizable=yes,scrollbars=auto,width=760,height=450,left='+leftPos+',top=0');
	wRecipeCorner.focus();
}

// Verifies search entry before submitting search
function chkSearchFrm(frmQ) {
	if (document.getElementById(frmQ).value == "search this site" || document.getElementById(frmQ).value == "")
		{ alert("Please enter your search query!"); return false; }
	else { return true; }
}

// body onload
function runscripts() {
	setsection();
}