/*
************************************
***** Javascript 1.1 Functions *****
************************************
Cookie( document , name , hours , path , domain , secure )
	Object used to contain a number of name/value pairs.  The arguments are as follows:
	- document = Include the document object here.
	- name = Specify the name of the cookie.
	- hours = Optional INTEGER specifying the number of hours to expire the cookie in.
	- path = Optional STRING to specify the path attribute, the section of the website that the cookie will be used in.
	- domain = Optional STRING to specify the domain attribut, the URL of the website that the cookie will be used in.
	- secure = Optional BOOLEAN that indicates a secure cookie.
_CookieStore()
	Method used within the cookie object to store away all of the name/value pairs.
_CookieLoad()
	Method used within the cookie object to preload all of the name/value pairs.
_CookieExpire()
	Method used within the cookie object to delete/expire it.
*/

/***********************************
***** Javascript 1.1 Functions *****
***********************************/
function Cookie(document, name, hours, path, domain, secure) {
  // ANY VAR IN "this" THAT DOES NOT START WITH A "$" WILL BE WRITTEN INTO THE COOKIE (READ FROM ALSO)
	this.$doc=document;
	this.$name=name;
	if(hours) this.$expiration=new Date((new Date()).getTime()+hours*3600000);
	else this.$expiration=null;
	if(path) this.$path=path;
	else this.$path=null;
	if(domain) this.$domain=domain;
	else this.$domain=null;
	if(secure) this.$secure=true;
	else this.$secure=false;
	if(!Cookie.prototype.store) {
	  // INITIALISE THE PROTOTYPE OBJECT TO CREATE OUR METHODS
		Cookie.prototype.store=_CookieStore;
		Cookie.prototype.expire=_CookieExpire;
		Cookie.prototype.load=_CookieLoad; }
}
function _CookieStore() {
	var cookieval="";
	for(var prop in this) {
		if((prop.charAt(0)=="$") || ((typeof this[prop])=="function") || (prop=="")) continue;
		if(cookieval!="") cookieval+="&";
		cookieval+=prop+":"+escape(this[prop]); }
	var cookie=this.$name+"="+cookieval;
	if(this.$expiration) cookie+="; expires="+this.$expiration.toGMTString();
	if(this.$path) cookie+="; path="+this.$path;
	if(this.$domain) cookie+="; domain="+this.$domain;
	if(this.$secure) cookie+="; secure="+this.$secure;
	this.$doc.cookie=cookie;
	return true;
}
function _CookieLoad() {
	var allcookies=this.$doc.cookie;
	if(allcookies=="") return false;
	var start=allcookies.indexOf(this.$name+"=");
	if(start==-1) return false;
	start+=(this.$name.length+1);
	var end=allcookies.indexOf(";", start);
	if(end==-1) end=allcookies.length;
	var cookieval=allcookies.substring(start,end);
	var a=cookieval.split("&");
	for(var i=0;i<a.length;i++) a[i]=a[i].split(":");
	for(var i=0;i<a.length;i++) this[a[i][0]]=unescape(a[i][1]);
	return true;
}
function _CookieExpire() {
	var cookie=this.$name+"=";
	if(this.$path) cookie+="; path="+this.$path;
	if(this.$domain) cookie+="; domain="+this.$domain;
	cookie+="; expires=Thu, 1 Jan 1970 00:00:00 GMT"; // MAKE IT EXPIRE!
	this.$doc.cookie=cookie;
	return true;
}


/*
 * TRACK VISITORS TO THE DOWNLOAD SOFTWARE PAGE
 */

// CHECK TO SEE IF THIS IS THE "/google.html" page
var myGoogleCookie=new Cookie(document, "myGoogleCookie", 96);  // 4 WEEKS
var myGoogleCookieSession=new Cookie(document, "myGoogleCookieSession");
if(self.location.pathname=="/google.html") {
	var txtReferrer=document.referrer;
  // CREATE A NEW NAME / VALUE
	myGoogleCookie.detailsEntered=((txtReferrer!="")?txtReferrer:"Google");
	myGoogleCookieSession.detailsEntered=((txtReferrer!="")?txtReferrer:"Google");
	myGoogleCookie.store();
	myGoogleCookieSession.store();
//	alert("Stored Google Cookie Value: '"+myGoogleCookie.detailsEntered+"'");
}

var myReferrerCookie=new Cookie(document, "myReferrerCookie", 96);  // 4 WEEKS
var myReferrerCookieSession=new Cookie(document, "myReferrerCookieSession");
var txtReferrerVal="", txtReferrerValSession="";
// CHECK TO SEE IF THE REFERRER HAS BEEN STORED YET
if(myReferrerCookieSession.load()) txtReferrerValSession=myReferrerCookieSession.detailsEntered;
if(txtReferrerValSession=="") {
	var txtReferrer=document.referrer;
  // CREATE A NEW NAME / VALUE
	if(txtReferrer!="") {
		myReferrerCookie.detailsEntered=txtReferrer;
		myReferrerCookie.store(); }
//	else myReferrerCookie.load();
	myReferrerCookieSession.detailsEntered=((txtReferrer!="")?txtReferrer:"none");
	myReferrerCookieSession.store();
//	alert("Stored Referrer Cookie Value: '"+myReferrerCookieSession.detailsEntered+"' => '"+myReferrerCookie.detailsEntered+"'");
}
