// JavaScript Document
//////////////////////////////////////////////////////////////////////////////////////
//Ajax
function createXMLHTTP() {
   var ajax;
   try {
      ajax = new ActiveXObject("Microsoft.XMLHTTP");
   }
   catch (e) {
      try {
         ajax = new ActiveXObject("Msxml2.XMLHTTP");
         alert(ajax);
      }
      catch (ex) {
         try {
            ajax = new XMLHttpRequest();
         }
         catch (exc) {
            alert("Esse browser não tem recursos para uso do Ajax");
            ajax = null;
         }
      }
      return ajax;
   }
   var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
   for (var i = 0; i < arrSignatures.length; i++) {
      try {
         var oRequest = new ActiveXObject(arrSignatures[i]);
         return oRequest;
      }
      catch (oError) { }
   }
   throw new Error("MSXML is not installed on your system.");
}

//////////////////////////////////////////////////////////////////////////////////////
//Verifica qntd de caracteres do campo passado e executa função passada
function verificaChars(obj, func, qtde, parm1, parm2, parm3) {
   if (obj.value.length == qtde) {
      obj.disabled = true;
      if (parm1 != null) {
         if (parm2 != null) {
            if (parm3 != null) {
               func(parm1, parm2, parm3);
            } else {
               func(parm1, parm2);
            }
         } else {
            func(parm1);
         }
      } else {
         func();
      }
      obj.disabled = false;
   }
}
//Verifica qntd de caracteres
//////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
//Função mask utilizada para criar máscararas para campos

function mask(o, opt) {
   v_obj = o
   v_opt = opt
   setTimeout("execMask()", 1)
}

function execMask() {
   v_obj.value = doMask(v_opt, v_obj.value)
}


//----------------------------------------------------------------------------------------------//

function doMask(option, value) {
   value = value.replace(/\D/g, "");

   switch (option) {
      case "phone": // (11) 1111-1111
         value = value.replace(/^(\d{2})(\d)/g, "($1) $2");
         value = value.replace(/(\d{4})(\d)/, "$1-$2");
         break;
      case "vox": // 1111-11
         value = value.replace(/^(\d{4})(\d)/g, "$1-$2");
         break;
      case "hora": // 11:11
         value = value.replace(/^(\d{2})(\d)/g, "$1:$2");
         break;
      case "zipcode": // CEP: 11111-11
         value = value.replace(/^(\d{5})(\d)/g, "$1-$2");
         break;
      case "date": // 11/11/1111
         value = value.replace(/^(\d{2})(\d)/g, "$1/$2");
         value = value.replace(/(\d{2})(\d)/, "$1/$2");
         break;
      case "decimal": // ...111.111.111,11
         value = value.replace(/(\d)(\d{2})$/g, "$1,$2");
         value = value.replace(/(\d)(\d{3},\d{2})/g, "$1.$2");
         value = value.replace(/(\d)(\d{3}\.\d{3},\d{2})/g, "$1.$2");
         break;
      case "kilo": // ...1111,111
         value = value.replace(/(\d)(\d{3})$/g, "$1,$2");
         break;
      case "cpf": // 111.111.111-11
         value = value.replace(/^(\d{3})(\d)/g, "$1.$2");
         value = value.replace(/(\d{3})(\d)/, "$1.$2");
         value = value.replace(/(\d{3})(\d)/, "$1-$2");
         break;
      case "id": // RG: 11.111.111-1 || 11.111.111-x
         value = value.replace(/^(\d{2})(\d)/g, "$1.$2");
         value = value.replace(/(\d{3})(\d)/, "$1.$2");
         value = value.replace(/(\d{3})(\d|x)/, "$1-$2");
         break;
      case "cnpj": // CNPJ: 00.000.000/0000-00
         value = value.replace(/(\d)(\d{2})$/g, "$1-$2");
         value = value.replace(/(\d)(\d{4}-\d{2})/g, "$1/$2");
         value = value.replace(/(\d)(\d{3}\/\d{4}-\d{2})/g, "$1.$2");
         value = value.replace(/(\d)(\d{3}\.\d{3}\/\d{4}-\d{2})/g, "$1.$2");
         break;
   }
   return value;
}
function sanitize(obj, patt) {
   var objVal = obj.value;
   var objId = obj.id;
   var regex = new RegExp(patt, "g");

   objVal = objVal.replace(regex, "");
   document.getElementById(objId).value = objVal;
}
// Função utilizada para bloquear a digitação de caracteres que não sejam números
function noDigit(o) {
   var objVal = o.value;
   var objId = o.id;

   objVal = objVal.replace(/\D/g, "");
   document.getElementById(objId).value = objVal;
}

