var err = 0;

function uploadimg(theform)
{
    $('#dvSubiendo').show();
    $('#btnSubir').hide();
    theform.submit();
}

function doneloading(id)
{
    parent.showImages(id);
}

function doneloadingNews(id)
{
    parent.showImagesNews(id);
}

function doneloadingerror()
{
    parent.showErrorImages(document.body.innerHTML);
}

function showImages(id)
{
    $.get("index.php",
        {controlador: "archivos", accion: "show", idSecc: id},
        function(data){
            $("#dvListImages").html(data);
            $('#dvSubiendo').hide();
            $('#btnSubir').show();
        }
    );
}

function showImagesNews(id)
{
    $.get("index.php",
        {controlador: "archivos", accion: "showNews", idSecc: id},
        function(data){
            $("#dvListImages").html(data);
            $('#dvSubiendo').hide();
            $('#btnSubir').show();
        }
    );
}

function showErrorImages(txt)
{
    $('#dvSubiendo').hide();
    $('#btnSubir').show();
    alert(txt);
}

// Crea un nuevo comentario a una noticia
function newcomment(id) {
    $('#fNuevoComentario input[type=submit]').hide();
    $('#dvEnviando').show();
    $.post("/index.php?controlador=noticias&accion=newcomment&id="+id,
        {controlador: "noticias", accion: "newcomment", url: $('#h_url').val(), s_nombre: $('#s_nombre').val(), s_email: $('#s_email').val(), t_texto: $('#t_texto').val(), swAJAX: "yes"},
        function(data){
            if( data == '-1') {
                alert('Debes rellenar todos los campos');
            }
            else {
                $('.spNoComentarios').hide();
                $('.dvComentarios ul').html($('.dvComentarios ul').html()+data);
                $('#h_url').val('');
                $('#s_nombre').val('');
                $('#s_email').val('');
                $('#t_texto').val('');
            }
            $('#fNuevoComentario input[type=submit]').show();
            $('#dvEnviando').hide();
        }
    );

    return false;
}

// Inserta imagen en el area de texto activa, en la posicion del cursor
function showImgURI(img)
{    
    //$('#spImgURI').html(img);
    var imagen = "<img src='"+img+"'/>";
    window.tinyMCE.execCommand('mceInsertContent', false, imagen);
}

function showMenu(items)
{
    $(items).slideToggle();
    if( $(items).css("display") == "block" )
    {
        // Cerrar menu
        $.get("index.php",
            {controlador: "admin", accion: "closeMenu", item: items},
            function(data){
            }
        );
    }
    else
    {
        // Abrir menu
        $.get("index.php?controlador=admin&accion=openMenu&item="+items,
            {controlador: "admin", accion: "openMenu", item: items},
            function(data){
            }
        );
    }
}

function hideMsg()
{
    $('.dvOK').html('');
    $('.dvOK').slideUp();
    $('.dvError').html('');
    $('.dvError').slideUp();
}

function addMenu(idForm)
{ 
    var f = $('#fAddMenu_'+idForm);
    //var secc = document.getElementById('n_seccion_fk'+idForm).options[document.getElementById('n_seccion_fk'+idForm).selectedIndex].value;
    var secc = $('#n_seccion_fk_'+idForm).val();
    var tit = $('#s_titulo_'+idForm).val();
        
    var menu =  idForm;
        
    //$("#spBotones"+post).fadeOut(700);
    $.post("index.php?controlador=menu&accion=add",
        {controlador: "menu", accion: "add", n_seccion_fk: secc, s_titulo: tit, n_menu_fk: menu},
        function(data){            
            $("#ulListItems"+idForm).html($("#ulListItems"+idForm).html()+"\n"+data);
            $("#ulListItems"+idForm).sortable('refresh');
            document.getElementById("n_seccion_fk_"+idForm).selectedIndex = 0;
            $("#s_titulo_"+idForm).val('');
        }, "text"
    );
    
}

function setTitle(val, txt, id)
{
    
    if( val == '0')
    {
        $('#s_titulo_'+id).val('');
    }
    else
    {
        $('#s_titulo_'+id).val(txt);
    }
}

function makeSortable(id)
{
    $("#ulListItems"+id).sortable({ 
    handle : '.handle',
    opacity: 0.6,
    cursor: 'move',
    update : function () { 
      var order = $('#ulListItems'+id).sortable('serialize'); 
      //$("#info").load("process-sortable.php?"+order);
      
    $.get("index.php",
    {controlador: "menu", accion: "reorder", orden: order},
        function(data){            
            
        }
    );
    } 
  }); 
}

