var BrowserDetect = {
  init: function () {
    this.browser = this.searchString(this.dataBrowser) || "unknown";
    this.version = ' '+this.searchVersion(navigator.userAgent)
      || ' '+this.searchVersion(navigator.appVersion)
      || '';
    this.OS = this.searchString(this.dataOS) || "unknown";
  },
  searchString: function (data) {
    for (var i=0;i<data.length;i++) {
      var dataString = data[i].string;
      var dataProp = data[i].prop;
      this.versionSearchString = data[i].versionSearch || data[i].identity;
      if (dataString) {
        if (dataString.indexOf(data[i].subString) != -1)
          return data[i].identity;
      }
      else if (dataProp)
        return data[i].identity;
    }
  },
  searchVersion: function (dataString) {
    var index = dataString.indexOf(this.versionSearchString);
    if (index == -1) return;
    return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
  },
  dataBrowser: [
    {   string: navigator.userAgent,
      subString: "OmniWeb",
      versionSearch: "OmniWeb/",
      identity: "OmniWeb"
    },
    {
      string: navigator.userAgent,
      subString: "Chrome",
      identity: "Google Chrome",
      versionSearch: "Chrome"
    },
    {
      string: navigator.vendor,
      subString: "Apple",
      identity: "Safari"
    },
    {
      prop: window.opera,
      identity: "Opera"
    },
    {
      string: navigator.vendor,
      subString: "iCab",
      identity: "iCab"
    },
    {
      string: navigator.vendor,
      subString: "KDE",
      identity: "Konqueror"
    },
    {
      string: navigator.userAgent,
      subString: "Firefox",
      identity: "Firefox"
    },
    {
      string: navigator.vendor,
      subString: "Camino",
      identity: "Camino"
    },
    {
      string: navigator.userAgent,
      subString: "Netscape",
      identity: "Netscape"
    },
    {
      string: navigator.userAgent,
      subString: "MSIE",
      identity: "Explorer",
      versionSearch: "MSIE"
    },
    {
      string: navigator.userAgent,
      subString: "Gecko",
      identity: "Mozilla",
      versionSearch: "rv"
    },
    {
      string: navigator.userAgent,
      subString: "Mozilla",
      identity: "Netscape",
      versionSearch: "Mozilla"
    }
  ],
  dataOS : [
    {
      string: navigator.platform,
      subString: "Win",
      identity: "Windows"
    },
    {
      string: navigator.platform,
      subString: "Mac",
      identity: "Mac"
    },
    {
      string: navigator.platform,
      subString: "Linux",
      identity: "Linux"
    }
  ]

};
BrowserDetect.init();
function GetCookiesStatus(){
  return (navigator.cookieEnabled)?1:0;
}
function GetJavaStatus(){
  return (navigator.javaEnabled())?1:0;
}
function GetResolution(){
  return screen.width + 'x' + screen.height;
}
function GetColorDepth(){
  return screen.colorDepth;
}
function GetTimeZone(){
  var d = new Date();
  return -(d.getTimezoneOffset()/60);
}
function getHost(){
  if(! (location && location.protocol && location.host && /https?:/.test(location.protocol)) ){
    return 'localhost';
  }
  var host = location.host.replace(/^www\./i, '');
  host = host.replace(/:\d+$/, '');
  host = host.replace(/^\./, '');
  host = host.replace(/\.$/, '');
  host = host.replace(/[^a-zA-Z0-9\.\-]+/g, '');
  return host ? host : 'localhost';
}
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
function eraseCookie(name) {
  createCookie(name,"",-1);
}
function OnIgnoreMe(){
  var arDivs = [];
  ar = document.getElementsByTagName("div");
  var r_div=/^(WG_LT_IM_t_)\d*$/i
  for (i=0;i<ar.length;i++){
    if (r_div.test(ar[i].id)){
      arDivs.push(ar[i]);
    }
  }
  if (GetCookiesStatus()==1){
    s_cookie = readCookie("WG_IM_C");
    if (s_cookie == WG_id){
      eraseCookie("WG_IM_C");
      for (i=0;i<arDivs.length;i++){
        document.getElementById(arDivs[i].id).innerHTML=WG_LT_IM_1;
      }
    }else{
      createCookie("WG_IM_C", WG_id, 365);
      for (i=0;i<arDivs.length;i++){
        document.getElementById(arDivs[i].id).innerHTML=WG_LT_IM_0;
      }
    }
  } else {
    alert(WG_LT_IM_err);
  }
}
function SetInoreMe(){
  var arDivs = [];
  ar = document.getElementsByTagName("div");
  var r_div=/^(WG_LT_IM_t_)\d*$/i
  for (i=0;i<ar.length;i++){
    if (r_div.test(ar[i].id)){
      arDivs.push(ar[i]);
    }
  }
  if (GetCookiesStatus()==1){
    s_cookie = readCookie("WG_IM_C");
    if (s_cookie == WG_id){
      for (i=0;i<arDivs.length;i++){
        arDivs[i].innerHTML=WG_LT_IM_0;
      }
    }else{
      for (i=0;i<arDivs.length;i++){
        arDivs[i].innerHTML=WG_LT_IM_1;
      }
    }
  } else{
    for (i=0;i<arDivs.length;i++){
      arDivs[i].innerHTML=WG_LT_IM_1;
    }
  }
}
function isset(variable_name)
{
  try
  {
    if (typeof(eval(variable_name)) != 'undefined')
      if (eval(variable_name) != null)
        return true;
  } catch(e) {
  }
  return false;
}
function isInt(x) {
  var y=parseInt(x);
  if (isNaN(y)) return false;
  return x==y && x.toString()==y.toString();
 }
