function changeColor(id){
	$(id).setStyle("background-color", "#E9E8E3");
}

function deleteColor(id){
	$(id).setStyle("background-color", "#FAF9F3");
}

// Função para mudar elemento para display: block
// @param {String || HTMLElement} el

function show(el){
	$(el).setStyle("display", "block");
}


// Função para mudar elemento para display: none
// @param {String || HTMLElement} el

function hide(el){
	$(el).setStyle("display", "none");
}


// Função para alternar elemento entre display: none e block
// @param {String || HTMLElement} el

function toggle(el){
	var el = $(el);
	if(!el){ return; }
	var val = (el.getStyle("display") == "none") ? "block" : "none";
	el.setStyle("display", val);
}


// Corrige bug do menu flash ficar na frente do conteudo HTML em todos os browsers menos o IE
// @param {Number} acao: valor 1 traz menu para a frente, qualquer outro valor leva menu para tras

function changeLayerMenu(acao){
	//alert("entrou");

	
	if(acao==1) {
		var z_topo = 5000;
		var z_conteudo = 10;
	} else {
		var z_topo = 10;
		var z_conteudo = 5000;
	}
	
	$("topo").setStyle("zIndex", z_topo);
	$("conteudo").setStyle("zIndex", z_conteudo);
}

//Função para correção de Bug no ie7 com menu superior e a função acima
function verificaBrowser(){
	var ua = navigator.userAgent.toLowerCase();
	if(!/msie/.test(ua)){
		return 1;
	}else{
		return 0;
	}
}

function initAccordion(){
	// Efeito sanfona
	// cria icones na esquerda e direita
	var els = $$(".g_toggler");
	els.forEach(
		function(el){
			var txt = el.innerHTML;
			el.innerHTML = '<span class="g_toggler_left"></span>' + txt + '<span class="g_toggler_right"></span>';
		}
	);
	// inicializa efeito sanfona
	new Accordion(
		$$(".g_toggler"),
		$$(".g_stretcher"),
		{
			onActive: function(el){
				el.addClass("current");
			},
			onBackground: function(el){
				el.removeClass("current");
			}
		}
	);
}

function initPrint(intAction){
	if(intAction == 0){
		// Inicia função de impresão
		var els = $$(".s_bt_print");
		els.forEach(
			function(els){
				els.onclick = function () {
					window.print();
				};
			}
		);
	}else{
		window.print();
	}
}

//funcao que chama POPUPS pelo Flash

function callPOP(endereco, titulo, w, h){
	TB.frameShow(endereco, titulo, w, h);
	window.scrollTo(0,0);
}

function callPOPCadastro(endereco, titulo, w, h){
	TB.frameShowCadastro(endereco, titulo, w, h);
	window.scrollTo(0,0);
	
}

function callPOP_default(endereco, titulo, w, h){
	TB.frameShow_default(endereco, titulo, w, h);
	window.scrollTo(0,0);
}


// função para fechar pop e redirecionar
function redirectTo(redirectTo) {
	location.href = redirectTo;
	//TB.remove('TB_iframe');
}


function limpa_campo(campo,valor_padrao) {
	if(campo.value==valor_padrao) {
		campo.value='';
	}
}

function completa_campo(campo,valor_padrao) {
	if(campo.value=='') {
		campo.value=valor_padrao;
	}
}

//Codifica string
function escapeTxt(os){
	var ns='';
	var t;
	var chr='';
	var cc='';
	var tn='';
	for(i=0;i<256;i++){
		tn=i.toString(16);
		if(tn.length<2)tn="0"+tn;
		cc+=tn;
		chr+=unescape('%'+tn);
	}
	cc=cc.toUpperCase();
	os.replace(String.fromCharCode(13)+'',"%13");
	for(q=0;q<os.length;q++){
		t=os.substr(q,1);
		for(i=0;i<chr.length;i++){
			if(t==chr.substr(i,1)){
				t=t.replace(chr.substr(i,1),"%"+cc.substr(i*2,2));
				i=chr.length;
			}
		}
		ns+=t;
	}
	return ns;
}

