﻿function buidaCercador()
{
document.buscador.nom.value="";
document.buscador.nom.focus();
}

function ompleCercador(idioma)
{
if (document.buscador.nom.value=="")
{

	if(idioma=='ca')
	{
		document.buscador.nom.value="Cerca un polígon...";
	}
	
	if(idioma=='es')
	{
		document.buscador.nom.value="Busca un polígono...";
	}

}
}

function ampliaImatges(imatge)
{

obj=document.getElementById("imatgeGran");
obj.src = imatge;   
	
}





//VALIDACIÓ FORMULARIS

//funcions generals 

function esta_ple(d1)
{
/* Torna
	0: Camp Buit
	1: Camp Ple
*/
	if (d1.value=='')
		return 0;
	else
		return 1;
}


function mira_email(email) {
/* Torna
        0: no hi ha res
        1: si es correcte
        9: email incorrecte
*/

if(email.value!="")
   {
   if (/^[A-Za-z0-9\.+_-]+@[A-Za-z0-9\.-]+\.[A-Za-z]{2,6}$/.test(email.value))
  	{
	return 1;
	}
	else
	{
	return 9;
	}
   }
else
   {
	return 0;
   }
}


function comprova_radio(que,longitud)
{

/*
        Retorna 0 si no hi ha cap seleccio
        Retorna el numero d'ordre de la seleccionada (començant per 1)
*/
                value=0;
                for(i=0;i<longitud;i++)
                {

                        if(que[i].checked == true)
                        {
                                value=i+1;
                        }
                }
                return value;
}



function alerta_en (str)
{
	alert("Check the field " + str + " ...");
}


function alerta_ca (str)
{
	alert("Revisa el camp " + str + " ...");
}

function alerta_fr (str)
{
	alert("Contrôlez le champ " + str + " ...");
}

function alerta_es (str)
{
	alert("Revisa el campo " + str + " ...");
}


// valida incripció


function inscripcio_ca()
{
        with (document.form1)
               {
               	result1 = esta_ple(nif);
		result2 = esta_ple(nom);
		result3 = esta_ple(cognom1);
		result4 = esta_ple(cognom2);
		result5 = esta_ple(telefon2);
        result6 = mira_email(email);
		result7 = esta_ple(empresa_rao);
		result8 = esta_ple(empresa_cif);


		
               	
		
               if (result1 == 0)
               {		pinta_blanc();
				alerta_ca('NIF');
				document.getElementById('nif').style.background = '#FFEFEF';
				nif.focus();
				return false;
				}
				
		else if (result2 == 0)
               {		pinta_blanc();
				alerta_ca('Nom');
				document.getElementById('nom').style.background = '#FFEFEF';
				nom.focus();
				return false;
				}
				
		else if (result3 == 0)
               {
				pinta_blanc();
				alerta_ca('Primer Cognom');
				document.getElementById('cognom1').style.background = '#FFEFEF';
				cognom1.focus();
				return false;
				}
				
		else if (result4 == 0)
               {
				pinta_blanc();
				alerta_ca('Segon Cognom');
				document.getElementById('cognom2').style.background = '#FFEFEF';
				cognom2.focus();
				return false;
				}
				
		else if (result5 == 0)
               {
				pinta_blanc();
				alerta_ca('Telèfon Mòbil');
				document.getElementById('telefon2').style.background = '#FFEFEF';
				telefon2.focus();
				return false;
				}
							
				
               else if (result6 != 1)
               {
				pinta_blanc();
				alert('Escriu una adreça de correu electrònic vàlida');
				document.getElementById('email').style.background = '#FFEFEF';
				email.focus();
				return false;
				}
				
		else if (result7 == 0)
               {
				pinta_blanc();
				alerta_ca('Empresa Raó Social');
				document.getElementById('empresa_rao').style.background = '#FFEFEF';
				empresa_rao.focus();
				return false;
				}
		
		else if (result8 == 0)
               {
				pinta_blanc();
				alerta_ca('Empresa CIF');
				document.getElementById('empresa_cif').style.background = '#FFEFEF';
				empresa_cif.focus();
				return false;
				}

	       else 
		   {
		   submit();
		   }
       }
}

