function ToggleContent(id){
	if(xGetElementById(id).style.display == 'none'){ fadeOutIn(id,'in'); } else { fadeOutIn(id,'out'); }
}

function ValidarPresentacion(){
	var MsgError = '';
	var PresentacionElegida = GetElementFormValue(xGetElementById('presentacion'));
	xGetElementById('EventoElegido').value = '';
	if(PresentacionElegida == ''){
		if(xGetElementById('insc_contenedor_errores').style.display != 'none'){ fadeOutIn('insc_contenedor_errores','out'); }
		hide('span_email_area_cliente');
		xGetElementById('tr_numero_cliente').style.display="none";
	}else{
		var objElegido = Presentaciones[PresentacionElegida];
		if(objElegido.finalizado == '1'){
			MsgError = '<strong>EVENTO FINALIZADO</strong><br />El evento seleccionado ha finalizado en la fecha '+ objElegido.fecha
			hide('span_email_area_cliente');
			xGetElementById('tr_numero_cliente').style.display="none";
		}
		if(objElegido.cerrada_inscripcion == '1'){
			MsgError = '<strong>INSCRIPCION CERRADA</strong><br />La inscripción al evento seleccionado ha sido cerrada en la fecha '+ objElegido.fecha_cierre
			hide('span_email_area_cliente');
			xGetElementById('tr_numero_cliente').style.display="none";
		}
		if(objElegido.solo_clientes == '1'){
			MsgError = '<strong>SOLO CLIENTES</strong><br />Hasta el '+ objElegido.fecha_clientes + ', la inscripción se encuentra abierta sólo para clientes de Dattatec.com.<br />Pasada dicha fecha será abierta para el público en general.'
			show('span_email_area_cliente');
			xGetElementById('tr_numero_cliente').style.display="";
			xGetElementById('EventoElegido').value = objElegido.evento;
		}
		if(objElegido.hay_lugar == '0'){
			MsgError = '<strong>CUPO COMPLETO</strong><br />El evento seleccionado posee su cupo completo. Sin embargo, la inscripción seguirá abierta y Usted quedará registrado en una lista de espera en caso de producirse vacantes.'
			hide('span_email_area_cliente');
			xGetElementById('tr_numero_cliente').style.display="none";
			xGetElementById('EventoElegido').value = objElegido.evento;
		}
		
		if(MsgError != ''){
			xGetElementById('insc_mensaje_errores').innerHTML = MsgError;
		}else{
			xGetElementById('insc_mensaje_errores').innerHTML = '';
			xGetElementById('EventoElegido').value = objElegido.evento;
		}
		if((MsgError != '') && (xGetElementById('insc_contenedor_errores').style.display == 'none')){fadeOutIn('insc_contenedor_errores','in'); }
		if((MsgError == '') && (xGetElementById('insc_contenedor_errores').style.display != 'none')){fadeOutIn('insc_contenedor_errores','out'); }
	}
}

function Registrar(){
	var MsgError = '';
	if(xGetElementById('EventoElegido').value == ''){
		MsgError = 'Debe seleccionar un evento con inscripción abierta para registrarse.';
		xGetElementById('insc_mensaje_errores').innerHTML = MsgError;
		if(xGetElementById('insc_contenedor_errores').style.display == 'none'){fadeOutIn('insc_contenedor_errores','in'); }
	}else{
		if(xGetElementById('insc_contenedor_errores').style.display != 'none'){fadeOutIn('insc_contenedor_errores','out'); }
		window.setTimeout('LanzarRegistro()', 400);
	}
}

function LanzarRegistro(){
		setClass(xGetElementById('Nombre'),'campo');
		setClass(xGetElementById('Apellido'),'campo');
		setClass(xGetElementById('Email'),'campo');
		setClass(xGetElementById('Cliente'),'campo');
		setClass(xGetElementById('identificacion'),'campo');
		setClass(xGetElementById('Ciudad'),'campo');
		setClass(xGetElementById('Pcia'),'campo');
		setClass(xGetElementById('Pais'),'campo');
		PonerTapa('form_inscripcion_container');
		PonerMensaje('tapa');
		makeRequest('/ajax-eventos-registro.php',GetRegistroResult,'POST',armarPost('inscEventoForm'));
}

