/*

Standard sniffer variables

*/

var isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
var NS4=(document.layers) ? true : false;
var IE4=(document.all && !isMac) ? true : false;
var ver4 = (NS4 || IE4) ? true : false;
var ns4 = NS4;
var ie4 = IE4;
var ns = NS4;
var ie = IE4;
var ver4 = (NS4 || IE4) ? true : false;
var ie5 = (navigator.appVersion.indexOf("MSIE 5")!= -1) ? true : false;
var IE5 = ie5;
var ie6 = (navigator.appVersion.indexOf("MSIE 6")!= -1) ? true : false;
var IE6 = ie6;
var IE5 = ie6;
var ie5 = ie6;
//debugger;

function meAlert(s) {
	if (sEMail != "undefined" && sEMail.toUpperCase() == "GORDON@GOROSE.COM") {
		window.alert(s);
	}
	return true;
}

function alertMe(s) {
	meAlert(s); 
	return true;
}

/*

COOKIES section

*/


var sArray = "'sEMail', 'sFromPage', 'sNextPage', 'sMsg',";
sArray += " 'sErrInfo', 'sReferredBy', 'bRememberMyEMail', 'sUserAgent',"; 
sArray += " 'sServer', 'iRegPageMode', 'iQPageMode',";
sArray += " 'sPassword', 'sCurPage', 'sExternalPage',";
sArray += " 'sScreen', 'sFullName', 'sSessionID', 'iCustomerID'";

eval("var aCookies = new Array(" + sArray + ")");

var iNoCookies = aCookies.length;
var i;
var sCookie;
var sVar;
var vCookieVal;
var sEval;
var sShowResults;
for (i=0; i <= iNoCookies - 1; i++) {
	sVar = aCookies[i];
	sCookie = sVar.substring(1, sVar.length).toUpperCase();
	// if (sCookie == "EMAIL") debugger;
	sEval = "vCookieVal = getCookie('" + sCookie + "'); ";
	if (sVar.substring(0, 1) == "i") {
		sEval += sVar + " = (vCookieVal != null) ? parseInt(vCookieVal) : 0;";
	}
	else if (sVar.substring(0, 1) == "b") {
		sEval += sVar + " = (vCookieVal != null) ?  ((vCookieVal.toUpperCase() == 'TRUE') ? true : false) : false;" ;
	}
	else {
		sEval += sVar + " = (vCookieVal != null) ? vCookieVal : " + "''" + ";";	
	}
	eval(sEval);
	if (sCookie == "SCREEN" && sScreen == "") {
		setCookie("Screen", screen.width.toString() + "x" + screen.height.toString() + "!" + screen.availWidth.toString() + "x" + screen.availHeight.toString());
	}
	//sShowResults += "Creating " + sVar + "\n\n";
	//sShowResults += "Cookie is " + 	sCookie + "\n";
	//sShowResults += "Eval is   " +  sEval+ "\n";
	//sShowResults += sVar + " is: " + eval(sVar).toString()+ "\n\n";
}

var IE4 = (sUserAgent == "IE4") ? 1 : 0;
var NS4 = ! IE4;

function getCookie(sCookie) {
	// if (sCookie=="IP") debugger;
	sCookie = sCookie.toUpperCase();
	// -- Put a space in front, so all cookies have format
	//    of " " + Cookiename followed by "=" or by ";"
	var s = " " + unescape(document.cookie);
	var sTempSearch;
	// -- Let's try the easiest case -- space before name, followed by name,  followed by "=" sign,
	//    expected case, where has value
	sTempSearch = " " + ((sCookie.substring(sCookie.length - 2, 1) != "=") ? sCookie + "=" : sCookie);
	var pos = s.indexOf(sTempSearch);
	if (pos == -1) return null;
	// -- We found just that, space, cookie name, then "="
	var start = pos + sCookie.length + 2; // -- Account for added space in this test		
	var end = s.indexOf(";", start);
	if (end == -1) {
		// -- Must be case where this is at end and there is no semi-colon!
		var value = s.substring(start);
	}
	else {
		var value = s.substring(start, end);
	}
	var re = /\+/;
	while (re.test(value)) {
		value = value.replace(re, " ");
	}
	return value;

}

function deleteCookie (name) {  
	name = name.toUpperCase();
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1000);   
	var cval = getCookie(name);
	/*var re = / /;
	while (re.test(cval)) {
		cval = cval.replace(re, "+");
	}	*/
	// -- Create info
	var sDelCookie = name + "=Delete" + "; path=/"
	/* if (sServer != null && ! isblank(sServer)) {
		sServer = sServer.toUpperCase();
		//if (sServer.indexOf("INSPIRON") == -1 && sServer.indexOf("LOCALHOST") == -1) {
		//	sDelCookie += "; domain=.activecert.com";
		//}
	}*/
	sDelCookie += "; expires=" + exp.toGMTString();
	// cval = escape(cval); 
	document.cookie = sDelCookie;
	return sDelCookie;
}

function setCookie(sCookieName, vCookieVal) {
	// if (sCookieName=="ErrInfo") debugger;
	// deleteCookie(sCookieName);
	sCookieName = sCookieName.toUpperCase();
	var isCookieNameLen = sCookieName.length;
	if (sCookieName.substring(isCookieNameLen - 1, 1) != "=") {
		sCookieName += " = "
	}
	var sSetCookie = sCookieName + escape(vCookieVal) + "; path=/"
	/*if (sServer != null && ! isblank(sServer)) {
		sServer = sServer.toUpperCase();
		//if (sServer.indexOf("INSPIRON") == -1 && sServer.indexOf("LOCALHOST") == -1) {
		//	sSetCookie += "; domain=.activecert.com";
		//}
	}*/
	// debugger;
	document.cookie = sSetCookie;
	return sSetCookie;
}