// validação de formulários
function Faleconosco() {

  if (document.email.Nome.value == "") {
    alert("Informe o seu nome!");
    document.email.Nome.focus();
    return false;
  }

  if (document.email.Email.value.indexOf("@") < 1) {
    alert("Informe corretamente seu e-mail!");
    document.email.Email.value = "";
    document.email.Email.focus();
    return false;
  }
  if (document.email.Telefone.value == "") {
    alert("Informe seu telefone de contato!");
    document.email.Telefone.focus();
    return false;
  }
  if (document.email.Titulo.value == "") {
    alert("Informe um título para a mensagem!");
    document.email.Titulo.focus();
    return false;
  }  
  if (document.email.Texto.value == "") {
    alert("Escreva sua mensagem!");
    document.email.Texto.focus();
    return false;
  } 
  }
//-------------------------------------------------------------- 
//--------------------------------------------------------------
function ValidaAmigo() {

  if (document.Amigo.NmRemet.value == "") {
    alert("Informe o seu nome!");
    document.Amigo.NmRemet.focus();
    return false;
  }

  if (document.Amigo.MailRemet.value.indexOf("@") < 1) {
    alert("Informe corretamente seu e-mail!");
    document.Amigo.MailRemet.value = "";
    document.Amigo.MailRemet.focus();
    return false;
  }
  if (document.Amigo.NmDest.value == "") {
    alert("Informe o nome do destinatário!");
    document.Amigo.NmDest.focus();
    return false;
  }
  if (document.Amigo.MailDest.value.indexOf("@") < 1) {
    alert("Informe corretamente o e-mail do destinatário!");
    document.Amigo.MailDest.value = "";
    document.Amigo.MailDest.focus();
    return false;
  }
  }
//-------------------------------------------------------------- 
//--------------------------------------------------------------
function validaProposta() {

  if (document.frmProp.Nome.value == "") {
    alert("Informe o seu nome!");
    document.frmProp.Nome.focus();
    return false;
  }
  if (document.frmProp.Email.value.indexOf("@") < 1) {
    alert("Informe corretamente seu e-mail!");
    document.frmProp.Email.value = "";
    document.frmProp.Email.focus();
    return false;
  }
  if (document.frmProp.Telefone.value == "") {
    alert("Informe seu telefone de contato!");
    document.frmProp.Telefone.focus();
    return false;
  }
  if (document.frmProp.Texto.value == "") {
    alert("Escreva sua mensagem!");
    document.frmProp.Texto.focus();
    return false;
  } 
  }
//-------------------------------------------------------------- 
// cria parâmetros para busca

function CreateString()
{
	document.FrmBusca.action='pesqportal.asp?Conc='+document.getElementById("Conc").value+'&Veic='+document.getElementById("Veic").value+'&Mod='+document.getElementById("Mod").value+'&Marca='+document.getElementById("Marca").value+'&Ano='+document.getElementById("Ano").value+'&VI='+document.getElementById("VI").value+'&VF='+document.getElementById("VF").value+'&QtdCarPag='+document.getElementById("QtdCarPag").value
	document.FrmBusca.submit();	
}

function MudaQtd()
{
		document.FrmBusca.action='pesqportal.asp?Conc='+document.getElementById("Conc").value+'&Veic='+document.getElementById("Veiculo").value+'&Mod='+document.getElementById("Mod").value+'&Marca='+document.getElementById("Marca").value+'&Ano='+document.getElementById("Ano").value+'&VI='+document.getElementById("VI").value+'&VF='+document.getElementById("VF").value+'&QtdCarPag='+document.getElementById("QtdCarPag").value
	
	document.FrmBusca.submit();
}

// funções do arquivo detalhes.asp
function DoPrinting(){
  if (!window.print){
  alert("Use o Netscape ou Internet Explorer \n nas versões 4.0 ou superior!")
  return
}
window.print()
}

// função Pop Up
function carregaPopUp(arquivoPop, alt,lag)
{
window.open(arquivoPop,'PopUP','scrollbars=no,width='+alt+',height='+lag+'');
}
//--------------------------------------------------------------


