function valSenha(campo1, campo2, msg) {
    if (campo1.value != campo2.value) {
        if (msg)
            alert(msg);
        campo2.focus();
        return false;
    }
    return true;
}

function testaRadio(obj) {
    for (x1=0; x1<obj.length; x1++)
        if (obj[x1].checked)
            return true;
    return '';
}

function tiraEspaco(value) {
    while (value.indexOf(" ") != -1) {
        value = value.replace(" ", "");
    }
    return(value);
}

function validar() {
    result = true;
    var campoFoco = '';

    for (x = 0; x < this.campos.length; x++) {
        if (this.campos[x].length > 0) {
            try {
                if (this.campos[x].type.toLowerCase()=='select-one') {
                    if ((!this.campos[x].value) || (tiraEspaco(this.campos[x].value)=="//")) {
                        this.msg+=this.caption[x] + '\n';
                        result = false;
                    }
                }
            }
            catch (e) {
                if (this.campos[x][0].type.toLowerCase()=='radio'){
                    if (!testaRadio(this.campos[x])) {
                        this.msg+=this.caption[x] + '\n';
                        result = false;
                    }
                }
            }
        }
        else
        if (this.campos[x].type.toLowerCase()=='checkbox') {
            if (!this.campos[x].checked) {
                this.msg+=this.caption[x] + '\n';
                result = false;
            }
        }
        else {
            if ((!this.campos[x].value) || (tiraEspaco(this.campos[x].value)=="//")) {
                this.msg+=this.caption[x] + '\n';
                result = false;
            }
            else 
            if (parseFloat(strToFloat(this.campos[x].value)) <= 0) {
                this.msg+=this.caption[x] + '\n';
                result = false;
            }
        }

        if (!result) {
            if (!campoFoco) {
                try {
                    campoFoco = this.campos[x]; 
                    campoFoco.focus();
                }
                catch (e) {
                }
            }
        }
    }
    if (!result)
        alert(this.msg);
    return result;
}

function addCampo(obj, caption) {
    this.campos[this.campos.length] = obj;
    this.caption[this.caption.length] = caption;
}

function setCheckBox(obj, value) {
    checkObj(obj, value, 'checkbox');
}

function checkObj(obj, value, type) {
    for (x = 0; x < obj.length; x++) {
        if (obj[x].value == value) {
            obj[x].checked = true;

            if (type == 'radio')
                obj[x].click();

            return true;
        }
    }
    return false;
}

function formatFloat(value) {
    if (value == 0)
        return "0,00";
    value = value.toString();

    if (value == parseFloat(value)) {
        value = strReplace(value, ".", ",");
    }
    else {
        value = strReplace(value, ".", "");
    }

    Dec = '00';
    Int = '0';
    if (value.indexOf(',') != -1) {
        Int = value.substring(0, value.indexOf(','));
        Dec = value.substring(value.indexOf(',') + 1);
    }
    else {
        Int = value;
    }


    if (Dec.length > 2) {
        Dec = Dec.substring(0, 2);
    }
    else {
        while (Dec.length < 2)
            Dec += '0';
    }

    Int = (Int*1);
    Int = Int.toString();
    aux = '';
    for (x = 1 ; x <= Int.length; x++) {
        sep = (((x % 3) == 0) && (x != Int.length))?'.':'';
        aux = sep + (Int.substring(Int.length - x, Int.length - x+1)) + aux;
    }
    Int = aux;

    return (Int + ',' + Dec);
}

function strToFloat(value) {
    value = strReplace(value, ".", "");
    value = (strReplace(value, ",", ".")*1);
    return value;
}

function floatToStr(value) {
    return formatFloat(strReplace(value, ".", ","));
}

function strReplace(value, antStr, newStr) {
    value = value.toString();
    while (value.indexOf(antStr) != -1) {
        value = value.replace(antStr, newStr);
    }
    return value;
}

