function validaForm(f) {
	
	if ( f.nom.value == "" ) {
		alert("El Nombre es obligatorio.")
		f.nom.focus()
		return false
	}
	
	if ( f.dir.value == "" ) {
		alert("La dirección es obligatoria.")
		f.dir.focus()
		return false
	}
	
	if ( f.cp.value == "" ) {
		alert("El Código postal es obligatorio.")
		f.cp.focus()
		return false
	} else {
		if ( f.cp.value.length < 5 || isNaN(f.cp.value) || 
	     	 f.cp.value.substring(0,2) < 1 || f.cp.value.substring(0,2) > 52 ) {
			alert("El Código postal no es correcto.")
			f.cp.focus()
			return false
		}	 
	}
	
	if ( f.pob.value == "" ) {
		alert("La población es obligatoria.")
		f.pob.focus()
		return false
	}
	
	if(f.tel.value=="" && f.tel.value=="") {
		alert("El teléfono es obligatorio.")
		f.tel.focus()
		return false
	}
	
	//Comprueba que se introduzcan los telefonos
		
	var tamTelf = 9
	if ( f.tel.value!="" && (isNaN(f.tel.value) || f.tel.value.length != tamTelf) ) {
		  alert("Por favor, escribe los " + tamTelf + " dígitos del teléfono.")
		  f.tel.focus()
		  return false
	}
	
	if ( f.nent.value == "" ) {
		alert("No nos comunicas el nº de depósitos que quieres que te llevemos.")
		f.nent.focus()
		return false
	}
	
	if ( f.con.value == "" ) {
		alert("Inserta una persona de contacto.")
		f.con.focus()
		return false
	}
		
	// Todo OK, enviamos el formulario
	return true
}

var validar=function(formulario,validarCampo,evt)
{
	if(validarCampo)
	{
   		evt = evt || window.event;
   		var cd= evt.which || evt.keyCode;
		return (cd<45 || cd >57)?false:true;
	}
}  

function validarletras(e) { // 1
    tecla = (document.all) ? e.keyCode : e.which; // 2
    if (tecla==8) return true; // 3
    patron =/[A-Za-z\s]/; // 4
    te = String.fromCharCode(tecla); // 5
    return patron.test(te); // 6
} 

function validaForm2(g) {
	
if ( g.cusu.value == "" ) {
		alert("El Código de Usuario está vacío.")
		g.cusu.focus()
		return false
	}
	
	if ( g.cli.value == "" ) {
		alert("El Código de Cliente está vacío.")
		g.cli.focus()
		return false
	}


return true
}


function validaForm3(h) {
	
if ( h.forma.value == "opcion") {
		alert("Debes seleccionar una forma de entrega")
		h.forma.focus()
		return false
	}
	
	return true
}

function validaForm4(k) {
	
	if ( k.nom.value == "" ) {
		alert("El Nombre es obligatorio.")
		k.nom.focus()
		return false
	}
	
	if( k.Email.value.length == 0 || !validamail(k.Email.value) ) {
		alert("El E-mail parece incorrecto.");
	    k.Email.focus()
		return false
    }
	
	//Comprueba que se introduzcan los telefonos
	
	if ( k.tel.value == "" ) {
		alert("El Telefono es obligatorio.")
		k.tel.focus()
		return false
	}
	
	var tamTelf = 9
	if ( k.tel.value!="" && (isNaN(k.tel.value) || k.tel.value.length != tamTelf) ) {
		  alert("Por favor, escribe los " + tamTelf + " dígitos del teléfono.")
		  k.tel.focus()
		  return false
	}
	
	if ( k.dir.value == "" ) {
		alert("La dirección es obligatoria.")
		k.dir.focus()
		return false
	}
	
	if ( k.pro.value == "" ) {
		alert("La población es obligatoria.")
		k.pro.focus()
		return false
	}
	
	if ( k.comentarios.value == "" ) {
		alert("Los comentarios son obligatorios.")
		k.comentarios.focus()
		return false
	}
	
	// Todo OK, enviamos el formulario
	return true
}

function validamail(Email){

	// Mínimo de 5 caracteres
	if (Email.length < 5)
		return false
		
	// Cadena de caracteres no permitidos
	var iChars = "+*|,\":<>[]{}`';()&$#% ";	
	
	// Primero comprobamos que en el email no haya algún 
	// caracter no permitido
	var eLength = Email.length;	
	for (var i=0; i < eLength; i++)	{		
		if (iChars.indexOf(Email.charAt(i)) != -1)
			return false
	}	
	
	// Comprobamos que la @ tenga algún caracter delante y alguno detrás
	var atIndex = Email.lastIndexOf("@");	
	if(atIndex < 1 || (atIndex == eLength - 1))
		return false

	// Comprobamos que exista '.' a partir del cuarto carácter, pero
	// que no acabé en '.'
	var pIndex = Email.lastIndexOf(".");	
	if(pIndex < 3 || (pIndex == eLength - 1))	
		return false;	

	// Por último, comprobamos que el punto esté detrás de la @
	if(atIndex > pIndex)	
		return false	

	return true
}

