/* funciones del formulario */

function validaForm() {
	var txtNom = document.getElementById("idNombre");
	var txtEml = document.getElementById("idEmail");
	var txtAsn = document.getElementById("idAsunto");
	var txtMsj = document.getElementById("idMensaje");
	
	var errNom = document.getElementById("avisoNombre");
	var errEml = document.getElementById("avisoEmail");
	var errAsn = document.getElementById("avisoAsunto");
	var errMsj = document.getElementById("avisoMensaje");
	
	var control = true;
	
	// NOMBRE
	if( txtNom.value == "" ) {
		control = false;
		errNom.innerHTML = "Campo obligatorio";
		txtNom.style.backgroundColor = "#fcc";
	} 
	else {
		errNom.innerHTML = "";
		txtNom.style.backgroundColor = "#fff";
	}
	
	// E-MAIL
	if( txtEml.value == "" ) {
		control = false;
		errEml.innerHTML = "Campo obligatorio";
		txtEml.style.backgroundColor = "#fcc";
	} 
	else if( validaEmail(txtEml.value) == false ) {
		control = false;
		errEml.innerHTML = "El formato no es correcto";
		txtEml.style.backgroundColor = "#fcc";
	}
	else {
		errEml.innerHTML = "";
		txtEml.style.backgroundColor = "#fff";
	}
	
	// ASUNTO
	if ( txtAsn.value == "" ){
		control = false;
		errAsn.innerHTML = "Campo obligatorio";
		txtAsn.style.backgroundColor = "#fcc";
	}
	else {
		errAsn.innerHTML = "";
		txtAsn.style.backgroundColor = "#fff";
	}
	
	// MENSAJE
	if ( txtMsj.value == "" ){
		control = false;
		errMsj.innerHTML = "Campo obligatorio";
		txtMsj.style.backgroundColor = "#fcc";
	}
	else {
		errMsj.innerHTML = "";
		txtMsj.style.backgroundColor = "#fff";
	}
	
	/*
	if ( control ) {
		document.getElementById("formContacto").submit();
	}
	*/
	return control;
}

function validaEmail(p) {
	var control = true;
	
	if ( p.indexOf("@") <= 0 ) {
		control = false;
	}
	
	if ( p.lastIndexOf(".") <= p.indexOf("@") ) {
		control = false;
	}
	
	return control;
}




