//==== onetApp CLASS

var $onet;
var $onet_version = "std107";

function badBrowser ()
{
  if ((window.innerWidth != $onet.nsWinWidth) || (window.innerHeight != $onet.nsWinHeight))
    location.reload()
}

function protoCode ($class)
{
  var $code = '';
  for (var $i = 1; $i < arguments.length; ++ $i)
    $code += $class +'.prototype.'+ arguments[$i] +'='+ arguments[$i] +';';
  $code += $class +'.prototype.ok=1;';
  return $code;
}

function nullErrorHandler ()
{
  return true;
}

function onetApp ()
{
//==== onetApp PUBLIC METHODS

function onPageLoad ($code)
{
  $onet.onPgLdCode += $code +";";
}

function onStreamAvail ($code)
{
  $onet.onStAvCode += $code +";";
}

function streamCheck ()
{
  if (! (document.createElement && document.body.appendChild))
    return

  var $js = document.createElement('script')
  $js.type = "text/javascript"
  $js.src = "/_s/kropka/s.js"
  document.body.appendChild ($js)
}

function streamOK ($code)
{
  setTimeout ($onet.onStAvCode, 50);
}

function urlEncode ($str)
{
  $str = ""+ $str
  $str = $str.replace (/\%/g, "%25")
  $str = $str.replace (/\s/g, "%20")
  $str = $str.replace (/\#/g, "%23")
  $str = $str.replace (/\&/g, "%26")
  $str = $str.replace (/\+/g, "%2b")
  $str = $str.replace (/\?/g, "%3f")
  $str = $str.replace (/\"/g, "%22")
  $str = $str.replace (/\'/g, "%27")
  return $str
}

function logoutLink ($tpre, $apre, $apost, $tpost)
{
  if ($onet.zuoIsl) document.write (unescape (
    $tpre + '<a href="http://www.onet.pl/logout.rd">'+
    $apre + $onet.zuoUid + $apost +
    '</a>' + $tpost))
}

function loginSwitch ($code1, $code0)
{
  if ($onet.zuoIsl)
  {
    var $login = $onet.zuoUid
    eval ($code1)
  }
  else
  {
    eval ($code0)
  }
}

function getInfo1 ($ver)
{
  if ($ver != $onet_version)
    $onet.dvError ($onet_version +'.js: library version mismatch ('+ $ver +')')
    
  var $info = new Object ()

  $info.scrWidth  = window.screen && screen.width ? screen.width : 0;
  $info.scrHeight = window.screen && screen.height ? screen.height : 0;
  $info.scrBits = 0;
  if (window.screen.colorDepth) $info.scrBits = window.screen.colorDepth;
  if (window.screen.pixelDepth) $info.scrBits = window.screen.pixelDepth;
  $info.winWidth = 0;
  if (window.innerWidth) $info.winWidth = window.innerWidth;
  if (document.body && document.body.clientWidth) $info.winWidth = document.body.clientWidth;
  $info.winHeight = 0;
  if (window.innerHeight) $info.winHeight = window.innerHeight;
  if (document.body && document.body.clientHeight) $info.winHeight = document.body.clientHeight;

  $onet.info = $info

  var $res = ($onet["adid"] ? ('&IR='+ $onet["adid"]) : '')+
    '&RI='+ urlEncode ($onet.curid)+
    '&CS='+ urlEncode ($info.scrWidth+'x'+$info.scrHeight+'x'+$info.scrBits)+
    '&CW='+ urlEncode ($info.winWidth+'x'+$info.winHeight)+
    '&C1='+ urlEncode ($onet.now)+
    '&CL='+ urlEncode ($onet_version)+
    '&DU='+ urlEncode ($onet.lhref)+
    '&DR='+ urlEncode ($onet.dref);

  return $res
}

function getInfoG ()
{
	var dt=new Date();
	var url=new String();
	var d=document;
	var href=new String(d.location);
	var w=window;
	var ref;
	if (d.referrer) { ref = new String(d.referrer); } else { ref = ""; }
	if(typeof(Error)!='undefined') {
		eval("try { if (typeof(top.document.referrer)=='string') { ref = top.document.referrer } } catch(_ex) { }");
		eval("try { while (w!=top) { typeof(w.parent.document.location); w = w.parent; } } catch(_ex) {}");
	}
	eval(' if (typeof(w.gemius_id)=="undefined") { w.gemius_id = Math.floor(Math.random()*1000000000); w.gemius_cnt = 1; } else { w.gemius_cnt++; }');
	url+='&tz='+dt.getTimezoneOffset()+'&href='+escape(href.substring(0,280))+'%23_'+w.gemius_id+'_'+w.gemius_cnt+'&ref='+escape(ref.substring(0,299));
	if (screen) {
		var s=screen;
		if (s.width) url+='&screen='+s.width+'x'+s.height;
		if (s.colorDepth) url+='&col='+s.colorDepth;
	}
	return url;
}

//==== onetApp PRIVATE METHODS

function hexToDec ($hex)
{
  return parseInt ("0x"+ $hex)
}

function decToHex ($dec, $minl)
{
  if (arguments.length < 2) $minl = 0;
  $dec = parseInt ($dec)
  var $d2h = "0123456789abcdef";
  var $hex = "";
  while ($dec > 0)
  {
    $hex = $d2h.charAt ($dec & 0xf) + $hex;
    $dec >>= 4
    -- $minl
  }
  while ($minl > 0)
  {
    $hex = "0" + $hex;
    -- $minl
  }
  return $hex
}

function zuoStr ($offset)
{
  var $str = ""
  var $len = hexToDec (document.cookie.substr ($offset, 1*2))
  for (var i = 0; i < $len; ++ i)
    $str += String.fromCharCode (hexToDec (document.cookie.substr ($offset+2+i*2, 2)))
  return $str
}

function usingFrames ()
{
  $onet.unFrame = 0
}

function pageLoadHook ()
{
  if ((self != top) && $onet.unFrame) top.location.href = self.location.href;

  if (document.layers)
  {
    $onet.nsWinWidth  = window.innerWidth;
    $onet.nsWinHeight = window.innerHeight;
    onresize          = badBrowser;
  }

  if ($onet.xjs)
    onet ('onPageLoad', '$onet.statGFinal()')

  if ($onet.onStAvCode)
    onet ('onPageLoad', '$onet.streamCheck()')

  setTimeout ($onet.onPgLdCode, 50);

  return true;
}

function statCheck ($id, $ok)
{
  if (2 != $onet.sttn)
    return

  ++ $onet.statn
  if (!$ok)
    $onet.statd += $id;

  if ($onet.statn < $onet.sttn)
    return
  if (! $onet.statd)
    return
  if (! window.location || ! window.location.protocol || ("http:" != window.location.protocol))
    return

  var $img = $onet.statk
  $img.src = $img.src.replace (/^([^\/]+\/+)[^.]+(.+)$/, "$1www$2&RA="+ $onet.statd)
}

function statError ($img)
{
  $img.onerror = null;

  if (window.location.protocol && ("http:" == window.location.protocol))
    $img.src = $img.src.replace (/^([^\/]+\/+)[^.]+(.+)$/, "$1www$2&RA=2")
}

function statKLoad ($img, $ok)
{
  $img.onerror = null;
  $img.onload = null;
  $onet.statk = $img

  statCheck ("k", $ok)
}

function statGFinal ()
{
  if (! (window.location.protocol && ("http:" == window.location.protocol)))
    return
  if (! (document.createElement && document.body.appendChild))
    return

  var $js = document.createElement('script')
  $js.type = "text/javascript"
  $js.src = $onet.xjs
  document.body.appendChild ($js)
}

function statGFunc ($img, $ok)
{
  $onet.statg = $img
  return new Function ('$onet.statGLoad ('+ $ok +')')
}

function statGLoad ($ok)
{
  if (! $onet.statg)
    return

  var $img = $onet.statg
  $img.onerror = null;
  $img.onload = null;

  statCheck ("g", $ok)

  if (! ($ok && $img.width && ($img.width > 1)))
    return

  var $now = (new Date()).getTime()
  $onet.xjs = "http://onet.hit.gemius.pl/_"+ $now +"/pbi_pe.js?id=W@vC6QnwKYIM3DNDKF@_APT7"
}

function clickIt ($link)
{
  if (! $onet.clickImg)
    $onet.clickImg = new Array ()

  var $img = new Image ()
  $img.src = $link +','+ $onet.pgid + (new Date()).getTime()
  $onet.clickImg[$onet.clickImg.length] = $img
}

function igetIEVer ()
{
  var $ua = navigator.userAgent
  var $mi = $ua.indexOf("MSIE")
  if ($ua.indexOf("Win") < 0)             return ""
  if ($ua.indexOf("MSIE") < 0)            return ""
  if ($ua.indexOf("Opera") >= 0)          return ""
  if ($ua.charAt($mi+5) < 4)              return ""
  if ($ua.charAt($mi+5) > 9)              return ""
  var $re = /^([\d.]+)/i;
  if (!$re.test ($ua.substring($mi+5)))   return ""
  $res = parseFloat (RegExp.$1)
  if (isNaN ($res))                       return ""
  return $res
}

function getIEVer ()
{
  return $onet.iev;
}

function isIE ($ver)
{
  if (! arguments.length) $ver = 5.00;
  return $onet.iev && $onet.iev >= $ver;
}

function set ($key, $val)
{
  $onet[$key] = $val;
}

function get ($key, $val)
{
  return $onet[$key];
}

function dvError ($msg)
{
  if (! window.fac424a6d2ff31fed70c79e47db5b406) return
  fac424a6d2ff31fed70c79e47db5b406 ('error', $msg)
}

function adsReq ($base, $req)
{
  $onet.csrbase = $base
  $onet.csrver = '/csr-'+ ($onet.pgid ? "003" : "002")

  for (var $i = 2; $i < arguments.length; $i += 2)
    $onet.adsData[arguments[$i]] = arguments[$i + 1]

  $onet.adssrc = $onet.csrbase + $onet.csrver +
    '/req='+ $req +
    '/now='+ (new Date()).getTime() +
    '/pgid='+ ($onet.pgid ? $onet.pgid : "") +
    '/csr.js'

  return unescape ('%3cscript language=javascript1.2 src="')+ $onet.adssrc +unescape('"%3e%3c/script%3e')
}

function adsSet ($key, $val)
{
  $body = ""
  $body += "<style type=text/css>\n"
  $body += ".onet-ad-"+ $key +" { display: none }\n"
  $body += "</style>"
  if ($onet.adsData[$key +"-prepend"])
    $body += $onet.adsData[$key +"-prepend"]
  $body += $val
  if ($onet.adsData[$key +"-append"])
    $body += $onet.adsData[$key +"-append"]
  $onet.adsResult[$key] = $body
  $onet.adsFound[$key] = 0
}

function adsRes ($val)
{
  if ("003:" == $val.substring (0, 4))
  {
    $val = $val.substring (4)
    var $rval = "";
    var $i = $val.length;
    while ($i > 0)
      $rval += $val.substring ((--$i), $i+1)
    $val = $rval
    eval ($val)
    $val = "<script language=javascript><!--\n"+
      "  // "+ $onet.csrbase + $onet.csrver +"\n"+
      $val +
      "//--></script>"
  }
  else
  {
    document.write ($val)
  }

  if (! $onet.adsResult["stats-head"])
    $onet.adsResult["stats-head"] = ""
  $onet.adsResult["stats-head"] += $val
}

function adsXtra ($val)
{
  location.href = "/index-xtra.html?"+ $val
}

function adsGet ($key)
{
  if (!$onet.adsResult[$key])
    return ""

  $onet.adsFound[$key] = 1
  return $onet.adsResult[$key]
}

function adsCheck ($pt)
{
  if ("check" == $pt)
  {
    if (! $onet.adspt)
      $onet.adsError ('warning', 'nieudany include '+ $onet.csrbase + $onet.csrver, ($onet.adsResult["stats-head"] ? $onet.adsResult["stats-head"] : "-empty-"))
    else if ("ok" != $onet.adspt)
      $onet.adsError ('error', 'blad '+ $onet.csrbase + $onet.csrver +' ('+ $onet.adspt +')', "")
    $onet.adspt = $pt
    var $missed = ""
    for (var $key in $onet.adsFound)
    {
      if ($onet.adsFound[$key])
        continue
      $missed += $onet.adsResult[$key]
      $onet.adsError ('error', "brak slotu '"+ $key +"'", "")
    }
    if ($missed)
    {
      $onet.adsResult["stats-magic"] = '<div id=onet-ad-stats-magic style="position: absolute; top: 0; left: 0; visibility: hidden">'+ $missed +'</div>'
      document.write ($onet.adsResult["stats-magic"])
    }
    onet ('onPageLoad', '$onet.adsCheck("final")')
  }
  else if ("final" == $pt)
  {
    if (window.document.getElementById && window.document.getElementsByTagName)
    {
      var $el = window.document.getElementById ('onet-ad-stats-magic')
      if ($el)
      {
        var $body = (window.document.getElementsByTagName ('body'))[0]
        $body.style.marginTop = $el.offsetHeight + 4
        $el.style.visibility = 'visible'
      }
    }
  }
  else
  {
    if ($onet.adspt)
      $onet.adsError ('warning', 'blad log. '+ $onet.csrbase + $onet.csrver +' ('+ $onet.adspt +' => '+ $pt +')', "")
    $onet.adspt = $pt
  }
}

function adsError ($type, $msg, $dbg)
{
  if (! $onet.errimg)
    $onet.errimg = new Array ()
  var $img = new Image ()
  $img.src = $onet.csrbase +"/kropka/0?"+
    "s=a" +
    "&p="+ $onet.pgid +
    "&t="+ (new Date()).getTime() +
    "&w="+ $type +
    "&m="+ urlEncode ($msg) +
    "&u="+ urlEncode ($onet.lhref) +
    "&d="+ urlEncode ($dbg)
  $onet.errimg[$onet.errimg.length] = $img
  if (! window.fac424a6d2ff31fed70c79e47db5b406) return
  fac424a6d2ff31fed70c79e47db5b406 ('csrerr', $type +": "+ $msg)
}

function test ()
{
  var $msg = ""
  for (var $i = 0; $i < arguments.length; ++ $i)
    $msg += $i +": "+ arguments[$i] +"\n";
  alert ($msg);
}

//==== onetApp CONSTRUCTOR

function construct ()
{
  $onet.onPgLdCode = ''
  $onet.onStAvCode = ''
  $onet.unFrame = 1
  $onet.sttn = 0
  $onet.statn = 0
  $onet.statd = ''
  $onet.adsResult = new Array ()
  $onet.adsFound = new Array ()
  $onet.adsData = new Array ()

  $onet.now   = (new Date()).getTime()
  $onet.curid = decToHex (Math.floor (Math.random() * 0x7ffff), 5) +
    decToHex (Math.floor ($onet.now / 1000), 8) +
    decToHex (Math.floor ($onet.now % 1000), 3)
  $onet.iev   = igetIEVer ()

  $onet.lhref = ''
  $onet.dref  = ''
  var $onerror = window.onerror
  window.onerror = nullErrorHandler
  $onet.lhref = location.href
  $onet.dref  = document.referrer
  window.onerror = $onerror

  if ('undefined' != typeof (document.cookie))
  {
    var $offset = document.cookie.indexOf ("onet_uid=")
    if ($offset >= 0)
    {
      $offset = document.cookie.indexOf ("=", $offset) + 1
      var $endstr = document.cookie.indexOf (";", $offset)
      if ($endstr == -1) $endstr = document.cookie.length
      $onet.zuoIsl = 1
      $onet.zuoUid = document.cookie.substring ($offset, $endstr)
    }
    else
    {
      $offset = document.cookie.indexOf ("onetzuo_ticket=")
      if ($offset >= 0)
      {
        $offset += 15
  
        var $zuoUid = zuoStr ($offset+47*2)
        if ("" != $zuoUid)
        {
          $onet.zuo = 1
          $onet.zuoUid = $zuoUid
          $onet.zuoMbx = zuoStr ($offset+(47+1+hexToDec (document.cookie.substr ($offset+47*2, 1*2)))*2)
    
          var $exp = 1000 * hexToDec (document.cookie.substr ($offset+38*2, 4*2));
          var $isl = $exp - $onet.now
          $onet.zuoIsl = $isl > 0 ? $isl : 0
        }
      }
    }
  }

  $idx = $onet.lhref.indexOf ("/index-xtra.html?")
  if ($idx >= 0)
    $onet.adsRes ("<script language=javascript><!--\n" +
      "  onet('set','adid','"+ $onet.lhref.substring ($idx+17) +"')\n" +
      "//--></script>")

  onload = $onet.pageLoadHook;
}

if (! this.ok)
{
  eval (protoCode ('onetApp',
    'construct',
    'onPageLoad',
    'onStreamAvail',
    'streamCheck',
    'streamOK',
    'pageLoadHook',
    'usingFrames',
    'logoutLink',
    'loginSwitch',
    'getInfo1',
    'getInfoG',
    'getIEVer',
    'isIE',
    'statError',
    'statKLoad',
    'statGFunc',
    'statGLoad',
    'statGFinal',
    'set',
    'get',
    'clickIt',
    'dvError',
    'adsReq',
    'adsRes',
    'adsSet',
    'adsGet',
    'adsXtra',
    'adsCheck',
    'adsError',
    'test'
  ));
}

//==== onetApp END

}

//==== onetApp ACCESSOR

function onet ()
{
  if (! $onet)
  {
    $onet = new onetApp ()
    $onet.construct ()
  }

  var $alen = arguments.length;
  if (! $alen)
    return $onet_version;

  if (! $onet[arguments[0]])
  {
    var $msg = "no such function onet('"+ arguments[0] +"'"
    for (var $i = 1; $i < $alen; ++ $i)
      $msg += ", '"+ arguments[$i] +"'"
    $msg += ")"
    $onet.dvError ($msg.replace (/</g, "&lt;"))
    return ""
  }

  var $call = 'call' +'@'+ $alen
  if (! $onet[$call] && $onet[arguments[0]])
  {
    var $code = 'return $onet[$args[0]] ( '
    for (var $i = 1; $i < $alen; ++ $i)
    {
      $code += '$args['+ $i +']'
      if ($i + 1 < $alen) $code += ','
    }
    $code += ' )'
    $onet[$call] = new Function ("$args", $code);
  }

  if ($onet[$call])
    return $onet[$call] (arguments)
  else
    return ""
}

