ns = document.layers
ie = document.all
var __nombrePanel = '__PanelEnProceso';
var __nombreBloqueador = '__PanelBloqueador';
var __nombreTxtFoco = '__txtFoco';
var __opacidad = 0.60;
var __temaDefecto = 'CarbonMetal';
var __intervalo;
function esconderParaItem(divpagina, precarga, txtNombre, Responsable, claseitem)
{
    if (txtNombre.value != "" & Responsable.value != "0" & claseitem.value != "0")
    {
        if (ie) precarga.style.visibility = "visible";
        if (ns) document.precarga.visibility = "show";
        if (ie) divpagina.style.visibility = "hidden";
        if (ns) document.divPagina.visibility = "hide";
    }
}
function esconderParaValidacionTexto(divpagina, txtNombre)
{
    var expresion = /^\s+/;
    var valido = expresion.test(txtNombre.value);

    if (txtNombre.value != "")
    {
        if (!valido)
        {
            if (ie) divpagina.style.visibility = "hidden";
            if (ns) document.divPagina.visibility = "hide";
        }
    }
}
function esconde(divpagina)
{
    if (ie) divpagina.style.visibility = "hidden";
    if (ns) document.divPagina.visibility = "hide";
}
function escondeFecha(divpagina, precarga, txtFecha)
{
    if (txtFecha.value == "")
    {
        if (ie) precarga.style.visibility = "visible";
        if (ns) document.precarga.visibility = "show";
        if (ie) divpagina.style.visibility = "hidden";
        if (ns) document.divPagina.visibility = "hide";
    }
}

//var oPopup = window.createPopup();

function AbrirEnProceso(preRuta, eventoOculta)
{
    var msgEnProceso;
    var imagen;
    var ancho;
    var alto;

    var rutaTemas = "App_Themes";
    // SGS - Si tiene argumentos, el primero se añadirá a la ruta de temas
    if (preRuta != null)
    {
        rutaTemas = preRuta + rutaTemas;
    }

    try
    {
        msgEnProceso = ResourceA02209;
    }
    catch (Exception)
    {
        msgEnProceso = "Trabajando";
    }

    try
    {
        temaEnProceso = Tema;

    }
    catch (Exception)
    {
        // Para las páginas donde no esté definida la variable Tema, para que no de error
        temaEnProceso = __temaDefecto;
    }
    try
    {
        if (AP_ImagenPrecarga == '')
            return;
        imagen = AP_ImagenPrecarga;
    }
    catch (Exception)
    {
        imagen = "P_Leon.gif";
    }
    try
    {
        ancho = AP_AnchoPrecarga;
    }
    catch (Exception)
    {
        ancho = 99;
    }
    try
    {
        alto = AP_AltoPrecarga;
    }
    catch (Exception)
    {
        alto = 45;
    }
    if (document.getElementById(__nombrePanel) != null)
        document.getElementById(__nombrePanel).style.display = '';
    else
    {
        var panel = document.createElement('div');
        panel.style.backgroundColor = "transparent";
        panel.style.top = '125px';
        panel.style.left = '50px';
        panel.style.width = ancho + 'px';
        panel.style.height = alto + 'px';
        panel.style.position = 'absolute';
        panel.style.zIndex = '1001';
        panel.innerHTML = '<table width="' + ancho + '"  height="' + alto + '" border="0" align="center" cellpadding="0" cellspacing="0" style="position:absolute;z-index:3;top:0px;left:0px" ><tr><td align="center"><img id="Leon" src="' + rutaTemas + '/' + temaEnProceso + '/Imagenes/' + imagen + '" style="border-width:0px;" /><br /></td></tr></table><input type="text" id="' + __nombreTxtFoco + '" style="width:0px" />';

        panel.id = __nombrePanel;
        document.body.appendChild(panel);
    }

    if (document.getElementById(__nombreBloqueador) != null)
        document.getElementById(__nombreBloqueador).style.display = '';
    else
    {
        var bloqueador = document.createElement('div');
        bloqueador.style.backgroundColor = 'lightslategray';
        bloqueador.style.position = 'absolute';
        bloqueador.style.zIndex = '1000';
//        bloqueador.style.left = "0px";
//        bloqueador.style.top = '0px';
        bloqueador.style.right = '0px';
        bloqueador.style.bottom = '0px';
        
        bloqueador.style.height = screen.availHeight + 'px'; // '100%';
        bloqueador.style.width = screen.availWidth + 'px'; //'100%';
        bloqueador.style.filter = 'alpha(opacity=' + __opacidad * 100 + ')';
        bloqueador.style.opacity = __opacidad;

        bloqueador.id = __nombreBloqueador;
        document.body.appendChild(bloqueador);
    }
    if (document.getElementById(__nombreTxtFoco) != null
    &&
    ((eventoOculta == null)
    || (eventoOculta != null && eventoOculta == true)))
    {
        try
        {
            __addEvento(document.getElementById(__nombreTxtFoco), 'blur', __delPanel);
            document.getElementById(__nombreTxtFoco).focus();
        } catch (Error)
        {
        }
    }
}

