function CookiesEnabled(){
	var expDate = new Date();
	var cookieable = false;
	var time = new Date();
	time.setTime(time.getTime() +(60*1000));
	var cookieExpires = time.toGMTString();
	//document.write("Your browser is: <b>", navigator.appName,"</b><BR>");
	//document.write("Version:  <b>",navigator.appVersion,"</b><BR>");
	//set your temprorary cookie & check to see if ANY cookies exist, including the one you just set
	document.cookie="Cookieable=yes; expires="+cookieExpires+";path=/;domain="+document.domain;
	//document.write(document.cookie);
	if (document.cookie.length>0){
		//document.write("Your browser supports cookies.<BR><BR>");
		cookieable = true;
	} else {
		//document.write("Your browser doesn't support cookies,  or they're currently disabled.<BR><BR>");
		//document.write(document.cookie.substring(0,document.cookie.length)+"<BR><BR>");
		cookieable = false;
	}
	document.cookie="Cookieable=CLEAR; expires=Sun, 09-Nov-97 01:00:00 GMT"+";path=/;domain="+document.domain;
	var expDate = new Date();
	expDate.setTime(expDate.getTime() + (24*60*60*1000)); 
	SetCookie("CookiesEnabled", "true", expDate);
	return cookieable;
}	

function clearErrors(){ 
	var expDate = new Date();
	expDate.setTime(expDate.getTime()); 
	SetCookie("acerrors", "CLEAR", expDate, "/");
	SetCookie("acerrortext","CLEAR", expDate, "/");
}

function clearErrorsAndRefresh(){
	clearErrors();
	history.go(0);
}

function refresh(){
	history.go(0);
}
function GetSession() {
	var id = GetCookie("sessionID");
	if ((id == null) || (id == "undefined"))
		 id = "no id";
	return id;
}

function SetACUser(){
	SetCookie("validated", "yes");
}

function ACUser(){
	var ac=GetCookie("validated");
	return ac;
}

function SetSession(value){
	var expMins = 15; // or number of minutes 
	var expDate = new Date();
	expDate.setTime(expDate.getTime() +  (60 * expMins)); 
	SetCookie("sessionID", value, expDate);
	alert(document.cookie);
}

function GetCookie(name) {
    	var start = document.cookie.indexOf(name+"=");
    	var len = start+name.length+1;
    	if ((!start) && (name != document.cookie.substring(0,name.length))) 
    		return null;
    	if (start == -1) 
    		return null;
    	var end = document.cookie.indexOf(";",len);
    	if (end == -1) 
    		end = document.cookie.length;
    	var cval = unescape(document.cookie.substring(len,end));
    	
    	// spaces come in as '+', convert back to spaces, convert !'s to <BR>\n
    	cval.replace(/\!/g,"<BR>\n");
    	return cval.replace(/\+/g, " ");
}

function SetCookie(name,value,expires,path,domain,secure) {
	// make sure the document.domain is not www.(something.com)
	if (domain){
		var rootdom = domain.replace(/www./g,"");
		domain = rootdom;
	}
	document.cookie = name + "=" +escape(value) +
	        ( (expires) ? ";expires=" + expires.toGMTString() : ";") +
	        ( (path) ? ";path=" + path : ";") + 
	        ( (domain) ? ";domain=" + domain : ";") +
	        ( (secure) ? ";secure" : ";");
}

