// JavaScript Document
//Author JP

function multivista_switch(lang) {

  if(lang=='esp')
	go_spanish();
  else if(lang=='eng')
	go_english();
  else {
	  go_spanish();
	  }
};


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

function go_spanish() {
  Set_Cookie('vista','','/');
  var url = document.URL;
  if (url.indexOf('/site/cache/nroedic/taxport') > 0) {
    // Caso taxonomia con cache.
    var indices = url.match(/\/(\d+)_(\d+)_(\d+)_(\d+)\./);
    // alert(indices[0] +' '+ indices[1] +' '+ indices[2] +' '+ indices[3] +' '+ indices[4]);
    for(i=1;i<=4;i++) {
      if (indices[i] == 0) { indices[i] = ''; };
    };
    self.location.href = '/cgi-bin/prontus_taxport_lista.cgi?_MV=&_REL_PATH_PRONTUS=/prontus_ctm'
                       + '&seccion=' + indices[1]
                       + '&tema=' + indices[2]
                       + '&subtema=' + indices[3]
                       + '&nropag=' + indices[4];
  }else if (url.indexOf('/cgi-bin/') > 0) {
    // Caso pagina dinamica vuelve a la home.
    self.location.href = '/prontus_ctm';
  }else{
    window.location.reload();
  };
}; // go_spanish

function go_english() {
  Set_Cookie('vista','eng','/');
  var url = document.URL;
  if (url.indexOf('/site/cache/nroedic/taxport') > 0) {
    // Caso taxonomia con cache.
    var indices = url.match(/\/(\d+)_(\d+)_(\d+)_(\d+)\./);
    // alert(indices[0] +' '+ indices[1] +' '+ indices[2] +' '+ indices[3] +' '+ indices[4]);
    self.location.href = '/cgi-bin/prontus_taxport_lista.cgi?_MV=eng&_REL_PATH_PRONTUS=/prontus_ctm'
                       + '&seccion=' + indices[1]
                       + '&tema=' + indices[2]
                       + '&subtema=' + indices[3]
                       + '&nropag=' + indices[4];
  }else if (url.indexOf('/cgi-bin/') > 0) {
    // Caso pagina dinamica vuelve a la home.
    self.location.href = '/prontus_ctm';
  }else{
    window.location.reload();
  };
}; // go_english


//Función utilizada para cambiar el formato de una fecha del tipo dd/mm/aaaa a mm/dd/aaaa
//Según el String lang, utilizado por el idioma devuelve la cadena en otro orden
function muestraFecha(lang,fecha) {
	  if(lang=='esp'){
 document.write(fecha);
 } else if(lang=='eng'){
	 trozos = fecha.split ("/");
 document.write(trozos[1]+'/'+trozos[0]+'/'+trozos[2]);
 }else {
 document.write(fecha);
	  }
};
