<!--DOCUMENT CONTENT_TYPE="text/javascript"  -->

DEFAULT_REFRESH_TIME = 600000;
REFRESH_LIMIT = 600000;
var cert_IsAutoRefresh = false;

/*
 * Funciones internas al script Certifica-IAB
 */
function cert_getFlashVersion()
{
	var flashVersion = -1;
	if (navigator.plugins && navigator.plugins.length) {
		var objFlash = navigator.plugins["Shockwave Flash"];
		if (objFlash) {
			if (objFlash.description) {
				flashDesc = objFlash.description;
				flashVersion = flashDesc.charAt(flashDesc.indexOf('.')-1);
			}
		}

		if (navigator.plugins["Shockwave Flash 2.0"]) {
			flashVersion = 2;
		}
	} else if (navigator.mimeTypes && navigator.mimeTypes.length) {
		x = navigator.mimeTypes['application/x-shockwave-flash'];
		if (x && x.enabledPlugin) {
			flashVersion = 0; // no detectada!
		}
	}

	/*@cc_on
	for(var i = 10; i > 0; i--) {
		try {
			var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
			flashVersion = i;
			break;
		} catch(e){}
	}	
	@*/
	return flashVersion;
}

function cert_setCookie(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 cert_getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function cert_deleteCookie(name, path, domain) {
  if (cert_getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function cert_RefreshInt()
{
  var now = new Date();

  cert_setCookie('autorefresh_time', now.getTime());
  location.reload();
}

function cert_IsAutoRefresh_func() {
    var now = new Date();
    var tsCookie = cert_getCookie('autorefresh_time');
  
    cert_deleteCookie('autorefresh_time');
  
    if (tsCookie) {
        var d = now.getTime() - tsCookie;
        if (d <= REFRESH_LIMIT) {
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
/*
 * Funciones PUBLICAS
 */

/*
 * cert_Refresh: permite hacer autorefresh de la pagina y cumplir con las normas
 *               fijadas por el IAB al respecto.
 *
 * iTime: tiempo en minutos en el cual se deberá hacer autorefresh
 *
 */
function cert_getReferrer()
{
   var referrer = document.referrer;
   if (self.cert_getReferrer14)
      return cert_getReferrer14();
/*@cc_on
  @if(@_jscript_version >= 5 )
   try { 
      if ( self != top ) referrer = top.document.referrer;
   } catch(e) {};
  @end
  @*/
  return referrer;
} 
 
function cert_Refresh( iTime ) {
  var refreshTime;
  refreshTime = ((iTime) ? iTime*60*1000 : DEFAULT_REFRESH_TIME);

  cert_IsAutoRefresh = cert_IsAutoRefresh_func();
  setTimeout( 'cert_RefreshInt()', refreshTime );
}

/*
 * tagCertificaIAB: permite registrar un pageview, y cumplir con las normas del IAB
 *                  en lo relativo a los autorefresh.
 *
 * isHome: Valor 1 o 0, para indicar si la pagina marcada es el home o no (1=Home).
 *
 */
function tagCertificaIAB(iSiteId, isHome) 
{
	  var size, colors, referrer, url;
    size = colors = referrer = 'otro';
    hr=escape(document.location);
    var now = new Date();
    var mustCount = true;
    var path;

    if (cert_IsAutoRefresh) {
        path = '/autorefresh';
        if (isHome) {
            var tsCookie = cert_getCookie('cert_hit_time');
            var d = now.getTime() - tsCookie;
            if (d < DEFAULT_REFRESH_TIME) {
                mustCount = false;
            }
        } else {
            mustCount = false;
        }
    } else {
       path = '/normal';
    }
    if (mustCount) {
       var url;
       if (isHome) {
           cert_setCookie('cert_hit_time', now.getTime());
           path = '/home' + path;
       } else {
           path = '/resto_sitio' + path;
       }
       if ( window.screen.width ) size = window.screen.width;
       if ( window.screen.colorDepth ) colors = window.screen.colorDepth;
       else if ( window.screen.pixelDepth ) colors = window.screen.pixelDepth;
       url = 
       'http://hits.e.cl/cert/hit.dll?sitio_id=' + iSiteId + '&path=' + path +
       '&referer=' + referrer + '&size=' + size + '&colors=' + colors;
    url += '&java=' + navigator.javaEnabled() + '&flash=' + cert_getFlashVersion();
       document.writeln( '<img src="' + url + '" width="1" height="1" border="0" alt="Certifica.com">' );
    }
}
// ::::::::::::: AGREGADO NUEVO

DEFAULT_PIVOT_NAME = 'cert_Pivot';
function cert_registerHit(iSiteId, sPath, sPivotName) 
{
   var sAppend = '&cert_cachebuster=' + (1 + Math.floor (Math.random() * 10000));
   if ( !sPivotName )
      sPivotName = DEFAULT_PIVOT_NAME;
   if ( document.images )
      if ( document.images[sPivotName] )
         document.images[sPivotName].src = cert_getTagCertifica(iSiteId, sPath, sAppend);
}

function cert_getTagCertifica(iSiteId, sPath, sAppend) 
{
    var size, colors, referrer, url;
    size = colors = referrer = 'otro';
    var o = cert_qVal('url_origen');
    if (o != null && o != '')
       referrer = o;
    else 
       referrer = escape(cert_getReferrer());
    if ( window.screen.width ) size = window.screen.width;
    if ( window.screen.colorDepth ) colors = window.screen.colorDepth;
    else if ( window.screen.pixelDepth ) colors = window.screen.pixelDepth;
    url = 
       'http://prima.certifica.com/cert/hit.dll?sitio_id=' + iSiteId + '&path=' + sPath +
       '&referer=' + referrer + '&size=' + size + '&colors=' + colors;
    url += '&java=' + navigator.javaEnabled();
    if (sAppend)
        url += sAppend;
    return url;    
}