function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
		endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

function saveReferrerCookie() {
	todayDate = new Date;
	id = todayDate;
	id= todayDate.getTime(); 

	ref="" +document.referrer;
	se="" +document.location.search;
	url=""+document.URL;
	hora=""+todayDate.getDate()+"/"+(todayDate.getMonth()+1)+"/"+todayDate.getYear()+"  "+todayDate.getHours()+":"+todayDate.getMinutes();

	if(top.document.location==document.referrer || (document.referrer == '' && top.document.location != '')) {
		ref=""+top.document.referrer;
		se=""+top.document.location.search;
		url=""+top.document.URL;
	}

	s="ref="+ref;
	s+="&id="+id;
	s+="&url="+url;
	s+="&time="+hora;
	expireDate = new Date;
	expireDate.setMonth(expireDate.getMonth()+3);

	var id2 = GetCookie('SurfDetails');

	if (id2 == null) {
		document.cookie = "SurfDetails="+s+";expires=" + expireDate.toGMTString();
	} else {
		if (url != "") {
			if ((url.indexOf("zztype") > 0)) {
				document.cookie = "SurfDetails="+s+";expires=" + expireDate.toGMTString();
			}
		}
	}
}