//RUNAT="CLIENT"
//this generates a valid cookie date
var CookieJs=true;

function CookieDate(lDaysFromToday) 
{
	//arg1=The number of days (+/-) from today (LongInt)
	//PURPOSE:
	//  this function is necessary because cookie dates
	//  MUST BE in this EXACT format: "Tuesday, 01-Apr-1999 08:00:00 GMT"

	var outstr;
	var temp;
	var lDiff;
	var szDay;
	var szMonth;
	var tempdate=new Date();
	var idate=Date.parse(tempdate);

	//if they sent us an invalid datediff, just use today's date
	if (isNaN(Number(lDaysFromToday)))
		lDiff=0
	else
		lDiff=(lDaysFromToday * 86400000); //86400000=number of milliseconds in a day

	//get the date plus the difference
	idate=Number(idate)+Number(lDiff)
	tempdate.setTime(idate);

	//start building the format
	szDay=DayStr(tempdate.getDay());
	szMonth=MonthStr(tempdate.getMonth());
	outstr=szDay + ", " + tempdate.getDate() + "-" + szMonth + "-" + (1900+Number(tempdate.getYear())) + " " + "12:00:00 GMT";
	return(outstr);
};

//Get the name of the month
function MonthStr(iMonth)
{
	switch(iMonth)
	{	case 0:
			return("Jan");
			break;
		case 1:
			return("Feb");
			break;
		case 2:
			return("Mar");
			break;
		case 3:
			return("Apr");
			break;
		case 4:
			return("May");
			break;
		case 5:
			return("Jun");
			break;
		case 6:
			return("Jul");
			break;
		case 7:
			return("Aug");
			break;
		case 8:
			return("Sep");
			break;
		case 9:
			return("Oct");
			break;
		case 10:
			return("Nov");
			break;
		case 11:
			return("Dec");
			break;
		default:
			return("");
	};
};

//Get the name of the weekday
function DayStr(iDay)
{
	switch(iDay)
	{	case 0:
			return("Sunday");
			break;
		case 1:
			return("Monday");
			break;
		case 2:
			return("Tuesday");
			break;
		case 3:
			return("Wednesday");
			break;
		case 4:
			return("Thursday");
			break;
		case 5:
			return("Friday");
			break;
		case 6:
			return("Saturday");
			break;
		default:
			return("");
	};
};

//Retrieves a cookie by name
function GetCookie(szKey, szDefault)
{
	//these five variables are used in the string manipulation
	//code that finds the variable in the cookie.
	var iLocation;
	var iNameLength, iValueLength;
	var iNextSemicolon;
	var szTemp, szCookie;
	if (szDefault==null) {szDefault="";};

	//calculate length and location of variable name
	szKey=szKey+"=";
	iNameLength = szKey.length;
	szCookie=document.cookie;

	//if szCookie is blank, NN 2.0 can't do an indexOf()
	if (szCookie=="")
		iLocation=-1
	else
		iLocation = szCookie.indexOf(szKey);
	
	//check for existence of variable name			
	if (iLocation < 0)
	{
		 //variable not found, so it can't be read
		 return unescape(szDefault);
	}
	else
	{
		 //get a smaller substring to work with
		 szTemp = szCookie.substring(iLocation, szCookie.length);

		 //found full string
		 iNextSemicolon = szTemp.indexOf(";")

		 //if not found, then we need the last element of the cookie
		 if (iNextSemicolon < 0) 
		 {
			  iNextSemicolon = szTemp.length + 1;
		 };
		
		 //check for empty variable (Var1=;)
		 if (iNextSemicolon == (iNameLength))
		 {
			  //variable is empty
			  return "";
		 }
		 else
		 {
			  //hey, it worked
			  return unescape(szTemp.substring(iNameLength, iNextSemicolon));
		 };
	};
};

//Saves a Cookie
function SetCookie(name,value,expires,path,domain,secure) 
{
	var szCookie;
	szCookie = name + "=" + escape (value) + 
		((expires) ? "; expires=" + expires : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = szCookie;
};