function AbrirEnProcesoInit()
{
    var imagen;
    var ancho;
    var alto;

    var rutaTemas = "App_Themes";
    // SGS - Si tiene argumentos, el primero se añadirá a la ruta de temas
    if (arguments.length > 0)
    {
        rutaTemas = arguments[0] + rutaTemas;
    }

    try
    {
        temaEnProceso = Tema;

    }
    catch (Exception)
    {
        // Para las páginas donde no esté definida la variable Tema, para que no de error
        temaEnProceso = __temaDefecto;
    }
    try
    {
        if (AP_ImagenPrecarga == '')
            return;
        imagen = AP_ImagenPrecarga;
    }
    catch (Exception)
    {
        imagen = "P_Leon.gif";
    }
    try
    {
        ancho = AP_AnchoPrecarga;
    }
    catch (Exception)
    {
        ancho = 99;
    }
    try
    {
        alto = AP_AltoPrecarga;
    }
    catch (Exception)
    {
        alto = 45;
    }

    var panel = '<div id="' + __nombrePanel + '" style="background-color:transparent;position:absolute;top:125px;left:50px;width:' + ancho + 'px;height:' + alto + 'px;z-index:1001"><table width="' + ancho + '"  height="' + alto + '" border="0" align="center" cellpadding="0" cellspacing="0" ><tr><td align="center"><img id="Leon" src="' + rutaTemas + '/' + temaEnProceso + '/Imagenes/' + imagen + '" style="border-width:0px;" /><br /></td></tr></table></div>';
    var al = window.screen.availHeight+'px';
    var an = window.screen.availWidth+'px';
    var bloqueo = '<div id="' + __nombreBloqueador + '" style="background-color:lightslategray;position:absolute;width:'+an+';height:'+al+';bottom:0px;right:0px;z-index:1000;filter:Alpha(opacity=' + __opacidad * 100 + ');opacity:' + __opacidad + '"></div>';
    document.write(panel + bloqueo);
}

