function noticias() {};


/**********************************************************************************
FUNCIÓN INICIALIZAR ENLACES
**********************************************************************************/
noticias.inicializar = function() {
	
	mecanica_paginador(noticias);
//activar paginador
	activa_paginador(noticias);

	$("#bus_buscar").click(function(event) { $("#pag_offset").val(0);  noticias.buscar(); });
	$("#bus_borrar").click(function(event) { $("#bus_texto").val(""); $("#pag_offset").val(0); noticias.buscar();  	});

	$("#aceptar").click(function(event) { $("#bus_texto").val(""); $("#pag_offset").val(0);  noticias.buscar(); });

	$("#listado a").click(function(event) { noticias.ver($(this).parents("tr").attr("id"));	});
	$("#cancelar").click(function(event) { noticias.boton_cancelar_sin_dialogWindow();  });	
	$("#cancelar_portada").click(function(event) { noticias.ir_portada();  });	

	noticias.dibujar_paginador();

}



/**********************************************************************************
FUNCIÓN PARA REALIAZAR BUSQUEDAS
**********************************************************************************/
noticias.buscar=function() {
		
	//obtener variables
	var busqueda=$("#bus_texto").val();
	var offset=$("#pag_offset").val();

	if (busqueda=="" ) cadena="./base/index.php?controlador=noticias&accion=listar&";
	else cadena="./base/index.php?controlador=noticias&accion=listar&bus_texto="+escape(busqueda)+"&";
	cadena += "pag_offset="+escape(offset);
	$.ajax({
		url: cadena,
		type: "POST",
		cache: false,
		contentType: "application/x-www-form-urlencoded",
		error: function (xhr, ajaxOptions, thrownError){
			if (xhr.status == 403)  document.location="validar.php?enduser=on"; 			
			return;
        } ,
		success: function(html){	
			$("#contenedor").html(html);
			noticias.inicializar();					
		}
	});
}

/**********************************************************************************
FUNCIÓN ACCIONDB: para modificar o borrar enlaces
**********************************************************************************/
noticias.ver = function (id) {
	cadena = "./base/index.php?controlador=noticias&accion=ver&id=" + id;
	$.ajax({
		url: cadena,
		type: "POST",
		cache: false,
		error: function (xhr, ajaxOptions, thrownError){
			if (xhr.status == 403)  alert("Error del servidor");
			return;
        } ,
		success: function(html){	
		
			$("#contenedor").html(html);
			noticias.inicializar();			
	 	}
	});
}



noticias.ver_noticias = function(accion) {
	cadena = "./base/index.php?controlador=noticias&accion="+accion;
	$.ajax({
		url: cadena,
		type: "POST",
		cache: false,
		error: function (xhr, ajaxOptions, thrownError){
			if (xhr.status == 403)  alert("Error del servidor");
			return;
        } ,
		success: function(html){
			
			$("#contenedor_noticias").html(html);
			noticias.inicializar();			
	 	}
	});
}


/**********************************************************************************
FUNCIÓN DEL BOTÓN CANCELAR
**********************************************************************************/
noticias.boton_cancelar_sin_dialogWindow = function() {
		
	noticias.disabled=false; 
	
	//dialogWindow.destroyWindow(); 
	noticias.buscar();
}
/**********************************************************************************
FUNCIÓN DE IR A PORTADA
**********************************************************************************/
noticias.ir_portada = function() {
		
	noticias.disabled=false; 
	location.href="index.php?modulo=portada";
}
