/*
  sst7.js 1.9 - 24/07/2009
  Funciona junto con certifica_2010.js

  uso:
  sst7('site','aid','path','tit','tipo');
  sst7_click(aid,path,tit,tipo);
  sst7_reload();
  sst7_minutos();
  sst7_lomas(site,tit,tipo,url);
  sst7_jq(site,aid,path,tit,tipo);
  sst7_jq_lomas(site,tit,tipo,url);
  sst7_encodetext(texto);
*/

function sst7(site,aid,path,tit,tipo) {
  if (site == null) site = '-';
  if (aid == null)  aid = '-';
  if (path == null) path = '-';
  if (tit == null)  tit = '-';
  if (tipo == null) tipo = '-';
  // Todo a lowercase.
  site = site.toLowerCase();
  aid = aid.toLowerCase();
  tipo = tipo.toLowerCase();
  // Elimina caracteres no permitidos.
  site = site.replace(/[^0-9a-z\_\-]/g,'');
  aid  = aid.replace(/[^0-9a-z]/g,'');
  path = sst7_encodetext(path);
  tit  = escape(tit);
  tipo = tipo.replace(/[^a-z]/g,'');
  // Corrige strings.
  path = path.replace(/;;/g, ';');
  // Detecta el URL de la pagina.
  url  = document.location+'';
  url  = url.replace(/[\<\>\%]/g,'');
  var ran = (1 + Math.floor (Math.random() * 100000));
  var sst7_url_source="/sst7.sst?site="+site+"&path="+path+"&aid="+aid+"&tipo="+tipo+"&tit="+tit+"&url="+url+"&ran="+ran;
  document.writeln("<img height=\"1\" width=\"1\" src=\"" + sst7_url_source + "\" name=\"sst7_img\" alt=\"SimpleStats\">");
  // Descomentar y adaptar si se integrara Certifica aqui.
  path = path.replace(/;/g,'/');
  var idCert = sst7_getIdCertifica();
  tagCertifica(idCert,path);
}; // sst7

function sst7_reload() {
  var src = document.images['sst7_img'].src;
  var ran = (1 + Math.floor (Math.random() * 100000));
  var found = src.match(/path=([^&]*)/);
  var path = found[1];
  src = src.replace(/ran=[0-9]*/,'ran='+ran);
  document.images['sst7_img'].src = src;
  // Descomentar y adaptar si se integrara Certifica aqui.
  path = path.replace(/;/g,'/');
  var idCert = sst7_getIdCertifica();
  cert_registerHit(idCert,path,'cert_JLPivot');
}; // sst7_reload

function sst7_minutos() {
  sst7_reload();
  setTimeout('sst7_minutos()',60000);
};

