function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}

function MM_findObj(n, d) { //v4.0
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && document.getElementById) x = document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function MM_timelineStop(tmLnName) { //v1.2
    if (document.MM_Time == null) MM_initTimelines(); //if *very* 1st time
    if (tmLnName == null)  //stop all
        for (var i = 0; i < document.MM_Time.length; i++) document.MM_Time[i].ID = null;
    else document.MM_Time[tmLnName].ID = null; //stop one
}

function MM_timelinePlay(tmLnName, myID) { //v1.2
    var i, j, tmLn, props, keyFrm, sprite, numKeyFr, firstKeyFr, propNum, theObj, firstTime = false;
    if (document.MM_Time == null) MM_initTimelines(); //if *very* 1st time
    tmLn = document.MM_Time[tmLnName];
    if (myID == null) { myID = ++tmLn.ID; firstTime = true; } //if new call, incr ID
    if (myID == tmLn.ID) { //if Im newest
        setTimeout('MM_timelinePlay("' + tmLnName + '",' + myID + ')', tmLn.delay);
        fNew = ++tmLn.curFrame;
        for (i = 0; i < tmLn.length; i++) {
            sprite = tmLn[i];
            if (sprite.charAt(0) == 's') {
                if (sprite.obj) {
                    numKeyFr = sprite.keyFrames.length; firstKeyFr = sprite.keyFrames[0];
                    if (fNew >= firstKeyFr && fNew <= sprite.keyFrames[numKeyFr - 1]) {//in range
                        keyFrm = 1;
                        for (j = 0; j < sprite.values.length; j++) {
                            props = sprite.values[j];
                            if (numKeyFr != props.length) {
                                if (props.prop2 == null) sprite.obj[props.prop] = props[fNew - firstKeyFr];
                                else sprite.obj[props.prop2][props.prop] = props[fNew - firstKeyFr];
                            } else {
                                while (keyFrm < numKeyFr && fNew >= sprite.keyFrames[keyFrm]) keyFrm++;
                                if (firstTime || fNew == sprite.keyFrames[keyFrm - 1]) {
                                    if (props.prop2 == null) sprite.obj[props.prop] = props[keyFrm - 1];
                                    else sprite.obj[props.prop2][props.prop] = props[keyFrm - 1];
                                } 
                            } 
                        } 
                    } 
                }
            } else if (sprite.charAt(0) == 'b' && fNew == sprite.frame) eval(sprite.value);
            if (fNew > tmLn.lastFrame) tmLn.ID = 0;
        } 
    }
}

function MM_timelineGoto(tmLnName, fNew, numGotos) { //v2.0
    var i, j, tmLn, props, keyFrm, sprite, numKeyFr, firstKeyFr, lastKeyFr, propNum, theObj;
    if (document.MM_Time == null) MM_initTimelines(); //if *very* 1st time
    tmLn = document.MM_Time[tmLnName];
    if (numGotos != null)
        if (tmLn.gotoCount == null) tmLn.gotoCount = 1;
        else if (tmLn.gotoCount++ >= numGotos) { tmLn.gotoCount = 0; return }
    jmpFwd = (fNew > tmLn.curFrame);
    for (i = 0; i < tmLn.length; i++) {
        sprite = (jmpFwd) ? tmLn[i] : tmLn[(tmLn.length - 1) - i]; //count bkwds if jumping back
        if (sprite.charAt(0) == "s") {
            numKeyFr = sprite.keyFrames.length;
            firstKeyFr = sprite.keyFrames[0];
            lastKeyFr = sprite.keyFrames[numKeyFr - 1];
            if ((jmpFwd && fNew < firstKeyFr) || (!jmpFwd && lastKeyFr < fNew)) continue; //skip if untouchd
            for (keyFrm = 1; keyFrm < numKeyFr && fNew >= sprite.keyFrames[keyFrm]; keyFrm++);
            for (j = 0; j < sprite.values.length; j++) {
                props = sprite.values[j];
                if (numKeyFr == props.length) propNum = keyFrm - 1 //keyframes only
                else propNum = Math.min(Math.max(0, fNew - firstKeyFr), props.length - 1); //or keep in legal range
                if (sprite.obj != null) {
                    if (props.prop2 == null) sprite.obj[props.prop] = props[propNum];
                    else sprite.obj[props.prop2][props.prop] = props[propNum];
                } 
            }
        } else if (sprite.charAt(0) == 'b' && fNew == sprite.frame) eval(sprite.value);
    }
    tmLn.curFrame = fNew;
    if (tmLn.ID == 0) eval('MM_timelinePlay(tmLnName)');
}

function MM_showHideLayers() { //v3.0
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3) if ((obj = MM_findObj(args[i])) != null) {
        v = args[i + 2];
        if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v = 'hide') ? 'hidden' : v; }
        obj.visibility = v;
    }
}