function nopublicar()
{
        $('#d_fpublica').val('');
        $('#spprograma').addClass('hidden');
 
}

function publicar()
{
        $('#d_fpublica').val('');
        $('#spprograma').removeClass('hidden');
}

function chgFPublicar(txt)
{
    if( txt != '' )
        $('#d_fpublicar').checked = true;
    else
        $('#d_fpublicar').checked = false;
}

function delUser(id, login)
{
    if(confirm('¿Eliminar '+login+'? Esto no puede deshacerse.'))
    {
        $('#trUser'+id).fadeOut(1000);
        $.get("index.php?controlador=admin&accion=delUser&id="+id,
        {},
        function(data){                        
        }
    );
    }
}

function deleteMenuItem(id, orden, tipo, idForm)
{
    if(confirm('¿Eliminar item del menú? Esto no puede deshacerse.'))
    {
        $('#itemMenu_'+id).fadeOut(1000);
        setTimeout(function(){$('#itemMenu_'+id).remove()},1002);
        $.get("index.php?controlador=menu&accion=delMenu&id="+id+"&orden="+orden+"&tipo="+tipo,
        {},
        function(data){
            //alert(data);
            $("#ulListItems"+idForm).sortable('refresh'); // Actualizar reordenar
        }
    );
    }
}

function editInicioMenu(idForm)
{
    $('#spMsgGuardando_'+idForm).show();
    
    var f = $('#n_inicio_'+idForm).is(':checked');
    
    var menu =  idForm;
        
    $.post("index.php?controlador=menu&accion=editInicio",
        {controlador: "menu", accion: "editInicio", checkvalue: f, n_menu_fk: menu},
        function(data){
            $('#spMsgGuardando_'+idForm).hide();
            $('#spMsgGuardado_'+idForm).fadeIn();
            setTimeout(function(){$('#spMsgGuardado_'+idForm).fadeOut();},1200);
        }, "text"
    );
}

/* Resumenes */

function addResumen(idForm)
{
    var f = $('#fAddResumen');
    //var secc = document.getElementById('n_seccion_fk'+idForm).options[document.getElementById('n_seccion_fk'+idForm).selectedIndex].value;
    var secc = $('#n_seccion_fk').val();
    var tit = $('#s_titulo').val();

    var resumen =  idForm;

    //$("#spBotones"+post).fadeOut(700);
    $.post("index.php?controlador=secciones&accion=addSeccResumen",
        {controlador: "secciones", accion: "addSeccResumen", n_seccion_fk: secc, s_titulo: tit, n_resumen_fk: resumen},
        function(data){
            $("#ulListItems").html($("#ulListItems").html()+"\n"+data);
            $("#ulListItems").sortable('refresh');
            document.getElementById("n_seccion_fk").selectedIndex = 0;
            $("#s_titulo").val('');
        }, "text"
    );

}

function setTitleResumen(val, txt)
{

    if( val == '0')
    {
        $('#s_titulo').val('');
    }
    else
    {
        $('#s_titulo').val(txt);
    }
}

function deleteResumenItem(id, orden, idForm)
{
    if(confirm('¿Eliminar sección del resumen? Esto no puede deshacerse.'))
    {
        $('#itemSecc_'+id).fadeOut(1000, function(){$('#itemSecc_'+id).remove()});
        $.get("index.php?controlador=secciones&accion=delItemResumen&id="+id+"&orden="+orden+"&resid="+idForm,
        {},
        function(data){
            //alert(data);
            $("#ulListItems").sortable('refresh'); // Actualizar reordenar
        }
    );
    }
}

function makeResumenSortable(id)
{
    $("#ulListItems").sortable({
    handle : '.handle',
    opacity: 0.6,
    cursor: 'move',
    update : function () {
      var order = $('#ulListItems').sortable('serialize');
      //$("#info").load("process-sortable.php?"+order);

    $.get("index.php",
    {controlador: "secciones", accion: "reorderResumen", orden: order, resid: id},
        function(data){
            //alert(data);
        }
    );
    }
  });
}