//////////////////////////////////////////////////////////////////////////////////////
//Função para exibir data
var hoje = new Date();
/*function CriaArray (n) {
this.length = n
}*/

function escreveData() {
   var NomeMes = new Array();
   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";

   var dia = hoje.getDate();
   var mes = hoje.getMonth();
   var ano = hoje.getYear();

   if (ano < 2000) { // Y2K Fix, Isaac Powell
      ano = ano + 1900;
   }
   if (dia < 10) {
      dia = "0" + dia;
   }

   return dia + " de " + NomeMes[mes] + " de " + ano;
}

function escreveDia() {
   var dias = hoje.getDay();
   var NomeDia = new Array();
   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";

   return NomeDia[dias];
}
//Função para exibir data
//////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////
//Funções Dreamweaver
function MM_swapImgRestore() { //v3.0
   var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() { //v3.0
   var d = document; if (d.images) {
      if (!d.MM_p) d.MM_p = new Array();
      var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
         if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
   }
}

function MM_findObj(n, d) { //v4.01
   var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
      d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
   }
   if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
   for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
   if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
   var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
      if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function MM_displayStatusMsg(msgStr) { //v1.0
   status = msgStr;
   document.MM_returnValue = true;
}

function MM_openBrWindow(theURL, winName, features) { //v2.0
   window.open(theURL, winName, features);
}

function MM_jumpMenu(targ, selObj, restore) { //v3.0
   eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
   if (restore) selObj.selectedIndex = 0;
}
//Funções Dreamweaver
//////////////////////////////////////////////////////////////////////////////////////*/

//ADM
//////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////
//Intranet

//////////////////////////////////////////////////////////////////////////////////////
///Saudação: Bom dia, tarde e noite
function escreveSaudacao() {
   var hours = hoje.getHours();
   var saudacao = "";
   if (hours >= 0 && hours < 12) {
      saudacao = "Bom dia"
   } else if (hours >= 12 && hours < 18) {
      saudacao = "Boa tarde"
   } else if (hours >= 18) {
      saudacao = "Boa noite";
   }
   return saudacao;
}
///Saudação: Bom dia, tarde e noite
//////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////
///Iframe ajustável
function iframeAutoHeight(altura) {
   //by Micox - elmicox.blogspot.com - elmicox.com - webly.com.br  
   if (navigator.appName.indexOf("Internet Explorer") > -1) { //ie sucks
      var func_temp = function() {
         var val_temp = altura.contentWindow.document.body.scrollHeight
         altura.style.height = val_temp + "px";
      }
      setTimeout(function() { func_temp() }, 100) //ie sucks
   } else {
      var val = altura.contentWindow.document.body.parentNode.offsetHeight
      altura.style.height = val + "px";
   }
}
///Iframe ajustável
//////////////////////////////////////////////////////////////////////////////////////


$(function() { //Function executed after the page loads
   var dataExtensa = escreveDia() + ", " + escreveData();
   $("#saudacao").html(document.createTextNode(escreveSaudacao()));
   $("#date").html($.trim(dataExtensa));
   $("a[rel*=external]").attr("target", "_blank");
});

//////////////////////////////////////////////////////////////////////////////////////
//OpenMap
function OpenMap(pProposta, pES, pCS, pBS, pCPS, pEC, pCC, pBC, pCPC) {
   var Parametro = ""

   var Proposta = pProposta;
   //alert("Proposta: "+Proposta);
   var EstadoSaida = pES;
   //alert("EstadoSaida: "+EstadoSaida);
   var CidadeSaida = pCS;
   //alert("CidadeSaida: "+CidadeSaida);
   var BairroSaida = pBS;
   if (Proposta == "arredores") {
      var CepSaida = pCPS;
      //alert("CepSaida: "+CepSaida);
   }


   if (EstadoSaida != "") {
      Parametro = "ess=" + EstadoSaida;
      //alert("ParametroES: "+Parametro);
   }
   if (CidadeSaida != "") {
      Parametro = Parametro + "&cis=" + CidadeSaida;
      //alert("ParametroCS: "+Parametro);
   }
   if (Proposta == "arredores") {
      if (CepSaida != "") {
         Parametro = Parametro + "&ces=" + CepSaida;
         //alert("ParametroCES: "+Parametro);
      }
   }

   var EstadoChegada = pEC;
   //alert("EstadoChegada: "+EstadoChegada);
   var CidadeChegada = pCC;
   //alert("CidadeChegada: "+CidadeChegada);
   if (Proposta == "arredores") {
      var CepChegada = pCPC;
      //alert("CepChegada: "+CepChegada);
   }

   if (EstadoChegada != "") {
      Parametro = Parametro + "&esc=" + EstadoChegada;
      //alert("ParametroEC: "+Parametro);
   }
   if (CidadeChegada != "") {
      Parametro = Parametro + "&cic=" + CidadeChegada;
      //alert("ParametroCC: "+Parametro);
   }
   if (Proposta == "arredores") {
      if (CepChegada != "") {
         Parametro = Parametro + "&cec=" + CepChegada;
         //alert("ParametroCEC: "+Parametro);
      }
   }
   //alert("ParametroFinal: "+Parametro);
   MM_openBrWindow('http://www.eco-carroagem.com.br/eco_googlemap.asp?' + Parametro, 'googlemap', 'scrollbars=yes,width=540,height=520');
}
//OpenMap
//////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////
//FORMS
//////////////////////////////////////////////////////////////////////////////////////
//OpenCep
function OpenCep(param) {
   var vProposta = param;
   //alert("vProposta: "+vProposta);
   //var spanCepSaida = document.getElementById("cepSaida");
   //var spanCepChegada = document.getElementById("cepChegada");
   if (vProposta == "todas") {
      document.getElementById("cepSaida").style.display = "none";
      document.getElementById("cepChegada").style.display = "none";
   } else {
      document.getElementById("cepSaida").style.display = "";
      document.getElementById("cepChegada").style.display = "";
   }
}
//OpenCep
//////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////
//Clear form
$.fn.clearForm = function() {
   return this.each(function() {
      var type = this.type, tag = this.tagName.toLowerCase();
      if (tag == 'form')
         return $(':input', this).clearForm();
      if (type == 'text' || type == 'password' || tag == 'textarea')
         this.value = '';
      else if (type == 'checkbox' || type == 'radio')
         this.checked = false;
      else if (tag == 'select')
      //this.selectedIndex = -1;
         this.selectedIndex = 0;
   });
};


//Clear form
//////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////
//Load combs ajax cidade
//Vinculacao dos selects
function loadCombosS(url, idElm) {
   var codEstS = "";
   //var idEstS = "";
   var paramsS = $("#es").val();
   codEstS = paramsS;
   /*	if(paramsS != ""){
   idEstS = paramsS.split(";");
   codEstS = idEstS[0];
   }*/
   //alert("codEstS= "+codEstS);
   var loadCombosS = createXMLHTTP();
   loadCombosS.open("post", url, true);
   loadCombosS.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   loadCombosS.onreadystatechange = function() {
      if (loadCombosS.readyState == 4) {// abaixo o texto do gerado no arquivo executa.asp e colocado no div
         $("#" + idElm).html(loadCombosS.responseText); //substitui innerHTML
      }
   }
   loadCombosS.send("codestados=" + codEstS);

}

function loadCombosC(url, idElm) {
   var codEstC = "";
   var paramsC = $("#ec").val();
   codEstC = paramsC;

   /*	if(paramsC != ""){
   idEstC = paramsC.split(";");
   codEstC = idEstC[0];
   }*/
   //alert("codEstC= "+codEstC);
   var loadCombosC = createXMLHTTP();
   loadCombosC.open("post", url, true);
   loadCombosC.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   loadCombosC.onreadystatechange = function() {
      if (loadCombosC.readyState == 4) {// abaixo o texto do gerado no arquivo executa.asp e colocado no div
         $("#" + idElm).html(loadCombosC.responseText); //substitui innerHTML
      }
   }
   loadCombosC.send("codestadoc=" + codEstC);

}

function loadCombosTS(url, cs, idElm) {
   var codEstS = "";
   var paramsS = $("#es").val();
   codEstS = paramsS;
   //alert("codEstS= "+codEstS);
   var loadCombosTS = createXMLHTTP();
   loadCombosTS.open("post", url, true);
   loadCombosTS.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   loadCombosTS.onreadystatechange = function() {
      if (loadCombosTS.readyState == 4) {// abaixo o texto do gerado no arquivo executa.asp e colocado no div
         $("#" + idElm).html(loadCombosTS.responseText); //substitui innerHTML
         $('#cs>option').each(function() {
            var cid = $(this).val().replace(' ', '|');
            if (cid == "") cid = 0;
            if (cid == cs) {
               $(this).attr('selected', true);
            } else {
               $(this).attr('selected', false);
            }
         });
      }
   }
   loadCombosTS.send("codestados=" + codEstS + "&cidade=" + cs);
}

function loadCombosTC(url, cc, idElm) {
   var codEstC = "";
   var paramsC = $("#ec").val();

   codEstC = paramsC;

   //alert("codEstC= "+codEstC);
   var loadCombosTC = createXMLHTTP();
   loadCombosTC.open("post", url, true);
   loadCombosTC.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   loadCombosTC.onreadystatechange = function() {
      if (loadCombosTC.readyState == 4) {// abaixo o texto do gerado no arquivo executa.asp e colocado no div
         $("#" + idElm).html(loadCombosTC.responseText); //substitui innerHTML
         $('#cc>option').each(function() {
            var cid = $(this).val().replace(' ', '|');
            if (cid == "") cid = 0;
            if (cid == cc) {
               $(this).attr('selected', true);
            } else {
               $(this).attr('selected', false);
            }
         });
      }
   }
   loadCombosTC.send("codestadoc=" + codEstC + "&cidade=" + cc);

}

function loadCombosCidadeInfo(url, idElm) {
   var codEstC = "";
   var paramsC = $("#uf").val();

   if (paramsC != "") {
      idEstC = paramsC.split("|");
      codEstC = idEstC[0];
   }
   //alert("codEstC= "+codEstC);
   var loadCombosCidadeInfo = createXMLHTTP();
   loadCombosCidadeInfo.open("post", url, true);
   loadCombosCidadeInfo.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   loadCombosCidadeInfo.onreadystatechange = function() {
      if (loadCombosCidadeInfo.readyState == 4) {// abaixo o texto do gerado no arquivo executa.asp e colocado no div
         $("#" + idElm).html(loadCombosCidadeInfo.responseText); //substitui innerHTML
      }
   }
   loadCombosCidadeInfo.send("codestado=" + codEstC);

}

//para busca da secao cidade
function loadCombosCidadeADM(url, idElm, idSC, vl) {
   var params = $("#uf").val();
   var vidSuaCidade = idSC;
   var validar = vl;
   /*	alert("params: "+params);
   alert("url: "+url);
   alert("idElm: "+idElm);
   alert("vidSuaCidade: "+vidSuaCidade);
   alert("validar: "+validar);*/
   var loadCombosCidadeADM = createXMLHTTP();
   loadCombosCidadeADM.open("post", url, true);
   loadCombosCidadeADM.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   loadCombosCidadeADM.onreadystatechange = function() {
      if (loadCombosCidadeADM.readyState == 4) {// abaixo o texto do gerado no arquivo executa.asp e colocado no div
         $("#" + idElm).html(loadCombosCidadeADM.responseText); //substitui innerHTML
      }
   }
   loadCombosCidadeADM.send("codestado=" + params + "&idSuaCidade=" + vidSuaCidade + "&validar=" + validar);
}

//para busca da secao cidade
function loadCombosCidade(url, idElm) {
   var params = $("#uf").val();
   /*	alert("params: "+params);
   alert("url: "+url);
   alert("idElm: "+idElm);*/
   var loadCombosCidade = createXMLHTTP();
   loadCombosCidade.open("post", url, true);
   loadCombosCidade.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   loadCombosCidade.onreadystatechange = function() {
      if (loadCombosCidade.readyState == 4) {// abaixo o texto do gerado no arquivo executa.asp e colocado no div
         $("#" + idElm).html(loadCombosCidade.responseText); //substitui innerHTML
      }
   }
   loadCombosCidade.send("codestado=" + params);
}
//para busca da secao servicos cidade
function loadCombosServicosCidadeADM(url, idElm, idSC, vl, complete) {
   var params = $("#uf").val();
   var vidServicosProfissionais = idSC;
   var validar = vl;
   /*	alert("params: "+params);
   alert("url: "+url);
   alert("idElm: "+idElm);
   alert("vidServicosProfissionais: "+vidServicosProfissionais);
   alert("validar: "+validar);*/
   var loadCombosServicosCidadeADM = createXMLHTTP();
   loadCombosServicosCidadeADM.open("post", url, true);
   loadCombosServicosCidadeADM.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   loadCombosServicosCidadeADM.onreadystatechange = function() {
      if (loadCombosServicosCidadeADM.readyState == 4) {// abaixo o texto do gerado no arquivo executa.asp e colocado no div
         $("#" + idElm).html(loadCombosServicosCidadeADM.responseText); //substitui innerHTML
         if (complete) complete();
      }
   }
   loadCombosServicosCidadeADM.send("codestado=" + params + "&idServicosProfissionais=" + vidServicosProfissionais + "&validar=" + validar);
}

//para busca da secao servicos
function loadCombosServicosADM(url, idElm, idSC, vl, complete) {
   var params = $("#sp").val();
   var vidServicosProfissionais = idSC;
   var validar = vl;
   /*	alert("params: "+params);
   alert("url: "+url);
   alert("idElm: "+idElm);
   alert("vidServicosProfissionais: "+vidServicosProfissionais);
   alert("validar: "+validar);*/
   var loadCombosServicosADM = createXMLHTTP();
   loadCombosServicosADM.open("post", url, true);
   loadCombosServicosADM.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   loadCombosServicosADM.onreadystatechange = function() {
      if (loadCombosServicosADM.readyState == 4) {// abaixo o texto do gerado no arquivo executa.asp e colocado no div
         $("#" + idElm).html(loadCombosServicosADM.responseText); //substitui innerHTML
         if (complete) complete();
      }
   }
   loadCombosServicosADM.send("codservico=" + params + "&idServicosProfissionais=" + vidServicosProfissionais + "&validar=" + validar);
}

//para busca da secao cidade
function loadCombosServicos(url, idElm, complete) {
   var params = $("#sp").val();
   /*	alert("params: "+params);
   alert("url: "+url);
   alert("idElm: "+idElm);*/
   var loadCombosServicos = createXMLHTTP();
   loadCombosServicos.open("post", url, true);
   loadCombosServicos.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   loadCombosServicos.onreadystatechange = function() {
      if (loadCombosServicos.readyState == 4) {// abaixo o texto do gerado no arquivo executa.asp e colocado no div
         $("#" + idElm).html(loadCombosServicos.responseText); //substitui innerHTML
         if (complete) complete();
      }
   }
   loadCombosServicos.send("codservico=" + params);
}
//para busca da secao cidade
function loadCombos(url, idElm) {
   var params = $("#uf").val();
   var loadCombos = createXMLHTTP();
   //$("#"+idElm).html("Aguarde, carregando a cidade...");
   loadCombos.open("post", url, true);
   loadCombos.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   loadCombos.onreadystatechange = function() {
      if (loadCombos.readyState == 4) {// abaixo o texto do gerado no arquivo executa.asp e colocado no div
         $("#" + idElm).html(loadCombos.responseText); //substitui innerHTML
      }
   }
   loadCombos.send("codestado=" + params);

}
//Load combs ajax cidade
//////////////////////////////////////////////////////////////////////////////////////


function ZeraCampoCep() {
   //alert("zeraCep");
   document.getElementById("fcep").value = "";
   document.getElementById("fvalidarcep").value = "";
}

function ZeraCampoCepR() {
   //alert("zeraCepResp");
   document.getElementById("fcepr").value = "";
   document.getElementById("fvalidarcepr").value = "";
}

function ZeraCampoCepE() {
   //alert("zeraCepResp");
   document.getElementById("fcepempresa").value = "";
   document.getElementById("fvalidarcepe").value = "";
}

function ResetValidarCep() {
   //alert("ResetValida");
   document.getElementById("fvalidarcep").value = "1";
}

function ResetValidarCepR() {
   //alert("ResetValidaResp");
   document.getElementById("fvalidarcepr").value = "1";
}

function ResetValidarCepE() {
   //alert("ResetValidaResp");
   document.getElementById("fvalidarcepe").value = "1";
}

//////////////////////////////////////////////////////////////////////////////////////
///showHideSou
function showHideSou(param) {
   //alert("param: "+param);
   //alert("acessou showhidesou");
   var divMotorista = document.getElementById("Motorista");
   var divCarteiraHabilitacao = document.getElementById("CarteiraHabilitacao");
   var divCarteiraValidade = document.getElementById("CarteiraValidade");
   var divVeiculo1 = document.getElementById("Veiculo1");
   var divVeiculo2 = document.getElementById("Veiculo2");
   var divMarcas = document.getElementById("fmarca");
   //var divObsevacoes = document.getElementById("Observacoes");


   if (param == "motoristapassageiro") {
      //alert("paramIF: "+param);
      divMotorista.style.display = "";
      divCarteiraHabilitacao.style.display = "";
      divCarteiraValidade.style.display = "";
      divVeiculo1.style.display = "";
      divVeiculo2.style.display = "";
      divMarcas.style.display = "";
   } else if (param == "motorista") {
      //alert("paramIF: "+param);
      divMotorista.style.display = "";
      divCarteiraHabilitacao.style.display = "";
      divCarteiraValidade.style.display = "";
      divVeiculo1.style.display = "none";
      divVeiculo2.style.display = "none";
      divMarcas.style.display = "none";
   } else if (param == "passageiro") {
      //alert("paramIF: "+param);
      divMotorista.style.display = "none";
      divCarteiraHabilitacao.style.display = "none";
      divCarteiraValidade.style.display = "none";
      divVeiculo1.style.display = "none";
      divVeiculo2.style.display = "none";
      divMarcas.style.display = "none";
   }
}
///showHideSou 
//////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////
///showHideTrabalho
function showHideTrabalho(param) {
   //alert("param: "+param);
   var trEmpregado = document.getElementById("empregado_");
   var trAutonomo = document.getElementById("autonomo_");
   var trEstudante = document.getElementById("estudante_");
   var trAposentado = document.getElementById("aposentado_");
   var trCertifico = document.getElementById("certifico_");
   var divEmpregado = document.getElementById("divcomboCNPJ_Empregado");
   var divEstudante = document.getElementById("divcomboCNPJ_Estudante");
   //selects  ********bug ie6
   var selectEstadoEntidade = document.getElementById("idEstadoEntidade");
   var selectEstadoAgencia = document.getElementById("idEstadoAgencia");
   var selectGrauAposentado = document.getElementById("idGrauAposentado");
   var selectEstadoContato = document.getElementById("idEstadoContato");

   //ocultando tudo
   trEmpregado.style.display = "none";
   divEmpregado.style.display = "none";
   trAutonomo.style.display = "none";
   trEstudante.style.display = "none";
   divEstudante.style.display = "none";
   trAposentado.style.display = "none";
   //selects
   selectEstadoEntidade.style.display = "none";
   selectEstadoAgencia.style.display = "none";
   selectGrauAposentado.style.display = "none";
   selectEstadoContato.style.display = "none";

   if (param == "Trabalho") {
      //alert("trabalho");
      trEmpregado.style.display = "";
      divEmpregado.style.display = "none";
      trAutonomo.style.display = "none";
      trEstudante.style.display = "none";
      trAposentado.style.display = "none";
      trCertifico.style.display = "none";
      //selects
      selectEstadoEntidade.style.display = "none";
      selectEstadoAgencia.style.display = "none";
      selectGrauAposentado.style.display = "none";
      selectEstadoContato.style.display = "none";
   } else if (param == "Autônomo") {
      //alert("autonomo");
      trEmpregado.style.display = "none";
      trAutonomo.style.display = "";
      trEstudante.style.display = "none";
      trAposentado.style.display = "none";
      trCertifico.style.display = "";
      //selects
      selectEstadoEntidade.style.display = "";
      selectEstadoAgencia.style.display = "none";
      selectGrauAposentado.style.display = "none";
      selectEstadoContato.style.display = "none";
   } else if (param == "Estudante") {
      //alert("estudante");
      trEmpregado.style.display = "none";
      trAutonomo.style.display = "none";
      trEstudante.style.display = "";
      divEstudante.style.display = "none";
      trAposentado.style.display = "none";
      trCertifico.style.display = "none";
      //selects
      selectEstadoEntidade.style.display = "none";
      selectEstadoAgencia.style.display = "none";
      selectGrauAposentado.style.display = "none";
      selectEstadoContato.style.display = "none";
   } else if (param == "Aposentado") {
      //alert("aposentado");
      trEmpregado.style.display = "none";
      trAutonomo.style.display = "none";
      trEstudante.style.display = "none";
      trAposentado.style.display = "";
      trCertifico.style.display = "";
      //selects
      selectEstadoEntidade.style.display = "none";
      selectEstadoAgencia.style.display = "";
      selectGrauAposentado.style.display = "";
      selectEstadoContato.style.display = "";
   }
}
///showHideTrabalho 
//////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////
///showHideSou
function showHideCartao(param) {
   //alert(param);
   var trItau = document.getElementById("Itau");
   var trCartoes = document.getElementById("Cartoes");
   var trBoleto = document.getElementById("Boleto");

   if (param == "I") {
      trItau.style.display = "";
      trCartoes.style.display = "none";
      trBoleto.style.display = "none";
   } else if (param == "V" || param == "M" || param == "A") {
      trItau.style.display = "none";
      trCartoes.style.display = "";
      trBoleto.style.display = "none";
   } else if (param == "B") {
      trItau.style.display = "none";
      trCartoes.style.display = "none";
      trBoleto.style.display = "";
   }
}
///showHideSou 
//////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////
///showHideResponsavel
function dadosResponsavel(param) {
   //alert("dadosresponsavel");
   var tdParentesco = document.getElementById("tdParentesco");
   var divenderResp = document.getElementById("divcomboenderecoResp");
   /*   var divVeiculo1 = document.getElementById("Veiculo1");
   var divMarcas = document.getElementById("fmarca");*/

   var trCep = document.getElementById("DadosResponsavel");
   if (param == "idade1618") {
      //divMarcas.style.display = "none";
      //divVeiculo1.style.display = "none";
      trCep.style.display = "";
      tdParentesco.style.display = "";
      divenderResp.style.display = "";
   } else if (param == "naoaceita") {
      trCep.style.display = "none";
      tdParentesco.style.display = "none";
      divenderResp.style.display = "none";
      //divMarcas.style.display = "none";
      //divVeiculo1.style.display = "";
   }
}
///showHideResponsavel
//////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////
///showHideEmpresa
function showHideEmpresa(param) {
   //alert(param);
   var trEmpresa = document.getElementById("Empresa");
   if (param == "Física") {
      trEmpresa.style.display = "none";
   } else if (param == "Jurídica") {
      trEmpresa.style.display = "";
   }
}
///showHideEmpresa
//////////////////////////////////////////////////////////////////////////////////////

function validaData(data) {
   var RegExPattern = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
   if ((data.match(RegExPattern)) && (data != '')) {
      return true;
   } else {
      return false
   }
}

function isEmail(email) {
   var validaEmail = /^[a-z0-9_.-]+@[a-z0-9_-]+\.[a-z0-9.-]+$/i.test(email); //Validacao de e-mail com Regex
   return validaEmail
}

function validarCPF(cpf) {
   var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
   if (!filtro.test(cpf)) {
      alert("Preencha corretamente o campo CPF!!!");
      return false;
   }

   cpf = cpf.replace(".", "");
   cpf = cpf.replace("-", "");
   cpf = cpf.replace(".", "");

   if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
		cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
		cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
		cpf == "88888888888" || cpf == "99999999999") {
      alert("Preencha corretamente o campo CPF!!!\nCPF Inválido!!!");
      return false;
   }

   soma = 0;
   for (i = 0; i < 9; i++) soma += parseInt(cpf.charAt(i)) * (10 - i);
   resto = 11 - (soma % 11);
   if (resto == 10 || resto == 11) resto = 0;
   if (resto != parseInt(cpf.charAt(9))) {
      alert("Preencha corretamente o campo CPF!!!\nCPF Inválido!!!");
      return false;
   }
   soma = 0;
   for (i = 0; i < 10; i++) soma += parseInt(cpf.charAt(i)) * (11 - i);
   resto = 11 - (soma % 11);
   if (resto == 10 || resto == 11) resto = 0;
   if (resto != parseInt(cpf.charAt(10))) {
      alert("Preencha corretamente o campo CPF!!!\nCPF Inválido!!!");
      return false;
   }
   return true;
}