function abrirJanelaCentralizada(jsUrl, jsNome, jsWidth, jsHeight, jsScroll, jsResize) {

    xLeft = (screen.width) ? (screen.width - jsWidth) / 2 : 0;
    xTop = (screen.height) ? (screen.height - jsHeight) / 2 : 0;
    var jsConfig = 'height=' + jsHeight + ',width=' + jsWidth + ',top=' + xTop + ',left=' + xLeft + ',status=no,scrollbars=' + jsScroll + ',resizable=' + jsResize;
    window.open(jsUrl, jsNome, jsConfig);
}

function abrir_janela(url, nome, w, h) { //v1.0
    var acertos = 'width=' + w + ', height=' + h + ',left=20, top=20, screenx=20, screeny=20, resizable=no';
    window.open(url, nome, acertos);
}

// onde: url = endereço / janela = nome da janela / L = largura / A = altura / Centro = true ou false / Sbar (statusbar) = 0 ou 1 / SCbar (scrollbars) = 0 ou 1 / Rsize = 0 ou 1
// ***  url,janela,L,A,Centro,Sbar,SCbar,Rsize  ***
function janela(url, janela, L, A, Centro, Sbar, SCbar, Rsize, Mbar) { //v2.0
    var hor;
    var ver;
    if (Centro == true) {
        //		hor = L;
        hor = (screen.width - L) / 2;
        //		ver = A;
        ver = (screen.height - A) / 2;
        ver = ver - 35;
    }
    else { hor = 20; ver = 20; }
    var acertos = 'width=' + L + ', height=' + A + ',left=' + hor + ', top=' + ver + ', screenx=' + hor + ', screeny=' + ver + ', status=' + Sbar + ', scrollbars=' + SCbar + ', resizable=' + Rsize + ', menuBar=' + Mbar;
    window.open(url, janela, acertos);
}

/***************************************************************/
/*					Funções para impressão    				   */
/***************************************************************/

function imprimirTabela(idObject) {

    var xWidth = 800;
    var xHeight = 500;
    var xMac = (navigator.userAgent.indexOf("Mac") != -1);
    var xDoc = (document.all) ? 1 : 0;
    var xIE_NS = (window.print) ? 1 : 0;
    var xDocumentContainer = document.getElementById(idObject);
    var xLeft = (screen.width) ? (screen.width - xWidth) / 2 : 0;
    var xTop = (screen.height) ? (screen.height - xHeight) / 2 : 0;
    var xConfig = 'height=' + xHeight + ',width=' + xWidth + ',top=' + xTop + 'px,left=' + xLeft + 'px,status=no,scrollbars=yes,resizable=no,toolbar=yes';
    var xWindowObject = window.open('', "_PopUp", xConfig);

    xWindowObject.document.writeln('<html><head><title>Hermes Vendas - Impressão</title>');
    xWindowObject.document.writeln('<link href="/_css/impressao.css" rel="stylesheet" type="text/css" media="print, screen" />');
    xWindowObject.document.writeln('</head><body><table>');
    xWindowObject.document.writeln(xDocumentContainer.innerHTML);
    xWindowObject.document.writeln('</table></body></html>');

    setTimeout(function () { if (xIE_NS) { xWindowObject.document.close(); xWindowObject.focus(); xWindowObject.print(); xWindowObject.close(); } else if (xDoc && !xMac) { xWindowObject.vbPrintPage(); xWindowObject.close(); } else { alert('Por favor, utilize o icone do menu superior para imprimir.'); } }, 1000);

}


/***************************************************************/

// Data-Hora de Hoje

var now = new Date();
var mName = now.getMonth();
var dName = now.getDay() + 1;
var dayNr = now.getDate();
var yearNr = now.getYear();

var segs = now.getSeconds();
var mins = now.getMinutes();
var horaat = now.getHours();
var tempo = now.getTime();

// Declaração da Matriz mês

var meses = new Array();

meses[1] = "janeiro";
meses[2] = "fevereiro";
meses[3] = "março";
meses[4] = "abril";
meses[5] = "maio";
meses[6] = "junho";
meses[7] = "julho";
meses[8] = "agosto";
meses[9] = "setembro";
meses[10] = "outubro";
meses[11] = "novembro";
meses[12] = "dezembro";

mes = meses[now.getMonth() + 1];

if (dName == 1) Day = "domingo";
if (dName == 2) Day = "segunda-feira";
if (dName == 3) Day = "ter&ccedil;a-feira";
if (dName == 4) Day = "quarta-feira";
if (dName == 5) Day = "quinta-feira";
if (dName == 6) Day = "sexta-feira";
if (dName == 7) Day = "s&aacute;bado";
if (yearNr < 2000) var Year = 1900 + yearNr;
else var Year = yearNr;
// Escreve a data
hoje = (" " + Day + ", " + dayNr + " de " + mes + " de " + Year);