/* Contenedores */
function addContenedor(idForm)
{ 
    var f = $('#fAddMenu_'+idForm);
    //var secc = document.getElementById('n_seccion_fk'+idForm).options[document.getElementById('n_seccion_fk'+idForm).selectedIndex].value;
    var secc = $('#n_seccion_fk_'+idForm).val();
    var tit = $('#s_titulo_'+idForm).val();
        
    var menu =  idForm;
        
    //$("#spBotones"+post).fadeOut(700);
    $.post("index.php?controlador=menu&accion=add_contenedor",
        {controlador: "menu", accion: "add_contenedor", n_seccion_fk: secc, s_titulo: tit, n_contenedor_fk: menu},
        function(data){            
            $("#ulListItems"+idForm).html($("#ulListItems"+idForm).html()+"\n"+data);
            $("#ulListItems"+idForm).sortable('refresh');
            document.getElementById("n_seccion_fk_"+idForm).selectedIndex = 0;
            $("#s_titulo_"+idForm).val('');
        }, "text"
    );
    
}

function addMenuCont(idForm)
{ 
    var f = $('#fAddMenu_'+idForm);
    //var secc = document.getElementById('n_seccion_fk'+idForm).options[document.getElementById('n_seccion_fk'+idForm).selectedIndex].value;
    var secc = $('#n_seccion_fk_cont_'+idForm).val();
    var tit = $('#s_titulo_cont_'+idForm).val();
        
    var menu =  idForm;
        
    //$("#spBotones"+post).fadeOut(700);
    $.post("index.php?controlador=menu&accion=add",
        {controlador: "menu", accion: "add", contenedor: 'yes', n_seccion_fk: secc, s_titulo: tit, n_menu_fk: menu},
        function(data){            
            $("#ulListItems"+idForm).html($("#ulListItems"+idForm).html()+"\n"+data);
            $("#ulListItems"+idForm).sortable('refresh');
            document.getElementById("n_seccion_fk_"+idForm).selectedIndex = 0;
            $("#s_titulo_"+idForm).val('');
        }, "text"
    );
    
}

function setTitleContenedor(val, txt, id)
{
    
    if( val == '0')
    {
        $('#s_titulo_'+id).val('');
    }
    else
    {
        $('#s_titulo_'+id).val(txt);
    }
}

function setTitleCont(val, txt, id)
{
    
    if( val == '0')
    {
        $('#s_titulo_cont_'+id).val('');
    }
    else
    {
        $('#s_titulo_cont_'+id).val(txt);
    }
}

function makeSortableContenedor(id)
{
    $("#ulListItems"+id).sortable({ 
    handle : '.handle',
    opacity: 0.6,
    cursor: 'move',
    update : function () { 
      var order = $('#ulListItems'+id).sortable('serialize'); 
      //$("#info").load("process-sortable.php?"+order);
      
    $.get("index.php",
    {controlador: "menu", accion: "reorder_contenedor", orden: order},
        function(data){            
            
        }
    );
    } 
  }); 
}


function openContenedor(id) {
    $('#'+id).slideDown();
}

function closeContenedor(id) {
    $('#'+id).slideUp();
}

function showContenedor(id)
{
    //$('#'+id).slideToggle();
}

function deleteContenedorItem(id, orden, tipo, idForm)
{
    if(confirm('¿Eliminar item del contenedor? Esto no puede deshacerse.'))
    {
        $('#itemMenu_'+id).fadeOut(1000);
        setTimeout(function(){$('#itemMenu_'+id).remove()},1002);
        $.get("index.php?controlador=menu&accion=delContenedor&id="+id+"&orden="+orden+"&tipo="+tipo,
        {},
        function(data){
            //alert(data);
            $("#ulListItems"+idForm).sortable('refresh'); // Actualizar reordenar
        }
    );
    }
}

function delTipoContenedor(id)
{
    if(confirm('¿Eliminar este contenedor y todos sus items? Esto no puede deshacerse.'))
    {
        $('#dvh2_'+id).fadeOut(1000);
        $('#menu_'+id).fadeOut(1000);
        setTimeout(function(){$('#dvh2_'+id).remove()},1002);
        setTimeout(function(){$('#menu_'+id).remove()},1002);
        $.get("index.php?controlador=menu&accion=delTipoContenedor&id="+id,
        {},
        function(data){
            //alert(data);
        }
    );
    }
}

