
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}



  function MM_openBrWindow(theURL,winName,features) 
{ //v2.0
  window.open(theURL,winName,features);
}

function VoltaVeiculo(cod_veiculo,cod_cliente,cod_veiculo_troca)
   {
   window.opener.location.href=("reg_vendas_trocas_1.asp?cod_veiculo=" + cod_veiculo + "&cod_cliente=" + cod_cliente + "&cod_veiculo_troca=" + cod_veiculo_troca + "&vec_escolhido=SIM");
   window.self.close();
    }

function VoltaVeiculoTroca(cod_veiculo,cod_cliente,cod_veiculo_troca)
   {
   window.opener.location.href=("reg_vendas_trocas_1.asp?cod_veiculo=" + cod_veiculo + "&cod_cliente=" + cod_cliente + "&cod_veiculo_troca=" + cod_veiculo_troca + "&vec_escolhido_troca=SIM");
   window.self.close();
    }

function VoltaVeiculoReserva(link,cod_veiculo)
   {
   window.opener.location.href=(link + "?cod_veiculo=" + cod_veiculo + "&vec_escolhido=SIM");
   window.self.close();
    }

function VoltaClienteReserva(cod_cliente)
   {
   window.opener.location.href=("reservar_veiculo.asp?cod_cliente=" + cod_cliente + "&cli_escolhido=SIM");
   window.self.close();
    }


function formHandler(form){
var URL = document.form.mais_opcoes.options[document.form.mais_opcoes.selectedIndex].value;
window.location.href = URL;
}

function FormataCPF(Campo,teclapres){
	var tecla=teclapres.keyCode;
	var sCaracteres="0123456789";
	var sCaracter=String.fromCharCode(event.keyCode);
	var vr=new String(Campo.value);
	vr=vr.replace(".","");
	vr=vr.replace(".","");
	vr=vr.replace("-","");
	tam=vr.length+1;
	if(tecla !=9 && tecla !=8){
		if(sCaracteres.indexOf(sCaracter)==-1){
			event.returnValue=false;
			return;
		}
		if(tam>3 && tam<7)
			Campo.value=vr.substr(0,3)+'.'+vr.substr(3,tam);
		if(tam>=7 && tam <10)
			Campo.value=vr.substr(0,3)+'.'+vr.substr(3,3)+'.'+vr.substr(6,tam-6);
		if(tam>=10 && tam<12)
			Campo.value=vr.substr(0,3)+'.'+vr.substr(3,3)+'.'+vr.substr(6,3)+'-'+vr.substr(9,tam-9);
	}
}



function FormataCNPJ(Campo,teclapres){
	var tecla=teclapres.keyCode;
	var sCaracteres="0123456789";
	var sCaracter=String.fromCharCode(event.keyCode);
	if(sCaracteres.indexOf(sCaracter)==-1){
		event.returnValue=false;
		return;
	}
	if(event.keyCode==37 || event.keyCode==39 || event.keyCode==16 || event.keyCode==36 || event.keyCode==35){
		event.returnValue=false;
		return;
	}
	var vr=new String(Campo.value);
	vr=vr.replace(".","");
	vr=vr.replace(".","");
	vr=vr.replace("/","");
	vr=vr.replace("-","");
	tam=vr.length+1 ;
	if(tecla !=9 && tecla !=8){
		if(tam>2 && tam<6)
			Campo.value=vr.substr(0,2)+'.'+vr.substr(2,tam);
		if(tam>=6 && tam<9)
			Campo.value=vr.substr(0,2)+'.'+vr.substr(2,3)+'.'+vr.substr(5,tam-5);
		if(tam>=9 && tam<13)
			Campo.value=vr.substr(0,2)+'.'+vr.substr(2,3)+'.'+vr.substr(5,3)+'/'+vr.substr(8,tam-8);
		if(tam>=13 && tam<15)
			Campo.value=vr.substr(0,2)+'.'+vr.substr(2,3)+'.'+vr.substr(5,3)+'/'+vr.substr(8,4)+'-'+vr.substr(12,tam-12);
	}
}
var NUM_DIGITOS_CNPJ=14;
var NUM_DIGITOS_CPF =11;
String.prototype.lpad=function(pSize,pCharPad){
	var str=this;
	var dif=pSize-str.length;
	var ch=String(pCharPad).charAt(0);
	for(;dif>0;dif--)str=ch+str;
	return(str);
}
String.prototype.trim=function(){
	return this.replace(/^\s*/,"").replace(/\s*$/,"");
}




