var primeiravez = 1;
function moveLeft(nameDivItens, button, buttonIdRight, HiddenIdIndice) {

    var itensVisible = 4;
    var buttonRight = document.getElementById(buttonIdRight);
    var widthContainer = document.getElementById(nameDivItens).offsetWidth;
    var widthItem = -1;

    var itens = document.getElementById(nameDivItens).getElementsByTagName('li');
    var indexvisible = -1;
    var i = 0;

    for (i = 0; i < itens.length; i++) {

        if (itens[i].style.display != 'none') {

            if (indexvisible == -1)
                indexvisible = i;


        }
        itens[i].style.display = 'none';
    }


    if (indexvisible <= 0)
        indexvisible = itens.length - 5;
    else
        indexvisible -= itensVisible;


    for (i = indexvisible; i < indexvisible + itensVisible; i++) {

        if (i < itens.length) {
            itens[i].style.display = 'block';
        }
        else {
            itens[i - itens.length].style.display = 'block';
        }
    }

    if (indexvisible <= 0) {
        button.className = 'btn-produtos-esq-off';
        button.disabled = true;
    }
    else {
        button.className = 'btn-produtos-esq';
        button.disabled = false;
    }


    if (indexvisible + itensVisible >= itens.length) {
        buttonRight.className = 'btn-produtos-dir-off';
        buttonRight.disabled = true;
    }
    else {
        buttonRight.className = 'btn-produtos-dir';
        buttonRight.disabled = false;
    }

    var ControleHidden = document.getElementById(HiddenIdIndice);
    var indice = parseInt(ControleHidden.value);

    document.getElementById(HiddenIdIndice).value = indice - 1;

}


function moveRight(nameDivItens, button, buttonIdLeft, HiddenIdIndice) {
    var itensVisible = 4;
    var buttonLeft = document.getElementById(buttonIdLeft);
    var widthContainer = document.getElementById(nameDivItens).offsetWidth;
    var widthItem = -1;

    var itens = document.getElementById(nameDivItens).getElementsByTagName('li');
    var indexvisible = -1;
    var i = 0;


    for (i = 0; i < itens.length; i++) {


        if (itens[i].style.display != 'none') {
            if (indexvisible == -1) {

                indexvisible = i;
            }

            itens[i].style.display = 'none';
        }
    }



    if (indexvisible + itensVisible >= itens.length)
        indexvisible = 0;
    else
        indexvisible += itensVisible;


    var positionCurrent = 0;
    var j = 0;

    var intervalo = 0;


    for (i = indexvisible; i < indexvisible + itensVisible; i++) {
        if (i < itens.length) {
            //sleep(1000);

            itens[i].style.display = 'block';
        }
        else {

            itens[i - itens.length].style.display = 'block';
        }
    }


    if (indexvisible + itensVisible >= itens.length) {
        button.className = 'btn-produtos-dir-off';
        button.disabled = true;
    }
    else {
        button.className = 'btn-produtos-dir';
        button.disabled = false;
    }

    if (indexvisible <= 0) {
        buttonLeft.className = 'btn-produtos-esq-off';
        buttonLeft.disabled = true;
    }
    else {
        buttonLeft.className = 'btn-produtos-esq';
        buttonLeft.disabled = false;
    }

    var ControleHidden = document.getElementById(HiddenIdIndice);
    var indice = parseInt(ControleHidden.value);

    document.getElementById(HiddenIdIndice).value = indice + 1;


}

function sleep(milliseconds) {
    var start = new Date().getTime();
    for (var i = 0; i < 1e7; i++) {
        if ((new Date().getTime() - start) > milliseconds) {
            break;
        }
    }
}


/************************************************************************
*
*Decription: Formata Data em um textbox
*Author: Matheus Moreno
*
************************************************************************/
function FormataData(e, obj) {
    //usar no evento keypress
    //bloqueia caracteres alfa e coloca as barras nas posições        


    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    var vrRetorno = false;

    //Backspace e Tab
    if (key != 8 && key != 0) {
        goodChars = "0123456789";
        if (goodChars.indexOf(keychar) != -1) {
            if ((obj.value.length == 2 || obj.value.length == 5) && key != 8) {
                obj.value += "/";
            }

            vrRetorno = true;
        }
    }
    else {
        vrRetorno = true;
    }

    return vrRetorno;
}

