var objVeiculos=null;
var vFrmFiltroVeiculo="";

function initVeiculos(data){
   objVeiculos=new Veiculos();
   vFrmFiltroVeiculo=document.frmFiltro;
}

function Veiculos()
{
	this.BASEXML="inc/xml/";
	this.XML="getXMLUTIL.asp";
	this.Categoria='';
	this.Combustivel='';
	this.Ano='';
	this.AnoModelo='';
	this.Cor='';
	this.Lote='';
	this.Retorno=0;
}

Veiculos.prototype.getURL=function(opt)
{ 
	if(opt.toUpperCase()!="NULL")
	{
		var vUrl=this.BASEXML;
		vUrl=vUrl+this.XML;
		vUrl=vUrl+"?dv="+opt+"&"+this.getParametros();
		return vUrl;
	}
}

Veiculos.prototype.getParametros=function()
{
	var pVeiculos="categoria="+this.Categoria+"&combustivel="+this.Combustivel;
	pVeiculos=pVeiculos+"&anom="+this.AnoModelo+"&ano="+this.Ano+"&cor="+this.Cor;
	pVeiculos=pVeiculos+"&lote="+this.Lote+"&Retorno="+this.Retorno+"&rdn="+Math.random();	
	return pVeiculos;
}

Veiculos.prototype.setCategoria=function(value){
	this.Categoria=value;	
}

Veiculos.prototype.setCombustivel=function(value){
	this.Combustivel=value;	
}

Veiculos.prototype.setAno=function(value){
	this.Ano=value;	
}

Veiculos.prototype.setAnoModelo=function(value){
	this.AnoModelo=value;	
}

Veiculos.prototype.setCor=function(value){
	this.Cor=value;	
}

Veiculos.prototype.setLote=function(value){
	this.Lote=value;	
}

function fCombo(varCampoSelecionado,varCampoCarregar){
	var vObj=vFrmFiltroVeiculo.item(varCampoSelecionado);
	var varValor=vObj.options[vObj.selectedIndex].value;
	
	if(vObj.name.toUpperCase()=="TXTCATEGORIAS"){
	   objVeiculos.setCategoria(varValor);
	}
	else if(vObj.name.toUpperCase()=="TXTCOMBUSTIVEL"){
		objVeiculos.setCombustivel(varValor);
	}
	else if(vObj.name.toUpperCase()=="TXTANO"){
		objVeiculos.setAno(varValor);
	}
	else if(vObj.name.toUpperCase()=="TXTANOMODELO"){
		objVeiculos.setAnoModelo(varValor);
	}
	else if(vObj.name.toUpperCase()=="TXTCOR"){
		objVeiculos.setCor(varValor);
	}
	
	if(varCampoCarregar!="0"){
		var vObjLoading=getDiv('dvAguarde');				
		getDados(objVeiculos.getURL(varCampoCarregar),copulaCombo,"xml",vObjLoading);
	}
}

function fComboSel(varCampoSelecionado,varCampoCarregar){
	if(varCampoCarregar!="0"){
		var vObjLoading=getDiv('dvAguarde');				
		getDados(objVeiculos.getURL(varCampoCarregar),copulaCombo,"xml",vObjLoading);
	}
}

function copulaCombo(strXml)
{
	  var varRetorno=strXml.getElementsByTagName("erro")[0].firstChild.nodeValue;
	  var vObj=strXml.getElementsByTagName("div")[0].firstChild.nodeValue;
	  
	  var bSel=false;
	  
	  if(varRetorno=="False") {
		  limpaCombo(vFrmFiltroVeiculo.item(vObj));
		  
		  var dataArray=strXml.getElementsByTagName("registro");		  
		  if(dataArray.length > 0) {
			 for(var i = 0;i < dataArray.length ; i++)
			 {					
			    var varID = dataArray[i].attributes.getNamedItem("id").value;				
				var varValor = dataArray[i].attributes.getNamedItem("text").value;
				var varSel = dataArray[i].attributes.getNamedItem("sel").value;
				if(varSel=="true"){
					bSel=true;	
				}
				addOption(varID,varValor,vFrmFiltroVeiculo.item(vObj),varSel); 
			 }
		 }		
	 }
	 setDiv("dvAguarde","");
	 
	 if(bSel==true){
		if(vObj.toUpperCase()=="TXTCOMBUSTIVEL"){
		   fComboSel('txtCombustivel','txtAno');
		}
		else if(vObj.toUpperCase()=="TXTANO"){
		   fComboSel('txtAno','txtAnoModelo');
		}
		else if(vObj.toUpperCase()=="TXTANOMODELO"){		   
		   fComboSel('txtAnoModelo','txtCor');
		}
	 }
}

function fPesquisarVeiculos(){
	var vForm=vFrmFiltroVeiculo;
	var varCat=vForm.txtCategorias.options[vForm.txtCategorias.selectedIndex].value;	
	var varAno=vForm.txtAno.options[vForm.txtAno.selectedIndex].value;	
	var varAnoModelo=vForm.txtAnoModelo.options[vForm.txtAnoModelo.selectedIndex].value;	
	var varCombustivel=vForm.txtCombustivel.options[vForm.txtCombustivel.selectedIndex].value;	
	var varCor=vForm.txtCor.options[vForm.txtCor.selectedIndex].value;	
	var varLote=vForm.txtLote.options[vForm.txtLote.selectedIndex].value;	
	var varLoteText=vForm.txtLote.options[vForm.txtLote.selectedIndex].index;
		
	if (varLoteText == 1)
	{
		location="veiculosOrdenado.asp";		
	}
	else
	{
	
	objVeiculos.setCategoria(varCat);
	objVeiculos.setCombustivel(varCombustivel);
	objVeiculos.setAno(varAno);
	objVeiculos.setAnoModelo(varAnoModelo);
	objVeiculos.setCor(varCor);
	objVeiculos.setLote(varLote);
	
		location="veiculos.asp?"+objVeiculos.getParametros();
	}
}