function dataextenso(dia) {
    days = new Array(7)
    days[1] = "Domingo";
    days[2] = "Segunda";
    days[3] = "Terça"; 
    days[4] = "Quarta";
    days[5] = "Quinta";
    days[6] = "Sexta";
    days[7] = "Sabado";

    months = new Array(12)
    months[1] = "Janeiro";
    months[2] = "Fevereiro";
    months[3] = "Março";
    months[4] = "Abril";
    months[5] = "Maio";
    months[6] = "Junho";
    months[7] = "Julho";
    months[8] = "Agosto";
    months[9] = "Setembro";
    months[10] = "Outubro"; 
    months[11] = "Novembro";
    months[12] = "Desembro";
    today = new Date(); 

    day   = days[today.getDay() + 1]
    month = months[today.getMonth() + 1]
    date  = today.getDate()
    year  =today.getYear();
    if (year < 2000)
        year = year + 1900;
    if (!dia)
        return (date +' de ' + month + " de " + year);
    else
        return (day + ", " +date +' de ' + month + " de " + year);  
}

function deixanumero(Data) {
    val='';
    for (x=0; x<Data.length; x++) {
        if (Data.substring(x,x+1)!='/' && Data.substring(x,x+1)!='-' && Data.substring(x,x+1)!='.')
        val+=Data.substring(x,x+1);
    }
    return(val)
}

function inverte(Data) {
    deixanumero(Data);
    val=val.substring(2,3)+val.substring(3,4)+'/'+
    val.substring(0,1)+val.substring(1,2)+'/'+
    val.substring(4,5)+val.substring(5,6)+val.substring(6,7)+val.substring(7,8);
    return(val);
}

function ShowTodayDate(Data) {
    Data=inverte(Data);
    now = new Date(Data);
    dia = now.getDate();
    mes = now.getMonth() + 1;
    ano = now.getFullYear();
    if (dia < 10)
        dia = "0" + dia
    if (mes < 10)
        mes = "0" + mes
    if (ano < 2000)
        ano = "19" + ano
    return(dia+"/" +mes+ "/" +ano)
}


function testadata(obj) {
    if(obj.value.length>0)
        if (deixanumero(obj.value) != deixanumero(ShowTodayDate(obj.value))) {
            alert('Data Inválida!' + ' ' + deixanumero(obj.value) + ' - ' + deixanumero(ShowTodayDate(obj.value)));
            obj.focus();
            obj.select();
        }
    else
        obj.value=ShowTodayDate(obj.value);
}

function testadata_(obj) {
    obj.value=deixaSoNumero(obj.value);
    if(obj.value.length>0) {
        if(obj.value.length>8) {
            obj.value=obj.value.substring(0,8);
        }
        if (obj.value!=deixaSoNumero(ShowTodayDate(obj.value))) {
            alert('Data Inválida!');
            obj.focus();
            obj.select();
        }
        else
            obj.value=ShowTodayDate(obj.value);
    }
    else
    obj.value='   /   /';
}


function TDate(name){
    document.write('<INPUT TYPE="text" NAME="'+name+'" onBlur="testadata(this);" maxlength="10" size="10">');
}

function tCpf(name, param) {
    document.write("<input type='text' name='"+name+"' "+param+" maxlength='15' OnBlur='onExitCPF(this)' onkeypress='return validaTecla(this, event)' onfocus='this.value=deixaSoNumero(this.value);this.select();' class='inputnor'>");
}

function tDate(name, param) {
    document.write('<INPUT TYPE="text" NAME="'+name+'" '+param+' onkeypress=\"return validaTecla(this, event)\" onBlur="testadata(this);" maxlength="10" class=form145 onfocus="this.value=deixaSoNumero(this.value); this.select();" value="   /   /">');
}

function tCep(name, param) {
    document.write("<input type=\"text\" size=\"12\" maxlength=\"10\" name=\""+name+"\" "+param+" class=form OnBlur=\"formataCEP(this)\" onkeypress=\"return validaTecla(this, event)\" onFocus=\"this.value = deixaSoNumero(this.value); this.select();\">");
}