function reportSessionStatus(){
	var cookiesEnabledSet = GetCookie("CookiesEnabled");
	if (cookiesEnabledSet == null){
		cookiesEnabled = CookiesEnabled();
	} else {
		cookiesEnabled = true;
	}
	var loginID = GetCookie("loginid");
	var errors = GetCookie("acerrors");
	var errortext = GetCookie("acerrortext");
	
	if ((!cookiesEnabled) || (loginID != null) || (errors != null)){
		document.writeln("<tr>");
 		document.writeln("	<td width=\"100%\" height=\"15\" colspan=\"2\" background=\"images/lineSpacer35.gif\">");
 		document.writeln("		<p class=\"ACSection\"><img border=\"0\" src=\"images/GreenTriangle.gif\" width=\"12\" height=\"12\">");
		document.writeln("		Session Status");
		document.writeln("	</td>");
		document.writeln("</tr>");
	}
	if (!cookiesEnabled){
		document.writeln("<tr>");
		document.writeln("	<td width=\"100%\"  colspan=\"2\" background=\"\">");
		document.writeln("		<font color=\"#D90000\">");
		document.writeln("		<p class=\"ACSectionText\">Your browser does not support cookies or you have cookies disabled. You must enable cookies to use these features.");
		document.writeln("		</font>");
		document.writeln("	</td>");
		document.writeln("</tr>");
	}
	if (loginID != null){
		document.writeln("<tr>");
		document.writeln("	<td width=\"100%\"  colspan=\"2\" background=\"\">");
		document.writeln("		<font color=\"#D90000\">");
		document.writeln("		<p class=\"ACSectionText\">You are currently logged in as ", loginID, ". <a href=\"#\" onClick=\"refresh()\" class=\"ACLink\"><font size=\"1\">Refresh session state</font></a>");
		document.writeln("		</font>");
		document.writeln("	</td>");
		document.writeln("</tr>");
	}
	if (errors != null){
		document.writeln("<tr>");
		document.writeln("	<td width=\"100%\" colspan=\"2\" background=\"\">");
		document.writeln("		<font color=\"#D90000\">");
		document.writeln("		<p class=\"ACSectionText\">Last messages (", errors, "). <a href=\"#\" onClick=\"clearErrorsAndRefresh()\" class=\"ACLink\"><font size=\"1\">Clear messages</font></a>");
		document.writeln("		<div align=\"center\"><table width=\"85%\">");
		document.writeln("			<p align = \"left\" class=\"ACText\">", errortext, "");
		document.writeln("			<p align = \"left\" class=\"ACText\"> </p>");
		document.writeln("		</font></table></div>");
		document.writeln("	</td>");
		document.writeln("</tr>");
	}
}
function showMessages(){
	var cookiesEnabledSet = GetCookie("CookiesEnabled");
	if (cookiesEnabledSet == null){
		cookiesEnabled = CookiesEnabled();
	} else {
		cookiesEnabled = true;
	}
	var loginID = GetCookie("loginid");
	var errors = GetCookie("acerrors");
	var errortext = GetCookie("acerrortext");
	
	if ((!cookiesEnabled) || (loginID != null) || (errors != null)){
		document.writeln("<tr>");
 		document.writeln("	<td width=\"100%\" height=\"15\" colspan=\"2\" background=\"images/lineSpacer35.gif\">");
 		document.writeln("		<p class=\"ACSection\"><img border=\"0\" src=\"images/GreenTriangle.gif\" width=\"12\" height=\"12\">");
		document.writeln("		Session Status");
		document.writeln("	</td>");
		document.writeln("</tr>");
	}
	if (loginID != null){
		document.writeln("<tr>");
		document.writeln("	<td width=\"100%\"  colspan=\"2\" background=\"\">");
		document.writeln("		<font color=\"#D90000\">");
		document.writeln("		<p class=\"ACSectionText\">You are currently logged in as ", loginID, ".");
		document.writeln("		</font>");
		document.writeln("	</td>");
		document.writeln("</tr>");
	}
	if (errors != null){
		document.writeln("<tr>");
		document.writeln("	<td width=\"100%\" colspan=\"2\" background=\"\">");
		document.writeln("		<font color=\"#D90000\">");
		document.writeln("		<p class=\"ACSectionText\">Last messages (", errors, ").");
		document.writeln("		<div align=\"center\"><table width=\"85%\">");
		document.writeln("			<p align = \"left\" class=\"ACText\">", errortext, "");
		document.writeln("			<p align = \"left\" class=\"ACText\"> </p>");
		document.writeln("		</font></table></div>");
		document.writeln("	</td>");
		document.writeln("</tr>");
	}
}