// Críticas de Horário
if (segs < 10) segs = "0" + segs;
if (mins < 10) mins = "0" + mins;
if (horaat < 10) hora = "0" + horaat;

// Crítica de Saudação
//var sauda;
//if (horaat >= 5 && horaat <= 12) { sauda = Bom dia; }
//	else if (horaat > 12 && horaat <= 6) { sauda = Boa tarde; }
//		else { sauda = Boa noite; }

// Escreve Horário
hora = (horaat + ":" + mins + " hs");

// Função para Troca de Cor das Células de uma Tabela
function mOvr(src, clrOver) {
    if (!src.contains(event.fromElement)) {
        src.style.cursor = 'hand';
        src.bgColor = clrOver;
    }
}
function mOut(src, clrIn) {
    if (!src.contains(event.toElement)) {
        src.style.cursor = 'default';
        src.bgColor = clrIn;
    }
}
function mClk(src) {
    if (event.srcElement.tagName == 'TD') {
        src.children.tags('A')[0].click();
    }
}

function MM_reloadPage(init) {
    if (init == true) with (navigator) {
        if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
            document.MM_pgW = innerWidth; document.MM_pgH = innerHeight; onresize = MM_reloadPage;
        } 
    }
    else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function noStatus(msg) {
    status = msg;
    document.retorno = true;
}

function hidetab(idt, state) { idt.style.display = state; }
function showtab(idt, state) { idt.style.display = state; }

function alt(camada, estado, txt) {
    var mousex = window.event.x;        // mouse X
    var mousey = window.event.y;        // mouse Y
    camada.style.visibility = estado;   // mostrar ou esconder camada
    camada.style.left = mousex;         // obj X + 5
    camada.style.top = mousey;          // obj Y 
    nota.innerHTML = txt;                 // texto a ser mostrado na nota
}

function verNota(camada, estado, txt, classe) {
    if (camada == altDir) {
        var mousex = window.event.x - 205; 	// mouse X
        var mousey = window.event.y - 5; 		// mouse Y
        obj = notaDir;
    }
    else {
        var mousex = window.event.x + 5; 		// mouse X
        var mousey = window.event.y + 5; 		// mouse Y
        obj = notaEsq;
    }
    camada.style.visibility = estado; 				// mostrar ou esconder camada
    camada.style.left = mousex; 					// obj X + 5
    camada.style.top = mousey; 					// obj Y 
    obj.innerHTML = txt; 									// texto a ser mostrado na nota
    obj.className = classe; 							// classe do objeto
}

function email(campo) {
    var ok = campo.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
    if (!ok) {
        if (confirm("Este email não é válido. Clique em 'OK' para corrigir ou 'Cancel' para continuar.")) {
            campo.focus();
            campo.select();
        }
        else { return; }
    }
}

function formataData(campo) {
    t = campo.value;
    if (t.length == 2) { campo.value = campo.value + '/'; }
    if (t.length == 5) { campo.value = campo.value + '/'; }
}
function validata(obj) {
    if (event.keyCode == 0 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 46 || event.keyCode == 16 || event.shiftKey) { return false }
    if (obj.tagName == 'INPUT') {
        if (obj.value.length == 2 || obj.value.length == 5) obj.value += "/";
        if (obj.value.length == 8 && obj.maxLength == 10) {
            ano = obj.value.substr(6, 2);
            if (ano < 18) {
                ano = '20' + ano;
                obj.value = obj.value.substr(0, 6) + ano;
                tab(obj);
                return;
            }
            else {
                if (ano == 20 || ano == 19) { return false; }
                ano = '19' + ano;
                obj.value = obj.value.substr(0, 6) + ano;
                tab(obj);
                return;
            }
        }
        if (obj.value.length == obj.maxLength) { tab(obj); return; }
    }
    if (obj.tagName == 'SPAN') {
        cData = obj.innerText;
        if (cData.length == 2 || cData.length == 5) cData += "/"; obj.innerText = cData;
        if (cData.length == 8) {
            ano = cData.substr(6, 2);
            if (ano < 18) {
                ano = '20' + ano;
                cData = cData.substr(0, 6) + ano;
                obj.innerText = cData;
            }
            else {
                if (ano == 20 || ano == 19) { return false; }
                ano = '19' + ano;
                cData = cData.substr(0, 6) + ano;
                obj.innerText = cData;
            }
        }
    }
}

function tab(obj) {
    if (obj.value.length >= obj.maxLength) {
        var a = -1, b = 0;
        while (b < obj.form.length && a == -1) {
            if ((b + 1) == obj.form.length) { obj.blur(); return false; }
            if (obj.form[b] == obj) { obj.blur(); obj.form[b + 1].focus(); }
            b++;
        }
    }
}