/* Carruseles */
function addCarrusel(idForm)
{ 
    var f = $('#fAddMenu_'+idForm);
    //var secc = document.getElementById('n_seccion_fk'+idForm).options[document.getElementById('n_seccion_fk'+idForm).selectedIndex].value;
    var secc = $('#n_seccion_fk_'+idForm).val();
        
    var carrusel =  idForm;
        
    //$("#spBotones"+post).fadeOut(700);
    $.post("index.php?controlador=secciones&accion=add_carrusel",
        {controlador: "secciones", accion: "add_carrusel", n_seccion_fk: secc, n_carrusel_fk: carrusel},
        function(data){            
            $("#ulListItems"+idForm).html($("#ulListItems"+idForm).html()+"\n"+data);
            $("#ulListItems"+idForm).sortable('refresh');
            document.getElementById("n_seccion_fk_"+idForm).selectedIndex = 0;
            $("#s_titulo_"+idForm).val('');
        }, "text"
    );
    
}

function addMenuCarr(idForm)
{ 
    var f = $('#fAddMenu_'+idForm);
    //var secc = document.getElementById('n_seccion_fk'+idForm).options[document.getElementById('n_seccion_fk'+idForm).selectedIndex].value;
    var secc = $('#n_seccion_fk_cont_'+idForm).val();
    var tit = $('#s_titulo_cont_'+idForm).val();
        
    var menu =  idForm;
        
    //$("#spBotones"+post).fadeOut(700);
    $.post("index.php?controlador=menu&accion=add",
        {controlador: "menu", accion: "add", contenedor: 'yes', n_seccion_fk: secc, s_titulo: tit, n_menu_fk: menu},
        function(data){            
            $("#ulListItems"+idForm).html($("#ulListItems"+idForm).html()+"\n"+data);
            $("#ulListItems"+idForm).sortable('refresh');
            document.getElementById("n_seccion_fk_"+idForm).selectedIndex = 0;
            $("#s_titulo_"+idForm).val('');
        }, "text"
    );
    
}

function setTitleCarrusel(val, txt, id)
{
    
    if( val == '0')
    {
        $('#s_titulo_'+id).val('');
    }
    else
    {
        $('#s_titulo_'+id).val(txt);
    }
}

function setTitleCarr(val, txt, id)
{
    
    if( val == '0')
    {
        $('#s_titulo_cont_'+id).val('');
    }
    else
    {
        $('#s_titulo_cont_'+id).val(txt);
    }
}

function makeSortableCarrusel(id)
{
    $("#ulListItems"+id).sortable({ 
    handle : '.handle',
    opacity: 0.6,
    cursor: 'move',
    update : function () { 
      var order = $('#ulListItems'+id).sortable('serialize'); 
      //$("#info").load("process-sortable.php?"+order);
      
    $.get("index.php",
    {controlador: "secciones", accion: "reorder_carrusel", orden: order},
        function(data){            
            
        }
    );
    } 
  }); 
}

function showCarrusel(id)
{
    $('#'+id).slideToggle();
}

function insertCarrusel(id)
{    
    var ins = $('#s_insertado_'+id).val();
        
    $.get("index.php?controlador=secciones&accion=insertCarrusel&id="+id+"&s_insertado="+ins,
    {},
    function(data){
        //alert(data);
        $("#spInsertado"+id).fadeIn(800);
        setTimeout(function(){$("#spInsertado"+id).fadeOut(900);},1300);
    }
    );
    
}

function deleteCarruselItem(id, orden, tipo, idForm)
{
    if(confirm('¿Eliminar item de la presentación? Esto no puede deshacerse.'))
    {
        $('#itemMenu_'+id).fadeOut(1000);
        setTimeout(function(){$('#itemMenu_'+id).remove()},1002);
        $.get("index.php?controlador=secciones&accion=delCarrusel&id="+id+"&orden="+orden+"&tipo="+tipo,
        {},
        function(data){
            //alert(data);
            $("#ulListItems"+idForm).sortable('refresh'); // Actualizar reordenar
        }
    );
    }
}

function delTipoCarrusel(id)
{
    if(confirm('¿Eliminar esta presentaci&oacute;n y todos sus items? Esto no puede deshacerse.'))
    {
        $('#dvh2_'+id).fadeOut(1000);
        $('#menu_'+id).fadeOut(1000);
        setTimeout(function(){$('#dvh2_'+id).remove()},1002);
        setTimeout(function(){$('#menu_'+id).remove()},1002);
        $.get("index.php?controlador=secciones&accion=delTipoCarrusel&id="+id,
        {},
        function(data){
            //alert(data);
        }
    );
    }
}
/**/

