function LmValidacaoDeDados(frm)
{

	var ysnValorPreenchido = false;
	
	// Pelo Menos Um Campo Requerido
	if (frm.cboMarca.value.length > 0) ysnValorPreenchido = true
	if (frm.cboVeiculo.value.length > 0) ysnValorPreenchido = true
	if (frm.cboAnoModeloDe.value.length > 0) ysnValorPreenchido = true
	if (frm.cboAnoModeloAte.value.length > 0) ysnValorPreenchido = true
	if (frm.txtKilometragemDe.value.length > 0) ysnValorPreenchido = true
	if (frm.txtKilometragemAte.value.length > 0) ysnValorPreenchido = true
	if (frm.chkEhZeroKilometro.checked == true) ysnValorPreenchido = true
	if (frm.txtPrecoVendaDe.value.length > 0) ysnValorPreenchido = true
	if (frm.txtPrecoVendaAte.value.length > 0) ysnValorPreenchido = true
	if (frm.cboCombustivel.value.length > 0) ysnValorPreenchido = true
	if (frm.cboTipoCambio.value.length > 0) ysnValorPreenchido = true
	if (frm.cboNumeroPortas.value.length > 0) ysnValorPreenchido = true
	if (frm.cboTracao.value.length > 0) ysnValorPreenchido = true
	if (frm.chkOpcArCondicionado.checked == true) ysnValorPreenchido = true
	if (frm.chkOpcDirecaoHidraulica.checked == true) ysnValorPreenchido = true
	if (frm.chkOpcVidrosDianteirosEletricos.checked == true) ysnValorPreenchido = true
	if (frm.chkEhBlindado.checked == true) ysnValorPreenchido = true

	if (ysnValorPreenchido == false)
	{
		alert("Pelo menos um critério deve ser fornecido");
		return (false);
	}

	// Verifica se a Kilometragem possui apenas caracteres numéricos
	if (frm.txtKilometragemDe.value.length > 0)
	{
		var txtCampo = frm.txtKilometragemDe;
		var strCharValidos = "0123456789.";
		var ysnCampoEhValido = true;
		if (txtCampo.value.length > 0)
		{
			for (i = 0; i < txtCampo.value.length; i++)
			{
				var strChar = txtCampo.value.charAt(i);
				for (j = 0; j < strCharValidos.length; j++)
					if (strChar == strCharValidos.charAt(j))
						break;
				if (j == strCharValidos.length)
				{	
					ysnCampoEhValido = false;
					break;
				}
			}
			if (!ysnCampoEhValido)
			{
				alert("A Kilometragem do veículo deve possuir apenas caracteres numéricos. Ex.: 87500");
				txtCampo.focus();
				return (false);
			}
		}
	}
	if (frm.txtKilometragemAte.value.length > 0)
	{
		var txtCampo = frm.txtKilometragemAte;
		var strCharValidos = "0123456789.";
		var ysnCampoEhValido = true;
		if (txtCampo.value.length > 0)
		{
			for (i = 0; i < txtCampo.value.length; i++)
			{
				var strChar = txtCampo.value.charAt(i);
				for (j = 0; j < strCharValidos.length; j++)
					if (strChar == strCharValidos.charAt(j))
						break;
				if (j == strCharValidos.length)
				{	
					ysnCampoEhValido = false;
					break;
				}
			}
			if (!ysnCampoEhValido)
			{
				alert("A Kilometragem do veículo deve possuir apenas caracteres numéricos. Ex.: 87500");
				txtCampo.focus();
				return (false);
			}
		}
	}
    
    // Preço - Somente caracteres numéricos
	var txtCampo = frm.txtPrecoVendaDe;
	var strCharValidos = "0123456789.";
	var ysnCampoEhValido = true;
	if (txtCampo.value.length > 0)
	{
		for (i = 0; i < txtCampo.value.length; i++)
		{
			var strChar = txtCampo.value.charAt(i);
			for (j = 0; j < strCharValidos.length; j++)
				if (strChar == strCharValidos.charAt(j))
					break;
			if (j == strCharValidos.length)
			{	
				ysnCampoEhValido = false;
				break;
			}
		}
		if (!ysnCampoEhValido)
		{
			alert("O Preço Inicial do veículo deve possuir apenas caracteres numéricos. Ex.: 8500");
			txtCampo.focus();
			return (false);
		}
	}
	var txtCampo = frm.txtPrecoVendaAte;
	var strCharValidos = "0123456789.";
	var ysnCampoEhValido = true;
	if (txtCampo.value.length > 0)
	{
		for (i = 0; i < txtCampo.value.length; i++)
		{
			var strChar = txtCampo.value.charAt(i);
			for (j = 0; j < strCharValidos.length; j++)
				if (strChar == strCharValidos.charAt(j))
					break;
			if (j == strCharValidos.length)
			{	
				ysnCampoEhValido = false;
				break;
			}
		}
		if (!ysnCampoEhValido)
		{
			alert("O Preço Final do veículo deve possuir apenas caracteres numéricos. Ex.: 20800");
			txtCampo.focus();
			return (false);
		}
	}

  /* Ok, passou em todas as consistencias */
  return (true);
}

 /* A funcao abaixo seta o foco no primeiro campo da pagina assim que ela for aberta */