function enterPressed(e, id_campo) 
{     
       if (e.keyCode) code = e.keyCode;
       else if (e.which) code = e.which; // Netscape 4.?
       else if (e.charCode) code = e.charCode; // Mozilla
        
       if( code == 13 ) {  
            if (e.preventDefault) {
                e.preventDefault();
            } else {
                e.returnValue = false;
            }

            
			var campo=document.getElementById(id_campo);
			
			var string_padrao="\(CEP\) ou \(Nome\) ou \(Cidade/UF\)";
			if(string_padrao==campo.value) 
			{
				alert("Digite uma palavra para a busca");
				campo.focus();
			}else {
				callPOP('http://webservices.maplink2.com.br/renault2/lista.aspx?type=geral&value=' + escapeTxt(campo.value)
					, "Busca de Concession&aacute;rias", 1000, 554);
				campo.value = string_padrao;
				
				
			}
			
       }
      
	  
	
}
function busca_concessionaria(id_campo) {
	var campo=document.getElementById(id_campo);
	var string_padrao="\(CEP\) ou \(Nome\) ou \(Cidade/UF\)";
	if(string_padrao==campo.value) {
		alert("Digite uma palavra para a busca");
		campo.focus();
	}
	else {
		callPOP('http://webservices.maplink2.com.br/renault2/lista.aspx?type=geral&value=' + escapeTxt(campo.value)
			, "Busca de Concession&aacute;rias", 1000, 554);
		campo.value = string_padrao;
	}
}

/*function TagCounter(nomeTag)
{
	var intervalo = window.setInterval(setTagName, 1000);
	function setTagName() {
		_ATM.ATMFC(nomeTag);
	}
	clearInterval(intervalo);
	//atmCLL(nomeTag);	
}*/

function TagCounter(nomeTag)
{
	//atmCLL(nomeTag);
	_ATM.ATMFC(nomeTag);
}

function ZindexMonteOSeu1(){
	$("home_monte_o_seu").setStyle("z-index", "10000");
}

function ZindexMonteOSeu0(){
	$("home_monte_o_seu").setStyle("z-index", "-10000");
}

function ZindexDestaque1(){
	$("Novodestaque_home").setStyle("z-index", "10000");
}

function ZindexDestaque0(){
	$("Novodestaque_home").setStyle("z-index", "5001");
}


		function Zindex1(){
				
			$("rodape").setStyle("z-index", "5000");

		}
		function Zindex0(){
			
			$("rodape").setStyle("z-index", "0");
		
		
		}



//metodo para mude a direção
function mudarHome(){
	jQuery("#Novodestaque_home").css("height", "338px");
	//jQuery("#Novodestaque_home").find("object").attr("height", "338px");
	jQuery("#subconteudo").css("height", "171px");
	//alert("TESTE");
	var ufo_destaque_inferior = {movie:"swf/home/destaqueInferior.swf", width:"944", height:"146", wmode:"transparent", majorversion:"8", build:"40"};
	UFO.create(ufo_destaque_inferior, "destaqueHome2010");
}		
		
/*Metodo de busca do configurador*/

//metodo por cep
function buscaMonteoSeu_cep(cep)
{
	//alert(cep);
	url = 'http://webservices.maplink2.com.br/renault2/lista.aspx?type=geral&value='+cep;
	window.parent.TB.frameShow(url, "Busca de Concession&aacute;rias", "1000", "554");
}

//metodo por cidade e estado
function buscaMonteoSeu_cidade(estado,cidade)
{
	//alert(estado+"     "+cidade);
	url = 'http://webservices.maplink2.com.br/renault2/lista.aspx?type=cidade&value=' + estado+ cidade; 
	//window.parent.TB.frameShow(url, "Buscar Concession&aacute;rias", "1000", "554");
	//openIframe(url, 1000, 554)
	TB.frameShow(url, "Busca de Concession&aacute;rias", "1000", "554");
}