function tCnpj(name) {
    document.write("<input type=\"text\" class='inputnor' name=\""+name+"\" size=\"22\" maxlength=\"14\" class=form OnBlur=\"onExitCNPJ(this)\" onkeypress=\"return validaTecla(this, event)\" onfocus=\"this.value=deixaSoNumero(this.value);this.select();\">");
}

function tInteiro(name, param) {
    document.write('<INPUT TYPE="text" NAME="'+name+'" '+param+' onkeypress=\"return validaTecla(this, event)\"  maxlength="8" size="10" class=form onfocus="this.select();">');
}

function tEdit(name, param) {
    if (!param)
        param='size=10 maxlenght=10';
    document.write('<INPUT TYPE="text" NAME="'+name+'" '+param+' class=form>');
}

function tPassword(name, param) {
    if (!param)
        param='size=8 maxlenght=8';
    document.write('<INPUT TYPE="password" NAME="'+name+'" '+param+' class=form>');
}

function tSpace(width) {
    document.write('<div style="display:inline; width:'+width+'"></div>');
}

function tCpfCnpj(name, param) {
    document.write("<input type=\"text\" name=\""+name+"\" size=\"18\" maxlength=\"14\" "+param+" class=form OnBlur=\"testaTipo(this)\" onkeypress=\"return validaTecla(this, event)\" onfocus=\"this.value=deixaSoNumero(this.value);this.select();\">");
}

function tDecimal(name, param) {
    document.write('<INPUT TYPE="text" NAME="'+name+'" '+param+' onkeypress=\"return validaTecla(this, event, \'.\')\"  maxlength="8" size="10" class=form onfocus="this.select();">');
}

function tLabel(name, vcaption, width, param) {
    document.write('<INPUT TYPE="text" NAME="'+name+'" value="'+vcaption+'" '+param+' style="border:0;text-align:right;width:'+width+'" class=form onfocus="this.select();" TABINDEX=-1 readonly>');
}

function tCheckbox(name, param) {
    document.write("<input type=\"Checkbox\" NAME=\""+name+"\" \""+param+"\">");
}

function tEmail(name, param) {
    if (!param)
        param='size=10 maxlenght=10';
    document.write('<INPUT TYPE="text" NAME="'+name+'" '+param+' class=form onblur="valida_email(this)">');
}

function tPlaca(name, param) {
    document.write("<input type=\"text\" NAME=\""+name+"\" \""+param+"\" class=form onblur=\"validaPlaca(this)\" maxlength=7 size=10>");
}

function validaPlaca(obj) {
    var str, certo;
    certo=true;
    if (!obj.value)
        return false;

    if (obj.value.length<7) {
        alert('Placa inválida!');
        obj.focus();
        obj.select();
        return false;
    }
    str=obj.value.toUpperCase();
    for (x=0; x<7; x++) {
        if (x<3) {
            if (str.charAt(x)<'A' || str.charAt(x)>'Z' || str.charAt(x)==' ') {
                certo=false;
                break;
            }
        }
        else {
            if (str.charAt(x)<'0' || str.charAt(x)>'9' || str.charAt(x)==' ') {
                certo=false;
                break;
            }
        }
    }
    if (!certo) {
        alert('Placa inválida!');
        obj.focus();
        obj.select();
        return false;
    }
    obj.value=str;
}

function valKey(event) {
    var tecla;

    if (navigator.appName.indexOf("Netscape")!= -1)
        tecla = event.which;
    else
        tecla = event.keyCode;

    key = String.fromCharCode(tecla);
    if (tecla == 13)
        return false;

    switch (tecla) {
        case 0: 
        case 8: 
        return true;
        break;
    }
    //return((parseInt(key) == key)?true:false);
    return (parseInt(key) == key);
}
  
function sohNum(value) {
    var re = new RegExp('[^0-9]+', "ig");
    while (re.test(value)) {
        value = value.replace(/[^0-9]+/, "");
    }
    return value;
}

function FormataCPF(obj) {
    obj.value=
    obj.value.substring(0,3) + '.' +
    obj.value.substring(3,6) + '.' +
    obj.value.substring(6,9) + '-' +
    obj.value.substring(9,11);
}

