// JavaScript Document
function objetoAjax(){
var xmlhttp=false; 
try { 
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
} catch (e) { 
try { 
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
} catch (E) { 
xmlhttp = false; 
} 
} 

if (!xmlhttp && typeof XMLHttpRequest!='undefined') { 
xmlhttp = new XMLHttpRequest(); 
} 
return xmlhttp; 
} 

function validacion(form){
	divalertas = document.getElementById('msgbox');
	if (form.nombre.value.length < 1 || form.nombre.value == "Nombre"){
		divalertas.innerHTML = "<img src='images/icon_exclamation.gif' width='12' height='12' border='0', align='top' />&nbsp;&nbsp;Por favor, escriba su Nombre&nbsp;";
		divalertas.style.display = "none";
		$(divalertas).fadeIn(400);
		//setTimeout( "end_msgbox();", 5000);
		return false;
	}else if (form.email.value.length < 1 || form.email.value == "Email"){
		divalertas.innerHTML = "<img src='images/icon_exclamation.gif' width='12' height='12' border='0', align='top' />&nbsp;&nbsp;Por favor, escriba su Email&nbsp;";
		divalertas.style.display = "none";
		$(divalertas).fadeIn(400);
		//setTimeout( "end_msgbox();", 10000);
		return false;
	}else if ((form.email.value.indexOf('@', 0) == -1)||(form.email.value.length < 5)) {
		divalertas.innerHTML = "<img src='images/icon_exclamation.gif' width='12' height='12' border='0', align='top' />&nbsp;&nbsp;Por favor, escriba bien su Email&nbsp;";
		divalertas.style.display = "none";
		$(divalertas).fadeIn(400);
		//setTimeout( "end_msgbox();", 10000);
		return false;
	}else if (form.consulta.value.length < 1 || form.consulta.value == "Consulta"){
		divalertas.innerHTML = "<img src='images/icon_exclamation.gif' width='12' height='12' border='0', align='top' />&nbsp;&nbsp;Por favor, escriba su Consulta&nbsp;";
		divalertas.style.display = "none";
		$(divalertas).fadeIn(400);
		//setTimeout( "end_msgbox();", 10000);
		return false;
	}else{
		
		divalertas.innerHTML = "<img src='images/preloader.gif' width='12' height='12' border='0', align='top' />&nbsp;&nbsp;Enviando su Consulta, aguarde...&nbsp;";
		divalertas.style.display = "none";
		$(divalertas).fadeIn(400);
		nombre = form.nombre;
		email = form.email;
		consulta = form.consulta;
		ajax=objetoAjax(); 
		ajax.open("POST", "envio_consulta.php",true); 
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		ajax.onreadystatechange=function() { 
			if (ajax.readyState==4) { 
				if(ajax.responseText=="ok"){
					divalertas.style.display = "none";
					nombre.value = "Nombre";
					email.value = "Email";
					consulta.value = "Consulta";
					divalertas.innerHTML = "Su consulta ha sido enviada, gracias !&nbsp;";
					$(divalertas).fadeIn(400);
				}
			}
		}
		ajax.send("nombre="+nombre.value+"&email="+email.value+"&consulta="+consulta.value); 
	}
	
}
function end_msgbox(){
	divalertas = document.getElementById('msgbox');
	$(divalertas).fadeOut(400);
}

function infoc(imp){
	if(imp.id == "nombre"){
		if(imp.value == "Nombre"){
			imp.value = "";	
		}
	}else if(imp.id == "email"){
		if(imp.value == "Email"){
			imp.value = "";	
		}
	}else if(imp.id == "consulta"){
		if(imp.value == "Consulta"){
			imp.value = "";	
		}
	}
}
function outfoc(imp){
	if(imp.id == "nombre"){
		if(imp.value == ""){
			imp.value = "Nombre";
		}
	}else if(imp.id == "email"){
		if(imp.value == ""){
			imp.value = "Email";
		}
	}else if(imp.id == "consulta"){
		if(imp.value == ""){
			imp.value = "Consulta";
		}
	}
}