// 1, 0, or null.  If null then the cookie is not there
window.GetSSLCookie = function() {
	return GetSecureCookie('UseSSL');
};

window.SetSSLCookie = function(theValue) {
	SetSecureCookie('UseSSL', theValue);
};

window.GetHostStr = function() {	// will return this part of the path: http://www.realorganized.com
	var totalPath = window.location.href;
	var slashCount = 0;
	var pathLength = totalPath.length;
	for (var nthChar = 0; nthChar < pathLength; nthChar++) {
		if (totalPath.charAt(nthChar) == '/') slashCount++;
		if (slashCount == 3) return totalPath.substr(0, nthChar);
	}
	return null;
};

// will return host string except this time you can force ssl or not
window.ConvertHostStrSSL = function(useSSL) {
	var theStr = window.GetHostStr();
	if (useSSL) {
		theStr = theStr.replace('http:', 'https:');
	} else {
		theStr = theStr.replace('https:', 'http:');
	}
	return theStr;
};

window.IsValidEMailAddress = function(theAddress) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return (filter.test(theAddress));
};

// wil retun an alert if Caps lock key is set
window.CapsLock = function(e) {
	//var theCapsLock = window.document.getElementById('Error');
	//var kc = e.keyCode ? e.keyCode : e.which;
	//var sk = e.shiftKey ? e.shiftKey : ((kc == 16) ? true: false);
	//if (((kc >= 65 && kc <= 90) && !sk) || ((kc >= 97 && kc <= 122) && sk)) {
		//if (theCapsLock) {
			//theCapsLock.innerHTML = 'CAPS Lock is ON';
		//}
	//} else {
		//if (theCapsLock) {
			//theCapsLock.innerHTML = '';
		//}
	//}
	return true;
};

window.GetSourceCookie = function() {
	return GetSecureCookie('source');
};

window.SetSourceCookie = function(theValue) {
	SetSecureCookie('source', theValue);
};

// will return query param info.  format  of URL like this: http://www.a.com?scott=dude&larry=sam
window.GetQueryParam = function(paramName) {
   var re = new RegExp( "[?&]" + paramName + "=([^&$]*)", "i" );
   var offset = location.search.search(re);
   if ( offset == -1 ) return null;
   var outStr = unescape(RegExp.$1);
   outStr = outStr.replace('/',''); // path url and strip this
   return outStr;
}

window.FilterChars = function(e) {
	var kc = e.keyCode ? e.keyCode : e.which;
	if ((kc == 60) || (kc == 38)) {		// < and & are forbidden as XML does not like them
		return false;
	}
	return true;
};


window.GetSecureCookie = function(cookieName) {
	var theName = cookieName + "=";
	var nameLength = theName.length;
	var theDocument = this.document;
	var theCookies = theDocument.cookie;
	var startPos = theCookies.indexOf(theName);
	if (startPos < 0) return null;
	var endValue = theCookies.indexOf(";", startPos + nameLength);
	if (endValue == -1) endValue = theCookies.length + 1;
	var returnData = unescape(theCookies.substring(startPos + nameLength, endValue));
	return returnData;
};

window.SetSecureCookie = function(cookieName, theValue) {
	try {
		var today = new Date();
		var expires_date = new Date(today.getTime() + (365 * 1000 * 60 * 60 * 24));	// 1 year
		var cookStr = cookieName + "=" + escape(theValue) + ";expires=" + expires_date.toGMTString() + ";path=/secure";
		var theDocument = this.document;
		theDocument.cookie = cookStr;  // Firefox throws an error here!
	} catch(e) {
	}
};


//window.DeleteSecureCookie = function(cookieName) {
	//window.document.cookie = cookieName + "=" + ";expires=Thu, 01-Jan-1970 00:00:01 GMT" + ";path=/secure";
//};