var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;  	

function Trim(str){return str.replace(/^\s+|\s+$/g,"");}

function Teste()
{	
	testando = document.getElementById('teste').style.top;	
	alert(testando);		
}

//FUNÇÕES DA HOME///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ActiveAba()
{
	//alert(document.getElementById('abaNovos').className);
	document.getElementById('abaNovos').className = "aba2";
}

//window.onload = function ActiveAba();

function ActiveAbaVolta()
{
	document.getElementById('abaNovos').className = "aba";
}

function popup(Largura, Altura, Nome, Endereco)
{
	window.open(Endereco,Nome,'height='+Altura+',width='+Largura+'resizable=no,scrollbars=no,toolbar=no,location=no,status=no,directories=no');
}

function popupscroll(Largura, Altura, Nome, Endereco)
{
	window.open(Endereco,Nome,'height='+Altura+',width='+Largura+'resizable=no,scrollbars=yes,toolbar=no,location=no,status=no,directories=no');
}

//FUNÇÕES ABAS TOPO///////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function AbaLojas()
{
    document.getElementById("oplojas").style.display = "block";
    document.getElementById("oplojas").style.left = "342px";

    document.getElementById("opnacionais").style.display = "none";
    document.getElementById("opmotos").style.display = "none";
    document.getElementById("opimportados").style.display = "none";
}

function AbaNacionais()
{
    document.getElementById("opnacionais").style.display = "block";
    document.getElementById("opnacionais").style.left = "433px";
    
    document.getElementById("opimportados").style.display = "none";
    document.getElementById("opmotos").style.display = "none";
    document.getElementById("oplojas").style.display = "none";
}

function AbaImportados()
{
    document.getElementById("opimportados").style.display = "block";
    document.getElementById("opimportados").style.left = "479px";
    
    document.getElementById("opnacionais").style.display = "none";
    document.getElementById("opmotos").style.display = "none";
    document.getElementById("oplojas").style.display = "none";
}

function AbaMotos()
{
    
    document.getElementById("opmotos").style.display = "block";
    document.getElementById("opmotos").style.left = "515px";

    document.getElementById("opimportados").style.display = "none";
    document.getElementById("opnacionais").style.display = "none";
    document.getElementById("oplojas").style.display = "none";
}

function AbaSemiNovos()
{
    document.getElementById("opmotos").style.display = "none";
    document.getElementById("opimportados").style.display = "none";
    document.getElementById("opnacionais").style.display = "none";
    document.getElementById("oplojas").style.display = "none";		
    	
    //window.open('http://www.itavemaplus.com.br');
    window.location.replace('Seminovos.aspx');
}

function AbaBlindados()
{
    
    document.getElementById("opmotos").style.display = "none";
    document.getElementById("opimportados").style.display = "none";
    document.getElementById("opnacionais").style.display = "none";
    document.getElementById("oplojas").style.display = "none";

    //window.open('http://www.itavemablindados.com.br/');
    window.location.replace('Blindados.aspx');
}


//ITAVEMA HELP///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function Ajudas(idajuda, idleft, idtop) 
{
	var ajudas = "ajuda1,ajuda2,ajuda_buscarapida_carros,ajuda_buscarapida_motos,ajuda_buscavalores";
	
	objs2 = ajudas.split(",");
	for(i=0; i<objs2.length; i++)
	{
		document.getElementById(objs2[i]).style.display = "none";
	}
	
	document.getElementById(idajuda).style.display = "block";
	document.getElementById(idajuda).style.left = idleft+"px";
	document.getElementById(idajuda).style.top = idtop+"px";	
}
	
//MINHA LISTA/////////////
function Maximizar()
{	
    if(document.getElementById("minimizar").innerHTML == "minimizar lista"){
		
			document.getElementById("minimizar").innerHTML = "maximizar lista";
		
		}
		
	else{
		
			document.getElementById("minimizar").innerHTML = "minimizar lista";
		
		}
	
}
	
//SEMINOVOS/////////////

function Maximizar2(){
	
        if(document.getElementById("minimizar2").innerHTML == "minimizar seminovos"){
			
				document.getElementById("minimizar2").innerHTML = "maximizar seminovos";
			
			}
			
		else{
			
				document.getElementById("minimizar2").innerHTML = "minimizar seminovos";
			
			}
		
	}



// FUNÇÕES DA BUSCA ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Financiamento(cod){

	document.getElementById("simular_1" + cod).style.display = "block";
	
	document.getElementById("avista" + cod).style.display = "none";
	document.getElementById("consorcio" + cod).style.display = "none";
	document.getElementById("usado" + cod).style.display = "none";
	document.getElementById("troco" + cod).style.display = "none";

}

