/*
  sst7.js 1.0.1 para simplestats.altavoz.net
  uso:
  sst7('site','aid','path','tit','tipo');
  Ej:
  sst7('terrado','-','Inicio','Portada Principal','por');

*/

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();
  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,'');
  url  = url.replace(/\?.*$/,''); // 1.10
  var ran = (1 + Math.floor (Math.random() * 100000));

  var sst7_url_source="http://simplestats.altavoz.net/sst7.sst?site="+site+"&path="+path+"&aid="+aid+"&tipo="+tipo+"&tit="+tit+"&url="+url;
  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,'/');
  // tagCertifica(999999,path);

}; // sst7

