/*
  sst7.js 1.1 - 17/07/2008
  uso:
  sst7('site','aid','path','tit','tipo');
  sst7_click(aid,path,tit,tipo);
  sst7_reload();
  sst7_minutos();
*/

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(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();
  // path = path.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() * 10000));

  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\">");

  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\">");

  path = path.replace(/;/g,'/');
  tagCertifica(105644,path);

}; // sst7

// sst7 alone.
function sst7a(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();
  // path = path.toLowerCase();
  tipo = tipo.toLowerCase();
  // Elimina caracteres no permitidos.
  site = site.replace(/[^0-9a-z\_\-]/g,'');
  aid  = aid.replace(/[^0-9a-z]/g,'');
  // path = path.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() * 10000));

  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\">");

  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\">");

  path = path.replace(/;/g,'/');

}; // sst7a


function sst7_reload() {
  var src = document.images['sst7_img'].src;
  var ran = (1 + Math.floor (Math.random() * 10000));
  var found = src.match(/path=([^&]*)/);
  var path = found[1];
  path = path.replace(/;/g,'/');
  src = src.replace(/ran=[0-9]*/,'ran='+ran);
  document.images['sst7_img'].src = src;
  cert_registerHit(105644,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;
  path = path.replace(/;/g,'/');
  cert_registerHit(105644,path,'cert_JLPivot');
}; // sst7_click

function sst7_lomas(tit,tipo,url) {
  var src;
  if(document.images['sst7_lm']) {
    src = document.images['sst7_lm'].src;
  } else {
    // Si es que la imagen aún 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  = 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);
  document.images['sst7_lm'].src = src;
}; // sst7_lomas

