function CheckCookie (CookieName) {
	var lf = "\n";
	var CookieString = document.cookie;
	var CookieSet = CookieString.split (';');
	var SetSize = CookieSet.length;
	var CookiePieces
	var CookieAvailable
	var ReturnValue = "";
	var x = 0;
	for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {
		CookiePieces = CookieSet[x].split ('=');
		if (CookiePieces[0].substring (0,1) == ' ') {
			CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);
		}
		if (CookiePieces[0] == CookieName) {
			ReturnValue = CookiePieces[1];
			//alert("Welcome, " + CookiePieces[1])
			CookieAvailable = "Y"
		}
	}
	if(ReturnValue=="")
		alert('A cookie was not set. '+lf+'Please ensure that your browser is accepting cookies.');
		CookieAvailable = "N"
}
function getUserName(CookieName) {
	var lf = "\n";
	var CookieString = document.cookie;
	var CookieSet = CookieString.split (';');
	var SetSize = CookieSet.length;
	var CookiePieces
	var ReturnValue = "";
	var x = 0;
	for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {
		CookiePieces = CookieSet[x].split ('=');
		if (CookiePieces[0].substring (0,1) == ' ') {
			CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);
		}
		if (CookiePieces[0] == CookieName) {
			ReturnValue = CookiePieces[1];
			return unescape(ReturnValue);
		}
	}
}
function replaceCookieValue(name, newval) {
	//alert("name=" + name + ",newval=" + newval);
	document.cookie = name + "=" + escape (newval) + "; path=/;";
	//alert("newcookie=" + document.cookie);
	window.location.href="/webapp/CustLogon/LogoutServlet";
	return null;	
}

function saveLogin(inForm) {
	
	if(inForm.savep.checked){
	
		var today = new Date();
		var expires = new Date(today.getTime() + (30 * 86400000));
		
	    var name = "lakevilleSavedU";
	    var value = inForm.userid.value;
	    //alert(value);
		SetCookie (name, value, expires, "/");
		
		name = "lakevilleSavedP";
	    value = inForm.password.value;
	    //alert(value);
		SetCookie (name, value, expires, "/");
	} else {
		if (isCookieExists("lakevilleSavedU")){
			DeleteCookie("lakevilleSavedU", "/");
		}
		if (isCookieExists("lakevilleSavedP")){
			DeleteCookie("lakevilleSavedP", "/");
		}
	}
}

function getLoginName() {
	
	return getCookieValue("lakevilleSavedU");
}

function getLoginPassword() {
	return getCookieValue("lakevilleSavedP");
}

function getLoginChecked() {
	if (isCookieExists("lakevilleSavedU")){
		return "checked";
	} else {
		return "";
	}
} 

function getLogin(inForm) {
	if (isCookieExists("lakevilleSavedU")){
		inForm.userid.value = getCookieValue("lakevilleSavedU");
		inForm.savep.checked = true;
	}
	if (isCookieExists("lakevilleSavedP")){
		inForm.password.value = getCookieValue("lakevilleSavedP");
		inForm.savep.checked = true;
	} 
}
