function onLoadFocus(formName, elementName) {
/*This function is intented for focusing on a form element on page load.
formName = The name or number of the form containing the element to focus on.  This argument cannot be null.
elementName = The name or number of the element on which to focus.  If left blank, this will default to the first element.
Do not use if the form you are trying to focus on is invisible, or the input is a hidden type.
*/
	if (formName == "" || formName == null) {
		var f = 0;
		if (elementName == "" || elementName == null) {
			for (i = 0; i < document.forms[0].elements.length; i++) {
				if (document.forms[0].elements[i].type.toLowerCase() != "hidden") {
					document.forms[0].elements[i].focus();
					break;
				}
			}
		}
		else {
				document.forms[0].elements[elementName].focus();
		}
	}
	else {
		if (elementName == "" || elementName == null) {
			for (i = 0; i < document.forms[formName].elements.length; i++) {
				if (document.forms[formName].elements[i].type.toLowerCase() != "hidden") {
					document.forms[formName].elements[i].focus();
					break
				}
			}
		}
		else {
				document.forms[formName].elements[elementName].focus();
		}
	}
}

function readCookie(strCookieName) {
	var arg = strCookieName + "=";
	var clen = document.cookie.length;
	var start = document.cookie.indexOf();

	var i = 0
	var j = document.cookie.indexOf(i + arg.length);
	for (i; i < clen; i++) {
		if (document.cookie.substring(i, j) == arg) {
			var end = document.cookie.indexOf(";", j);
			if (end == -1) {
				end = clen
			}
			return unescape(document.cookie.substring(j, end).slice(arg.length, end ));
		}
		else {
			return null;
		}
	}
}

