i = 0;
var crcinvalidos = new Array('~', '`', '!', '#', '$', '%', '%', '^', '&', '*', '(', ')', ',');
function visivel(obj, v) {
    if (v) {
        obj.style.visibility = 'visible';
        obj.style.position = 'static';
    } else {
        obj.style.visibility = 'hidden';
        obj.style.position = 'absolute';
    }
    return true;
}

function tab(controle, n) {
    if (controle.value.length == n) {
        var j = 0;
        while (document.forms[i].elements[j] != null && document.forms[i].elements[j].name != controle.name) j++;
        while (document.forms[i].elements[j].name == controle.name) j++;
        if (document.forms[i].elements[j] != null) document.forms[i].elements[j].focus();
    }
}

function extra(opcao, input) {
    //if (opcao==-1) v=',true);'; else v=',false);';
    if (opcao == -1) v = true; else v = false;
    //eval('alert(document.forms[0].medicamentoEspeciaisIndividuo.value)');

    //alert('visivel(document.forms[0].'+input+v);
    visivel(input, v);
    return true;
}

function cpfValido(controle) {

    eval('var strcpf=document.forms[i].' + controle + '.value;');
    strcpf = strcpf.replace(/\./gi, '');
    strcpf = strcpf.replace(/\-/gi, '');
    //alert(strcpf);

    var wSomaDosProdutos = 0;
    var wResto = 0;
    var wDigitChk = 0;
    var wDigitChk2 = 0;
    var wStatus = 0;
    var wI = 0;


    for (wI = 0; wI < 9; wI++)
        wSomaDosProdutos += parseInt(strcpf.substring(wI, wI + 1)) * (11 - (wI + 1));

    var wResto = wSomaDosProdutos - parseInt(wSomaDosProdutos / 11) * 11;

    if (wResto == 0 || wResto == 1)
        wDigitChk1 = 0;
    else
        wDigitChk1 = 11 - wResto;


    wSomaDosProdutos = 0;
    for (wI = 0; wI < 9; wI++)
        wSomaDosProdutos += parseInt(strcpf.substring(wI, wI + 1)) * (12 - (wI + 1));


    wSomaDosProdutos += 2 * wDigitChk1;
    wResto = wSomaDosProdutos - parseInt(wSomaDosProdutos / 11) * 11;
    if (wResto == 0 || wResto == 1)
        wDigitChk2 = 0;
    else
        wDigitChk2 = 11 - wResto;

    var ch1 = strcpf.charAt(9);
    var ch2 = strcpf.charAt(10);

    if (parseInt(ch1) == wDigitChk1 && parseInt(ch2) == wDigitChk2) return true;

    alert("Numero de CPF invalido!");
    eval('document.forms[i].' + controle + '.select();');
    return false;
}

function DaysInMonth(WhichMonth, WhichYear) {
    var DaysInMonth = 31;
    if (WhichMonth == 4 || WhichMonth == 6 || WhichMonth == 9 || WhichMonth == 11) DaysInMonth = 30;
    if (WhichMonth == 2 && (WhichYear / 4) != Math.floor(WhichYear / 4)) DaysInMonth = 28;
    if (WhichMonth == 2 && (WhichYear / 4) == Math.floor(WhichYear / 4)) DaysInMonth = 29;
    return DaysInMonth;
}

function dataValida(controle) {
    var j;
    eval('var dia = parseInt(document.forms[i].' + controle + '[0].value);');
    eval('var mes = parseInt(document.forms[i].' + controle + '[1].value);');
    eval('var ano = parseInt(document.forms[i].' + controle + '[2].value);');
    //alert(dia+'/'+mes+'/'+ano);
    if (isNaN(dia) || isNaN(mes) || isNaN(ano)) {
        if (isNaN(dia)) j = '0';
        else if (isNaN(mes)) j = '1';
        else j = '2';

        alert('Data inválida');
        eval('document.forms[i].' + controle + '[' + j + '].focus();');
        return false;
    }
    if (mes > 12) {
        alert('Data inválida');
        eval('document.forms[i].' + controle + '[1].focus();');
        return false;
    }
    if (ano < 1900) {
        alert('Data inválida');
        eval('document.forms[i].' + controle + '[2].focus();');
        return false;
    }
    //alert(DaysInMonth(mes,ano));
    if (dia > DaysInMonth(mes, ano)) {
        alert('Data inválida.');
        eval('document.forms[i].' + controle + '[0].focus();');
        return false;
    }

    return true;
}

