	function mostrarMarca(urlComercio){
		var selector = document.getElementById("marcas");	
		var nomCodMarca = selector.options[selector.selectedIndex].value;
		
		window.location.href=urlComercio+'marca/'+nomCodMarca+'/1';
	}
	
	function mostrarPrecio() {
		var selector = document.getElementById("opcionPrecios");	
		var atributos = selector.options[selector.options.selectedIndex].value;
		var listaAtributos = atributos.split('#|,%#%,|#');
		var precio = listaAtributos[0];
		var precioOferta = listaAtributos[1];	
		var stock = listaAtributos[2];	
	
		if (atributos == "") {
			var mensaje = document.getElementById("mensajePrecio");	
			mensaje.style.display = "";
	
			var contenedorOferta = document.getElementById("contenedorPrecioOferta");
			contenedorOferta.innerHTML = "";
	
			var contenedorPrecio = document.getElementById("contenedorPrecioNormal");
			contenedorPrecio.innerHTML = "";
	
			var contenedorStock = document.getElementById("contenedorStocks");
			contenedorStock.innerHTML = "";
		} else {
			if (precioOferta != "" && precioOferta != " " && precioOferta != "0" && precioOferta != "undefined") {
				var mensaje = document.getElementById("mensajePrecio");	
				mensaje.style.display = "none";
		
				textoDiv = formato_numero(precioOferta,2,",",".");	
				textoDiv = "Precio oferta: <span>" + textoDiv + "€</span>"; //"<img src='images/precios/descansados/pos.gif' />";			
		
				var contenedorOferta = document.getElementById("contenedorPrecioOferta");		
				contenedorOferta.innerHTML = textoDiv;
		
				textoDiv = formato_numero(precio,2,",",".");	
				textoDiv = "Precio: <span>" + textoDiv + "€</span>"; //"<img src='images/precios/descansados/pos.gif' />";				
		
				var contenedorPrecio = document.getElementById("contenedorPrecioNormal");
				contenedorPrecio.innerHTML = textoDiv;		
			} else {
				var mensaje = document.getElementById("mensajePrecio");	
				mensaje.style.display = "none";
		
				textoDiv = formato_numero(precio, 2, ",", ".");	
				textoDiv = "Precio: <span>" + textoDiv + "€</span>";
		
				var contenedorOferta = document.getElementById("contenedorPrecioOferta");
				contenedorOferta.innerHTML = textoDiv;
		
				var contenedorPrecio = document.getElementById("contenedorPrecioNormal");
				contenedorPrecio.innerHTML = "";
			}
		
			if(stock >= 1){
				if(stock >= 6){
					var contenedorStock = document.getElementById("contenedorStocks");
					contenedorStock.innerHTML = ""; //"<img src='img/diponible_ok.jpg' alt='Disponible' tittle='Disponible' />";
				} else{
					var contenedorStock = document.getElementById("contenedorStocks");
					contenedorStock.innerHTML = ""; //"<img src='img/diponible_media.jpg' alt='Últimas unidades' tittle='Últimas unidades' />";
				}
			} else {
				var contenedorStock = document.getElementById("contenedorStocks");
				contenedorStock.innerHTML = "<img src='img/agotado-temporal.png' alt='Agotado' tittle='Agotado' />"; //"<img src='img/diponible_no.jpg' alt='Agotado' tittle='Agotado' />";
			}
		}
	}
	
	function comprobarPrecio() {
		var formulario = document.getElementById("formularioCompra");	
		var contenedorNumOpcion = document.getElementById("numOpcion");	
		var selector = document.getElementById("opcionPrecios");	
	
		if (selector.value != "no") {
			var atributos = selector.options[selector.options.selectedIndex].value;
			var listaAtributos = atributos.split('#|,%#%,|#');
			var precio = listaAtributos[0];
			var precioOferta = listaAtributos[1];	
			var stock = listaAtributos[2];
			var numOpcion = listaAtributos[3];
			var contenedorOferta = document.getElementById("contenedorPrecioOferta");			
			var contenedorPrecio = document.getElementById("contenedorPrecioNormal");		
			var contenedorStock = document.getElementById("contenedorStocks");
	
			if (stock != undefined) {
				if (stock > 0) {
					contenedorNumOpcion.value = numOpcion;
					formulario.submit();	
				} else {
					alert("Lo sentimos, la opción seleccionada para este producto se encuentra agotada temporalmente.");
				}
			} else {
				alert("Seleccione una opción para mostrar el precio del producto antes de incluirlo en su compra.");
			}
		} else {
			var stockProd = document.getElementById("stockProd");	
	
			if (stockProd.value == "no") {
				alert("Lo sentimos, la opción seleccionada para este producto se encuentra agotada temporalmente.");
			} else {
				contenedorNumOpcion.value = 0;
				formulario.submit();	
			}
		}
	}
	
	function variar_valor(letra,id,urlComercio) {
		var valor = Number(document.getElementById('caja_de_texto'+id).value);
		var precioProducto = parseFloat(document.getElementById('precioProducto'+id).firstChild.nodeValue.replace(",","."));
		var totalProductoCaja = document.getElementById('totalProducto'+id);
		var totalProducto = parseFloat(document.getElementById('totalProducto'+id).firstChild.nodeValue.replace(",","."));
		var totalCompraCaja = document.getElementById('totalCompra');
		var totalCompra = parseFloat(document.getElementById('totalCompra').firstChild.nodeValue.replace(",","."));
	
		switch(letra) {
			case 'b': 
				valor = valor + 1;
				break;
			case 'c':
				valor = valor - 1;		
				break;
		}
	
		if (valor > 0) {	
			document.getElementById('caja_de_texto' + id).value = valor;
	
			totalCompra = totalCompra - totalProducto;	
			totalProducto = valor * precioProducto;
	
			totalCompra = totalCompra + totalProducto;		
	
			window.location.href=urlComercio+'actualizaCantidades/'+ id +'/'+ valor;
		} else {
			alert('No puede haber menos de una unidad.');	
	
			document.getElementById('caja_de_texto'+id).value = totalProducto / precioProducto;
		}
	}
	
	function formato_numero(numero, decimales, separador_decimal, separador_miles) {
		numero=parseFloat(numero);
	
		if (isNaN(numero)) {
			return "";
		}
	
		if (decimales!==undefined) {
	
			// Redondeamos
	
			numero=numero.toFixed(decimales);
		}
	
		// Convertimos el punto en separador_decimal
	
		numero = numero.toString().replace(".", separador_decimal!==undefined ? separador_decimal : ",");
	
		if (separador_miles) {
	
			// Añadimos los separadores de miles
	
			var miles=new RegExp("(-?[0-9]+)([0-9]{3})");
			while (miles.test(numero)) {
				numero=numero.replace(miles, "$1" + separador_miles + "$2");
			}
		}
	
		return numero;
	}
	
	function seleccionarDatos() {
		var con = document.getElementById("con");
		var sin = document.getElementById("sin");
		var rellenar = document.getElementById("rellenar");
	
		if (rellenar.checked) {
			con.style.display = "";
			sin.style.display = "none";	
	
			document.getElementById("checkHidden").value = "SI";
			document.getElementById("nombreHidden").value = document.getElementById("nombre2").value;
			document.getElementById("apellidosHidden").value = document.getElementById("apellidos2").value;
			document.getElementById("dniHidden").value = document.getElementById("dni2").value;
			document.getElementById("provinciaHidden").value = document.getElementById("provincia2").value;
			document.getElementById("poblacionHidden").value = document.getElementById("poblacion2").value;
			document.getElementById("direccionHidden").value = document.getElementById("direccion2").value;
			document.getElementById("cpHidden").value = document.getElementById("cp2").value;
			document.getElementById("tlfHidden").value = document.getElementById("tlf2").value;
		} else if (!rellenar.checked) {
			sin.style.display = "";
			con.style.display = "none";		
			document.getElementById("checkHidden").value = "NO";
			document.getElementById("nombreHidden").value = document.getElementById("nombre1").value;
			document.getElementById("apellidosHidden").value = document.getElementById("apellidos1").value;
			document.getElementById("dniHidden").value = document.getElementById("dni1").value;
			document.getElementById("provinciaHidden").value = document.getElementById("provincia1").value;
			document.getElementById("poblacionHidden").value = document.getElementById("poblacion1").value;
			document.getElementById("direccionHidden").value = document.getElementById("direccion1").value;
			document.getElementById("cpHidden").value = document.getElementById("cp1").value;
			document.getElementById("tlfHidden").value = document.getElementById("tlf1").value;
		}	
	}
	
	function seleccionarDatos2(opcion) {
		var con = document.getElementById("con");
		var con2 = document.getElementById("con2");
		var sin = document.getElementById("sin");
		
		if (opcion == "rellenar1") {
			sin.style.display = "none";
			con2.style.display = "none";
			con.style.display = "";	
	
			if (document.getElementById("comoEnvio1").checked) {
				document.getElementById("formaEnvioHidden").value = "Enviar"; 	
				document.getElementById("nombreHidden").value = document.getElementById("nombre2").firstChild.nodeValue;
				document.getElementById("apellidosHidden").value = document.getElementById("apellidos2").firstChild.nodeValue;
				document.getElementById("provinciaHidden").value = document.getElementById("provincia2").firstChild.nodeValue;
				document.getElementById("poblacionHidden").value = document.getElementById("poblacion2").firstChild.nodeValue;
				document.getElementById("direccionHidden").value = document.getElementById("direccion2").firstChild.nodeValue;
				document.getElementById("cpHidden").value = document.getElementById("cp2").firstChild.nodeValue;
				document.getElementById("telefonoHidden").value = document.getElementById("telefono2").firstChild.nodeValue;
				document.getElementById("comentariosHidden").value = document.getElementById("comentarios2").value;
				
				document.getElementById("provincia2Etiqueta").style.display = ""; 		
				document.getElementById("poblacion2Etiqueta").style.display = ""; 		
				document.getElementById("direccion2Etiqueta").style.display = ""; 		
				document.getElementById("cp2Etiqueta").style.display = ""; 				
			}	
	
			if (document.getElementById("comoEnvio2").checked) {
				document.getElementById("formaEnvioHidden").value = "Recojer"; 	
				document.getElementById("nombreHidden").value = document.getElementById("nombre2").firstChild.nodeValue;
				document.getElementById("apellidosHidden").value = document.getElementById("apellidos2").firstChild.nodeValue;
				document.getElementById("provinciaHidden").value = "";
				document.getElementById("poblacionHidden").value = "";
				document.getElementById("direccionHidden").value = "";
				document.getElementById("cpHidden").value = "";
				document.getElementById("telefonoHidden").value = document.getElementById("telefono2").firstChild.nodeValue;
				document.getElementById("comentariosHidden").value = document.getElementById("comentarios2").value;
				
				document.getElementById("provincia2Etiqueta").style.display = "none"; 		
				document.getElementById("poblacion2Etiqueta").style.display = "none"; 		
				document.getElementById("direccion2Etiqueta").style.display = "none"; 		
				document.getElementById("cp2Etiqueta").style.display = "none"; 				
			}
		} else if (opcion == "rellenar2") {
			sin.style.display = "none";
			con2.style.display = "";
			con.style.display = "none";	
	
			if (document.getElementById("comoEnvio1").checked) {
				document.getElementById("formaEnvioHidden").value = "Enviar"; 	
				document.getElementById("nombreHidden").value = document.getElementById("nombre3").firstChild.nodeValue;
				document.getElementById("apellidosHidden").value = document.getElementById("apellidos3").firstChild.nodeValue;
				document.getElementById("provinciaHidden").value = document.getElementById("provincia3").firstChild.nodeValue;
				document.getElementById("poblacionHidden").value = document.getElementById("poblacion3").firstChild.nodeValue;
				document.getElementById("direccionHidden").value = document.getElementById("direccion3").firstChild.nodeValue;
				document.getElementById("cpHidden").value = document.getElementById("cp3").firstChild.nodeValue;
				document.getElementById("telefonoHidden").value = document.getElementById("telefono3").firstChild.nodeValue;
				document.getElementById("comentariosHidden").value = document.getElementById("comentarios3").value;
				
				document.getElementById("provincia3Etiqueta").style.display = ""; 		
				document.getElementById("poblacion3Etiqueta").style.display = ""; 		
				document.getElementById("direccion3Etiqueta").style.display = ""; 		
				document.getElementById("cp3Etiqueta").style.display = ""; 				
			}	
	
			if (document.getElementById("comoEnvio2").checked) {
				document.getElementById("formaEnvioHidden").value = "Recojer"; 	
				document.getElementById("nombreHidden").value = document.getElementById("nombre3").firstChild.nodeValue;
				document.getElementById("apellidosHidden").value = document.getElementById("apellidos3").firstChild.nodeValue;
				document.getElementById("provinciaHidden").value = "";
				document.getElementById("poblacionHidden").value = "";
				document.getElementById("direccionHidden").value = "";
				document.getElementById("cpHidden").value = "";
				document.getElementById("telefonoHidden").value = document.getElementById("telefono3").firstChild.nodeValue;
				document.getElementById("comentariosHidden").value = document.getElementById("comentarios3").value;
	
				document.getElementById("provincia3Etiqueta").style.display = "none"; 		
				document.getElementById("poblacion3Etiqueta").style.display = "none"; 		
				document.getElementById("direccion3Etiqueta").style.display = "none"; 		
				document.getElementById("cp3Etiqueta").style.display = "none"; 				
			}
		} else if (opcion == "rellenar0") {
			sin.style.display = "";
			con2.style.display = "none";
			con.style.display = "none";	
	
			if (document.getElementById("comoEnvio1").checked) {
				document.getElementById("formaEnvioHidden").value = "Enviar"; 	
				document.getElementById("nombreHidden").value = document.getElementById("nombre1").value;
				document.getElementById("apellidosHidden").value = document.getElementById("apellidos1").value;
				document.getElementById("provinciaHidden").value = document.getElementById("provincia1").value;
				document.getElementById("poblacionHidden").value = document.getElementById("poblacion1").value;
				document.getElementById("direccionHidden").value = document.getElementById("direccion1").value;
				document.getElementById("cpHidden").value = document.getElementById("cp1").value;
				document.getElementById("telefonoHidden").value = document.getElementById("telefono1").value;
				document.getElementById("comentariosHidden").value = document.getElementById("comentarios1").value;
	
				document.getElementById("provincia1Etiqueta").style.display = ""; 		
				document.getElementById("poblacion1Etiqueta").style.display = ""; 		
				document.getElementById("direccion1Etiqueta").style.display = ""; 		
				document.getElementById("cp1Etiqueta").style.display = ""; 				
			}	
	
			if (document.getElementById("comoEnvio2").checked) {
				document.getElementById("formaEnvioHidden").value = "Recojer"; 	
				document.getElementById("nombreHidden").value = document.getElementById("nombre1").value;
				document.getElementById("apellidosHidden").value = document.getElementById("apellidos1").value;
				document.getElementById("provinciaHidden").value = "";
				document.getElementById("poblacionHidden").value = "";
				document.getElementById("direccionHidden").value = "";
				document.getElementById("cpHidden").value = "";
				document.getElementById("telefonoHidden").value = document.getElementById("telefono1").value;
				document.getElementById("comentariosHidden").value = document.getElementById("comentarios1").value;
	
				document.getElementById("provincia1Etiqueta").style.display = "none"; 		
				document.getElementById("poblacion1Etiqueta").style.display = "none"; 		
				document.getElementById("direccion1Etiqueta").style.display = "none"; 		
				document.getElementById("cp1Etiqueta").style.display = "none"; 				
			}
		}
	}
	
	function seleccionarDatos3(boton) {
		var visualizar = document.getElementById("tablaVisualizar");
		var modificar = document.getElementById("tablaModificar");
		var editar = document.getElementById("botonModificar");
		var guardar = document.getElementById("botonGuardar");
		var formulario = document.getElementById("formulario");
		var password1 = document.getElementById("password1").value;
		var password2 = document.getElementById("password2").value;
	
		if (boton == "EDITAR") {
			modificar.style.display = "";
			guardar.style.display = "";	
			visualizar.style.display = "none";	
			editar.style.display = "none";	
		} else if (boton == "GUARDAR") {
			var formulario = document.getElementById("formulario");
			
			// Rangos de caracteres para validación de:
			
			var checkOK  =	"ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" +	// Nombre y apellidos
							"áéíóúàèìòùäëïöüâêîôûãõå" +
							"abcdefghijklmnñopqrstuvwxyz " +
							"1234567890ªº-,./()";
							
			var checkOK2 =	"ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" +	// Dirección
							"áéíóúàèìòùäëïöüâêîôûãõå" +
							"abcdefghijklmnñopqrstuvwxyz " +
							"1234567890ªº-,./()";
							
			var checkOK3 = "0123456789";	// Código postal
			var checkOK4 = "abcdefghijklmnopqrstuvwxyz" + "1234567890-_.@";		// Nombre de usuario
			var checkOK5 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "1234567890";	// Contraseña
	
			if (formulario.nombre.value.length < 3) {
				alert("Escriba al menos 3 caracteres en el campo \"Nombre\".");
				formulario.nombre.focus();
				return (false);
			} else {
				var checkStr = formulario.nombre.value;
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
					ch = checkStr.charAt(i);
					for (j = 0; j < checkOK.length; j++)
						if (ch == checkOK.charAt(j))
							break;
	
					if (j == checkOK.length) {
						allValid = false;
						break;
					}
				}
	
				if (!allValid) {
					alert("Escriba sólo letras en el campo \"Nombre\".");
					formulario.nombre.focus();
	
					return (false);
				}
			}
	
			if (formulario.apellidos.value.length < 3) {
				alert("Escriba al menos 3 caracteres en el campo \"Apellidos\".");
				formulario.apellidos.focus();
				return (false);
			} else {
				var checkStr = formulario.apellidos.value;
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
					ch = checkStr.charAt(i);
	
					for (j = 0; j < checkOK.length; j++)
						if (ch == checkOK.charAt(j))
							break;
	
					if (j == checkOK.length) {
						allValid = false;
						break;
					}
				}
	
				if (!allValid) {
					alert("Escriba sólo letras en el campo \"Apellidos\".");
					formulario.apellidos.focus();
					return (false);
				}
			}
	
			if ((formulario.usuario.value.indexOf ('@', 0) == -1) || (formulario.usuario.value.length < 5)) {
				alert("Escriba una dirección de correo válida en el campo \"Email\".");
				formulario.usuario1.focus();
				return (false);
			}
	
			var checkStr = formulario.usuario.value;
			var allValid = true;
			var decPoints = 0;
			var allNum = "";
	
			for (i = 0; i < checkStr.length; i++) {
				ch = checkStr.charAt(i);
				for (j = 0; j < checkOK4.length; j++)
					if (ch == checkOK4.charAt(j))
						break;
	
				if (j == checkOK4.length) {
					allValid = false;
					break;
				}
	
				allNum += ch;
			}
	
			if (!allValid) {
				alert("Escriba una dirección de correo válida en el campo \"Email\".");
				formulario.usuario.focus();
				return (false);
			}
	
			if (formulario.password1.value.length > 0 || formulario.password2.value.length > 0) {
				if (formulario.password1.value.length < 6) {
					alert("La contraseña debe tener como mínimo 6 caracteres.");
					formulario.password1.focus();
					return (false);	
				}
		
				var checkStr = formulario.password1.value;
				var allValid = true;
				var decPoints = 0;
				var allNum = "";
		
				for (i = 0; i < checkStr.length; i++) {
					ch = checkStr.charAt(i);
		
					for (j = 0; j < checkOK5.length; j++)
						if (ch == checkOK5.charAt(j))
							break;
		
					if (j == checkOK5.length) {
						allValid = false;
						break;
					}
		
					allNum += ch;
				}
		
				if (!allValid) {
					alert("Escriba sólo letras y números en el campo \"Contraseña\".");
					formulario.password1.focus();
		
					return (false);
				}
		
				var checkStr = formulario.password2.value;
				var allValid = true;
				var decPoints = 0;
				var allNum = "";
		
				for (i = 0; i < checkStr.length; i++) {
					ch = checkStr.charAt(i);
		
					for (j = 0; j < checkOK5.length; j++)
						if (ch == checkOK5.charAt(j))
							break;
		
					if (j == checkOK5.length) {
						allValid = false;
						break;
					}
		
					allNum += ch;
				}
		
				if (!allValid) {
					alert("Escriba sólo letras y números en el campo \"Repetir contraseña\".");
					formulario.password2.focus();
					return (false);
				}
		
				if (formulario.password1.value != formulario.password2.value){
					alert("Las contraseñas no coinciden.");
					formulario.password1.focus();
		
					return (false);	
				}
			}
			
			if (formulario.dni.value.testDNI() != true) {
				if (formulario.dni.value.testCIF() != true) {
					if (formulario.dni.value.testNIE() != true) {
						alert("El DNI/CIF/NIE introducido no es válido.");
						return (false);	
					}
				}
			}
	
			if (formulario.provincia.value.length < 3) {
				alert("Escriba al menos 3 caracteres en el campo \"Provincia\".");
				formulario.provincia.focus();
				return (false);
			} else {
				var checkStr = formulario.provincia.value;
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
					ch = checkStr.charAt(i);
	
					for (j = 0; j < checkOK.length; j++)
						if (ch == checkOK.charAt(j))
							break;
	
					if (j == checkOK.length) {
						allValid = false;
						break;
					}
				}
	
				if (!allValid) {
					alert("Escriba sólo letras en el campo \"Provincia\".");
					formulario.provincia.focus();
	
					return (false);
				}
			}
	
			if (formulario.poblacion.value.length < 3) {
				alert("Escriba al menos 3 caracteres en el campo \"Población\".");
				formulario.poblacion.focus();
	
				return (false);
			} else {
				var checkStr = formulario.poblacion.value;
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
					ch = checkStr.charAt(i);
	
					for (j = 0; j < checkOK.length; j++)
						if (ch == checkOK.charAt(j))
							break;
	
					if (j == checkOK.length) {
						allValid = false;
						break;
					}
				}
	
				if (!allValid) {
					alert("Escriba sólo letras en el campo \"Población\".");
					formulario.poblacion.focus();
	
					return (false);
				}
			}
	
			if (formulario.direccion.value.length < 3) {
				alert("Escriba al menos 3 caracteres en el campo \"Dirección\".");
				formulario.direccion.focus();
	
				return (false);
			} else {
				var checkStr = formulario.direccion.value;
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
					ch = checkStr.charAt(i);
	
					for (j = 0; j < checkOK2.length; j++)
						if (ch == checkOK2.charAt(j))
							break;
	
					if (j == checkOK2.length) {
						allValid = false;
						break;
					}
				}
	
				if (!allValid) {
					alert("Escriba sólo letras y números en el campo \"Dirección\".");
					formulario.direccion.focus();
	
					return (false);
				}
			}
	
			if (formulario.cp.value.length < 5 || formulario.cp.value.length > 5) {
				alert("Escriba 5 dígitos en el campo \"Código Postal\".");
				formulario.cp.focus();
				return (false);
			}	
	
			var checkStr = formulario.cp.value;
			var allValid = true;
			var decPoints = 0;
			var allNum = "";
	
			for (i = 0; i < checkStr.length; i++) {
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK3.length; j++)
					if (ch == checkOK3.charAt(j))
						break;
	
				if (j == checkOK3.length) {
					allValid = false;
					break;
				}
	
				allNum += ch;
			}
	
			if (!allValid) {
				alert("Escriba sólo números en el campo \"Código Postal\".");
				formulario.cp.focus();
	
				return (false);
			}
	
			if (formulario.telefono.value.length < 9 || formulario.telefono.value.length > 9) {
				alert("Escriba 9 dígitos en el campo \"Teléfono\".");
				formulario.edad.focus();
	
				return (false);
			}
			
			var checkStr = formulario.telefono.value;
			var allValid = true;
			var decPoints = 0;
			var allNum = "";
	
			for (i = 0; i < checkStr.length; i++) {
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK3.length; j++)
					if (ch == checkOK3.charAt(j))
						break;
	
				if (j == checkOK3.length) {
					allValid = false;
					break;
				}
	
				allNum += ch;
			}
	
			if (!allValid) {
				alert("Escriba sólo números en el campo \"Teléfono\".");
				formulario.telefono.focus();
	
				return (false);
			}	
	
			if (formulario.password1.value.length > 0) {
				var newPwdCod = hex_md5(formulario.password1.value);
	
				if (newPwdCod.length > 30) {
					newPwdCod = newPwdCod.substring(0, 30);				
				}
	
				formulario.password1.value = newPwdCod;
				formulario.password2.value = newPwdCod;
			}
			
			formulario.submit();
		}	
	}
	
	function iSubmitEnter(oEvento,urlComercioSegura){ 
	
		 
	
		var iAscii = 0; 	 
	
		 
	
		 if (oEvento.keyCode){ 
	
			 iAscii = oEvento.keyCode; 				  
	
		 }else if (oEvento.which){ 
	
			 iAscii = oEvento.which; 		 
	
		 }else{ 
	
			 return false; 
	
		 }
	
		 
	
		 if (iAscii == 13) {
	
			comprobarUsuario(urlComercioSegura);
	
		 } 
	
	
	
		 return true; 
	
	} 
	
	
	
	
	
	function comprobarUsuario(urlComercioSegura){
	
		var formulario = document.getElementById("formulario");
	
		var user = document.getElementById("usuario").value;
	
		var campoUser = document.getElementById("usuario");
	
		var pass = document.getElementById("password").value;
	
		var campoPass = document.getElementById("password");
	
		var checkOK4 = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + "1234567890-_.@";
	
		var checkOK5 = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + "1234567890";
	
		
	
		if ((user.indexOf ('@', 0) == -1)||(user.length < 5)) {
	
			alert("Escribe una dirección de correo electrónico válida.");
	
			campoUser.focus();
	
			return (false);
	
		}
	
		
	
		var checkStr = user;
	
		var allValid = true;
	
		var decPoints = 0;
	
		var allNum = "";
	
		for (i = 0; i < checkStr.length; i++) {
	
			ch = checkStr.charAt(i);
	
			for (j = 0; j < checkOK4.length; j++)
	
				if (ch == checkOK4.charAt(j))
	
					break;
	
			if (j == checkOK4.length) {
	
				allValid = false;
	
				break;
	
			}
	
			allNum += ch;
	
		}
	
		if (!allValid) {
	
			alert("Escribe una dirección de correo electrónico válida.");
	
			campoUser.focus();
	
			return (false);
	
		}
	
		
	
		
	
		if (pass.length < 6){
	
			alert("La contraseña debe tener como mínimo 6 caracteres.");
	
			campoPass.focus();
	
			return (false);	
	
		}
	
		
	
		var checkStr = pass;
	
		var allValid = true;
	
		var decPoints = 0;
	
		var allNum = "";
	
		for (i = 0; i < checkStr.length; i++) {
	
			ch = checkStr.charAt(i);
	
			for (j = 0; j < checkOK5.length; j++)
	
				if (ch == checkOK5.charAt(j))
	
					break;
	
			if (j == checkOK5.length) {
	
				allValid = false;
	
				break;
	
			}
	
			allNum += ch;
	
		}
	
		if (!allValid) {
	
			alert("La contraseña no es válida.");
	
			campoPass.focus();
	
			return (false);
	
		}	
	
		
	
		// Encripto la contraseña
	
		//pass = hex_md5(pass);
	
		// Mando el formulario
	
		formulario.submit();
	
	}
	
	
	
	
	
	function recuperarPass(urlComercioSegura){
	
		var user = document.getElementById("textfield").value;		
	
		var checkOK4 = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + "1234567890-_.@";
	
		
	
		if ((user.indexOf ('@', 0) == -1)||(user.length < 5)) {
	
			alert("Escriba una dirección de correo electrónico válida.");
	
			campoUser.focus();
	
			return (false);
	
		}
	
		
	
		var checkStr = user;
	
		var allValid = true;
	
		var decPoints = 0;
	
		var allNum = "";
	
		for (i = 0; i < checkStr.length; i++) {
	
			ch = checkStr.charAt(i);
	
			for (j = 0; j < checkOK4.length; j++)
	
				if (ch == checkOK4.charAt(j))
	
					break;
	
			if (j == checkOK4.length) {
	
				allValid = false;
	
				break;
	
			}
	
			allNum += ch;
	
		}
	
		if (!allValid) {
	
			alert("Escriba una dirección de correo electrónico válida.");
	
			campoUser.focus();
	
			return (false);
	
		}
	
		
	
		window.location.href=urlComercioSegura+'recuperar-password/'+ user +'/';
	
	}
	
	
	
	
	
	function restablecerPW(){	
	
		var formulario = document.getElementById("formulario")
	
		var password1 = document.getElementById("password1").value;
	
		var password2 = document.getElementById("password2").value;
	
			
	
		if (password1 != password2){
	
			alert("Las contraseñas nuevas no coinciden");
	
		}else{
	
			formulario.submit();	
	
		}	
	
	}
	
	
	
	
	
	function pasoCuatro(urlComercioSegura){	
	
		var checkin = document.getElementById("checkbox");
	
		
	
		if(checkin.checked){	
	
			location.href=urlComercioSegura+'mi-compra/paso-4/pagar/';
	
		}else{
	
			alert("Debe leer y aceptar las condiciones de venta");
	
			checkin.focus();
	
		}
	}
	
	function trim(s) {
		return s.replace(/^\s+|\s+$/g,"");
	}
	
	function comprobarRegistroUsuarios() {
		var formulario = document.getElementById("formulario");	 
		
		// Rangos de caracteres para validación de:
		
		var checkOK  =	"ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" +	// Nombre y apellidos, provincia, poblacion
						"áéíóúàèìòùäëïöüâêîôûãõå" +
						"abcdefghijklmnñopqrstuvwxyz " +
						"1234567890ªº-,./()";
						
		var checkOK2 =	"ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" +	// Dirección
						"áéíóúàèìòùäëïöüâêîôûãõå" +
						"abcdefghijklmnñopqrstuvwxyz " +
						"1234567890ªº-,./()";
						
		var checkOK3 = "0123456789";	// Código postal, telefono
		var checkOK4 = "abcdefghijklmnopqrstuvwxyz" + "1234567890-_.@";		// Nombre de usuario
		var checkOK5 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "1234567890";	// Contraseña

		if (formulario.nombre.value.length < 3) {
			alert("Escribe al menos 3 caracteres en el campo \"Nombre\".");
			formulario.nombre.focus();
			return (false);
		} else {
			var checkStr = formulario.nombre.value;
	
			var allValid = true;
	
			for (i = 0; i < checkStr.length; i++) {
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK.length; j++)
					if (ch == checkOK.charAt(j))
						break;
	
				if (j == checkOK.length) {
					allValid = false;
					break;
				}
			}
	
			if (!allValid) {
				alert("Escribe sólo letras en el campo \"Nombre\".");
				formulario.nombre.focus();
				return (false);
			}
		}
	
		if (formulario.apellidos.value.length < 3) {
			alert("Escribe al menos 3 caracteres en el campo \"Apellidos\".");
			formulario.apellidos.focus();
			return (false);
		} else {
			var checkStr = formulario.apellidos.value;
			var allValid = true;
	
			for (i = 0; i < checkStr.length; i++) {
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK.length; j++)
					if (ch == checkOK.charAt(j))
						break;
	
				if (j == checkOK.length) {
					allValid = false;
					break;
				}
			}
	
			if (!allValid) {
				alert("Escribe sólo letras en el campo \"Apellidos\".");
				formulario.apellidos.focus();
				return (false);
			}
		}
	
		
		if (formulario.dni.value != "") {
			
			// Sólo si el pais es España, verificar el DNI. Sino, puede ser cualquier numero.
		
			if(formulario.pais.options[formulario.pais.selectedIndex].value == '55') {
				if(formulario.dni.value.testDNI() != true){
					if(formulario.dni.value.testCIF() != true){
						if(formulario.dni.value.testNIE() != true){
							alert("El DNI/CIF/NIE introducido no es válido.");
							return (false);	
						}
					}
				}
			}
		}
		
		var checkStr = formulario.telefono.value;
		var allValid = true;
		var decPoints = 0;
		var allNum = "";
	
		for (i = 0; i < checkStr.length; i++) {
			ch = checkStr.charAt(i);
	
			for (j = 0; j < checkOK3.length; j++)
				if (ch == checkOK3.charAt(j))
					break;
	
			if (j == checkOK3.length) {
				allValid = false;
				break;
			}
	
			allNum += ch;
		}
	
		if (!allValid) {
			alert("Escribe sólo números en el campo \"Teléfono\".");
			formulario.telefono.focus();
			return (false);
		}	
	
		if ((formulario.usuario.value.indexOf('@') == -1) || (formulario.usuario.value.length < 5)) {
			alert("Escribe una dirección de correo válida en el campo \"Email\".");
			formulario.usuario.focus();
			return (false);
		}
	
		var checkStr = formulario.usuario.value;
		var allValid = true;
		var decPoints = 0;
		var allNum = "";
	
		for (i = 0; i < checkStr.length; i++) {
			ch = checkStr.charAt(i);
	
			for (j = 0; j < checkOK4.length; j++)
				if (ch == checkOK4.charAt(j))
					break;
	
			if (j == checkOK4.length) {
				allValid = false;
				break;
			}
	
			allNum += ch;
		}
	
		if (!allValid) {
			alert("Escribe una dirección de correo válida en el campo \"Email\".");
			formulario.usuario.focus();
			return (false);
		}
	
		if ((formulario.usuario2.value.indexOf ('@') == -1) || (formulario.usuario2.value.length < 5)) {
			alert("Escribe una dirección de correo válida en el campo \"Repetir email\".");
			formulario.usuario2.focus();
			return (false);
		}
	
		var checkStr = formulario.usuario2.value;
		var allValid = true;
		var decPoints = 0;
		var allNum = "";
	
		for (i = 0; i < checkStr.length; i++) {
			ch = checkStr.charAt(i);
	
			for (j = 0; j < checkOK4.length; j++)
				if (ch == checkOK4.charAt(j))
					break;
	
			if (j == checkOK4.length) {
				allValid = false;
				break;
			}
	
			allNum += ch;
		}
	
		if (!allValid) {
			alert("Escribe una dirección de correo válida en el campo \"Repetir email\".");
			formulario.usuario2.focus();
			return (false);
		}
	
		if(formulario.usuario.value != formulario.usuario2.value){
			alert("Las direcciones de email no coinciden.");
			formulario.usuario.focus();
			return (false);
		}
	
		if (formulario.password.value.length < 6){
			alert("La contraseña debe tener como mínimo 6 caracteres.");
			formulario.password.focus();
			return (false);	
		}
	
		var checkStr = formulario.password.value;
		var allValid = true;
		var decPoints = 0;
		var allNum = "";
	
		for (i = 0; i < checkStr.length; i++) {
			ch = checkStr.charAt(i);
	
			for (j = 0; j < checkOK5.length; j++)
				if (ch == checkOK5.charAt(j))
					break;
	
			if (j == checkOK5.length) {
				allValid = false;
				break;
			}
	
			allNum += ch;
		}
	
		if (!allValid) {
			alert("Escribe sólo letras y números en el campo \"Contraseña\".");
			formulario.password.focus();
			return (false);
		}
	
		var checkStr = formulario.password2.value;
		var allValid = true;
		var decPoints = 0;
		var allNum = "";
	
		for (i = 0; i < checkStr.length; i++) {
			ch = checkStr.charAt(i);
	
			for (j = 0; j < checkOK5.length; j++)
				if (ch == checkOK5.charAt(j))
					break;
	
			if (j == checkOK5.length) {
				allValid = false;
				break;
			}
	
			allNum += ch;
		}
	
		if (!allValid) {
			alert("Escribe sólo letras y números en el campo \"Repetir contraseña\".");
			formulario.password2.focus();
			return (false);
		}
	
		if (formulario.password.value != formulario.password2.value){
			alert("Las contraseñas no coinciden.");
			formulario.password.focus();
			return (false);	
		}
	
		if(formulario.provincia.value != ""){
			if (formulario.provincia.value.length < 3) {
				alert("Escribe al menos 3 caracteres en el campo \"Provincia\".");
				formulario.provincia.focus();
				return (false);
			}else{	
				var checkStr = formulario.provincia.value;
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
					ch = checkStr.charAt(i);
	
					for (j = 0; j < checkOK.length; j++)
						if (ch == checkOK.charAt(j))
							break;
	
					if (j == checkOK.length) {
						allValid = false;
						break;
					}
				}
	
				if (!allValid) {
					alert("Escribe sólo letras en el campo \"Provincia\".");
					formulario.provincia.focus();
					return (false);
				}
			}
		}
	
		if(formulario.poblacion.value != ""){
			if (formulario.poblacion.value.length < 3) {
				alert("Escribe al menos 3 caracteres en el campo \"Población\".");
				formulario.poblacion.focus();
				return (false);
			}else{	
				var checkStr = formulario.poblacion.value;
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
					ch = checkStr.charAt(i);
	
					for (j = 0; j < checkOK.length; j++)
						if (ch == checkOK.charAt(j))
							break;
	
					if (j == checkOK.length) {
						allValid = false;
						break;
					}
				}
	
				if (!allValid) {
					alert("Escribe sólo letras en el campo \"Población\".");
					formulario.poblacion.focus();
					return (false);
				}
			}
		}
	
		if(formulario.direccion.value != ""){
			if (formulario.direccion.value.length < 3) {
				alert("Escribe al menos 3 caracteres en el campo \"Dirección\".");
				formulario.direccion.focus();
				return (false);
			}else{	
				var checkStr = formulario.direccion.value;
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
					ch = checkStr.charAt(i);
	
					for (j = 0; j < checkOK2.length; j++)
						if (ch == checkOK2.charAt(j))
							break;
	
					if (j == checkOK2.length) {
						allValid = false;
						break;
					}
				}
	
				if (!allValid) {
					alert("Escribe sólo letras y números en el campo \"Dirección\".");
					formulario.direccion.focus();
					return (false);
				}
			}
		}
	
		if(formulario.cp.value != ""){
			
			// Sólo si el pais es España, verificar el Código postal. Sino, puede ser cualquier texto.
		
			if(formulario.pais.options[formulario.pais.selectedIndex].value == '55') {
				if (formulario.cp.value.length < 5 || formulario.cp.value.length > 5) {
					alert("Escribe 5 dígitos en el campo \"Código Postal\".");
					formulario.cp.focus();
					return (false);
				}	
		
				var checkStr = formulario.cp.value;
				var allValid = true;
				var decPoints = 0;
				var allNum = "";
		
				for (i = 0; i < checkStr.length; i++) {
					ch = checkStr.charAt(i);
		
					for (j = 0; j < checkOK3.length; j++)
						if (ch == checkOK3.charAt(j))
							break;
		
					if (j == checkOK3.length) {
						allValid = false;
						break;
					}
		
					allNum += ch;
				}
		
				if (!allValid) {
					alert("Escribe sólo números en el campo \"Código Postal\".");
					formulario.cp.focus();
					return (false);
				}
			}
		}
	
		if(formulario.como.selectedIndex == 0) {
			alert("Por favor, díganos cómo nos conoció");
			formulario.como.focus();
			return (false);	
		}
		
		if(!formulario.aceptoPPD.checked){
			alert("Debe aceptar la política de protección de datos.");
			formulario.aceptoPPD.focus();
			return (false);	
		}	
	
		if (trim(formulario.recaptcha_response_field.value) == "" || formulario.recaptcha_response_field.value.indexOf(' ') == -1 ||
			formulario.recaptcha_response_field.value.indexOf(' ') != formulario.recaptcha_response_field.value.lastIndexOf(' ')) {
				alert("Debe indicar las dos palabras que se ven en la imagen");
				formulario.recaptcha_response_field.focus();
				return (false);
		}
			
		formulario.submit();			
	}
	
	function ConfirmarFormaPago(tipoPago,urlComercio){
	
		
	
		var formulario = document.getElementById("formulario");
	
		var formaPago = document.getElementById("formaPago");
	
		
	
		switch(tipoPago){
	
			case "Transferencia":
	
				formaPago.value = "transferencia";
	
				break;
	
				
	
			case "Domiciliacion":
	
				formaPago.value = "domiciliacion";
	
				break;
	
			
	
			case "ContraReembolso":
	
				formaPago.value = "contrareembolso";
	
				break;
	
				
	
			case "Tarjeta":
	
				formaPago.value = "tarjeta";			
	
				break;
	
				
	
			case "Metalico":
	
				formaPago.value = "metalico";			
	
				break;
	
				
	
			default:
	
				formulario.action = "";
	
		}
	
		
	
		formulario.action = urlComercio+"guardarPaso4.php";
	
		formulario.submit();
	
	}
	
	
	
	
	
	
	
	function iSubmitEnterBusqueda(oEvento,urlComercio){ 
	
		 
	
		var iAscii = 0; 	 
	
		 
	
		 if (oEvento.keyCode){ 
	
			 iAscii = oEvento.keyCode; 				  
	
		 }else if (oEvento.which){ 
	
			 iAscii = oEvento.which; 		 
	
		 }else{ 
	
			 return false; 
	
		 }
	
		 
	
		 if (iAscii == 13) {
	
			buscar(urlComercio);
	
		 } 
	
	
	
		 return true; 
	
	} 
	
	
	
	function buscar(urlComercio){
	
		var formulario = document.getElementById("formBuscar");
	
		var palabras = document.getElementById("buscador").value;
	
		var checkOK2 = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + "1234567890";
	
		
	
		if(palabras.length > 0 && palabras != "Buscar artículos"){	
	
			var checkStr = palabras;
	
			var allValid = true;
	
			for (i = 0; i < checkStr.length; i++) {
	
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK2.length; j++)
	
					if (ch == checkOK2.charAt(j))
	
						break;
	
				if (j == checkOK2.length) {
	
					allValid = false;
	
					break;
	
				}
	
			}
	
			if (!allValid) {
	
				alert("Escriba sólo letras y números para realizar una búsqueda.");
	
				return (false);
	
			}
	
		}else{
	
			alert("Escriba el nombre de un producto, la referencia, la marca o parte de su descripción para buscarlo.");
	
			return (false);		
	
		}	
	
	
	
		formulario.submit();
	
	}
	
	
	
	
	
	
	
	function seleccionarOrden(seleccionado,url,urlComercio){
	
		var formulario = document.getElementById("formOrden");	
	
		formulario.action = urlComercio+url+seleccionado;	
	
		formulario.submit();
	
	}
	
	
	
	
	
	function gastosDeEnvio(opcion){
	
		var divMrw = document.getElementById('mrw');
	
		var divCorreos = document.getElementById('correos');
	
		var formaEnvioHidden = document.getElementById('formaEnvioHidden');
	
		
	
		if(opcion == "correos"){
	
			divMrw.style.display = "none";
	
			divCorreos.style.display = "";
	
			formaEnvioHidden.value = "Correos";
	
		}else{
	
			divMrw.style.display = "";
	
			divCorreos.style.display = "none";
	
			formaEnvioHidden.value = "MRW";
	
		}
	
	}
	
	
	
	
	
	function comprobarEnvio(){	
	
		var formulario = document.getElementById("formulario");	 
	
		var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
	
		var checkOK2 = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚÄËÏÖÜ" + "abcdefghijklmnñopqrstuvwxyzáéíóúäëïöü " + "1234567890ªº-,./()¿?¡!*\n\r";
	
		var checkOK3 = "0123456789";
	
		var checkOK4 = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + "1234567890-_.@";
	
		var checkOK5 = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + "1234567890";
	
		
	
		if(formulario.formaEnvio.value == ""){
	
			alert("Elija como desea recibir su pedido.");
	
			return (false);
	
		}
	
		
	
		if(formulario.formaEnvio.value == "Enviar"){
	
					
	
			if (formulario.nombre.value.length < 3) {
	
				alert("Escriba al menos 3 caracteres en el campo \"Nombre\".");
	
				return (false);
	
			}else{	
	
				var checkStr = formulario.nombre.value;
	
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
	
					ch = checkStr.charAt(i);
	
					for (j = 0; j < checkOK.length; j++)
	
						if (ch == checkOK.charAt(j))
	
							break;
	
					if (j == checkOK.length) {
	
						allValid = false;
	
						break;
	
					}
	
				}
	
				if (!allValid) {
	
					alert("Escriba sólo letras en el campo \"Nombre\".");
	
					return (false);
	
				}
	
			}
	
			
	
			
	
			if (formulario.apellidos.value.length < 3) {
	
				alert("Escriba al menos 3 caracteres en el campo \"Apellidos\".");
	
				return (false);
	
			}else{	
	
				var checkStr = formulario.apellidos.value;
	
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
	
					ch = checkStr.charAt(i);
	
					for (j = 0; j < checkOK.length; j++)
	
						if (ch == checkOK.charAt(j))
	
							break;
	
					if (j == checkOK.length) {
	
						allValid = false;
	
						break;
	
					}
	
				}
	
				if (!allValid) {
	
					alert("Escriba sólo letras en el campo \"Apellidos\".");
	
					return (false);
	
				}
	
			}
	
			
	
			
	
			if (formulario.provincia.value.length < 3) {
	
				alert("Escriba al menos 3 caracteres en el campo \"Provincia\".");
	
				return (false);
	
			}else{	
	
				var checkStr = formulario.provincia.value;
	
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
	
					ch = checkStr.charAt(i);
	
					for (j = 0; j < checkOK.length; j++)
	
						if (ch == checkOK.charAt(j))
	
							break;
	
					if (j == checkOK.length) {
	
						allValid = false;
	
						break;
	
					}
	
				}
	
				if (!allValid) {
	
					alert("Escriba sólo letras en el campo \"Provincia\".");
	
					return (false);
	
				}
	
			}
	
			
	
			
	
			if (formulario.poblacion.value.length < 3) {
	
				alert("Escriba al menos 3 caracteres en el campo \"Población\".");
	
				return (false);
	
			}else{	
	
				var checkStr = formulario.poblacion.value;
	
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
	
					ch = checkStr.charAt(i);
	
					for (j = 0; j < checkOK.length; j++)
	
						if (ch == checkOK.charAt(j))
	
							break;
	
					if (j == checkOK.length) {
	
						allValid = false;
	
						break;
	
					}
	
				}
	
				if (!allValid) {
	
					alert("Escriba sólo letras en el campo \"Población\".");
	
					return (false);
	
				}
	
			}
	
			
	
			
	
			if (formulario.direccion.value.length < 3) {
	
				alert("Escriba al menos 3 caracteres en el campo \"Dirección\".");
	
				return (false);
	
			}else{	
	
				var checkStr = formulario.direccion.value;
	
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
	
					ch = checkStr.charAt(i);
	
					for (j = 0; j < checkOK2.length; j++)
	
						if (ch == checkOK2.charAt(j))
	
							break;
	
					if (j == checkOK2.length) {
	
						allValid = false;
	
						break;
	
					}
	
				}
	
				if (!allValid) {
	
					alert("Escriba sólo letras y números en el campo \"Dirección\".");
	
					return (false);
	
				}
	
			}
	
			
	
			
	
			if (formulario.cp.value.length < 5 || formulario.cp.value.length > 5) {
	
				alert("Escriba 5 dígitos en el campo \"Código Postal\".");
	
				return (false);
	
			}	
	
			
	
			var checkStr = formulario.cp.value;
	
			var allValid = true;
	
			var decPoints = 0;
	
			var allNum = "";
	
			for (i = 0; i < checkStr.length; i++) {
	
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK3.length; j++)
	
					if (ch == checkOK3.charAt(j))
	
						break;
	
				if (j == checkOK3.length) {
	
					allValid = false;
	
					break;
	
				}
	
				allNum += ch;
	
			}
	
			if (!allValid) {
	
				alert("Escriba sólo números en el campo \"Código Postal\".");
	
				return (false);
	
			}
	
			
	
			
	
			if (formulario.telefono.value.length < 9 || formulario.telefono.value.length > 9) {
	
				alert("Escriba 9 dígitos en el campo \"Teléfono\".");
	
				return (false);
	
			}	
	
			
	
			var checkStr = formulario.telefono.value;
	
			var allValid = true;
	
			var decPoints = 0;
	
			var allNum = "";
	
			for (i = 0; i < checkStr.length; i++) {
	
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK3.length; j++)
	
					if (ch == checkOK3.charAt(j))
	
						break;
	
				if (j == checkOK3.length) {
	
					allValid = false;
	
					break;
	
				}
	
				allNum += ch;
	
			}
	
			if (!allValid) {
	
				alert("Escriba sólo números en el campo \"Teléfono\".");
	
				return (false);
	
			}	
	
			
	
			
	
			
	
			if(formulario.comentarios.value.length > 0){	
	
				var checkStr = formulario.comentarios.value;
	
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
	
					ch = checkStr.charAt(i);
	
					for (j = 0; j < checkOK2.length; j++)
	
						if (ch == checkOK2.charAt(j))
	
							break;
	
					if (j == checkOK2.length) {
	
						allValid = false;
	
						break;
	
					}
	
				}
	
				if (!allValid) {
	
					alert("Escriba sólo letras y números en el campo \"Comentarios\".");
	
					return (false);
	
				}
	
			}
	
		}
	
		
	
		if(formulario.formaEnvio.value == "Recojer"){
	
			
	
			if (formulario.nombre.value.length < 3) {
	
				alert("Escriba al menos 3 caracteres en el campo \"Nombre\".");
	
				return (false);
	
			}else{	
	
				var checkStr = formulario.nombre.value;
	
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
	
					ch = checkStr.charAt(i);
	
					for (j = 0; j < checkOK.length; j++)
	
						if (ch == checkOK.charAt(j))
	
							break;
	
					if (j == checkOK.length) {
	
						allValid = false;
	
						break;
	
					}
	
				}
	
				if (!allValid) {
	
					alert("Escriba sólo letras en el campo \"Nombre\".");
	
					return (false);
	
				}
	
			}
	
			
	
			
	
			if (formulario.apellidos.value.length < 3) {
	
				alert("Escriba al menos 3 caracteres en el campo \"Apellidos\".");
	
				return (false);
	
			}else{	
	
				var checkStr = formulario.apellidos.value;
	
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
	
					ch = checkStr.charAt(i);
	
					for (j = 0; j < checkOK.length; j++)
	
						if (ch == checkOK.charAt(j))
	
							break;
	
					if (j == checkOK.length) {
	
						allValid = false;
	
						break;
	
					}
	
				}
	
				if (!allValid) {
	
					alert("Escriba sólo letras en el campo \"Apellidos\".");
	
					return (false);
	
				}
	
			}
	
			
	
			if (formulario.telefono.value.length < 9 || formulario.telefono.value.length > 9) {
	
				alert("Escriba 9 dígitos en el campo \"Teléfono\".");
	
				return (false);
	
			}	
	
			
	
			var checkStr = formulario.telefono.value;
	
			var allValid = true;
	
			var decPoints = 0;
	
			var allNum = "";
	
			for (i = 0; i < checkStr.length; i++) {
	
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK3.length; j++)
	
					if (ch == checkOK3.charAt(j))
	
						break;
	
				if (j == checkOK3.length) {
	
					allValid = false;
	
					break;
	
				}
	
				allNum += ch;
	
			}
	
			if (!allValid) {
	
				alert("Escriba sólo números en el campo \"Teléfono\".");
	
				return (false);
	
			}	
	
			
	
			if(formulario.comentarios.value.length > 0){	
	
				var checkStr = formulario.comentarios.value;
	
				var allValid = true;
	
				for (i = 0; i < checkStr.length; i++) {
	
					ch = checkStr.charAt(i);
	
					for (j = 0; j < checkOK2.length; j++)
	
						if (ch == checkOK2.charAt(j))
	
							break;
	
					if (j == checkOK2.length) {
	
						allValid = false;
	
						break;
	
					}
	
				}
	
				if (!allValid) {
	
					alert("Escriba sólo letras y números en el campo \"Comentarios\".");
	
					return (false);
	
				}
	
			}
	
		}
	
		formulario.submit();	
	
	}
	
	
	
	
	
	function compruebaPrimerPaso(){
	
		var formulario = document.getElementById("formulario");	
	
		var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
	
		var checkOK2 = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + "1234567890ªº-,./()";
	
		var checkOK3 = "0123456789";
	
		var checkOK4 = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + "1234567890-_.@";
	
		var checkOK5 = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + "1234567890";
	
		
	
		if (formulario.nombre.value.length < 3) {
	
			alert("Escriba al menos 3 caracteres en el campo \"Nombre\".");
	
			return (false);
	
		}else{	
	
			var checkStr = formulario.nombre.value;
	
			var allValid = true;
	
			for (i = 0; i < checkStr.length; i++) {
	
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK.length; j++)
	
					if (ch == checkOK.charAt(j))
	
						break;
	
				if (j == checkOK.length) {
	
					allValid = false;
	
					break;
	
				}
	
			}
	
			if (!allValid) {
	
				alert("Escriba sólo letras en el campo \"Nombre\".");
	
				return (false);
	
			}
	
		}
	
		
	
		
	
		if (formulario.apellidos.value.length < 3) {
	
			alert("Escriba al menos 3 caracteres en el campo \"Apellidos\".");
	
			return (false);
	
		}else{	
	
			var checkStr = formulario.apellidos.value;
	
			var allValid = true;
	
			for (i = 0; i < checkStr.length; i++) {
	
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK.length; j++)
	
					if (ch == checkOK.charAt(j))
	
						break;
	
				if (j == checkOK.length) {
	
					allValid = false;
	
					break;
	
				}
	
			}
	
			if (!allValid) {
	
				alert("Escriba sólo letras en el campo \"Apellidos\".");
	
				return (false);
	
			}
	
		}
	
		
	
		
	
		if(formulario.dni.value.testDNI() != true){
	
			if(formulario.dni.value.testCIF() != true){
	
				if(formulario.dni.value.testNIE() != true){
	
					alert("El DNI/CIF/NIE introducido no es válido.");
	
					return (false);	
	
				}
	
			}
	
		}
	
		
	
		
	
		if (formulario.provincia.value.length < 3) {
	
			alert("Escriba al menos 3 caracteres en el campo \"Provincia\".");
	
			return (false);
	
		}else{	
	
			var checkStr = formulario.provincia.value;
	
			var allValid = true;
	
			for (i = 0; i < checkStr.length; i++) {
	
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK.length; j++)
	
					if (ch == checkOK.charAt(j))
	
						break;
	
				if (j == checkOK.length) {
	
					allValid = false;
	
					break;
	
				}
	
			}
	
			if (!allValid) {
	
				alert("Escriba sólo letras en el campo \"Provincia\".");
	
				return (false);
	
			}
	
		}
	
		
	
		
	
		if (formulario.poblacion.value.length < 3) {
	
			alert("Escriba al menos 3 caracteres en el campo \"Población\".");
	
			return (false);
	
		}else{	
	
			var checkStr = formulario.poblacion.value;
	
			var allValid = true;
	
			for (i = 0; i < checkStr.length; i++) {
	
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK.length; j++)
	
					if (ch == checkOK.charAt(j))
	
						break;
	
				if (j == checkOK.length) {
	
					allValid = false;
	
					break;
	
				}
	
			}
	
			if (!allValid) {
	
				alert("Escriba sólo letras en el campo \"Población\".");
	
				return (false);
	
			}
	
		}
	
		
	
		
	
		if (formulario.direccion.value.length < 3) {
	
			alert("Escriba al menos 3 caracteres en el campo \"Dirección\".");
	
			return (false);
	
		}else{	
	
			var checkStr = formulario.direccion.value;
	
			var allValid = true;
	
			for (i = 0; i < checkStr.length; i++) {
	
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK2.length; j++)
	
					if (ch == checkOK2.charAt(j))
	
						break;
	
				if (j == checkOK2.length) {
	
					allValid = false;
	
					break;
	
				}
	
			}
	
			if (!allValid) {
	
				alert("Escriba sólo letras y números en el campo \"Dirección\".");
	
				return (false);
	
			}
	
		}
	
		
	
		
	
		if (formulario.cp.value.length < 5 || formulario.cp.value.length > 5) {
	
			alert("Escriba 5 dígitos en el campo \"Código Postal\".");		
	
			return (false);
	
		}	
	
		
	
		var checkStr = formulario.cp.value;
	
		var allValid = true;
	
		var decPoints = 0;
	
		var allNum = "";
	
		for (i = 0; i < checkStr.length; i++) {
	
			ch = checkStr.charAt(i);
	
			for (j = 0; j < checkOK3.length; j++)
	
				if (ch == checkOK3.charAt(j))
	
					break;
	
			if (j == checkOK3.length) {
	
				allValid = false;
	
				break;
	
			}
	
			allNum += ch;
	
		}
	
		if (!allValid) {
	
			alert("Escriba sólo números en el campo \"Código Postal\".");		
	
			return (false);
	
		}	
	
		
	
		if (formulario.tlf.value.length < 9 || formulario.tlf.value.length > 9) {
	
			alert("Escriba 9 dígitos en el campo \"Teléfono\".");
	
			formulario.tlf.focus();
	
			return (false);
	
		}else{	
	
			var checkStr = formulario.tlf.value;
	
			var allValid = true;
	
			var decPoints = 0;
	
			var allNum = "";
	
			for (i = 0; i < checkStr.length; i++) {
	
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK3.length; j++)
	
					if (ch == checkOK3.charAt(j))
	
						break;
	
				if (j == checkOK3.length) {
	
					allValid = false;
	
					break;
	
				}
	
				allNum += ch;
	
			}
	
			if (!allValid) {
	
				alert("Escriba sólo números en el campo \"Teléfono\".");
	
				formulario.tlf.focus();
	
				return (false);
	
			}	
	
		}
	
		
	
			
	
		formulario.submit();	
	
		
	
	}
	
	
	
	
	
	function compruebaContactar(){
	
		var formulario = document.getElementById("formulario");	 
	
		var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
	
		var checkOK2 = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚÄËÏÖÜ" + "abcdefghijklmnñopqrstuvwxyzáéíóúäëïöü " + "1234567890ªº-,./()¿?¡!*\n\r";
	
		var checkOK3 = "0123456789";
	
		var checkOK4 = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + "1234567890-_.@";
	
		var checkOK5 = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + "1234567890";
	
		
	
		if (formulario.responsable.value.length < 3) {
	
			alert("Escriba al menos 3 caracteres en el campo \"Nombre\".");
	
			formulario.responsable.focus();
	
			return (false);
	
		}else{	
	
			var checkStr = formulario.responsable.value;
	
			var allValid = true;
	
			for (i = 0; i < checkStr.length; i++) {
	
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK.length; j++)
	
					if (ch == checkOK.charAt(j))
	
						break;
	
				if (j == checkOK.length) {
	
					allValid = false;
	
					break;
	
				}
	
			}
	
			if (!allValid) {
	
				alert("Escriba sólo letras en el campo \"Nombre\".");
	
				formulario.responsable.focus();
	
				return (false);
	
			}
	
		}
	
			
	
		if (formulario.telf.value.length < 9 || formulario.telf.value.length > 9) {
	
			alert("Escriba 9 dígitos en el campo \"Teléfono\".");
	
			formulario.telf.focus();
	
			return (false);
	
		}else{	
	
			var checkStr = formulario.telf.value;
	
			var allValid = true;
	
			var decPoints = 0;
	
			var allNum = "";
	
			for (i = 0; i < checkStr.length; i++) {
	
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK3.length; j++)
	
					if (ch == checkOK3.charAt(j))
	
						break;
	
				if (j == checkOK3.length) {
	
					allValid = false;
	
					break;
	
				}
	
				allNum += ch;
	
			}
	
			if (!allValid) {
	
				alert("Escriba sólo números en el campo \"Teléfono\".");
	
				formulario.telf.focus();
	
				return (false);
	
			}	
	
		}
	
		
	
		if ((formulario.email.value.indexOf ('@', 0) == -1)||(formulario.email.value.length < 5)) {
	
			alert("Escriba una dirección de correo válida en el campo \"Email\".");
	
			formulario.email.focus();
	
			return (false);
	
		}else{	
	
			var checkStr = formulario.email.value;
	
			var allValid = true;
	
			var decPoints = 0;
	
			var allNum = "";
	
			for (i = 0; i < checkStr.length; i++) {
	
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK4.length; j++)
	
					if (ch == checkOK4.charAt(j))
	
						break;
	
				if (j == checkOK4.length) {
	
					allValid = false;
	
					break;
	
				}
	
				allNum += ch;
	
			}
	
			if (!allValid) {
	
				alert("Escriba una dirección de correo válida en el campo \"Email\".");
	
				formulario.email.focus();
	
				return (false);
	
			}	
	
		}
	
		
	
		if(formulario.duda.value.length > 0){	
	
			var checkStr = formulario.duda.value;
	
			var allValid = true;
	
			for (i = 0; i < checkStr.length; i++) {
	
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK2.length; j++)
	
					if (ch == checkOK2.charAt(j))
	
						break;
	
				if (j == checkOK2.length) {
	
					allValid = false;
	
					break;
	
				}
	
			}
	
			if (!allValid) {
	
				alert("Escriba sólo letras y números en el campo \"Consulta\".");
	
				formulario.duda.focus();
	
				return (false);
	
			}
	
		}else{
	
			alert("Escribanos sus dudas en el campo \"Consulta\".");
	
			formulario.duda.focus();
	
			return (false);		
	
		}
	
		
	
		if(!formulario.aceptoPdp.checked){
	
			alert("Debe aceptar la política de protección de datos.");
	
			formulario.aceptoPPD.focus();
	
			return (false);	
	
		}	
	
		
	
		formulario.submit();
	
	}
	
	
	
	function verCapaVideo(){
	
		document.getElementById("capaVideo").style.display = ""; 
	
	}
	
	
	
	function cerrarCapaVideo(){
	
		document.getElementById("capaVideo").style.display = "none"; 
	
	}
	
	
	
	function modalidadEnvio(modalidad){
	
		
	
		if(modalidad == 1){		
	
			
	
			if(document.getElementById("seleccionador").value == "rellenar1"){
	
				document.getElementById("con").style.display = ""; 
	
				document.getElementById("con2").style.display = "none"; 
	
				document.getElementById("sin").style.display = "none"; 
	
				
	
				
	
				document.getElementById("direccion2Etiqueta").style.display = ""; 
	
				document.getElementById("provincia2Etiqueta").style.display = ""; 
	
				
	
				
	
				document.getElementById("formaEnvioHidden").value = "Enviar"; 		
	
				
	
				document.getElementById("provinciaHidden").value = document.getElementById("provincia2").firstChild.nodeValue;
	
				document.getElementById("poblacionHidden").value = document.getElementById("poblacion2").firstChild.nodeValue;
	
				document.getElementById("direccionHidden").value = document.getElementById("direccion2").firstChild.nodeValue;
	
				document.getElementById("cpHidden").value = document.getElementById("cp2").firstChild.nodeValue;
	
			}
	
			
	
			
	
			if(document.getElementById("seleccionador").value == "rellenar2"){
	
				document.getElementById("con").style.display = "none"; 
	
				document.getElementById("con2").style.display = ""; 
	
				document.getElementById("sin").style.display = "none"; 
	
				
	
				document.getElementById("formaEnvioHidden").value = "Enviar"; 	
	
				
	
				document.getElementById("direccion3Etiqueta").style.display = ""; 
	
				document.getElementById("provincia3Etiqueta").style.display = ""; 
	
				
	
				document.getElementById("provinciaHidden").value = document.getElementById("provincia3").firstChild.nodeValue;
	
				document.getElementById("poblacionHidden").value = document.getElementById("poblacion3").firstChild.nodeValue;
	
				document.getElementById("direccionHidden").value = document.getElementById("direccion3").firstChild.nodeValue;
	
				document.getElementById("cpHidden").value = document.getElementById("cp3").firstChild.nodeValue;			
	
			}
	
			
	
			
	
			if(document.getElementById("seleccionador").value == "rellenar0"){
	
				document.getElementById("con").style.display = "none"; 
	
				document.getElementById("con2").style.display = "none"; 
	
				document.getElementById("sin").style.display = ""; 
	
				
	
				document.getElementById("formaEnvioHidden").value = "Enviar"; 	
	
				
	
				document.getElementById("direccion1Etiqueta").style.display = ""; 
	
				document.getElementById("provincia1Etiqueta").style.display = ""; 
	
				document.getElementById("poblacion1Etiqueta").style.display = ""; 
	
				document.getElementById("cp1Etiqueta").style.display = ""; 
	
				
	
				document.getElementById("provinciaHidden").value = document.getElementById("provincia1").value;
	
				document.getElementById("poblacionHidden").value = document.getElementById("poblacion1").value;
	
				document.getElementById("direccionHidden").value = document.getElementById("direccion1").value;
	
				document.getElementById("cpHidden").value = document.getElementById("cp1").value;
	
			}	
	
						
	
			
	
		}
	
		
	
		
	
		
	
		
	
		if(modalidad == 2){
	
			if(document.getElementById("seleccionador").value == "rellenar0"){
	
				document.getElementById("con").style.display = "none"; 
	
				document.getElementById("con2").style.display = "none"; 
	
				document.getElementById("sin").style.display = ""; 
	
				
	
				document.getElementById("formaEnvioHidden").value = "Recojer"; 	
	
				document.getElementById("provinciaHidden").value = "";
	
				document.getElementById("poblacionHidden").value = "";
	
				document.getElementById("direccionHidden").value = "";
	
				document.getElementById("cpHidden").value = "";
	
				
	
				document.getElementById("provincia1Etiqueta").style.display = "none"; 		
	
				document.getElementById("poblacion1Etiqueta").style.display = "none"; 		
	
				document.getElementById("direccion1Etiqueta").style.display = "none"; 		
	
				document.getElementById("cp1Etiqueta").style.display = "none"; 	
	
			}
	
			
	
			if(document.getElementById("seleccionador").value == "rellenar1"){
	
				document.getElementById("con").style.display = ""; 
	
				document.getElementById("con2").style.display = "none"; 
	
				document.getElementById("sin").style.display = "none"; 
	
				
	
				document.getElementById("formaEnvioHidden").value = "Recojer"; 	
	
				document.getElementById("provinciaHidden").value = "";
	
				document.getElementById("poblacionHidden").value = "";
	
				document.getElementById("direccionHidden").value = "";
	
				document.getElementById("cpHidden").value = "";
	
				
	
				document.getElementById("provincia2Etiqueta").style.display = "none"; 		
	
				document.getElementById("direccion2Etiqueta").style.display = "none"; 	
	
			}
	
			
	
			if(document.getElementById("seleccionador").value == "rellenar2"){
	
				document.getElementById("con").style.display = "none"; 
	
				document.getElementById("con2").style.display = ""; 
	
				document.getElementById("sin").style.display = "none"; 
	
					
	
				document.getElementById("formaEnvioHidden").value = "Recojer"; 	
	
				document.getElementById("provinciaHidden").value = "";
	
				document.getElementById("poblacionHidden").value = "";
	
				document.getElementById("direccionHidden").value = "";
	
				document.getElementById("cpHidden").value = "";
	
				
	
				document.getElementById("formaEnvioHidden").value = "Recojer"; 	
	
				document.getElementById("provincia3Etiqueta").style.display = "none"; 		
	
				document.getElementById("direccion3Etiqueta").style.display = "none"; 
	
			}			
	
		}
	
	}
	
	function selInstalacion() {
		if (document.getElementById('formulario').instalacion.selectedIndex == 1)
			document.getElementById('velViento').style.display='none';
		else
			document.getElementById('velViento').style.display='block';
	}
	
	function selConexion() {
		if (document.getElementById('formulario').conexion.selectedIndex == 1)
			document.getElementById('tipoBaterias').style.display='none';
		else
			document.getElementById('tipoBaterias').style.display='block';
	}
	
	function compruebaPresupuesto(){
		var formulario = document.getElementById("formulario");	 
	
		var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
		var checkOK2 = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚÄËÏÖÜ" + "abcdefghijklmnñopqrstuvwxyzáéíóúäëïöü " + "1234567890ªº-,./()¿?¡!*\n\r";
		var checkOK3 = "0123456789";
		var checkOK4 = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + "1234567890-_.@";
		var checkOK5 = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + "1234567890";
	
		if (formulario.nombre.value.length < 3) {
			alert("Escriba al menos 3 caracteres en el campo \"Nombre\".");
			formulario.nombre.focus();
			return (false);
		} else {
			var checkStr = formulario.nombre.value;
			var allValid = true;
	
			for (i = 0; i < checkStr.length; i++) {
				ch = checkStr.charAt(i);
				for (j = 0; j < checkOK.length; j++)
					if (ch == checkOK.charAt(j))
						break;
	
				if (j == checkOK.length) {
					allValid = false;
					break;
				}
			}
	
			if (!allValid) {
				alert("Escriba sólo letras en el campo \"Nombre\".");
				formulario.nombre.focus();
				return (false);
			}
		}
	
		if (formulario.apellidos.value.length < 3) {
			alert("Escriba al menos 3 caracteres en el campo \"Apellidos\".");
			formulario.apellidos.focus();
	
			return (false);
		} else {
			var checkStr = formulario.apellidos.value;
			var allValid = true;
	
			for (i = 0; i < checkStr.length; i++) {
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK.length; j++)
					if (ch == checkOK.charAt(j))
						break;
	
				if (j == checkOK.length) {
					allValid = false;
					break;
				}
			}
	
			if (!allValid) {
				alert("Escriba sólo letras en el campo \"Apellidos\".");
				formulario.apellidos.focus();
	
				return (false);
			}
		}
	
		if (formulario.empresa.value.length < 3) {
			alert("Escriba al menos 3 caracteres en el campo \"Empresa\".");
			formulario.empresa.focus();
			return (false);
		} else {
			var checkStr = formulario.empresa.value;
			var allValid = true;
	
			for (i = 0; i < checkStr.length; i++) {
				ch = checkStr.charAt(i);
				for (j = 0; j < checkOK2.length; j++)
					if (ch == checkOK2.charAt(j))
						break;
	
				if (j == checkOK2.length) {
					allValid = false;
					break;
				}
			}
	
			if (!allValid) {
				alert("Escriba sólo letras en el campo \"Empresa\".");
				formulario.empresa.focus();
				return (false);
			}
		}
	
		if ((formulario.email.value.indexOf ('@', 0) == -1)||(formulario.email.value.length < 5)) {
			alert("Escriba una dirección de correo válida en el campo \"Email\".");
			formulario.email.focus();
			return (false);
		} else {
			var checkStr = formulario.email.value;
			var allValid = true;
			var decPoints = 0;
			var allNum = "";
	
			for (i = 0; i < checkStr.length; i++) {
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK4.length; j++)
					if (ch == checkOK4.charAt(j))
						break;
	
				if (j == checkOK4.length) {
					allValid = false;
					break;
				}
	
				allNum += ch;
			}
	
			if (!allValid) {
				alert("Escriba una dirección de correo válida en el campo \"Email\".");
				formulario.email.focus();
				return (false);
			}	
		}
	
		if (formulario.telf.value.length < 9 || formulario.telf.value.length > 9) {
			alert("Escriba 9 dígitos en el campo \"Teléfono\".");
			formulario.telf.focus();
			return (false);
		} else {
			var checkStr = formulario.telf.value;
			var allValid = true;
			var decPoints = 0;
			var allNum = "";
	
			for (i = 0; i < checkStr.length; i++) {
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK3.length; j++)
					if (ch == checkOK3.charAt(j))
						break;
	
				if (j == checkOK3.length) {
					allValid = false;
					break;
				}
	
				allNum += ch;
			}
	
			if (!allValid) {
				alert("Escriba sólo números en el campo \"Teléfono\".");
				formulario.telf.focus();
				return (false);
			}	
		}
	
		if (formulario.ciudad.value.length < 3) {
			alert("Escriba al menos 3 caracteres en el campo \"Ciudad\".");
			formulario.ciudad.focus();
			return (false);
		} else {
			var checkStr = formulario.ciudad.value;
			var allValid = true;
	
			for (i = 0; i < checkStr.length; i++) {
				ch = checkStr.charAt(i);
				for (j = 0; j < checkOK2.length; j++)
					if (ch == checkOK2.charAt(j))
						break;
	
				if (j == checkOK2.length) {
					allValid = false;
					break;
				}
			}
	
			if (!allValid) {
				alert("Escriba sólo letras en el campo \"Ciudad\".");
				formulario.ciudad.focus();
				return (false);
			}
		}
	
		if (formulario.instalacion.value == "") {
			alert("Seleccione una opción en el campo \"Tipo de instalación\".");
			formulario.instalacion.focus();
			return (false);
		}
	
		if (formulario.conexion.value == "") {
	
			alert("Seleccione una opción en el campo \"Tipo de conexión\".");
	
			formulario.conexion.focus();
	
			return (false);
	
		}
	
		
	
		if (formulario.velocidad.value == "" && formulario.instalacion.selectedIndex != 1) {
	
			alert("Seleccione una opción en el campo \"Velocidad media del viento\".");
	
			formulario.velocidad.focus();
	
			return (false);
		}
	
		
	
		if (formulario.uso.value == "") {
	
			alert("Seleccione una opción en el campo \"Tipo de uso\".");
	
			formulario.uso.focus();
	
			return (false);
	
		}
	
		
	
		if (formulario.baterias.value == "" && formulario.conexion.selectedIndex != 1) {
	
			alert("Seleccione una opción en el campo \"Tipo de baterías\".");
	
			formulario.baterias.focus();
	
			return (false);
	
		}
	
		
	
		if (formulario.ambiente.value == "") {
	
			alert("Seleccione una opción en el campo \"Tipo de ambiente\".");
	
			formulario.ambiente.focus();
	
			return (false);
	
		}
	
		
	
		if (formulario.zona.value == "") {
	
			alert("Seleccione una opción en el campo \"Zona geográfica\".");
	
			formulario.zona.focus();
	
			return (false);
	
		}
	
		
	
		if (formulario.consumo.value == "") {
	
			alert("Seleccione una opción en el campo \"Consumo en Vatios/Día\".");
	
			formulario.consumo.focus();
	
			return (false);
	
		}else{	
	
			var checkStr = formulario.consumo.value;
	
			var allValid = true;
	
			var decPoints = 0;
	
			var allNum = "";
	
			for (i = 0; i < checkStr.length; i++) {
	
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK3.length; j++)
	
					if (ch == checkOK3.charAt(j))
	
						break;
	
				if (j == checkOK3.length) {
	
					allValid = false;
	
					break;
	
				}
	
				allNum += ch;
	
			}
	
			if (!allValid) {
	
				alert("Escriba sólo números en el campo \"Consumo en Vatios/Día\".");
	
				formulario.consumo.focus();
	
				return (false);
	
			}	
	
		}
	
		
	
		if (formulario.autonomia.value == "") {
	
			alert("Seleccione una opción en el campo \"Días de autonomía\".");
	
			formulario.autonomia.focus();
	
			return (false);
	
		}else{	
	
			var checkStr = formulario.autonomia.value;
	
			var allValid = true;
	
			var decPoints = 0;
	
			var allNum = "";
	
			for (i = 0; i < checkStr.length; i++) {
	
				ch = checkStr.charAt(i);
	
				for (j = 0; j < checkOK3.length; j++)
	
					if (ch == checkOK3.charAt(j))
	
						break;
	
				if (j == checkOK3.length) {
	
					allValid = false;
	
					break;
	
				}
	
				allNum += ch;
	
			}
	
			if (!allValid) {
	
				alert("Escriba sólo números en el campo \"Días de autonomía\".");
	
				formulario.autonomia.focus();
	
				return (false);
	
			}	
	
		}	
	
		
	
		
	
		if(!formulario.aceptoPdp.checked){
	
			alert("Debe aceptar la política de protección de datos.");
	
			formulario.aceptoPPD.focus();
	
			return (false);	
	
		}	
	
		
	
		formulario.submit();
	
	}
	
	String.prototype.testCIF = function(){
	
		var pares = 0;
	
		var impares = 0;
	
		var suma;
	
		var ultima;
	
		var unumero;
	
		var uletra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I");
	
		var xxx;
	
	   
	
		texto = this.toUpperCase();
	
	   
	
		var regular = new RegExp(/^[ABCDEFGHKLMNPQS]\d{7}[0-9,A-J]$/g);
	
		if (!regular.exec(texto)) return false;
	
			 
	
		ultima = texto.substr(8,1);
	
	
	
		for (var cont = 1 ; cont < 7 ; cont ++){
	
			xxx = (2 * parseInt(texto.substr(cont++,1))).toString() + "0";
	
			impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
	
			pares += parseInt(texto.substr(cont,1));
	
		}
	
		xxx = (2 * parseInt(texto.substr(cont,1))).toString() + "0";
	
		impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
	
		 
	
		suma = (pares + impares).toString();
	
		unumero = parseInt(suma.substr(suma.length - 1, 1));
	
		unumero = (10 - unumero).toString();
	
		if(unumero == 10) unumero = 0;
	
		 
	
		if ((ultima == unumero) || (ultima == uletra[unumero]))
	
			return true;
	
		else
	
			return false;
	
	}
	
	
	
	
	
	String.prototype.testDNI = function() {
	
		dni = this.toUpperCase();
	
		numero = dni.substr(0,dni.length-1);
	
		let = dni.substr(dni.length-1,1);
	
		let = let.toUpperCase();
	
		numero = numero % 23;
	
		letra = 'TRWAGMYFPDXBNJZSQVHLCKET';
	
		lletra = letra.charAt(numero);
	
	   
	
		return (lletra == let)
	
	}
	
	
	
	
	
	String.prototype.testNIE = function() {
	
		var dni = this.toUpperCase();
	
		var pre = dni.substr(0, 1);
	
		var prev = '0';
	
		if (pre == 'X')
	
		   prev = '0';
	
		else if (pre == 'Y')
	
		   prev = '1';
	
		else if (pre == 'Z')
	
		   prev = '2';
	
		numero = prev + dni.substr(1,dni.length-1);
	
		return numero.testDNI();
	
	}
	