function verifica_form(form) {
var passed = false;
var ok = false
var campo
for (i = 0; i < form.length; i++) {
  campo = form[i].name;
  if (form[i].df_verificar == "sim") {
    if (form[i].type == "text"  | form[i].type == "textarea" | form[i].type == "password" | form[i].type == "select-one") {
      if (form[i].value == "" | form[i].value == "http://") {
		form[campo].className='campo_alerta'
        form[campo].focus();
        alert("Preencha corretamente o campo");
        return passed;
        stop;
      }
    }
    else if (form[i].type == "radio") {
      for (x = 0; x < form[campo].length; x++) {
        ok = false;
        if (form[campo][x].checked) {
          ok = true;
          break;
        }
      }
      if (ok == false) {
        form[campo][0].focus();
		form[campo][0].select();
        alert("Informe uma das opcões");
        return passed;
        stop;
      }
    }
    var msg = ""
    if (form[campo].df_validar == "cpf") msg = checa_cpf(form[campo].value);
    if (form[campo].df_validar == "cnpj") msg = checa_cnpj(form[campo].value);
    if (form[campo].df_validar == "cpf_cnpj") {
	  msg = checa_cpf(form[campo].value);
	  if (msg != "") msg = checa_cnpj(form[campo].value);
	}
    if (form[campo].df_validar == "email") msg = checa_email(form[campo].value);
    if (form[campo].df_validar == "numerico") msg = checa_numerico(form[campo].value);
    if (msg != "") {
	  if (form[campo].df_validar == "cpf_cnpj") msg = "informe corretamente o número do CPF ou CNPJ";
	  form[campo].className='campo_alerta'
      form[campo].focus();
      form[campo].select();
      alert(msg);
      return passed;
      stop;
    }
  }
}
passed = true;
return passed;
}
function desabilita_cor(campo) {
campo.className='campos_formulario'
}

function checa_numerico(String) {
var mensagem = "Este campo aceita somente números"
var msg = "";
if (isNaN(String)) msg = mensagem;
return msg;
}
function checa_email(campo) {
var mensagem = "Informe corretamente o email"
var msg = "";
var email = campo.match(/(\w+)@(.+)\.(\w+)$/);
if (email == null){
  msg = mensagem;
  }
return msg;
}
function checa_cpf(CPF) {
var mensagem = "informe corretamente o número do CPF"
var msg = "";
if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
  CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
  CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
  CPF == "88888888888" || CPF == "99999999999")
msg = mensagem;
soma = 0;
for (y=0; y < 9; y ++)
soma += parseInt(CPF.charAt(y)) * (10 - y);
resto = 11 - (soma % 11);
if (resto == 10 || resto == 11)resto = 0;
if (resto != parseInt(CPF.charAt(9)))
  msg = mensagem; soma = 0;
for (y = 0; y < 10; y ++)
  soma += parseInt(CPF.charAt(y)) * (11 - y);
resto = 11 - (soma % 11);
if (resto == 10 || resto == 11) resto = 0;
if (resto != parseInt(CPF.charAt(10)))
  msg = mensagem;
return msg;
}
function checa_cnpj(s) {
var mensagem = "informe corretamente o número do CNPJ"
var msg = "";
var y;
var c = s.substr(0,12);
var dv = s.substr(12,2);
var d1 = 0;
for (y = 0; y < 12; y++)
{
d1 += c.charAt(11-y)*(2+(y % 8));
}
if (d1 == 0) msg = mensagem;
d1 = 11 - (d1 % 11);
if (d1 > 9) d1 = 0;
if (dv.charAt(0) != d1)msg = mensagem;
d1 *= 2;
for (y = 0; y < 12; y++)
{
d1 += c.charAt(11-y)*(2+((y+1) % 8));
}
d1 = 11 - (d1 % 11);
if (d1 > 9) d1 = 0;
if (dv.charAt(1) != d1) msg = mensagem;
return msg;
}

// obriga a selecionar checkbox para comparar carros

function validaCheckbox(form) {
var total = 0;
var max = form.Carro.length;
for (var idx = 0; idx < max; idx++) {
if (eval("document.frmPesqComparar.Carro[" + idx + "].checked") == true) {
    total += 1;
   }
}
if (total < 2) {
alert("Selecione, pelo menos, dois carros.");
return false;
}
}
// transparencia para arquivos PNG
function correctPNG()
   {
   for(var i=0; i<document.images.length; i++)
      {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
         img.outerHTML = strNewHTML
         i = i-1
         }
      }
   }
window.attachEvent("onload", correctPNG);