var esie = false;
var esns = false;
var version = 0;
var elnav9= "";
if (document.all) {esie = true;docu="document.all.";styl=".style";}
if (document.layers) {esns = true;docu="document.";styl="";}
if (esie) {version = parseInt(navigator.appVersion)};

elnavegador=null;laversion=0;elnav9="";
elnavegador = navigator.appName;
laversion = parseInt(navigator.appVersion);

if (elnavegador == "Netscape" && laversion < 4) elnav9="NT3";
else if (elnavegador == "Microsoft Internet Explorer") elnav9 = "IE";
else if (elnavegador == "Netscape" && laversion > 3) elnav9 = "NT4";

// reload con netscape

function MM_reloadPage(init) {
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


// FUNCIONES



// mostrar capas

function mostrar (capac1) {
if (esie) {document.all.item(capac1).style.visibility = "inherit";}
if (esns) {
	frase = docu + capac1;
	frase = eval (frase);
	frase.visibility = "show";
	frase = "";
		}
}

// esconder capas
function esconder (capac1) {
if (esie) {document.all.item(capac1).style.visibility = "hidden";}
if (esns) {
	frase = docu + capac1;
	frase = eval (frase);
	frase.visibility = "hidden";
	frase = "";
	}
}

function abven33 (pag,w,h) {
ventana=window.open(pag,'himel','toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no,width='+ w + ',height=' + h);
}

function recolocar(capamov,diX,diY) {
if (esns) {
capa = eval ("document."+capamov);
capa.left = diX;
capa.top = diY;
}
if (esie) {
capa = eval ("document.all."+capamov);
capa.style.left = diX;
capa.style.top = diY;
}
return true;
}


// parametros: pagina, width, height, top, left
function abven (pag,w,h,t,l) {
posicion = "";
if (t!=null) {posicion = ',top=' + t + ',left=' + l};

strF = "window.open('"+ pag + "','himel','toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no,width=" + w + ",height=" + h + posicion + "')";
strV = "window.open('','himel','toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no,width=0,height=0')";

 if (elnav9 == "NT4" && window.whimel22){
      if (whimel22.name == "himel") whimel22.close();
 }
if (elnav9 == "IE"){
   if (window.whimel22){
     whimel22 = eval(strV);
     whimel22.close();
     setTimeout("whimel22 = eval(strF)",500);
   } 
   else whimel22 = eval(strF);
 }
 if(elnav9 != "IE") whimel22 = eval(strF);

}





// con barras de desplazamiento
// parametros: pagina, width, height, top, left
function abveninf (pag,w,h,t,l) {
posicion = "";
if (t!=null) {posicion = ',top=' + t + ',left=' + l};

strF = "window.open('"+ pag + "','himel','toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=yes,resizable=yes,width=" + w + ",height=" + h + posicion + "')";
strV = "window.open('','himel','toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=yes,resizable=yes,width=0,height=0')";

 if (elnav9 == "NT4" && window.whimel22){
      if (whimel22.name == "himel") whimel22.close();
 }
if (elnav9 == "IE"){
   if (window.whimel22){
     whimel22 = eval(strV);
     whimel22.close();
     setTimeout("whimel22 = eval(strF)",500);
   } 
   else whimel22 = eval(strF);
 }
 if(elnav9 != "IE") whimel22 = eval(strF);

}



function escribir(valor)
{
lafra = txtnavini + txtnav[valor] + txtnavfin;

    if (esie) {document.all.txtnav.innerHTML=lafra;}
	if (esns) {document.txtnav.document.open();document.txtnav.document.write (lafra);document.txtnav.document.close();}
}




function subire(capa){
param = eval ("'" + capa + "'");
if (abajo < limite) {
arriba = arriba + valcam;
abajo = abajo + valcam;
moveby (param,-valcam,0);

}
}

function bajare(capa){

param = eval ("'" + capa + "'");

if (arriba > 0) {
arriba = arriba - valcam;
abajo = abajo - valcam;

moveby (capa,valcam,0);


}
}

function subire2(){

if (carga2) {
mover = setInterval ('subire(\'crono\');',tiempo);

}
}

function bajare2(){

if (carga2) {
mover = setInterval ('bajare(\'crono\');',tiempo);
}
}

function parar(){
if (carga2) {
clearInterval (mover);
}
}



function moveby (lacapa,diX,diY){
capa = eval(docu + lacapa);
if (esns) {
capa.left = capa.left + diX;
capa.top = capa.top + diY;
}
if (esie) {
capa.style.left = capa.style.pixelLeft + diX;
capa.style.top = capa.style.pixelTop + diY;
}
return true;
}




function recortar (lacapa,arriba,abajo) {

capamov  = eval(docu + lacapa);
if (esie){
	auto = "auto";
	elclip = "rect(" + arriba + "," + auto + "," + abajo + "," + auto + ")";
	capamov.style.clip = elclip;
}

if (esns){
	capamov.clip.top = arriba;
	capamov.clip.bottom = abajo;
}


}

function abven22 (pag,w,h) {
ventana=window.open(pag,'caatb','toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=yes,resizable=no,width='+ w + ',height=' + h);
}

//vaciar inputs de espacios en blanco
function vaciar(caja) {
if (esie)
	obj=eval("document."+caja);
else
	obj=eval("document.contenidos.document."+caja);

  //while(obj.value.charAt(obj.value.length-1)==' ') 
	//obj.value=obj.value.substring(0,obj.value.length-1);
  valor="";
  for (i=0;i<obj.value.length;i++)
    if (obj.value.charAt(i)!=" ")
	  valor = valor + obj.value.charAt(i);
  obj.value=valor;
    	
}

function vaciar2(caja) {
obj=eval("document."+caja);

  //while(obj.value.charAt(obj.value.length-1)==' ') 
	//obj.value=obj.value.substring(0,obj.value.length-1);
  valor="";
  for (i=0;i<obj.value.length;i++)
    if (obj.value.charAt(i)!=" ")
	  valor = valor + obj.value.charAt(i);
  obj.value=valor;
    	
}

function vaciar3(caja) {
obj=eval(caja);

  //while(obj.value.charAt(obj.value.length-1)==' ') 
	//obj.value=obj.value.substring(0,obj.value.length-1);
  valor="";
  for (i=0;i<obj.value.length;i++)
    if (obj.value.charAt(i)!=" ")
	  valor = valor + obj.value.charAt(i);
  obj.value=valor;
    	
}

//vaciar inputs de espacios en blanco sólo al inicio
function vaciarini(caja) {
if (esie)
	obj=eval("document."+caja);
else
	obj=eval("document.cuerpo.document."+caja);
  
i=0;
while(obj.value.charAt(i)==' ')
	i++;
obj.value=obj.value.substring(i,obj.value.length);
    	
}

function vaciarini2(caja) {
obj=eval("document."+caja);
  
i=0;
while(obj.value.charAt(i)==' ')
	i++;
obj.value=obj.value.substring(i,obj.value.length);
    	
}

function vaciarini3(caja) {
obj=eval(caja);
  
i=0;
while(obj.value.charAt(i)==' ')
	i++;
obj.value=obj.value.substring(i,obj.value.length);
    	
}

function agregar(pagina,titulo){

if (document.all) {javascript:window.external.AddFavorite(pagina,titulo);}
else
{
alert ("Acció només disponible en Internet Explorer\n\nPremi CTRL+D per a afegir la pàgina manualment");
}
}

//Verifica si el campo NIF es correcto
function vnif(obj)
{ var clave = "TRWAGMYFPDXBNJZSQVHLCKE";
docum = eval(obj);

dni = docum.value.substring(0,docum.value.length-1);
letra = (docum.value.substring(docum.value.length-1,docum.value.length)).toUpperCase();

fin = clave.substring(dni % 23,1+(dni % 23));

if (letra!=fin) {
  alert("El NIF es incorrecte");
  docum.select();
  docum.focus();
  return false; }
else {
  docum.value = dni + letra;
  return true; }
}