function campoDigitado(controle, campo) {
    eval('var texto = document.forms[i].' + controle + '.value;');
    if (texto == '') {
        alert('Por favor, digite ' + campo);
        eval('document.forms[i].' + controle + '.focus();');
        return false;
    }
    return true;
}

function numeroValido(controle, campo) {
    eval('var texto = document.forms[i].' + controle + '.value;');

    var certo = true;
    for (var j = 0; j < texto.length; j++) {
        certo = certo && !isNaN(texto.charAt(j));
        //if (certo) alert('Continua certo. Atual: '+texto.charAt(j)); else alert('Já está errado. Atual: '+texto.charAt(j)); 
    }

    if (!certo) {
        alert('Por favor, digite um número para o ' + campo);
        eval('document.forms[i].' + controle + '.focus();');
        return false;
    }
    return true;
}


function numerObr(controle, campo) {
    eval('var texto = document.forms[i].' + controle + '.value;');
    var certo = true;
    for (var j = 0; j < texto.length; j++) {
        certo = certo && !isNaN(texto.charAt(j));
        //if (certo) alert('Continua certo. Atual: '+texto.charAt(j)); else alert('Já está errado. Atual: '+texto.charAt(j)); 
    }
    if (texto == '') certo = false;
    if (!certo) {
        alert('Por favor, digite um número para o ' + campo);
        eval('document.forms[i].' + controle + '.focus();');
        return false;
    }
    return true;
}

function numeroDDDValido(controle, campo) {
    eval('var tamanho = document.forms[i].' + controle + '.value.length');
    eval('var numero = parseInt(document.forms[i].' + controle + '.value);');
    if (isNaN(numero)) {
        alert('Por favor, digite um número para o ' + campo);
        eval('document.forms[i].' + controle + '.focus();');
        return false;
    }
    else if (tamanho < 2) {
        alert('Por favor, O ' + campo + ' deve ter 2 digitos');
        eval('document.forms[i].' + controle + '.focus();');
        return false;
    }
    return true;
}

function caixaSelecionada(controle, campo) {
    eval('var valor = document.forms[i].' + controle + '.selectedIndex;');
    if (valor == 0) {
        alert('Por favor, escolha ' + campo);
        eval('document.forms[i].' + controle + '.focus();');
        return false;
    }
    return true;
}

function valorSelecionado(controle, campo, v) {
    //eval('var valor = document.forms[i].'+controle+'[document.forms[i].'+controle+'.selectedIndex];');
    eval('var valor = document.forms[i].' + controle + '.value;');
    
    if (valor == 0) {
        alert('Por favor, escolha ' + campo);
        eval('document.forms[i].' + controle + '.focus();');
        return false;
    }
    
    return true;
}

function senhaValida(caixa1, caixa2) {
    
    eval('var valor = document.forms[i].' + caixa1 + '.value;');
    eval('var valor2 = document.forms[i].' + caixa2 + '.value;');
    
    if (valor == '' || isNaN(valor.value) || valor.length < 4) {
        if (valor.value == '')
            alert('Por favor, digite uma senha.')
        else
            alert('A senha precisa ser um número com 4 algarismos.')
        eval('document.forms[i].' + caixa1 + '.focus();');
        return false;
    }
    
    if (valor != valor2) {
        alert('A(s) senha(s) digitadas são diferentes.');
        caixa2.value = '';
        caixa2.focus();
        return false;
    }
    
    return true;
}

function vrfcrcemail(email) {
    var tudocerto = true;
    for (j = 0; j < crcinvalidos.length && tudocerto; j++) {
        if (email.indexOf(crcinvalidos[j]) != -1)
            tudocerto = false;
    }
    return tudocerto;
}
function vrfemailvld(email) {
    var tudocerto = true;
    if (!vrfcrcemail(email))
        tudocerto = false;
    if (email.charAt(0) == '.' || email.charAt(0) == '@')
        tudocerto = false;
    if (email.charAt(email.indexOf(".") + 1) == ".")
        tudocerto = false;
    if (email.indexOf("@") > -1) {
        var emailsemarroba = email.slice(email.indexOf("@") + 1, email.length);
        if (
			(emailsemarroba.indexOf("@") > -1) ||
			(email.charAt(email.indexOf("@") + 1) == ".") ||
			(email.charAt(email.indexOf("@") - 1) == ".") ||
			(emailsemarroba.indexOf("@") == "") ||
			(emailsemarroba.indexOf(".") == -1) ||
			(email.charAt(email.length - 1) == ".") ||
			(emailsemarroba.charAt(email.indexOf(".") + 1) == ".")
		) tudocerto = false;
    }
    else tudocerto = false;
    return tudocerto;
}
function emailValido(controle) {
    eval('var email = document.forms[i].' + controle + '.value;');
    if ((vrfemailvld(email)))
        return true;
    else {
        alert("E-mail Inválido!");
        eval('document.forms[i].' + controle + '.focus();');
        return false;
    }
}