function LmSetarFocoNoPrimeiroCampo(pstrNomePrimeiroCampo) { 
   var i=0, j=0;
   for (j=0; j<document.forms.length; j++) {
      for (i=0; i<document.forms[j].elements.length; i++) {
        if (document.forms[j].elements[i].name == pstrNomePrimeiroCampo) {
           document.forms[j].elements[i].focus(); 
           break; 
        }
      }
   }
}

function lmAbrirJanelaVeiculo()
{
	var strPagina = 'frmAnuncioCarregaVeiculo.asp?strMarca='+
		window.document.frmAnuncio.cboMarca.value

	// Abre a tela de escolha do Veículo
    window.document.frmAnuncio.cboVeiculo.focus();
	var pid;
	pid = window.open(strPagina,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,menubar=no,width=400,height=200,top=100,left=200');
	pid.focus();
    // window.document.frmAnuncio.cboVersao.value = ""

}

function lmAbrirJanelaVersao()
{
	var strPagina = 'frmAnuncioCarregaVersao.asp?strMarca='+
		window.document.frmAnuncio.cboMarca.value+'&strVeiculo='+
		window.document.frmAnuncio.cboVeiculo.value

	// Verifica se ele já selecionou a marca.
	if (window.document.frmAnuncio.cboMarca.value.length == 0) 
    {
       alert("Primeiro você deve selecionar a Marca e o Veículo, depois a Versão.");
       window.document.frmAnuncio.cboMarca.focus();
       return (false);
    }

	// Abre a tela de escolha da Versao
    window.document.frmAnuncio.cboVersao.focus();
	var pid;
	pid = window.open(strPagina,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,menubar=no,width=400,height=200,top=150,left=200');
	pid.focus();
}



function LmAtualizaAnoModelo(pintAnoCorrente)
{

	window.document.frmAnuncio.cboAnoModeloAte.value = ""

	while ( window.document.frmAnuncio.cboAnoModeloAte.length > 0 )
	{
		for ( i = 0 ; i < window.document.frmAnuncio.cboAnoModeloAte.length ; ++i)
		{
			window.document.frmAnuncio.cboAnoModeloAte.remove(i);
		}
	}

	if (window.document.frmAnuncio.cboAnoModeloDe.value == "")
		return;
	pintAnoCorrente = pintAnoCorrente + 1;

	oOption = window.document.createElement("OPTION");
	oOption.value = "";
	oOption.text = "";
	window.document.frmAnuncio.cboAnoModeloAte.add(oOption);

	for (i=window.document.frmAnuncio.cboAnoModeloDe.value;i<=pintAnoCorrente;i++)
	{
		oOption = window.document.createElement("OPTION");
		oOption.value = i;
		oOption.text = i;
		window.document.frmAnuncio.cboAnoModeloAte.add(oOption);
	}
}





function LmLimpaKm()
{
	if (window.document.frmAnuncio.chkEhZeroKilometro.checked == true)
	{
		window.document.frmAnuncio.txtKilometragemDe.value = "";
		window.document.frmAnuncio.txtKilometragemAte.value = "";
	}
}

