// JavaScript Document

function ListarEventos(pag){
	if(pag==null) pag=0;
	
	var datos="pagajax=paginas/web/tabla_eventos.php";
	datos+="&pag="+pag;
	datos+="&"+$('#frmFiltro').serialize();
	//MostrarAviso(datos);
	$.ajax({
		url: "paginas/ajax.php",
		data: datos,      
		global: false,
      	type: "POST",
		async: false,
		success: function(html){ $('#visor').html(html); }
	})
}

function FichaEvento(id){
	if(id==null) id="";
	var data="&id="+id;
	CargarSeccion("web","ficha_evento", data);		
}

function AccionesEventos(accion, id){
	if(id==null) id="";
	
	var datos="pagajax=paginas/web/ajax_eventos.php";
	datos+="&id="+id;
	datos+="&accion="+accion;
	if(accion=="almacenar"){
		datos+="&"+$('#frmEvento').serialize();
	}
	//MostrarAviso(datos);
	var html=$.ajax({
		url: "paginas/ajax.php",
		data: datos,      
		global: false,
      	type: "POST",
		async: false,
		success: function(){}
	}).responseText;	
	return(html);
}

function AlmacenarEvento(id){
	var txt="";
	var ok=true;
	if($('#titulo').val()==""){
		txt+="Debe indicar un titulo";
		ok=false;
	}
	if($('#tipo').val()==""){
		txt+="No ha indicado el tipo de evento";
		ok=false;
	}
	if($('#email').val()==""){
		txt+="Debe indicar un email para las suscripciones";
		ok=false;
	}
	
	if(ok){
		if(id==null) id="";
		var html=AccionesEventos('almacenar', id);
		if(html!=""){
			MostrarAviso(html, "Almacenar Evento");	
		}else{
			CargarSeccion("web","visor_eventos");
		}
	}else{
		MostrarAviso("De completar la siguiente informaci\xF3n:<br/>"+txt,"Almacenar Evento");
	}
}

function EliminarEvento(id){
	if(id!="" && confirm("\xBFDesea eliminar este Evento?")){
		var html=AccionesEventos('eliminar',id);
		if(html!=""){
			MostrarAviso(html, "Eliminar Evento");	
		}
		ListarEventos();
	}
}

function CambiarEstadoEvento(id){
	var html=AccionesEventos('cambiar_estado',id);
	if(html!=""){
		MostrarAviso(html, "Cambiar Estado Evento");	
	}
	ListarEventos();
}
/*==================================================================*/
/*							TIPOS DE EVENTOS						*/
/*==================================================================*/
function AccionesTiposEvento(accion, id, valor){
	if(id==null) id="";
	if(valor==null) valor="";
	
	var datos="pagajax=paginas/web/ajax_tiposeventos.php";
	datos+="&accion="+accion;
	datos+="&id="+id;
	datos+="&valor="+valor;
	if(accion=="almacenar"){
		datos+="&"+$('#frmTiposEvento').serialize();
	}
	//MostrarAviso(datos);
	var html=$.ajax({
		url: "paginas/ajax.php",
		data: datos,      
		global: false,
      	type: "POST",
		async: false,
		success: function(){}
	}).responseText;	
	return(html);
}

function SelectTiposEvento(obj_id, tipo){
	var html=AccionesTiposEvento('selecttipo','',tipo);
	$('#'+obj_id).html(html);
}

function GestionTiposEvento(){
	var html=AccionesTiposEvento('gestiontiposevento');
	$('#div_tiposeventos').html(html);
	MostrarDialogo('div_tiposeventos',"Gesti&oacute;n de Tipos de Eventos", 400, 360);
	ListarTiposEvento();
	FichaTiposEvento();
}

function ListarTiposEvento(){
	var html=AccionesTiposEvento('listatipos');
	$('#listatipos').html(html);
}

function FichaTiposEvento(id){
	if(id==null) id="";
	var html=AccionesTiposEvento('fichatipos',id);
	$('#fichatipos').html(html);
}

function AlmacenarTiposEvento(id){
	if(id==null) id="";
	var html=AccionesTiposEvento('almacenar',id);
	if(html!=""){
		MostrarAviso(html, "Almacenar Tipo Evento");	
	}else{
		ListarTiposEvento();
		FichaTiposEvento();
		SelectTiposEvento('tipo', $('#tipo').val());	
	}
}

function EliminarTiposEvento(id){
	if(id==null) id="";
	var html=AccionesTiposEvento('eliminar',id);
	if(html!=""){
		MostrarAviso(html, "Eliminar Tipo Evento");	
	}else{
		ListarTiposEvento();
		FichaTiposEvento();
		SelectTiposEvento('tipo', $('#tipo').val());	
	}
}