/*Imprimir configurador*/
function imprimirMonteSeu(idModelo, tipoVersao, codigoVersao, anoModelo, anoFabricacao, preco, cor, adesivo, packOpcional, nomeVersao)
{
	if (adesivo == null ||adesivo == "" )
		adesivo = "_";
		
	var url = Base.source.SitePath+"ImprimirMonteSeu.aspx?idCarro="+idModelo+"&Versao="+tipoVersao+"&codVersao="+codigoVersao+"&anoModelo="+anoModelo+"&anoFabri="+anoFabricacao+"&preco="+preco+"&cor="+cor+"&pack="+packOpcional+"&nomeVersao="+nomeVersao+"&adesivo="+adesivo;
	openIframe(url, 770, 550);
}

function imprimirAcessorios(url, altura, largura)
{
	openIframe(url, altura, largura);
}

function goTwitter(url, carro)
{
	
	jQuery.getJSON('http://json-tinyurl.appspot.com/?url=' + url + '&callback=?', 
        function(data)
        { 
			urlNova = data.tinyurl;
			//alert(urlNova);
			window.open("http://twitter.com/home?status=Monte o seu "+carro + urlNova, '_blank');
        }
    );
}

//Funções utilizadas na consulta de acessórios
function CarregaListaDDLModeloPaginacao(pagina)
{
	AjaxAcessorios(jQuery("#ddlCarros1").val(), jQuery("#ddlCategorias1").val(), pagina);
}

function CarregaListaDDLModeloVeiculo()
{
	AjaxAcessorios(jQuery("#ddlCarros1").val(), 1, 1);
}			

function CarregaListaDDLModelo()
{
	AjaxAcessorios(jQuery("#ddlCarros1").val(), jQuery("#ddlCategorias1").val(), 1);
}
			
function AjaxAcessorios(idM, idC, pagina)
{
	jQuery.ajax(
		{
			type: "POST",
			url: '/ajax/ConsultaAcessorios.aspx',
			data: { idModel: idM, idCategoria:idC, paginaAtual:pagina},
			dataType: 'json',
			success: function(data) {
				//Recebe os dados e passa para as variáveis
				var ListaAcessorio = data[0];
				var qtdPaginas = data[1];
				var paginaAtual = data[2];
				var PaginacaoAcessorios = data[3];
				var ddlCategoria = data[4];
				var imgModelo = data[5];
				
				//Insere a imagem do veículo
				jQuery("#s_col_carro").html("<img border='0' alt='' src='"+ imgModelo +"' id='imgModelo'>");
				//Insere a lsita de acessorios
				jQuery("#dvListaAcessorios").html(ListaAcessorio);
				//substitui a lista de acessorios
				jQuery("#dvCategorias1").html("");
				jQuery("#dvCategorias1").html(ddlCategoria);
				//Seta o valor na lista de acessorios
				jQuery("select[id=ddlCategorias1]").val(idC);
				//Insere a paginação
				jQuery("#dvPaginacao").html(PaginacaoAcessorios);
				//Grava a página atual em uma div
				jQuery("#pAtual").html(paginaAtual);
				
				//Grifa a o número da página atual
				jQuery(".paginacao_atual"+paginaAtual).css('text-decoration','underline');
				
				//Carrega ou esconde os botões "próximo" e "anterior"
				CarregaBotoes(qtdPaginas, paginaAtual);
		}

	});
}

function CarregaBotoes(qtdPaginas, paginaAtual)
{
	if (qtdPaginas <= 1)
	{
		jQuery("#dvAnterior").css('display', 'none');
		jQuery("#dvProximo").css('display', 'none');
	}
	else
	{
		jQuery("#dvAnterior").css('display', 'inline');
		jQuery("#dvProximo").css('display', 'inline');
	}
	if (paginaAtual == 1)
		jQuery("#dvAnterior").css('display', 'none');
	if (paginaAtual == qtdPaginas)
		jQuery("#dvProximo").css('display', 'none');				
}
//--------------------fim