function TabFocus(obj) {
    camada = obj.parentElement;
    continua = true;
    while (continua) {
        while (camada.tagName != "DIV")
            camada = camada.parentElement;
        if (camada.style.overflow != "hidden")
            continua = false;
        else
            camada = camada.parentElement;
    }
    orelhas = camada.all.item("tabBtPaleta")
    if (orelhas != null) {
        tabelas = camada.all.item("tabPaleta")
        for (p = 0; p < tabelas.length; p++) {
            if ((tabelas[p].style.display == 'none') && (tabelas[p].contains(obj)))
                controleTab(orelhas[p]);
        }
    }
    obj.focus();
}

function forceTab(obj) {
    try {
        var a = -1, b = 0;
        if (obj.ignoratab == '1') {
            obj.blur();
            hideOp();
            return;
        }
        while (b < obj.form.length && a == -1) {
            if ((b + 1) == obj.form.length) { obj.blur(); return false; }
            if (obj.form[b] == obj) {
                while (obj.form[b + 1].type == 'button' || obj.form[b + 1].type == 'hidden' || obj.form[b + 1].readOnly == true) {
                    b++;
                    aa = 0;
                    if ((b + 1) == obj.form.length) { obj.blur(); hideOp(); return false; }
                }
                obj.blur();
                campo = obj.form[b + 1];
                TabFocus(campo);
            }
            b++;
        }
    }
    catch (err) {
        AvisoErro("FORCETAB: ", err);
    }
}

function doNumber() {
    var whichcode = window.event.keyCode;
    if (whichcode != 45) {
        if (whichcode < 48) whichcode = 0;
        if (whichcode > 57) whichcode = 0;
    }
    window.event.keyCode = whichcode;
}

function popNoticia(src, txt) {
    document.tempo.caminho.value = src;
    document.tempo.legenda.value = txt;
    document.tempo.method = 'POST';
    document.tempo.action = "zoom.asp";
    janela('zoom.asp', 'zoom', 728, 450, true, 1, 1, 1);
    document.tempo.target = "zoom";
    document.tempo.submit()
}

// =======================	VIEW PIC - ZOOM NAS IMAGENS ============================
function viewPic(img) {
    picfile = new Image();
    picfile.src = (img);
    fileCheck(img);
}

function fileCheck(img) {
    if ((picfile.width != 0) && (picfile.height != 0)) {
        makeWindow(img);
    }
    else {
        funzione = "fileCheck('" + img + "')";
        intervallo = setTimeout(funzione, 10);
    }
}
function makeWindow(img) {
    ht = picfile.height;
    wd = picfile.width;

    var args = "height=" + ht + ",innerHeight=" + ht;
    args += ",width=" + wd + ",innerWidth=" + wd;
    if (window.screen) {
        var avht = screen.availHeight;
        var avwd = screen.availWidth;
        var xcen = (avwd - wd) / 2;
        var ycen = (avht - ht) / 2;
        args += ",left=" + xcen + ",screenX=" + xcen;
        args += ",top=" + ycen + ",screenY=" + ycen + ",resizable=yes";
    }

    popwin = window.open("", "_blank", args)
    popwin.document.open()
    popwin.document.write('<html><head><title>' + img + '</title></head><body bgcolor=white scroll=no topmargin=0 leftmargin=0 rightmargin=0 bottomargin=0 marginheight=0 marginwidth=0><div style="position: absolute; top:0px;left:0px"><a href="javascript:window.close()"><img src="' + img + '" width="' + wd + '" height="' + ht + '" border="0"></a></div></body></html>')
    popwin.document.close()
}
// =========================================================================
function NormalizarActiveXObject(objIdInner, flashId, w, h, params) {
    // —————————————————————————-
    // Função para normalização do plugin "Macromedia Flash Player" pela Tag "OBJECT"
    // referente a atualização disponibilizada pela Microsoft para o Internet Explorer
    // Patch "KB912945" para WindowsXP - Home/Professional - SP1 e SP2
    // —————————————————————————-
    // Função dentro dos padrões W3C - sem utilização da Tag "EMBED", via método "innerHTML"
    // —————————————————————————-
    // Parâmetros requeridos:
    // objIdInner = ID do Objeto onde o código será inserido em tempo de execução ** Ítem obrigatório
    // flashId = ID do Objeto flash, para devida identificação ** Ítem obrigatório
    // w = Largura ** Ítem obrigatório
    // h = Altura ** Ítem obrigatório
    // params = parâmetros de formatação ".SWF", definidos na página de origem ** Ítem obrigatório
    // —————————————————————————-
    var strInner = ('<object id="' + flashId + '" type="application/x-shockwave-flash" data="' + params[0][1] + '" width="' + w + '" height="' + h + '">');
    for (i = 0; i < params.length; i++) { strInner += ('<param name="' + params[i][0] + '" value="' + params[i][1] + '"/>'); }
    strInner += ('</object>');
    if (document.getElementById) {
        document.getElementById(objIdInner).innerHTML = strInner;
    } else if (document.all) {
        document.all.objIdInner.innerHTML = strInner;
    } else {
        alert("Prezado cliente, seu navegador não é compatível com\nalgumas das tecnologias utilizadas neste site.\nPor favor atualize seu navegador.");
    }
}
// =========================================================================
function VerificaCampos() {

    //VALIDAÇÃO DOS CAMPOS

    if (document.tempo.cadEmail.value.length < 1) {
        alert("O campo EMAIL não pode estar vazio.");
        document.tempo.cadEmail.focus();
        return;
    }

    if (document.tempo.cadEmail.value.indexOf("@") == -1) {
        alert("EMAIL inválido!");
        document.tempo.cadEmail.focus();
        return;
    }

    document.tempo.submit();

}

