function validarEmail(email)
{
	var d;
  	d  = email.indexOf("@"), 
	d2 = email.lastIndexOf(".");
  	if((d<=0)||(email.indexOf(" ")!=-1)||(d>=email.length-1)||(d2<=d)||(d2>=email.length-1))
  	{
    	return false;
  	}
  	return true;
}

function valida_contacto(){
	var theForm = document.form1;
	var emailRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	var telfRE = /^[0-9]{2,3}-? ?[0-9]{6,7}$/;
	var telfRE1 = /^[0-9]+$/;
	var errMsg = "";
	var setfocus = "";
	
	if (theForm['mensaje'].value == ""){
		errMsg = "Mensaje es un campo obligatotio";
		document.getElementById('mensaje').className='text_rojo';
		setfocus = "['mensaje']";
	}
	
	if (theForm['programa'].value == ""){
		errMsg = "Programa es un campo obligatotio";
		document.getElementById('programa').className='text_rojo';
		setfocus = "['programa']";
	}
	
	if (theForm['instituto'].value == ""){
		errMsg = "Instituto de trabajo o estudio es un campo obligatotio";
		document.getElementById('instituto').className='text_rojo';
		setfocus = "['instituto']";
	}

	if (!validarEmail(theForm['email'].value)){
		errMsg = "Ingrese un E-Mail Válido, campo obligatorio";
		document.getElementById('email').className='text_rojo';
		setfocus = "['email']";
	}

	if (!telfRE1.test(theForm['telefono'].value)){
		errMsg = "Teléfono es un campo obligatotio y solo permite ingreso de números";
		document.getElementById('telefono').className='text_rojo';
		setfocus = "['telefono']";
	}
	
	if (theForm['fechanacimiento'].value == ""){
		errMsg = "Fecha de Nacimiento es un campo obligatotio";
		document.getElementById('fechanacimiento').className='text_rojo';
		setfocus = "['fechanacimiento']";
	}
	
	if (theForm['apellidos'].value == ""){
		errMsg = "Apellidos es un campo obligatotio";
		document.getElementById('apellidos').className='text_rojo';
		setfocus = "['apellidos']";
	}
	
	if (theForm['nombres'].value == ""){
		errMsg = "Nombres es un campo obligatotio";
		document.getElementById('nombres').className='text_rojo';
		setfocus = "['nombres']";
	}
	
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	
	else {
		theForm['enviar'].disabled = true;
		theForm.submit();
	}
}
