<!--

function item(COD,VALUE,RELATION) {
  		 this.COD = COD;
  		 this.VALUE = VALUE;
  		 this.RELATION = RELATION;
}  
  
function buscar(destino,fonte,valor,select) {
  destino.length = 1; 
  x = 0;
  sel = 0; 
  for (i = 0; i < fonte.max; i++)
  { if (fonte[i].COD == 0 & fonte[i].RELATION == '')
    { } else
    { if (fonte[i].RELATION == valor | fonte[i].RELATION == 0)
      { destino.options[x] = new Option(fonte[i].VALUE,fonte[i].COD); x++; }
      if (fonte[i].COD == select) { sel = (x-1); }
    }  
  }
  destino.options[sel].selected=true;
}

function checkcampos(form) {
    var erro_string = "";  
    if (form.codmarca.options[form.codmarca.options.selectedIndex].value == 0) { erro_string += "Selecione uma Marca \n"; }
    if (form.codmodelo.options[form.codmodelo.options.selectedIndex].value == 0) { erro_string += "Selecione um Modelo \n"; }
    if (form.valorini.value != "R$ de" & form.valorfin.value != "R$ até" & form.valorini.value != "" & form.valorfin.value != "") 
    { erro_string = ""; 
    }
    if (erro_string != "") { erro_string += "\n                OU                \n\n Digite valores Iniciais e Finais para uma busca por valor \n "; }
    if (erro_string == "") { return true; } else { alert(erro_string); return false; }
}

function checkcampos2(form) {
    var erro_string = "";  
    if (form.codrevenda.options[form.codrevenda.options.selectedIndex].value == 0) { erro_string += "Selecione uma Revenda \n"; }    
    if (erro_string == "")
    { return true;
    } else { alert(erro_string); return false; }    
}

function checkcampos3(form) {
    var erro_string = "";  
    if (form.codcategoria.options[form.codcategoria.options.selectedIndex].value == 0) { erro_string += "Selecione uma Categoria \n"; }    
    if (erro_string == "")
    { return true;
    } else { alert(erro_string); return false; }    
}

function ir(form) { form.submit(); }
function ir2(form) 
{ if (vermarcados()) { form.submit(); }
}

function addIEFavorite() { 
   if (window.external) { external.AddFavorite(location.href, 'VeiculosBR'); }
   else {
      alert("Seu navegador não suporta essa função.\n" +
      "Se você está usando o Netscape Navigator, clique em Bookmarks\n" +
      "e depois em Add Bookmark para colocar esse site na sua lista de favoritos.");
      }
}
        hoje = new Date()
        dia = hoje.getDate()
        dias = hoje.getDay()
        mes = hoje.getMonth()
        ano = hoje.getYear()
        if (dia < 10) dia = "0" + dia
        if (ano < 2000) ano = 1900 + ano

        function CriaArray (n) { this.length = n }
        NomeDia = new CriaArray(7)
        NomeDia[0] = "Domingo"
        NomeDia[1] = "Segunda-feira"
        NomeDia[2] = "Ter&ccedil;a-feira"
        NomeDia[3] = "Quarta-feira"
        NomeDia[4] = "Quinta-feira"
        NomeDia[5] = "Sexta-feira"
        NomeDia[6] = "S&aacute;bado"

        NomeMes = new CriaArray(12)
        NomeMes[0] = "Janeiro"
        NomeMes[1] = "Fevereiro"
        NomeMes[2] = "Mar&ccedil;o"
        NomeMes[3] = "Abril"
        NomeMes[4] = "Maio"
        NomeMes[5] = "Junho"
        NomeMes[6] = "Julho"
        NomeMes[7] = "Agosto"
        NomeMes[8] = "Setembro"
        NomeMes[9] = "Outubro"
        NomeMes[10] = "Novembro"
        NomeMes[11] = "Dezembro"