function soNumero(objeto){
	var keypress=event.keyCode;
	var campo=eval(objeto);
	var caracteres='01234567890';
	if((caracteres.indexOf(String.fromCharCode(keypress))!=-1))
		event.returnValue=true;
	else 
		event.returnValue=false;
}


function validaCasasDecimal(objeto,maxlength,casas,valor){
	if((objeto.value.indexOf(',')!=-1))
	{
	if((objeto.value.length-objeto.value.indexOf(','))>casas+1)
		objeto.value=objeto.value.substr(0,objeto.value.length-1);
	}
	else{
		if((objeto.value.length)>=maxlength-(casas+valor))
			objeto.value=objeto.value.substr(0,(maxlength-(casas+valor)));
	}
}

function digitaData(Campo,teclapres){
	var tecla=teclapres.keyCode;
	vr=Campo.value;
	vr=vr.replace(".","");
	vr=vr.replace("/","");
	vr=vr.replace("/","");
	tam=vr.length+1;

	if(tecla !=9 && tecla !=8){
		if(tam>2 && tam<5)
			Campo.value=vr.substr(0,tam-2)+'/'+vr.substr(tam-2,tam);
		if(tam>=5 && tam<=10)
			Campo.value=vr.substr(0,2)+'/'+vr.substr(2,2)+'/'+vr.substr(4,4);}
}
function digitaNumero(){
	var Tecla=window.event.keyCode;
	event.cancelBubble=true;
	if((Tecla>47 && Tecla<58)|| Tecla==13)event.returnValue=true;
	else
		event.returnValue=false;
}

////////////////////////////////////////////////////////////
// Documento Java Script                                  //
// Francisco C Paulino - Tofinha - [EMAIL PROTECTED] //
// 06/11/2002                                             //
////////////////////////////////////////////////////////////

 function FormataReais(fld, milSep, decSep, e) {
 var sep = 0;
 var key = '';
 var i = j = 0;
 var len = len2 = 0;
 var strCheck = '0123456789';
 var aux = aux2 = '';
 var whichCode = (window.Event) ? e.which : e.keyCode;
 if (whichCode == 13) return true;
 key = String.fromCharCode(whichCode);  // Valor para o código da Chave
 if (strCheck.indexOf(key) == -1) return false;  // Chave inválida
 len = fld.value.length;
 for(i = 0; i < len; i++)
 if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != 
decSep)) 
 break;
 aux = '';
 for(; i < len; i++)
 if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += 
fld.value.charAt
 (i);
 aux += key;
 len = aux.length;
 if (len == 0) fld.value = '';
 if (len == 1) fld.value = '0'+ decSep + '0' + aux;
 if (len == 2) fld.value = '0'+ decSep + aux;
 if (len > 2) {
 aux2 = '';
 for (j = 0, i = len - 3; i >= 0; i--) {
 if (j == 3) {
 aux2 += milSep;
 j = 0;
 }
 aux2 += aux.charAt(i);
 j++;
 }
 fld.value = '';
 len2 = aux2.length;
 for (i = len2 - 1; i >= 0; i--)
 fld.value += aux2.charAt(i);
 fld.value += decSep + aux.substr(len - 2, len);
 }
 return false;
 }



/*** 
* Descrição.: formata um campo do formulário de 
* acordo com a máscara informada... 
* Parâmetros: - objForm (o Objeto Form) 
* - strField (string contendo o nome 
* do textbox) 
* - sMask (mascara que define o 
* formato que o dado será apresentado, 
* usando o algarismo "9" para 
* definir números e o símbolo "!" para 
* qualquer caracter... 
* - evtKeyPress (evento) 
* Uso.......: <input type="textbox" 
* name="xxx"..... 
* onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);"> 
* Observação: As máscaras podem ser representadas como os exemplos abaixo: 
* CEP -> 99.999-999 
* CPF -> 999.999.999-99 
* CNPJ -> 99.999.999/9999-99 
* Data -> 99/99/9999 
* Tel Resid -> (99) 999-9999 
* Tel Cel -> (99) 9999-9999 
* Processo -> 99.999999999/999-99 
* C/C -> 999999-! 
* E por aí vai... 
***/

