<!-- INI 1: FUNCOES PARA PULAR DE CAMPO (TAB) -->
VerifiqueTAB = false;
function Mostra(quem, tammax) {

    if ( (quem.value.length == tammax) && (VerifiqueTAB) ) {
        var i=0,j=0, indice=-1;
        for (i=0; i<document.forms.length; i++) {
            for (j=0; j<document.forms[i].elements.length; j++) {
                if (document.forms[i].elements[j].name == quem.name) {
                    indice=i;
                    break;
                }
            }

            if (indice != -1)
            break;
        }

        for (i=0; i<=document.forms[indice].elements.length; i++) {
            if (document.forms[indice].elements[i].name == quem.name) {
                while ( (document.forms[indice].elements[(i+1)].type == "hidden") &&
                (i < document.forms[indice].elements.length) ) {
                    i++;
                }

                document.forms[indice].elements[(i+1)].focus();
                VerifiqueTAB=true;
                break;
            }
        }
    }
}

function PararTAB(quem) { VerifiqueTAB=false; }
function ChecarTAB() { VerifiqueTAB=true; }
<!-- FIM 1 -->

<!-- INI 1: Abre janela -->
function openWin(page,width,height) {
    window.open(page, "","width="+ width +",height="+ height +",scrollbars=1,menubar=yes")
}
<!-- FIM 1 -->

<!-- INI 1: Escreve em algum div -->
function divChangeText(divId,text) {
/*    if (document.all) {
        document.all(divId).innerHTML = newText;
    }
    else if (document.layers) {
        with(document.layers[divId].document) {
            clear();
            newText = "<div style='position:absolute;top:0;left:2'>" + newText + "<\div>";
            write(newText);
            close();
        }
    }
    else */

    if (document.getElementById) {
        document.getElementById(divId).innerHTML = text;
    }
}
<!-- FIM 1 -->

<!-- INICIO 1: Mostra iframe -->

var oTimeOut;

function ProcessHiddenAds()  { /* oTimeOut = window.setInterval("CheckAdLoaded()","4000"); */   }

function CheckAdLoaded() {
    try {
        if (document.getElementById('AdPage').style.visibility == 'visible')  { ToggleAd();  ClearAdInterval(); }
        else { ToggleAd(); }

        return;
    }
    catch (exception)  { return; }
}

function ClearAdInterval() {
    try { window.clearInterval(oTimeOut);   }
    catch (exception)  { return; }
}

var page;
function ToggleAd(link,sDisp,height) {
    var sExp='';

    if (!height) { height=200; }

    sDispImg = 'AdPageArrow';

    var text = "<IFRAME frameborder=\"0\" src=\""+ link +"\" width=100% height=100%></IFRAME>";

    try {
        if (document.getElementById(sDisp).style.visibility == 'visible' && page == text) {
            document.getElementById(sDisp).style.height='0';
            document.getElementById(sDisp).style.visibility = 'hidden';
            document.getElementById(sDisp).innerHTML = "";
        }

        else {
            page = text;
            document.getElementById(sDisp).style.height=height;
            document.getElementById(sDisp).style.visibility = 'visible';
            document.getElementById(sDisp).innerHTML = text;
        }
    }
    catch (exception)  {  }
}

/*
var mpr = '[preview]';
var mcpr = '[close preview]';
var psize = '200';


function pv(url, id) {
    if(document.all || document.getElementById) {
        document.write('<a class="opener" href="'+url+'" onClick="pview(this);return false">'+mpr+'</a>');
    }
}

function pview(link) {
    var ie4 = (document.all && !document.getElementById) ? true : false;

    if (ie4 == 1) {
        var iframe = document.all['if'+link.id]; }

    else {
        var iframe = document.getElementById('if'+link.id); }

    if(link.innerHTML == mpr) {

        if(iframe) {
        // should never happen
            iframe.src = link.href;
            iframe.style.height = psize;
            iframe.style.visibility = 'visible';
        }

        else {
            // generate an inline frame containing the link
            myBR = document.createElement('br');
            myBR.setAttribute('id','br'+link.id);
            link.parentNode.appendChild(myBR);
            myIframe = document.createElement('iframe');
            myIframe.setAttribute('security','restricted');
            myIframe.setAttribute('id','if'+link.id);
            myIframe.setAttribute('width','100%');
            myIframe.setAttribute('height',psize);
            myIframe.setAttribute('src',link.href);
            link.parentNode.appendChild(myIframe);
        }

        //link.innerText = mcpr;
        link.innerHTML = mcpr;
    }

    else if(iframe) {
        if (ie4 == 1) {
            myBR = document.all['br'+link.id];
        }
        else {
            myBR = document.getElementById('br'+link.id);
        }

        link.innerHTML = mpr;
        link.parentNode.removeChild(iframe);
        link.parentNode.removeChild(myBR);
    }
}*/

<!-- FIM 1 -->

<!-- INI 1 -->
/* Transforma dados no formato de moeda */
function formatCurrency(num) {
    num = replaceChar(num);
    num = num.toString().replace(/\$|\,/g,'');

    if(isNaN(num)) { num = "0"; }

    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();

    if(cents<10)
        cents = "0" + cents;

//    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
//        num = num.substring(0,num.length-(4*i+3))+','+
//        num.substring(num.length-(4*i+3));
//    }

    return (((sign)?'':'-') + num + '.' + cents);
}
<!-- FIM -->

