function validar(){
	msg = '';
	if(document.form.nombre.value == ''){
		msg = 'Por favor ingresa tu Nombre';
		
	}else if((document.form.email.value == '') || !(/^[0-9a-z_\.\-]+@[0-9a-z_\.\-]+\.[a-z]{2,4}$/.test(document.form.email.value.toLowerCase()))){
		msg += 'Por favor ingresa un correo Valido';	
		
			
		}else if(document.form.asunto.value ==''){
		msg+= 'Por favor ingresa Asunto';	
		
			}else if(document.form.mensaje.value ==''){
		msg+= 'Por favor ingresa tu mensaje';	
		
	
	}
	if(msg != ''){
	alert(msg);	
	msg = '';
	}else {valida();
	}
}

var READY_STATE_COMPLETE=4;
var peticion_http = null;
function inicializa_xhr() {
if(window.XMLHttpRequest) {
return new XMLHttpRequest();
}
else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function crea_query_string() {
var nombre = document.getElementById("nombre");
var email = document.getElementById("email");
var asunto = document.getElementById("asunto");
var mensaje = document.getElementById("mensaje");
return "nombre=" + encodeURIComponent(nombre.value) +
"&email=" + encodeURIComponent(email.value) +
"&asunto=" + encodeURIComponent(asunto.value) +
"&mensaje=" + encodeURIComponent(mensaje.value) +
"&nocache=" + Math.random();
}
function valida() {
peticion_http = inicializa_xhr();
if(peticion_http) {
peticion_http.onreadystatechange = procesaRespuesta;
peticion_http.open("POST", "respuesta.php", true);
peticion_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var query_string = crea_query_string();
peticion_http.send(query_string);
}
}
function procesaRespuesta() {
if(peticion_http.readyState == 2 || peticion_http.readyState == 4){
document.getElementById("respuesta").innerHTML = '<img src="loading.gif" />';
}



if(peticion_http.readyState == READY_STATE_COMPLETE) {
if(peticion_http.status == 200) {
	setTimeout('document.getElementById("respuesta").innerHTML = peticion_http.responseText;', 500);
	document.getElementById("main").style.display='none';
}
}

}




		
			
		
		
