// JavaScript Document

primer=1;

function mostrar(camp, text){
	eval("document."+camp+".value='"+text+"'");
	eval("document."+camp+".style.visibility='visible'");
}

function amagar(camp){
	eval("document."+camp+".value=''");
		eval("document."+camp+".style.visibility='hidden'");
}

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

function validarFormAct(){
	if( document.formulari.nom.value=="" ||  document.formulari.cognoms.value=="" || document.formulari.dni.value=="" || document.formulari.email.value=="" || document.formulari.adreca.value==""|| document.formulari.telefon.value=="" ){
		alert("Sis plau, cal introduir les dades marcades amb *");	
		return false;
	}else{
		ok=document.formulari.email.value.indexOf("@");
		if(ok===-1 || ok===0 || ok===(document.formulari.email.value.length)-1){
			alert("El email no es correcte");	
			return false;
		}	
	}
}

function changeImgSc(id,num,tipo){
		obj="media"+primer;
		document.getElementById(obj).style.borderColor="";
		obj="media"+num;
		document.getElementById(obj).style.borderColor="#FF0000";
		primer=num;
	xajax_changeImg(id,tipo);
}

function ObrirURL(ruta,loc){
	loc=escape(loc);
	window.open(''+ruta+loc+'');
}


//////////////////////////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);
}

//////////////////////////FLV  PLUGINS////////////////////////////////

function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}
