// JavaScript Document

// Función para validar los campos del formulario de contacto
function validarFormulario(){
	if(document.frmPedidos.empresa.value==""){
		alert("Por favor introduzca la Empresa");
		document.frmPedidos.empresa.focus();
		return false;
	}
	
	if(document.frmPedidos.contacto.value==""){
		alert("Por favor introduzca Persona de Contacto");
		document.frmPedidos.contacto.focus();
		return false;
	}
	
	if(document.frmPedidos.email.value==""){
		alert("Por favor introduzca el e-mail");
		document.frmPedidos.email.focus();
		return false;
	}else{
		var vemail=checkEmailAddress(document.frmPedidos.email);
		if (vemail==false){
			return false;
		}
	}
	
	if (document.frmPedidos.info.value==""){
		alert("Por favor introduzca información que desea recibir");
		document.frmPedidos.info.focus();
		return false;
	}
}

//*************************************************************************//
function checkEmailAddress(field)//Valida Email
{

	var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.tv)|(\.la)|(\.name)|(\.us)|(\.cc)|(\.co)|(\..{2,2}))$)\b/gi);

	if (goodEmail){
		return true
	} else {
		alert('Por favor introduzca una dirección de e-mail válida')
		field.focus()
		field.select()
		return false
	}
}

// Validación de campos numéricos (funciona en IE y Mozilla)
function validarCamposNumericos(e){ 
	tecla = (document.all) ? e.keyCode : e.which;
    if (tecla==8) return true;
    patron = /[0123456789]/;
    te = String.fromCharCode(tecla);
    return patron.test(te);
} 