<!-- INI 1 -->
function replaceChar(entry) {
    out = ","; /* replace this */
    add = "."; /* with this */
    temp = "" + entry; /* temporary holder */

    while (temp.indexOf(out)>-1) {
        pos= temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add +
        temp.substring((pos + out.length), temp.length));
    }
    return temp;
}
<!-- FIM -->

<!-- INI: Verifica codigo -->
// Codel Validation.
function check_code(e) {
    ok = "abcdefghijklmnopqrstuvxzyw1234567890_";

    for(i=0; i < e.length ;i++) {
        if(ok.indexOf(e.charAt(i))<0){
            return false;
        }
    }

    return true;
}
<!-- FIM -->

<!-- INI: Verifica Part Number -->
// PartNumber Validation.
function check_partnumber(e) {
    ok = "1234567890";

    for(i=0; i < e.length ;i++) {
        if(ok.indexOf(e.charAt(i))<0){
            return false;
        }
    }

    return true;
}
<!-- FIM -->

<!-- INI: Verifica email -->
// Email Validation. Written by PerlScriptsJavaScripts.com
function check_email(e) {
    ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

    for(i=0; i < e.length ;i++){
        if(ok.indexOf(e.charAt(i))<0){
            return (false);
        }
    }

//    if (document.images) {
        re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
        re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        if (!e.match(re) && e.match(re_two)) {
            return (-1);
        }
//    }
}
<!-- FIM -->

<!-- INI: Funcao para validar CPF -->
function validaCPF(cpf) {
    erro = new String;
	var cpf = cpf.replace(/\D/g,"");
    if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n";
    var nonNumbers = /\D/;
    if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n";
    if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999") {
        erro += "Numero de CPF invalido!"
    }
    var a = [];
    var b = new Number;
    var c = 11;
    for (i=0; i<11; i++){
        a[i] = cpf.charAt(i);
        if (i < 9) b += (a[i] * --c);
    }
    if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
    b = 0;
    c = 11;
    for (y=0; y<10; y++) b += (a[y] * c--);
    if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
    if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])) {
        erro +="Digito verificador com problema!";
    }
    if (erro.length > 0){
        return false;
    }
    return true;
}

<!-- INI: Funcao para validar CNPJ -->
function validaCNPJ(CNPJ) {
    erro = new String;
    if (CNPJ.length < 14) erro += "Necessario preencher corretamente o numero do CNPJ! \n\n";
/*    if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
        if (erro.length == 0) erro += "Necessario preencher corretamente o numero do CNPJ! \n\n";
    }*/
/*    //substituir os caracteres que não são números
    if(document.layers && parseInt(navigator.appVersion) == 4){
        x = CNPJ.substring(0,2);
        x += CNPJ. substring (3,6);
        x += CNPJ. substring (7,10);
        x += CNPJ. substring (11,15);
        x += CNPJ. substring (16,18);
        CNPJ = x;
    } else {*/
        CNPJ = CNPJ.replace (".","");
        CNPJ = CNPJ.replace (".","");
        CNPJ = CNPJ.replace ("-","");
        CNPJ = CNPJ.replace ("/","");
//    }

    var nonNumbers = /\D/;
    if (nonNumbers.test(CNPJ)) erro += "A verificacao de CNPJ suporta apenas numeros! \n\n";
    var a = [];
    var b = new Number;
    var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
    for (i=0; i<12; i++){
        a[i] = CNPJ.charAt(i);
        b += a[i] * c[i+1];
    }
    if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
    b = 0;
    for (y=0; y<13; y++) {
        b += (a[y] * c[y]);
    }
    if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
    if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
        erro +="Dígito verificador com problema!";
    }

    if (erro.length > 0){
        return false;
    }

    return true;
}

// Fun�es adicionadas por Renato em 09/12/06

String.prototype.trim = function() { return this.replace(new RegExp("^\\s+|\\s+$", "gi"), ""); } // Remove os espa�s em branco no in�io e final de uma string

        // Formata os nmeros digitados de acordo com o documento
        function formatDoc(element,docType) {
            var txt = element.value.replace(/\D/g,"");
            if (element.value.length > 0) {
                switch (docType) {
                    case 'ie':
                        element.value = txt.replace(/(\d\d\d)(\d\d\d)(\d\d\d)(\d\d\d)/, "$1.$2.$3.$4" ); break; 
                    case 'cpf':
                        element.value = txt.replace(/(\d\d\d)(\d\d\d)(\d\d\d)(\d\d)/, "$1.$2.$3-$4" ); break;
                    case 'cnpj':
                        element.value = txt.replace(/(\d\d)(\d\d\d)(\d\d\d)(\d\d\d\d)(\d\d)/, "$1.$2.$3/$4-$5" ); break;
                    case 'cep':
                        element.value = txt.replace(/(\d\d\d\d\d)(\d\d\d)/, "$1$2" ); break;
                    case 'tel':
                        element.value = txt.replace(/(\d?\d\d\d)(\d\d\d\d)/, "$1-$2" ); break;
 				}
            }
        }

		// Aceita somente d�itos
        function checkDigits(e) {
            var tecla = e.keyCode
            if (!(tecla == 46 ||tecla == 8 ||tecla == 9 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 || tecla >= 35 && tecla <= 39)) {
                return false;
            } else { return true; }
        }

<!-- FIM -->

// Luiz Fernando 30/01/2007
// Controle de DIVs
function Hide(string){
    document.getElementById(string).style.display = "none";
}
function Show(string){
    document.getElementById(string).style.display = "";
}
function seeUnsee(string){
    var string = document.getElementById(string);
    if(string.style.display == "")
        string.style.display = "none";
    else{
        string.style.display = "";
    }
}
