function SoNumero(objEvent){
	iKeyCode = objEvent.which;
  	if((iKeyCode>=48 && iKeyCode<=57) || (iKeyCode==8) || (iKeyCode==0)){
		return true;
	}
	else{
		return false;
	}	
}
function Confirm(Mens,Url){
	if(confirm(Mens)){
		window.location.href=Url;	
	}
}
function PulaCampo(Qtde,Campo,Proximo) {
	if (Campo.value.length == Qtde) {		
		document.getElementById(Proximo).focus();
	}
}
function PopUp(Endereco,Largura,Altura,Esquerda,Topo,Scroll,Resize){
	window.open(Endereco,'Janela','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+Scroll+',resizable='+Resize+',top='+Topo+',left='+Esquerda+',width='+Largura+',height='+Altura);return false;marginwidth=0;marginheight=0;
}
function PuxarFotoVeiculo(IdVeiculo,Cont){	
	var req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	var url="foto_veiculo.php?IdVeiculo="+IdVeiculo+"&Cont="+Cont;	
	req.onreadystatechange = function(){		
		if (req.readyState == 4) {			
			if (req.status == 200) {
				document.getElementById('foto_veiculo').innerHTML = req.responseText;				
			}
			else{
				alert("ERRO\n" + req.statusText);
			}
		}
		else{
			document.getElementById('foto_veiculo').innerHTML = "<div align='center'><br /><br /><br /><br /><br /><img src='images/loading.gif'></div>";
		}
	}
	req.open("GET", url, true);
	req.send(null); 
}
function ChamaSelect(Tipo,Id){
	var req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	var url="select_"+Tipo+".php?Id="+Id;	
	req.onreadystatechange = function(){		
		if (req.readyState == 4) {			
			if (req.status == 200) {
				document.getElementById("select_"+Tipo).innerHTML = req.responseText;				
			}
			else{
				alert("ERRO\n" + req.statusText);
			}
		}
		else{
			document.getElementById("select_"+Tipo).innerHTML = "CARREGANDO...";
		}
	}
	req.open("GET", url, true);
	req.send(null); 
}
function Limpar(valor, validos) {
	// retira caracteres invalidos da string
	var result = "";
	var aux;
	for (var i=0; i < valor.length; i++) {
		aux = validos.indexOf(valor.substring(i, i+1));
		if (aux>=0) {
			result += aux;
		}
	}
	return result;
}
function Formata(campo,tammax,teclapres,decimal) {
	var tecla = teclapres.keyCode;
	vr = Limpar(campo.value,"0123456789");
	tam = vr.length;
	dec=decimal
	if (tam < tammax && tecla != 8){ 
		tam = vr.length + 1 ; 
	}
	if (tecla == 8 ){ 
		tam = tam - 1 ; 
	}
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= dec ){ 
			campo.value = vr ; 
		}
		if ( (tam > dec) && (tam <= 5) ){
			campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; 
		}
		if ( (tam >= 6) && (tam <= 8) ){
			campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ;
		}
		if ( (tam >= 9) && (tam <= 11) ){
			campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
		}
		if ( (tam >= 12) && (tam <= 14) ){
			campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
		}
		if ( (tam >= 15) && (tam <= 17) ){
			campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;
		}
	}
}
function PularLinha(Texto,Id){
	var Texto=Texto+"<br />";
	document.getElementById(Id).value=Texto;
}
function ConfCadVeiculo(){
	var Form=document.FormVeiculo;
	var r=Form.Grupo;
	for(var i=0;i<r.length;i++){
		if(r[i].selected){
			var Grupo=r[i].value;
		}
	}
	if(Grupo=="NADA"){
		alert("SELECIONE UM GRUPO");
		Form.Grupo.focus();
	}
	else if(Form.Modelo.value==""){
		alert("INFORME O MODELO");
		Form.Modelo.focus();
	}
	else if(Form.Contato.value==""){
		alert("INFORME A FORMA DE CONTATO");
		Form.Contato.focus();
	}
	else{
		updateRTE('Descricao');
		Form.submit();	
	}
}
function Flash(largura, altura, arquivo,transparente){
	if(transparente=="SIM"){
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+largura+'" height="'+altura+'" style="margin-right:0px;float:left;">');
		document.write('<param name="movie" value="'+arquivo+'" />');
		document.write('<param name="wmode" value="transparent" />');
		document.write('<embed src="'+arquivo+'" wmode="transparent"  quality="hight" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+largura+'" height="'+altura+'"></embed>');
		document.write('</object>');
	}
	else{
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+largura+'" height="'+altura+'" style="margin-right:0px;float:left;">');
		document.write('<param name="movie" value="'+arquivo+'" />');		
		document.write('<embed src="'+arquivo+'" quality="hight" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+largura+'" height="'+altura+'"></embed>');
		document.write('</object>');
	}
}
function ConfBusca(){
	var Form=document.FormBusca;
	if(Form.Modelo.value==""){
		alert("INFORME O MODELO");
		Form.Modelo.focus();
	}
	else if(Form.AnoIni.value==""){
		alert("INFORME O ANO");
		Form.AnoIni.focus();
	}
	else if(Form.AnoFim.value==""){
		alert("INFORME O ANO");
		Form.AnoFim.focus();
	}
	else{
		Form.submit();	
	}
}