String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	var currentDomain = location.host;
	document.cookie = name+"="+value+expires+"; path=/; domain=" + currentDomain;
}

function getCookieValue(searchName,defaultval) {
    var retVal = false;
    if (typeof(defaultval)!="undefined") retVal=defaultval;
    
    var cookies = document.cookie.split(";");

    for (var i = 0; i < cookies.length; i++) {
	if (cookies[i].indexOf("&") != -1) {
	    var parentName = cookies[i].slice(0, cookies[i].indexOf("="));
	    var parentValue = cookies[i].slice(cookies[i].indexOf("=") + 1);
	    var parentArr = parentValue.split("&");
	    for (var j = 0; j < parentArr.length; j++) {
		var cookieCrumbs = parentArr[j].split("=");
		var cookieName = cookieCrumbs[0];
		var cookieValue = cookieCrumbs[1];
		if (cookieName.trim() == searchName.trim()) {
		    retVal = cookieValue;
		    break;
		}
	    }
	    //alert ('cookieArray ' + parentName);
	}
	else {
	    var cookieCrumbs = cookies[i].split("=");
	    var cookieName = cookieCrumbs[0];
	    var cookieValue = cookieCrumbs[1];
	    if (cookieName.trim() == searchName.trim()) {
		retVal = cookieValue;
		break;
	    }
	}
    }
    return retVal;
}

//this is getting added here because I don't have a better place for it
//however, i'd prefer it in the end user header

var InitialEntry = getCookieValue('InitialEntry');
var SessionEntry = getCookieValue('SessionEntry');

if (InitialEntry) {
	createCookie('InitialEntry', InitialEntry, 365)
}
else {
	InitialEntry = location.href;
	createCookie('InitialEntry', InitialEntry, 365)
}

if (SessionEntry) {
	createCookie('SessionEntry', SessionEntry)
}
else {
	SessionEntry = location.href;
	createCookie('SessionEntry', SessionEntry)
}