function askDelete(id)
{
    if($('#trDeleteItem'+id).css("display") == "none")
        $('#trItem'+id).css("height","auto");
    else
        $('#trItem'+id).css("height","45px");
    $('#trDeleteItem'+id).toggle();
    $('#trDatosItem'+id).hide();
}

function showRuta(id)
{
    if($('#trInfoItem'+id).css("display") == "none")
        $('#trItem'+id).css("height","auto");
    else
        $('#trItem'+id).css("height","45px");
    $('#trInfoItem'+id).toggle();
    $('#trDatosItem'+id).hide();
}

function doDeleteSection(id)
{
    if(confirm('¿Está seguro de que desea eliminar esta sección? Esto no puede deshacerse.'))
    {
        $('#trDeleteItem'+id).fadeOut(1000);
        $('#trItem'+id).fadeOut(1000);
        $('#trDatosItem'+id).fadeOut(1000);
        setTimeout(function(){$('#trDeleteItem'+id).remove()},1002);
        setTimeout(function(){$('#trItem'+id).remove()},1002);
        setTimeout(function(){$('#trDatosItem'+id).remove()},1002);
        
        $.get("index.php?controlador=secciones&accion=deleteSection&id="+id,
        {},
        function(data){
            //alert(data);
        }
    );
    }
}

function doDeleteNoticia(id)
{
    if(confirm('¿Está seguro de que desea eliminar esta noticia? Esto no puede deshacerse.'))
    {
        $('#trDeleteItem'+id).fadeOut(1000);
        $('#trItem'+id).fadeOut(1000);
        $('#trDatosItem'+id).fadeOut(1000);
        setTimeout(function(){$('#trDeleteItem'+id).remove()},1002);
        setTimeout(function(){$('#trItem'+id).remove()},1002);
        setTimeout(function(){$('#trDatosItem'+id).remove()},1002);
        
        $.get("index.php?controlador=noticias&accion=deleteNoticia&id="+id,
        {},
        function(data){
            //alert(data);
        }
    );
    }
}

function doDeleteComentario(id)
{
    if(confirm('¿Está seguro de que desea eliminar este comentario? Esto no puede deshacerse.'))
    {
        $('#liComm_'+id).fadeOut(1000, function(){$('#liComm_'+id).remove()});

        $.get("/index.php?controlador=noticias&accion=deleteComentario&id="+id,
        {},
        function(data){
            //alert(data);
        }
    );
    }
}

function doDeleteCatGaleria(id)
{
    if(confirm('¿Está seguro de que desea eliminar esta categoría y todas sus fotos? Esto no puede deshacerse.'))
    {
        $('#trDeleteItem'+id).fadeOut(1000);
        $('#trItem'+id).fadeOut(1000);
        $('#trDatosItem'+id).fadeOut(1000);
        setTimeout(function(){$('#trDeleteItem'+id).remove()},1002);
        setTimeout(function(){$('#trItem'+id).remove()},1002);
        setTimeout(function(){$('#trDatosItem'+id).remove()},1002);
        
        $.get("index.php?controlador=secciones&accion=deleteCatGaleria&id="+id,
        {},
        function(data){
            //alert(data);
        }
    );
    }
}

function doDeleteArchivo(id)
{
    if(confirm('¿Está seguro de que desea eliminar este archivo? Esto no puede deshacerse.'))
    {
        $('#trDeleteItem'+id).fadeOut(1000);
        $('#trItem'+id).fadeOut(1000);
        $('#trDatosItem'+id).fadeOut(1000);
        setTimeout(function(){$('#trDeleteItem'+id).remove()},1002);
        setTimeout(function(){$('#trItem'+id).remove()},1002);
        setTimeout(function(){$('#trDatosItem'+id).remove()},1002);
        
        $.get("index.php?controlador=archivos&accion=deleteArchivoBib&id="+id,
        {},
        function(data){
            //alert(data);
        }
    );
    }
}

function makeImgs()
{ 
    var imgs = $('.thickbox');
    for(i=0;i<imgs.length;i++)
    {
        imgs[i].id = "imgThickbox"+i;
        img = document.getElementById(imgs[i].id);
        //if( img.parentNode.tagName.toLowerCase() == 'p' )
        //{
            img.onclick = function(){tb_show(this.title, this.src);};
        //}
    }
}

function hideImgs()
{
    $('#fade').hide();
    $('#light').hide();
}

function enviando()
{
    $('#dvEnviando').show();
    $('#btnEnviar, #btnSendInicial').hide();
}