function Form_Validator() {
    if (document.tempo.cod.value.length < 5) {
        alert("O Código do Distribuidor deve conter 6 números.");
        document.tempo.cod.focus();
        return;
    }

    //validacao do campo codigo do usuario que só aceita números

    var checkOK = "0123456789\t\r\n\f";
    var checkStr = document.tempo.cod.value;
    var allValid = true;
    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
                break;
        if (j == checkOK.length) {
            allValid = false;
            break;
        }
    }
    if (!allValid) {
        alert("Digite sem pontos, traços e sem o DIS do código - ex.: 012345");
        document.tempo.cod.focus();
        return;
    }

    //validacao do campo senha do usuario que não aceita caracteres especiais

    var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\t\r\n\f";
    var checkStr = document.tempo.senha.value;
    var allValid = true;
    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
                break;
        if (j == checkOK.length) {
            allValid = false;
            break;
        }
    }
    if (!allValid) {
        alert("Não é permitido digitar caracteres especiais.");
        document.tempo.senha.focus();
        return;
    }


    if (document.tempo.senha.value.length < 4) {
        alert("A senha deve conter 4 dígitos no mínimo.");
        document.tempo.senha.focus();
        return;
    }

    document.tempo.submit();
}



// *** LOGIN *******************************************

function Enviar() {
    alert('01');
    if (document.confirmacao.codPos.value.length < 6) {
        alert("O Código do Distribuidor deve conter 6 números.");
        document.confirmacao.codPos.focus();
        return;
    }

    //validacao do campo codigo do usuario que só aceita números

    var checkOK = "0123456789\t\r\n\f";
    var checkStr = document.confirmacao.codPos.value;
    var allValid = true;
    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
                break;
        if (j == checkOK.length) {
            allValid = false;
            break;
        }
    }

    alert('02');

    if (!allValid) {
        alert("Digite sem pontos, traços e sem o DIS do código - ex.: 12345");
        document.confirmacao.codPos.focus();
        return;
    }
    alert('03');

    if (!checaCPF(document.confirmacao.cpf.value)) {
        alert("CPF inválido.");
        document.confirmacao.cpf.focus();
        return;
    }

    alert('04');

    if (document.confirmacao.data1.value.length < 1) {
        alert("Informe o dia da data de nascimento.");
        document.confirmacao.data1.focus();
        return;
    }

    alert('05');

    if (document.confirmacao.data2.value.length < 1) {
        alert("Informe o mês da data de nascimento.");
        document.confirmacao.data2.focus();
        return;
    }

    alert('06');

    if (document.confirmacao.data3.value.length < 4) {
        alert("Informe o ano da data de nascimento.");
        document.confirmacao.data3.focus();
        return;
    }

    alert('07');

    var url = ('login_senha_perdida.asp?cod=' + document.confirmacao.codPos.value + '&data1=' + document.confirmacao.data1.value + '&data2=' + document.confirmacao.data2.value + '&data3=' + document.confirmacao.data3.value + '&cpf=' + document.confirmacao.cpf.value + '');

    document.confirmacao.comando.value = 1;
    document.confirmacao.target = "login_senha";
    document.confirmacao.action = url;
    document.confirmacao.submit();

}