function vldcampos() {
    var CountItens = document.forms[i].length;
    resultado = true;

    for (k = 0; k < CountItens - 1 && resultado == true; k++) {
        if (document.forms[i].elements[k].name == '_Telefones') {
            for (m = 0; m < document.forms[i].elements[k].length; m++)
                document.forms[i].elements[k][m].selected = true;
        }
        if (document.forms[i].elements[k].name == '_Especialidades') {
            for (m = 0; m < document.forms[i].elements[k].length; m++)
                document.forms[i].elements[k][m].selected = true;
        }
        if (document.forms[i].elements[k].name == '_Emails') {
            for (m = 0; m < document.forms[i].elements[k].length; m++)
                document.forms[i].elements[k][m].selected = true;
        }
        if (document.forms[i].elements[k].name.charAt(0) != "_") {
            switch (document.forms[i].elements[k].tipovalidacao) {
                case "obrigatorio": 
                    {
                        resultado = campoDigitado(document.forms[i].elements[k].name, document.forms[i].elements[k].descricao);
                        break;
                    }
                case "selecionado": 
                    {
                        resultado = caixaSelecionada(document.forms[i].elements[k].name, document.forms[i].elements[k].descricao);
                        break;
                    }
                case "cpf": 
                    {
                        resultado = cpfValido(document.forms[i].elements[k].name);
                        break;
                    }
                case "data": 
                    {
                        resultado = dataValida(document.forms[i].elements[k].name);
                        break;
                    }
                case "numero": 
                    {
                        resultado = numeroValido(document.forms[i].elements[k].name, document.forms[i].elements[k].descricao);
                        break;
                    }
                case "numeroobrigatorio": 
                    {
                        resultado = numerObr(document.forms[i].elements[k].name, document.forms[i].elements[k].descricao);
                        break;
                    }
                case "ddd": 
                    {
                        resultado = numeroDDDValido(document.forms[i].elements[k].name, document.forms[i].elements[k].descricao);
                        break;
                    }
                case "senha": 
                    {
                        resultado = senhaValida(document.forms[i].elements[k].name, document.forms[i].elements[k + 1].name);
                        break;
                    }
                case "email": 
                    {
                        resultado = emailValido(document.forms[i].elements[k].name);
                        break;
                    }
            }
        }
    }
    return resultado;
}
function ColocaOpcao(Selnome, CaixaIndice, CaixaTexto, TextoPlus, TextoPlusPlus) {
    var Indice = eval('document.forms[i].' + CaixaIndice + '.value;');
    var Texto = eval('document.forms[i].' + CaixaTexto + '.value;');
    var TextoPlus = eval('document.forms[i].' + TextoPlus + '.value;');

    if (
		numeroDDDValido('_ddd', 'O DDD do TELEFONE') &&
		campoDigitado('_tel', 'O TELEFONE') &&
		caixaSelecionada('_fkTelefoneTipo', 'O TIPO DE TELEFONE')
		) {
        var NovaOpcao = new Option(TextoPlus + ' ' + Texto, Indice + ' ' + TextoPlus + ' ' + Texto, false, false);
        eval('document.forms[i].' + Selnome + '.options[document.forms[i].' + Selnome + '.length]=NovaOpcao;');
    }
    return true;
}
function ExcluiOpcao(ObjSel) {
    if (eval('frm.' + ObjSel + '.selectedIndex') >= 0)
        eval('document.forms[i].' + ObjSel + '.options[document.forms[i].' + ObjSel + '.selectedIndex] = null;');
}



function ColocaOpcaoEspec(Selnome, SelEspec) {

    var Indice = eval('document.forms[i].' + SelEspec + '.value;');
    var Texto = eval('document.frm.' + SelEspec + '[document.forms[i].' + SelEspec + '.selectedIndex].text;');


    var NovaOpcao = new Option(Texto, Indice, false, false);
    eval('document.forms[i].' + Selnome + '.options[document.forms[i].' + Selnome + '.length]=NovaOpcao;');

    return true;
}