//--------------------Consulta Chassi Área de Recall Veículos

function valida_chassi()
{
	jQuery("#alert").html("display","block");
	jQuery("#alert").html("O chassi deve conter 8 digitos");
	//alert("Utilize os 8 &uacute;ltimos digitos do seu chassi.");
	//jQuery("#NumeroChassi").css("border","1px solid red");
}

function esconde(){
	jQuery("#NumeroChassi").val("");
	jQuery('.boxRecall_baixo').css('display','block');
	jQuery('.recall_box4').css('display','none');
	jQuery('.recall_box2').css('display','none');
	jQuery('.recall_box5').css('display','none');
	
	//Ajuste para voltar a altura correta
	jQuery('.boxsRecall').attr("style", "");
	jQuery('.recall_box2_botoes').css("margin-top", "120px");	
	jQuery('.recall_box2_botoes').css("margin-left", "114px");
}



function search_by_chassi (val) {
	jQuery('#loadingRecall').css('display','block');

	var caminho = Base.source.SitePath + "recallPortal/Ajax/GetStatusRecallByChassi/" + val.toUpperCase();
	jQuery.ajax({
		type: "POST",
		url: caminho,
		dataType: 'json',
		success: function (response) {
			var chassi = response[0];
			var qtdItens = response[1];
			var idRecalls = response[2];

			//Dados do Recall
			var id = null;
			var status = null;
			var descricao = null;
			var anomodelo = null;
			var datainicial = null;
			var data = null;
			var width = null;
			var height = null;
			var modal = null;
			var cont = 0;

			//Verifica se o chassi possui recalls
			if (idRecalls.length == 0) {
				//jQuery(".replyto").html("Seu veículo não foi convocado para nenhum Recall anterior.");
				jQuery(".replyto").html("");
				jQuery(".replyto").html("N&atilde;o h&aacute; nenhum recall para o seu Renault.");
				jQuery('.numeroChassi').html(jQuery('#NumeroChassi').val().toUpperCase());
				jQuery('.boxRecall_baixo').css('display','none');
				jQuery('.recall_box4').css('display','block');
				
				//Set altura da box
				jQuery('.recall_box4_center').css("height", "125px");
				jQuery('.boxsRecall').css("height", "215px");
				//Set altura dos botões da box
				jQuery('.recall_box2_botoes').css("margin-top", "10px");
				
			}
			else {
				jQuery(".replyto").html("");
				
				var msg = "";
				var altura = 84+(idRecalls.length * 43);
				var alturabox = 120 + altura;
				jQuery(".boxsRecall").css("height", alturabox +"px");
				
				for (var i = 1; i <= idRecalls.length; i++) {
					id = idRecalls[i - 1][0];
					status = idRecalls[i - 1][1];
					descricao = idRecalls[i - 1][2];
					data = idRecalls[i - 1][3].split(" ");
					width = idRecalls[i - 1][4];
					height = idRecalls[i - 1][5];
					modal = idRecalls[i - 1][6];
					datainicial = data[0];
					
					
					
					if (status == "PENDENTE") {
						cont= cont+1;
						status = "<font color='red'>"+ status +"</font> ";
						if(datainicial == ""){
							msg = "<div style='color:#bd2727;font-weight:bold;'>Recall Pendente</div>&nbsp;- "+descricao+"<br><div style='margin-top:4px'><div style='width:171px;float:left; height:15px'></div><div class='maisRecall' style='margin-top:0px' onclick=\"Shadowbox.open({content:'" + Base.source.SitePath + "html/recall/" + modal + "',title:'Recall',height:" + height + ",width:" + width + ",player:'iframe'});\"></div></div><br><br>";
						}
						else{
							msg = "<div style='color:#bd2727;font-weight:bold;'>Recall Pendente</div>&nbsp;- "+descricao+"<br><div style='margin-top:4px'><div style='width:171px;'>Data de atendimento: " +datainicial.toString().split(" ", 1)+"</div><div class='maisRecall' style='margin-top:0px' onclick=\"Shadowbox.open({content:'" + Base.source.SitePath + "html/recall/" + modal + "',title:'Recall',height:" + height + ",width:" + width + ",player:'iframe'});\"></div></div><br><br>";
						}
					}
					else
					{
						if(datainicial == ""){
							msg = "<div style='color:#46a733;font-weight:bold;'>Recall Realizado</div>&nbsp;- "+descricao+"<br><div style='margin-top:4px'><div style='width:171px;float:left; height:15px'></div><div class='maisRecall' style='margin-top:0px' onclick=\"Shadowbox.open({content:'" + Base.source.SitePath + "html/recall/" + modal + "',title:'Recall',height:" + height + ",width:" + width + ",player:'iframe'});\"></div></div><br><br>";
						}
						else{
							msg = "<div style='color:#46a733;font-weight:bold;'>Recall Realizado</div>&nbsp;- "+descricao+"<br><div style='margin-top:4px'><div style='width:171px;'>Data de atendimento: " +datainicial.toString().split(" ", 1)+"</div><div class='maisRecall' style='margin-top:0px' onclick=\"Shadowbox.open({content:'" + Base.source.SitePath + "html/recall/" + modal + "',title:'Recall',height:" + height + ",width:" + width + ",player:'iframe'});\"></div></div><br><br>";
						}
					}
					jQuery(".replyto").append(msg);
				}
				if(cont>0){
					jQuery('.boxRecall_baixo').css('display','none');
					jQuery('.recall_box2').css('display','block');
					jQuery('.recall_box5').css('display','none');
				}
				else{
					jQuery('.boxRecall_baixo').css('display','none');
					jQuery('.recall_box2').css('display','none');
					jQuery('.recall_box5').css('display','block');
					
				}
				
				jQuery('.numeroChassi').html(jQuery('#NumeroChassi').val().toUpperCase());
				
				jQuery('.recall_box2_center').css("height", altura +"px");
				jQuery('.recall_box4_center').css("height", altura +"px");
				jQuery('.recall_box5_center').css("height", altura +"px");
				
				//Altura dos botoes
				/*var alturabotao = 0;
				if (idRecalls.length > 1)
				{
					alturabotao = jQuery('.recall_box2_center').height() - 170;
					if((jQuery.browser.msie) && (jQuery.browser.version == "9.0"))
						{
							alturabotao = jQuery('.recall_box2_center').height() - 445;
						}
					jQuery('.recall_box2_botoes').attr("style", "");
					jQuery('.recall_box2_botoes').css("margin-top", alturabotao + "px");
				}
				else
				{
					alturabotao = 54;
					jQuery('.recall_box2_botoes').attr("style", "");
					jQuery('.recall_box2_botoes').css("margin-top", alturabotao + "px");
				}*/
			}
			jQuery('#loadingRecall').css('display','none');
		}
	});

}

