function MM_validateForm() { //v4.0

  var i,p,q,nm,nmtext,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);

    if (val) { nm=val.name; 
	       chckd=val.checked;
		   id = val.id;
		   value = val.value;

		if (nm == "name"){
			nmtext = "Nom";
		}
		else if (nm == "surname"){
			nmtext = "Cognoms";
		}
		else if (nm == "NIF"){
			nmtext = "N.I.F.";
		}		
		else if (nm == "country"){
			nmtext = "País";
		}
		else if (nm == "phone"){
			nmtext = "Telèfon";
		}
		else if (nm == "email"){
			nmtext = "Adreça electrònica";
		}	
		else if (nm == "emailconf"){
			nmtext = "Comprovació d´adreça electrònica";
		}		
		else if (nm == "address"){
			nmtext = "Adreça";
		}			
		else if (nm == "city"){
			nmtext = "Població";
		}		
		else if (nm == "zipcode"){
			nmtext = "Codi postal";
		}
		else if (nm == "region"){
			nmtext = "Regió";
		}				
		else if ((nm == "password1F") || (nm == "fpassword")){
			nmtext = "Contrasenya";
		}				
		else if (nm == "password2F"){
			nmtext = "Comprovació de contrasenya";
		}	
		else if ((nm == "usernameF") || (nm == "fusername") || (nm == "email1")){
			nmtext = "Adreça electrònica";
		}
		else if (nm == "idCity"){
			nmtext = "Població de destí";
		}
		else if ((nm == "numAdults") || (nm == "numAdultsNR")){
			nmtext = "Nombre de persones adultes";
		}
		else if (nm == "numChildrenNR"){
			nmtext = "Nombre d'infants de 2 a 12 anys";
		}
		else if (nm == "nameHotel"){
			nmtext = "Nom de l´hotel";
		}
		else if (nm == "phoneHotel"){
			nmtext = "Telèfon de l'hotel";
		}
		else if (nm == "emailHotel"){
			nmtext = "Adreça electrònica de l'hotel";
		}
		else if (nm == "nombre"){
			nmtext =  "El seu nom";
		}
		else if (nm == "emailFrom"){
			nmtext =  "La seva adreça electrònica";
		}
		else if (nm == "emailTo"){
			nmtext =  "L'adreça electrònica del seu amic";
		}
		else if (nm == "firstinput"){
			nmtext =  "Data";
		}
		else if (nm == "secondinput"){
			nmtext =  "Data";
		}		
		else if ((nm == "firstinputArrival") || (nm == "firstinputH")){
			nmtext =  "Data d'arribada";
		}				
		else if (nm == "secondinputExit"){
			nmtext =  "Data sortida";
		}		
		else if (nm == "numFlight"){
			nmtext =  "Número de vol";
		}
		else if (nm == "timeArriveFlight"){
			nmtext =  "Hora prevista d'arribada";
		}
		else if (nm == "addressDevolutionCar"){
			nmtext =  "Adreça";
		}			
		else if (nm == "arrivalTimeHour"){
			nmtext =  "Hora d'arribada: Hora";
		}
		else if (nm == "arrivalTimeMinute"){
			nmtext =  "Hora d'arribada: Minuts";
		}
		else if (nm == "exitTimeHour"){
			nmtext =  "Hora de sortida: Hora";
		}	
		else if (nm == "exitTimeMinute"){
			nmtext =  "Hora de sortida: Minuts";
		}	
		else if ((nm == "originAirport") || (nm == "arriveAirport")){
			nmtext =  "Aeroport d'origen";
		}	
		else if ((nm == "originNumFlight") || (nm == "numFlightArrive") || (nm == "numFlightExit")){
			nmtext =  "Número de vol";
		}	
		else if (nm == "exitAirport"){
			nmtext =  "Aeroport de destí";
		}
		else if ((nm == "idRoomNR") || (nm == "idRoom1")){
			nmtext =  "Tipus d'habitació";
		}
		else if ((nm == "idRegimesNR") || (nm == "idRegimes1")){
			nmtext =  "Règim";
		}
		else if ((nm == "numNightsH") || (nm == "numNights")){
			nmtext =  "Nombre de nits";
		}																												
		else{
			nmtext = nm;
		}

	if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { 
	p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nmtext+' ha de contenir una adreça de correu electrònic vàlida.\n';
      } 
      else if (test.indexOf('checked')!=-1) { 

		if ((id == "RSV0") && (value == "TXTFLD") && (chckd == true)){

			if (document.form1.nameHotel.value == ""){ errors += '- Nom de l´hotel és obligatori.\n';}
			if (document.form1.addressHotel.value == ""){ errors += '- Adreça és obligatori.\n';}
		}
		else if (id != "RSV0"){
        if (chckd == false) errors+='- Ha d´acceptar les condicions d´ús del servei.\n';
		}
      } 
      else if (test!='R') { 
	num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nmtext+' ha de ser un valor numèric.\n';
        if (test.indexOf('inRange') != -1) { 
		p=test.indexOf(':');
          	min=test.substring(8,p); max=test.substring(p+1);
          	if (num<min || max<num) errors+='- '+nmtext+' ha de ser un valor numèric entre '+min+'  '+max+'.\n';
    	} 
      } 

    } 
    else if (test.indexOf('selected')!=-1) {
		if (id == "idDestinacio" && document.getElementById("idDestinacio").value == ""){
			errors+='- Per favor seleccioni una destinació.\n';
		}
    }		
	else if (test.charAt(0) == 'R') errors += '- '+nmtext+' és obligatori.\n'; }
  } if (errors) alert('S´han trobat els següents errors:\n'+errors);
  document.MM_returnValue = (errors == '');
}


function checkNIF()
  {

    nifcif = document.form1.NIF.value.substring (0, 1);

    if (EsNumero(nifcif)) {


//    if (document.form1.NIF.value.length==0) 
//    {
//      document.form1.NIF.focus();  
//      alert ("Debe facilitarnos el número de identificación fiscal.");
//      return(false);
//    }
    var letras=0;
    for (var i=0; i<document.form1.NIF.value.length; i++) 
    {
      var ch = document.form1.NIF.value.substring (i, i+1);
      if ( (ch < "0" || ch > "9") && (ch < "a" || ch > "z") && (ch < "A" || ch > "Z") )
      {
        alert("El número d'identificació fiscal facilitat és erroni.");
        document.form1.NIF.value = "";
        document.form1.NIF.focus();

        return(false);
      }
      if ( (ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z") )
      {
        letras++;
      }  
    }
    if (letras>2)
    {
      alert("El número d'identificació fiscal facilitat és erroni.");
      document.form1.NIF.value = "";
      document.form1.NIF.focus();
      return(false);
    }

    var numNIF = document.form1.NIF.value.substring(0,8);
    var lletraNIF = document.form1.NIF.value.substring(8,9);

    var cadena = 'TRWAGMYFPDXBNJZSQVHLCKET';
    var posicion = numNIF % 23;

    var lletraNIFOK = cadena.charAt(posicion);

    if (lletraNIF != lletraNIFOK){
      alert("El número d'identificació fiscal facilitat és erroni.");
      document.form1.NIF.value = "";
      document.form1.NIF.focus();
      return(false)
    }

    return true;
 
    }
    else{


	if (validarCIF(document.form1.NIF.value)){
		return(true)
	}
	else{
		alert("El número d'identificació fiscal facilitat és erroni.");
	        document.form1.NIF.value = "";
	        document.form1.NIF.focus();
		return(false)
	}

    }
}