function validaCNPJ(CNPJID) {
	CNPJ = CNPJID;
	erro = new String;
	if (CNPJ.length < 18) erro += " necessario preencher corretamente o numero do CNPJ! \n\n";
	if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
	if (erro.length == 0) erro += " necessario preencher corretamente o numero do CNPJ! \n\n";
	}
	//substituir os caracteres que nao sao numeros
	if(document.layers && parseInt(navigator.appVersion) == 4){
		x = CNPJ.substring(0,2);
		x += CNPJ.substring(3,6);
		x += CNPJ.substring(7,10);
		x += CNPJ.substring(11,15);
		x += CNPJ.substring(16,18);
		CNPJ = x;
	} else {
		CNPJ = CNPJ.replace(".","");
		CNPJ = CNPJ.replace(".","");
		CNPJ = CNPJ.replace("-","");
		CNPJ = CNPJ.replace("/","");
	}
	var nonNumbers = /\D/;
	if (nonNumbers.test(CNPJ)) erro += "A verificacao de CNPJ suporta apenas números! \n\n";
		var a = [];
		var b = new Number;
		var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
		for (i=0; i<12; i++){
		a[i] = CNPJ.charAt(i);
		b += a[i] * c[i+1];
	}
		if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
		b = 0;
		for (y=0; y<13; y++) {
		b += (a[y] * c[y]);
	}
	if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
	if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
		erro +="Digito verificador do CNPJ com problema!";
	}
	if (erro.length > 0){
		alert(erro);
		return false;
	} else {
		//alert("CNPJ valido!");
		return true;
	}
		return true;

}

