// -----------------------------------------------
// setea una cookie con un determinado valor.
function Set_Cookie(name,value,path,expires,domain,secure) {
  document.cookie = name + "=" +escape(value) +
    ( (expires) ? ";expires=" + expires.toGMTString() : "") +
    ( (path) ? ";path=" + path : "") +
    ( (domain) ? ";domain=" + domain : "") +
    ( (secure) ? ";secure" : "");
}; // Set_Cookie


// -----------------------------------------------
// cambia a la vista español
function go_spanish() {
  Set_Cookie('vista','','/');
  var url = document.URL;
  if (url.indexOf('/site/cache/nroedic/taxport') > 0) {
    var urltotax = get_url(url, '');
    if(urltotax == '') {self.location.href = '/';}
    self.location.href = urltotax;

  } else if (url.indexOf('/cgi-bin/') > 0) {
    // Caso pagina dinamica vuelve a la home.
    self.location.href = '/';
  } else {
    window.location.reload();
  };
}; // go_spanish


// -----------------------------------------------
// cambia a la vista inglés
function go_english() {
  Set_Cookie('vista','en','/');
  var url = document.URL;
  if (url.indexOf('/site/cache/nroedic/taxport') > 0) {
    var urltotax = get_url(url, 'en');
    if(urltotax == '') {self.location.href = '/';}
    self.location.href = urltotax;

  }else if (url.indexOf('/cgi-bin/') > 0) {
    // Caso pagina dinamica vuelve a la home.
    self.location.href = '/';
  }else{
    window.location.reload();
  };
}; // go_english


// -----------------------------------------------
// obtiene la url a entregar
function get_url(url, vista) {

  var prontus = url.match(/(\/[a-zA-Z_0-9]+)\/site\//);
  if(prontus[1]=='' || prontus[1]==undefined) {
    return '';
  }
  var indices = url.match(/\/(\d+)_(\d+)_(\d+)_(\d+)\./);
  var urltotax = '/cgi-bin/prontus_taxport_lista.cgi?_MV='+vista+'&_REL_PATH_PRONTUS='+prontus[1];
  if(indices[1]>0) urltotax = urltotax + '&seccion=' + indices[1];
  if(indices[2]>0) urltotax = urltotax + '&tema=' + indices[2];
  if(indices[3]>0) urltotax = urltotax + '&subtema=' + indices[3];
  if(indices[4]>0) urltotax = urltotax + '&nropag=' + indices[4];
  return urltotax;
}

