
var PAGINA="";//"http://localhost/pruebas/limusinas/presupuesto/";
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(nombre, comentario, email, telefono, empresa, pais, sitio, conoces) {
	return "nombre=" + encodeURIComponent(nombre) +
	"&comentario=" + encodeURIComponent(comentario) + 
	"&telefono=" + encodeURIComponent(telefono) + 
	"&empresa=" + encodeURIComponent(empresa) + 
	"&pais=" + encodeURIComponent(pais) + 
	"&sitio=" + encodeURIComponent(sitio) + 
	"&conoces=" + encodeURIComponent(conoces) + 
	"&email=" + encodeURIComponent(email);
}

function enviar(){
	var nombre=document.getElementById("nombre_").value;
	var comentario=document.getElementById("comentario_").value;
	var email=document.getElementById("email_").value;
	var telefono=document.getElementById("telefono_").value;
	var empresa=document.getElementById("empresa_").value;
	var pais=document.getElementById("pais_").value;
	var sitio=document.getElementById("sitio_").value;
	var conoces=document.getElementById("conoces_").value;

if (comprobar(email, comentario, nombre, telefono)){
		peticion_http=null;
		peticion_http=inicializa_xhr();
		if (peticion_http){
			peticion_http.onreadystatechange = procesaRespuesta;
			peticion_http.open("POST", PAGINA+"contacto.php", true);
			peticion_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			peticion_http.send(crea_query_string(nombre, comentario, email, telefono, empresa, pais, sitio, conoces));
		}
	}else{
		alert("¡¡¡ Campos requeridos sin rellenar !!!");
	}
}

function procesaRespuesta() {
	if(peticion_http.readyState == READY_STATE_COMPLETE) {
		if(peticion_http.status == 200) {
			alert("Formulario enviado, en breve nos pondremos en contacto con usted "+peticion_http.responseText);
		}
	}
}

function comprobar(comentario, email, telefono, comentario){
	if (comentario==""){
		return false;
	}
	if (email==""){
		return false;
	}
	if (telefono==""){
		return false;
	}
	if (comentario==""){
		return false;
	}
	return true;
}