function isCPF(cpf) {
   var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
   if (!filtro.test(cpf)) {
      return false;
   }

   cpf = cpf.replace(/[.-]/g, "");

   if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
		cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
		cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
		cpf == "88888888888" || cpf == "99999999999") {
      return false;
   }

   soma = 0;
   for (i = 0; i < 9; i++) soma += parseInt(cpf.charAt(i)) * (10 - i);
   resto = 11 - (soma % 11);
   if (resto == 10 || resto == 11) resto = 0;
   if (resto != parseInt(cpf.charAt(9))) {
      return false;
   }

   soma = 0;
   for (i = 0; i < 10; i++) soma += parseInt(cpf.charAt(i)) * (11 - i);
   resto = 11 - (soma % 11);
   if (resto == 10 || resto == 11) resto = 0;
   if (resto != parseInt(cpf.charAt(10))) {
      return false;
   }
   return true;
}

function isCNPJ(cnpj) {
   var filtro = /^\d{2}.\d{3}.\d{3}\/\d{4}-\d{2}$/i;

   if (!filtro.test(cnpj)) {
      return false;
   }

   cnpj = cnpj.replace(/[./-]/g, "");

   var a = [];
   var b = new Number;
   var c = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
   for (i = 0; i < 12; i++) {
      a[i] = cnpj.charAt(i);
      b += a[i] * c[i + 1];
   }
   if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11 - x }
   b = 0;
   for (y = 0; y < 13; y++) {
      b += (a[y] * c[y]);
   }
   if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11 - x; }
   if ((cnpj.charAt(12) != a[12]) || (cnpj.charAt(13) != a[13])) {
      return false;
   }
   return true;
}
