
 // FUNCIÓ PER A LA VALIDACIÓ DE FORMULARIS
 function comprovacio(camps,noms,eltexte,frase){

    var camps = camps.split(',');
    var noms = noms.split(',');
    var correcte = 1;

    for(i=0;i<(camps.length);i++){

      if(camps[i]=='email'){

        if ((document.getElementById('email').value =="") || !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('email').value))){

          alert("Email incorrecte.");
          return (false);

        }

      }
      else if(!document.getElementById(camps[i]).value){

        alert(eltexte+noms[i]);
        document.getElementById(camps[i]).focus();
        correcte=0;
      }
    }

    if(correcte){

      if(confirm(frase)) correcte=1;
      else correcte=0;

    }

    if(correcte){
      return true;
    }
    else return false;
}

function SeleccioFotos(nom_foto)
{
	var ruta;

		ruta = "./includes/tallfoto.php?ruta=../img/galeria/" + nom_foto + "&posx=0&posy=0&width=400&height=400&opcio=escala";
		document.getElementById('imatge_ampliada').src = "";
		document.getElementById('imatge_ampliada').src = ruta;
		document.getElementById('popup').style.visibility = 'visible';
		
}
function AmagarFoto()
{
	document.getElementById('popup').style.visibility = 'hidden';
}
function AmagarBanner()
{
	document.getElementById('banner').style.visibility = 'hidden';
}

function input(idinput,textovalue) {
	var campo = document.getElementById(idinput);
	if (campo.value.length==0) {
		campo.value=textovalue;
	}
}
function inputClick(idinput,textovalue) {
	var campo = document.getElementById(idinput);
	if (campo.value==textovalue) {
		campo.value="";
	}
}
lastheight = '';
function dreta(capa){
	document.getElementById(capa).scrollTop+=1;
	if (document.getElementById(capa).scrollTop==lastheight) document.getElementById(capa).scrollTop=0;
	else lastheight = document.getElementById(capa).scrollTop;
		setTimeout("dreta('"+capa+"')",1);
}

function esquerra(capa){
	document.getElementById(capa).scrollLeft=document.getElementById(capa).scrollLeft-5;
	if(actiu)
		setTimeout("esquerra('"+capa+"')",1);
}
function activaTransicio(actual,nbfotos, opac) {
	capa = "trans_"+actual;
	if(opac>10){
		document.getElementById(capa).style.filter='Alpha(Opacity='+opac+')';
		opac=opac-5;
		setTimeout("activaTransicio('"+actual+"',"+nbfotos+","+opac+")",100);
	}else{
/*		proxima = parseInt(actual)+1;
		//document.write(proxima+"<br/>");
		//alert(proxima);
		if (proxima==nbfotos) {
			setTimeout("activaTransicio1(0,"+nbfotos+",10)",100);
		}
		else setTimeout("activaTransicio1("+proxima+","+nbfotos+",10)",100);
//		document.getElementById(capa).style.visibility='hidden';
		if (actual==0) document.getElementById(capa).style.filter='Alpha(Opacity=20)';
		else document.getElementById(capa).style.filter='Alpha(Opacity=0)';*/

		proxima = parseInt(actual)+1;
		if (proxima==nbfotos) {
			setTimeout("activaTransicio(0,"+nbfotos+",10)",100);
		}
		else setTimeout("activaTransicio("+proxima+","+nbfotos+",10)",100);
		if (actual==0) apaga = parseInt(nbfotos)-2;
		if (actual==1) apaga = parseInt(nbfotos)-1;
		document.getElementById("trans_"+apaga).style.filter='Alpha(Opacity=0)';
	}
}
function pausecomp(millis) {
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); }
	while(curDate-date < millis);
}
function comprobaFormulari(texteAlert) {
	var form = document.forms.contactoForm;
	if (form.email!="") {
		var s = form.email.value;
		var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
		if (s.length == 0 ) return true;
		   if (filter.test(s))
		      form.submit();
		   else {
		   		alert(texteAlert);
				form.email.focus();
			}
	}
	else alert(texteAlert);
}
function abreCapaServeis() {
	var capa = document.getElementById('capaserveis');
	capa.style.visibility = "visible";
}
function tancaCapaServeis() {
	var capa = document.getElementById('capaserveis');
	capa.style.visibility = "hidden";
}
function abreCapaProjectes() {
	var capa = document.getElementById('capaprojectes');
	capa.style.visibility = "visible";
}
function tancaCapaProjectes() {
	var capa = document.getElementById('capaprojectes');
	capa.style.visibility = "hidden";
}

function habilita(tipus) {
	if (tipus==1) {
		document.getElementById('preumax').disabled = false;
	}
	else {
		document.getElementById('preumax').disabled = true;
		document.getElementById('preumax').selectedIndex = 0;
	}
}
function cercar(ERRORMSG) {
	if (document.cercaForm.tipus.selectedIndex>0) {
		document.cercaForm.submit();
	}
	else alert(ERRORMSG);
}
function calcula(camp1,camp2,camp3) {
	var interes;
	var plazo;
	var cuota;

	plazo=camp2*12;
	interes=(camp3/12);

	valor1=1+(interes/100);
	valor2=-1*plazo;
	valor3=Math.pow(valor1,valor2);
	valor4=1-valor3;

	cuota=(camp1*interes)/(100*valor4);
	cuota=Number(cuota).toFixed(2);

	document.getElementById('resultat').value=cuota;
}