function noticia_show_hist(anioIni, anioEnd, anioSel)
{
    // Deshabilitar todos:
    for (var i = anioIni; i <= anioEnd; i++) {
        $('#li_' + i).removeClass('selected');
        $('#historico_' + i).hide();
    }
    // Habilitar el seleccionado:
    $('#historico_' + anioSel).show();
    $('#li_' + anioSel).addClass('selected');
}
function noticia_list(pagina)
{
    if (!document.sending) {
        document.sending = true;
        $.ajax({
            type: "POST",
            url: WEB_PATH + "app/ajax/noticia_list.php",
            data: {
                p: pagina
            },
            success: function(response) {
                document.sending = false;
                $('#noticia_col_izq').html(response);
            },
            error: function(obj, what_happen, other_obj) {
            }
        });
    }
}

function noticia_add()
{
    if (!document.sending && noticia_valid()) {
        $('#form_noticia').submit();
        //location.reload(true);
    }

}

function noticia_eliminar(id_noticia) {
    if(confirm('¿Está seguro que desea eliminar esta noticia?')) {
        if (!document.sending) {
            document.sending = true;
            $.ajax({
                type: "POST",
                url: WEB_PATH + "app/ajax/noticia_del.php",
                data: {
                    id_noticia: id_noticia
                },
                success: function(response) {
                    if(isNaN(response)) {
                        alert('Ocurrió un error al intentar borrar la noticia.\nIntentalo denuevo mas tarde.');
                    }
                    else {
                        document.sending = false;
                        $('#block_noticia_' + response).remove();
                    }
                }
            });
        }
    }
}

function noticia_get_dialog(id_escuela, id_noticia) {
    if (!document.sending) {
        document.sending = true;
        $.ajax({
            type: "POST",
            url: WEB_PATH + "app/ajax/noticia_get_dialog.php",
            data: {
                id_noticia: id_noticia,
                id_escuela: id_escuela
            },
            success: function(response) {
                document.sending = false;
                $('#content_dialog_articulo').html(response);
                msgbox_show('content_dialog_articulo');
            },
            error: function(obj, what_happen, other_obj) {
            }
        });
    }
}

function noticia_valid()
{

    var valid = true;
    if ($('#txtTituloNoticia').val().trim() == '')
    {
        valid = false;
        $('#pErrorNoticia').html('Debe ingresar un título');
    }
    else if ($('#txtCopeteNoticia').val().trim() == '')
    {
        valid = false;
        $('#pErrorNoticia').html('Debe ingresar un copete');
    }
    else if ($('#txtDescripcionNoticia').val().trim() == '')
    {
        valid = false;
        $('#pErrorNoticia').html('Debe ingresar una descripción');
    }
    else if ($()) {

    }
    return valid;
}

function limpiar_panel(){
    $('#txtTituloNoticia').val("");
    $('#txtCopeteNoticia').val("");
    $('#txtDescripcionNoticia').val("");
    $('#txtEmbedNoticia').val("");
    $('#fileFotoNoticia').val("");
    $('#pErrorNoticia').html('');
}