function valida_CPF(obj) {
    s=obj.value;
    var varFirstChr = s.charAt(0);
    var vaCharCPF = false;
    soma=0;
    for ( i=0; i<9; i++ ) {
        soma += (10-i) * ( eval(s.charAt(i)) );
    }
    digito_verificador = 11-(soma % 11);
    if ((soma % 11) < 2)
       digito_verificador = 0;
    if ( eval(s.charAt(9)) != digito_verificador ) {
        alert("CPF inválido!");
        return false;
    }

    soma=0;
    for ( i=0; i<9; i++ ) {
        soma += (11-i) * ( eval(s.charAt(i)) );
    }
    soma += 2 * ( eval(s.charAt(9)) );
    digito_verificador = 11-(soma % 11);
    if ((soma % 11) < 2)
        digito_verificador = 0;
    if ( eval(s.charAt(10)) != digito_verificador ) {
        alert("CPF inválido!");
        return false;
    }
    return true;
}
  
function exitCpf(obj) {
    if (obj.value)
        if (!valida_CPF(obj.value))
            obj.focus();
        else
            obj.value = formataCpf(obj.value);
}
  
function setBG(obj) {
        obj.style.backgroundImage = 'url(http://www.placasnet.com.br/2006/img/mn_divisao.gif)';
}

function clearBG(obj) {
        obj.style.backgroundImage = '';
}