function AbrirEnProcesoOpaco()
{
    var msgEnProceso;
    var imagen;
    var ancho;
    var alto;

    var rutaTemas = "App_Themes";


    try
    {
        msgEnProceso = ResourceA02209;
    }
    catch (Exception)
    {
        msgEnProceso = "Trabajando";
    }

    try
    {
        temaEnProceso = Tema;

    }
    catch (Exception)
    {
        // Para las páginas donde no esté definida la variable Tema, para que no de error
        temaEnProceso = __temaDefecto;
    }
    try
    {
        if (AP_ImagenPrecarga == '')
            return;
        imagen = AP_ImagenPrecarga;
    }
    catch (Exception)
    {
        imagen = "P_Leon.gif";
    }
    try
    {
        ancho = AP_AnchoPrecarga;
    }
    catch (Exception)
    {
        ancho = 99;
    }
    try
    {
        alto = AP_AltoPrecarga;
    }
    catch (Exception)
    {
        alto = 45;
    }
    if (document.getElementById(__nombrePanel) != null)
        document.getElementById(__nombrePanel).style.display = '';
    else
    {
        var panel = document.createElement('div');
        panel.style.backgroundColor = "transparent";
        panel.style.top = '125px';
        panel.style.left = '50px';
        panel.style.width = ancho + 'px';
        panel.style.height = alto + 'px';
        panel.style.position = 'absolute';
        panel.style.zIndex = '1001';
        panel.innerHTML = '<table width="' + ancho + '"  height="' + alto + '" border="0" align="center" cellpadding="0" cellspacing="0" style="position:absolute;z-index:3;top:0px;left:0px" ><tr><td align="center"><img id="Leon" src="' + rutaTemas + '/' + temaEnProceso + '/Imagenes/' + imagen + '" style="border-width:0px;" /><br /></td></tr></table><input type="text" id="' + __nombreTxtFoco + '" style="width:0px" />';

        panel.id = __nombrePanel;
        document.body.appendChild(panel);
    }

    if (document.getElementById(__nombreBloqueador) != null)
        document.getElementById(__nombreBloqueador).style.display = '';
    else
    {
        var bloqueador = document.createElement('div');
        bloqueador.style.backgroundColor = 'lightslategray';
        bloqueador.style.position = 'absolute';
        bloqueador.style.zIndex = '1000';
        bloqueador.style.left = "0px";
        bloqueador.style.top = '0px';
//        bloqueador.style.right = '0px';
//        bloqueador.style.bottom = '0px';
        
        bloqueador.style.height = screen.availHeight + 'px'; // '100%';
        bloqueador.style.width = screen.availWidth + 'px'; //'100%';
        bloqueador.style.filter = 'alpha(opacity=100)';
        bloqueador.style.opacity = __opacidad;

        bloqueador.id = __nombreBloqueador;
        document.body.appendChild(bloqueador);
    }
    if (document.getElementById(__nombreTxtFoco) != null)
    {
        try
        {
            __addEvento(document.getElementById(__nombreTxtFoco), 'blur', __delPanel);
            document.getElementById(__nombreTxtFoco).focus();
        } catch (Error)
        {
        }
    }
}


function CerrarEnProceso()
{
    //	var bloqueador = document.getElementById('fondo');
    //	if (bloqueador != null)
    //		document.body.removeChild(bloqueador);
    var parent;
    if (document.getElementById(__nombrePanel) != null)
    {
        parent = document.getElementById(__nombrePanel).parentNode;
        var panel = document.getElementById(__nombrePanel);
        try {
            parent.removeChild(panel);
        }
        catch (Error) {
            if(panel)
                panel.style.display = 'none';
        }
    }
    //oPopup.hide();
    if (document.getElementById(__nombreBloqueador) != null)
    {
        parent = document.getElementById(__nombreBloqueador).parentNode;
        var bloq = document.getElementById(__nombreBloqueador);
        try {
            parent.removeChild(bloq);
        }
        catch (Error) {
            if(bloq)
                bloq.style.display = 'none';
        }
        //          El siguiente codigo es para que tenga un efecto de alpha el velo al ocultar
        //        if (__intervalo != null) {
        //            clearInterval(__intervalo);
        //        }
        //        __intervalo = setInterval(function() {
        //            var __objeto = document.getElementById(__nombreBloqueador);
        //            var __valor = parseFloat(__objeto.style.opacity);            
        //            if (__valor < 0) {
        //                __objeto.parentNode.removeChild(__objeto); //style.display='none';
        //                clearInterval(__intervalo);
        //            }
        //            else {
        //                __valor = __valor - 0.10;
        //                __objeto.style.opacity = __valor;
        //                __objeto.style.filter = 'alpha(opacity=' + (__valor * 100) + ')';
        //            }
        //        }, 30);        
    }

    try
    {
        __delEvento(document.getElementById(__nombreTxtFoco), 'blur', __delPanel);
    }
    catch (Error)
	{ }
}

