			function enviar(){
				if (validar() == true){
					document.datos.submit();
				}
			}

           function numeros_solo(){
                   var key=window.event.keyCode;
                   if (key < 48 || key > 57){
                   window.event.keyCode=0;
                   }
           }

			function toNum(str){
				for(i = 0; i < str.length; i++){
					if (str.charAt(i) != '0'){
						return parseInt(str.substring(i));
					}
				}
				return parseInt(str);
			}

			function validar(){
				error = "";
                if (!trim(document.datos.clave.value).length > 0) error += "- No has introducido la clave.\n";
                if (!trim(document.datos.nombre.value).length > 0) error += "- No has introducido el nombre.\n";
                if (!trim(document.datos.direccion.value).length > 0) error += "- No has introducido la Direccion.\n";
				if (!trim(document.datos.apellidos.value).length > 0) error += "- No has introducido los apellidos.\n";
                if (!trim(document.datos.localidad.value).length > 0) error += "- No has introducido tu Localidad.\n";
                if (!trim(document.datos.codpostal.value).length > 0) error += "- No has introducido el Codigo Postal.\n";
                if (!isPhone(document.datos.telefono.value)) error += "- El numero de telefono no es valido.\n";
                if (!trim(document.datos.email.value).length > 0 && document.datos.email.value.indexOf("@") < 0) error += "- El email no es valido.\n";
                if (!nif(document.datos.dni.value)) error += "- Su DNI o NIF no es valido, revise: 8 Numeros y su letra.\n";
                if (!ValidoCP(document.datos.codpostal.value)) error += "- Su Codigo Postal no es valido.\n";
		if (!document.datos.terminos.checked) error += "- Debes aceptar los terminos de contrato.\n";


           function ValidoCP(cp){
                CPValido=true
                //si no tiene 5 caracteres no es válido
                if (cp.length != 5)
                  CPValido=false

                return CPValido
                }

           function nif(dni) {
                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);
                if (letra!=let){
                   return false;
                 }
                   return true;

                }

		   if (error.length > 0){
					alert("Por favor compruebe los siguientes campos:\n" + error);
					return false;
				}else{
					return true;
				}
			}

			function isPhone(x){
				if (trim(x).length == 9){
					if (x.charAt(0) == '9' || x.charAt(0) == '6'){
						for (i = 0; i < x.length; i++){
							if ( isNaN(parseInt(x.charAt(i))) ){
								return false;
							}
						}
						return true;
					}
				}
				return false;
   }

			function LTrim(s){
				// Devuelve una cadena sin los espacios del principio
				for(i = 0; i < s.length; i++){
					if(s.charAt(i) != ' '){
						return s.substring(i);
						break;
					}
				}
				return "";
			}

			function RTrim(s){
				// Quita los espacios en blanco del final de la cadena
				for(i = s.length-1; i >= 0; i--){
					if(s.charAt(i) != ' '){
						return s.substring(0,i+1);
						break;
					}
				}
				return "";
			}

			function trim(s){
				// Quita los espacios del principio y del final
				return LTrim(RTrim(s));
			}

