			jQuery.validator.setDefaults({
				success: "valid"
			});			
			
			function comprovadni(dni) {
				
				dni = dni.replace(/\./g, '');
				dni = dni.replace(/-/g, '').toUpperCase();
				var regex = new RegExp('^[0-9]{8}[TRWAGMYFPDXBNJZSQVHLCKE]$')
				if(!regex.test(dni)) return false;
				numero = dni.substr(0,dni.length-1);
				let = dni.substr(dni.length-1,1);
				numero = numero % 23;
				letra='TRWAGMYFPDXBNJZSQVHLCKET';
				letra=letra.substring(numero,numero+1);
				return letra==let;
			}

			function comprovanie(nie) {
				lletraPrimera = nie.substr(0, 1).toUpperCase();
				var numeroSubstituir;
				switch(lletraPrimera){
					case 'X':
						numeroSubstituir = '0';
						break;
					case 'Y':
						numeroSubstituir = '1';
						break;
					case 'Z':
						numeroSubstituir = '2';
						break;
				}
				restaEsDniNie = nie.substr(1, nie.length);
				return ((lletraPrimera=='X' || lletraPrimera=='Y' || lletraPrimera=='Z') && comprovadni(numeroSubstituir + restaEsDniNie));
			}
			
			function comprovacif(cif) {
				par = 0
				non = 0
				letras="ABCDEFGHKLMNPQS"
				let=cif.charAt(0)
				
				if (cif.length!=9){
					return false
				}
				if (letras.indexOf(let.toUpperCase())==-1){
					return false
				}


				for (zz=2;zz<8;zz+=2){
					par = par+parseInt(cif.charAt(zz))
				}

				for (zz=1;zz<9;zz+=2){
					nn = 2*parseInt(cif.charAt(zz))
					if (nn > 9) nn = 1+(nn-10)
						non = non+nn
				}

				parcial = par + non
				control = (10 - ( parcial % 10))
				if (control!=cif.charAt(8)){
					return false
				}
				return true;
			}
			
			function comprovadnicontrol(dni, opcional) {
				dni = dni.replace(/\./g, '');
				dni = dni.replace(/-/g, '').toUpperCase();
				if(dni.length == 8 && opcional){
					var regex = new RegExp('^[0-9]{8}$')
					return(regex.test(dni));
				}else if(dni.length == 9){
					var regex = new RegExp('^[0-9]{8}[TRWAGMYFPDXBNJZSQVHLCKE]$')
					if(!regex.test(dni)) return false;
					numero = dni.substr(0,dni.length-1);
					let = dni.substr(dni.length-1,1);
					numero = numero % 23;
					letra='TRWAGMYFPDXBNJZSQVHLCKET';
					letra=letra.substring(numero,numero+1);
					return letra==let;
				}
				return false;
			}
			
			//DNI
			jQuery.validator.addMethod("dni", function(value, element) {
				return this.optional(element) || comprovadni(value);
			});
			
			//NIE
			jQuery.validator.addMethod("nie", function(value, element) {
				return this.optional(element) || comprovanie(value);
			});
			
			//DNI + NIE
			jQuery.validator.addMethod("dninie", function(value, element) {
				return this.optional(element) || comprovadni(value) || comprovanie(value);
			});
			
			//CIF
			jQuery.validator.addMethod("cif", function(value, element) {
				return this.optional(element) || comprovacif(value);
			});
			
			// DNI AMB LA LLETRA OPCIONAL
			jQuery.validator.addMethod("dnicontrol", function(value, element) {
				return this.optional(element) || comprovadnicontrol(value, $(element).hasClass('LletraOpcional'));
			});
			
			function comprovatelefon(telefon) {
			  var ereg = new RegExp(/^[0-9\+\ \(\)\-]{9,23}$/)
			  return ereg.test(telefon);
			}
			
			jQuery.validator.addMethod("telefon", function(value, element) {
				return this.optional(element) || comprovatelefon(value);
			});
			
			function comprovatelefonchi(telefon) {
			  var ereg = new RegExp(/^[0-9\+\ \(\)\-]{7,23}$/)
			  return ereg.test(telefon);
			}
			
			jQuery.validator.addMethod("telefon_chi", function(value, element) {
				return this.optional(element) || comprovatelefonchi(value);
			});
			
			function comprovatelefonmvlchi(telefon) {
				telefon = telefon.replace('.','').replace('/','').replace('-','').replace(' ','');
				
				var ereg = new RegExp(/^[0-9]{8,9}$/)
				return ereg.test(telefon);
			}
			
			jQuery.validator.addMethod("telefon_mvl_chi", function(value, element) {
				return this.optional(element) || comprovatelefonmvlchi(value);
			});
			
			jQuery.validator.addMethod("telefon_es_fix", function(value, element) {
				return this.optional(element) || comprovatelefonesfix(value);
			});
			
			jQuery.validator.addMethod("telefon_es_mbl", function(value, element) {
				return this.optional(element) || comprovatelefonesmbl(value);
			});
			
			jQuery.validator.addMethod("telefon_es_fix_mbl", function(value, element) {
				return this.optional(element) || comprovatelefonesfix(value) || comprovatelefonesmbl(value);
			});
			
			jQuery.validator.addMethod("emailnote", function(value, element, param) {
				return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value) || jQuery.inArray(value.toUpperCase(), param) != -1;
			});
			
			jQuery.validator.addMethod("telefon_multi", function(value, element, param) {
				if(this.optional(element)) return true;
				var Opcions = String(param).split(',');
				for(var k in Opcions){
					switch(Opcions[k]){
						case 'INT':
							if(comprovatelefoninternacional(value)){
								return true;
							}
							break;
						case 'FIXES':
							if(comprovatelefonesfix(value)){
								return true;
							}
							break;
						case 'FIXCHI':
							if(comprovatelefonchi(value)){
								return true;
							}
							break;
						case 'MBLES':
							if(comprovatelefonesmbl(value)){
								return true;
							}
							break;
						case 'MBLCHI':
							if(comprovatelefonmvlchi(value)){
								return true;
							}
							break;
					}
				}
				return false;
			});
			
			function comprovatelefoninternacional(telefon){	
				telefon = telefon.replace(/[\. \(\)\+\-]/g,'');
				var ereg = new RegExp(/^00[0-9]{8,}$/)
				return ereg.test(telefon);
			}
			
			function comprovatelefonesfix(telefon){
				telefon = telefon.replace(/[\. \(\)\+\-]/g,'');
				var ereg = new RegExp(/^[89][0-9]{8}$/)
				return ereg.test(telefon);
			}
			
			function comprovatelefonesmbl(telefon){
				telefon = telefon.replace(/[\. \(\)\+\-]/g,'');
				var ereg = new RegExp(/^[67][0-9]{8}$/)
				return ereg.test(telefon);
			}
			
			function isInteger(s){
				var i;
				for (i = 0; i < s.length; i++){   
					// Check that current character is number.
					var c = s.charAt(i);
					if (((c < "0") || (c > "9"))) return false;
				}
				// All characters are numbers.
				return true;
			}
			function stripCharsInBag(s, bag){
				var i;
				var returnString = "";
				// Search through string's characters one by one.
				// If character is not in bag, append to returnString.
				for (i = 0; i < s.length; i++){   
					var c = s.charAt(i);
					if (bag.indexOf(c) == -1) returnString += c;
				}
				return returnString;
			}
			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 );
			}
			function DaysArray(n) {
				for (var i = 1; i <= n; i++) {
					this[i] = 31
					if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
					if (i==2) {this[i] = 29}
			   } 
			   return this
			}
			
			function isDate(dtStr){
				var dtCh = '/';
				var minYear = 1900;
				var maxYear = 2100;
				var daysInMonth = DaysArray(12)
				var pos1=dtStr.indexOf(dtCh)
				var pos2=dtStr.indexOf(dtCh,pos1+1)
				var strDay=dtStr.substring(0,pos1)
				var strMonth=dtStr.substring(pos1+1,pos2)
				var strYear=dtStr.substring(pos2+1)
				strYr=strYear
				if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
				if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
				for (var i = 1; i <= 3; i++) {
					if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
				}
				month=parseInt(strMonth)
				day=parseInt(strDay)
				year=parseInt(strYr)
				if (pos1==-1 || pos2==-1){
					//alert("The date format should be : dd/mm/yyyy")
					return false
				}
				if (strMonth.length<1 || month<1 || month>12){
					//alert("Please enter a valid month")
					return false
				}
				if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
					//alert("Please enter a valid day")
					return false
				}
				if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
				//if (strYear.length != 4 || year==0 ){
					//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
					return false
				}
				if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
					//alert("Please enter a valid date")
					return false
				}
			return true
			}

			jQuery.validator.addMethod("data", function(value, element) {
				//return this.optional(element) || /^(?:(?:(?:0?[1-9]|1\d|2[0-8])\/(?:0?[1-9]|1[0-2]))\/(?:(?:1[6-9]|[2-9]\d)\d{2}))$|^(?:(?:(?:31\/0?[13578]|1[02])|(?:(?:29|30)\/(?:0?[1,3-9]|1[0-2])))\/(?:(?:1[6-9]|[2-9]\d)\d{2}))$|^(?:29\/0?2\/(?:(?:(?:1[6-9]|[2-9]\d)(?:0[48]|[2468][048]|[13579][26]))))$/.test(value);
				if(value == "__/__/____")element.value="";
				return this.optional(element) || isDate(value);				
			});
			
			function comprovarut(value){
				if(value.length < 8 || value.length > 10) return false;
				if(value.lastIndexOf('-') != -1 && value.lastIndexOf('-') != value.length-2) return false; 

				value = value.replace('-', '').replace(' ', '').replace('/', '').toUpperCase();
				numero = value.substr(0,value.length-1);
				digitcomprovacio = value.substr(value.length-1,1);
				
				var mult = 2;
				var suma = 0;
				var resultat;
				for(var i = numero.length - 1; i >= 0; i--){
					if(mult > 7) mult = 2;
					suma += mult * numero.substr(i, 1);
					mult++;					
				}
				
				resultat = 11 - (suma % 11);
				if(resultat == 11){
					resultat = "0";
				}else if(resultat == 10){
					resultat = "K";
				}
				
				return resultat == digitcomprovacio;
			}
			
			jQuery.validator.addMethod("rut", function(value, element) {
				return this.optional(element) || comprovarut(value);
			});
			
			function comprovastring(value){
				
				var ereg = new RegExp(/[0-9]+/)
				if(ereg.test(value)) return false;
				
				var ereg = new RegExp(/^[-,\.;\\\'\/áàâãäªÁÀÄéèêëÉÈÊËíìîïÍÌÎÏòóôõöºÓÒÔÕÖúùûüÚÙÛÜçÇÑñ\w ]+$/)
				if(!ereg.test(value)) return false;
				
				return true;
			}
			
			jQuery.validator.addMethod("string", function(value, element) {
				return this.optional(element) || comprovastring(value);
			});
			
			
			function comprovastring_especial(value){
				var ereg = new RegExp(/^[a-zA-Z\'\-,áàâãäªÁÀÄéèêëÉÈÊËíìîïÍÌÎÏòóôõöºÓÒÔÕÖúùûüÚÙÛÜçÇÑñ ]+$/);
				if(!ereg.test(value)) return false;
				return true;
			}
			
			jQuery.validator.addMethod("string_especial", function(value, element) {
				return this.optional(element) || comprovastring_especial(value);
			});
			
			// CODI POSTAL ESPANYA + ANDORRA
			function comprovacpandorra(cp){
				
				var comp1 = false;
				var comp2 = false;
				
				var ereg1 = new RegExp(/^([1-9]{2}|[0-9][1-9]|[1-9][0-9])[0-9]{3}$/);
				comp1 = ereg1.test(cp);
				
				var ereg2 = new RegExp(/^(AD|ad)[0-9]{3}$/)
				comp2 = ereg2.test(cp);
				
				return (comp1 == true || comp2 == true);
			}
			jQuery.validator.addMethod("cpandorra", function(value, element) {
				return this.optional(element) || comprovacpandorra(value);
			});
			
			
			function comprovadatahora(value){
				var data;
				var hora;
				data = value.substring(0, 10);
				
				data = data.substring(8,10) + '/' + data.substring(5,7) + '/' + data.substring(0,4);
				hora = value.substring(11);
				return isDate(data) && esHora(hora);	
			}
			
			function esHora(valor){
				var hora;
				var minut;
				var segon;
				
				if(!/^(([0-9]{1,4})|[0-9]{1,2}\:[0-9]{2})$/.test(valor)) return false;
				valor = valor.replace(':', '').substring(0,4);
				if(valor.length < 3){
					valor = valor + '00';
				}
				valor = '0000' + valor;
				hora = valor.substring(valor.length - 4, valor.length - 2);
				minut = valor.substring(valor.length - 2, valor.length);
				if(hora < 0 || hora > 23) return false;
				if(minut < 0 || minut > 59) return false;				
				return true;
			}
			
			jQuery.validator.addMethod("datahora", function(value, element) {
				if(value == "____-__-__ __:__")element.value="";
				return this.optional(element) || comprovadatahora(value);
			});
			
			function comprovaLlistaEmails(value){
				var retorn = true;
				var emails = value.split(',');
				for (var i = 0; i < emails.length; i++){
					retorn = retorn && /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(emails[i]);
				}
				return retorn;
				
			}
			
			jQuery.validator.addMethod("llistaemails", function(value, element) {
				return this.optional(element) || comprovaLlistaEmails(value);
			});
			
			function comprovamovil(value){
				value = value.replace('.','').replace('/','').replace('-','').replace(' ','');
				var ereg = new RegExp(/^(34|)(6|7){1}[0-9]{8}$/);
				if(!ereg.test(value)) return false;
				return true;
			}
			
			jQuery.validator.addMethod("movil", function(value, element) {
				return this.optional(element) || comprovamovil(value);
			});
			
			jQuery.validator.addMethod("importdec", function(value, element) {
				return this.optional(element) || /^([0-9]+)?([,\.]([0-9]{1,2})?)?$/.test(value);
			});
			
			jQuery.validator.addMethod("importdecn", function(value, element) {
				return this.optional(element) || /^([+-]?[0-9]+)?([,\.]([0-9]{1,2})?)?$/.test(value);
			});
			
			jQuery.validator.addMethod("importenter", function(value, element) {
				return this.optional(element) || /^[0-9]+$/.test(value);
			});
			
			jQuery.validator.addMethod("importentern", function(value, element) {
				return this.optional(element) || /^[+-]?[0-9]+$/.test(value);
			});
			
			jQuery.validator.addMethod("hora", function(value, element) {
				return this.optional(element) || esHora(value);
			});
			
			jQuery.validator.addMethod("datacontrol", function(value, element) {
				value = DonaDataSegonsValor(value);
				return this.optional(element) || isDate(value);
			});
			
			jQuery.validator.addMethod("numcompte", function(value, element) {
				var Identf = $(element).attr('id').slice(0,-2); // Trec el "_X"
				var Entitat = $('#' + Identf + '_0').val();
				var Oficina = $('#' + Identf + '_1').val();
				var DC = $('#' + Identf + '_2').val();
				var NumCompte = $('#' + Identf + '_3').val();
				return this.optional(element) || (DC == CalculDigitControl(Entitat, Oficina, NumCompte));
			});
			
			jQuery.validator.addMethod("rangdata", function(value, element, param) {
				value = DonaDataSegonsValor(value);
				var okMinim = true;
				var okMaxim = true;				
				if(isDate(param[0]) && isDate(value)){
					if(CompararDates(value, param[0]) < 0){
						okMinim = false;
					}
				}
				if(isDate(param[1]) && isDate(value)){
					if(CompararDates(value, param[1]) > 0){
						okMaxim = false;
					}
				}
				return this.optional(element) || (okMinim && okMaxim);
			});
			
			function Formatejar(valor, num){
				valor = Array(num).join('0') + valor;
				var iLen = valor.length;
				return valor.substring(iLen, iLen - num);
			}
			
			function CompararDates(data1, data2){
				d1 = new Date(StrToData(data1));
				d2 = new Date(StrToData(data2));
				return d1 - d2;
			}
			
			function StrToData(str){
				var retorn=new Date();
				valors = str.split(/[\/]/);
				retorn.setFullYear(parseInt(valors[2], 10), parseInt(valors[1], 10) - 1,parseInt(valors[0], 10));
				return retorn;
			}
			
			function DonaDataSegonsValor(value){
				var lngDia;
				var lngMes;
				var lngAny;
				
				var currentTime = new Date();
				
				lngDia = '';
				lngMes = currentTime.getMonth() + 1;
				lngAny = currentTime.getFullYear()

				if(/^[0-9]{1,2}$/.test(value)){
					lngDia = parseInt(value, 10);
					if(lngDia < currentTime.getDate()){
						currentTime.setMonth(currentTime.getMonth() + 1 );
						
						lngMes = currentTime.getMonth() + 1;
						lngAny = currentTime.getFullYear()
					}
				}
				
				if(/^[0-9]{1,2}[\-\/][0-9]{1,2}$/.test(value)){
					valors = value.split(/[\-\/]/);
					lngDia = parseInt(valors[0], 10);
					lngMes = parseInt(valors[1], 10);
				}
				
				if(/^[0-9]{4}$/.test(value)){
					lngDia = parseInt(value.substring(0, 2), 10);
					lngMes = parseInt(value.substring(2, 4), 10);
				}
				
				if(/^[0-9]{1,2}[\-\/][0-9]{1,2}[\-\/][0-9]{2}$/.test(value)){
					valors = value.split(/[\-\/]/);
					lngDia = parseInt(valors[0], 10);
					lngMes = parseInt(valors[1], 10);
					var intAny = parseInt(valors[2], 10);
					if((intAny + 2000 - 10) > lngAny){ // 10 anys de marge
						lngAny = 1900 + intAny;
					}else{
						lngAny = 2000 + intAny;
					}
				}
				
				if(/^[0-9]{1,2}[\-\/][0-9]{1,2}[\-\/][0-9]{4}$/.test(value)){
					valors = value.split(/[\-\/]/);
					lngDia = parseInt(valors[0], 10);
					lngMes = parseInt(valors[1], 10);
					lngAny = parseInt(valors[2], 10);
				}
				
				if(/^[0-9]{4}[\-\/][0-9]{1,2}[\-\/][0-9]{1,2}$/.test(value)){
					valors = value.split(/[\-\/]/);
					lngDia = parseInt(valors[2], 10);
					lngMes = parseInt(valors[1], 10);
					lngAny = parseInt(valors[0], 10);
				}
				
				if(/^[0-9]{6}$/.test(value)){
					lngDia = parseInt(value.substring(0, 2), 10);
					lngMes = parseInt(value.substring(2, 4), 10);
					var intAny = parseInt(value.substring(4, 6), 10);
					if((intAny + 2000 - 10) > lngAny){ // 10 anys de marge
						lngAny = 1900 + intAny;
					}else{
						lngAny = 2000 + intAny;
					}
				}				
				
				if(/^[0-9]{8}$/.test(value)){
					lngDia = parseInt(value.substring(0, 2), 10);
					lngMes = parseInt(value.substring(2, 4), 10);					
					lngAny = parseInt(value.substring(4, 8), 10);
				}
				if(lngDia != ''){
					value = Formatejar(lngDia, 2) + '/' + Formatejar(lngMes, 2) + '/' + Formatejar(lngAny, 4);
				}
				return value;
			}
			
			jQuery.fn.SetValor = function(valor)
			{
				var processat = false;
				if(jQuery(this).hasClass('PWTextBoxMonedaDecimal')){
					processat = true;
					SetValorMonedaDecimal(jQuery(this), valor);
				}
				if(jQuery(this).hasClass('PWTextBoxMonedaEnter')){
					processat = true;
					SetValorMonedaNoDecimal(jQuery(this), valor);
				}
				if(jQuery(this).hasClass('PWComboBox') || jQuery(this).hasClass('PWComboBoxIntern')){
					processat = true;
					SetValorComboBox(jQuery(this), valor);
				}
				if(jQuery(this).hasClass('PWTextBoxText') || jQuery(this).hasClass('PWTextBoxTextIntern') || 
					jQuery(this).hasClass('PWTextArea') || jQuery(this).hasClass('PWHidden') ||
					jQuery(this).hasClass('PWTextBoxTelefon') || jQuery(this).hasClass('PWTextBoxEmail') ||
					jQuery(this).hasClass('PWTextBoxHora') || jQuery(this).hasClass('PWTextBoxPassword')){
					processat = true;
					SetValorTextBoxText(jQuery(this), valor);
				}
				if(jQuery(this).hasClass('PWTextBoxNumeric') || jQuery(this).hasClass('PWTextBoxNumericIntern')){
					processat = true;
					SetValorTextBoxNumeric(jQuery(this), valor);
				}
				if(jQuery(this).hasClass('PWTextBoxData')){
					processat = true;
					SetValorTextBoxData(jQuery(this), valor);
				}
				if(jQuery(this).hasClass('PWCheckBox')){
					processat = true;
					SetValorCheckBox(jQuery(this), valor);
				}
				if(jQuery(this).hasClass('PWTextBoxDocumentsIdentificatius')){
					processat = true;
					SetValorTextBoxDocumentsIdentificatius(jQuery(this), valor);
				}
				if(jQuery(this).hasClass('PWTextBoxNumeroCompte')){
					processat = true;
					SetValorTextBoxNumeroCompte(jQuery(this), valor);
				}
				if(jQuery(this).hasClass('PWListBox')){
					processat = true;
					SetValorListBox(jQuery(this), valor);
				}
				if(jQuery(this).hasClass('PWOptionList')){
					processat = true;
					SetValorOptionList(jQuery(this), valor);
				}
				if(jQuery(this).hasClass('PWCheckBoxList')){
					processat = true;
					SetValorCheckBoxList(jQuery(this), valor);
				}
				if(!processat){alert('SET VALOR: No implementado ' + jQuery(this).attr('id'));}
				else{jQuery(this).trigger('blur');}
				return this;
			}
			
			jQuery.fn.GetValor = function(opcio)
			{
				if(jQuery(this).hasClass('PWTextBoxMonedaDecimal')){
					return GetValorMonedaDecimal(jQuery(this));
				}
				if(jQuery(this).hasClass('PWTextBoxMonedaEnter')){
					return GetValorMonedaNoDecimal(jQuery(this));
				}
				if(jQuery(this).hasClass('PWComboBox') || jQuery(this).hasClass('PWComboBoxIntern')){
					processat = true;
					return GetValorComboBox(jQuery(this));
				}
				if(jQuery(this).hasClass('PWTextBoxText') || jQuery(this).hasClass('PWTextBoxTextIntern') || 
					jQuery(this).hasClass('PWTextArea') || jQuery(this).hasClass('PWHidden') ||
					jQuery(this).hasClass('PWTextBoxTelefon') || jQuery(this).hasClass('PWTextBoxEmail') ||
					jQuery(this).hasClass('PWTextBoxHora') || jQuery(this).hasClass('PWTextBoxPassword')){
					
					processat = true;
					return GetValorTextBoxText(jQuery(this));
				}
				if(jQuery(this).hasClass('PWTextBoxNumeric') || jQuery(this).hasClass('PWTextBoxNumericIntern')){
					processat = true;
					return GetValorTextBoxNumeric(jQuery(this));
				}
				if(jQuery(this).hasClass('PWTextBoxData')){
					processat = true;
					return GetValorTextBoxData(jQuery(this));
				}
				if(jQuery(this).hasClass('PWCheckBox')){
					processat = true;
					return GetValorCheckBox(jQuery(this));
				}
				if(jQuery(this).hasClass('PWTextBoxDocumentsIdentificatius')){
					processat = true;
					return GetValorTextBoxDocumentsIdentificatius(jQuery(this), opcio);
				}
				if(jQuery(this).hasClass('PWTextBoxNumeroCompte')){
					processat = true;
					return GetValorTextBoxNumeroCompte(jQuery(this), opcio);
				}
				if(jQuery(this).hasClass('PWListBox')){
					processat = true;
					return GetValorListBox(jQuery(this));
				}
				if(jQuery(this).hasClass('PWOptionList')){
					processat = true;
					return GetValorOptionList(jQuery(this));
				}
				if(jQuery(this).hasClass('PWCheckBoxList')){
					processat = true;
					return GetValorCheckBoxList(jQuery(this));
				}
				alert('GET VALOR: No implementado ' + jQuery(this).attr('id'));
				return '';
			}
			
			jQuery.fn.DeshabilitarForm = function()
			{
				if(jQuery(this).find('[name=deshabilitat]').size() == 0){
					var e = $('<input type="hidden" name="deshabilitat" value="s" />');
					jQuery(this).append(e);
					return true;
				}
				return false;
			}
			
			jQuery.fn.HabilitarForm = function()
			{
				if(jQuery(this).find('[name=deshabilitat]').size() > 0){
					jQuery(this).find('[name=deshabilitat]').remove();
					return true;
				}
				return false;
			}
			
			jQuery.fn.HiHaCanvis = function()
			{
				var retorn = false;
				if(this.get(0).tagName.toLowerCase() == 'form'){
					jQuery(this).find('.PWCheckBox, .PWCheckBoxList, .PWComboBox, .PWHidden, ' +
					'.PWListBox, .PWOptionList, .PWTextArea, .PWTextBoxData, .PWTextBoxDocumentsIdentificatius, ' +
					'.PWTextBoxEmail, .PWTextBoxHora, .PWTextBoxMoneda, .PWTextBoxNumeric, .PWTextBoxNumeroCompte, ' +
					'.PWTextBoxTelefon, .PWTextBoxText, .PWTextBoxPassword').each(function(){
						if(jQuery(this).HiHaCanvis()){
							retorn = true;
						}
					});
					return retorn;
				}else{
					return !CompararValors(jQuery(this).data('ValorInici'), jQuery(this).GetValor());
				}
			}
			
			jQuery.fn.DonaCanvis = function()
			{
				var retorn = [];
				if(this.get(0).tagName.toLowerCase() == 'form'){
					jQuery(this).find('.PWCheckBox, .PWCheckBoxList, .PWComboBox, .PWHidden, ' +
					'.PWListBox, .PWOptionList, .PWTextArea, .PWTextBoxData, .PWTextBoxDocumentsIdentificatius, ' +
					'.PWTextBoxEmail, .PWTextBoxHora, .PWTextBoxMoneda, .PWTextBoxNumeric, .PWTextBoxNumeroCompte, ' +
					'.PWTextBoxTelefon, .PWTextBoxText, .PWTextBoxPassword').each(function(){
						if(jQuery(this).HiHaCanvis()){
							retorn[retorn.length] = jQuery(this).DonaCanvis();
						}
					});
				}else{
					if(jQuery(this).HiHaCanvis()){
						retorn = [jQuery(this).attr('id'), jQuery(this).data('ValorInici'), jQuery(this).GetValor()];
					}
				}
				return retorn;
			}

			jQuery.fn.Reset = function()
			{
				var retorn = false;
				if(this.get(0).tagName.toLowerCase() == 'form'){
					jQuery(this).find('.PWCheckBox, .PWCheckBoxList, .PWComboBox, .PWHidden, ' +
					'.PWListBox, .PWOptionList, .PWTextArea, .PWTextBoxData, .PWTextBoxDocumentsIdentificatius, ' +
					'.PWTextBoxEmail, .PWTextBoxHora, .PWTextBoxMoneda, .PWTextBoxNumeric, .PWTextBoxNumeroCompte, ' +
					'.PWTextBoxTelefon, .PWTextBoxText, .PWTextBoxPassword').each(function(){
						jQuery(this).Reset();
					});
					return retorn;
				}else{
					return jQuery(this).SetValor(jQuery(this).data('ValorInici'));
				}
			}
			
			function CalculaLletraDni(NumDni) {
				RestaDiv  = NumDni % 23;
				Lletres	  = 'TRWAGMYFPDXBNJZSQVHLCKET';
				LletraDni = Lletres.substring(RestaDiv, RestaDiv + 1);
				return LletraDni;
			}
			
			function CalculDigitControl(Entitat, Oficina, NumCompte){
				Entiat = Right(repeat('0', 4) + Entitat, 4);
				Oficina = Right(repeat('0', 4) + Oficina, 4);
				NumCompte = Right(repeat('0', 10) + NumCompte, 10);
				
				EntitatOficina = '00' + Entitat + Oficina;
				return obtenerDigito(EntitatOficina) + obtenerDigito(NumCompte);
			}
			
			function obtenerDigito(valor){
				valores = new Array(1, 2, 4, 8, 5, 10, 9, 7, 3, 6);
				control = 0;
				for (i=0; i<=9; i++)
				  control += parseInt(valor.charAt(i)) * valores[i];
				control = 11 - (control % 11);
				if (control == 11) control = 0;
				else if (control == 10) control = 1;
				return control.toString();
			}
			
			function ArrayCompare(a, b) {
				if (a.length != b.length) { return false; }
				a = a.sort();
				b = b.sort();
				for (var i = 0; i < a.length; i++) {
					if (a[i] !== b[i]) { 
						return false;
					}
				}
				return true;
			};
			
			function CompararValors(a, b){
					
				if($.isArray(a) && $.isArray(b)){
					return ArrayCompare(a, b);
				}else if(!$.isArray(a) && !$.isArray(b)){
					return a == b;
				}else{
					return false;
				}
			};

/*
 * jQuery Watermark plugin
 * Version 1.2 (7-DEC-2010)
 * @requires jQuery v1.3 or later
 *
 * Examples at: http://mario.ec/static/jq-watermark/
 * Copyright (c) 2010 Mario Estrada
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
(function(a){var k=a.browser.msie&&a.browser.version<8;a.watermarker=function(){};a.extend(a.watermarker,{defaults:{color:"#999",left:0,top:0,fallback:false,animDuration:300,minOpacity:0.6},setDefaults:function(e){a.extend(a.watermarker.defaults,e)},checkVal:function(e,c){e.length==0?a(c).show():a(c).hide();return e.length>0},html5_support:function(){return"placeholder"in document.createElement("input")}});a.fn.watermark=function(e,c){var i;c=a.extend(a.watermarker.defaults,c);i=this.filter("textarea, input:not(:checkbox,:radio,:file,:submit,:reset)");
if(!(c.fallback&&a.watermarker.html5_support())){i.each(function(){var b,f,j,g,d,h=0;b=a(this);if(b.attr("data-jq-watermark")!="processed"){f=b.attr("placeholder")!=undefined&&b.attr("placeholder")!=""?"placeholder":"title";j=e===undefined||e===""?a(this).attr(f):e;g=a('<span class="watermark_container"></span>');d=a('<span class="watermark">'+j+"</span>");f=="placeholder"&&b.removeAttr("placeholder");g.css({display:"inline-block",position:"relative"});k&&g.css({zoom:1,display:"inline"});b.wrap(g).attr("data-jq-watermark",
"processed");if(this.nodeName.toLowerCase()=="textarea"){e_height=b.css("line-height");e_height=e_height==="normal"?parseInt(b.css("font-size")):e_height;h=b.css("padding-top")!="auto"?parseInt(b.css("padding-top")):0}else{e_height=b.outerHeight();if(e_height<=0){e_height=b.css("padding-top")!="auto"?parseInt(b.css("padding-top")):0;e_height+=b.css("padding-bottom")!="auto"?parseInt(b.css("padding-bottom")):0;e_height+=b.css("height")!="auto"?parseInt(b.css("height")):0}}h+=b.css("margin-top")!="auto"?
parseInt(b.css("margin-top")):0;f=b.css("margin-left")!="auto"?parseInt(b.css("margin-left")):0;f+=b.css("padding-left")!="auto"?parseInt(b.css("padding-left")):0;d.css({position:"absolute",display:"block",fontFamily:b.css("font-family"),fontSize:b.css("font-size"),color:c.color,left:4+c.left+f,top:c.top+h,height:e_height,lineHeight:e_height+"px",textAlign:"left",pointerEvents:"none"}).data("jq_watermark_element",b);a.watermarker.checkVal(b.val(),d);d.click(function(){a(a(this).data("jq_watermark_element")).trigger("focus")});
b.before(d).bind("focus.jq_watermark",function(){a.watermarker.checkVal(a(this).val(),d)||d.stop().fadeTo(c.animDuration,c.minOpacity)}).bind("blur.jq_watermark change.jq_watermark",function(){a.watermarker.checkVal(a(this).val(),d)||d.stop().fadeTo(c.animDuration,1)}).bind("keydown.jq_watermark",function(){a(d).hide()}).bind("keyup.jq_watermark",function(){a.watermarker.checkVal(a(this).val(),d)})}});return this}};a(document).ready(function(){a(".jq_watermark").watermark()})})(jQuery);