function somenteNumero(e)
				{
					var tecla=(window.event)?event.keyCode:e.which;   
					if((tecla>47 && tecla<58)) return true;
					else
					{
							if (tecla==8 || tecla==0) return true;
							else  return false;
					}
				}	
						

function search_by_chassi_print (val) {
	
	var caminho = Base.source.SitePath + "recallPortal/Ajax/GetStatusRecallByChassi/" + val.toUpperCase();
	jQuery.ajax({
		type: "POST",
		url: caminho,
		dataType: 'json',
		success: function (response) {
			var chassi = response[0];
			var qtdItens = response[1];
			var idRecalls = response[2];

			//Dados do Recall
			var id = null;
			var status = null;
			var descricao = null;
			var anomodelo = null;
			var datainicial = null;
			var data = null;
			var cont = 0;

			//Verifica se o chassi possui recalls
			if (idRecalls.length == 0) {
				//jQuery(".replyto").html("Seu veículo não foi convocado para nenhum Recall anterior.");
				jQuery(".replyto").html("");
				jQuery(".replyto").html("N&atilde;o h&aacute; nenhum recall para o seu Renault.");
				jQuery('.numeroChassi').html(jQuery('#NumeroChassi').val().toUpperCase());
				jQuery('.boxRecall_baixo').css('display','none');
				jQuery('.recall_box4').css('display','block');
				
			}
			else {
				jQuery(".replyto").html("");
				
				var msg = "";
				
				for (var i = 1; i <= idRecalls.length; i++) {
					id = idRecalls[i - 1][0];
					status = idRecalls[i - 1][1];
					descricao = idRecalls[i - 1][2];
					data = idRecalls[i - 1][3].split(" ");
					datainicial = data[0];
					
					if (status == "PENDENTE") {
							cont= cont+1;
							status = "<font color='red'>"+ status +"</font> ";
							if(datainicial == ""){
								msg = "<div style='color:#bd2727;float: left; width: auto;'><span style='font-weight:bold;'>Recall Pendente</span></div>&nbsp;- "+descricao+"<br><br>";
							}
							else{
								msg = "<div style='color:#bd2727;float: left; width: auto;'><span style='font-weight:bold;'>Recall Pendente</span></div>&nbsp;- "+descricao+"<br>Data de atendimento: " +datainicial.toString().split(" ", 1)+"<br><br>";
							}
							
							/*msg = "<div style='color:#bd2727;float: left; width: auto;'><span style='font-weight:bold;'>Recall Pendente</span></div>&nbsp;- "+descricao+"<br>Data de atendimento: " +datainicial.toString().split(" ", 1)+"<br><br>";
							}
							else
							{
							msg = "<div style='color:#46a733;float: left; width: auto;'><span style='font-weight:bold;'>Recall Realizado</span></div>&nbsp;- "+descricao+"<br>Data de atendimento: " +datainicial.toString().split(" ", 1)+"<br><br>";*/
					}
					
					else
					{
						if(datainicial == ""){
							msg = "<div style='color:#46a733;float: left; width: auto;'><span style='font-weight:bold;'>Recall Realizado</span></div>&nbsp;- "+descricao+"<br><br>";
						}
						else{
							msg = "<div style='color:#46a733;float: left; width: auto;'><span style='font-weight:bold;'>Recall Realizado</span></div>&nbsp;- "+descricao+"<br>Data de atendimento: " +datainicial.toString().split(" ", 1)+"<br><br>";
						}
					}
					
					jQuery(".replyto").append(msg);
				}
				if(cont>0){
					jQuery('.boxRecall_baixo').css('display','none');
					jQuery('.recall_box2').css('display','block');
					jQuery('.recall_box5').css('display','none');
				}
				else{
					jQuery('.boxRecall_baixo').css('display','none');
					jQuery('.recall_box2').css('display','none');
					jQuery('.recall_box5').css('display','block');
					
				}
				
				jQuery('.numeroChassi').html(jQuery('#NumeroChassi').val().toUpperCase());
				jQuery('.recall_box2_center').css("height", 84+(idRecalls.length * 43)+"px");
				jQuery('.recall_box4_center').css("height", 84+(idRecalls.length * 43)+"px");
				jQuery('.recall_box5_center').css("height", 84+(idRecalls.length * 43)+"px");
			}

		}
		
	});

}

function getRecallById(idHtml, idRecall, url, heigth, weight)
{
 jQuery("#" + idHtml).load(Base.source.SitePath + "recallPortal/Home/getRecallById/" + idRecall+"/"+url+"/"+heigth+"/"+weight);
}