function enviandoInicial() {
    aux = $('#fContactarInicio').html();
    $('#dvEnviando').show();
    $('#btnEnviar, #btnSendInicial').hide();

    $.post("index.php?controlador=secciones&accion=show&rewrite=contactar",
        {controlador: "secciones", accion: "show", btnEnviar: 'Enviar', s_nombre: $('#s_nombre').val(), s_email: $('#s_email').val(), t_comentario: $('#t_comentario').val(), swAJAX: "yes"},
        function(data){
            // Mostrar mensaje de OK o KO
            $('#fContactarInicio').fadeOut(400, function(){
                    $('#fContactarInicio').html(data);
                    $('#fContactarInicio').fadeIn(400);
                });
            // Volver a mostrar el formulario
            setTimeout( function(){
                $('#fContactarInicio input[type=text], #fContactarInicio textarea').val($(this).attr('rel'));
                $('#fContactarInicio').fadeOut(400, function(){
                    $('#fContactarInicio').html(aux);
                    $('#fContactarInicio').fadeIn(400);
                });
            }, 5000);
        }
    );

    return false;
}

function deleteFileDoc(id)
{
    if( confirm('¿Desea borrar este archivo?') )
    {
        $("#spFileDoc"+id).fadeOut(700);
        setTimeout(function(){$("#spFileDoc"+id).remove();}, 700);
        $.get("index.php?controlador=archivos&accion=deleteFileDoc&id="+id,
            {},
            function(data){
                //alert(data);
            }
        );
    }
}

function deleteCatDoc(id)
{
    if( confirm('Si elimina una categoría eliminará tambien todos sus archivos asociados. Esto no puede deshacerse. ¿Desea borrar esta categoría?') )
    {
        $("#liCatDocs"+id).fadeOut(700);
        setTimeout(function(){$("#liCatDocs"+id).remove();}, 700);
        $.get("index.php?controlador=archivos&accion=deleteCatDoc&id="+id,
            {},
            function(data){
                //alert(data);
            }
        );
    }
}

var idxImgLogo = 1;
function rotateLogo()
{
    setInterval(function(){
                            // Esconde actual
                            $('#imgHead').fadeOut(700);
                            setTimeout(function(){
                                            // Cambia imagen
                                            (idxImgLogo==3)?idxImgLogo=1:idxImgLogo++;
                                                
                                            $('#imgHead').attr('src','/images/style_azul/marcoImgHead_'+idxImgLogo+'.gif');
                                            // Muestra actual
                                            $('#imgHead').fadeIn(700);
                                        },700);
                            
                            // Llama a la funcion
                        },
                        7200);
}

function showImgGallery(href, titledesc)
{
    $('#imgBig').fadeOut(500);
    $('#spTitulo').fadeOut(500);
    $('#spDesc').fadeOut(500);
    
    arr = titledesc.split(" - ");
    title = arr[0];
    text = arr[1];
    
    setTimeout( function(){
                    $('#imgBig').attr("src",href);
                    setTimeout( function(){
                                    $('#imgBig').fadeIn(600);
                                    $('#spTitulo').html(title);
                                    $('#spDesc').html(text);
                                    $('#spTitulo').fadeIn(600);
                                    $('#spDesc').fadeIn(600);
                                },
                                200);
                },
                501);
}

function hideEditFoto()
{
    $('#dvEditFoto').hide();
    $('#hEditFoto').hide();
}

function showEditFoto(id, titulo, desc, file)
{
    $('#dvPostCat').hide();
    
    $('#dvEditFoto').show();
    $('#hEditFoto').show();
    
    $('#s_titulo').val(titulo);
    $('#t_desc').val(desc);
    $('#idFoto').val(id);
    $('#fotoActual').attr('src','/fotos_galerias/thumb_'+file);
    
}

function deleteFotoGaleria(id)
{
    if(confirm('¿Está seguro de que desea eliminar esta foto? Esto no puede deshacerse.'))
    {
        $('#dvListImgEdit'+id).fadeOut(1000);
        setTimeout(function(){$('#dvListImgEdit'+id).remove()},1002);
        
        $.get("index.php?controlador=secciones&accion=deleteFotoGaleria&id="+id,
        {},
        function(data){
            //alert(data);
        }
    );
    }
}

