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 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.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.location.replace('Blindados.aspx');

	}


//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 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;
    }
}

// Validação de campo Data
// onkeypress="return formatarData(this,event);" onblur="validarData(this);"

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 (typeof obj.value != 'undefined') {
        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();
        }
    }
}


/// #Inicio
///Funcões usadas no painel de compare modelos 0 km para os projetos novos / e no usercontrol de modelos novos para o layout antigo abrac

//funcao usada para criar a div flutuante
function AbrirDivFlutuanteOver(src) {
    FecharDivFlutuante();
    var id = "divModelo" + src;
    window.document.getElementById(id).style.display = "inline";
    window.document.getElementById(id).style.display = "block";
    //esconder outros
}

//funcao usada para criar a div flutuante
function AbrirDivFlutuanteOut() {
    $(this).find("div.clsDivFlutBaseCompare").first().hide();
}

//funcao usada para fechar a div flutuante
function FecharDivFlutuante() {
    var divs = window.document.getElementsByTagName("DIV");
    for (var i = 0; i < divs.length; i++) {
        if (divs[i].className == "clsDivFlutBaseCompare") {
            divs[i].style.display = "inline";
            divs[i].style.display = "none";
        }
    }
}


//Funcao usada para o link da home do layout padrao abrac para montar a pagina de compare modelos
function CompararModelos0km() {
    //recupera o chek de modelo
    var checksSecundario = window.document.getElementsByName("chkModeloCompare");
    var modelos = "";
    var conta = 0;
    var validado = 0;

    //procura todos os modelos checados para a busca
    for (var i = 0; i < checksSecundario.length; i++) {
        if (checksSecundario[i].checked) {
            conta = conta + 1;
            if (modelos == "") {
                modelos = modelos + checksSecundario[i].value;
            }
            else {
                modelos = modelos + "," + checksSecundario[i].value;
            }
            checksSecundario[i].checked = false;
        }
    }

    /// verifica se possui mais de 3 modelos selecionados se possuir ele passa a variavel validado para 1 
    /// e retorna para a tela pois podemos selecionar no maximo 3 modelos
    if (conta > 3) {
        validado = 1;
    }

    // verifica se a variavel validado esta ok para prosseguir o redirect para a pagina de comparação
    if (validado == 0) {
        // se a variavel modelos foi preenchida ele redireciona para a pagina correta
        // se nao volta para a tela para que o usuario selecione algum modelo
        if (modelos == "" || modelos == null) {
            alert("Selecione o modelo desejado");
        }
        else {
            window.location.replace("CompararVersoes.aspx?mo=" + modelos);
        }
    }
    else {
        alert("Selecione no maximo 3 modelos");
    }
}

///valida os modelos selecionados
function ValidarCompararModelos0km() {
    var checksSecundario = window.document.getElementsByName("chkModeloCompare");
    var checksSecundario = window.document.getElementsByName("chkModeloCompare");
    var divImBtComparar01 = window.document.getElementById("divImBtComparar01");

    var conta = 0;

    divImBtComparar01.style.display = "none";

    //verfica os modelos checados
    for (var i = 0; i < checksSecundario.length; i++) {
        if (checksSecundario[i].checked) {
            conta = conta + 1;
        }
    }

    //bloqueia ou desbloqueia os modelos conforme a quantidade selecionada
    if (conta == 3) {
        for (var i = 0; i < checksSecundario.length; i++) {
            if (checksSecundario[i].checked) {
                checksSecundario[i].disabled = false;
            }
            else {
                checksSecundario[i].disabled = true;
            }
        }
    }
    else {
        for (var i = 0; i < checksSecundario.length; i++) {
            checksSecundario[i].disabled = false;
        }
    }

    if (conta >= 1) {
        divImBtComparar01.style.display = "inline";
    }
    else {
        divImBtComparar01.style.display = "none";
    }
}

///Funcões usadas no painel de compare modelos 0 km para os projetos novos / e no usercontrol de modelos novos para o layout antigo abrac
/// #Fim
