var arrPath; var strPath; var strSrc;
var arrNav; var arrNav02;

var strSect = ""; var numSect = -1;
var strSectCurr = "";

var bolReset = false; var bolSbmt = false;

strSrc = getQryVal("src");
if(strSrc != "") {saveCookie("src", strSrc, 0);}

strPath = window.location.pathname;
arrPath = strPath.split("/");
if(arrPath[(arrPath.length - 1)] == "") {strPath = strPath + "index.html";}

function rollOverMNav(sect, curr) {
	var strSectNew; var numSectNew;
	var strTemp;
	
	bolReset = false;
	
	strTemp = sect.slice((sect.length - 2), sect.length);
	if(strTemp == parseInt(strTemp, 10)) {
		strSectNew = sect.slice(0, (sect.length - 2));
		numSectNew = parseInt(strTemp, 10);
	} else {strSectNew = sect; numSectNew = 0;}
	strSectCurr = curr;
	
	if(strSectNew != strSect) {
		if(strSect != "") {
			if(numSect != 0) {
				if(numSect < 10) {strTemp = '0' + numSect;} else {strTemp = '' + numSect;}
				document.getElementById(strSect + strTemp).className = 'off';
			}
			document.getElementById(strSect + '00').style.visibility = 'hidden';
			if(strSect != strSectCurr) {document.getElementById(strSect).className = 'off';}
		}
		if(strSectNew != strSectCurr) {document.getElementById(strSectNew).className = 'roll';}
		document.getElementById(strSectNew + '00').style.visibility = 'visible';
	} else {
		if(numSect != 0) {
			if(numSect < 10) {strTemp = '0' + numSect;} else {strTemp = '' + numSect;}
			document.getElementById(strSect + strTemp).className = 'off';
		}
		if(numSectNew < 10) {strTemp = '0' + numSectNew;} else {strTemp = '' + numSectNew;}
		document.getElementById(strSect + strTemp).className = 'on';
	}

	strSect = strSectNew; numSect = numSectNew;
}

function rollOutMNav(sect) {
	bolReset = true;
	setTimeout(rsetMNav, 1000);
}

function rsetMNav() {
	var strTemp;

	if(bolReset) {
		if(numSect != 0) {
			if(numSect < 10) {strTemp = '0' + numSect;} else {strTemp = '' + numSect;}
			document.getElementById(strSect + strTemp).className = 'off';
		}
		document.getElementById(strSect + '00').style.visibility = 'hidden';
		if(strSect != strSectCurr) {document.getElementById(strSect).className = 'off';}
	
		strSect = ""; numSect = -1; bolReset = false;
	}
}

function dispLNav() {
	var strNav = ""; var strNav02 = "";
	var bolSNav; var i; var j;
	
	
	strNav = '<div id="leftnav">\n';
	for(i=0; i<arrNav.length; i++) {
		if(typeof(arrNav[i][2]) != "undefined") {
			arrNav02 = arrNav[i][2]; strNav02 = ""; bolSNav = false;
			for(j=0; j<arrNav02.length; j++) {
				strNav02 = strNav02 + '<div><div class="level2';
				if(arrNav02[j][1] == strPath) {strNav02 = strNav02 + ' on'; bolSNav = true;}
				strNav02 = strNav02 + '"><a href="' + arrNav02[j][1] + '">' + arrNav02[j][0] + '</a></div></div>\n';
			}
			strNav = strNav + '<div><div class="level1';
			if((arrNav[i][1] == strPath) || bolSNav) {strNav = strNav + ' open';}
			strNav = strNav + '"><a href="' + arrNav[i][1] + '">' + arrNav[i][0] + '</a></div></div>\n';
			if((arrNav[i][1] == strPath) || bolSNav) {strNav = strNav + strNav02;}
		} else {
			strNav = strNav + '<div><div class="level1';
			if(arrNav[i][1] == strPath) {strNav = strNav + ' on';}
			strNav = strNav + '"><a href="' + arrNav[i][1] + '">' + arrNav[i][0] + '</a></div></div>\n';
		}
	}
	strNav = strNav + '</div>\n';
	
	document.write(strNav);
}

function sbmtForm() {
	if(!bolSbmt) {
		bolSbmt = true;
		if(chckText(document.webform.name.value) && chckText(document.webform.company.value) && chckText(document.webform.email.value) && chckText(document.webform.telephone.value) &&
			chckText(document.webform.city.value) && chckText(document.webform.state.value) && chckText(document.webform.country.value) && chckText(document.webform.comments.value)) {
			if(chckEmail(document.webform.email.value)) {
				strSrc = getCookieVal("src");
				if(strSrc != null) {document.webform.lead.value = strSrc;}
				document.webform.submit();
			} else {
				alert('Please fill in a valid email address.');
				bolSbmt = false;
			}
		} else {
			alert('Please fill in all of the required fields.');
			bolSbmt = false;
		}
	}
}

function chckText(txt) {
	var intLen;
	var i; var bolRet;
	
	i = 0; bolRet = false;
	intLen = txt.length;
	while(i < intLen){ 
		if(txt.substr(i,1) != ' ') {bolRet = true; break;}
		i++;
	}
	
	return bolRet;
}

function chckEmail(eml) {
	var intLen;
	var i; var j; var bolRet;
	
	i = 0; j = 0; bolRet = false;
	intLen = eml.length;
	while(i < intLen){ 
		if(j == 0) {if(eml.substr(i,1) == '@') {j = 1;}}
		if(j == 1) {if(eml.substr(i,1) == '.') {bolRet = true; break;}}
		i++;
	}
	
	return bolRet;
}

function chckQry() {
	var strErr;
	
	strErr = getQryVal("err");
	
	switch(strErr) {
		case "0":
			alert('Your request has been sent!');
			break;
		case "1":
			alert('There seems to be an issue with the sending of your request.\n\nPlease try again later.');
			break;
		default: break;
	}
}

function getQryVal(key) {
	var arrQuery; var arrVars01; var arrVars02; var strVal;
	var x;
	
	arrQuery = window.location.search.split("?");
	strVal = "";
	if(arrQuery != "") {
		arrVars01 = arrQuery[1].split("&");
		
		for(x in arrVars01) {
			arrVars02 = arrVars01[x].split("=");
			if(arrVars02[0] == key) {strVal = arrVars02[1]; break;}
		}
	}
	
	return strVal;
}

function saveCookie(key, val, days) {
	var objDate; var strExp;
	
	if(days != 0) {
		objDate = new Date();
		objDate.setTime(objDate.getTime() + (days*24*60*60*1000));
		strExp = "; expires=" + objDate.toGMTString();
	}
	else {strExp = "";}
	document.cookie = key + "=" + val + strExp + "; path=/";
}

function getCookieVal(key) {
	var arrCook; var strCook; var strKey;
	var i;
	
	var strKey = key + "=";
	var arrCookie = document.cookie.split(';');
	for(i=0; i<arrCookie.length; i++) {
		strCook = arrCookie[i];
		while(strCook.charAt(0) == ' ') {strCook = strCook.substring(1,strCook.length);}
		if(strCook.indexOf(strKey) == 0) {return strCook.substring(strKey.length, strCook.length);}
	}
	return null;
}