/*
String that specifies or receives the name=value; pairs, plus any of the values listed in Possible Values.

name=value;        Where name = the name of the cookie i.e. "Field Name" and value = the "Data"

expires=date;      Setting no expiration date on a cookie causes it to expire when the browser
                   closes. If you set an expiration date, the cookie is saved across browser
				   sessions. If you set an expiration date in the past, the cookie is deleted.
				   Use GMT format to specify the date.
  
domain=domainname; Setting the domain of the cookie allows pages on a domain made up of more than
                   one server to share cookie information. The domain tells the browser to which
				   domain the cookie should be sent. If you don't specify a domain, then it
				   becomes the domain of the page that sets the cookie, such as www.domain.com.
				   The purpose of the domain is to allow cookies to cross sub-domains. A cookie
				   will not be read by this.domain.com because its domain is set to that.domain.com.
				   To have a cookie read on all sub-domains, set the domain to domain.com. You can
				   not set a domain to a domain that the page is not in, i.e. microsoft.com.


path=path;         Setting a path for the cookie allows the current document to share cookie
                   information with other pages within the same domain—that is, if the path is set
				   to /thispathname, all pages in /thispathname and all pages in subfolders of
				   /thispathname can access the same cookie information. To share cookie information
				   between all paths then set the path to /. Example path=/; or path=/cgi-bin;

secure;           Setting a cookie as secure; means the stored cookie information can be accessed
                  only from a secure environment.
				  
Example of a cookie: 'ppkcookie2=another test; expires=Fri, 3 Aug 2001 20:47:11 UTC; path=/; secure'
*/

function readCookie(rcname)
{
	var nameEQ = rcname + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function writeCookie(wcname,wcvalue,wcdays,wchours,wcminutes,wcseconds,wcdomain,wcpath,wcsecure)
{
	var name = wcname + "=" + wcvalue;
	//var value = wcvalue;
	
	// Set Expires=
	if ((wcdays>0) || (wchours>0) || (wcminutes>0) || (wcseconds>0))
	{
		var thedate = new Date();
		var daysinmils = wcdays*24*60*60*1000;
		var hoursinmils = wchours*60*60*1000;
		var minutesinmils = wcminutes*60*1000;
		var secondsinmils = wcseconds*1000;
		//date.setTime(date.getTime()+(days*24*60*60*1000));
		thedate.setTime(thedate.getTime()+(daysinmils+hoursinmils+minutesinmils+secondsinmils));
		var expires = "; expires="+thedate.toGMTString();
	}else{
		var expires = "";
	}
	// Set Domain=
	if (wcdomain != ""){
		var domain = "; domain=" + wcdomain;
	}else{
		var domain = "";
	}
	// Set Path=
	if (wcpath != ""){
		var path = "; path=" + wcpath;
	}else{
		var path = "; path=/";
	}
	// Set Secure=
	if (wcsecure == 1){
		var secure = "; secure";
	}else{
		var secure = "";
	}	
	//alert(name+expires+domain+path+secure);
	document.cookie = name+expires+domain+path+secure;
}

function deleteCookie(dcname)
{
	writeCookie(dcname,"",-1,"","","","","","");
}

function CheckForCookieAcceptance(){
	deleteCookie('TestForCookies');
	writeCookie('TestForCookies',1,0,0,0,0,0,0,0);
	if (readCookie('TestForCookies') != 1){
		alert(CookieMessage);
		return(false);
	}else{
		return(true);
	}	
}

var CookieMessage = "Cookies are required to use this website.\n\n" +
					"IMPORTANT => Reload this page AFTER the required settings have been changed in your browser.";