function Avista(cod){

	document.getElementById("avista" + cod).style.display = "block";

	document.getElementById("simular_1" + cod).style.display = "none";
	document.getElementById("consorcio" + cod).style.display = "none";
	document.getElementById("usado" + cod).style.display = "none";
	document.getElementById("troco" + cod).style.display = "none";

}

function Consorcio(cod){

	document.getElementById("consorcio" + cod).style.display = "block";

	document.getElementById("avista" + cod).style.display = "none";
	document.getElementById("simular_1" + cod).style.display = "none";
	document.getElementById("usado" + cod).style.display = "none";
	document.getElementById("troco" + cod).style.display = "none";

}

function Usado(cod){
	
	document.getElementById("usado" + cod).style.display = "block";

	document.getElementById("avista" + cod).style.display = "none";
	document.getElementById("consorcio" + cod).style.display = "none";
	document.getElementById("simular_1" + cod).style.display = "none";
	document.getElementById("troco" + cod).style.display = "none";

}

function Troco(cod){
	
	document.getElementById("troco" + cod).style.display = "block";

	document.getElementById("avista" + cod).style.display = "none";
	document.getElementById("consorcio" + cod).style.display = "none";
	document.getElementById("usado" + cod).style.display = "none";
	document.getElementById("simular_1" + cod).style.display = "none";

}

/* simular_1 */


function Aparece(div){
	
		document.getElementById(div).style.display = "block";

}

function Desaparece(div){
	
		document.getElementById(div).style.display = "none";
}

function DesapareceItens(src)
{
	objs = src.split(",")
	for(i=0; i<objs.length; i++)
	{
		document.getElementById(objs[i]).style.display = "none";
	}
}

function ApareceItens(src)
{
	objs = src.split(",")
	for(i=0; i<objs.length; i++)
	{
		document.getElementById(objs[i]).style.display = "none";
	}
}


function ApareceDetalhe(codDiv){
	
		document.getElementById("normal" + codDiv).style.display = "none";
		document.getElementById("detalhe" + codDiv).style.display = "block";

}


function VoltaDetalhe(codDiv){
	
		document.getElementById("normal" + codDiv).style.display = "block";
		document.getElementById("detalhe" + codDiv).style.display = "none";

}

function DiplayLoja(obj){
	
	if(document.getElementById(obj).style.display == "none")
	{
	    document.getElementById(obj).style.display = "block";
	}
	else
	{
	    document.getElementById(obj).style.display = "none";
	}
		

}


function formatarData(obj,event) {

    if(isIE) { // Internet Explorer
        nTecla = event.keyCode; 
        }
        else if(isWin) { // Nestcape
            
            nTecla = event.which;//evtKeyPress.which;
	    }
	var chrDigito = String.fromCharCode(nTecla);    
    //var chrDigito = String.fromCharCode(event.keyCode);
    if(isNaN(chrDigito) || chrDigito == " ") {return false;}
    if(obj.value.length == 10) {return false;}

    if(obj.value.length == 2 || obj.value.length == 5) {
        obj.value = obj.value + "/";
    }
    obj.value = obj.value + chrDigito;
    return false;
}

function validarData(obj) {
    if(obj.value != "") 
    {
      if(isNaN(Date.parse(obj.value)) || Date.parse(obj.value) < -900000000000) 
      {
        alert("Data Incorreta."); 
        obj.focus();
      }
    }
}

function acessoPopup(codigo)
 {
   
    WebHome_PrincipalMaster.ContagemCliques(parseInt(codigo), ContagemCliques_CallBack);
   
    return true;
 }
 function ContagemCliques_CallBack(response)
 {
    if (response.error != null)
     {
      alert("Ocorreu um erro!"); 
      return;
     }         
 }
	
function exibirTelefone123(companhia)
{   
    if(document.getElementById("telefone_"+companhia).style.display == "none")
    {
        document.getElementById("telefone_"+companhia).style.display = "block";
        document.getElementById("verTelefone_"+companhia).style.display = "none";
        //WebHome_PrincipalMaster.ContagemCliquesVerTelefone(parseInt(codigo), ContagemCliques_CallBack);
    }
}
	
function ContagemCliquesVerTelefone_CallBack(response)
 {
    if (response.error != null)
     {
      alert(response.error);
      alert("Ocorreu um erro!"); 
      return;
     }         
 }	
	
function abrirNovoVeiculo()
{     
    if(document.getElementById("div_NovoVeiculo").style.display == "block")
    {
        document.getElementById("div_NovoVeiculo").style.display = "none";
        document.getElementById("ctl00_ctl00_Meio_Meio_hfNovoVeiculo").value = "0"; 
    }
    else
    {
        id = document.getElementById("ctl00_ctl00_Meio_Meio_hfCodDetalheVeiculo").value;
        if(id != "0")
        {
            if(document.getElementById("detalheVeiculo_"+id).style.display == "block")
            {
                document.getElementById("detalheVeiculo_"+id).style.display = "none";
            }            
        }
        document.getElementById("div_NovoVeiculo").style.display = "block";
        document.getElementById("ctl00_ctl00_Meio_Meio_pnlNenhumCadastro").style.display = "none";        
        document.getElementById("ctl00_ctl00_Meio_Meio_hfDetalheVeiculo").value = "0"; 
        document.getElementById("ctl00_ctl00_Meio_Meio_hfNovoVeiculo").value = "1"; 
    }
}