function checaCPF(CPF) {
    if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
		        CPF == "22222222222" || CPF == "33333333333" || CPF == "44444444444" ||
		        CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
		        CPF == "88888888888") // || CPF == "99999999999")
    {
        return (false);
    }
    soma = 0;
    for (i = 0; i < 9; i++)
        soma += parseInt(CPF.charAt(i)) * (10 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
        resto = 0;
    if (resto != parseInt(CPF.charAt(9))) {
        return (false);
    }

    soma = 0;
    for (i = 0; i < 10; i++)
        soma += parseInt(CPF.charAt(i)) * (11 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
        resto = 0;
    if (resto != parseInt(CPF.charAt(10))) {
        return (false);
    }
    return (true);
}

function VerificaCampos() {

    //VALIDAÇÃO DOS CAMPOS

    if (document.tempo.cadEmail.value.length < 1) {
        alert("O campo EMAIL não pode estar vazio.");
        document.tempo.cadEmail.focus();
        return;
    }

    if (document.tempo.cadEmail.value.indexOf("@") == -1) {
        alert("EMAIL inválido!");
        document.tempo.cadEmail.focus();
        return;
    }

    document.tempo.submit();

}

function Cadastro() {

    if (document.confirmacao.cod_dist_cad.value.length < 6) {
        alert("O Código do Distribuidor deve conter 6 números.");
        document.confirmacao.cod_dist_cad.focus();
        return;
    }

    //validacao do campo codigo do usuario que só aceita números

    var checkOK = "0123456789\t\r\n\f";
    var checkStr = document.confirmacao.cod_dist_cad.value;
    var allValid = true;
    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
                break;
        if (j == checkOK.length) {
            allValid = false;
            break;
        }
    }
    if (!allValid) {
        alert("Digite sem pontos, traços e sem o DIS do código - ex.: 12345");
        document.confirmacao.cod_dist_cad.focus();
        return;
    }

    if (!checaCPF(document.confirmacao.cpf_cad.value)) {
        alert("CPF inválido.");
        document.confirmacao.cpf_cad.focus();
        return;
    }


    if (document.confirmacao.data1cad.value.length < 1) {
        alert("Informe o dia da data de nascimento.");
        document.confirmacao.data1cad.focus();
        return;
    }
    if (document.confirmacao.data2cad.value.length < 1) {
        alert("Informe o mês da data de nascimento.");
        document.confirmacao.data2cad.focus();
        return;
    }
    if (document.confirmacao.data3cad.value.length < 4) {
        alert("Informe o ano da data de nascimento.");
        document.confirmacao.data3cad.focus();
        return;
    }
    if (document.confirmacao.senha_cad.value.length < 1) {
        alert("Preencha o campo senha.");
        document.confirmacao.senha_cad.focus();
        return;
    }

    if (document.confirmacao.senha_cad2.value.length < 1) {
        alert("Preencha a confirmação da senha.");
        document.confirmacao.senha_cad2.focus();
        return;
    }

    if (document.confirmacao.senha_cad.value != document.confirmacao.senha_cad2.value) {
        alert("Os campos de Senha e Comfirmação não coincidem!.");
        document.confirmacao.senha_cad.value = '';
        document.confirmacao.senha_cad2.value = '';
        document.confirmacao.senha_cad.focus();
        return;
    }
    if (document.confirmacao.perg_secreta_cad.value.length < 1) {
        alert("Preencha a Pergunta Secreta.");
        document.confirmacao.perg_secreta_cad.focus();
        return;
    }
    if (document.confirmacao.resp_secreta_cad.value.length < 1) {
        alert("Preencha a Resposta Secreta.");
        document.confirmacao.resp_secreta_cad.focus();
        return;
    }

    document.confirmacao.comando.value = "Cadastro";
    document.confirmacao.submit();
}

function checaCPF(CPF) {
    if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
			        CPF == "22222222222" || CPF == "33333333333" || CPF == "44444444444" ||
			        CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
			        CPF == "88888888888") // || CPF == "99999999999")
    {
        return (false);
    }
    soma = 0;
    for (i = 0; i < 9; i++)
        soma += parseInt(CPF.charAt(i)) * (10 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
        resto = 0;
    if (resto != parseInt(CPF.charAt(9))) {
        return (false);
    }

    soma = 0;
    for (i = 0; i < 10; i++)
        soma += parseInt(CPF.charAt(i)) * (11 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
        resto = 0;
    if (resto != parseInt(CPF.charAt(10))) {
        return (false);
    }
    return (true);

}

function MM_reloadPage(init) {
    if (init == true) with (navigator) {
        if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {

            document.MM_pgW = innerWidth; document.MM_pgH = innerHeight; onresize = MM_reloadPage;

        }
    }
    else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH) location.reload();
}

MM_reloadPage(true);

function popImg(src, txt) {
    document.tempo.caminho.value = src;
    document.tempo.legenda.value = txt;
    document.tempo.method = 'POST';
    document.tempo.action = "img_destaque.asp";
    janela('img_destaque.asp', 'Destaque', 320, 350, true, 1, 1, 1);
    document.tempo.target = "Destaque";
    document.tempo.submit()
}

function MM_openBrWindow(theURL, winName, features) { //v2.0
    window.open(theURL, winName, features);
}