function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
  var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

  if(document.all) { // Internet Explorer
   nTecla = evtKeyPress.keyCode; }
  else if(document.layers) { // Nestcape
   nTecla = evtKeyPress.which;
  }

  sValue = objForm[strField].value;

  // Limpa todos os caracteres de formatação que
  // já estiverem no campo.
  sValue = sValue.toString().replace( "-", "" );
  sValue = sValue.toString().replace( "-", "" );
  sValue = sValue.toString().replace( ".", "" );
  sValue = sValue.toString().replace( ".", "" );
  sValue = sValue.toString().replace( "/", "" );
  sValue = sValue.toString().replace( "/", "" );
  sValue = sValue.toString().replace( "(", "" );
  sValue = sValue.toString().replace( "(", "" );
  sValue = sValue.toString().replace( ")", "" );
  sValue = sValue.toString().replace( ")", "" );
  sValue = sValue.toString().replace( " ", "" );
  sValue = sValue.toString().replace( " ", "" );
  fldLen = sValue.length;
  mskLen = sMask.length;

  i = 0;
  nCount = 0;
  sCod = "";
  mskLen = fldLen;

  while (i <= mskLen) {
   bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
   bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

   if (bolMask) {
    sCod += sMask.charAt(i);
    mskLen++; }
   else {
    sCod += sValue.charAt(nCount);
    nCount++;
   }

   i++;
  }

  objForm[strField].value = sCod;

  if (nTecla != 8) { // backspace
   if (sMask.charAt(i-1) == "9") { // apenas números...
    return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
   else { // qualquer caracter...
    return true;
   } }
  else {
   return true;
  }
 }

VerifiqueTAB=true;
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=false;
          break;
       } 
     } 
   } 
} 

function PararTAB(quem) { VerifiqueTAB=false; } 
function ChecarTAB() { VerifiqueTAB=true; }


<!--
    var visibleVar="null";
    if (navigator.appName == "Netscape") {
                layerStyleRef="layer.";
                layerRef="document.layers";
                styleSwitch="";
                visibleVar="show";
    } else {
                layerStyleRef="layer.style.";
                layerRef="document.all";
                styleSwitch=".style";
                visibleVar="visible";
    }

    function showLayer(layerName){
        eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="'+visibleVar+'"');
    }

    function hideLayer(layerName){
        eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
    }







function Open_Detalhes(cod_veiculo) {
            f_dialogOpen("pop_detalhes.asp?cod_veiculo=" + cod_veiculo, 'popupimg', 'width=770,height=520');
         }

function Open_Proposta(cod_veiculo) {
            f_dialogOpen("pop_proposta.asp?p=1&cod_veiculo=" + cod_veiculo, 'popupimg', 'width=600,height=520');
         }


function Open_Indique(cod_veiculo) {
            f_dialogOpen("pop_indique.asp?p=1&cod_veiculo=" + cod_veiculo, 'popupimg', 'width=600,height=520');
         }

function Open_Imprime(cod_veiculo) {
            f_dialogOpen("pop_imprimir.asp?p=1&cod_veiculo=" + cod_veiculo, 'popupimg', 'scrollbars=yes,width=735,height=520');
         }

function Open_Seguro(cod_veiculo) {
            f_dialogOpen("pop_seguros.asp", 'popupimg', 'width=770,height=520');
         }

function Open_Financiamento(cod_veiculo) {
            f_dialogOpen("pop_financiamento.asp", 'Financiamento', 'scrollbars=yes,width=770,height=520');
         }


function numeros(valor) {
    valorTemp = "";
    for (i = 0; i < valor.length; i++) {
        if (!isNaN(valor.charAt(i)) && valor.charAt(i)
!= '.') {
            valorTemp += valor.charAt(i);
        }
    }
    return valorTemp;
}


/* Recebe como parâmetros um objeto campo e seu valor e o numero de casas decimais.Formata o valor do campo, respeitando as casas decimais necessárias.Deve ser chamada no evento onKeyUp.Ex.: campoValor(campo,"12345678",3) preenche o campo com valor "12.345,678". */

function campoValor(campo,valor,casasDecimais) {
    valor = numeros(valor);
    campo.value = valor;

    if (valor.length >= (casasDecimais + 1)) {
        tamanho = valor.length;
        decimal = "," +
valor.substring(tamanho-casasDecimais,tamanho);
        antes = ((tamanho - casasDecimais) % (3));
        antesString = valor.substring(0,antes);
        vezes = Math.floor((valor.length -
casasDecimais)/3);
        valorTemp =
valor.substring(0,tamanho-casasDecimais);
        if(tamanho == 0) {
            valorFinal = "";
        } else {
            campo.value = "";
            for (i = 0; i < vezes; i++) {
                if (antes != 0 || i > 0) {
                    campo.value = campo.value + "." +
valor.substring(((i*3)+antes),((i*3)+antes+3));
                } else {
                    campo.value = campo.value +
valor.substring(((i*3)+antes),((i*3)+antes+3));
                }
            }
            valorFinal = antesString + campo.value +
decimal;
        }
        campo.value = valorFinal;
    }
}