/************************************************************************
*
*Decription: Formata Hora em um textbox
*Author: Matheus Moreno
*
************************************************************************/
function FormataHora(e, obj) {
    //usar no evento keypress
    //bloqueia caracteres alfa e coloca as barras nas posições        


    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    var vrRetorno = false;

    //Backspace e Tab
    if (key != 8 && key != 0) {
        goodChars = "0123456789";
        if (goodChars.indexOf(keychar) != -1) {
            if ((obj.value.length == 2) && key != 8) {
                obj.value += ":";
            }

            vrRetorno = true;
        }
    }
    else {
        vrRetorno = true;
    }

    return vrRetorno;
}


/************************************************************************
*
*Decription: Inserir maxlength em um textbox multiline
*Author: wellington nagasawa
*
************************************************************************/
function InserirMaxLength(e, obj, max) {
    var key = window.event ? e.keyCode : e.which;
    var vrRetorno = false;
    //Backspace e Tab
    if (key != 8 && key != 0) {
        if (obj.value.length < max) {
            vrRetorno = true;
        }
    }
    else {
        vrRetorno = true;
    }

    return vrRetorno;
}


/************************************************************************
*
*Decription: Formata CEP em um textbox
*Author: Matheus Moreno
*
************************************************************************/
function FormataValidade(e, obj) {
    //usar no evento keypress
    //bloqueia caracteres alfa e coloca as barras nas posições



    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    var vrRetorno = false;

    if (key != 6 && key != 0) {
        goodChars = "0123456789";
        if (goodChars.indexOf(keychar) != -1) {
            if (obj.value.length == 2)
                obj.value += "/";

            vrRetorno = true;
        }
    }
    else {
        vrRetorno = true;
    }

    return vrRetorno;
}


/************************************************************************
*
*Decription: Formata Telefone
*Author: Matheus Moreno
*
************************************************************************/
function FormataTelefone(e, obj) {
    //usar no evento keypress
    //bloqueia caracteres alfa e coloca as barras nas posições

    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    var vrRetorno = false;

    if (key != 8 && key != 0) {
        goodChars = "0123456789";
        if (goodChars.indexOf(keychar) != -1) {
            if (obj.value.length == 1)
                obj.value = "(" + obj.value;
            if (obj.value.length == 3)
                obj.value += ") ";
            if (obj.value.length == 9)
                obj.value += "-";

            vrRetorno = true;
        }
    }
    else {
        vrRetorno = true;
    }

    return vrRetorno;
}



/************************************************************************
*
*Decription: Formata Telefone
*Author: Luiz Fernando Camargo Mascarenhas
*
************************************************************************/
function FormataTelefoneSemDDD(e, obj) {
    //usar no evento keypress
    //bloqueia caracteres alfa e coloca as barras nas posições

    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    var vrRetorno = false;

    if (key != 8 && key != 0) {
        goodChars = "0123456789";
        if (goodChars.indexOf(keychar) != -1) {
            if (obj.value.length == 4)
                obj.value += "-";

            vrRetorno = true;
        }
    }
    else {
        vrRetorno = true;
    }

    return vrRetorno;
}



/************************************************************************
*
*Decription: Formata Campo para formato Decimal com as casas decimais indicadas
*Author: Luiz Fernando Camargo Mascarenhas
*
************************************************************************/
function FormataDecimal(e, obj) {
    //usar no evento keypress
    //bloqueia caracteres alfa e coloca as barras nas posições

    var strInput = obj.value;
    var numCasasDecimais;
    numCasasDecimais = 2;


    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    var vrRetorno = false;

    alert(strInput);
    if (strInput.length >= 8) {
        return false;
    }

    if (key != 8 && key != 0) {
        goodChars = "0123456789";
        if (goodChars.indexOf(keychar) != -1) {

            //Remove os espaços
            if (strInput.length > numCasasDecimais) {
                objInput.value = strInput.substr(0, strInput.length - numCasasDecimais) + "," + strInput.substr(strInput.length - numCasasDecimais);
            } else {
                objInput.value = "0," + ("000" + strInput).substr(("000" + strInput).length - numCasasDecimais);
            }


            vrRetorno = true;
        }
    }
    else {
        vrRetorno = true;
    }

    return vrRetorno;
}