function ColocaOpcaoResp(Selnome, Nome, SelResp, ddd, telefone) {
    var Indice = eval('document.forms[i].' + Nome + '.value;');
    Indice = Indice + ' ' + eval('document.forms[i].' + SelResp + '.value;');
    Indice = Indice + ' ' + eval('document.forms[i].' + ddd + '.value;');
    Indice = Indice + ' ' + eval('document.forms[i].' + telefone + '.value;');
    var Texto = eval('document.forms[i].' + Nome + '.value;');


    if (
		campoDigitado('_resp', 'O Nome') &&
		caixaSelecionada('_fkresponsaveltipo', 'O TIPO DE Parente') &&
		numeroDDDValido('_dddcontato', 'O DDD do TELEFONE') &&
		campoDigitado('_telcontato', 'O TELEFONE')
		) {
        var NovaOpcao = new Option(Texto, Indice, false, false);
        eval('document.forms[i].' + Selnome + '.options[document.forms[i].' + Selnome + '.length]=NovaOpcao;');
    }
    return true;
}

function contacheck(obj) {
    var max = 1;
    var box = obj.frm.box.checked;
    //var conta = (box ? 1 : 0) 
    if (conta > max) {
        alert("Para este item selecionado vc podera somente checar um  ");
        obj.checked = false;
    }
}

function ColocarnaSel(SelPrincipal, SubObjs) {
    var Objs = new Array(5);
    var d = 0;
    var valores, valoresaux;
    var str = "";
    var valstr = "";


    Objs[d] = "";
    for (c = 0; c <= SubObjs.length; c++) {
        if (SubObjs.charAt(c) != "," && c < SubObjs.length)
            Objs[d] = Objs[d] + SubObjs.charAt(c);
        else {
            d = d + 1;
            Objs[d] = "";
            if (Objs[d - 1].substring(1, 3) != 'fk') {
                str = str + ' ' + eval('document.forms[i].' + Objs[d - 1] + '.value;');
                valstr = valstr + ' ' + eval('document.forms[i].' + Objs[d - 1] + '.value;');
            } else {
                str = str + ' ' + eval('document.forms[i].' + Objs[d - 1] + '[document.forms[i].' + Objs[d - 1] + '.selectedIndex].text;');
                valstr = valstr + ' ' + eval('document.forms[i].' + Objs[d - 1] + '[document.forms[i].' + Objs[d - 1] + '.selectedIndex].value;');
            }
        }
    }
    AdcSelVals(SelPrincipal, valstr.substring(1, valstr.length), str);
    return true;
}

function PegarSelecionado(SelPrincipal, SubObjs) {
    var Objs = new Array(5);
    var d = 0;
    var valores, valoresaux;

    Objs[d] = "";
    for (c = 0; c < SubObjs.length; c++) {
        if (SubObjs.charAt(c) != ",")
            Objs[d] = Objs[d] + SubObjs.charAt(c);
        else {

            d = d + 1;
            Objs[d] = "";
        }
    }
    valores = eval('document.forms[i].' + SelPrincipal + '[document.forms[i].' + SelPrincipal + '.selectedIndex].value;');
    d = 0;
    valoresaux = "";
    for (c = 0; c <= valores.length; c++) {
        if (valores.charAt(c) != " " && c < valores.length)
            valoresaux = valoresaux + valores.charAt(c);
        else {
            valoresaux = "'" + valoresaux + "'";
            eval('document.forms[i].' + Objs[d] + '.value=' + valoresaux + ';')
            d = d + 1;
            valoresaux = "";
        }
    }
    return true;
}

function AdcSelVals(SelPrincipal, Indice, Texto) {
    var NovaOpcao = new Option(Texto, Indice, false, false);
    eval('document.forms[i].' + SelPrincipal + '.options[document.forms[i].' + SelPrincipal + '.length]=NovaOpcao;');

    return true;
}

function ColocaValores(SelPrincipal, Indice, Texto) {
    var Indice = eval('document.forms[i].' + Indice + '.value;');
    var Texto = eval('document.forms[i].' + Texto + '.value;');

    AdcSelVals(SelPrincipal, Indice, Texto);
    return true;
}


function val(str) {
    var value = parseFloat(String(str).replace(/\./g, "").replace(/\,/, "."))

    return isNaN(value) ? 0 : value
}

function isArray(obj) {
    return (obj.constructor == Array)
}

