// JavaScript Document

function IdiomaSw(){
	location.href=window.location.href;		
}

function ajust_separ(ref1,ref2){
	elementref1=xGetElementById(ref1);
	newpos1=xHeight(elementref1);
	elementref2=xGetElementById(ref2);
	newpos2=xHeight(elementref2);
	if(newpos2<newpos1){
		newpos=newpos1;
	}else{
		newpos=newpos2;
	}
	element=xGetElementById("sepcol");
	xHeight(element,newpos);
}

///////////////////////////// MENUS /////////////////////////////
function mostrarMenu(submenu,id){
		xShow(submenu);
		document.getElementById(id).style.fontWeight="bold";
}

function ocultarFondo2(){
	clearTimeout(retardo2);	
	retardo2=setTimeout("ocultar2()",500);
}

function ocultarFondo4(){
	clearTimeout(retardo4);	
	retardo4=setTimeout("ocultar4()",500);
}

function cambibg2(id,color){
	document.getElementById(id).style.backgroundColor="#"+color;	
	retardo2=setTimeout("ocultar2()",500);
}

function cambibg4(id,color){
	document.getElementById(id).style.backgroundColor="#"+color;	
	retardo4=setTimeout("ocultar4()",500);
}

function mostrarCapa(id,color){
	document.getElementById(id).style.backgroundColor="#"+color;
	clearTimeout(retardo2);
	clearTimeout(retardo4);
}

function ocultar2(){
	xHide('submenu2');
	document.getElementById("menu2").style.fontWeight="normal";
	clearTimeout(retardo2);	
}

function ocultar4(){
	xHide('submenu4');
	document.getElementById("menu4").style.fontWeight="normal";	
	clearTimeout(retardo4);	
}

//////////////////////////FUNCIONS formularis////////////////////////////////

function validarCur(Idioma){
	if( document.formulario.Nombre.value=="" ||  document.formulario.Apellido.value=="" || document.formulario.Mail.value=="" || document.formulario.accept.value== 0 || document.formulario.Pais.value=="" || document.formulario.Poblacion.value=="" || document.formulario.CP.value=="" || document.formulario.Direccion.value=="" || document.formulario.Documento.value==""){
		if(Idioma=="Cat"){
			alert("Es necesari omplir les dades que tenen *");	
		}else{
			alert("Es necesario rellenar los datos marcados con *");	
		}
		return false;
	}else{
		ok=document.formulario.Mail.value.indexOf("@");
		if(ok===-1 || ok===0 || ok===(document.formulario.Mail.value.length)-1){
			if(Idioma=="Cat"){
				alert("El mail no es correcte");	
			}else{
				alert("El mail no es correcto");	
			}
			return false;
		}	
	}
}

function validarCont(Idioma){
if( document.formulario.Nombre.value=="" ||  document.formulario.Apellido.value=="" || document.formulario.Mail.value=="" || document.formulario.accept.value==0 || document.formulario.Poblacion.value=="" ||  document.formulario.Provincia.value==""){
		if(Idioma=="Cat"){
			alert("Es necesari omplir les dades que tenen *");	
		}else{
			alert("Es necesario rellenar los datos marcados con *");	
		}
		return false;
}else{
		ok=document.formulario.Mail.value.indexOf("@");
		if(ok===-1 || ok===0 || ok===(document.formulario.Mail.value.length)-1 ){
			if(Idioma=="Cat"){
				alert("El mail no es correcto");	
			}else{
				alert("El mail no es correcte");	
			}
			return false;
		}	
	}
}

//////////////////////////FUNCIONS GENERALS////////////////////////////////

// CAMBIAR A FORMATO NUMERICO PARA MOSTRAR CON JAVASCRIPT  //
function numerico(numero){
	numero *=100;
	numero=Math.round(numero);
	numero /=100;
	
	numeroCadena=Math.abs(numero).toString();

	if(numeroCadena.indexOf(".")==-1){
		numeroCadena+=".00";
	}else{
		decimales=numeroCadena.substr(numeroCadena.indexOf("."));
		if(decimales.length ==2){
			numeroCadena+="0";
		}
	}
	numeroCadena=numeroCadena.replace(/\./,",");
	if (numeroCadena.length > 6){
		posfinal=numeroCadena.indexOf(",",0);
		dec=numeroCadena.substring(posfinal);
		ent=numeroCadena.substring(0,posfinal);
		longitud=ent.length % 3;
		while (longitud<ent.length){
			if(longitud==0){
				longitud=3;
			}
			ent=ent.substr(0,longitud)+"."+ent.substr(longitud,ent.length);
			longitud+=4
		}
		numeroCadena=ent+dec;
	}
	numeroCadena=numeroCadena+" €";
	
	return numeroCadena;
}

// TRADUCCION NUMERO DECIMAL Y MILLARES  A  FORMATO INGLES//
function formatoNum(numero){
	posfinal=numero.indexOf(",",0);
	dec=numero.substring(posfinal);
	ent=numero.substring(0,posfinal);
	dec=dec.replace(/\,/,".");
	ent=ent.replace(/\./,"");
	numeroCadena=ent+dec
return numeroCadena;
}


//////////////////////////CONTROL POPUPS////////////////////////////////

function AbrirVentanaPop(Direccion,NombreVen){
	navegador=navigator.userAgent;
	window.document.formulario.accept.checked=0;
	if(navegador.indexOf("Safari")==-1){
		parametros="width=780, height=685, left=100, top=50, resizable=no, menubar=no, toolbar=no, directories=no, scrollbars=auto, status=no";
	}else{
		parametros="width=800, height=705, left=100, top=50, resizable=no, menubar=no, toolbar=no, directories=no, scrollbars=auto, status=no";	
	}
	ventanaPop=window.open(Direccion,NombreVen,parametros);	
	ventanaPop.focus();
}

function AbrirVentanaLegal(Direccion,NombreVen){
	navegador=navigator.userAgent;
	if(navegador.indexOf("Safari")==-1){
		parametros="width=805, height=685, left=100, top=50, resizable=no, menubar=no, toolbar=no, directories=no, scrollbars=yes, status=no";
	}else{
		parametros="width=825, height=705, left=100, top=50, resizable=no, menubar=no, toolbar=no, directories=no, scrollbars=yes, status=no";	
	}
	ventanaPop=window.open(Direccion,NombreVen,parametros);	
	ventanaPop.focus();
}

function AbrirVentanaMapa(Direccion,NombreVen){
	navegador=navigator.userAgent;
	if(navegador.indexOf("Safari")==-1){
		parametros="width=705, height=570, left=100, top=50, resizable=no, menubar=no, toolbar=no, directories=no, scrollbars=no, status=no";
	}else{
		parametros="width=725, height=590, left=100, top=50, resizable=no, menubar=no, toolbar=no, directories=no, scrollbars=no, status=no";	
	}
	ventanaPop=window.open(Direccion,NombreVen,parametros);	
	ventanaPop.focus();
}

function CerrarPop(){
	opener.window.document.formulario.accept.checked=1;
	opener.window.document.formulario.accept.value="1";
	window.close();
}

function CerrarMapa(url){
	opener.window.location.href=url;
	window.close();
}


//////////////////////////PAGAMENTS////////////////////////////////

function registrat(camp){
	eval("document."+camp+".submit()");
}

function Refresc(desti){
	location.href=desti;	
}

function VeureAnt(){
	xVisibility("cist_ant",true);
}

//////////////////////////FORMULARIS////////////////////////////////