var isNN = (navigator.appName.indexOf("Netscape") != -1);
function autoTab(input, len, e) {

    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0, 8, 9] : [0, 8, 9, 16, 17, 18, 37, 38, 39, 40, 46];
    if (input.value.length >= len && !containsElement(filter, keyCode)) {
        input.value = input.value.slice(0, len);
        var ob = input.form[(getIndex(input, len) + 1) % input.form.length];
        if (ob.type == 'text' || ob.type == 'button')
            ob.focus();
    }

    function containsElement(arr, ele) {
        var found = false, index = 0;
        while (!found && index < arr.length)
            if (arr[index] == ele)
                found = true;
            else
                index++;
        return found;
    }

    function getIndex(input) {
        var index = -1, i = 0, found = false;
        while (i < input.form.length && index == -1)
            if (input.form[i] == input) index = i;
            else i++;
        return index;
    }
    return true;
}
// *** FIM LOGIN ***************************************

/***************************************************************/
/*		    FUNÇÕES PARA CONTAR NUMERO DE DIAS ENTRE DATAS     */
/***************************************************************/

// Scripts for days between dates
var df = 2; //date format dd/mm/yyyy

//<<**Custom Date object
var GREGORIAN = 0;
var JULIAN = 1;
var year = 0;
var month = 0;
var day = 0;
var julianday = 0.0;
var modifiedjulianday = 0.0;

function ipart(r) { return Math.round(r - 0.5) }
function getJulianDay() { return this.julianday }
function getModifiedJulianDay() { return this.modifiedjulianday }

function CustomDate(yr, mo, da, type) {
    year = yr * 1.0;  //convert string to float
    if (year < -4713 || year > 3268) {
        alert("Year out of range");
        return;
    }
    month = mo * 1.0;
    day = da * 1.0;
    if (year == 1582 && month == 10 && day > 4 && day < 15) {
        alert("Invalid date: 15 Oct immediately followed 4 Oct in the year 1582")
        return;
    }
    if (year < 0) year = year + 1; //B.C. date correction
    var a = ipart((14 - month) / 12);
    var y = year + 4800 - a;
    var m = month + 12 * a - 3;
    if (type == GREGORIAN) {
        julianday = day + ipart((153 * m + 2) / 5) + y * 365 + ipart(y / 4) - ipart(y / 100) + ipart(y / 400) - 32045;
    }
    if (type == JULIAN) {
        julianday = day + ipart((153 * m + 2) / 5) + y * 365 + ipart(y / 4) - 32083;
    }
    modifiedjulianday = julianday - 2400000.5; //Zero at 17 Nov 1858 00:00:00 UTC
    this.getJulianDay = getJulianDay();
    this.getModifiedJulianDay = getModifiedJulianDay();
}
//CustomDate**>>

function fix2DigitDate(dateval) {
    var date = dateval + "" //dateval must be a string
    if (date.length < 3) {
        date = 1900 + date * 1.0
        date = date + ""  //to string
    }
    return date
}

function parseDate(dateval, eraval) {
    var dary = dateval.split("/")
    var era;
    eraval > 0 ? era = -1 : era = 1
    var y = fix2DigitDate(dary[2]) * era
    switch (df) {
        case 1: { m = dary[0]; d = dary[1] } // mm/dd/yyyy
            break;
        case 2: { m = dary[1]; d = dary[0] } // dd/mm/yyyy
            break;
        default: { m = dary[0]; d = dary[1] }
    }
    var calendar
    if (y > 1582) calendar = GREGORIAN
    else if (y < 1582) calendar = JULIAN
    else if (m < 10 | (m == 10 && d < 15)) calendar = JULIAN
    else calendar = GREGORIAN
    i = new CustomDate(y, m, d, calendar)
    return i
} //dateval

//Calculate days between dates	
function calcDBD(strD1, strD2) {
    var err
    var era1 = 0
    var era2 = 0
    var date1 = strD1
    var date2 = strD2
    err = checkdate(date1, era1);
    if (err == 1) return
    err = checkdate(date2, era2);
    if (err == 1) return
    firstdate = parseDate(date1, era1)
    seconddate = parseDate(date2, era2)
    dbd = seconddate.getJulianDay - firstdate.getJulianDay
    return dbd
}

function compararDatas(date1, date2) {
    var data_1 = date1;
    var data_2 = date2;
    var Compara01 = parseInt(data_1.split("/")[2].toString() + data_1.split("/")[1].toString() + data_1.split("/")[0].toString());
    var Compara02 = parseInt(data_2.split("/")[2].toString() + data_2.split("/")[1].toString() + data_2.split("/")[0].toString());
    if (Compara01 > Compara02) {
        return false;
    }
    else {
        return true;
    }
}

