function validar_casa_transito(){
	var msg = ' ';
	if(document.form.nombre.value == ''){
		msg = 'Ingrese su nombre';
	}else if(document.getElementById("telefono").value == ''){
		msg += 'Escriba su telefono';
	}else if((document.getElementById("email").value == '') || !(/^[0-9a-z_\.\-]+@[0-9a-z_\.\-]+\.[a-z]{2,4}$/.test(document.form.email.value.toLowerCase()))){
		msg += 'Ingrese un correo válido';	
	}else if(document.form.tipocasa.selectedIndex == 0){
		msg += 'Elija el tipo de animal a acoger';	
	}else if(document.form.vivo.selectedIndex == 0){
		msg += 'Elija casa o departamento';	
	}else if(document.form.tiempo.selectedIndex == 0){
		msg += 'Elija cuánto tiempo puede ser casa de acogida';	
	}else if(document.form.condicion.selectedIndex == 0){
		msg += 'Elija la condición de acogida';	
	}else if(document.getElementById("numerosemanas").value == ''){
		msg += 'Elija el número de semanas, meses o semestres';
	}else if(document.getElementById("mensaje").length == ''){
		msg+= 'Ingrese Mensaje';
	}
	if(msg != ' '){
	alert(msg);	
	msg = ' ';
	}else {valida_casa_transito();
	}
}

var READY_STATE_COMPLETE=4;
var peticion_http = null;
function inicializa_xhr_casa_transito() {
if(window.XMLHttpRequest) {
return new XMLHttpRequest();
}
else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function crea_query_string_casa_transito() {
var nombre = document.getElementById("nombre");
var telefono = document.getElementById("telefono");
var email = document.getElementById("email");
var tipocasa = document.getElementById("tipocasa");
var vivo = document.getElementById("vivo");
var tiempo = document.getElementById("tiempo");
var condicion = document.getElementById("condicion");
var numerosemanas = document.getElementById("numerosemanas");
var mensaje = document.getElementById("mensaje");
return "nombre=" + encodeURIComponent(nombre.value) +
"&telefono=" + encodeURIComponent(telefono.value) +
"&email=" + encodeURIComponent(email.value) +
"&tipocasa=" + encodeURIComponent(tipocasa.value) +
"&vivo=" + encodeURIComponent(vivo.value) +
"&tiempo=" + encodeURIComponent(tiempo.value) +
"&condicion=" + encodeURIComponent(condicion.value) +
"&numerosemanas=" + encodeURIComponent(numerosemanas.value) +
"&mensaje=" + encodeURIComponent(mensaje.value) +
"&nocache=" + Math.random();
}
function valida_casa_transito() {
	peticion_http = inicializa_xhr_casa_transito();
	if(peticion_http) {
		peticion_http.onreadystatechange = procesaRespuesta_casa_transito;
		peticion_http.open("POST", "/wp-content/themes/animales/casa_transito_proceso.php", true);
		peticion_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		var query_string = crea_query_string_casa_transito();
		peticion_http.send(query_string);
	}
}
function procesaRespuesta_casa_transito() {

	if(peticion_http.readyState == 2 || peticion_http.readyState == 3){
		document.getElementById("formulario").innerHTML = '<img src="loading.gif" />';
	}
	if(peticion_http.readyState == READY_STATE_COMPLETE) {
		if(peticion_http.status == 200) {
			document.getElementById("formulario").innerHTML = peticion_http.responseText;
		}
	}

}




		
			
		
		