function writeCookie(strCookieName, strValues, expiredays) {
if (expiredays == null || expiredays == "") {
	 expiredays = 30;
}
	var expirationDate = new Date();
	expirationDate.setTime(expirationDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = strCookieName + " = " + strValues + ";" + ((expiredays == null) ? "" : "; expires=" + expirationDate.toGMTString()) + "; domain=." + document.domain + " ";
}

function deleteCookie(strCookieName) {
	if (readCookie(strCookieName) != null) {
		document.cookie = strCookieName + "=;expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

/*------------------------------
Style 1: March 17, 2000
Style 2: Mar 17, 2000
Style 3: Saturday March 17, 2000
Style 4: Sat Mar 17, 2000
Style 5: Sat March 17, 2000
Style 6: 17 March 2000
Style 7: 17 Mar 2000
Style 8: 17 Mar 00
Style 9: 3/17/00
Style 10: 3-17-00
Style 11: Saturday March 17
--------------------------------*/

var months = new Array();
months[1] = "January";  months[7] = "July";
months[2] = "February"; months[8] = "August";
months[3] = "March";    months[9] = "September";
months[4] = "April";    months[10] = "October";
months[5] = "May";      months[11] = "November";
months[6] = "June";     months[12] = "December";

var months2 = new Array();
months2[1] = "Jan"; months2[7] = "Jul";
months2[2] = "Feb"; months2[8] = "Aug";
months2[3] = "Mar"; months2[9] = "Sep";
months2[4] = "Apr"; months2[10] = "Oct";
months2[5] = "May"; months2[11] = "Nov";
months2[6] = "Jun"; months2[12] = "Dec";

var days = new Array();
days[1] = "Sunday";    days[5] = "Thursday";
days[2] = "Monday";    days[6] = "Friday";
days[3] = "Tuesday";   days[7] = "Saturday";
days[4] = "Wednesday";

var days2 = new Array();
days2[1] = "Sun"; days2[5] = "Thu";
days2[2] = "Mon"; days2[6] = "Fri";
days2[3] = "Tue"; days2[7] = "Sat";
days2[4] = "Wed";

var todaysdate = new Date();
date = todaysdate.getDate();
day = todaysdate.getDay() + 1;
month = todaysdate.getMonth() + 1;
yy = todaysdate.getYear();
year = (yy < 1000) ? yy + 1900 : yy;
year2 = 2000 - year; year2 = (year2 < 10) ? "0" + year2 : year2;

var dateline = new Array();
dateline[1] = months[month] + " " + date + ", " + year;
dateline[2] = months2[month] + " " + date + ", " + year;
dateline[3] = days[day] + " " + months[month] + " " + date + ", " + year;
dateline[4] = days2[day] + " " + months2[month] + " " + date + ", " + year;
dateline[5] = days2[day] + " " + months[month] + " " + date + ", " + year;
dateline[6] = date + " " + months[month] + " " + year;
dateline[7] = date + " " + months2[month] + " " + year;
dateline[8] = date + " " + months2[month] + " " + year2;
dateline[9] = month + "/" + date + "/" + year;
dateline[10] = month + "-" + date + "-" + year;
dateline[11] = days[day] + " " + months[month] + " " + date;

function rightMenu() {
var HTML = '<div id="rightmenu">';
}

function bakeCookie(strCookieName, formName) {
	while (strCookieName == null || strCookieName == "") {
		if (document.forms[formName].name != null) {
			strCookieName = document.forms[formName].name.toLowerCase();
		}
		else if (document.forms[formName].id != null) {
			strCookieName = document.forms[formName].id.toLowerCase();
		}
		else {
		strCookieName ="default";
		}
	}
	var ingredients = new Array();
	var i = 0;
	var values = "";
	for (i; i < document.forms[formName].elements.length; i++) {
		if (document.forms[formName].elements[i].type.toLowerCase() == "submit" || document.forms[formName].elements[i].type.toLowerCase() == "button" || document.forms[formName].elements[i].type.toLowerCase() == "reset" || document.forms[formName].elements[i].type.toLowerCase() == "checkbox") {
		}
		else {
			if (document.forms[formName].elements[i].type.toLowerCase() == "password") {
				ingredients[i] = document.forms[formName].elements[i].value;
			}
			else {
				ingredients[i] = document.forms[formName].elements[i].value.toLowerCase();
			}
		}
	}
	values += ingredients.join(",");
	values += "," + dateline[10];
	writeCookie(strCookieName, values);
}

function getCookieData(strCookieName, formName) {
//alert(formName);
	if (readCookie(strCookieName) != null) {
		var data = readCookie(strCookieName).split(",");
		if (document.forms[formName].elements.length < data.length) {
				var parsed = data.slice(0, 0 + document.forms[formName].elements.length)
//				alert(parsed);
				for (i = 0; i < parsed.length; i++) {
					document.forms[formName].elements[i].value = parsed[i]
				}
			}
		else {
				for (i = 0; i < data.length; i++) {
					document.forms[formName].elements[i].value = data[i]
				}
		}
	}
}


function doLogin(strFormName, strFormAction, blnBreakFrames) {
	document.forms[strFormName].action = strFormAction
	if (blnBreakFrames == "true" || blnBreakFrames == 1 || blnBreakFrames == true) {
		if (top != self && window.parent.frames[0].name.toLowerCase() == "rightmenu") {
			document.forms[strFormName].target = "_parent";
		}
	}
	if (document.forms[strFormName].chkRemeberLogin.checked) {
		bakeCookie(strCookieName.toLowerCase(), strFormName);
		document.forms[strFormName].submit()
	}
	else {
		document.forms[strFormName].submit()
	}
}

function doLogout(strCookieName) {
	if (readCookie(strCookieName) != null || readCookie(strCookieName) != "") {
		deleteCookie(strCookieName);
	}
	window.location.assign("http://helpdesk.goldenrulesoftware.com/user/logout.asp");
}

function statusMsg(msg) {
if (top != self) {
parent.window.status = msg;
}
else {
window.status = msg;
}
return true;
}

function autoSubmit2(strCookieName, formName, formAction) {
//alert(strCookieName.toLowerCase());
//alert(readCookie(strCookieName.toLowerCase()))
	if (readCookie(strCookieName.toLowerCase()) != null) {
		document.forms[formName].action = formAction;
		getCookieData(strCookieName.toLowerCase(), formName);
//alert("Email = " + document.forms[formName].elements[0].value);
//alert("Password = " + document.forms[formName].elements[1].value);
//alert(formName);
		document.forms[formName].method = "post";
		document.forms[formName].submit();
	}
}

function breakframes() {
	if (parent.location != location) {
		parent.location = location
	}
}

function isPosInteger(inputValue) {
/*This function is a check to see if a given value is a positive Whole Number.*/
	var strInput = inputValue.toString();
	for (var i = 0; i < strInput.length; i++) {
		var oneChar = strInput.charAt(i)
		if (oneChar < "0" || oneChar > "9") {
			return false
		}
	}
	return true
}

function SearchError(strSearchType) {
	if (strSearchType == "" || strSearchType == null) {
	strSearchType = "Article";
	}
	var strSearchError = "When searching by " + strSearchType + " ID Number you may only use positve whole numbers. \n  Your search can not contain any letters, spaces, or special characters.";
	return strSearchError;
}

function SearchKB(formName) {
	var searchKB = document.forms[formName]
	if (searchKB.rdoSearchType[1].checked) {
		if (isNaN(searchKB.txtSearchTerm.value) == true) {
			alert(SearchError())
			searchKB.reset()
		}
		else if (isPosInteger(searchKB.txtSearchTerm.value) == false) {
			alert(strSearchError())
			searchKB.reset()
		}
		else {
			searchKB.action = "http://kb.goldenrulesoftware.com/article.asp?ID=" + parseInt(searchKB.txtSearchTerm.value);
			searchKB.submit()
		}
	}
	else {
		searchKB.action = "http://kb.goldenrulesoftware.com/search.asp";
		searchKB.submit();
	}
}