﻿var PARAMETRO_ID_DESTINO = "ClientID";
var PARAMETRO_VALOR_DESTINO = "Value";
var ID_TEXT_BOX = "__PesquisaTextBox";
var ID_HIDDEN = "_hdnValor";

var JanelaAberta;

function Trim(value)
{
    return value.replace(/^\s+|\s+$/g, '');
}

function LeftTrim(value)
{
    return value.replace(/^\s+/, '');
}

function RightTrim(value)
{
    return value.replace(/\s+$/, '');
}

function AbrirJanela(caminhoPagina, width, height)
{
    var top = (screen.height / 2) - (height / 2);
    var left = (screen.width / 2) - (width / 2);

    var parametros = 'menubar=no,height=' + height + ',width=' +
        width + ',resizable=no,toolbar=no,scrollbars=yes,location=no,status=no,left=' +
        left + ',top=' + top;

    var novaJanela = window.open(caminhoPagina, "JanelaPopup", parametros);
    var janelaPai = novaJanela;
    JanelaAberta = novaJanela;
}

function FecharJanela(evt)
{
	var e = RecuperarEvento(evt);

	window.opener.JanelaAberta = null;
    window.close();

    return PararEvento(e);
}

function Page_Resize()
{
    var tblCabecalho = document.getElementById("tblCabecalho");

    if (tblCabecalho)
    {
        var tblConteudo = document.getElementById("tblConteudo");
        var divCorpoPagina = document.getElementById("divCorpoPagina");
        var tdRodape = document.getElementById("tdRodape");

        var clientHeight = document.documentElement.clientHeight;
        var cabecalhoHeight = tblCabecalho.offsetHeight;
        var rodapeHeight = tdRodape.offsetHeight;

        tblConteudo.setAttribute("height", ((clientHeight -
            cabecalhoHeight) - rodapeHeight) + "px");

        divCorpoPagina.style.height = tblConteudo.offsetHeight + "px";
    }

    FixarWidthConteudo();
}

function FixarWidthConteudo()
{
    var menu = document.getElementById("menu");
    var conteudo = document.getElementById("conteudo");

    if (conteudo)
    {
	    if (!menu || menu.style.display == "none")
	    {
	        var divVisibilidadeMenu = document.getElementById("divVisibilidadeMenu");

            if (divVisibilidadeMenu)
	            conteudo.style.width = (document.body.clientWidth - 9) + "px";
	        else
	            conteudo.style.width = (document.body.clientWidth - 10) + "px";
	    }
	    else
	        conteudo.style.width = (document.body.clientWidth - 209) + "px";
    }
}

function QueryString(URL, ID) {

    if (URL.indexOf('?' + ID + '=') > -1) 
    {
        var qString = URL.split('?');
        var keyVal = qString[1].split('&');

        for (var i = 0; i < keyVal.length; i++) 
        {
            if (keyVal[i].indexOf(ID + '=') == 0) 
            {
                var val = keyVal[i].split('=');
                return val[1];
            }
        }
        return "";
    }
    else 
    {
        return "";
    } 
}
