function setCookie(c_name,value,expiredays)
{var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}
function checkCookie()
{
  if(getCookie('referer')==null || getCookie('referer')=="" || getCookie('referer')!=window.location.querystring["ref"])
  {
    var val = window.location.querystring["ref"];

    if (val!=null && val!="")
    {
      setCookie('referer',val,14);
    } 
  }
}

location.querystring = (function() {   
    // The return is a collection of key/value pairs   
    var result = {};   
  
    // Gets the query string with a preceeding '?'   
    var querystring = location.search;   
  
    // document.location.search is empty if a query string is absent   
    if (!querystring)   
        return result;   
  
    // substring(1) to remove the '?'   
    var pairs = querystring.substring(1).split("&");   
    var splitPair;   
  
    // Load the key/values of the return collection   
    for (var i = 0; i < pairs.length; i++) {   
        splitPair = pairs[i].split("=");   
        result[splitPair[0]] = splitPair[1];   
    }   
  
    return result;   
})();  
