function extract_domain(URL){
 URL = URL.toLowerCase(); 
 
 URL = URL.replace("http://www.", '');
 URL = URL.replace("www.", '');
 URL = URL.replace("http://", '');
 
 var pos = URL.search("/");
 
 //return pos;   
 if (pos == -1) { 
   return URL;
 }
 else 
   return URL.substring(0, pos);  
};

var url = document.referrer; 

if (url != ''){
  if (extract_domain(location.href) != extract_domain(url)){
  	// Cookie bus laikomas tiek dienu 
    var days = 30;
    var date = new Date();

    date.setTime(date.getTime ()+(days*24*60*60*1000));

    var expires = "; expires="+date.toGMTString();
    // Irasom sausauneli refferer
    document.cookie = 'ref='+url+'' + expires;
  };
}  
 	

