/*
  sst7.js 1.10 - 25/03/2010
  uso:
  sst7('site','aid','path','tit','tipo');
  sst7_click(aid,path,tit,tipo);
  sst7_reload();
  sst7_minutos();
*/

var sst7_server_name = 'http://sst.df.cl';
if(location.protocol == 'https:') {
    sst7_server_name = '/sst';
};
var sst7_url_img_pivot = '/prontus_df/imag/auxi/b.gif';
var sst7_certifica_id = 9902;
var sst7_certifica_pivot = 'cert_Pivot';


// -----------------------------------------------------------------------------
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 = sst7_server_name+"/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\" />");

  // Se escribe el tag Pivote de Certifica para contar clicks
  sst7_write_certifica_pivot();

}; // 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,'/');
  // cert_registerHit(sst7_certifica_id, path, 'cert_Pivot');
}; // 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,'/');
  cert_registerHit(sst7_certifica_id,path);
}; // 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 = sst7_server_name+"/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\" />");
  };
}; // sst7_lomas
// -----------------------------------------------------------------------------
function sst7_lomas_coment() {
  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;
  };
  var tipo = 'com';
  var ran = (1 + Math.floor (Math.random() * 10000));

  // se cambia el tipo y el random
  src = src.replace(/tipo=[^&#]*/,'tipo='+tipo);
  src = src.replace(/ran=[^&#]*/,'ran='+ran);

  document.images['sst7_lm'].src = src;

}; // sst7_lomas

// -----------------------------------------------------------------------------
function sst7_write_certifica_pivot() {
  var sPivotName = sst7_certifica_pivot;
  if (document.getElementById(sPivotName))
    return;

  document.writeln("<img height=\"1\" width=\"1\" src=\"" + sst7_url_img_pivot + "\" id=\"" + sPivotName + "\" />");

}; // sst7_lomas