function WriteName() { document.write (NomeDia[dias]); }
function WriteDate() { document.write (dia + " de " + NomeMes[mes] + " de " + ano); }
function mostraano() { document.write (ano) }
function abrir(link) { window.open (link, "", "width=745,height=500,resizable,scrollbars,screenX=0,screenY=0,top=0,left=0"); }
function abrir2(link){ window.open (link, "", "width=420,height=300,resizable,scrollbars,screenX=40,screenY=40,top=40,left=40"); }
function abrirp(link){ window.open (link, "", "width=200,height=200,resizable,scrollbars,screenX=40,screenY=40,top=40,left=40"); }

function barralat(){	
	if(screen.width>1000){
		if(navigator.appVersion.indexOf('MSIE 5.0')==-1) {
				document.getElementById('barralateral').style.display = 'block';
		}
	}
}

var xmlhttp
var destino
var selecionado

function loadXMLDoc(url)
{ xmlhttp=null  
  if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest() }
  else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") }
  if (xmlhttp!=null)
  { xmlhttp.onreadystatechange=state_Change
    xmlhttp.open("GET",url,true)
    xmlhttp.send(null)
  } else { alert("Your browser does not support XMLHTTP.") }
}

function state_Change()
{ if (xmlhttp.readyState==4) // if xmlhttp shows "loaded"
  { if (xmlhttp.status==200) // if "OK"
    { 
      monta();    
    } else { alert("Problem retrieving XML data:" + xmlhttp.statusText) }
  } else if (xmlhttp.readyState==1) { destino.options[0] = new Option("carregando ...","0"); }
}

function monta()
{     var response = xmlhttp.responseXML.documentElement;
      sel = 0;
      x=response.getElementsByTagName("registro");
      for (i=0;i<x.length;i++)
      { xx=x[i].getElementsByTagName("label");
        xy=x[i].getElementsByTagName("codigo");
        destino.options[i] = new Option(xx[0].firstChild.data,xy[0].firstChild.data);
        if (xy[0].firstChild.data == selecionado) { sel = i; }
      }
      destino.options[sel].selected=true;      
}

function buscar2(tb,dest,rel,sel)
{ 
  if (rel > 0)
  { destino = dest;
    selecionado = sel;  
    var url = "";    
    url = "buscar.php?tb="+ tb + "&rel=" + rel;  
    loadXMLDoc(url);    
  }  
}

function buscar3(tb,dest,rel,rel2,sel)
{ 
  if (rel > 0)
  { destino = dest;
    selecionado = sel;  
    var url = "";    
    url = "buscar.php?tb="+ tb + "&rel=" + rel + "&rel2=" + rel2 ;
    loadXMLDoc(url);    
  }  
}

function buscar4(tb,dest,rel,rel2,rel3,sel)
{ 
  if (rel > 0)
  { destino = dest;
    selecionado = sel;  
    var url = "";    
    url = "buscar.php?tb="+ tb + "&rel=" + rel + "&rel2=" + rel2 + "&rel3=" + rel3;
    loadXMLDoc(url);    
  }  
}

function zerar(temp,tabela)
{ tabela = 'Selecione ' + tabela;
  for (m=temp.options.length;m>=0;m--) { temp.options[m]=null }
  temp.options[0] = new Option(tabela,'0');  	
}


var quanti = 0;

function setcook(novo,marcou)
{ var cook = ""; 
  cook = unescape(document.cookie);
  if (marcou)
  { if (cook.length == 0) { cook = novo;  }
    else
    { var tmp = cook.split(";");
      var achou = "N";      
      for (i = 0; i < tmp.length; i++)
      { if (tmp[i] == novo) { achou = "S"; }
      }    
      if (achou == "N") { cook += ";" + novo; }
    }
  } else
  { var tmp = cook.split(";");
    var j = 0;
    cook = "";
    for (i = 0; i < tmp.length; i++)
    { if (tmp[i] != novo)
      { if (j == 0) { cook = tmp[i]; j++; } else { cook += ";" + tmp[i]; j++; }
      }
    }
  }	
  document.cookie = escape(cook);  
  quanti = cook.length;
}
function getcook()
{ var cook = ""; 
  cook = unescape(document.cookie); 
  //alert(cook); 
  quanti = cook.length;  
}