function otraInsc(){
	document.inscEventoForm.reset();
	xGetElementById('EventoElegido').value = '';
	hide('span_email_area_cliente');
	xGetElementById('tr_numero_cliente').style.display="none";
	hide('insc_contenedor_errores');
	xGetElementById('insc_mensaje_errores').innerHTML = '';
	if(xGetElementById('cartel_registro_ok').style.display != 'none'){ fadeOutIn('cartel_registro_ok','out'); }
	xGetElementById('cartel_registro_ok_msg').innerHTML = '';
	xGetElementById('img_head_insc_form').src =	Images_Protocolo+':\/\/'+Images_HostName+'\/'+idiomaActual+'/imagenes/eventos-form-head.gif';
	hide('link_otra_inscripcion');
	if(xGetElementById('form_insc_div').style.display == 'none'){ fadeOutIn('form_insc_div','in'); }
}

function GetRegistroResult(xmlhttp) {
	switch (xmlhttp.readyState){
		case 1: 			
			//onLoading();
			break;
		case 2:
			//onLoaded();
			break;
		case 3:
			//onInteractive();
			break;
		case 4:
			var ErrorHTML = ''; var i; 
			var responseXML = xmlhttp.responseXML;
			var Errores = responseXML.getElementsByTagName('error');
			var Registro = responseXML.getElementsByTagName('registro');
		
			if(Errores.length > 0){
				ErrorHTML = '<strong>Ocurrieron los siguientes errores:</strong><br />';
				for (i=0; i<Errores.length; i++){
					ErrorHTML += Errores[i].firstChild.nodeValue+'<br />';
					if((Errores[i].getAttribute('campo')) && ((Errores[i].getAttribute('campo')) != '')){ setClass(xGetElementById(Errores[i].getAttribute('campo')),'campoError'); }
				}
				if(ErrorHTML != ''){ xGetElementById('insc_mensaje_errores').innerHTML = ErrorHTML; }
				if((ErrorHTML != '') && (xGetElementById('insc_contenedor_errores').style.display == 'none')){ fadeOutIn('insc_contenedor_errores','in'); }
				SacarMensaje();
				SacarTapa();
			}else{
				if(Registro.length > 0){
					if(Registro[0].getAttribute('hay_lugar') == 0){
						var MsgHTML = 'El registro de sus datos se llevó a cabo en forma exitosa.<br /><br /><strong>ATENCION..!!</strong><br />Usted ha sido registrado en una lista de espera y en caso de producirse alguna vacante durante la confirmación de asisencia, estaremos contactándolo.<br />Muchas Gracias..!!';
					}else{
						var MsgHTML = 'El registro de sus datos se llevó a cabo en forma exitosa.<br />En minutos estará llegando a su casilla un email con el código de acceso e instrucciones para su acreditación el día del evento. En caso de no llegar el e-mail, por favor, verifique en la carpeta de correo no deseado.<br /><br /><strong>Nos vemos en la Jornada..!</strong>';
					}
					xGetElementById('cartel_registro_ok_msg').innerHTML = MsgHTML;
					if(xGetElementById('form_insc_div').style.display != 'none'){ fadeOutIn('form_insc_div','out'); }
					document.inscEventoForm.reset();
					SacarMensaje();
					SacarTapa();
					xGetElementById('img_head_insc_form').src =	Images_Protocolo+':\/\/'+Images_HostName+'\/'+idiomaActual+'/imagenes/eventos-form-registro-ok-head.gif';
					if(xGetElementById('cartel_registro_ok').style.display == 'none'){ fadeOutIn('cartel_registro_ok','in'); }
					show('link_otra_inscripcion');
				}else{
					ErrorHTML = 'Ha ocurrido un error, por favor intente más tarde o repórtelo a través del formulario de <a href="contacto">contacto</a>.';
					xGetElementById('insc_mensaje_errores').innerHTML = ErrorHTML;
					if(xGetElementById('insc_contenedor_errores').style.display == 'none'){ fadeOutIn('insc_contenedor_errores','in'); }
					SacarMensaje();
					SacarTapa();
				}
			}
			break;
	}
}



