// JavaScript Document
//----------------------------------------------------------------------
//Funciones para AJAX
//----------------------------------------------------------------------

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;
}

//--------------------------------------
//me permite enviar el formulario de los planes
function enviar_formulario(){
	//detecto el lugar e la respuesta
	$resultado = window.document.getElementById('respuesta');
	
	//capturo los valores del formulario
	$nombre =  window.document.getElementById('nombre').value;
	$pais =  window.document.getElementById('pais').value;
	$ciudad =  window.document.getElementById('ciudad').value;
	$telefonos =  window.document.getElementById('telefonos').value;
	$direccion =  window.document.getElementById('direccion').value;
	$email =  window.document.getElementById('email').value;
	$comentarios =  window.document.getElementById('comentarios').value;
	$deseo_respuesta =  window.document.getElementById('deseo_respuesta').checked;
	
	//alert($nombre + " " + $pais + " " + $ciudad + " " + $telefonos + " " + $direccion + " " + $email + " " + $comentarios + " " + $deseo_respuesta);
	
	$continuar = true;
	$error = "DATOS INCOMPLETOS\n\n";
	
	//valido que los datos ingresados esten correctos
	$nombre = Valida_Texto($nombre);
	if($nombre==""){
		$error += "- Ingrese su nombre.\n";
		$continuar = false;
	}
	$email = Valida_Texto($email);
	if($email==""){
		$error += "- Ingrese un email.\n";
		$continuar = false;
	}
	
	if($deseo_respuesta){
		$deseo_respuesta = 1;
	} else {
		$deseo_respuesta = 0;
	}
	
	//realizo el proceso
	if($continuar){
		//Instanciamos el objetoAjax
		ajax=objetoAjax();
		//Usamos el medoto POST
		//Archivo que realizará la operacion
		ajax.open("POST", "../consultas/enviar_contacto.php",true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState==4) {
				window.alert(ajax.responseText);
				$resultado.innerHTML = "";
			} else {
				$resultado.innerHTML = "Espere un momento se esta procesando el envío ... ";
			}
		}
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//enviando los valores
		ajax.send("nombre="+$nombre+"&pais="+$pais+"&ciudad="+$ciudad+"&direccion="+$direccion+"&email="+$email+"&telefonos="+$telefonos+"&comentarios="+$comentarios+"&deseo_respuesta="+$deseo_respuesta);
	}else{
		alert ($error);
	}
	return false;
}