	function jsTrim(str){
	// Elimina los espacios de inicio y final de una cadena de caracteres
		for(var i=0; i<str.length;)	{
			if(str.charAt(i)==" ")
				str=str.substring(i+1, str.length);
			else
				break;
		}
	
		for(var i=str.length-1; i>=0; i=str.length-1){
			if(str.charAt(i)==" ")
				str=str.substring(0,i);
			else
				break;
		}
		return str;
	}
	
	function quitarEspacios(str){
	// Elimina los espacios interiores sobrantes de una cadena
		var aux = "";
		for(var i=0; i<str.length; i++){
			if(str.charAt(i)!=" " || (str.charAt(i)==" " && str.charAt(i-1)!=" "))
				aux+= str.charAt(i);
		}
		return aux;
	}
	
	function validar(f){
	// Validación genérica de formularios para campos text, password y textArea
	// Utiliza las propiedades del formulario: name, type, title, maxlength
		for(var n=0; n<f.elements.length; n++){
		
			if((f.elements[n].type == "text") || (f.elements[n].type == "password") || (f.elements[n].type == "textarea")){
			
				var tipoCampo = f.elements[n].name.substring(0,3);
				var obligatorio = (f.elements[n].name.substring(3,5) == "Ob");
				f.elements[n].value = jsTrim(f.elements[n].value);
				
				if(f.elements[n].value.length<1 && obligatorio){
				
					alert(txt_idioma[0] + f.elements[n].title + txt_idioma[1]);
					f.elements[n].focus();
					return false;
					
				}else{
				
					if(tipoCampo=="log" || tipoCampo=="psw"){	// Login o Password
					
						if(!validaLogin(f.elements[n],f.elements[n].title))
						
							return false;
							
					}else if(tipoCampo=="txt"){				// Texto 
					
						if(obligatorio || (!obligatorio && f.elements[n].value.length>0))
						
							if(!validaTxt(f.elements[n],f.elements[n].title))
							
								return false;
								
					}else if(tipoCampo=="txa"){				// TextArea
					
						if(obligatorio || (!obligatorio && f.elements[n].value.length>0)){
						
							if(!validaTxa(f.elements[n],f.elements[n].title))
							
								return false;
								
							if(!limiteCorrecto(f.elements[n],f.elements[n].title))
							
								return false;
								
						}
					}else if(tipoCampo=="alf"){				// Alfanumérico
					
						if(obligatorio || (!obligatorio && f.elements[n].value.length>0))
						
							if(!validaAlf(f.elements[n],f.elements[n].title))
							
								return false;
								
					}else if(tipoCampo=="fch"){				// Fecha
					
						if(obligatorio || (!obligatorio && f.elements[n].value.length>0))
						
							if(!validaFecha(f.elements[n],f.elements[n].title))
							
								return false;
								
					}else if(tipoCampo=="eml"){				// eMail
					
						if(obligatorio || (!obligatorio && f.elements[n].value.length>0)){
						
							if(!validaEml(f.elements[n],f.elements[n].title))
							
								return false;
						}
					}else if(tipoCampo=="tlf"){				// Teléfono o Fax
					
						if(obligatorio || (!obligatorio && f.elements[n].value.length>0)){
						
							if(!validaTlf(f.elements[n],f.elements[n].title))
							
								return false;
								
						}
						
					}else if(tipoCampo=="num"){				// Números
					
						if(obligatorio || (!obligatorio && f.elements[n].value.length>0)){
						
							if(!validaNum(f.elements[n],f.elements[n].title))
								return false;
						}
					}else if(tipoCampo=="dec"){				// Números
					
						if(obligatorio || (!obligatorio && f.elements[n].value.length>0)){
						
							if(!validaDec(f.elements[n],f.elements[n].title))
								return false;
						}
					}
				}
			}
		}
		return true;
	}
	
	function validaLogin(campo,nombreCampo){
		var CARACTERES = "1234567890abcdefghijklmnopqrstuvwxyzáéíóúäëïöüàèìòùABCDEFGHIJKLMNOPQRSTUVWXYZÁÉÍÓÚÄËÏÖÜÀÈÌÒÙ-_&.";		
		if(campo.value.length<6 || campo.value.indexOf(" ")!=-1){
			if(campo.value.length<6)
				alert(txt_idioma[0]+nombreCampo+txt_idioma[2]);
			else
				alert(txt_idioma[0]+nombreCampo+txt_idioma[3]);
			campo.focus();
			campo.select();
			return false;
		}else{
			for(var i=0; i<campo.value.length; i++){
				var temp = campo.value.substring(i, i+1);
				if(CARACTERES.indexOf(temp) == -1){
					alert(txt_idioma[0]+nombreCampo+txt_idioma[4]);
					campo.focus();
					campo.select();
					return false;
				}
			}
		}
		return true;
	}
	
	function validaTxt(campo,nombreCampo){
		/*var TEXTO = "1234567890 abcdefghijklmnñopqrstuvwxyzáéíóúäëïöüàèìòùâêîôûABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚÄËÏÖÜÀÈÌÒÙÂÊÎÔÛ-_-&()[]@#.,:;´`‘’“”„ß€\r\n\t\'’^¡!¿?=%$ºª³²+*{}çÇ<>\/\|"•";
		
		for(var i=0; i<campo.value.length; i++){
			var temp = campo.value.substring(i, i+1);
			if(TEXTO.indexOf(temp) == -1){
				alert(txt_idioma[0]+nombreCampo+txt_idioma[5]);
				campo.focus();
				campo.select();
				return false;
			}
		}*/
		return true;
	}
	
	function validaAlf(campo,nombreCampo){
		
		/*var ALFANUMERICO = "1234567890 abcdefghijklmnñopqrstuvwxyzáéíóúäëïöüàèìòùâêîôûABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚÄËÏÖÜÀÈÌÒÙÂÊÎÔÛ-_&#•()[]@.,:;´`^¡!¿?=%$ºª+*{}çÇ<>/'ß€³²|";
		for(var i=0; i<campo.value.length; i++){
			var temp = campo.value.substring(i, i+1);
			if ( (campo.value.charCodeAt(i) != 13) && (campo.value.charCodeAt(i) != 10) && (ALFANUMERICO.indexOf(temp) == -1)){
				alert(txt_idioma[0]+nombreCampo+txt_idioma[6]);
				campo.focus();
				campo.select();
				return false;
			}
		}*/
		return true;
	}
	
	function validaTxa(campo,nombreCampo){
		/*var ALFANUMERICO_TXA = "1234567890 abcdefghijklmnñopqrstuvwxyzáéíóúäëïöüàèìòùâêîôûABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚÄËÏÖÜÀÈÌÒÙÂÊÎÔÛ-_-&()[]@#.,:;´`‘’“”„ß€\r\n\t\'’^¡!¿?=%$ºª³²+*{}çÇ<>|\/\"•";
		
		for(var i=0; i<campo.value.length; i++){
			var temp = campo.value.substring(i, i+1);
			if ( (campo.value.charCodeAt(i) != 13) && (campo.value.charCodeAt(i) != 10) && (ALFANUMERICO_TXA.indexOf(temp) == -1)){
				alert(i+campo.value.charAt(i)+txt_idioma[0]+nombreCampo+txt_idioma[6]);
				campo.focus();
				campo.select();
				return false;
			}
		}*/
		return true;
	}
	
	function validaEml(campo,nombreCampo){
		var CARACTERES = "1234567890abcdefghijklmnopqrstuvwxyzáéíóúäëïöüàèìòùABCDEFGHIJKLMNOPQRSTUVWXYZÁÉÍÓÚÄËÏÖÜÀÈÌÒÙ-_&.";
		
		var posArroba = campo.value.indexOf("@");
		var posPunto = campo.value.lastIndexOf(".");
		if(posArroba==-1 || posPunto==-1 || posPunto<posArroba || (posPunto==(posArroba+1)) || campo.value.length<6 || (posPunto<(campo.value.length-5))){
			alert(txt_idioma[7]);
			campo.focus();
			campo.select();
			return false;
		}
		for(var i=0; i<campo.value.length; i++){
			var temp = campo.value.substring(i, i+1);
			if(temp!="@" && temp!="."){
				if(CARACTERES.indexOf(temp) == -1){
					alert(txt_idioma[0]+nombreCampo+txt_idioma[4]);
					campo.focus();
					campo.select();
					return false;
				}
			}
		}
		return true;
	}
	
	function validaTlf(campo,nombreCampo){
		var DIGITOS = "1234567890";
		var ESPECIALES = "() /.+-";
		
		if(campo.value.length<9){
			alert(txt_idioma[8]+nombreCampo+txt_idioma[9]);
			campo.focus();
			campo.select();
			return false;
		}
		var num = 0;
		for(var i=0; i<campo.value.length; i++){
			var temp = campo.value.substring(i, i+1);
			if(DIGITOS.indexOf(temp) != -1)
				num++;
			else if(ESPECIALES.indexOf(temp) == -1){
				alert(txt_idioma[0]+nombreCampo+txt_idioma[4]);
				campo.focus();
				campo.select();
				return false;
			}
		}
		if(num<9){
			alert(txt_idioma[8]+nombreCampo+txt_idioma[10]);
			campo.focus();
			campo.select();
			return false;
		}
		return true;
	}
	
	function validaNum(campo,nombreCampo){
		var NUMEROS = "1234567890";
		
		for(var i=0; i<campo.value.length; i++){
			var temp = campo.value.substring(i, i+1);
			if(NUMEROS.indexOf(temp) == -1){
				alert(txt_idioma[0]+nombreCampo+txt_idioma[11]);
				campo.focus();
				campo.select();
				return false;
			}
		}
		return true;
	}
	
	function validaDec(campo,nombreCampo){
		var NUMEROS = "1234567890";
		var	PUNTO = ".";
		var	MENOS = "-";
		var yapunto="no";
		var inicio = 0;
		
		if (MENOS.indexOf(campo.value.substring(0, 1)) != -1)
		{
			inicio=1;
		}
		for(var i=inicio; i<campo.value.length; i++){
			var temp = campo.value.substring(i, i+1);
			if (PUNTO.indexOf(temp) != -1)
			{
				if (yapunto=="si")
				{
					alert(txt_idioma[0]+nombreCampo+txt_idioma[17]);
					campo.focus();
					campo.select();
					return false;
				}
				yapunto="si";
			}
			else
			{
				if(NUMEROS.indexOf(temp) == -1){
					alert(txt_idioma[0]+nombreCampo+txt_idioma[17]);
					campo.focus();
					campo.select();
					return false;
				}
			}
		}
		return true;
	}

	function limiteCorrecto(campo,nombreCampo){		// Control de caracteres de textarea
		if(campo.maxlength<campo.value.length){
			alert(txt_idioma[0]+nombreCampo+txt_idioma[12]+campo.maxlength+txt_idioma[13]);
			campo.focus();
			campo.select();
			return false;		
		}
		return true;
	}

	CP =new Array('15','01','02','03','04','33','05','06','07','08','09','10','11','39','12','51','13','14','16','17','18','19','20','21','22','23','26','35','24','25','27','28','29','52','30','31','32','34','36','37','38','40','41','42','43','44','45','46','47','48','49','50');	
	var poscpespeciales=new Array('10','10','34','34','34','29','29','29','41','16','29','29','51','51','43','10','21','46','10','10','10','10','10','51','51','9','51','35'); //codigos especiales
	var cpespeciales=new Array('01211','01427','03657','04647','04690','08281','08619','08697','09471','14449','22583','22584','22806','22808','26127','26212','28190','28310','34260','34492','34815','39232','42142','42220','42269','43421','44591','50686'); //posición en el combox de las provincias con codigos especiales

	function fCambiaComboProvincia(vCampo,vprov) 
	{
		var lon=CP.length;
		var cpotot=vCampo.value.toString();
		if (cpotot.length!=5) 
		{
			alert('Código Postal no válido');
			vCampo.focus();
			vprov.selectedIndex=52;
		}
		else
		{
			var cpo=cpotot.substring(0,2);
			var posCPo;
		
			posCPo=-1;
			for (i=0;i<lon;i++) 
			{
				if (CP[i]==cpo) 
				{
					posCPo=i;
				}
			}
			if (posCPo>=0) 
			{
				vprov.selectedIndex=posCPo;		
			}
			else 
			{
				alert('Código Postal no válido');
				vCampo.focus();
				vprov.selectedIndex=posCPo;		
			}
			//PARA CODIGOS POSTALES ESPECIALES CARGADOS EN LOS ARRAYS cpespeciales Y poscpespeciales
			for (i=0;i<poscpespeciales.length;i++)
			{
				if(cpotot==cpespeciales[i])
				{
					vprov.selectedIndex=poscpespeciales[i];
					return	
				}
			}
		}
	}

	function ValidarNIF(obj) 
	{
		if (obj.value.length != 9) 
		{
			if (obj.value.length==7) 
			{ 
				obj.value = "00"+obj.value;
			}
			if (obj.value.length==8) 
			{ 
				obj.value = "0"+obj.value;
			}
			if (obj.value.length==6) 
			{ 
				obj.value = "000"+obj.value;
			}
			if ((obj.value.length==0) || (obj.value.length > 9)) 
			{
				alert("NIF incorrecto");
				obj.select();
			}
		}
		var letra = obj.value.substring (0, 1);
		if (isNaN(letra)) 
		{
			letra = letra.toUpperCase();
		}
		var dni = obj.value.substring (0, 8);
		if (isNaN(dni)) 
		{	
			alert("NIF incorrecto");
			obj.select();
		}
		var numero = parseInt(dni,10);
		var letranif = obj.value.substring (8, 9);
		letranif = letranif.toUpperCase();
		var letra;
		var ArrayLetras= new Array("T","R","W","A","G","M","Y","F","P","D","X","B","N","J","Z","S","Q","V","H","L","C","K","E");
		ASC= numero % 23;
		letra=ArrayLetras[ASC];
		if (letranif  != letra) 
		{
			alert("NIF incorrecto");
			obj.select();
		}
	} 
 


