// JavaScript Cookie Code
// Coding by Ammon Johns
// www.webmarketingplus.co.uk

// You may not modify or use this code except as stated in at
// http://www.webmarketingplus.co.uk/promotions/cookie-tracking.html

//perform a couple operations on the query string
//first slice the '?' from the string
//next split the name/value strings into an array
//var values	= location.search.slice(1).split('&');

//initialize the name/value pair array
//var name_value	= new Array();

//loop through the same/value strings and assign the
//name/values to an associative array
//for(var i=0; i<values.length; ++i) {
	//var temp		= values[i].split('=');
	//name_value[temp[0]]	= temp[1];
//}

//pass the name to return the value
//function getValue(key) {
//	return name_value[key];
//}


var cDomain = self.location.hostname;
if(cDomain.indexOf(".") < cDomain.lastIndexOf(".")){
 var domainOffset = cDomain.indexOf(".")+1
cDomain = cDomain.substr(domainOffset);
}

if(document.referrer.indexOf(cDomain)==-1 && document.referrer!="" && document.cookie.indexOf("referrer=")==-1){
var expDays = 90;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
var refdate = new Date();
document.cookie = "referrer=" + escape(document.referrer + "&&&" + unescape(location.search)) + "; expires=" + exp.toGMTString() + "; path=/" + "; domain=" + cDomain;
}
//link=" + escape(location.search)) + ";
//document.cookie = "referrer=" + escape(document.referrer + "&&&" + refdate.toGMTString()) + "; expires=" + exp.toGMTString() + "; path=/" + "; domain=" + cDomain + "; refLink=" + escape(location.search);
//}

var allCookies = document.cookie;
var cPos = allCookies.indexOf("referrer=");
if(cPos != -1){
var cdstart = cPos + 9;
var cdend = allCookies.indexOf(";", cdstart);
if(cdend == -1) cdend = allCookies.length;
var cookieContent = allCookies.substring(cdstart,cdend);
cookieContent = unescape(cookieContent);
var cdatestart = cookieContent.indexOf("&&&", 0);
var cdateend = cookieContent.length;
var cRefer = cookieContent.substring(0,cdatestart);
//var cDateRef = cookieContent.substring(cdatestart +2,cdateend)
var refLink = cookieContent.substring(cdatestart +11,cdateend);
}
else{
var cRefer = "No cookie";
var cDateRef = "No cookie";
}