function InvitarAmigo(){
	if(xGetElementById('invitacion_contenedor_errores').style.display != 'none'){fadeOutIn('invitacion_contenedor_errores','out'); }
	window.setTimeout('LanzarInvitacion()', 400);
}

function LanzarInvitacion(){
	setClass(xGetElementById('NyA'),'campo');
	setClass(xGetElementById('TuEmail'),'campo');
	setClass(xGetElementById('Email_1'),'campo');
	setClass(xGetElementById('Email_2'),'campo');
	setClass(xGetElementById('Email_3'),'campo');
	setClass(xGetElementById('Email_4'),'campo');
	PonerTapa('form_invitacion_container');
	PonerMensaje('tapa');
	makeRequest('/ajax-eventos-invitacion.php',GetInvitacionResult,'POST',armarPost('invitacionForm'));
}

function GetInvitacionResult(xmlhttp) {
	switch (xmlhttp.readyState){
		case 1: 			
			//onLoading();
			break;
		case 2:
			//onLoaded();
			break;
		case 3:
			//onInteractive();
			break;
		case 4:
			var ErrorHTML = ''; var i; 
			var responseXML = xmlhttp.responseXML;
			var Errores = responseXML.getElementsByTagName('error');
			var Invitacion = responseXML.getElementsByTagName('invitacion');
		
			if(Errores.length > 0){
				ErrorHTML = '<strong>Ocurrieron los siguientes errores:</strong><br />';
				for (i=0; i<Errores.length; i++){
					ErrorHTML += Errores[i].firstChild.nodeValue+'<br />';
					if((Errores[i].getAttribute('campo')) && ((Errores[i].getAttribute('campo')) != '')){ setClass(xGetElementById(Errores[i].getAttribute('campo')),'campoError'); }
				}
				if(ErrorHTML != ''){ xGetElementById('invitacion_mensaje_errores').innerHTML = ErrorHTML; }
				if((ErrorHTML != '') && (xGetElementById('invitacion_contenedor_errores').style.display == 'none')){ fadeOutIn('invitacion_contenedor_errores','in'); }
				SacarMensaje();
				SacarTapa();
			}else{
				if(Invitacion.length > 0){
					var MsgHTML = 'Las invitaciones se enviaron en forma exitosa.<br /><br /><strong>Muchas Gracias</strong>';
					xGetElementById('cartel_invitacion_ok_msg').innerHTML = MsgHTML;
					if(xGetElementById('form_invitacion_div').style.display != 'none'){ fadeOutIn('form_invitacion_div','out'); }
					document.invitacionForm.reset();
					SacarMensaje();
					SacarTapa();
					if(xGetElementById('cartel_invitacion_ok').style.display == 'none'){ fadeOutIn('cartel_invitacion_ok','in'); }
					show('link_otra_invitacion');
				}else{
					ErrorHTML = 'Ha ocurrido un error, por favor intente más tarde o repórtelo a través del formulario de <a href="contacto">contacto</a>.';
					xGetElementById('invitacion_mensaje_errores').innerHTML = ErrorHTML;
					if(xGetElementById('invitacion_contenedor_errores').style.display == 'none'){ fadeOutIn('invitacion_contenedor_errores','in'); }
					SacarMensaje();
					SacarTapa();
				}
			}
			break;
	}
}

function otraInv(){
	document.invitacionForm.reset();
	hide('invitacion_contenedor_errores');
	xGetElementById('invitacion_mensaje_errores').innerHTML = '';
	if(xGetElementById('cartel_invitacion_ok').style.display != 'none'){ fadeOutIn('cartel_invitacion_ok','out'); }
	xGetElementById('cartel_invitacion_ok_msg').innerHTML = '';
	hide('link_otra_invitacion');
	if(xGetElementById('form_invitacion_div').style.display == 'none'){ fadeOutIn('form_invitacion_div','in'); }
}