/************************************************************************
*
*Decription: Formata CEP em um textbox
*Author: Matheus Moreno
*
************************************************************************/
function FormataCEP(e, obj) {
    //usar no evento keypress
    //bloqueia caracteres alfa e coloca as barras nas posições

    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    var vrRetorno = false;

    if (key != 8 && key != 0) {
        goodChars = "0123456789";
        if (goodChars.indexOf(keychar) != -1) {
            if (obj.value.length == 5)
                obj.value += "-";

            vrRetorno = true;
        }
    }
    else {
        vrRetorno = true;
    }

    return vrRetorno;
}

/************************************************************************
*
*Decription: mostra/oculta caixa de texto de acordo com um controle passado como parâmetro
*Author: Camila Foltran
*
************************************************************************/
function MostraEOcultaTextBox(controlPessoaJuridica, controlPessoaFisica, idLinha, TextBox, e, obj) {
    var pessoaJuridica = true;
    var pessoaFisica = true;
    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    var vrRetorno = false;

    if (obj.id == controlPessoaFisica) {
        pessoaJuridica = false;
    }

    if (obj.id == controlPessoaJuridica) {
        pessoaFisica = false;
    }

    document.getElementById(controlPessoaJuridica).checked = pessoaJuridica;
    document.getElementById(controlPessoaFisica).checked = pessoaFisica;


    if (pessoaJuridica == false && pessoaFisica == true) {
        document.getElementById(idLinha).style.display = 'none';
        document.getElementById(TextBox).maxLength = 14;
        document.getElementById(TextBox).value = "";
        vrRetorno = true;
    }
    else {
        document.getElementById(idLinha).style.display = 'block';
        document.getElementById(TextBox).maxLength = 18;
        document.getElementById(TextBox).value = "";
        vrRetorno = true;
    }
    return vrRetorno;
}


/************************************************************************
*
*Decription: Formata CNPJ/CPF de acordo com um controle passado como parâmetro
*Author: Matheus Moreno
*
************************************************************************/
function FormataCPFCNPJ(controlPessoa, tipoControle, e, obj) {
    //usar no evento keypress
    //bloqueia caracteres alfa e coloca as barras nas posições

    var pessoaJuridica = true;

    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    var vrRetorno = false;

    if (tipoControle == "dropdownlist") {
        if (document.getElementById(controlPessoa).value == "False")
            pessoaJuridica = false;
    }
    else if (tipoControle == "checkbox") {
        pessoaJuridica = document.getElementById(controlPessoa).checked;
    }
    else if (tipoControle == "radiobutton") {
        if (document.getElementById(controlPessoa).checked == false)
            pessoaJuridica = false;
    }

    if (pessoaJuridica == false) {
        if (key != 8 && key != 0) {
            goodChars = "0123456789";
            if (goodChars.indexOf(keychar) != -1) {

                if ((obj.value.length == 3 || obj.value.length == 7) && key != 8)
                { obj.value += "."; }
                if ((obj.value.length == 11) && key != 8)
                { obj.value += "-"; }

                vrRetorno = true;
            }
        }
        else {
            vrRetorno = true;
        }
    }
    else {
        if (key != 8 && key != 0) {
            goodChars = "0123456789";
            if (goodChars.indexOf(keychar) != -1) {

                if ((obj.value.length == 2 || obj.value.length == 6) && key != 8)
                { obj.value += "."; }
                if ((obj.value.length == 10) && key != 8)
                { obj.value += "/"; }
                if ((obj.value.length == 15) && key != 8)
                { obj.value += "-"; }

                vrRetorno = true;
            }
        }
        else {
            vrRetorno = true;
        }
    }

    return vrRetorno;
}



