/******************************************************
 *Cookie Functions by Bryan English 11-3-00
 ******************************************************/

/************************************
 *This returns the value of a cookie
 *by the name of "cookieName"
 ************************************/
function getCookie(cookieName)
   {	
   var cookieBeg, cookieEnd;
   var cookieJar = document.cookie;
   
   //look for the cookie//
   cookieBeg = cookieJar.indexOf(cookieName,0);
   if(cookieBeg < 0)return null;
   else cookieBeg +=  cookieName.length + 1;
   
   //get value of cookie//
   cookieEnd = cookieJar.indexOf(";",cookieBeg);
   if(cookieEnd < 0)cookieEnd = cookieJar.length;
   
   //return value of cookie//
   return unescape(cookieJar.substring(cookieBeg,cookieEnd));
   }

/***********************************
 *This sets a cookie with all the
 *available properties
 ***********************************/
function setCookie(name,value,expires,path,domain,secure)
{
	var theDate = new Date();
	theDate.setTime(theDate.getTime() + expires);
	var expCrumb = ((expires == null) ? "" : ("; expires=" + theDate.toGMTString()));
	var pathCrumb = ((path == null) ? "" : ("; path=/" + path));
	var domainCrumb = ((domain == null) ? "" : ("; domain=" + domain));
	var secureCrumb = ((secure == true) ? "; secure" : "");
	if (value==null) value=""
	document.cookie = name + "=" + escape(value) + expCrumb + pathCrumb + domainCrumb + secureCrumb;
}
	
/***********************************
 *This is an easy why to set a cookie
 ***********************************/
function setQuickCookie(name,value)
{
	document.cookie = name + "=" + escape(value);
}

/***********************************
 *This deletes a cookie
 ***********************************/
function trashCookie(cookieName)
{
	setCookie(cookieName,"deleteMe",-1 * weeks)
}

/***********************************
 *This updates a cookie if it exists
 ***********************************/
function touchCookie(name,expires)
{
	if (getCookie(name) == null)
		return;
	var theDate = new Date();
	theDate.setTime(theDate.getTime() + expires);
	var expCrumb = ((expires == null) ? "" : ("; expires=" + theDate.toGMTString()));
	document.cookie = name + "=" + escape(getCookie(name)) + expCrumb;
}

function getContactCookies(name, el){
	var testVal = getCookie(name);
	if (testVal == "null") testVal = "";
	if (testVal == null) testVal = "";
	if (name == null) el.value = "";
	else el.value = testVal;
}