<!--
function validaremail(s) {
	var ok = true;
	var minusculas = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
	var maiusculas = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
	var numeros    = new Array("0","1","2","3","4","5","6","7","8","9");
	var caracteres = new Array(".","-","_","@");
	var i = 0;
	while (i < s.length)
  { if ((!inarray(s.charAt(i),minusculas)) && (!inarray(s.charAt(i),maiusculas)) && (!inarray(s.charAt(i),numeros)) && (!inarray(s.charAt(i),caracteres)))
    { ok = false; i = s.length; }
    i++;
  }
  if (ok)
	{ if (inarray(s[0],caracteres)) { ok = false; }
	  var parts = s.split("@");
	  if (parts.length == 2) 
	  { var part1 = parts[0];
	    var part2 = parts[1];
	    if (part1.length < 3) { ok = false; }
	    if (part2.length < 5) { ok = false; }
	    if (part2.indexOf(".") < 1) { ok = false; }
	  }	else { ok = false; }
	}
	return ok;
}

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 (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 checkformvalor(form) {
    var erro_string = "";      
    if (form.valorini.value.length < 1 & form.valorini.value.length < 1) 
    { erro_string += "Digite valores Iniciais e Finais para uma busca por valor \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, 'QueroAuto'); }
   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=700,height=455,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 trim(stringToTrim)  { return stringToTrim.replace(/^\s+|\s+$/g,""); }
function ltrim(stringToTrim) { return stringToTrim.replace(/^\s+/,""); }
function rtrim(stringToTrim) { return stringToTrim.replace(/\s+$/,""); }

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,rel2)
{ if (rel > 0)
  { destino = dest;
    selecionado = sel;
    var url = "";
    url = "buscar.php?tb="+ tb + "&rel=" + rel + "&rel2=" + rel2;
    loadXMLDoc(url);
  }  
}

function zerar(temp,mensagem)
{ for (m=temp.options.length;m>=0;m--) { temp.options[m]=null }
  temp.options[0] = new Option(mensagem,'0');  	
}

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 perguntarsj(link){ if(confirm('Apagar Veículo ?\n\nSe apagar este veículo, você precisará pagar novamente para anunciá-lo !')){ window.location = link ; } }

function mostra_indicar() {
  if (document.getElementById("tabIndicar").style.display == 'none') 
  { document.getElementById("tabDetalhes").style.display = 'none';
    document.getElementById("tabIndicar").style.display = '';
    document.getElementById("tabProposta").style.display = 'none';
  } else 
  { document.getElementById("tabDetalhes").style.display = '';
    document.getElementById("tabIndicar").style.display = 'none';
  }
}

function mostra_proposta() {	
  if (document.getElementById("tabProposta").style.display == 'none')
  { document.getElementById("tabDetalhes").style.display = 'none';
    document.getElementById("tabProposta").style.display = '';
    document.getElementById("tabIndicar").style.display = 'none';  
  } else 
  { document.getElementById("tabDetalhes").style.display = '';
    document.getElementById("tabProposta").style.display = 'none';
  }	
}

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 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;
}

function milhar(vr)
{ var tam = vr.length;
  var ret = "";
  var j = 0;
  if (tam > 3)
  { tam--;
    for (i = tam; i >= 0; i--)
    { j++;
      if ((j % 3) == 0 && i > 0)
      { ret = "." + vr.charAt(i) + ret;
      } else { ret = vr.charAt(i) + ret; }
    }
    return ret;
  } else { return vr; }
}

function formataVALOR(Campo, teclapres){	
  if ((teclapres.keyCode > 47 && teclapres.keyCode < 58) || (teclapres.keyCode > 95 && teclapres.keyCode< 106))
  { var pesq3 = new RegExp("[^0-9]", "g");
    var vr = new String(Campo.value);
    vr  = vr.replace(pesq3,"");    
    tam = vr.length;
    var sair = 0;
    while (sair == 0) { if (vr.charAt(0) == "0") { vr = vr.substr(1,tam); tam = vr.length; } else { sair = 1 ; } }
    if (tam == 0) { Campo.value = "R$ 0,0"; }
    if (tam == 1) { Campo.value = "R$ 0," + vr.substr(0,tam); }
    if (tam == 2) { Campo.value = "R$ " + milhar(vr.substr(0,1)) + "," + vr.substr(1,1); }
    if (tam >  2) { Campo.value = "R$ " + milhar(vr.substr(0,tam - 1)) + "," + vr.substr(tam - 1,1); }
    //alert(ret.indexOf(","));    
  }	
}

function verif_pesquisa(form) {
    var erro_string = "";
    var ok = true;
    var codtipo = form.codtipo.options[form.codtipo.selectedIndex].value;
    var codmarca = form.codmarca.options[form.codmarca.selectedIndex].value;
    var codmodelo = form.codmodelo.options[form.codmodelo.selectedIndex].value;
    if (codtipo == 0 || codmarca == 0 || codmodelo == 0)
    { if (codtipo > 0)
      {  var validos = new Array("0","1","2","3","4","5","6","7","8","9",".",",");
         var vini = trim(form.valorini.value);
         var vfin = trim(form.valorfin.value);
         var parts = vini.split(" ");
         if (parts.length == 2) 
	       { var part1 = parts[0];
	         var part2 = parts[1];
	         if (part1 != "R$") { ok = false; }
	         var i = 0;
	         while (i < part2.length)
           { if ((!inarray(part2.charAt(i),validos)))
             { ok = false; i = part2.length; }
             i++;
           }
	       }	else { ok = false; }
      	 if (!ok) { erro_string += "Valor Inicial não parece ser válido \n"; }
      	 var parts = vfin.split(" ");
         if (parts.length == 2) 
	       { var part1 = parts[0];
	         var part2 = parts[1];
	         if (part1 != "R$") { ok = false; }
	         var i = 0;
	         while (i < part2.length)
           { if ((!inarray(part2.charAt(i),validos)))
             { ok = false; i = part2.length; }
             i++;
           }
	       }	else { ok = false; }
      	 if (!ok) { erro_string += "Valor Final não parece ser válido \n"; }
      }
      if (erro_string != "") 
      { erro_string = "Selecione Tipo, Marca e Modelo para fazer uma busca simples \n OU \n Selecione Tipo, Valor Inicial e Valor Final para uma busca por Valores \n" + erro_string;
        ok = false;
      }
    }
    if (erro_string != "") { alert(erro_string); }
    return ok;
}
//-->