/************************************************************************
*
*Decription: Formata CNPJ/CPF de com o tipo pessoa passado
*Author: Luiz Fernando Mascarenhas
*
************************************************************************/
function FormataCNPJ(e, obj) {
    //usar no evento keypress
    //bloqueia caracteres alfa e coloca as barras nas posições    
    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    var vrRetorno = false;


    if (key != 8 && key != 0) {
        goodChars = "0123456789";
        if (goodChars.indexOf(keychar) != -1) {

            if ((obj.value.length == 2 || obj.value.length == 6) && key != 8)
            { obj.value += "."; }
            if ((obj.value.length == 10) && key != 8)
            { obj.value += "/"; }
            if ((obj.value.length == 15) && key != 8)
            { obj.value += "-"; }

            vrRetorno = true;
        }
    }
    else {
        vrRetorno = true;
    }


    return vrRetorno;
}




/************************************************************************
*
*Decription: Formata CPF 
*Author: Camila Foltran
*
************************************************************************/
function FormataCPF(e, obj) {
    //usar no evento keypress
    //bloqueia caracteres alfa e coloca as barras nas posições

    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    var vrRetorno = false;

    if (key != 8 && key != 0) {
        goodChars = "0123456789";
        if (goodChars.indexOf(keychar) != -1) {

            if ((obj.value.length == 3 || obj.value.length == 7) && key != 8)
            { obj.value += "."; }
            if ((obj.value.length == 11) && key != 8)
            { obj.value += "-"; }

            vrRetorno = true;
        }
    }
    else {
        vrRetorno = true;
    }
    return vrRetorno;
}


/************************************************************************
*
*Decription: Formata CPF 
*Author: Camila Foltran
*
************************************************************************/
function FormataIE(e, obj) {
    //usar no evento keypress
    //bloqueia caracteres alfa e coloca as barras nas posições

    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    var vrRetorno = false;

    if (key != 8 && key != 0) {
        goodChars = "0123456789";
        if (goodChars.indexOf(keychar) != -1) {

            if ((obj.value.length == 3 || obj.value.length == 7) && key != 8)
            { obj.value += "."; }
            if ((obj.value.length == 11) && key != 8)
            { obj.value += "-"; }

            vrRetorno = true;
        }
    }
    else {
        vrRetorno = true;
    }
    return vrRetorno;
}






/*****************************************************************************
*
*Decription: Limpa campos vinculados a um campo de CNPJ/CPF quando alterar
o tipo de pessoa (FISICA ou JURIDICA)
*Author: Matheus Moreno
*
******************************************************************************/
var maxLengthPessoaFisica = 14;
var maxLengthPessoaJuridica = 18;
function clearFieldsCPFCNPJ(controlclicked, controlPessoaJuridica, controlPessoaFisica, tipoControle) {
    var i = 0;
    var maxLenght = maxLengthPessoaJuridica;

    if (tipoControle == "dropdownlist") {
        if (document.getElementById(controleTipoPessoa).value == "False")
            maxLenght = maxLengthPessoaFisica;
    }
    else if (tipoControle == "checkbox") {
        if (pessoaJuridica = document.getElementById(controleTipoPessoa).checked == false)
            maxLenght = maxLengthPessoaFisica;
    }

    if (arguments.length > 2) {
        for (i = 2; i < arguments.length; i++) {
            if (document.getElementById(arguments[i]).type == 'text') {
                document.getElementById(arguments[i]).value = '';
                document.getElementById(arguments[i]).maxLength = maxLenght;
            }
        }
    }
}

/*****************************************************************************
*
*Decription: Limpa campos vinculados a um campo de CNPJ/CPF quando alterar do tipo radios
o tipo de pessoa (FISICA ou JURIDICA
*Author: Matheus Moreno
*
******************************************************************************/
function clearFieldsCPFCNPJRadios(controlclicked, controlPessoaJuridica, controlPessoaFisica) {
    var i = 0;
    var maxLenght = maxLengthPessoaJuridica;

    if (controlclicked.id != controlPessoaJuridica) {
        pessoaJuridica = false;
        document.getElementById(controlPessoaJuridica).checked = false;
        document.getElementById(controlPessoaFisica).checked = true;
        maxLenght = maxLengthPessoaFisica;
    }
    else {
        document.getElementById(controlPessoaJuridica).checked = true;
        document.getElementById(controlPessoaFisica).checked = false;
    }


    if (arguments.length > 3) {
        for (i = 3; i < arguments.length; i++) {
            if (document.getElementById(arguments[i]).type == 'text') {
                document.getElementById(arguments[i]).value = '';
                document.getElementById(arguments[i]).maxLength = maxLenght;
            }
        }
    }
}

