// COOKIE FUNCTIONS
//	INITIALIZE EXP DATE, ACTUAL EXPIRATION IS IN SET COOKIE SO WE HAVE CURRENT TIME
var exp = new Date(); 

function getCookieVal (offset) { 
	var endstr = document.cookie.indexOf (";", offset); 
	if (endstr == -1) 
		endstr = document.cookie.length; 
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) { 
	var arg = name + "="; 
	var alen = arg.length; 
	var clen = document.cookie.length; 
	var i = 0; 
	while (i < clen) { 
		var j = i + alen; 
		if (document.cookie.substring(i, j) == arg) 
			return getCookieVal (j); 
		i = document.cookie.indexOf(" ", i) + 1; 
		if (i == 0) break; 
	} 
	return null;
}

function SetCookie (name, value) { 
	var expMins = 30;
	var expd = new Date(); 
	expd.setTime(expd.getTime() + (expMins*60*1000));
	var argv = SetCookie.arguments; 
	var argc = SetCookie.arguments.length; 
	var expires = expd; 
	var path = (argc > 3) ? argv[3] : null; 
	var domain = (argc > 4) ? argv[4] : null; 
	var secure = (argc > 5) ? argv[5] : false; 
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) + 
	((domain == null) ? "" : ("; domain=" + domain)) + 
	((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) { 
	var exp = new Date(); 
	exp.setTime (exp.getTime() - 1); 
	var cval = GetCookie (name); 
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function storeCookies() {
    //Major Problem: Only - 20 - Cookies may be stored
	SetCookie ('userid', 	document.login_form.userid.value, exp);
	SetCookie ('password', 	document.login_form.password.value, exp);

	window.location.replace("loginchk.htm");

    //return false;
    //return true;
}

function getRadioValue(radioName) {
	for (x=0; x< radioName.length; x++) {
		if (radioName[x].checked) {
			return radioName[x].value;
		}
	}
	return "no answer";
}
function getSelectValue(selectName) {
	for (x=0; x< selectName.length; x++) {
		if (selectName[x].selected) {
			return selectName[x].value;
		}
	}
	return "no answer";
}
// END COOKIE FUNCTIONS