function exibirManutencao()
{    
    document.getElementById("veiculos").style.display = "none";
    document.getElementById("manutencaoProgramada").style.display = "block";
}

function exibirManutencoes(ind, id)
{
    if(document.getElementById("manutencoes_"+ind).style.display == "block")
    {
        document.getElementById("manutencoes_"+ind).style.display = "none";
    }
    else
    {
        document.getElementById("manutencoes_"+ind).style.display = "block";
        document.getElementById("div_NovaManutencao_"+ind).style.display = "none";
        document.getElementById("km_"+id).style.display = "none";
    }    
    //document.getElementById("ctl00_Meio_hVeiculo").value = id;    
}

function exibirNovaManutencao(ind, id)
{   
    
    for (var i = 0; i <= document.getElementById("ctl00_ctl00_Meio_Meio_ucManutencaoProgramada_hfTotalVeiculos").value-1; i++) 
    {             
          document.getElementById("div_NovaManutencao_"+i).style.display = "none";
    }

    if(document.getElementById("div_NovaManutencao_"+ind).style.display == "block")
    {
        document.getElementById("div_NovaManutencao_"+ind).style.display = "none";
    }
    else
    {
        document.getElementById("div_NovaManutencao_"+ind).style.display = "block";
        document.getElementById("manutencoes_"+ind).style.display = "none";
        document.getElementById("ctl00_ctl00_Meio_Meio_ucManutencaoProgramada_hfNovaManutencao").value = id;   
    }
    //document.getElementById("ctl00_Meio_hVeiculo").value = id;     
    return true;
}

function exibirVeiculo(id)
{
    if(document.getElementById("div_NovoVeiculo").style.display == "block")
    {
        document.getElementById("div_NovoVeiculo").style.display = "none";
    }
       
    if(document.getElementById("detalheVeiculo_"+id).style.display == "block")
    {
        document.getElementById("detalheVeiculo_"+id).style.display = "none";
        document.getElementById("ctl00_ctl00_Meio_Meio_hfCodDetalheVeiculo").value = "0"; 
    }
    else
    {
        document.getElementById("detalheVeiculo_"+id).style.display = "block";
        document.getElementById("ctl00_ctl00_Meio_Meio_hfCodDetalheVeiculo").value = id; 
        document.getElementById("ctl00_ctl00_Meio_Meio_hfDetalheVeiculo").value = "1";          
    }
}

function exibirKm(id)
{
    //document.getElementById("ctl00_Meio_hVeiculo").value = id;    
    if(document.getElementById("km_"+id).style.display == "block")
    {
        document.getElementById("km_"+id).style.display = "none";
    }
    else
    {
        document.getElementById("km_"+id).style.display = "block";
        
        document.getElementById("manutencoes_"+id).style.display = "none";
        document.getElementById("div_NovaManutencao_"+id).style.display = "none";
        
    }
}


// NÃO ACEITA DIGITAR TEXTO
function semTexto(event){
    if(isIE) 
    { 
        nTecla =  window.event.keyCode; 
    }
    else if(isWin) 
    { 
        nTecla = event.which;
    }
    
    if ( !( nTecla <= 57 && nTecla >= 48 ) )
    {
        if(isIE) 
        { 
             window.event.keyCode = 0; 
        }
        else if(isWin) 
        { 
             var newEvent = document.createEvent("KeyEvents");
             newEvent.initKeyEvent("keypress", true, true, document.defaultView,
                      event.ctrlKey, event.altKey, event.shiftKey,
                      event.metaKey, 0, 0);
             event.preventDefault();
             event.target.dispatchEvent(newEvent); 
        }
    }
}


