var contacto_enviando = false;
var ContactoWin = "";
var Asunto = "";

function window_open_contacto(xAsunto) 
{
	Asunto = xAsunto;
	ContactoWin = new Window({className: "alphacube", minimizable: false, maximizable: false, resizable: false, destroyOnClose: true, showEffectOptions: {duration:null}})
	ContactoWin.setURL(RUTA+"estructura/pop_contacto.php?asunto="+Asunto);
	ContactoWin.setSize(450,300);         
	ContactoWin.showCenter("modal");
}

function contacto_check(doc) 
{
	MSG_BOX = $('div_msg');

	var NombreObj = document.getElementById("Nombre");
	var EmailObj = document.getElementById("Email");
	var MensajeObj = document.getElementById("Mensaje");
	var TelefonoObj = document.getElementById("Telefono");
	var InteresObj = document.getElementById("Interes");
	
	if (NombreObj.value == "") {
		msg("Debe completar el Nombre");
		NombreObj.focus();
	} else if (EmailObj.value == "") {
		msg("Debe completar el Email");
		EmailObj.focus();
	} else if (!isEmail(EmailObj)) {
		msg("Email invalido");
		EmailObj.focus();
	} else if (MensajeObj.value == "") {
		msg("Debe completar el Mensaje");
		MensajeObj.focus();
	} else {
		contacto_send(NombreObj.value, EmailObj.value, MensajeObj.value, TelefonoObj.value, InteresObj.value);
	}
}

function contacto_send(A,B,C,D,E) 
{
	if (!contacto_enviando) {
		var AJAX = new sack(RUTA+MODULO+"/ajax/contacto/");
		AJAX.setVar("Nombre", A);
		AJAX.setVar("Email", B);
		AJAX.setVar("Mensaje", C);
		AJAX.setVar("Telefono", D);
		AJAX.setVar("Interes", E);
		AJAX.onCompletion = function() {
			var v_result = AJAX.response.split("|");
			var result = v_result[0];
			if (result) {
				if (ContactoWin != ''){
					ContactoWin.setHTMLContent("<div align='center'>Mensaje enviado. Gracias por contactarse.</div>");	
					ContactoWin.setTitle("");
				} else {
					msg("Mensaje enviado. Gracias por contactarse.");
					document.getElementById("Nombre").value = "";
					document.getElementById("Email").value = "";
					document.getElementById("Mensaje").value = "";
					document.getElementById("Telefono").value = "";
					document.getElementById("Interes").value = "";
				}
			} else {
				msg("En este momento el sistema de envio de mails está caído. Lo sentimos.");
			}
			contacto_enviando = false;
		}
		msg("Enviando...");
		contacto_enviando = true;
		AJAX.runAJAX();
	} else {
		msg("Enviando, aguarde por favor...");
	}
}

function inscripcion_check(doc) 
{
	MSG_BOX = $('div_msg');
	
	if (!document.sending) {
		if ($F("Nombre") == "") {
			msg("Debe completar el nombre");
			$("Nombre").focus();
		} else if ($F("Telefono") == "") {
			msg("Debe completar el tel&eacute;fono");
			$("Telefono").focus();
		} else {
			document.sending = true;
			var AJAX = new sack(RUTA+MODULO+"/ajax/inscripcion-contacto/");
			AJAX.setVar("Nombre", $F("Nombre"));
			AJAX.setVar("Telefono", $F("Telefono"));
			AJAX.setVar("Email", $F("Email"));
			AJAX.setVar("Mensaje", $F("Mensaje"));
			AJAX.onCompletion = function() 
			{
				if (AJAX.response == 1) {
					msg("Mensaje enviado. Gracias por contactarse.");
					$("Nombre").value = "";
					$("Email").value = "";
					$("Mensaje").value = "";
					$("Telefono").value = "";
				} else {
					msg("El servidor no responde.");
				}
				document.sending = false;
			}
			msg("Enviando...");
			AJAX.runAJAX();
		}
	}
}
