
// Distinci� de los navegadores
 
mozilla = (document.getElementById)? true:false; 
netscape = (document.layers)? true:false ; 
explorer = (document.all)? true:false; 

// Ocultar capas

function ocultarCapa(idElemento){
	if (netscape) elemento = document.layers[idElemento].visibility = "hide";
	else if (explorer) elemento = document.all(idElemento).style.visibility = "hidden";
	else if (mozilla) elemento = document.getElementById(idElemento).style.visibility = "hidden";
	}
	
// Ver capas

function verCapa(idElemento){
	if (netscape) elemento = document.layers[idElemento].visibility = "show";
	else if (explorer) elemento = document.all(idElemento).style.visibility = "visible";
	else if (mozilla) elemento = document.getElementById(idElemento).style.visibility = "visible";
	}

// Crea una pagina nueva con la imagen que se da como argumento 
 
function crearPagina(imagenVer,ancho,alto){ 

ventana = window.open(imagenVer,imagenVer,"menubar=no, width=" + (ancho + 30) +", height="+ (alto + 30) + ", scrollbars=no"); 

// ventana.document.write("<html><head><title>Imagen</title>");
//ventana.document.write("</head>");
//ventana.document.write("<body style='background-color=\"#003333\"'>");
//ventana.document.write("<div align='center' id='contenido'>");
//ventana.document.write("<img src='" + imagenVer + "' width='" + ancho + "' height='" + alto + "' border=1 hspace=5 vspace=5></div>");
//ventana.document.write("</body></html>");


}
// Script para ver mapa de carreteras

function verMapaExterno(pobla)
{
var w = 800, h = 600;
if (document.all || document.layers) {
   w = screen.availWidth;
   h = screen.availHeight;
}

var popW = 799, popH = 559;
var leftPos = (w-popW)/2, topPos = (h-popH)/2;

//window.open('page,html','popup','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);

var mapaurl="http://www.campsa.com/esp/infinito/gcampsa/localizador/localidades/informacion/resolv_nbe.asp?Opc=IBL&Nivel=60&Local="+escape(pobla);
window.open(mapaurl,'mapapop','scrollbars=1,width='+popW+',height='+popH+',left='+leftPos+',top='+topPos+',toolbar=yes,menubar=no,personalbar=no,resizable=yes');return false;
}

function verCalculoRuta(origen,destino)
{
if (origen == '')
    alert('Debe indicar un origen para calcular la ruta');
else {
var w = 800, h = 600;
if (document.all || document.layers) {
   w = screen.availWidth;
   h = screen.availHeight;
}

var popW = 799, popH = 559;
var leftPos = (w-popW)/2, topPos = (h-popH)/2;
var maparuta="http://www.campsa.com/esp/infinito/gcampsa/ruta/calcular/resolv_iti.asp?origen="+escape(origen)+"&destino="+escape(destino)+"&local1=&local2=&local3=&via=R&eess=E&Nivel=200";
window.open(maparuta,'mapapop','scrollbars=1,width='+popW+',height='+popH+',left='+leftPos+',top='+topPos+',toolbar=yes,menubar=no,personalbar=no,resizable=yes');

}

return false;

}

function activar(idElemento){
	if (mozilla) {
		elemento = document.getElementById(idElemento).style;
		elemento.color = "#000";
		elemento.background = "#CCCCCC";
		}
	}
function desactivar(idElemento){
	if (mozilla) {
		elemento = document.getElementById(idElemento).style;
		elemento.color = "#CCCCCC";
		elemento.background = "black";		
		}
	}
 
function enconstruccion(x) {
	if (x=="1") {alert("Disculpeu, aquesta part encare esta en construcci�");}
	if (x=="2") {alert("Sorry, this part is pended.");}
	if (x=="3") {alert("Sorry, this part is pended.");}
	if (x=="4") {alert("Sorry, this part is pended.");}
	}

function verTexto(Idioma) {
	ocultarTexto();

	if (Idioma == "castellano") {
	
		if (explorer) document.all("textoCastellano").style.visibility = "visible" ;
		else if (mozilla) document.getElementById("textoCastellano").style.visibility = "visible" ;
	}
	
	if (Idioma == "frances") {
	
		if (explorer) document.all("textoFrances").style.visibility = "visible" ;
		else if (mozilla) document.getElementById("textoFrances").style.visibility = "visible" ;
	}
	if (Idioma == "aleman") {
	
		if (explorer) document.all("textoAleman").style.visibility = "visible" ;
		else if (mozilla) document.getElementById("textoAleman").style.visibility = "visible" ;
	}
	if (Idioma == "catalan") {
	
		if (explorer) document.all("textoCatalan").style.visibility = "visible" ;
		else if (mozilla) document.getElementById("textoCatalan").style.visibility = "visible" ;
	}
	if (Idioma == "ingles") {
	
		if (explorer) document.all("textoIngles").style.visibility = "visible" ;
		else if (mozilla) document.getElementById("textoIngles").style.visibility = "visible" ;
	}
}
function ocultarTexto() {

	if (explorer) {
		document.all("textoCastellano").style.visibility = "hidden" ;
		document.all("textoFrances").style.visibility = "hidden" ;
		document.all("textoAleman").style.visibility = "hidden" ;
		document.all("textoCatalan").style.visibility = "hidden" ;
		document.all("textoIngles").style.visibility = "hidden" ;
		}
	              
	else if (mozilla) { 
		document.getElementById("textoCastellano").style.visibility = "hidden" ;
		document.getElementById("textoFrances").style.visibility = "hidden" ;
		document.getElementById("textoAleman").style.visibility = "hidden" ;
		document.getElementById("textoCatalan").style.visibility = "hidden" ;
		document.getElementById("textoIngles").style.visibility = "hidden" ;
		}
	}
	

// toggle visibility

function toggle( targetId ){
  if (document.getElementById){
  		target = document.getElementById( targetId );
  			if (target.style.display == "none"){
  				target.style.display = "";
  			} else {
  				target.style.display = "none";
  			}
  	}
}


// swap images


function newImage(arg) {
     if (document.images) {
          rslt = new Image();
          rslt.src = arg;
          return rslt;
     }
}

function changeImages() {
     if (document.images && (preloadFlag == true)) {
          for (var i=0; i<changeImages.arguments.length; i+=2) {
               document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
          }
     }
}

var preloadFlag = false;

function preloadImages() {
     if (document.images) {

        ojoAnimado = newImage("i/ojoAnimado.gif");
		ojoMamedu= newImage("i/ojoMamedu.gif");
        preloadFlag = true;
     }
}

// switch styles

function setActiveStyleSheet(title) {
  var i, a, main;
  for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("rel") &&
        a.getAttribute("rel").indexOf("style") != -1 &&
        a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("rel") &&
        a.getAttribute("rel").indexOf("style") != -1 &&
        a.getAttribute("title") &&
        !a.disabled
        ) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("rel") &&
        a.getAttribute("rel").indexOf("style") != -1 &&
        a.getAttribute("rel").indexOf("alt") == -1 &&
        a.getAttribute("title")
        ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