/*****************************************************************************
*
*Decription: Permite entrada de números decimais
*Author: Marcelo Azevedo
*
******************************************************************************/
function ConsisteNum(e) {
    //usar no evento onkeypress
    //se o caracter digitado não for pertencente ao goodChars, retorna falso (ascii = 0)

    //v=v.replace(/\D/g,""); Remove tudo o que não é dígito

    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    var vrRetorno = false;

    if (key != 8 && key != 0) {
        goodChars = "0123456789,.";
        if (goodChars.indexOf(keychar) != -1) {

            vrRetorno = true;
        }
    }
    else {
        vrRetorno = true;
    }

    return vrRetorno;
}

/*****************************************************************************
*
* Description: Permite inserção somente de números
* Author: Camila Foltran
*
******************************************************************************/
function SomenteNumeros(e) {
    //usar no evento onkeypress
    //se o caracter digitado não for pertencente ao goodChars, retorna falso (ascii = 0)

    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    var vrRetorno = false;

    if (key != 8 && key != 0) {
        goodChars = "0123456789";
        if (goodChars.indexOf(keychar) != -1) {
            vrRetorno = true;
        }
    }
    else {
        vrRetorno = true;
    }
    return vrRetorno;
}

/*****************************************************************************
*
* Description: Permite inserção somente de números
* Author: Camila Foltran
*
******************************************************************************/
function SomenteNumerosQtdeProdutos(e, obj) {
    //usar no evento onkeypress
    //se o caracter digitado não for pertencente ao goodChars, retorna falso (ascii = 0)

    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    var vrRetorno = false;

    if (key != 8 && key != 0) {
        goodChars = "123456789";
        if (goodChars.indexOf(keychar) != -1) {
            vrRetorno = true;
        }
    }
    else {
        vrRetorno = true;
    }
    return vrRetorno;
}

/*****************************************************************************
*
*Decription: Verifica se é o tamanho máximo de um campo
*Author: Marcelo Azevedo
*
******************************************************************************/
function isMaxLength(txtBox, maxLenght) {
    if (txtBox) {
        return (txtBox.value.length > maxLenght);
    }
}

/*****************************************************************************
*
*Decription: Bloquea quando exceder o tamanho máximo permitido em um textbox e emite
um alerta
*Author: Matheus Moreno
*
******************************************************************************/
function validateMaxLenght(control, maxLenght) {
    if (isMaxLength(control, maxLenght)) {
        alert('O campo execedeu o tamanho permitido');
        control.focus();
        return false;
    }

    return true;
}

/***********
funções auxiliares q não permitem ctrl+c ctrl+v em campos numéricos
***********/
function numero(idControle, integer) {

    v = document.getElementById(idControle).value;

    var numValidator;
    if (integer == 0) {
        numValidator = new RegExp("[0-9]+(([,]|[.])([0-9])+)*");
    }
    else {
        numValidator = new RegExp("[0-9]+");
    }


    if (!v.match(numValidator)) {
        alert('Valor inválido');
        document.getElementById(idControle).value = '';
    }

    return v;
}

function mascara(o, f) {
    v_obj = o;
    v_fun = f;
    setTimeout("execmascara()", 1);
}