function submitNotas()
{
    tinyMCE.triggerSave(true,true);
    $.post("index.php?controlador=notas&accion=modificar",
        {controlador: "notas", accion: "modificar", t_texto: $('#t_texto').val()},
        function(data){
            $('#dvOKNota').slideDown();
        }
    );
    
}

/*
 Funcion: setOrden
 Proposito: cambia por AJAX el tipo de ordenacion de un grupo de items
 Parametros:
    tabla -> cadena, tabla en la que se cambiara el tipo de orden
    id -> id del contenedor (categoria, por ejemplo) al que cambiar el tipo de orden
    orden -> cadena con el nuevo tipo de orden
        fasc = fecha ascendente
        fdes = fecha descendente
        nasc = nombre ascendente
        ndes = nombre descendiente
        manual = orden manual
 Retorno: ninguno, recarga la pagina completa al completarse la llamada AJAX
*/
function setOrden(tabla, id, orden)
{
    $.post("index.php?controlador=secciones&accion=chgOrderGeneral",
        {controlador: "secciones", accion: "chgOrderGeneral", tab: tabla, nid: id, norden: orden},
        function(data){
            // alert(data);
            location.reload();
        }
    );
}

function makeSortableFotosGaleria(id)
{
    
    $("#tbListado").sortable({ 
    handle : '.handle',
    opacity: 0.6,
    cursor: 'move',
    update : function () { 
      var order = $('#tbListado').sortable('serialize'); 
      
      
        $.get("index.php",
        {controlador: "secciones", accion: "reorder_fotos_galeria", orden: order},
            function(data){            
                
            }
        );
    } 
  }); 
}


/*
Funciones recursivas para rotar las imagenes haciendo un fundido de una a otra
Se llaman desde document.ready, pasando el primer indice
Si se aniaden mas hay que cambiar el tope en (idx==3)?... y poner el nuevo tope
Tienen timeouts distintos, y de forma que uno no sea la suma de otros dos para evitar
    cambios simultaneos
El fundido lo hace con una capa padre donde pone la imagen antes de hacer el fadeout
*/
function rotateLogoA(idx) {
    var obj = $('#imgRotateDVA');
    var img = $('#imgRotateDVA img');
    // Poner imagen en div padre
    obj.css("background-image","url(/images/imgRotateA"+idx+".png)");
    // Fadeout de imagen
    img.fadeOut(900, function(){
        // Cambiar imagen
        (idx==3)?idx=1:idx++;
        img.attr("src","/images/imgRotateA"+idx+".png");
        // Fadein de imagen
        img.fadeIn(900);
        // Repetir cada 5 segundos
        setTimeout("rotateLogoA("+idx+")",4500);
        });
    
}

function rotateLogoB(idx) {
    var obj = $('#imgRotateDVB');
    var img = $('#imgRotateDVB img');
    // Poner imagen en div padre
    obj.css("background-image","url(/images/imgRotateB"+idx+".png)");
    // Fadeout de imagen
    img.fadeOut(900, function(){
        // Cambiar imagen
        (idx==3)?idx=1:idx++;
        img.attr("src","/images/imgRotateB"+idx+".png");
        // Fadein de imagen
        img.fadeIn(900);
        // Repetir cada 5 segundos
        setTimeout("rotateLogoB("+idx+")",7800);
        });
    
}

function rotateLogoC(idx) {
    var obj = $('#imgRotateDVC');
    var img = $('#imgRotateDVC img');
    // Poner imagen en div padre
    obj.css("background-image","url(/images/imgRotateC"+idx+".png)");
    // Fadeout de imagen
    img.fadeOut(900, function(){
        // Cambiar imagen
        (idx==3)?idx=1:idx++;
        img.attr("src","/images/imgRotateC"+idx+".png");
        // Fadein de imagen
        img.fadeIn(900);
        // Repetir cada 5 segundos
        setTimeout("rotateLogoC("+idx+")",3100);
        });
    
}

$(document).ready(function() {

    if( $('.h1Section').length > 0 ) {
        var n = $('<h1></h1>').addClass('h1SectionShadow').html($('.h1Section').html());
        $('.h1Section').css('color','#133147');
        $('.h1Section').css('padding-left','2px');
        $('.h1Section').after(n);
    }

	/*setTimeout(function(){
	rotateLogoA(1); 
	},
	2000);
	setTimeout(function(){
	rotateLogoB(1);
	},
	4300);
	setTimeout(function(){ 
	rotateLogoC(1);
	},
	1200);*/
    makeImgs();
});