function showPopupGaragem(id,w,h)
 {
        var myBackground = document.getElementById( "popupGaragemBackground" );
	        myBackground.style.display = "inline";
	        myBackground.style.display = "block";
	        
            myBackground.style.position = "absolute";
            myBackground.style.width = getPageSize()[0] + "px";
            myBackground.style.height = getPageSize()[1] + "px";
            myBackground.style.left = "0px";
            myBackground.style.top = "0px";
            //myBackground.style.backgroundColor = "#ffffff";
            myBackground.style.filter = "alpha(opacity=70)";
            myBackground.style.opacity = 0.7;
            myBackground.style.zIndex = 10000;
		        
        var myDetails = document.getElementById(id);
            //myDetails.style.backgroundColor = "#ffffff";
            //myDetails.style.border = "solid 1px #d4d4d4";
            myDetails.style.position = "absolute";
            myDetails.align = "center";
            myDetails.style.width = w+"px";
            myDetails.style.height = h+"px";
            myDetails.style.left = ((getPageSize()[0] - w)/2) + "px";
            myDetails.style.top = (getCoords()[1] + 50) + "px";
            myDetails.style.zIndex = 10001;
            
        var containerFechar = myDetails.getElementsByTagName("div")[0];
        var botaoFechar = containerFechar.getElementsByTagName("a")[0];
            //botaoFechar.style.backgroundColor = "#ffffff";
            botaoFechar.style.border = "solid 0px #d4d4d4";
            botaoFechar.style.padding = "5px 5px 5px 5px";
            
    }
    
    function hidePopupGaragem() {
        var form = window.parent.document.getElementsByTagName("form")[0];
        var myBackground = window.parent.document.getElementById("popupGaragemBackground");        
        var myDetails = window.parent.document.getElementById("ctl00_ctl00_Meio_Meio_popupGaragemContainer");
        
        if( myBackground && myDetails ) {
            myBackground.style.display = "inline";
	        myBackground.style.display = "none";
	        myDetails.style.display = "inline";
	        myDetails.style.display = "none";
	        
	        /*if( form ) {
	            form.removeChild( myDetails );
		        delete myDetails;

		        form.removeChild( myBackground );
		        delete myBackground;
	        }*/
        }
    }
    
    function verificarGaragem()
    {        
        document.getElementById("ctl00_Meio_ucRevisao_txtSenha").value = "";
        document.getElementById("ctl00_Meio_ucRevisao_txtSenhaConfirma").value = "";
        if(document.getElementById("cbGaragem").checked)
        {
            document.getElementById("tblGaragem").style.display = "block";            
        }   
        else
        {
            document.getElementById("tblGaragem").style.display = "none";
        }     
    }
    
   /* function setarHfMarcas(obj, btnSubmit)
    {   
        if(document.getElementById(obj).checked)
        {
            document.getElementById('ctl00_Meio_ucBuscaHome_ucBuscaRapidaHome_ucSelecionarMarcaModeloNovos_hfMarca').value += "," + document.getElementById(obj).value;
        }     
        else
        {
            document.getElementById('ctl00_Meio_ucBuscaHome_ucBuscaRapidaHome_ucSelecionarMarcaModeloNovos_hfMarca').value = document.getElementById('ctl00_Meio_ucBuscaHome_ucBuscaRapidaHome_ucSelecionarMarcaModeloNovos_hfMarca').value.replace(document.getElementById(obj).value, "0");
        }        
        document.getElementById(btnSubmit).click();
    } */
    function setarHfMarcas(obj, btnSubmit, hfMarca)
    {   
        if(document.getElementById(obj).checked)
        {
            document.getElementById(hfMarca).value += "," + document.getElementById(obj).value;            
        }     
        else
        {
            document.getElementById(hfMarca).value = document.getElementById(hfMarca).value.replace(document.getElementById(obj).value, "0");
        }        
        document.getElementById(btnSubmit).click();
    } 
    
function compararSenha()
{
    if(document.getElementById("cbGaragem").checked)
    {
        var txtSenha = document.getElementById("ctl00_Meio_ucRevisao_txtSenha");
        var txtSenhaConfirma = document.getElementById("ctl00_Meio_ucRevisao_txtSenhaConfirma");
        if (String(txtSenha.value).trim() != "")
        {
            if (txtSenha.value != txtSenhaConfirma.value)
            {                
                alert("Senha e Confirmação de senha não conferem");
                return false;
            }
        }    
            
        if (String(txtSenhaConfirma.value).trim() != "")
        {
            if (txtSenha.value != txtSenhaConfirma.value)
            {
                alert("Senha e Confirmação de senha não conferem");
                return false;
            }
        }    
        
        else 
        {
            if (String(txtSenha.value).trim() == "" || String(txtSenhaConfirma.value).trim() == "")
            {
                alert("Senha e Confirmação de senha obrigatorios");
                return false;
            } 
            else 
            {
                if (txtSenha.value != txtSenhaConfirma.value)
                {
                    alert("Senha e Confirmação de senha não conferem");
                    return false;
                }
            }
        }
    }
}

function closeIframe(idDiv, idIFrame)
{
    var form = window.parent.document.getElementsByTagName("form")[0];
    var myBackground = window.parent.document.getElementById( idDiv );
    var myDetails = window.parent.document.getElementById( idIFrame );
    
    if( myBackground && myDetails)
    {
        if( form )
        {
            form.removeChild( myDetails );
	        delete myDetails;

	        form.removeChild( myBackground );
	        delete myBackground;
        }
    }
}