function sst7_click(aid,path,tit,tipo) {
  var src;
  if(document.images['sst7_img']) {
    src = document.images['sst7_img'].src;
  } else {
    // Si es que la imagen aún no se ha creado
    return;
  };
  if ((path != null) && (path != 'undefined') && (path != '')) {
    path = path.replace(/;;/g, ';');
    path = sst7_encodetext(path);
    src = src.replace(/path=[^&#]*/,'path='+path);
  };
  if ((tipo != null) && (tipo != 'undefined') && (tipo != '')) {
    tipo = tipo.toLowerCase();
    tipo = tipo.replace(/[^a-z]/g,'');
    src = src.replace(/tipo=[^&#]*/,'tipo='+tipo);
  };
  if ((aid != null) && (aid != 'undefined') && (aid != '')) {
    aid = aid.toLowerCase();
    aid  = aid.replace(/[^0-9a-z]/g,'');
    src = src.replace(/aid=[^&#]*/,'aid='+aid);
  };
  if ((tit != null) && (tit != 'undefined') && (tit != '')) {
    tit  = escape(tit);
    src = src.replace(/tit=[^&#]*/,'tit='+tit);
  };
  var ran = (1 + Math.floor (Math.random() * 10000));
  src = src.replace(/ran=[0-9]*/,'ran='+ran);
  document.images['sst7_img'].src = src;

  // Descomentar y adaptar si se integrara Certifica aqui.
  path = path.replace(/;/g,'/');
  var idCert = sst7_getIdCertifica();
  cert_registerHit(idCert,path,'cert_JLPivot');
}; // sst7_click

function sst7_lomas(site,tit,tipo,url) {
  var src = '';
  if(document.images['sst7_lm']) {
    src = document.images['sst7_lm'].src;
  } else {
    // Si es que la imagen aun no se ha creado
    // return true;
  };
  if ((tipo != null) && (tipo != 'undefined') && (tipo != '')) {
    tipo = tipo.toLowerCase();
    tipo = tipo.replace(/[^a-z]/g,'');
    src = src.replace(/tipo=[^&#]*/,'tipo='+tipo);
  }else{
    return true;
  };
  if ((tit != null) && (tit != 'undefined') && (tit != '')) {
    tit  = unescape(tit); // Por si viene ya escapeado.
    tit  = escape(tit);
    src = src.replace(/tit=[^&#]*/,'tit='+tit);
  }else{
    return true;
  };
  if ((url != null) && (url != 'undefined') && (url != '')) {
    src = src.replace(/url=[^&#]*/,'url='+url);
  }else{
    return true;
  };
  var ran = (1 + Math.floor (Math.random() * 10000));
  src = src.replace(/ran=[0-9]*/,'ran='+ran);

  if(document.images['sst7_lm']) {
    document.images['sst7_lm'].src = src;
  }else{
    var sst7_lomas_source="/sstlm.sst?site="+site+"&tipo="+tipo+"&tit="+tit+"&url="+url+"&ran="+ran;
    document.writeln("<img height=\"1\" width=\"1\" src=\"" + sst7_lomas_source + "\" name=\"sst7_lm\" alt=\"Lo más\">");
  };
}; // sst7_lomas

function sst7_jq(site,aid,path,tit,tipo) {
  if (site == null) { site = '-'; };
  if (aid == null)  { aid = '-'; };
  if (path == null) { path = '-'; };
  if (tit == null)  { tit = '-'; };
  if (tipo == null) { tipo = '-'; };

  // Todo a lowercase.
  site = site.toLowerCase();
  aid = aid.toLowerCase();
  tipo = tipo.toLowerCase();

  // Elimina caracteres no permitidos.
  site = site.replace(/[^0-9a-z\_\-]/g,'');
  aid  = aid.replace(/[^0-9a-z]/g,'');
  path = sst7_encodetext(path);
  tit  = escape(tit);
  tipo = tipo.replace(/[^a-z]/g,'');
  // Corrige strings.
  path = path.replace(/;;/g, ';');
  // Detecta el URL de la pagina.
  url  = document.location+'';
  url  = url.replace(/[\<\>\%]/g,'');
  var ran = (1 + Math.floor (Math.random() * 100000));
  var sst7_url_source="/sst7.sst?site="+site+"&path="+path+"&aid="+aid+"&tipo="+tipo+"&tit="+tit+"&url="+url+"&ran="+ran;
  if($("img[name='sst7_img']").size() == 1) {
    $("img[name='sst7_img']:first").attr('src', sst7_url_source);
  } else {
    $("body").append("<img height=\"1\" width=\"1\" src=\"" + sst7_url_source + "\" name=\"sst7_img\" alt=\"SimpleStats\" />");
  };
  // Descomentar y adaptar si se integrara Certifica aqui.
  path = path.replace(/;/g,'/');
  var idCert = sst7_getIdCertifica();
  sURL = cert_getURL(idCert, path);
  if($("img[name='sst7_cert']").size() == 1) {
    $("img[name='sst7_cert']:first").attr('src', sURL);
  } else {
    $("body").append("<img height=\"1\" width=\"1\" src=\"" + sURL + "\" name=\"sst7_cert\" alt=\"Certifica.com\" />");
  };
}; // sst7_jq

function sst7_jq_lomas(site,tit,tipo,url) {
  var src = '';
  if(document.images['sst7_lm']) {
    src = document.images['sst7_lm'].src;
  } else {
    // Si es que la imagen aun no se ha creado
    // return true;
  };
  if ((tipo != null) && (tipo != 'undefined') && (tipo != '')) {
    tipo = tipo.toLowerCase();
    tipo = tipo.replace(/[^a-z]/g,'');
    src = src.replace(/tipo=[^&#]*/,'tipo='+tipo);
  }else{
    return true;
  };
  if ((tit != null) && (tit != 'undefined') && (tit != '')) {
    tit  = unescape(tit); // Por si viene ya escapeado.
    tit  = escape(tit);
    src = src.replace(/tit=[^&#]*/,'tit='+tit);
  }else{
    return true;
  };
  if ((url != null) && (url != 'undefined') && (url != '')) {
    src = src.replace(/url=[^&#]*/,'url='+url);
  }else{
    return true;
  };
  var ran = (1 + Math.floor (Math.random() * 10000));
  src = src.replace(/ran=[0-9]*/,'ran='+ran);
  var sst7_lomas_source="/sstlm.sst?site="+site+"&tipo="+tipo+"&tit="+tit+"&url="+url+"&ran="+ran;
  if($("img[name='sst7_lm']").size() == 1) {
    $("img[name='sst7_lm']:first").attr('src', sst7_lomas_source);
  } else {
    $("body").append("<img height=\"1\" width=\"1\" src=\"" + sst7_lomas_source + "\" name=\"sst7_lm\" alt=\"SimpleStats\" />");
  };
}; // sst7_jq_lomas

function sst7_encodetext(texto) {
  var txt = texto;
  txt = txt.replace(/Á/g,'A');
  txt = txt.replace(/É/g,'E');
  txt = txt.replace(/Í/g,'I');
  txt = txt.replace(/Ó/g,'O');
  txt = txt.replace(/Ú/g,'U');
  txt = txt.replace(/á/g,'a');
  txt = txt.replace(/é/g,'e');
  txt = txt.replace(/í/g,'i');
  txt = txt.replace(/ó/g,'o');
  txt = txt.replace(/ú/g,'u');
  txt = txt.replace(/Ñ/g,'N');
  txt = txt.replace(/ñ/g,'n');
  txt = txt.replace(/Ü/g,'U');
  txt = txt.replace(/ü/g,'u');
  txt = txt.replace(/á/g,'a');
  txt = txt.replace(/&[a-zA-Z]+;/g,'');
  txt = txt.replace(/[^0-9a-zA-Z;\_\- ]/g,'');
  txt = txt.replace(/ /g,'_');
  return txt;
}; // sst7_encodetext

function sst7_getIdCertifica() {
    var thehost = window.location.host;
    if(thehost.indexOf('triunfo.cl') >= 0) {
        return 23289;
    };
    return 105989;
};