function ChangeUrl(id){
  window.location="http://widget-okiba.com/visitor/stats/id/"+id;
}
var Base64 = {
  _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
  encode : function (input) {
    var output = "";
    var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
    var i = 0;
    input = Base64._utf8_encode(input);
    while (i < input.length) {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);
      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;
      if (isNaN(chr2)) {
        enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
        enc4 = 64;
      }
      output = output +
      this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
      this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
    }
    return output;
  },
  decode : function (input) {
    var output = "";
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;
    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
    while (i < input.length) {
      enc1 = this._keyStr.indexOf(input.charAt(i++));
      enc2 = this._keyStr.indexOf(input.charAt(i++));
      enc3 = this._keyStr.indexOf(input.charAt(i++));
      enc4 = this._keyStr.indexOf(input.charAt(i++));
      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;
      output = output + String.fromCharCode(chr1);
      if (enc3 != 64) {
        output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
        output = output + String.fromCharCode(chr3);
      }
    }
    output = Base64._utf8_decode(output);
    return output;
  },
  _utf8_encode : function (string) {
    string = string.replace(/\r\n/g,"\n");
    var utftext = "";
    for (var n = 0; n < string.length; n++) {
      var c = string.charCodeAt(n);
      if (c < 128) {
        utftext += String.fromCharCode(c);
      }
      else if((c > 127) && (c < 2048)) {
        utftext += String.fromCharCode((c >> 6) | 192);
        utftext += String.fromCharCode((c & 63) | 128);
      }
      else {
        utftext += String.fromCharCode((c >> 12) | 224);
        utftext += String.fromCharCode(((c >> 6) & 63) | 128);
        utftext += String.fromCharCode((c & 63) | 128);
      }
    }
    return utftext;
  },
  _utf8_decode : function (utftext) {
    var string = "";
    var i = 0;
    var c = c1 = c2 = 0;
    while ( i < utftext.length ) {
      c = utftext.charCodeAt(i);
      if (c < 128) {
        string += String.fromCharCode(c);
        i++;
      }
      else if((c > 191) && (c < 224)) {
        c2 = utftext.charCodeAt(i+1);
        string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
        i += 2;
      }
      else {
        c2 = utftext.charCodeAt(i+1);
        c3 = utftext.charCodeAt(i+2);
        string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
        i += 3;
      }
    }
    return string;
  }
}
function MyEncode(strEncode){
  return ((((encodeURIComponent(strEncode)).replace(/\./g,"%252E")).replace(/%3A/g, "%253A")).replace(/%2F/g,"%252F"));
}
function GetEl(s_el){
  return document.getElementById(s_el);
}
function pause(ms)
{
  var date = new Date();
  var curDate = null;
  do { curDate = new Date(); }
  while(curDate-date < ms);
}
function EDec(str) {
  var ta=document.createElement("textarea");
  ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
  return ta.value;
}
function HandleAClick(aObj, evt){
  evt = evt || window.event;
  var shref = aObj.href;
  var linkText = aObj.innerHTML ? EDec(aObj.innerHTML.replace(/<[^>]+>/g, '')) : '';
  linkText = linkText.replace(/[\s\r\n\t]+/g, ' ');
  var img = document.createElement('IMG');
  img.width = '1';
  img.height = '1';
  s_WG_ip=(isset('WG_ip'))?WG_ip:'';
  s_WG_ignore= (WG_cnt>0)?'ignore':'';
  s_WG_ignore_cook = (GetCookiesStatus()==1)?((readCookie("WG_IM_C")==WG_id)?"ignore":''):''
  img.src = 'http://widget-okiba.com/widget.php?wgtype=10'+
  '&id='+MyEncode(WG_id)+
  '&pageurl='+Base64.encode(location.href)+
  '&pagetitle='+MyEncode(document.title)+
  '&referer='+Base64.encode(document.referrer)+
  '&ip='+MyEncode((s_WG_ip.length==0)?'':s_WG_ip)+
  '&ignore='+MyEncode(s_WG_ignore)+
  '&ignorec='+MyEncode(s_WG_ignore_cook)+
  '&outreferer='+Base64.encode(shref)+
  '&outtitle='+MyEncode(linkText)+
  '&browser='+MyEncode(BrowserDetect.browser)+MyEncode(BrowserDetect.version)+
  '&os='+MyEncode(BrowserDetect.OS)+
  '&tz='+MyEncode(GetTimeZone())+
  '&cookies='+GetCookiesStatus()+
  '&java='+GetJavaStatus()+
  '&scres='+MyEncode(GetResolution())+
  '&scdeph='+MyEncode(GetColorDepth());
  document.body.appendChild(img);
  pause(500);
  return true;
}
function InstallATrack(a){
  if(typeof(a.onclick) == 'function'){
    return;
  } else {
    a.onclick = function(e){ return HandleAClick(this, e) };
  }
}
function urldecode_go(str){
  window.location = encodeURIComponent(str);
}
function ProcessLinks(){
  var arr = document.body.getElementsByTagName('A');
  for(var i = 0; i < arr.length; i++){
    if(/^(http:\/\/|\/)/.test(arr[i].href)){
      InstallATrack(arr[i]);
    }
  }
}
function SetupOnClick(){
  if(typeof(window['ClickTrkInst']) == 'undefined'){
    window['ClickTrkInst'] = true;
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
      window.onload = ProcessLinks;
    } else {
      window.onload = function() {
        ProcessLinks();
        oldonload();
      }
    }
  }
}
function GetRequestUrl(surl, stitle, wg){
  wgbc=(isset('WG_BC'))?WG_BC:'';
  wghc=(isset('WG_HC'))?WG_HC:'';
  wgtc=(isset('WG_TC'))?WG_TC:'';
  wglc=(isset('WG_LC'))?WG_LC:'';
  wgbrc=(isset('WG_BRC'))?WG_BRC:'';
  wgwdpx=(isset('WG_WDPX'))?WG_WDPX:'';
  subtype=(isset('WG_TP'))?WG_TP:0;
  subtype2=(isset('WG_TP2'))?WG_TP2:0;
  subtype3=(isset('WG_TP3'))?WG_TP3:0;
  subtype4=(isset('WG_TP4'))?WG_TP4:0;
  if (typeof surl == "undefined") surl='';
  WG_l_type = (typeof wg == "undefined")?WG_type:wg;
  if (typeof stitle == "undefined") stitle='';
  s_WG_ip=(isset('WG_ip'))?WG_ip:'';
  s_WG_ignore= (WG_cnt>0)?'ignore':'';
  s_WG_ignore_cook = (GetCookiesStatus()==1)?((readCookie("WG_IM_C")==WG_id)?"ignore":''):'';
  sCharset = (typeof document.characterSet=="undefined")?(document.charset):(document.characterSet);
  document.write("<div id='WG_"+ WG_cnt +"'></div>");
  return 'http://widget-okiba.com/widget.php?wgtype='+MyEncode(WG_l_type)+
  '&id='+MyEncode(WG_id)+
  '&pageurl='+Base64.encode(location.href)+
  '&pagetitle='+MyEncode(document.title)+
  '&referer='+Base64.encode(document.referrer)+
  '&ip='+MyEncode((s_WG_ip.length==0)?'':s_WG_ip)+
  '&ignore='+MyEncode(s_WG_ignore)+
  '&ignorec='+MyEncode(s_WG_ignore_cook)+
  '&outreferer='+MyEncode(surl)+
  '&outtitle='+MyEncode(stitle)+
  '&wgbc='+MyEncode(wgbc)+
  '&wghc='+MyEncode(wghc)+
  '&wgtc='+MyEncode(wgtc)+
  '&wglc='+MyEncode(wglc)+
  '&wgbrc='+MyEncode(wgbrc)+
  '&wgwdpx='+MyEncode(wgwdpx)+
  '&subtype='+MyEncode(subtype)+
  '&subtype2='+MyEncode(subtype2)+
  '&subtype3='+MyEncode(subtype3)+
  '&subtype4='+MyEncode(subtype4)+
  '&browser='+MyEncode(BrowserDetect.browser)+MyEncode(BrowserDetect.version)+
  '&os='+MyEncode(BrowserDetect.OS)+
  '&tz='+MyEncode(GetTimeZone())+
  '&cookies='+GetCookiesStatus()+
  '&java='+GetJavaStatus()+
  '&scres='+MyEncode(GetResolution())+
  '&scdeph='+MyEncode(GetColorDepth())+
  '&wgdiv='+MyEncode(WG_cnt)+
  '&cp='+MyEncode(sCharset);
}
if (isset('WG_id') && isset('WG_type') && isInt(WG_id) && isInt(WG_type)) {
  if (isset('WG_cnt'))
    WG_cnt += 1;
  else
    WG_cnt = 0;
  SetupOnClick();
  document.write('<script type="text/javascript" src="' + GetRequestUrl()+ '"></script>');
}