function get_krs_cookie(name) {
        var prefix = name + "="
        var cookieStartIndex = document.cookie.indexOf(prefix)
        if (cookieStartIndex == -1) return 0
        var cookieEndIndex = document.cookie.indexOf(";",cookieStartIndex + prefix.length)
        if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length
        return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}


function set_krs_cookie(name, value, expires, path, domain, secure) {
        var curCookie = name + "=" + escape(value) +
                ((expires) ? "; expires=" + expires.toGMTString() : "") +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                ((secure) ? "; secure" : "")
        document.cookie = curCookie
}


function tracker_krs(kid) {

   cy = document.cookie?"1":"0"
   dr = escape(document.referrer)
   wl = escape(window.location.href)
   rw = screen.width
   rh = screen.height

   if (cy == 0) document.write("<a href='http://www.krs-ix.ru/counter/info/"+kid+"' target='_blank'><img src='http://log.krs-ix.ru/krs.php?id="+kid+"&s=1&dr="+dr+"&wl="+wl+"&rw="+rw+"&rh="+rh+"' border=1 width=88 height=31 alt='KRS-IX Counter'><\/a>")
   else {
          uid = get_krs_cookie("KRSCAT")
          if (uid != 0) document.write("<a href='http://www.krs-ix.ru/counter/info/"+kid+"' target='_blank'><img src='http://log.krs-ix.ru/krs.php?id="+kid+"&s="+uid+"&dr="+dr+"&wl="+wl+"&rw="+rw+"&rh="+rh+"' border=0 width=88 height=31 alt='KRS-IX Counter'><\/a>")
          else {
                 var dt = new Date()
                 dt.setTime(dt.getTime() + 90 * 24 * 60 * 60 * 1000)
                 uid=Math.round(Math.random()*999999999);
                 set_krs_cookie("KRSCAT", uid, dt, '')
                 document.write("<a href='http://www.krs-ix.ru/counter/info/"+kid+"' target='_blank'><img src='http://log.krs-ix.ru/krs.php?id="+kid+"&s="+uid+"&dr="+dr+"&wl="+wl+"&rw="+rw+"&rh="+rh+"' border=0 width=88 height=31 alt='KRS-IX Counter'><\/a>")
            }       
    }
}