function createIframe(idDiv, idIFrame, url,w, h)
{
        var myBackground = document.getElementById( idDiv );
        var form =  document.getElementsByTagName("form")[0];
        if( ! myBackground ){
	        if( form ){
	        
		        var myBackground = document.createElement("div");
		            myBackground.style.position = "absolute";
		            myBackground.id = idDiv;
		            myBackground.style.filter = "alpha(opacity=70)";
		            myBackground.style.opacity = 0.7;		
		            myBackground.style.width = getPageSize()[0] + "px";
		            myBackground.style.height = getPageSize()[1] + "px";
		            myBackground.style.left = "0px";
		            myBackground.style.top = "0px";
		            myBackground.style.backgroundColor = "#000000";		                        
		            myBackground.style.zIndex = 10000;
		            myBackground.overflow = "auto";
		        
		            form.appendChild( myBackground );
		        
                var myDetails = document.createElement( "iframe" );
                    myDetails.id = idIFrame;
                    myDetails.style.position = "absolute";
                    myDetails.setAttribute("class", "clsIframeGaragemCadastro");
                    myDetails.align = "center";
                    myDetails.frameBorder = 0;
                    myDetails.style.filter = "alpha(opacity=100)";
                    myDetails.style.width = w;
                    myDetails.style.height = h;
                    myDetails.style.left = (screen.width / 2) - 325 + "px";
                    myDetails.style.top = (getCoords()[1] + 50) + "px";                    
                    myDetails.style.zIndex = 10001;
                    myDetails.scrolling = "yes"
                    myDetails.src = url;                    
                    form.appendChild( myDetails );
                
	        }
        }
    }
    
function verificarCheckbox()
{ 
    if(document.getElementById("ctl00_ctl00_Meio_Meio_ucManutencaoProgramada_rptVeiculosByUsuario_ctl01_ucCadastrarManutencaoProgramada_dvManutencao_cbRecorrente") != null)
    {
        if(document.getElementById("ctl00_ctl00_Meio_Meio_ucManutencaoProgramada_rptVeiculosByUsuario_ctl01_ucCadastrarManutencaoProgramada_dvManutencao_cbRecorrente").checked)
        {
            document.getElementById("ctl00_ctl00_Meio_Meio_ucManutencaoProgramada_rptVeiculosByUsuario_ctl01_ucCadastrarManutencaoProgramada_dvManutencao_cbGarantia").disabled = true;
        }
        else
        {
            document.getElementById("ctl00_ctl00_Meio_Meio_ucManutencaoProgramada_rptVeiculosByUsuario_ctl01_ucCadastrarManutencaoProgramada_dvManutencao_cbGarantia").disabled = false;
        }
        
        if(document.getElementById("ctl00_ctl00_Meio_Meio_ucManutencaoProgramada_rptVeiculosByUsuario_ctl01_ucCadastrarManutencaoProgramada_dvManutencao_cbGarantia").checked)
        {
            document.getElementById("ctl00_ctl00_Meio_Meio_ucManutencaoProgramada_rptVeiculosByUsuario_ctl01_ucCadastrarManutencaoProgramada_dvManutencao_cbRecorrente").disabled = true;
        }
        else
        {
            document.getElementById("ctl00_ctl00_Meio_Meio_ucManutencaoProgramada_rptVeiculosByUsuario_ctl01_ucCadastrarManutencaoProgramada_dvManutencao_cbRecorrente").disabled = false;
        }
    }
}


function ExcluirImagemVeiculo(file, id)
{
        var controle = document.getElementById("ctl00_ctl00_Meio_Meio_hfImagem");
        controle.value = file;
        controle = document.getElementById(id + "_dvVeiculo_imgExcluirImagem");
        controle.click();
}

 function fnShowDateField(){
            var controle = document.getElementById("ctl00_ctl00_Meio_Meio_ucHistorico_divDateField")
            var ddlPeriodoPesquisa = document.getElementById("ctl00_ctl00_Meio_Meio_ucHistorico_ddlPeriodoPesquisa");
            var txtDateField = document.getElementById("ctl00_ctl00_Meio_Meio_ucHistorico_txtDateField");
            txtDateField.value = "";
            if (ddlPeriodoPesquisa.value == "4"){
                controle.style.display="inline";
            } else {
                controle.style.display="none";
            }
        }


function Formata_CPF_CNPJ(Campo, teclapres) {

    var vr = new String(Campo.value);
    vr = vr.replace(".", "");
    vr = vr.replace(".", "");
    vr = vr.replace("/", "");
    vr = vr.replace("-", "");
    vr = vr.replace(" ", "");

    var nonNumbers = /\D/;
    if (nonNumbers.test(vr))
        teclapres.returnValue = false;
    else {

        if (vr.length <= 11)
            return FormataCPF(Campo,teclapres);
        else
            return FormataCNPJ(Campo,teclapres);
    }
}

