///////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////// validate_form.js ///////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                   //
// isNotInteger(s):                      Verifica si s és un sencer.                                 //
// isDigit(c):                           Verifica si c es un dígito en un rango de "0" a "9".        //
// isDecimal(c)				             Verifica que c sigui un número, coma o punt per als números //
//                                       decimales.                                                  //
// isNumber(obj)			             Verifica que el valor del obj sigui un número.              //
// isEmptyNotWhiteSpace(s,obj):          Verifica si s està buit sense espais en blanc.              //
// DeteleWhiteSpace(s,obj):              Elimina los espacios en blanco que haya al principio de s.  //
// isTelephone(obj):                     Verifica si obj es un número de teléfono/fax.               //
// isMobile(obj,s):                      Comprueba que sea un número de móvil en el formato          //
//                                       internacional.                                              //
//                                       Si no lo tiene, le añade el +34                             //
// isMaxLenTextArea(c,maxlen):           Verifica que la longitud maxlen no sea más grande que el    //
//                                       contenido de c.                                             //
// isNotNameWhiteSpace(s,obj):           Verifica que s es un nombre de persona, empresa,...         //
//                                       aceptando espacios en blanco.                               //
// isMail(obj):			         Verifica si és un email amb sintaxis vàlida.                //
// isDNI_NIE_Passport(s):                Verifica si es un DNI, NIE o pasaporte válido.              //          
// isDNI(s):                             Verifica si s es un DNI.                                    // 
// isNIE(s):                             Verifica que s sea un NIE.                                  //
// isPassport(s):                        Verifica si s es un passporte.                              // 
// isDate(obj):                          Verifica si el objeto tiene formato de fecha                //
// isDateHour(obj):                      Verifica si el objeto tiene formato de fecha y hora         //
// isCorrectHour(shm):                   Devuelve true si se trata de una hora tipo: hh:mm y devuelve//
//                                       false en caso contrario.                                    //
// isCorrectDate(obj,day,month,year):    Verifica que la fecha sea correcta en base al año bisiesto  //
// daysInFebruary(year):                 Verifica si year es un año bisiesto y devuelve el número de //
//                                       días.                                                       //
// rankDates(s1,s2):                     Compara dos fechas, s1 debe ser menor que s2.               //
// isDateHourTo(obj):                    Verifica si el objeto tiene formato de fecha y hora. Si no  //
//                                       se le añade la hora, los minutos y los segundos. Se le añade//
//                                       la hora 23, los 59 minutos, y 59 segundos; para poder hacer //
//                                       filtros del tipo "Hasta" <= dd/mm/aa 23:59:59               // 
// isCorrectPasswords(pwd1,pwd2):        Comprueba que la contraseña introducida sea mayor de        //
//                                       4 caracteres, además que la contraseña introducida 2 veces  //
//                                       sea la misma                                                //
// isURL(s):                             Verifica si s té una sintaxis correcta de URL               //
// isImage(s):                           Verifica si s té una sintaxis de nom de fitxer d'imatge.    //
// isFile(s):                            Verifica si s té una sintaxis de nom de fitxer vàlid.       //
// isCodPostal(c):			 Verifica que c sigui un codi postal vàlid.                  //
///////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////
//isNotInteger(s): Verifica si s és un sencer
///////////////////////////////////////////////////////////////////////////////////////////////////////
function isNotInteger(s){
 var error=false;
 var i;
	for(i=0;i<s.length;i++){   
		var c = s.charAt(i);	
		if(!isDigit(c)) error = true;
	}	
	return error;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//isDigit(c): Verifica si c es un dígito en un rango de "0" a "9".
//////////////////////////////////////////////////////////////////////////////////////////////////////
function isDigit(c){
	return ((c >= "0") && (c <= "9"));
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//isEmptyNotWhiteSpace(s,obj): Verifica si s està buit sense espais en blanc
//////////////////////////////////////////////////////////////////////////////////////////////////////
function isEmptyNotWhiteSpace(s,obj){
	s = DeleteWhiteSpace(s,obj);
	return ((s == null) || (s.length == 0));
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//DeteleWhiteSpace(s,obj): Elimina los espacios en blanco que haya al principio de s.
//////////////////////////////////////////////////////////////////////////////////////////////////////
function DeleteWhiteSpace(s,obj){
var i;
var z=0;

	s=""+s;
	if(s.length!=0){
		while(s.substr(z,1)==" "){
			z++;
		}
		obj.value=s.substr(z,(s.length-z));
		s=obj.value;
	}
	return s;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//isTelephone(obj): Verifica si obj es un número de teléfono/fax.
//////////////////////////////////////////////////////////////////////////////////////////////////////
function isTelephone(obj){
	var ok=true;

	if(!isNaN(obj.value) && (""+obj.value).length>=9){
		var num = "0123456789()- +.";
		for (var intLoop = 0; intLoop < obj.value.length; intLoop++) {
			if ((-1 == num.indexOf(obj.value.charAt(intLoop))) && (!ok)) {
				ok=false;
			}
		}		
	} else {
		ok=false
	}
	
	return ok;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//isMobile(obj,s): Comprueba que sea un número de móvil el formato internacional. Si no lo tiene, 
//le añade el +34
//////////////////////////////////////////////////////////////////////////////////////////////////////
function isMobile(obj,s) {
	var ok=true;
	s=DeleteWhiteSpace(s,obj);
	
	if(!isNaN(s) && s.length>=9){
		var num = "0123456789+";
		for (var intLoop = 0; intLoop < s.length; intLoop++) {
			if ((-1 == num.indexOf(s.charAt(intLoop))) && (!ok)) {
				ok=false;
			}
		}		
	} else {
		ok=false;
	}
	
	// Le añado +34 si no lo tiene
	if (ok && (s.substring(0,1)!="+")){
		obj.value = "+34" + s;
	}

	return ok;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//isMaxLenTextArea(c,maxlen): Verifica que la longitud maxlen no sea más grande que el contenido de c.
//////////////////////////////////////////////////////////////////////////////////////////////////////
function isMaxLenTextArea(c,maxlen){	
	if(c.length>maxlen) {
		return true;
	} else {
		return false;
	}	
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//isNotNameWhiteSpace(s,obj): Verifica que s es un nombre de persona, empresa,... aceptando espacios 
//en blanco.
//////////////////////////////////////////////////////////////////////////////////////////////////////
function isNameWhiteSpace(s,obj) {
	var correct=true;
	
	if(s.length==0 || s=="") {
		correct=false;		
	} else {
		var i=0;		
		while(i<s.length){
			var c=s.substr(i,1);
			if(!isLetterOrNumberOrWhiteSpace(c) && !isCharAccent(c)) {
				correct=false;
			}
			i++;
		}		
	}
	return correct;	
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//isLetterOrNumberOrWhiteSpace(c)
//////////////////////////////////////////////////////////////////////////////////////////////////////
function isLetterOrNumberOrWhiteSpace(c) {
	return (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || (c==" ") || (c=="'") || (c=="-") || (c=="_") || (c=="·") || (c=="º") || (c=="ª")  || ((c >= "0") && (c <= "9")) || ((c=="+") || (c=="/") || (c=="@") || (c=="€") || (c=="$") || (c=="%") || (c=="&") || (c=="*")) || ((c=="!") || (c=="¡")) || ((c=="¿") || (c=="?")) || ((c==".") || (c==":")) || ((c==",") || (c==";")) || ((c=="(") || (c==")")) || ((c=="ñ") || (c=="Ñ")) || ((c=="ç") || (c=="Ç")));
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//isCharAccent(c)
//////////////////////////////////////////////////////////////////////////////////////////////////////
function isCharAccent(c){
	return ((c=="á") || (c=="à") || (c=="é") || (c=="è") || (c=="í") || (c=="ì") || (c=="ó") || (c=="ò") || (c=="ú") || (c=="ù") || (c=="Á") || (c=="À") || (c=="É") || (c=="È") || (c=="Í") || (c=="Ì") || (c=="Ó") || (c=="Ò") || (c=="Ú") || (c=="Ù"))
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//isMail(obj): Verifica si es un email con sintaxis válida.
//////////////////////////////////////////////////////////////////////////////////////////////////////
function isMail(obj){
var error = true;
var value=obj.value;

	if(value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
		error = false;
	}
	
	return error;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//isDNI_NIE_Passport(s): Verifica si es un DNI, NIE o pasaporte válido.
//////////////////////////////////////////////////////////////////////////////////////////////////////
function isDNI_NIE_Passport(s){
var ok=false;

	s = s.toUpperCase();
	if ((s.length == 0) || (s.length > 9)) {
		ok=false;
	} else {
	    // the field s, could be filled with:
    	// DNI -> begins with a number and eng with a letter
	    // NIE -> begins with X have 7 digits and ends with a letter
    	// PASSAPORT --> beguins with P and 7 digits ( add if the number is less than 7 digits )
	    switch (s.charAt(0).toUpperCase()) {
		case 'X': // is a NIE
    		ok = isNIE(s);
	       	break;
    	case 'P': //is a passaport
    		ok = isPassport(s);
	        break;
    	default: //is a dni
    		ok = isDNI(s);
	    }
	}
	return ok;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//isDNI(s): Verifica si s es un DNI.
//////////////////////////////////////////////////////////////////////////////////////////////////////
function isDNI(s) {
var sLastChar;
var sTmpDNI = null;
var bLastIsChar = false;
var iNum = null;
var ok = true;
    
	sTmpDNI = s;
    sLastChar = sTmpDNI.charAt(sTmpDNI.length - 1); //Begins at index 0 !!!!
    if (isNaN(sLastChar) != true) {
		bLastIsChar = false;
    } else {
        sTmpDNI = sTmpDNI.substring (0, sTmpDNI.length - 1);
        bLastIsChar = true;
    }
    // test if the rest is a number.
	if (isNaN(sTmpDNI) == true) {		
		ok = false;
	} else {
	   	iNum = parseInt(sTmpDNI, 10);	
	}

    // we test if the letter is correct or calc the letter.
    if (bLastIsChar == true) {
        if (sLastChar != getDNILetter(iNum)) {
        	ok = false;
        }
    } else {
        sLastChar = getDNILetter(iNum);
        //we modified the dni to add the letter
        s = s + sLastChar;
    }
	
    return ok;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//isNIE(s): Verifica que s sea un NIE.
//////////////////////////////////////////////////////////////////////////////////////////////////////
function isNIE(s) {
var sLastChar;
var sTmpNIE = null;
var bLastIsChar = false;
var iNum = null;
var ok = true;
    
    sTmpNIE = s.substring (1); // skip the X

    sLastChar = sTmpNIE.charAt (sTmpNIE.length - 1); //Begins at index 0 !!!!
    if (isNaN(sLastChar) != true) {
		bLastIsChar = false;
    }
	else {
        sTmpNIE = sTmpNIE.substring (0, sTmpNIE.length - 1);
        bLastIsChar = true;
    }
	
    // it must be 7 digits
    if (sTmpNIE.length != 7) {
		ok = false;
	}

    // probe if the rest is a nunmber.
	if (isNaN (sTmpNIE) == true) {
		ok = false;
	} else {
	   	iNum = parseInt(sTmpNIE, 10);	
	}

    // we test if the letter is correct or calc the letter.
    if (bLastIsChar == true) {
        if (sLastChar != getDNILetter (iNum)) {
        	ok = false;
        }
    } else {
        sLastChar = getDNILetter (iNum);
        //we modified the dni to add the letter
        s = s + sLastChar;
    }
	
    return ok;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//isPassport(s): Verifica si s es un passporte.
//////////////////////////////////////////////////////////////////////////////////////////////////////
function isPassport(s){
var sLastChar;
var sTmpPassport = null;
var bLastIsChar = false;
var iNum = null;
var ok = true;
    
    sTmpPassport = s.substring(1); // skip the P

    // probe if the rest is a nunmber.
	if (isNaN(sTmpPassport) == true) {
		ok = false;
	} else {
	   	iNum = parseInt(sTmpPassport, 10);	
	}

    // it must be ar least 7 digits else add 0
    if (sTmpPassport.length < 7){
        //add 0 at the begining ..
        var count = 7 - sTmpPassport.length;
        for (var x = 0; x < count; x++) sTmpPassport = "0" + sTmpPassport;
    }
    s = "P" + sTmpPassport;
    return ok;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
// getDNILetter(iNum)
//////////////////////////////////////////////////////////////////////////////////////////////////////
function getDNILetter(iNum){
    var sLetters = "TRWAGMYFPDXBNJZSQVHLCKE";
    var iNumber = parseInt(iNum, 10);
    iNumber = (iNumber % 23);

    return sLetters.charAt (iNumber);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
// isDate(obj): Verifica si el objeto tiene formato de fecha                                    //
//////////////////////////////////////////////////////////////////////////////////////////////////////
function isDate(obj){
	var day="";
	var month="";
	var year="";
	var ok=true;
	var s=obj.value;
	
	s=DeleteWhiteSpace(s,obj);	
	
	//miramos el formato de fecha
	if(s.length==10){ // formato ddmmaa mínimo para tratarlo como una fecha.
		if(s.indexOf("/") == -1){
			if(s.length==6 || s.length==8){
				day=s.substr(0,2);
				month=s.substr(2,2);
				year=s.substr(4,4);
			 } else {
			 	ok=false;
			 }
		} else {
			if((s.indexOf("/") != -1) && (s.lastIndexOf("/") != s.indexOf("/"))){
				day=s.substr(0,(s.indexOf("/")));
				month=s.substr((s.indexOf("/")+1),2);
				if(month.indexOf("/") != -1) {
					month=month.substr(0,1);
				}
				year=s.substr((s.lastIndexOf("/")+1),4);
			} else {
				ok=false;
			}
		}
	} else {
		ok=false;
	}

	if (ok){
		ok=isCorrectDate(obj,day,month,year);		
	}
 
 return ok;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
// isDateHour(obj): Verifica si el objeto tiene formato de fecha y hora                             // 
//////////////////////////////////////////////////////////////////////////////////////////////////////
function isDateHour(obj){
	var day="";
	var month="";
	var year="";
	var hour="";
	var minuts="";
	var shm="";
	var ok=true;
	var s=obj.value;
	
	s=DeleteWhiteSpace(s,obj);	

	//miramos si el formato de hora es correcto.
	if(s.indexOf(" ") != -1){
		shm = s.substring((s.indexOf(" ")+1),s.length);
		shm = DeleteWhiteSpace(shm,obj);
		if(0<shm.length && !isCorrectHour(shm)){ 
			shm = "00:00:00"; 
		}
		s = s.substr(0,(s.indexOf(" ")));
	}
	
	//miramos el formato de fecha
	if(s.length>=6){ // formato ddmmaa mínimo para tratarlo como una fecha.
		if(s.indexOf("/") == -1){
			if(s.length==6 || s.length==8){
				day=s.substr(0,2);
				month=s.substr(2,2);
				year=s.substr(4,4);
			 } else {
			 	ok=false;
			 }
		} else {
			if((s.indexOf("/") != -1) && (s.lastIndexOf("/") != s.indexOf("/"))){
				day=s.substr(0,(s.indexOf("/")));
				month=s.substr((s.indexOf("/")+1),2);
				if(month.indexOf("/") != -1) {
					month=month.substr(0,1);
				}
				year=s.substr((s.lastIndexOf("/")+1),4);
			} else {
				ok=false;
			}
		}
	} else {
		ok=false;
	}

	if (ok){
		ok=isCorrectDate(obj,day,month,year);		
	}

	if(0<shm.length){
		if(shm.indexOf(":") == -1){ 
			shm = shm + ":00:00"; 
		}
		if(shm.lastIndexOf(":") == shm.indexOf(":")){		
			shm = shm + ":00"; 
		}
	} else {
		shm="00:00:00";
	}
	if (ok){
		obj.value = obj.value + " " + shm;
	}
 
 return ok;
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// isCorrectHour(shm): Devuelve true si se trata de una hora tipo: hh:mm y devuelve false en caso contrario. //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isCorrectHour(shm){
	var ok = false;
	var h, m, s;
	
	if(shm.indexOf(":") != -1){
		h = parseInt(shm.substr(0,(shm.indexOf(":"))));
		if(shm.lastIndexOf(":") != shm.indexOf(":")){
			m = parseInt(shm.substring((shm.indexOf(":")+1),shm.lastIndexOf(":")));
			s = parseInt(shm.substring((shm.lastIndexOf(":")+1),shm.length));
			if(!isNaN(h) && 0<=h && h<=23 && !isNaN(m) && 0<=m && m<=59 && !isNaN(s) && 0<=s && s<=59){ 
				ok = true;
			} else { 
				ok = false;
			}
		} else {
			m = parseInt(shm.substring((shm.indexOf(":")+1),shm.length));
			if(!isNaN(h) && 0<=h && h<=23 && !isNaN(m) && 0<=m && m<=59){ 
				ok = true;
			} else { 
				ok = false;
			}
		}
	} else {
		h = parseInt(shm);
		if(!isNaN(h) && 0<=h && h<=23){ 
			ok = true;
		} else { 
			ok = false;
		}
	}
	
	return ok;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// isCorrectDate(obj,day,month,year): Verifica que la fecha sea correcta en base al año bisiesto
/////////////////////////////////////////////////////////////////////////////////////////////////////////
function isCorrectDate(obj,day,month,year){
var daysFebruary;
var daysInMonth = new Array(12);
var ok=true;
	
	daysInMonth[1] = 31;
	daysInMonth[2] = 29;
	daysInMonth[3] = 31;
	daysInMonth[4] = 30;
	daysInMonth[5] = 31;
	daysInMonth[6] = 30;
	daysInMonth[7] = 31;
	daysInMonth[8] = 31;
	daysInMonth[9] = 30;
	daysInMonth[10] = 31;
	daysInMonth[11] = 30;
	daysInMonth[12] = 31;
	
	day=parseFloat(day);
	month=parseFloat(month);
	year=parseFloat(year);

	if((!isNaN(day)) && (!isNaN(month)) && (!isNaN(year))) {
		if(day<=daysInMonth[month]){
			if(parseInt(month)==2){
				daysFebruary=daysInFebruary(year);   
				if(day > daysFebruary){
					ok=false;
				}
			}
			if(day<10) {
				var day="0"+day;
			}
			if(month<10) {
				var month="0"+month;
			}
			obj.value=day+"/"+month+"/"+year;
			
		} else {
			ok=false;
		}
	} else {
		ok=false;
	}
	
	return ok;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////
// daysInFebruary(year): Verifica si year es un año bisiesto y devuelve el número de días.
///////////////////////////////////////////////////////////////////////////////////////////////////////
function daysInFebruary(year){
   // February has 29 days in any year evenly divisible by four,
   // EXCEPT for centurial years which are not also divisible by 400.
	return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

///////////////////////////////////////////////////////////////////////////////////////////////////////
// rankDates(s1,s2): Compara dos fechas, s1 debe ser menor que s2
///////////////////////////////////////////////////////////////////////////////////////////////////////
function rankDates(s1,s2){
var day1="";
var month1="";
var year1="";
var day2="";
var month2="";
var year2="";
var error=false;
	
	day1=s1.substr(0,(s1.indexOf("/")));
	month1=s1.substr((s1.indexOf("/")+1),2);
	if(month1.indexOf("/") != -1){ 
		month1=month1.substr(0,1);
	}
	year1=s1.substr((s1.lastIndexOf("/")+1),4);
	
	day2=s2.substr(0,(s2.indexOf("/")));
	month2=s2.substr((s2.indexOf("/")+1),2);
	if(month2.indexOf("/") != -1) {
		month2=month2.substr(0,1);
	}
	year2=s2.substr((s2.lastIndexOf("/")+1),4);

	day1=parseFloat(day1);
	month1=parseFloat(month1);
	day2=parseFloat(day2);
	month2=parseFloat(month2);

	if(year2<year1) {
		error=false;
	} else {
		if(year2>year1)	{
			error=true;
		} else {
			if(month2<month1) {
				error=false;
			} else {
				if(month2>month1) {
					error=true;
				} else {
					if(day2<day1) { 
						error=false;
					} else {
						error=true;
					}
				}
			}
		}
	}

	return error;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
// isDateHourTo(obj): Verifica si el objeto tiene formato de fecha y hora. Si no se tiene la hora,  //
//                    los minutos y los segundos, le añade la hora 23, los 59 minutos, y 59 segundos//
//                    ; para poder hacer filtros del tipo "Hasta" (<= dd/mm/aa 23:59:59)            // 
//////////////////////////////////////////////////////////////////////////////////////////////////////
function isDateHourTo(obj){
	var day="";
	var month="";
	var year="";
	var hour="";
	var minuts="";
	var shm="";
	var ok=true;
	var s=obj.value;
	
	s=DeleteWhiteSpace(s,obj);	

	//miramos si el formato de hora es correcto.
	if(s.indexOf(" ") != -1){
		shm = s.substring((s.indexOf(" ")+1),s.length);
		shm = DeleteWhiteSpace(shm,obj);
		if(0<shm.length && !isCorrectHour(shm)){ 
			shm = "23:59:59"; 
		}
		s = s.substr(0,(s.indexOf(" ")));
	}
	
	//miramos el formato de fecha
	if(s.length>=6){ // formato ddmmaa mínimo para tratarlo como una fecha.
		if(s.indexOf("/") == -1){
			if(s.length==6 || s.length==8){
				day=s.substr(0,2);
				month=s.substr(2,2);
				year=s.substr(4,4);
			 } else {
			 	ok=false;
			 }
		} else {
			if((s.indexOf("/") != -1) && (s.lastIndexOf("/") != s.indexOf("/"))){
				day=s.substr(0,(s.indexOf("/")));
				month=s.substr((s.indexOf("/")+1),2);
				if(month.indexOf("/") != -1) {
					month=month.substr(0,1);
				}
				year=s.substr((s.lastIndexOf("/")+1),4);
			} else {
				ok=false;
			}
		}
	} else {
		ok=false;
	}

	if (ok){
		ok=isCorrectDate(obj,day,month,year);		
	}

	if(0<shm.length){
		if(shm.indexOf(":") == -1){ 
			shm = shm + ":59:59"; 
		}
		if(shm.lastIndexOf(":") == shm.indexOf(":")){		
			shm = shm + ":59"; 
		}
	} else {
		shm="23:59:59";
	}
	if (ok){
		obj.value = obj.value + " " + shm;
	}
 
 return ok;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////
// isCorrectPasswords(pwd1,pwd2): Comprueba que la contraseña introducida sea mayor de 5 caracteres, //
//                                además que la contraseña introducida 2 veces sea la misma.         //
///////////////////////////////////////////////////////////////////////////////////////////////////////
function isCorrectPasswords(pwd1,pwd2){
var ok=true;

	pwd1 = DeleteWhiteSpace(pwd1.value,pwd1);
	pwd2 = DeleteWhiteSpace(pwd2.value,pwd2);
	
	if (pwd1.length > 4){
		if (pwd1 != pwd2){
			ok = false;
		}
	} else {
		ok = false;
	}
	
	return ok;
}

///////////////////////////////////////////////////////////////////////////
// isURL(s): Verifica si s té una sintaxis correcta de URL               //
///////////////////////////////////////////////////////////////////////////
function isURL(obj){
var ok=false;
var reg = new RegExp("^http[s]?://\w[\.\w]+$", "i");

 if (obj.value.substring(0,4) != "http"){
	 obj.value="http://"+obj.value;
 }
 if(obj.value.search(reg) == -1){
	 ok = true;
 }
 return ok;
}

///////////////////////////////////////////////////////////////////////////
// isImage(s): Verifica si s té una sintaxis de nom de fitxer d'imatge.  //
///////////////////////////////////////////////////////////////////////////
function isImage(s){
	var error=true;
	
	if(s.search(/\w+\.(jpg|gif|png)$/i) == -1){
		error = false;
	}
	
	return error;
} 

///////////////////////////////////////////////////////////////////////////
// isFile(s): Verifica si s té una sintaxis de nom de fitxer vàlid.      //
//            De moment, es comproba que sigui un pdf, .doc o una imatge //
///////////////////////////////////////////////////////////////////////////
function isFile(s){
	var error=true;
	
	if(s.search(/\w+\.(jpg|gif|png|pdf|doc|zip|wav|mp3|mov|flv|mpg)$/i) == -1){
		error = false;
	}
	
	return error;
} 

///////////////////////////////////////////////////////////////////////////
// isDecimal(c): Verifica que c sigui un número, coma o punt per als     //
//               números decimales.                                      //
///////////////////////////////////////////////////////////////////////////
function isDecimal(c){
	return ((c == ".") || (c == ","))
}

///////////////////////////////////////////////////////////////////////////
// isNumber(obj): Verifica que el valor del obj sigui un número.         //
///////////////////////////////////////////////////////////////////////////
function isNumber(obj){
var c;
var ok = true;

	c = obj.value;
	if(c.length==0) {
		ok = false;
	} else {
		for(var i=0;i<c.length;i++)	{   	 
			if(!isDigit(c.substr(i,1)))	{
				if(!isDecimal(c.substr(i,1))){
					ok = false;
				}
			}
		}
	}
	return ok;	
}

////////////////////////////////////////////////////////////////
// isCodPostal(c): Verifica que c sigui un codi postal vàlid. //
////////////////////////////////////////////////////////////////
function isCodPostal(c){
	if(!isNaN(c) && c.length==5) return true;
	else return false;
}

///////////////////////////////////////////////////////////////////////////
//  ****** Funcions específiques per a la nova plana del TNC  ********   //
///////////////////////////////////////////////////////////////////////////



/********************************************************
	Aquesta funció mostra tots els métodes i les 
	propietats de l'objecte que rep com a paràmetre
*********************************************************/
function muestra_metodos(objeto,blanco)
{
 /*
   Aquesta funció imprimeix per pantalla, totes les propietats de l'objecte que li passem com a paràmetre
 */	
   for (var i in objeto)
   {
      if (parent)
	  {
             var msg = parent + "." + i + "\n" + objeto[i]; } else { var msg = i + "\n" + objeto[i];
	  }
      document.write(msg + "<br /><br />");
      // Si la propietat(i) és un objecte, processa recursivament l'objecte 
      if (typeof objeto[i] == "object")
      { 
         if (parent)
	 { 
	   muestra_metodos(objeto[i], parent + "." + i); } else { muestra_metodos(objeto[i], i);
	 }
      }
   }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////
// isCarnetConnectat(objForm): comproba que el nº de carnet es vàlid   XXXXX-XX                         //
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function isCarnetConnectat(objForm){
 var ok=true;
 
 // El codi ha de ser numèric
 if (isNumber(objForm.id)) {
 	var codi=objForm.id.value; // Nº de codi
 	var clau=objForm.id2.value;
	
	// Generem el número de carnet a partir del codi i la fórmula.
	var carnet=decHex((Math.pow(parseInt(codi/100),3)+Math.pow((codi%100),2))%63);
	
	if (clau.length != 0){
 		// Si els dos números coincideixen, la clau es correcte
		if (clau.toUpperCase()!=carnet.toUpperCase()){
			ok=false;
		}	
 	} else {
  		ok=false;
 	}
 } else {
 	ok=false;
 }
 
 return ok;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////
// decHex(num): converteix a hexadecimal el número que se li pasa                                        //
///////////////////////////////////////////////////////////////////////////////////////////////////////////
function decHex(num){
 var hexadecimal = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F")
 var hexaDec = Math.floor(num/16);
 var hexaUni = num - (hexaDec * 16);
 
 return hexadecimal[hexaDec] + hexadecimal[hexaUni];
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////
// validateForm(form): valida formulario																//
//////////////////////////////////////////////////////////////////////////////////////////////////////////

function validateForm(form){

	if( isEmptyNotWhiteSpace(form.nombre.value,form.nombre) ||
		isEmptyNotWhiteSpace(form.empresa.value,form.empresa) ||
		isEmptyNotWhiteSpace(form.email.value,form.email) ||
		isEmptyNotWhiteSpace(form.comentario.value,form.comentario)
	  ){
						
			if(form.lang.value == "cat") alert("Cal omplir tots els camps obligatoris");
			else if(form.lang.value == "cas") alert("Debe completar todos los campos obligatorios");
			else if(form.lang.value == "eng") alert ("You must complete all required fields");
	}
	else{
				
		if(isMail(form.email)) form.submit();
		else{
			  if(form.lang.value == "cat") alert("Cal introduir una adre\u00e7a de correu v\u00e0lida");
			  else if(form.lang.value == "cas") alert("Debe introducir una direcci\u00f3n de correo electr\u00f3nico v\u00e1lida");
			  else if(form.lang.value == "eng") alert ("You must enter a valid e-mail address");
			  
			  form.email.focus();
		}
	}
}
