function ReadCookie(name){
	var allCookie, CookieVal, length,start,end;
	cookieVal="";
	name=name+"="; //append equals to avoid false matches.
	allCookie=document.cookie;
	length=allCookie.length;
	if (length>0) {	//no cookies - user probably incinerated.
		start=allCookie.indexOf(name,0)
		if (start!=-1) {	//avoid if cookie wasn't set.
			start+=name.length;
			end=allCookie.indexOf(";",start);
			if (end==-1) {end=length;}
			cookieVal=unescape(allCookie.substring(start,end));
		}
	}
	return(cookieVal);
}
function WriteCookie(name,value,expires,domain,path,secure){
	var CookieVal,CookError;
	CookieVal=CookError="";
	if (name) {
		CookieVal=CookieVal+escape(name)+"=";
		if (value) {
			CookieVal=CookieVal+escape(value);
			if (expires) {
				CookieVal=CookieVal+"; expires="+expires.toGMTString();
			}
			if (domain){
				CookieVal=CookieVal+"; domain="+domain;
			}
			if (path) {
				CookieVal=CookieVal+"; path="+path;
			}
			if (secure) {
			CookieVal=CookieVal+"; secure";
			}
		} else {
			CookError=CookError+"Value failure";
		} //need value
	} else {
		CookError=CookError+"Name failure";
	} //need name
	if (!CookError) {
		document.cookie=CookieVal;//sets cookie
		if (value != ReadCookie(name)) //checks to make sure OK
			{CookError="Write failure";
		}
	}
	return CookError;
}

cookieValue = ReadCookie("referer");
if (cookieValue == '') {
//	alert ("Cookie trenutno ne postoji! '" + cookieValue + "'");
	result = WriteCookie("referer", document.referrer, '', ".yu4you.com", "/");
//	alert ('Upravo je upamcen cookie: ' + ref + ';\nrezultat operacije: ' + result);
} else {
//	alert ('Cookie vec postoji: ' + cookieValue);
}
