/*------------------------------------------------------------------------------------------------
VirtualPump main site scripting functions

Author:		Jim Robinson
Email:		jrobinson@shipcopumps.com
------------------------------------------------------------------------------------------------*/

function hideShow(elem, state) {
	obj=document.getElementById(elem);
	switch (state) {
		case 0: obj.className="hidden"; break; //manual - 0 to hide
		case 1: obj.className="visible"; break; //manual - 1 to show
		default: obj.className=(obj.className=="visible") ? "hidden" : "visible"; break; //auto
	}
}

function setPref(opt,val) {
	var date = new Date(); var days = 1;
	date.setTime(date.getTime()+(days*24*60*60*1000));
	document.cookie = opt + "=" + val + ";expires=" + date.toGMTString();
}

function getCookie(strName) {
	var numEndOfCookie;
	var Result = "";
	var allCookies = document.cookie;
	var SearchName = strName + "=";
	var StartOfCookie = allCookies.indexOf(SearchName)
	if (StartOfCookie != -1) {
		StartOfCookie += SearchName.length;
		EndOfCookie = allCookies.indexOf(";", StartOfCookie);
		if (EndOfCookie == -1) {
			EndOfCookie = allCookies.length;
		}
		Result = allCookies.substring(StartOfCookie, EndOfCookie);
	}
	return Result;
}

function tabTo(z) {
	// Build an array that contains only a record of DIVs on the page that have class names
	var obj = document.getElementsByTagName("LI"), count = 0, tId, div = new Array();
	for (k = 0; k < obj.length; k++) {
		if (obj[k].className=="tabSelect" || obj[k].className=="tabUnselect") {
			div[count] = obj[k].id;
			count++;
		}
	}
	// Unselect all tabs, but get the id for the tab of the DIV that was selected
	for (i = 0; i < count; i++) {
		if (div[i] == z)
			tId = i;
		document.getElementById("t"+i).className="tabUnselect";
		document.getElementById("t"+i+"_").style.display="none";
	}
	// Select the tab
	document.getElementById("t"+tId).className="tabSelect";
	document.getElementById("t"+tId+"_").style.display="block";
	setPref("tab",z); //store the previous clicked tab
}

function lastTab() {
	if (getCookie("tab")) {
		tabTo(getCookie("tab"));
	}
}