function FormataCPF (Campo, teclapres) {

    if(window.event)
    {
        var tecla = teclapres.keyCode;
    }
    else  
        tecla = teclapres.which;

    var vr = new String(Campo.value);
    vr = vr.replace(".", "");
    vr = vr.replace(".", "");
    vr = vr.replace("/", "");
    vr = vr.replace("-", "");
    vr = vr.replace(" ", "");


    var nonNumbers = /\D/;
    if (nonNumbers.test(vr))
        teclapres.returnValue = false;
    else {
    
        tam = vr.length;
        
        if (tecla != 9 && tecla != 8)
        {
            if (tam < 3)
                Campo.value = vr;
            if ((tam >= 3 && tam <= 5) && (tam != 3 || tecla != 46))
                Campo.value = vr.substr(0,3) + '.' + vr.substr(3,tam-3);
            if ((tam >= 6 && tam <= 8) && (tam != 6 || tecla != 46))
                Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
            if ((tam >= 9 && tam <= 11) && (tam != 9 || tecla != 45))
                Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
        }
    }
}

function FormataCNPJ(Campo, teclapres)
{
    if(window.event)
    {
        var tecla = teclapres.keyCode;
    }
    else  
        tecla = teclapres.which;

    var vr = new String(Campo.value);
    vr = vr.replace(".", "");
    vr = vr.replace(".", "");
    vr = vr.replace("/", "");
    vr = vr.replace("-", "");
    vr = vr.replace(" ", "");


    var nonNumbers = /\D/;
    if (nonNumbers.test(vr))
        teclapres.returnValue = false;
    else {
    
        tam = vr.length + 1;

        if (tecla != 9 && tecla != 8)
        {
            if (tam <= 2)
                Campo.value = vr;   
            if ((tam > 2 && tam < 6) && (tam != 3 || tecla != 46))
                Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
            if ((tam >= 6 && tam < 9) && (tam != 6 || tecla != 46))
                Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
            if ((tam >= 9 && tam < 13) && (tam != 9 || tecla != 47))
                Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
            if ((tam >= 13 && tam < 15) && (tam != 13 || tecla != 45))
                Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
        }
    }
}

function valida_CPF_CNPJ(obj,event){
    valor = obj.value;
    valor = valor. replace (".","");
    valor = valor. replace (".","");
    valor = valor. replace ("-","");
    valor = valor. replace ("/","");
    
    if (valor.length <= 11)
        return verifica_cpf(obj,event);
    else
        return validaCNPJ(obj,event);
}

//valida CPF
function verifica_cpf(obj,event){

	VlScan_cpf1 = obj.value;
	
	//Não faz a validação em caso de campo vazio
	if (VlScan_cpf1.length == 0)
	    return true;

	var valido = true;
	var VlSErr = '';
	
	VlScan_cpf2 = VlScan_cpf1.replace(".","");
	VlScan_cpf3 = VlScan_cpf2.replace("-","");
	VlScan_cpf = VlScan_cpf3.replace(".","");
	
	var st = VlScan_cpf;
	var validoc = true;

	var VlSAUXCPF = '';
	var VlSCount = 0;
	var VlSLen = st.length;
	for ( x = 0; x < VlSLen; x++ ) {
		if ( x == 0 ){
			VlSAUXCPF = st.substring(x,x+1);
		}
		if ( VlSAUXCPF == st.substring(x,x+1) ){
			VlSCount ++;	
		}
	}

	if (st == "")
	validoc = false;
	l = st.length;

	//aleterado para se usuário não digitar os zeros na frente do CPF, completar sozinho
	if ((l == 9) || (l == 8))
	{
	for (i = l ; i < 10; i++)
	{
	st = '0' + st
	}
	}
	l = st.length;
	st2 = "";
	for (i = 0; i < l; i++) {
	caracter = st.substring(i,i+1);
	if ((caracter >= '0') && (caracter <= '9'));
	st2 = st2 + caracter;
	}
	if ((st2.length > 11) || (st2.length < 10))
	validoc = false;
	if (st2.length==10)
	st2 = '0' + st2;
	digito1 = st2.substring(9,10);
	digito2 = st2.substring(10,11);
	digito1 = parseInt(digito1,10);
	digito2 = parseInt(digito2,10);
	sum = 0; mul = 10;
	for (i = 0; i < 9 ; i++) {
	digit = st2.substring(i,i+1);
	tproduct = parseInt(digit ,10) * mul;
	sum += tproduct;
	mul--;
	}
	dig1 = ( sum % 11 );
	if ( dig1==0 || dig1==1 )
	dig1=0;
	else
	dig1 = 11 - dig1;
	if (dig1!=digito1)
		validoc = false;
		sum = 0;
		mul = 11;
	for (i = 0; i < 10 ; i++) {
		digit = st2.substring(i,i+1);
		tproduct = parseInt(digit ,10)*mul;
		sum += tproduct;
		mul--;
	}
	dig2 = (sum % 11);
	if ( dig2==0 || dig2==1 )
		dig2=0;
	else
		dig2 = 11 - dig2;
	if (dig2 != digito2)
		validoc = false;
	//return (true);

if (validoc == false || VlSCount == VlSLen ) {
	VlSErr += 'CPF Incorreto \n' + String.fromCharCode(160);
	obj.focus();
	obj.value = '';
	valido = false;
}

if ( valido == false ){
	alert(VlSErr); 
}

return valido;
}