function GetObjetoPrecarga(virtualDirectoryPath)
{
    var imagen;
    var ancho;
    var alto;

    var rutaTemas = virtualDirectoryPath + "App_Themes";

    try
    {
        temaEnProceso = Tema;

    }
    catch (Exception)
    {
        // Para las páginas donde no esté definida la variable Tema, para que no de error
        temaEnProceso = __temaDefecto;
    }
    try
    {
        if (AP_ImagenPrecarga == '')
            return;
        imagen = AP_ImagenPrecarga;
    }
    catch (Exception)
    {
        imagen = "P_Leon.gif";
    }
    try
    {
        ancho = AP_AnchoPrecarga;
    }
    catch (Exception)
    {
        ancho = 99;
    }
    try
    {
        alto = AP_AltoPrecarga;
    }
    catch (Exception)
    {
        alto = 45;
    }

    var panel = document.createElement('div');
    panel.style.backgroundColor = "transparent";
    panel.style.top = '40px';
    panel.style.left = '250px';
    panel.style.width = ancho + 'px';
    panel.style.height = alto + 'px';
    panel.style.position = 'absolute';
    panel.style.zIndex = '800';
    panel.innerHTML = '<br><table width="' + ancho + '"  height="' + alto + '" border="0" align="center" cellpadding="0" cellspacing="0" ><tr><td align="center"><img id="Leon" src="' + rutaTemas + '/' + temaEnProceso + '/Imagenes/' + imagen + '" style="border-width:0px;" /><br /></td></tr></table>';
    panel.id = __nombrePanel;

    return panel;
}

function __addEvento(elemento, evento, funcion)
{
    if (elemento != null)
    {
        if (elemento.addEventListener)
        {
            elemento.addEventListener(evento, funcion, false);
        }
        else if (elemento.attachEvent)
        {
            elemento.attachEvent('on' + evento, funcion);
        }
    }
}

function __delEvento(elemento, evento, funcion)
{
    if (elemento != null)
    {
        if (elemento.removeEventListener)
        {
            elemento.removeEventListener(evento, funcion, false);
        }
        else if (elemento.detachEvent)
        {
            elemento.detachEvent('on' + evento, funcion);
        }
    }
}

function __delPanel()
{
    if (document.getElementById(__nombrePanel) != null)
        document.getElementById(__nombrePanel).parentNode.removeChild(document.getElementById(__nombrePanel));


    if (document.getElementById(__nombreTxtFoco) != null)
        __delEvento(document.getElementById(__nombreTxtFoco), 'blur', __delPanel)
}


function AbrirNoDisponible()
{

    var t = new Date();
    var ms = t.getMilliseconds();

    args = "status:no;help:no";
    return showModelessDialog('VentanasPopup/nodisponible.aspx?tmp=' + ms, '', args);
}
function AbrirNoDisponibleUrl(url)
{
    args = "dialogWidth:170px;dialogHeight:20px;dialogLeft:115px;dialogTop:175px;status:no;help:no";
    return showModelessDialog(url, '', args);
}

function MostrarPrecarga(objeto)
{
    objeto.style.display = "";
}