function findObj(n, d) { //n4 - n6 - ie5 - opera
    if (window.mmIsOpera)
        return (document.getElementById(n));

    if (document.all)
        return (document.all[n]);

    if (document.getElementById) {
        if (document.getElementById(n))
            return (document.getElementById(n));
    }

    if (document.getElementsByName) {
        if (document.getElementsByName(n)[0])
            return document.getElementsByName(n)[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];

    return x;
}

function findObj(n) {
    if (document.getElementsByName(n).length > 1)
        return document.getElementsByName(n);
    else
    if (document.getElementsByName(n)[0])
        return document.getElementsByName(n)[0];
    else
    if (document.getElementById(n))
        return document.getElementById(n);
}

function target(page) {
    findObj("iframeconteudo").src="corpo.php?pagina=" + page;
}

function onExitCPF(obj) {
    obj.value=deixaSoNumero(obj.value);
    if (obj.value.length>0)  {
        zero = '00000000000';
        obj.value = zero.substring(0, 11 - obj.value.length) + obj.value;        
        
        var valido = valida_CPF(obj);
        if (valido) {
            FormataCPF(obj);
        }
        else {
            obj.select();
            obj.focus();
        }
    }
}

function validaTecla(campo, event) {
    var BACKSPACE = 8;
    var TAB = 0;
    var key;
    var tecla;
    CheckTAB = true;
    if (navigator.appName.indexOf("Netscape")!= -1)
        tecla = event.which;
    else
        tecla = event.keyCode;
    key = String.fromCharCode(tecla);
    if (tecla == 13)
        return false;
    else
    if (tecla == BACKSPACE)
        return true;
    else
    if (tecla == TAB)
        return true;
    else
        return (isNum(key));
}

function deixaSoNumero(Data) {
    val = '';
    for (x = 0; x < Data.length; x++) {
        if (Data.charAt(x)=='0')
            val+=Data.charAt(x);
        else
            if (parseInt(Data.charAt(x)))
        val+=Data.charAt(x);
    }
    return(val)
}

function isNum(caractere) {
    var strValidos = "0123456789"
    if (strValidos.indexOf(caractere) == -1)
        return false;
    return true;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
    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();
}

function ajustaFr() {
    findObj('fr_aniver').height = fr_aniver.document.body.scrollHeight;
}

function ajustaFrame(doc) {
    findObj('fr_conteudo').style.height = doc.body.scrollHeight;
}

function showPesq(type, objName, iWidth, frame, msg, funcRetorno) {
    obj = findObj(objName);

    jaPesquisou = eval('jaPesquisou_' + objName);

    host = location.protocol + '//' + location.host + '/2004/';

    if (obj.value) {
        if (frame && (!jaPesquisou)) {
            frame = findObj('fr_' + objName);
            frame.src =  host + 'pesquisa.php?type=' + type + '&argumento=' + obj.value + '&frame=sim' + '&objName=' + objName + '&msg=' + msg + '&funcRetorno=' + funcRetorno;
        }
        else
        if (!frame) {
            iHeight = 400;
            w = wOpen(host + 'pesquisa.php?type=' + type + '&argumento=' + obj.value + '&objName=' + objName + '&msg=' + msg + '&funcRetorno=' + funcRetorno, 'pesquisa', iWidth, iHeight);
            w.focus();
        }
        eval('jaPesquisou_' + objName + '=true');
        return;
    }
    else
    if (!obj.value) {
        if (!frame) {
            alert('Digite algo para fazer a busca!!');
        }
        eval('jaPesquisou_' + objName + '=false');
    }
}

function wOpen(page, name, iWidth, iHeight, scroll) {
    if (!scroll)
        scroll = 1;
    iWidth=(!iWidth)?590:iWidth;
    iHeight=(!iHeight)?550:iHeight;

    vTop=((window.screen.availHeight/2)-(iHeight/2));
    vLeft=((window.screen.availWidth/2)-(iWidth/2));
    return window.open(page, name, "height="+iHeight+"; width="+iWidth+"; slocation=0, scrollbars=" + scroll + ", status=0, left="+vLeft+", top="+vTop+"");
}

function explode(sep, value) {
    var arr = new Array();
    index = -1;

    while (value.indexOf(sep) != -1) {
        index++;
        arr[index] = value.substring(0, value.indexOf(sep));
        value = value.substring(value.indexOf(sep) + sep.length);
    }
    index++;

    if (value)
        arr[index] = value;

    return arr;
}

function testFloat(obj) {
    if (!obj.value)
        return;

    val2 = strToFloat(obj.value);
    val1 = parseFloat(val2)
    if ((val1*1) != (val2*1)) {
        alert("Valor inválido!")
        obj.focus();
        obj.select();
    }
}

function setRadio(obj, value) {
    checkObj(obj, value, 'radio');
}

function ME_cBrowser(){
    this.ie=false;
    this.ns7=false;
    if (window.navigator.appName == 'Microsoft Internet Explorer')
        this.ie=true;
    else
    if (window.navigator.appName == 'Netscape')
        this.ns7=true;
}

g=new ME_cBrowser();

function titulo(tit) {
    document.write('<B><FONT COLOR="#ffffff" id=titulo_'+tit+'>'+tit+'</FONT></B>');
}

function valida_senha(campo1, campo2, status, mensagem) {
    if (campo1.value == campo2.value) {
        status.innerHTML = "";
        return true;
    }
    else {
        status.innerHTML = "<HR><font color=\"#FF0000\"><b>" + mensagem + "</b></font>";
        return false;
    }
}

function valida_email(obj) {
    email=obj.value;
    if (email) {
        if (email.indexOf("@")<=0 || email.indexOf(".")<=0 ||
        (email.indexOf("@")==email.length-1) ||
        (email.indexOf(".")==email.length-1) ||
        (email.indexOf("@")==(email.indexOf(".", email.indexOf("@")+1)-1)) ||
        (email.indexOf(".")==(email.indexOf("@", email.indexOf(".")+1)-1)) ||
        (email.indexOf("@")==(email.indexOf("@", email.indexOf("@")+1)-1)) ||
        (email.indexOf(".")==(email.indexOf(".", email.indexOf(".")+1)-1)) ||
        (email.indexOf(".", email.indexOf(".")+1)==(email.indexOf("@", email.indexOf(".")+1)-1))) {
            alert("Favor digitar um e-mail válido.");
            obj.focus();
            obj.select();
        }
    }
}

function FormataCNPJ(el) {
    vr = deixaSoNumero(el.value);
    tam = vr.length;
    if (tam == 14) {
        el.maxlength="18";
        if (tam <= 2)
            el.value = vr;
        if ((tam > 2) && (tam <= 6))
            el.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
        if ((tam >= 7) && (tam <= 10))
            el.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(5, 3) + '/';
        if ((tam >= 11) && (tam <= 18))
            el.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(5, 3) + '/' + vr.substr(8, 4) + '-' + vr.substr(12, 2);
    }
    else {
        if (tam > 0) {
            alert("Voce deve digitar 14 posições!");
            el.focus();
            el.select();
        }
    }
    return true;
}

function validaRenavam(obj) {
    if(obj.value.length > 0) {
        if (!Modulo11(obj)) {
            alert('RENAVAM Inválido!!');
            obj.focus();
            return false;
        }
        return true;
    }
}

function Modulo11(obj) {
    var iPeso, iSoma, iResto, Aux;
    iPeso = 2;
    iSoma = 0;
    szValue=obj.value;
    var szValueAux = new String(szValue.substring(0, szValue.length-1));
    var tam = szValueAux.length;
    tam = parseInt(tam,10)-1;
    for(i=parseInt(tam,10); i>=0; i--) {
        Aux = szValue.substr(i, 1);
        iSoma = parseInt(iSoma,10) + ( parseInt(Aux,10) * iPeso);
        if( iPeso == 9 )
        iPeso = 2;
        else
        iPeso+= 1;
    }
    iResto = iSoma % 11
    if( iResto == 0 || iResto == 1 )
    iResto = 0;
    else
    iResto = 11 - parseInt(iResto,10);

    if (szValue.substring(szValue.length-1,szValue.length) != iResto)  {
        //alert('Dígito verificador inválido!');
        //obj.focus();
        //obj.select();
        return false;
    }
    return true;
}

function CriaModulo11(cod) {
    var iPeso, iSoma, iResto, Aux;
    iPeso = 2;
    iSoma = 0;
    szValue=cod;
    var szValueAux = new String(szValue.substring(0, szValue.length));
    var tam = szValueAux.length;
    tam = parseInt(tam,10)-1;
    for(i=parseInt(tam,10); i>=0; i--) {
        Aux = szValue.substr(i, 1);
        iSoma = parseInt(iSoma,10) + ( parseInt(Aux,10) * iPeso);
        if( iPeso == 9 )
        iPeso = 2;
        else
        iPeso+= 1;
    }
    iResto = iSoma % 11
    if( iResto == 0 || iResto == 1 )
    iResto = 0;
    else
    iResto = 11 - parseInt(iResto,10);

    return cod+iResto;
}

function formataCEP(el) {
    vr = deixaSoNumero(el.value);
    tam = vr.length;
    if (tam == 8) {
        el.maxlength="10";
        if (tam <= 2)
            el.value = vr;
        if ((tam > 2) && (tam <= 8))
            el.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '-' + vr.substr(5, 3);
    }
    else {
        if (tam > 0) {
            alert("Voce deve digitar 8 posições!");
            el.focus();
            el.select();
        }
    }
    return true;
}

function formataHora(el) {
    vr = deixaSoNumero(el.value);
    tam = vr.length;
    if (tam == 4) {
        el.maxlength="4";
        if (tam <= 2)
            el.value = vr;
        if ((tam > 2) && (tam <= 8))
            el.value = vr.substr(0, 2) + ':' + vr.substr(2, 2) + ':00' + vr.substr(4, 2);
    }
    return true;
}

function onExitCNPJ(objeto) {
    objeto.value=deixaSoNumero(objeto.value);
    if (objeto.value.length>0)  {
        var valido = valida_CGC(objeto);
        if (valido) {
            FormataCNPJ(objeto);
        }
    }
}

function valida_CGC(obj) {
    // verifica o tamanho
    pcgc = obj.value;
    if (pcgc.length<14 && pcgc.length>0) {
        alert ("Tamanho Invalido de CNPJ");
        obj.focus();
        obj.select();
        return false;
    }
    else  {
        sim=true
    }
    if (sim )  { // verifica se e numero
        for (i=0;((i<=(pcgc.length-1))&& sim); i++)  {
            val = pcgc.charAt(i)
            // alert (val)
            if ((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4") &&
            (val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {
                sim=false
            }
        }
        if (sim) {// se for numero continua
            m2 = 2
            soma1 = 0
            soma2 = 0
            for (i=11;i>=0;i--) {
                val = eval(pcgc.charAt(i));
                // alert ("Valor do Val: "+val)
                m1 = m2;
                if (m2<9) {
                    m2 = m2+1;
                }
                else {
                    m2 = 2;
                }
                soma1 = soma1 + (val * m1);
                soma2 = soma2 + (val * m2);
            }  // fim do for de soma

            soma1 = soma1 % 11;
            if (soma1 < 2) {
                d1 = 0;
            }
            else {
                d1 = 11- soma1;
            }
            soma2 = (soma2 + (2 * d1)) % 11;
            if (soma2 < 2) {
                d2 = 0;
            }
            else {
                d2 = 11- soma2;
            }
            if ((d1==pcgc.charAt(12)) && (d2==pcgc.charAt(13)))  {
                sim=true;
            }
            else
                sim=false;
        }
    }
    if (!sim) {
        alert('CNPJ Inválido!');
        obj.focus();
        obj.select();
    }
    else
        return true;
}

function maxLength(obj, ev, size) {
    if (obj.value.length>=size) {
        ev.keyCode=0;
    }
}

function tIniFieldSet(name, legend, param) {
    if (!param)  {
        param="width='100%'";
    }
    document.write("<TABLE id='"+name+"' class=arial12 cellpadding=0 cellspacing=0 border=0 "+param+" style='border:1px solid #000000'><TR><TD><div style='position:relative;background:white;top:-8;left:4;display:inline'><I>"+legend+"</I></div><br>");
}

function tFimFieldSet() {
    document.write("</TD></TR></TABLE><br>");
}

function tFoto(name, src, vWidth) {
    image="";
    vHeight=(vWidth*4)/3;
    if (src)
        document.write("<img src='"+src+"' id='"+name+"' border=1 width="+vWidth+" height="+vHeight+">");
    else
        document.write("<table cellpadding=0 cellspacing=0 border=0 style='border:1px solid #000000' width="+vWidth+" height="+vHeight+"><tr><td align=center>Foto não disponível</td><tr></table>");
}

function BR() {
    document.write("<BR>");
}

function testaTipo(obj) {
    if (obj.value.length>0) {
        if (obj.value.length==11)
            onExitCPF(obj);
        else
        if (obj.value.length==14)
            onExitCNPJ(obj);
        else {
            alert('Dígito Inválido!')
            obj.select();
        }
    }
}

function bomDia() {
    var now = new Date();
    var mess="";
    if (now.getHours() < 12)
        mess = "Bom Dia";
    else
    if (now.getHours() < 18)
        mess = "Boa Tarde";
    else
    if (now.getHours() < 24)
        mess = "Boa Noite";
    document.write(mess);
}

function property(obj, obj_name) {
    var result = "";
    for (var i in obj) {
        try {
            document.write(obj.tagName + "." + i + " = " + obj[i] + "<br>");
        }
        catch(e) {
            document.write("erro!"+e+"<br>");
        }
    }
    return true;
}

function strReplace(value, antStr, newStr) {
    value = value.toString();
    while (value.indexOf(antStr) != -1) {
        value=value.replace(antStr, newStr);
    }
    return value;
}

function limpaForm(form) {
    with (form) {
        reset();
        for (x = 1; x < form.length; x++) {
            try {
                compo=form[x].type.toLowerCase();
                if ((compo=='text') || (compo=='textarea')) {
                    if ((compo=='text') && (strReplace(form[x].value, ' ','')=='//')) {
                        form[x].value=form[x].value;
                        form[x].readOnly=false;
                    }
                    else {
                        form[x].value='';
                        form[x].readOnly=false;
                    }
                }
                else
                if ((compo=='button') || (compo=='submit')) {
                    form[x].disabled=false;
                }
            }
            catch (e) {
            }
        }
    }
}