//valida CNPJ
function validaCNPJ(obj,event) 
{
     CNPJ = obj.value;
    
     //Não faz a validação em caso de campo vazio
     if (CNPJ.length == 0)
	     return true;

     erro = new String;
     
     //substituir os caracteres que não são números
     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 ("/","");
    }
    
    if (CNPJ.length < 14)
    { 
        erro = "CNPJ Incorreto! \n\n";
    }    
    
    var nonNumbers = /\D/;
    if (nonNumbers.test(CNPJ)) erro += "A verificação 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 ="CNPJ Incorreto!";
    }
    if (erro.length > 0)
    {
        alert(erro);
        obj.focus();
	    obj.value = '';
        return false;
    } 
    return true;
}

function exibirDivTelefone(id1, id2, id3)
{
    if(document.getElementById(id1).style.display == "none")
        document.getElementById(id1).style.display = "block";
    else
        document.getElementById(id1).style.display = "none";    
        
        document.getElementById(id2).style.display = "block";   
        document.getElementById(id3).style.display = "block";   
}

function exibirDivTelefonePopUp(id1, id2, id3)
{
    if(document.getElementById(id1).style.display == "none")
        document.getElementById(id1).style.display = "block";
    else
        document.getElementById(id1).style.display = "none";    
        
        document.getElementById(id2).style.display = "block";   
        document.getElementById(id3).style.display = "block";   
    
    var myDetails = window.parent.document.getElementById("idIFrame");
    myDetails.style.height = "723px";
}


//formata campos
function txtBoxFormat(strField, sMask, event) 
{
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

    if(isIE) 
    { 
        nTecla = event.keyCode; 
    }
    else if(isWin) 
    { 
        nTecla = event.which;
    }
    
    var chrDigito = String.fromCharCode(nTecla);


    sValue = strField.value;

    // Limpa todos os caracteres de formatação que estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
	    bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
	    bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

    if (bolMask) {
	    sCod += sMask.charAt(i);
	    mskLen++; }
    else {
	    sCod += sValue.charAt(nCount);
	    nCount++;
    }
    i++;
    }

    strField.value = sCod;
    
    if (nTecla != 8) 
    { // backspace
	    if (sMask.charAt(i-1) == "9") 
	    { // apenas números...
		    return ((nTecla > 47) && (nTecla < 58)); 
        } // números de 0 a 9
	    else 
	    {   
	        if( parseInt(nTecla) > parseInt(58) )
	        {
	            return true;
		    }
		    else
		    { 
		        return false; 
		    }  
		  
	    }
    }
    else 
    {
	    return true;
    }
}



function verificarServico()
{
    verificador = "Serviços em garantia";
    
    ddlServico = document.getElementById("ctl00_Meio_ucRevisao_ddlServico");
    txtDtAquisicao = document.getElementById("ctl00_Meio_ucRevisao_txtDtAquisicao");
    alert(unescape(verificador));
    //alert(ddlServico.options[ddlServico.selectedIndex].text.replace("ç","c"));
    //alert(ddlServico.options[ddlServico.selectedIndex].text.toString().replace("ç","c")+"/"+("Servicos em garantia").toString())
    if(String(ddlServico.options[ddlServico.selectedIndex].text).toString().replace("ç","c") == ("Servi&ccedil;os em garantia").toString())
    {
        alert('a');
        if (String(txtDtAquisicao.value).trim() == "")
        {
            alert('Preencha a Data de Compra do Veículo');
            txtDtAquisicao.focus();
            return false;
        }
    }       
}











function exibirNovoAgendamento(id)
{   
    if(document.getElementById("div_NovoAgendamento_"+id).style.display == "block")
    {
        document.getElementById("div_NovoAgendamento_"+id).style.display = "none";
    }
    else
    {
        document.getElementById("div_NovoAgendamento_"+id).style.display = "block";
       
    }        
    document.getElementById("agendamentos_"+id).style.display = "none";
}


function exibirAgendamentos(id)
{
    if(document.getElementById("agendamentos_"+id).style.display == "block")
    {
        document.getElementById("agendamentos_"+id).style.display = "none";
    }
    else
    {
        document.getElementById("agendamentos_"+id).style.display = "block"; 
       
        
    }       
     document.getElementById("div_NovoAgendamento_"+id).style.display = "none"; 
}