/* função q não permite ctrl+c, ctrl+v 
Author: Camila Foltran - Todos os direitos reservados
*/
function desabilitaCtrlKeyCombinacao(e) {
    //lista as combinações CTRL + key que queremos desabilitar:
    var forbiddenKeys = new Array('c', 'v');
    var key;
    var isCtrl;

    if (window.event) {
        key = window.event.keyCode;   //IE
        if (window.event.ctrlKey)
            isCtrl = true;
        else
            isCtrl = false;
    }
    else {
        key = e.which;    //firefox
        if (e.ctrlKey)
            isCtrl = true;
        else
            isCtrl = false;
    }

    // se ctrl é pressionado, verifica se outro key (tecla) é proibida
    if (isCtrl) {
        for (i = 0; i < forbiddenKeys.length; i++) {
            //case-insensitive comparation
            if (forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase()) {
                alert('Key combination CTRL + '
                                        + String.fromCharCode(key)
                                        + 'has been disabled.');
                return false;
            }
        }
    }
    return true;
}

/*****************************************************************************
*
* Description: Marca todos checkboxes passados por parâmetros a partir de 
*    quando checar o primeiro checkbox passado por parâmetro
* Author: Matheus Moreno
*
******************************************************************************/
function checkAllCheckbox(chkAll) {
    if (arguments.length > 1) {
        for (i = 1; i < arguments.length; i++) {
            document.getElementById(arguments[i]).checked = document.getElementById(arguments[0]).checked;
        }
    }
}

/*****************************************************************************
*
* Description: Desmarca a opcao todos quando deschecar um controle
* Author: Matheus Moreno
*
******************************************************************************/
function decheckOrCheckCheckboxAll(chkAll, chkClick) {
    var marcarCheckTodos = true;
    if (document.getElementById(chkClick).checked == false) {
        document.getElementById(chkAll).checked = false;
        marcarCheckTodos = false;
    }

    if (marcarCheckTodos == true && arguments.length > 2) {
        for (i = 2; i < arguments.length; i++) {
            if (document.getElementById(arguments[i]).checked == false)
                marcarCheckTodos = false;
        }
    }

    if (marcarCheckTodos == true) {
        document.getElementById(chkAll).checked = marcarCheckTodos;
    }

}


/*****************************************************************************
*
* Description: Envia informações selecionada pelo usuário para a página que abriu o pop up
* Author: Matheus Moreno
*
******************************************************************************/
function enviarInformacoesOpener(id, descricao, controleText, controleTextCodigo, controleHidden, concatenar) {
    if (controleText == "") {
        window.returnValue = id + ';' + descricao;
    }
    else {
        if (concatenar == 1) {
            window.opener.document.getElementById(controleText).value += ", " + descricao;
            window.opener.document.getElementById(controleHidden).value += "," + id;

            if (window.opener.document.getElementById(controleTextCodigo) != null) {
                window.opener.document.getElementById(controleTextCodigo).value += ", " + id;
            }
        }
        else {
            if (window.opener.document.getElementById(controleText) != null) {
                window.opener.document.getElementById(controleText).value = descricao;
            }
            if (window.opener.document.getElementById(controleHidden) != null) {
                window.opener.document.getElementById(controleHidden).value = id;
            }

            if (window.opener.document.getElementById(controleTextCodigo) != null) {
                window.opener.document.getElementById(controleTextCodigo).value = id;
            }
        }

    }
    window.close();
}

function abrirPopUp(path, title, width, height) {

    window.open(path, title, 'scrollbars=yes,titlebar=0,toolbar=0,menubar=0,location=false,status=0,width=' + width + ',height=' + height);
    return false;
}

