﻿if (typeof (console) == "undefined")
    console = { debug: function() { }, log: function() { } }

function mostrarMenuAdmin(){
    $(document).ready(function(){
        $(".menu-admin").show();
    });
}

function mostrarMenuPedidos() {
    $(document).ready(function() {
        $(".menu-pedidos").show();
    });
}

function mostrarMenuProtocolos() {
    $(document).ready(function() {
        $(".menu-protocolos").show();
    });
}

function mostrarMenuExtracto() {
    $(document).ready(function() {
        $(".menu-extracto").show();
    });
}

function mostrarMenuCartera() {
    $(document).ready(function() {
        $(".menu-cartera").show();
    });
}

function mostrarMenuTarifa() {
    $(document).ready(function() {
        $(".menu-tarifa").show();
    });
}

function mostrarMenuBuscar() {
    $(document).ready(function() {
        $(".menu-buscar").show();
    });
}

function mostrarMenu(){
    $(document).ready(function(){
        $("#menu").show();
    });
}

// Autorefresca un listado cada "periodo" segundos pulsando el botón de búsqueda del listado.
// Si no se encuentra el botón, se cancela el autorefresco.
// Si existe un chekbox desactivado dentro de un elemento con clase "alternador-autorefresco" no se refresca.
// Parámetros:
//  - periodo: periodo en segundos entre refrescos
//  - identificador: identificador único de este autorefresco
//  - selectorBoton: selector jQuery usado para encontrar el bótón de búsqueda a pulsar
//  - fnSaltar: (opcional) función llamada cada vez que se va a refrescar el listado. Si devuelve true no se realiza ese refresco.
function autorefresco(periodo, identificador, selectorBoton, fnSaltar) {
    fnSaltar = fnSaltar || function() {return false;}
    //console.debug("Estableciendo timer " + identificador + " cada " + periodo + " segundos");
    $(document).stopTime(identificador);
    $(document).everyTime(periodo, identificador, function(){
        // Se busca el botón de búsqueda de la Bolsa de Partes
        var boton = $(selectorBoton);
        
        // Si el botón no existe o se cumple la función de cancelación, se detiene el autorefresco
        if (boton.length == 0) {
            $(document).stopTime(identificador);
        }
        // Si existe y fnSaltar devuelve false, se refresca la Bolsa de Partes (pulsando el botón)
        else if (!fnSaltar()){
            // Se comprueba que no se ha desactivado el autorefresco
            var alternador = $(".alternador-autorefresco :checkbox");
            if (alternador.length > 0 && !alternador.is(":checked"))
                return;

            boton.click();
        }
    });
}


function autorefrescoContactos() {
    autorefresco(30 * 1000, 'refrescoContactos', '#ctl00_ContentPlaceHolder1_cmd_filtrar', 
                function(){ return $(".modalPopup:visible, ventanaCargando_mensaje:visible").length > 0; });
}

function autorefrescoEtiquetas() {
    autorefresco(15 * 1000, 'refrescoEtiquetas', '#ctl00_ContentPlaceHolder1_cmd_filtrar',
                function() { return $(".modalPopup:visible, ventanaCargando_mensaje:visible").length > 0; });
}

$(document).ready(function() {

    //Page Flip on hover

    $("#pageflip").hover(function() {
        $("ul.menu li").css("position", "");
        $("#pageflip img , .msg_block").stop()
			.animate({
			    width: '307px',
			    height: '319px'
			}, 500);
    }, function() {
        $("#pageflip img").stop()
			.animate({
			    width: '50px',
			    height: '52px'
			}, 220);
        $(".msg_block").stop()
			.animate({
			    width: '50px',
			    height: '50px'
			}, 200);
    });

});

function mostrarMenuProductos() {
    var img = document.getElementById('imgMenuProductos');
    var div = document.getElementById('divProductos');
    if (div.style.display == 'none') {
        div.style.display = 'block';
        img.src = 'menos.gif';
        img.title = 'Contraer menú';
    }
    else {
        div.style.display = 'none';
        img.src = 'mas.gif';
        img.title = 'Expandir menú';
    }

}

function mostrarMenuPrincipal() {
    var img = document.getElementById('imgMenuPrincipal');
    var div = document.getElementById('divPrincipal');
    if (div.style.display == 'none') {
        div.style.display = 'block';
        img.src = 'menos.gif';
        img.title = 'Contraer menú';
    }
    else {
        div.style.display = 'none';
        img.src = 'mas.gif';
        img.title = 'Expandir menú';
    }

}

function mostrarMenuAdministracion() {
    var img = document.getElementById('imgMenuAdministracion');
    var div = document.getElementById('divAdministracion');
    if (div.style.display == 'none') {
        div.style.display = 'block';
        img.src = 'menos.gif';
        img.title = 'Contraer menú';
    }
    else {
        div.style.display = 'none';
        img.src = 'mas.gif';
        img.title = 'Expandir menú';
    }

}

function abrir_ventana_e_imprimir() {
    var donde = 'http://www.google.es';
    var enlace = 'javascript:document.location=("' + donde + '");'
    enlace += 'window.print();';
    window.open(enlace);
}


function CargarPagina(web, ancho, alto) {
    derecha = (screen.width - ancho) / 2;
    arriba = (screen.height - alto) / 2;
    string = "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + ancho + ",height=" + alto + ",left=" + derecha + ",top=" + arriba + "";
    fin = window.open(web, "", string);
}

function CargarPaginaVacia(web, ancho, alto) {
    derecha = (screen.width - ancho) / 2;
    arriba = (screen.height - alto) / 2;
    string = "location=0,width=" + ancho + ",height=" + alto + ",left=" + derecha + ",top=" + arriba + "";
    fin = window.open(web, "", string);
}

function outTD(td, color) {

    td.bgColor = color;
}
function overTD(td, color) {

    td.bgColor = color;
        }