function exibirGraficoAbastecimentos(id) 
{    
    document.getElementById("graficoAbastecimentos_"+id).style.display = "block";
    document.getElementById("abastecimentos_"+id).style.display = "none";
    document.getElementById("div_NovoAbastecimento_"+id).style.display = "none";
}

function exibirAbastecimentos(id)
{
    if(document.getElementById("abastecimentos_"+id).style.display == "block")
    {
        document.getElementById("abastecimentos_"+id).style.display = "none";
    }
    else
    {
        document.getElementById("abastecimentos_"+id).style.display = "block"; 
        document.getElementById("div_NovoAbastecimento_"+id).style.display = "none";
        document.getElementById("graficoAbastecimentos_"+id).style.display = "none";
    }        
}

function exibirNovoAbastecimento(id)
{   
    if(document.getElementById("div_NovoAbastecimento_"+id).style.display == "block")
    {
        document.getElementById("div_NovoAbastecimento_"+id).style.display = "none";
    }
    else
    {
        document.getElementById("div_NovoAbastecimento_"+id).style.display = "block";
        document.getElementById("abastecimentos_"+id).style.display = "none";
        //document.getElementById("ctl00_ctl00_Meio_Meio_ucManutencaoProgramada_hfNovaManutencao").value = "1";   
    }        
}

function validarCadastroKm(txtKm)
{
    if(String(txtKm.value).trim() == "")
    {
        alert("Preencha a Km!");
        return false;
    }
}

function validarCadastroVeiculo(obj)
{
    ddlMarca = document.getElementById(obj+"_dvVeiculo_ddlMarca");
    ddlModelo = document.getElementById(obj+"_dvVeiculo_ddlModelo");
    ddlVersao = document.getElementById(obj+"_dvVeiculo_ddlVersao");
    txtPlaca = document.getElementById(obj+"_dvVeiculo_txtPlaca");
    txtKmAtual = document.getElementById(obj+"_dvVeiculo_txtKmAtual");
    txtCondutor = document.getElementById(obj+"_dvVeiculo_txtCondutor");
    
    mensagem = "";
    
    if(parseInt(ddlMarca.selectedIndex) <= 0)
    {
        mensagem += "Selecione a Marca!\n"
    }
    
    if(parseInt(ddlModelo.selectedIndex) <= 0)
    {
        mensagem += "Selecione o Modelo!\n"
    }
    
    if(parseInt(ddlVersao.selectedIndex) <= 0)
    {
        mensagem += "Selecione a Versão!\n"
    }
    
    if(String(txtPlaca.value).trim() == "")
    {
        mensagem += "Preencha a Placa!\n"        
    }
    
    if(String(txtKmAtual.value).trim() == "")
    {
        mensagem += "Preencha a Km Atual!\n"        
    }
    
    if(String(txtCondutor.value).trim() == "")
    {
        mensagem += "Preencha o Nome do Condutor!\n"        
    }   
    
    
     if(String(mensagem).trim() != "")
     {
        alert(mensagem);
        return false;
     }
    
}

function fnConfirmaDel()
{
    return confirm('Deseja realmente excluir o registro');
}


function validaAbastecimento(id)
{

    if(String(document.getElementById(id + "_txtDtDatRealizado").value).trim() == "")
    {
        alert('Preencha o campo Data.');
        return false;
    }
    if(String(document.getElementById(id + "_txtKm").value).trim() == "")
    {
        alert('Preencha o campo Km rodados.');
        return false;
    }
    
    if(String(document.getElementById(id + "_txtInLtAbastece").value).trim() == "")
    {
        alert('Preencha o campo Vol. Abastecido.');
        return false;
    }
    
    if(String(document.getElementById(id + "_ddlCombustivel").value).trim() == "")
    {
        alert('Preencha o campo Combustível.');
        return false;
    }
    
    if(String(document.getElementById(id + "_txtNuVlAbastecido").value).trim() == "")
    {
        alert('Preencha o campo Valor Pago.');
        return false;
    }
    
}

function limpaCampo(obj)
{
    obj.value = "";
}

function validaCadastroManutencao(obj)
{
    if(String(document.getElementById(obj + "_dvManutencao_txtKm").value).trim() == "" && 
       String(document.getElementById(obj + "_dvManutencao_txtLembrar").value).trim() == "" &&
       String(document.getElementById(obj + "_dvManutencao_txtData").value).trim() == "")
    {
        alert('Preencha o campo Lembrar com (Km) ou Lembrar no periodo ou Lembrar na Data.');
        return false;
    }    
}

function confirmDel()
{
    return confirm('Confirma a exclusão do veículo?');
}