function inscripcio2_ca()
{
        with (document.form1)
               {
               	result1 = esta_ple(nif);
		result2 = esta_ple(nom);
		result3 = esta_ple(cognom1);
		result4 = esta_ple(cognom2);
		result5 = esta_ple(telefon2);
               	result6 = mira_email(email);
		result7 = esta_ple(empresa_rao);
		result8 = esta_ple(empresa_cif);
		result9 = comprova_radio(bonificacio,2);
		result10 = comprova_radio(factura,2);

		
               	
		
               if (result1 == 0)
               {		pinta_blanc();
				alerta_ca('NIF');
				document.getElementById('nif').style.background = '#FFEFEF';
				nif.focus();
				return false;
				}
				
		else if (result2 == 0)
               {		pinta_blanc();
				alerta_ca('Nom');
				document.getElementById('nom').style.background = '#FFEFEF';
				nom.focus();
				return false;
				}
				
		else if (result3 == 0)
               {
				pinta_blanc();
				alerta_ca('Primer Cognom');
				document.getElementById('cognom1').style.background = '#FFEFEF';
				cognom1.focus();
				return false;
				}
				
		else if (result4 == 0)
               {
				pinta_blanc();
				alerta_ca('Segon Cognom');
				document.getElementById('cognom2').style.background = '#FFEFEF';
				cognom2.focus();
				return false;
				}
				
		else if (result5 == 0)
               {
				pinta_blanc();
				alerta_ca('Telèfon Mòbil');
				document.getElementById('telefon2').style.background = '#FFEFEF';
				telefon2.focus();
				return false;
				}
							
				
               else if (result6 != 1)
               {
				pinta_blanc();
				alert('Escriu una adreça de correu electrònic vàlida');
				document.getElementById('email').style.background = '#FFEFEF';
				email.focus();
				return false;
				}
				
		else if (result7 == 0)
               {
				pinta_blanc();
				alerta_ca('Empresa Raó Social');
				document.getElementById('empresa_rao').style.background = '#FFEFEF';
				empresa_rao.focus();
				return false;
				}
		
		else if (result8 == 0)
               {
				pinta_blanc();
				alerta_ca('Empresa CIF');
				document.getElementById('empresa_cif').style.background = '#FFEFEF';
				empresa_cif.focus();
				return false;
				}
				
		else if (result9== 0)
		{
				pinta_blanc();
				alert('Selecciona la bonificació')
				return false;
				}
				
		else if (result10== 0)
		{
				pinta_blanc();
				alert('Selecciona el tipus de factura')
				return false;
				}

	       else 
		   {
		   submit();
		   }
       }
}


 
 function pinta_blanc ()
 {
	document.getElementById('nif').style.background = '#FFF';
	document.getElementById('nom').style.background = '#FFF';
	document.getElementById('cognom1').style.background = '#FFF';
	document.getElementById('cognom2').style.background = '#FFF';
	document.getElementById('telefon2').style.background = '#FFF';
	document.getElementById('email').style.background = '#FFF';
	document.getElementById('empresa_rao').style.background = '#FFF';
	document.getElementById('empresa_cif').style.background = '#FFF';
 }
 
 // valida incripció serveis i acords


function solicitud_servei_ca()
{
        with (document.form1)
               {
               	result1 = esta_ple(nom);
				result2 = esta_ple(cognoms);
				result3 = mira_email(email);

				

               if (result1 == 0)
               {
				pinta_blanc2();
				alerta_ca('Nom');
				document.getElementById('nom').style.background = '#FFEFEF';
				nom.focus();
				return false;
				}
				
		else if (result2 == 0)
               {		
			   
			    pinta_blanc2();
				alerta_ca('Cognoms');
				document.getElementById('cognoms').style.background = '#FFEFEF';
				cognoms.focus();
				return false;
				}
				

								
               else if (result3 != 1)
               {
				pinta_blanc2();
				alert('Escriu una adreça de correu electrònic vàlida');
				document.getElementById('email').style.background = '#FFEFEF';
				email.focus();
				return false;
				}
				
		

	       else 
		   {
		   submit();
		   }
       }
}

 function pinta_blanc2 ()
 {
	document.getElementById('nom').style.background = '#FFF';
	document.getElementById('cognoms').style.background = '#FFF';
	document.getElementById('email').style.background = '#FFF';

 }
 
 function mesinfo ()
{
	if (document.getElementById('mesinfo').style.display =='none')
		{
			xDisplay('mesinfo', 'block');
		}
		
		else
		
		{
			xDisplay('mesinfo', 'none');
		}

}




// valida contactar


function contactar_ca()
{
        with (document.form1)
               {
               	result1 = esta_ple(empresa);
				result2 = esta_ple(persona_contacte);
				result3 = esta_ple(telefon);
				result4 = mira_email(email);

				

               if (result1 == 0)
               {
				pinta_blanc3();
				alerta_ca('Empresa');
				document.getElementById('empresa').style.background = '#FFEFEF';
				empresa.focus();
				return false;
				}
				
				else if (result2 == 0)
               {		
			   
			    pinta_blanc3();
				alerta_ca('Persona de Contacte');
				document.getElementById('persona_contacte').style.background = '#FFEFEF';
				persona_contacte.focus();
				return false;
				}
				
				else if (result3 == 0)
               {		
			   
			    pinta_blanc3();
				alerta_ca('Telèfon');
				document.getElementById('telefon').style.background = '#FFEFEF';
				telefon.focus();
				return false;
				}
				

								
               else if (result4 != 1)
               {
				pinta_blanc3();
				alert('Escriu una adreça de correu electrònic vàlida');
				document.getElementById('email').style.background = '#FFEFEF';
				email.focus();
				return false;
				}
				
		

	       else 
		   {
		   submit();
		   }
       }
}

 function pinta_blanc3 ()
 {
	document.getElementById('empresa').style.background = '#FFF';
	document.getElementById('persona_contacte').style.background = '#FFF';
	document.getElementById('telefon').style.background = '#FFF';
	document.getElementById('email').style.background = '#FFF';

 }