//necesario para abrir león sin velo, desde la botonera horizontal
function AbrirEnProcesoCabecera()
{
    var msgEnProceso;
    var imagen;
    var ancho;
    var alto;

    var rutaTemas = "../App_Themes";
    // SGS - Si tiene argumentos, el primero se añadirá a la ruta de temas
    if (arguments.length > 0)
    {
        rutaTemas = arguments[0] + rutaTemas;
    }

    try
    {
        msgEnProceso = ResourceA02209;
    }
    catch (Exception)
    {
        msgEnProceso = "Trabajando";
    }

    try
    {
        temaEnProceso = Tema;

    }
    catch (Exception)
    {
        // Para las páginas donde no esté definida la variable Tema, para que no de error
        temaEnProceso = __temaDefecto;
    }
    try
    {
        if (AP_ImagenPrecarga == '')
            return;
        imagen = AP_ImagenPrecarga;
    }
    catch (Exception)
    {
        imagen = "P_Leon.gif";
    }
    try
    {
        ancho = AP_AnchoPrecarga;
    }
    catch (Exception)
    {
        ancho = 99;
    }
    try
    {
        alto = AP_AltoPrecarga;
    }
    catch (Exception)
    {
        alto = 45;
    }
    if (document.getElementById(__nombrePanel) != null)
        document.getElementById(__nombrePanel).style.display = '';
    else
    {
        var panel = document.createElement('div');
        panel.style.backgroundColor = "transparent";
        panel.style.top = '40px';
        panel.style.left = '250px';
        panel.style.width = ancho + 'px';
        panel.style.height = alto + 'px';
        panel.style.position = 'absolute';
        panel.style.zIndex = '800';
        panel.innerHTML = '<table width="' + ancho + '"  height="' + alto + '" border="0" align="center" cellpadding="0" cellspacing="0" ><tr><td align="center"><img id="Leon" src="' + rutaTemas + '/' + temaEnProceso + '/Imagenes/' + imagen + '" style="border-width:0px;" /><br /></td></tr></table>';
        panel.id = __nombrePanel;
        document.body.appendChild(panel);
    }

}
function BloquearDivPagina()
{
    if (document.getElementById('divPagina') != null)
    {
        var bloqueador = document.createElement('div');
        bloqueador.style.backgroundColor = 'lightslategray';
        bloqueador.style.position = 'absolute';
        bloqueador.style.zIndex = '1000';
        bloqueador.style.bottom = '0px';
        bloqueador.style.right = '0px';

        bloqueador.style.height = screen.availHeight + 'px';
        bloqueador.style.width = screen.availWidth + 'px'; 
        
        bloqueador.style.filter = 'alpha(opacity=' + __opacidad * 100 + ')';
        bloqueador.style.opacity = __opacidad;

        bloqueador.id = __nombreBloqueador;
        document.getElementById('divPagina').appendChild(bloqueador);
        //document.body.appendChild(bloqueador);
    }
}
function DesbloquearDivPagina()
{
    if ((document.getElementById(__nombreBloqueador) != null) && (document.getElementById("divPagina") != null))
    {
        document.getElementById(__nombreBloqueador).parentNode.removeChild(document.getElementById(__nombreBloqueador));
        //document.getElementById("divPagina").removeChild(document.getElementById(__nombreBloqueador));
    }
}

//funcion para redimensionar la imagen
function __resizeImage(image, widthImg, heightImg, widthWin, heightWin, widthInc, heightInc)
{    
    if (image)
    {
        var widthW = (widthWin == 0 ? (window.innerWidth ? window.innerWidth : document.body.offsetWidth) : widthWin) + widthInc;

        var heightW = (heightWin == 0 ? (window.innerHeight ? window.innerHeight : document.body.offsetHeight) : heightWin) + heightInc;
        
        if (widthW < heightW)
        {
            if (parseInt((heightW * widthImg) / heightImg) >= widthW)
            {
                image.style.height = heightW + 'px';
                image.style.width = parseInt((heightW * widthImg) / heightImg) + 'px';
            }
            else
            {
                image.style.width = widthW + 'px';
                image.style.height = parseInt((widthW * heightImg) / widthImg) + 'px';
            }
        }
        else
        {
            if (parseInt((widthW * heightImg) / widthImg) >= heightW)
            {
                image.style.width = widthW + 'px';
                image.style.height = parseInt((widthW * heightImg) / widthImg) + 'px';
            }
            else
            {
                image.style.height = heightW + 'px';
                image.style.width = parseInt((heightW * widthImg) / heightImg) + 'px';
            }
        }
    }
}

function __resizeModalImage(image, widthImg, heightImg)
{
    if (image)
    {
        var widthW = (window.innerWidth ? window.innerWidth : (window.dialogWidth ? parseInt(window.dialogWidth.replace('px', '')) : document.body.offsetWidth));
        var heightW = (window.innerHeight ? window.innerHeight : (window.dialogHeight ? parseInt(window.dialogHeight.replace('px', '')) : document.body.offsetHeight));
        if (widthW < heightW)
        {
            if (parseInt((heightW * widthImg) / heightImg) >= widthW)
            {
                image.style.height = heightW + 'px';
                image.style.width = parseInt((heightW * widthImg) / heightImg) + 'px';
            }
            else
            {
                image.style.width = widthW + 'px';
                image.style.height = parseInt((widthW * heightImg) / widthImg) + 'px';
            }
        }
        else
        {
            if (parseInt((widthW * heightImg) / widthImg) >= heightW)
            {
                image.style.width = widthW + 'px';
                image.style.height = parseInt((widthW * heightImg) / widthImg) + 'px';
            }
            else
            {
                image.style.height = heightW + 'px';
                image.style.width = parseInt((heightW * widthImg) / heightImg) + 'px';
            }
        }
    }
}