function vermarcados()
{ var cook = ""; 
  cook = unescape(document.cookie);
  document.marcados.marcados.value = cook;  
  if (quanti > 0) { return true; } else { return false; }
}

function checar() 
{ var total = document.pesquisa.elements.length; 
  cook = unescape(document.cookie);
  var tmp = cook.split(";"); 
  for (i = 0; i < total; i++)
  { var e = document.pesquisa.elements[i];
    var nome = e.name;
    nome = nome.substr(1,nome.length-1);    
    for (j = 0; j < tmp.length; j++)
    { if (nome == tmp[j]) { e.checked = true; }
    }
  }
}

function PrintPage() { if (window.print) window.print(); else alert("O script não conseguiu enviar o documento diretamente para impressão,Pressione Ctrl+P ou selecione Imprimir no menu Arquivo para imprimir esta página."); }

function outracat(){
	if(document.form1.codcidade.value=="0"){
		document.form1.novacidade.disabled=0;
		document.getElementById('campooutras').style.visibility="visible";
		document.getElementById('campooutras2').style.visibility="visible";
		document.form1.novacidade.focus();

	} else {
		document.form1.novacidade.disabled=1;		
		document.getElementById('campooutras').style.visibility="hidden";
		document.getElementById('campooutras2').style.visibility="hidden";
	}
}

function outracat2(){
	if(document.form1.txtcodcidade.value=="0"){
		document.form1.novacidade.disabled=0;
		document.getElementById('campooutras').style.visibility="visible";
		document.getElementById('campooutras2').style.visibility="visible";
		document.form1.novacidade.focus();

	} else {
		document.form1.novacidade.disabled=1;		
		document.getElementById('campooutras').style.visibility="hidden";
		document.getElementById('campooutras2').style.visibility="hidden";
	}
}

function perguntarsj(link){ if(confirm('Apagar Veículo ?\n\nSe apagar este veículo, você precisará pagar novamente para anunciá-lo !')){ window.location = link ; } }

function inarray(s,a)
{ var achou = false;
  var i = 0;
	while (i < a.length)
  { if (a[i] == s) { achou = true; i = a.length; }
    i++;
  }
  return achou;  
}

function valida(campo,tecla){
  //48 a 57 = 0 a 9 e 96 a 105 = 0 a 9 no teclado numérico
  //8=backspace, 16=shift, 35=end, 36=home, 37,38,39,40=setas(esq,cima,dir,baixo), 127=delete
  var r = new Array(8,16,35,36,37,38,39,40,127);
  if (!inarray(tecla.keyCode,r))
  { var vr = new String(campo.value);
    var pesq = new RegExp("[^0-9]", "g");
	  campo.value = vr.replace(pesq,"");
	  return true;
  } else { return false; }
}

function mascara(campo, tecla, m) { // m = mascara 
  if (valida(campo,tecla))
  { var novo = "";
    var j    = 0;
    var r    = new Array(".","-","/",":","(",")"," ");
    var vr   = new String(campo.value);
    var pesq = new RegExp("[^0-9]", "g");
	  vr       = vr.replace(pesq,"");	  
	  tam      = vr.length;
	  for(i = 0; i < tam; i++)
    { if (inarray(m.charAt(i),r))
      { novo += m.charAt(i);
        tam++;
      } else
      { novo += vr.charAt(j);
        j++;
        if (j == vr.length) { tam = i; }
      }
    } 
	  campo.value = novo;
	}
}

function autoTab(input,len, e) {
  var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}

	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
		found = true;
		else
		index++;
		return found;
	}

	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
		return index;
	}
	return true;
}

//-->