/*****************************************************************************
*
* Description: Abrir popup de listagem
* Author: Matheus Moreno
*
******************************************************************************/
function abrirPopUpListagem(strPath, controleText, controleHidden, controleTextCodigo, width, height, args, submit, concatenarFiltro) {
    var filtroCodigo = ''
    if (document.getElementById(controleTextCodigo) != null) {
        filtroCodigo = document.getElementById(controleTextCodigo).value;
    }


    if (window.showModalDialog) {
        var retValue = window.showModalDialog('popups/' + strPath + '?qsFiltroText=' + document.getElementById(controleText).value + '&qsFiltroCodigo=' + filtroCodigo + '&qsArgumentos=' + args + '&qsConcatenarFiltro=' + concatenarFiltro, 'Listagem', 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;');
    }
    else {
        window.open('popups/' + strPath + '?qsFiltroText=' + document.getElementById(controleText).value + '&qsFiltroCodigo=' + filtroCodigo + '&qsArgumentos=' + args + '&qsCampoText=' + controleText + '&qsCampoCodigo=' + controleTextCodigo + '&qsCampoHiden=' + controleHidden + '&qsConcatenarFiltro=' + concatenarFiltro, 'Listagem', 'Width=' + width + 'px;Height=' + height + 'px;');
    }



    if (retValue != null) {
        if (concatenarFiltro == 0) {
            document.getElementById(controleText).value = retValue.split(';')[1];
            document.getElementById(controleHidden).value = retValue.split(';')[0];

            if (document.getElementById(controleTextCodigo) != null) {
                document.getElementById(controleTextCodigo).value = retValue.split(';')[0];
            }
        }
        else {
            if (document.getElementById(controleHidden).value != '') {
                document.getElementById(controleText).value += ', ' + retValue.split(';')[1];
                document.getElementById(controleHidden).value += ', ' + retValue.split(';')[0];

                if (document.getElementById(controleTextCodigo) != null) {
                    document.getElementById(controleTextCodigo).value += ', ' + retValue.split(';')[0];
                }
            }
            else {
                document.getElementById(controleText).value = retValue.split(';')[1];
                document.getElementById(controleHidden).value = retValue.split(';')[0];

                if (document.getElementById(controleTextCodigo) != null) {
                    document.getElementById(controleTextCodigo).value = retValue.split(';')[0];
                }
            }

        }

    }

    if (submit != 0) {

        document.forms[0].submit();
    }

    return false;
}

function desabiliOnClickLengthTextBox(controleText, minLength) {
    return (document.getElementById(controleText).value.length >= minLength);
}


/*****************************************************************************
*
*Decription: Verifica se dois campos foram preenchidos tamanho para o filtro
*Author: Alberto Barros
*
******************************************************************************/
function filtroObrigatorio(txtBoxInicio, textBoxTermino, mensagemGlobal) {
    if (document.getElementById(txtBoxInicio)) {
        if (document.getElementById(txtBoxInicio).value.length > 0 && document.getElementById(textBoxTermino).value.length == 0) {
            alert(mensagemGlobal);
            return false;
        }

        if (document.getElementById(txtBoxInicio).value.length == 0 && document.getElementById(textBoxTermino).value.length > 0) {
            alert(mensagemGlobal);
            return false;
        }
    }

    return true;

}

/*****************************************************************************
*
*Decription: Ocultar ou mostra linhas de uma tabela
*Author: Matheus Moreno
*
******************************************************************************/
function ocultarMostrarLinhas(ocultar) {
    var i = 0;

    if (ocultar) {
        for (i = 1; i < arguments.length; i++) {
            if (document.getElementById(arguments[i]) != null)
                document.getElementById(arguments[i]).style.display = 'none';
            else
                window.opener.document.getElementById(arguments[i]).style.display = 'none';
        }
    }
    else {
        for (i = 1; i < arguments.length; i++) {
            document.getElementById(arguments[i]).style.display = 'block';
        }
    }
}

/*****************************************************************************
*
*Decription: Valida Tela de Insercao Promoção Item
*Author: Matheus Moreno
*
******************************************************************************/
function validaInsercaoTelaPromocaoItem(controleDropSecao, controleTextProdutoSKU, labelErrorsId, mensagem, imagemId) {
    if (document.getElementById(controleDropSecao) == null && document.getElementById(controleTextProdutoSKU).value == '') {
        document.getElementById(labelErrorsId).innerText = mensagem;
        document.getElementById(labelErrorsId).style.display = 'block';
        //document.getElementById(imagemId).style.visibility = 'visible';
        return false;
    }
    else if (document.getElementById(controleDropSecao) != null) {
        if (document.getElementById(controleDropSecao).value == '' && document.getElementById(controleTextProdutoSKU).value == '') {
            document.getElementById(labelErrorsId).innerText = mensagem;
            document.getElementById(labelErrorsId).style.display = 'block';
            //document.getElementById(imagemId).style.visibility = 'visible';

            return false;
        }


    }

    document.getElementById(labelErrorsId).style.visibility = 'hidden';
    return true;
}

function validaInsercaoSKU(controleTextProdutoSKU, labelErrorsId, mensagem) {
    if (document.getElementById(controleTextProdutoSKU).value == '') {
        document.getElementById(labelErrorsId).innerText = mensagem;
        document.getElementById(labelErrorsId).style.display = 'block';

        return false;
    }

    return true;
}

function limparCampos() {
    for (i = 0; i < arguments.length; i++) {
        if (document.getElementById(arguments[i]) != null) {
            document.getElementById(arguments[i]).value = '';
        }
    }
}

/*****************************************************************************
*
*Decription: Habilita validador
*Author: Matheus Moreno
*
******************************************************************************/
function habiliarValidator(controle) {
    if (document.getElementById(controle) != null) {
        ValidatorEnable(document.getElementById(controle), true);
    }
}


/*****************************************************************************
*
*Decription: Desabilita Validador
*Author: Matheus Moreno
*
******************************************************************************/
function DesabiliarValidator(controle) {
    if (document.getElementById(controle) != null) {
        ValidatorEnable(document.getElementById(controle), false);
    }
}

function validarInsercaoProduto(controleHidden, mensagem, labelErrorsId, imagemId) {
    var pageIsValid = Page_ClientValidate('CadastroProduto');
    var hdn = document.getElementById(controleHidden);
    var lber = document.getElementById(labelErrorsId);
    var imgid = document.getElementById(imagemId);

    if (hdn != null && document.getElementById(controleHidden).value == '') {
        if (lber != null)
        {
            lber.innerText = mensagem;
            lber.style.display = 'block';
            lber.style.visibility = 'visible';
        }
        
        if (imgid != null)
        {
            imgid.style.display = 'inline';
            imgid.style.visibility = 'visible';
            imgid.src = "../admin/images/error.jpg";
        }

        return false;
    }
    
    if (lber != null)
    {
        lber.style.display = 'none';
        lber.style.visibility = 'hidden';
    }
    
    if (imgid != null)
    {
        imgid.style.display = 'none';
        imgid.style.visibility = 'hidden';
    }
    
    return pageIsValid;
}

/*****************************************************************************
*
*Decription: Valida se o campo de categoria do form receita foi preenchido
*Author: Luiz Fernando Mascarenhas
*
******************************************************************************/

function validarInsercaoReceita(controleHidden, mensagem, labelErrorsId, imagemId) {
    alert('teste');
    var pageIsValid = Page_ClientValidate('receita');

    if (document.getElementById(controleHidden).value == '') {
        document.getElementById(labelErrorsId).innerText = mensagem;
        document.getElementById(labelErrorsId).style.display = 'block';
        document.getElementById(labelErrorsId).style.visibility = 'visible';
        document.getElementById(imagemId).style.display = 'inline';
        document.getElementById(imagemId).style.visibility = 'visible';
        document.getElementById(imagemId).src = "../admin/images/error.jpg";


        return false;
    }
    document.getElementById(labelErrorsId).style.display = 'none';
    document.getElementById(labelErrorsId).style.visibility = 'hidden';
    document.getElementById(imagemId).style.display = 'none';
    document.getElementById(imagemId).style.visibility = 'hidden';


    return pageIsValid;
}



/*****************************************************************************
*
*Decription: Da foco em um botao quando entrar em um determinado textbox
*Author: Matheus Moreno
*
******************************************************************************/
function FocusElemento(e, input) {

    var key = window.event ? e.keyCode : e.which;

    if (key == 13) {
        document.getElementById(input).click();
        return false;
    }
    else {

        return true;
    }
}


function insertFlash(arquivo, tam_x, tam_y) {
    document.writeln('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + tam_x + '" height="' + tam_y + '">');
    document.writeln('<param name="movie" value="' + arquivo + '" />');
    document.writeln('<param name="wmode" value="transparent" />');
    document.writeln('<param name="quality" value="high" />');
    document.writeln('<embed src="' + arquivo + '" wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + tam_x + '" height="' + tam_y + '"></embed>');
    document.writeln('</object>');
}
