var sinoHeatLastIframe = -1;
var sinoHeatTime = 0;
var sinoHeatQuota = -1;
var sinoHeatBrowser = '';
var sinoHeatDocument = '';
var sinoHeatWait = 500;
var sinoHeatLocalWait = 0;
var sinoHeatHref = window.location.href == '' ? '' : encodeURIComponent(window.location.href);
function catchSinoHeat(e){
  try{
    if (sinoHeatQuota === 0) return true;
    if (e === undefined){
      e = window.event; c = e.button; element = e.srcElement;
    }else{
      c = e.which; element = null;
    }
    if (c === 0) return true;
    if (element !== null && element.tagName.toLowerCase() === 'iframe'){
      if (element.sourceIndex === sinoHeatLastIframe) return true;
      sinoHeatLastIframe = element.sourceIndex;
    }else{
      sinoHeatLastIframe = -1;
    }
    var x = e.clientX;
    var y = e.clientY;
    var w = sinoHeatDocument.clientWidth !== undefined ? sinoHeatDocument.clientWidth : window.innerWidth;
    var h = typeof(window.innerHeight) == 'undefined' ? sinoHeatDocument.clientHeight : window.innerHeight;
    var scrollx = window.pageXOffset === undefined ? sinoHeatDocument.scrollLeft : window.pageXOffset;
    var scrolly = window.pageYOffset === undefined ? sinoHeatDocument.scrollTop : window.pageYOffset;
    if (x > w || y > h) return true;
    clickTime = new Date();
    if (clickTime.getTime() - sinoHeatTime < 1000) return true;
    sinoHeatTime = clickTime.getTime();
    if (sinoHeatQuota > 0) sinoHeatQuota = sinoHeatQuota - 1;
    var sinoHeatImg = new Image();
    sinoHeatImg.src = sino_HeatServer+'?ucode='+(typeof sino_analyticstracker_ucode !== undefined ? sino_analyticstracker_ucode : 0)+'&h='+sinoHeatHref+'&x='+(x+scrollx)+'&y='+(y+scrolly)+'&w='+w+'&b='+sinoHeatBrowser+'&s='+screen.width+'x'+screen.height+'&c='+c+'&random='+Date();
    var now = new Date();
    sinoHeatLocalWait = now.getTime()+sinoHeatWait;
    while (sinoHeatLocalWait > now.getTime()) {
      now = new Date();
    }
  }
  catch(e){}
}
function initSinoHeat(){
  if (sino_HeatServer === '' || sinoHeatHref === '') return false;
  domain = window.location.href.match(/http:\/\/[^/]+\//);
  if (domain !== null && sino_HeatServer.substring(0, domain[0].length) === domain[0]){
    sino_HeatServer = sino_HeatServer.substring(domain[0].length - 1, sino_HeatServer.length);
  }
  if (document.addEventListener){
    document.addEventListener('mousedown', catchSinoHeat, false);
  }else if (document.attachEvent){
    document.attachEvent('onmousedown', catchSinoHeat);
  }
  iFrames = document.getElementsByTagName('iframe');
  for (i = 0; i < iFrames.length; i++){
    if (document.addEventListener){
      iFrames[i].addEventListener('focus', catchSinoHeat, false);
    }else if (document.attachEvent){
      iFrames[i].attachEvent('onfocus', catchSinoHeat);
    }
  }
  sinoHeatDocument = (document.documentElement !== undefined && document.documentElement.clientHeight !== 0) ? document.documentElement : document.body;
  var b = navigator.userAgent !== undefined ? navigator.userAgent.toLowerCase().replace(/-/g, '') : '';
  sinoHeatBrowser = b.replace(/iceweasel/, 'firefox').replace(/^.*(firefox|kmeleon|safari|msie|opera).*$/, '$1');
  if (b === sinoHeatBrowser || sinoHeatBrowser === '') sinoHeatBrowser = 'unknown';
}
initSinoHeat();