function bRecarregarElemento(oElemento_, szOpcao_, szQueryString_, oPostarElemento_) {
    // OBS.: O par&#65533;metro 'oElemento_' pode ser uma matriz de elementos.

    var szRequestUrl = location.pathname + "?opcao=" + szOpcao_ + "&" + szQueryString_

    //alert( szRequestUrl )

    var xhrInnerHtml = false;

    try {
        xhrInnerHtml = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {

        try {
            xhrInnerHtml = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (E) {
            //xmlhttp = false; // esta linha &#65533; que dava problema com firefox
            xhrInnerHtml = new XMLHttpRequest();
        }
    }

    if (!xhrInnerHtml) return false

    xhrInnerHtml.open("GET", szRequestUrl, false)

    if (oPostarElemento_) {
        // Posta os dados contido no elemento 'oPostarElemento_', ou seja, envia ao servidor os valores de todos os
        // campos que t&#65533;m um nome e que estejam dentro da tag referente &#65533; vari&#65533;vel 'oPostarElemento_', como se fosse
        // o 'submit' de um '<form method=POST>':
        postRequest(xhrInnerHtml, oPostarElemento_)
    }
    else {
        //TEM Q PASSAR null para funcionar no firefox:		    
        xhrInnerHtml.send(null)
    }

    //alert( xhrInnerHtml.responseText )

    var szInnerHtml = xhrInnerHtml.responseText

    if (!szInnerHtml) return false

    var reNodeHead = /<[^<>]+>/

    //alert( oElemento_.length )

    if (!isArray(oElemento_)) {

        if (oElemento_.outerHTML) {
            //IE:
            var szNodeHead = oElemento_.outerHTML.match(reNodeHead)
            oElemento_.outerHTML = szNodeHead + szInnerHtml + "</" + oElemento_.tagName + ">"
        }
        else // FIREFOX:            
            oElemento_.innerHTML = "<" + oElemento_.tagName + ">" + szInnerHtml + "</" + oElemento_.tagName + ">"

    }
    else if (!oElemento_.length) {
        return false
    }
    else {

        for (var i = 0; i < oElemento_.length; i++) {
            var szNodeHead = oElemento_[i].outerHTML.match(reNodeHead)
            oElemento_[i].outerHTML = szNodeHead + szInnerHtml + "</" + oElemento_[i].tagName + ">"
        }
    }

    return true
}

function vSomenteNum(evt, bAceitaVirgula_) {
    var key_code = evt.keyCode ? evt.keyCode :
                       evt.charCode ? evt.charCode :
                       evt.which ? evt.which : void 0;

    //Aceita a virgula para informar numeros decimais:
    if (bAceitaVirgula_ && key_code == 44)
        return true

    //key_code == 46

    // Habilita teclas <DEL>, <TAB>, <ENTER>, <ESC> e <BACKSPACE>
    if (key_code == 46 || key_code == 8 || key_code == 9 || key_code == 13 || key_code == 27) {
        return true;
    }

    // Habilita teclas <HOME>, <END>, mais as quatros setas de navegação (cima, baixo, direta, esquerda)
    else if (key_code >= 35 && key_code <= 40) {
        return true
    }

    // Habilita números de 0 a 9
    else if ((key_code >= 48) && (key_code <= 57)) {
        return true
    }

    return false;
}

function FormatMesAno(val) {
    var strPass = val.value;
    var mikExp = /[0123456789]/;

    for (i = 0; i < strPass.length; i++) {
        // charAt -> retorna o caractere posicionado no ?ndice especificado
        var lchar = val.value.charAt(i);
        var nchar = val.value.charAt(i + 1);

        if (i == 0) {
            // search -> retorna um valor inteiro, indicando a posi??o do inicio da primeira
            // ocorr?ncia de expReg dentro de instStr. Se nenhuma ocorrencia for encontrada o m?todo retornara -1
            // instStr.search(expReg);
            if ((lchar.search(mikExp) != 0) || (lchar > 3)) {
                val.value = "";
            }

        } else if (i == 1) {

            if (lchar.search(mikExp) != 0) {
                // substring(indice1,indice2)
                // indice1, indice2 -> ser? usado para delimitar a string
                var tst1 = val.value.substring(0, (i));
                val.value = tst1;
                continue;
            }

            if ((nchar != '/') && (nchar != '')) {
                var tst1 = val.value.substring(0, (i) + 1);

                if (nchar.search(mikExp) != 0)
                    var tst2 = val.value.substring(i + 2, strPass.length);
                else
                    var tst2 = val.value.substring(i + 1, strPass.length);

                val.value = tst1 + '/' + tst2;
            }

        } else if (i == 4) {

            if (lchar.search(mikExp) != 0) {
                var tst1 = val.value.substring(0, (i));
                val.value = tst1;
                continue;
            }

            if ((nchar != '/') && (nchar != '')) {
                var tst1 = val.value.substring(0, (i) + 1);

                if (nchar.search(mikExp) != 0)
                    var tst2 = val.value.substring(i + 2, strPass.length);
                else
                    var tst2 = val.value.substring(i + 1, strPass.length);

                val.value = tst1 + '/' + tst2;
            }
        }

        if (i >= 6) {
            if (lchar.search(mikExp) != 0) {
                var tst1 = val.value.substring(0, (i));
                val.value = tst1;
            }
        }
    }

    if (strPass.length > 10)
        val.value = val.value.substring(0, 10);
    return true;
}

function vFormatarTelefone(input_, evento_) {
    if (navigator.userAgent.indexOf("IE") != -1) {
        var keypress = window.event.keyCode;

        if (keypress > 47 && keypress < 58 && input_.value.length < 13) {

            /*if (input_.value.length == 0)
            input_.value = "(" + input_.value;
            if (input_.value.length == 3)
            input_.value = input_.value + ")";*/

            if (input_.value.length == 4)
                input_.value = input_.value + "-";

        }
        else
            event.returnValue = false;
    }
    else {

        lineaux = input_.value;

        var keypress = evento_.which;

        if (keypress == 8 || keypress == 0)
            return true;

        if ((keypress < 48 || keypress > 57) || input_.value.length >= 13)
            return false;



        /*if (lineaux.length == 0)
        lineaux = "(";
        if (lineaux.length == 3)
        lineaux = lineaux + ")";*/

        if (lineaux.length == 4)
            lineaux = lineaux + "-";

        lineaux = lineaux + (keypress - 48);
        input_.value = lineaux;

        return false;

    }

    return true;
}

function bConsistirPedido() {

    var oCamposEstoque = document.getElementsByName("qtdestoque")
    var oCamposQtd = document.getElementsByName("quantidade")
    var oCamposDescProd = document.getElementsByName("med_des")   
    
	var oCampoMinima = document.getElementsByName("qtdminima")
    var oCampoMaximo = document.getElementsByName("qtdmaxima")
	
    for (var i = 0; i < oCamposEstoque.length; i++)
	{	
		
		if (val(oCamposQtd[i].value) > 0 && val(oCampoMinima[i].value) > val(oCamposQtd[i].value))
		{
            alert("A quantidade MÍNIMA permitida para o produto \n'" + oCamposDescProd[i].value + "' é de (" + oCampoMinima[i].value + ")!")
            oCamposQtd[i].value = oCampoMinima[i].value
        }
		
		if (val(oCampoMaximo[i].value) < val(oCamposQtd[i].value))
		{
            alert("A quantidade MÁXIMA permitida para o produto \n'" + oCamposDescProd[i].value + "' é de (" + oCampoMaximo[i].value + ")!")
            oCamposQtd[i].value = oCampoMaximo[i].value
        }
		
        if (val(oCamposEstoque[i].value) < val(oCamposQtd[i].value))
		{
            alert("Neste momento o estoque disponível no portal para o produto\n'" + oCamposDescProd[i].value + "' é de (" + oCamposEstoque[i].value + ")!")
            oCamposQtd[i].value = oCamposEstoque[i].value
        }
    }

    return true
}

function vAvisemeEstoque(iCodProduto_, Distribuidora_ ) {

    //alert(iCodProduto_)
    
    if (confirm("Deseja realmente ser alertado quando este produto estiver disponível?"))
        frameAviseme.location = "Aviseme.asp?CodigoDiva=" + iCodProduto_ + "&Distribuidora=" + Distribuidora_

}

function str_pad(input, pad_length, pad_string, pad_type) {
    // Returns input string padded on the left or right to specified length with pad_string 
    //
    // version: 909.322
    // discuss at: http://phpjs.org/functions/str_pad
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // + namespaced by: Michael White (http://getsprink.com)
    // +      input by: Marco van Oort
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: str_pad('Kevin van Zonneveld', 30, '-=', 'STR_PAD_LEFT');
    // *     returns 1: '-=-=-=-=-=-Kevin van Zonneveld'
    // *     example 2: str_pad('Kevin van Zonneveld', 30, '-', 'STR_PAD_BOTH');
    // *     returns 2: '------Kevin van Zonneveld-----'
    var half = '', pad_to_go;

    var str_pad_repeater = function(s, len) {
        var collect = '', i;

        while (collect.length < len) { collect += s; }
        collect = collect.substr(0, len);

        return collect;
    };

    input += '';
    pad_string = pad_string !== undefined ? pad_string : ' ';

    if (pad_type != 'STR_PAD_LEFT' && pad_type != 'STR_PAD_RIGHT' && pad_type != 'STR_PAD_BOTH') { pad_type = 'STR_PAD_RIGHT'; }
    if ((pad_to_go = pad_length - input.length) > 0) {
        if (pad_type == 'STR_PAD_LEFT') { input = str_pad_repeater(pad_string, pad_to_go) + input; }
        else if (pad_type == 'STR_PAD_RIGHT') { input = input + str_pad_repeater(pad_string, pad_to_go); }
        else if (pad_type == 'STR_PAD_BOTH') {
            half = str_pad_repeater(pad_string, Math.ceil(pad_to_go / 2));
            input = half + input + half;
            input = input.substr(0, pad_length);
        }
    }

    return input;
}

function cnpjValido(cnpj) {
    regExp = /[^0-9]/gi;

    if (cnpj[0] == 0) {
        cnpj = cnpj.substring(1, cnpj.length);
    }

    cnpj = str_pad(cnpj.replace(regExp, ''), 14, '0', 'STR_PAD_LEFT');

    if (cnpj == '00000000000000' || cnpj == '11111111111111' || cnpj == '22222222222222' || cnpj == '33333333333333' || cnpj == '44444444444444' || cnpj == '55555555555555' || cnpj == '66666666666666' || cnpj == '77777777777777' || cnpj == '88888888888888' || cnpj == '99999999999999') {
        return false;
    } else if (cnpj.length != 14) {
        return false;
    } else {
        for (t = 12; t < 14; t++) {
            for (d = 0, p = t - 7, c = 0; c < t; c++) {
                d += cnpj[c] * p;
                p = (p < 3) ? 9 : --p;
            }

            d = ((10 * d) % 11) % 10;

            if (cnpj[c] != d) {
                return false;
            }
        }

        return true;
    }
}

function bEmailValido(szEmail_) {

    prim = szEmail_.indexOf("@")

    if (prim < 2) {
        return false;
    }

    if (szEmail_.indexOf("@", prim + 1) != -1) {
        return false;
    }

    if (szEmail_.indexOf(".") < 1) {
        return false;
    }

    if (szEmail_.indexOf(" ") != -1) {
        return false;
    }

    if (szEmail_.indexOf("zipmeil.com") > 0) {
        return false;
    }

    if (szEmail_.indexOf("hotmeil.com") > 0) {
        return false;
    }

    if (szEmail_.indexOf(".@") > 0) {
        return false;
    }

    if (szEmail_.indexOf("@.") > 0) {
        return false;
    }

    if (szEmail_.indexOf(".com.br.") > 0) {
        return false;
    }

    if (szEmail_.indexOf("/") > 0) {
        return false;
    }

    if (szEmail_.indexOf("[") > 0) {
        return false;
    }

    if (szEmail_.indexOf("]") > 0) {
        return false;
    }

    if (szEmail_.indexOf("(") > 0) {
        return false;
    }

    if (szEmail_.indexOf(")") > 0) {
        return false;
    }

    if (szEmail_.indexOf("..") > 0) {
        return false;
    }

    return true

}

//AJAX COMBO PAGAMENTO 
function GetXMLHttp() {
    if (navigator.appName == "Microsoft Internet Explorer") {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
}

var mod = GetXMLHttp();


function TeleVendasiphone(valor) {
    //alert(valor)
    mod.open("GET", "/iphone/CarregaClienteOL.asp?id=" + valor + "", true);
    // mod.open("GET", "/Distribuidora/CarregaClienteOL.asp?id=" + valor + "&cidade=" + cidade + "&cnpj=" + cnpj + "&razao=" + razao + "", true);
    mod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    mod.onreadystatechange = function() {
        if (mod.readyState == 4) {
            document.getElementById("resultadoVendas").innerHTML = mod.responseText;
        }
    };

    mod.send(null);
}


function TeleVendas(valor) {
    //alert(valor)
    mod.open("GET", "/Televendas/CarregaClienteOL.asp?id=" + valor + "", true);
    // mod.open("GET", "/Distribuidora/CarregaClienteOL.asp?id=" + valor + "&cidade=" + cidade + "&cnpj=" + cnpj + "&razao=" + razao + "", true);
    mod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    mod.onreadystatechange = function() {
        if (mod.readyState == 4) {
            document.getElementById("resultadoVendas").innerHTML = mod.responseText;
        }
    };

    mod.send(null);
}
function TeleVendas1(valor) {
    //alert(valor)
    mod.open("GET", "/Televendas/CarregaClienteOL.asp?id1=" + valor + "", true);
    // mod.open("GET", "/Distribuidora/CarregaClienteOL.asp?id=" + valor + "&cidade=" + cidade + "&cnpj=" + cnpj + "&razao=" + razao + "", true);
    mod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    mod.onreadystatechange = function() {
        if (mod.readyState == 4) {
            document.getElementById("resultadoVendas").innerHTML = mod.responseText;
        }
    };

    mod.send(null);
}

function TeleVendas2(valor) {
    //alert(valor)
    mod.open("GET", "/Televendas/CarregaClienteOL.asp?id2=" + valor + "", true);
    // mod.open("GET", "/Distribuidora/CarregaClienteOL.asp?id=" + valor + "&cidade=" + cidade + "&cnpj=" + cnpj + "&razao=" + razao + "", true);
    mod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    mod.onreadystatechange = function() {
        if (mod.readyState == 4) {
            document.getElementById("resultadoVendas").innerHTML = mod.responseText;
        }
    };

    mod.send(null);
}

function TeleVendas3(valor) {
    //alert(valor)
    mod.open("GET", "/Televendas/CarregaClienteOL.asp?id3=" + valor + "", true);
    // mod.open("GET", "/Distribuidora/CarregaClienteOL.asp?id=" + valor + "&cidade=" + cidade + "&cnpj=" + cnpj + "&razao=" + razao + "", true);
    mod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    mod.onreadystatechange = function() {
        if (mod.readyState == 4) {
            document.getElementById("resultadoVendas").innerHTML = mod.responseText;
        }
    };

    mod.send(null);
}


function alimentarCombo(valor) {

    mod.open("GET", "/Distribuidora/CarregaClienteOL.asp?id=" + valor + "", true);
    // mod.open("GET", "/Distribuidora/CarregaClienteOL.asp?id=" + valor + "&cidade=" + cidade + "&cnpj=" + cnpj + "&razao=" + razao + "", true);
    mod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    mod.onreadystatechange = function() {
        if (mod.readyState == 4) {
            document.getElementById("resultado").innerHTML = mod.responseText;
        }
    };

    mod.send(null);
}



function alimentarCombo1(valor) {

    mod.open("GET", "/Distribuidora/CarregaClienteOL.asp?id1=" + valor + "", true);
    // mod.open("GET", "/Distribuidora/CarregaClienteOL.asp?id=" + valor + "&cidade=" + cidade + "&cnpj=" + cnpj + "&razao=" + razao + "", true);
    mod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    mod.onreadystatechange = function() {
        if (mod.readyState == 4) {
            document.getElementById("resultado").innerHTML = mod.responseText;
        }
    };

    mod.send(null);
}

function alimentarCombo2(valor) {

    mod.open("GET", "/Distribuidora/CarregaClienteOL.asp?id2=" + valor + "", true);
    // mod.open("GET", "/Distribuidora/CarregaClienteOL.asp?id=" + valor + "&cidade=" + cidade + "&cnpj=" + cnpj + "&razao=" + razao + "", true);
    mod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    mod.onreadystatechange = function() {
        if (mod.readyState == 4) {
            document.getElementById("resultado").innerHTML = mod.responseText;
        }
    };

    mod.send(null);
} 


function vAbrirMenuAdm( szCnpj_ )
	{	
		oModalMenu = dhtmlmodal.open('EmailBox', 'iframe', 'menuAdm.asp?CNPJ=' + szCnpj_, 'Menu', 'width=605px,height=110px,center=1, resize=0,scrolling=0')
}

function alimentarComboRelatorio(produto) {
    mod.open("GET", "/adm/CarregaProduto.asp?Produto=" + produto + "", true);
    mod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    mod.onreadystatechange = function () {
        if (mod.readyState == 4) {
            document.getElementById("resultadoPedido").innerHTML = mod.responseText;
        }
    };
    mod.send(null);
}

function atualizarcaptcha(valor) {
    // alert("oi")
    mod.open("GET", "/FaleConosco/captcha/atualiza.asp?id=" + valor + "", true);
    mod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    mod.onreadystatechange = function () {
        if (mod.readyState == 4) {
            // alert(mod.responseText)
            document.getElementById("resultado").innerHTML = mod.responseText;
        }
    };
    mod.send(null);
} 
