function vacio(formul,campo,texto){	
	if(eval('document.getElementById("'+formul+'").'+campo+'.'+'value')==""){
		alert("El campo "+texto+" no puede quedar vacio");
		eval('document.getElementById("'+formul+'").'+campo+'.'+'style.border'+'="2px solid #E40000"');
		eval('document.getElementById("'+formul+'").'+campo+'.'+'focus()');
		return false;
	}
	else{
		eval('document.getElementById("'+formul+'").'+campo+'.'+'style.border'+'="1px solid #0079B1"');
		return true;
	}
}	
function isEmailAddress(elemento,form){
	var s = elemento.value;
	var filter=/^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_.-]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (s.length == 0 ) return true;
		if (filter.test(s))
			return true;
		else
		alert("Introduzca una dirección de correo válida");
		document.getElementById(form).email.style.border="2px solid #E70000";
		elemento.focus();
		return false;
}
function ntelefono (elemento,form) {
	tel=elemento;
	x=elemento.value;
	ntel=new Number(x);
	if (x.length == 0) return true;
	if (x.length<9 || isNaN(ntel)){
	 		alert('Teléfono incorrecto, tiene letras \n o menos de nueve digitos');
			document.getElementById(form).telefono.style.border="2px solid #E70000";
			elemento.focus();
			return false;
	}
	else { 
		return true;
	}
}



function enviare(h)	{
	if (isEmailAddress(document.getElementById(h).email, h)&& ntelefono(document.getElementById(h).telefono,h) != false){
    	if (vacio(h,"nombre","Persona de contacto") == false) return;
    	if (vacio(h,"empresa","Empresa") == false) return;
		if (vacio(h,"email","Correo electrónico") == false) return;
    	if (vacio(h,"telefono","Teléfono") == false) return;
    	if (h=="contacto") {
			document.getElementById(h).action="contacto.php?e=1";
		}
		if (h=="distribucion") {
			document.getElementById(h).action="distribucion.php?e=2";
		}
		document.getElementById(h).submit();
	}
}