//Validate the dates
function checkdate(date, era) {
    var err = 0
    var valid = "0123456789/"
    //var ok = "yes"
    var temp;
    if (date == null || date.length < 1) err = 1 //is there a date?
    //check for invalid characters
    for (var i = 0; i < date.length; i++) {
        temp = "" + date.substring(i, i + 1)
        if (valid.indexOf(temp) == "-1") err = 1
    }
    //split is Javascript 1.2
    dary = date.split("/")
    if (df == 1) {
        b = dary[0] //month
        d = dary[1] //day
    }
    if (df == 2) {
        b = dary[1] //month
        d = dary[0] //day
    }
    f = dary[2] //year
    if (err != 1 && f.length < 3) { //one or two digit date
        f = fix2DigitDate(f) //20th century
        if (era != null && era == 1) {
            err = 1;  //BC years must be 4 digits
            date = date + " B.C."
        }
    }
    if (b < 1 || b > 12) err = 1
    if (d < 1 || d > 31) err = 1
    if (f < 0 || f > 9999) err = 1
    if (b == 4 || b == 6 || b == 9 || b == 11) {
        if (d == 31) err = 1
    }
    if (b == 2) {  //leap year checking
        var g = parseInt(f / 4)
        if (isNaN(g)) err = 1
        if (d > 29) err = 1
        if (d == 29) {
            //leap years are always divisible by 4
            if ((f / 4) != parseInt(f / 4)) err = 1
            //in the Gregorian calendar century years are not leap years unless divisible by 400
            if (f > 1582) {
                if (((f / 100) == parseInt(f / 100)) && (f / 400 != parseInt(f / 400))) err = 1
            }
        }
    }
    return err
} //checkdate

//Get today's date. Date object works ok here.
function enterToday() {
    var today = ""
    var time = new Date()
    var month = time.getMonth() + 1
    var date = time.getDate()
    var year = time.getYear()
    // Y2K Fix by Isaac Powell
    // http://onyx.idbsu.edu/~ipowell
    if ((navigator.appName == "Microsoft Internet Explorer") && (year < 2000))
        year = "19" + year
    if (navigator.appName == "Netscape")
        year = 1900 + year
    if (date < 10) { date = "0" + date }
    if (month < 10) { month = "0" + month }
    //select American or European date format
    df == 1 ? today = month + "/" + date + "/" + year : today = date + "/" + month + "/" + year
    document.datainput.seconddate.value = today
    document.datainput.era2.selectedIndex = 0;
} //enterToday
 

function travaDuploEspaco() {
    var campo = event.srcElement;
    if (campo == null) return false;
    if (campo.tagName != 'INPUT' && campo.tagName != 'TEXTAREA' || campo.value.length < 1) return false;
    ultCharASCII = campo.value.charCodeAt(campo.value.length - 1);
    if (ultCharASCII == 32 && event.keyCode == 32) event.keyCode = 0;
}

function limpaDuploEspaco() {
    var campo = event.srcElement;
    var txtPadrao = "";
    var charAtual, charAnter;
    if (campo == null) return false;
    if (campo.tagName != 'INPUT' && campo.tagName != 'TEXTAREA' || campo.value.length <= 2) return false;
    txtAtual = campo.value.split("");
    for (i = 0; i < txtAtual.length; i++) {
        charAtual = txtAtual[i].charCodeAt(1 - 1);
        charAnter = (i < 1) ? txtAtual[i] : txtAtual[i - 1].charCodeAt(1 - 1);
        if (charAtual != 32) { txtPadrao += txtAtual[i]; } else { if (charAnter != 32) { txtPadrao += txtAtual[i]; } }
    }
    if (campo.value.indexOf("  ") != -1) { campo.value = txtPadrao; }
}

function validarDataRegEx(value) {
    var valid = false;

    // Define uma expressão regular para validar se a data informada está
    // no formato nn/nn/nnnn, onde n é um número entre 0 e 9
    var regex = new RegExp("^([0-9]{2})/([0-9]{2})/([0-9]{4})$");
    var matches = regex.exec(value);

    if (matches != null) {
        var day = parseInt(matches[1], 10);
        var month = parseInt(matches[2], 10) - 1;
        var year = parseInt(matches[3], 10);

        var date = new Date(year, month, day, 0, 0, 0, 0);
        valid = date.getFullYear() == year && date.getMonth() == month && date.getDate() == day;
    }

    return valid;
}

function gera_boleto(id) {

    var parcela
    var dt_venc

    parcela = document.getElementById("parcela_" + id).value;
    dt_venc = document.getElementById("dt_vencimento_" + id).value;
    val_parc = document.getElementById("val_parc_" + id).value;
    val_desc = document.getElementById("val_desc_" + id).value;

    document.getElementById("parcela").value = parcela;
    document.getElementById("dt_vencimento").value = dt_venc;
    document.getElementById("val_parc").value = val_parc;
    document.getElementById("val_desc").value = val_desc;

    f = document.getElementById("tempo");

    f.action = "boleto.asp";
    f.method = "post"; 
    f.submit();

}




/***************************************************************/

