﻿/*
 * Funções de Start
 */
$(document).ready(function() {
	$(document).pngFix();
	$('#pr').focus();
	modalTituloCidade();
	titulosRelacionados();
	retornoAnuncios();
	
	var valorInicial = location.search.split("=");
	
	$('#btnFechar, #btnFinalizar, #btnCancelar').each(function() {
		$(this).click(function(event) {
			$('#mask').hide();
			$('.window').hide();
		});
	});
	
	contPromocaoi = setTimeout("mudaRotativo('promocaoi');", 10000);
	clearTimeout(contPromocaoi);
	
	/*
	 * Efeito no campo de pesquisa
	 */
	$('#pr').keyup(function() {
		if ($(this).val().length > 0) {
			$(this).css('background-image', 'none');
		}
		else {
			$(this).css('background-image', 'url(app-content/themes/buscador/medias/bg_pr.gif)');
		}
	});
	
	if (valorInicial[1]) {
		retornoGratuitas();
		//$('#pt').val(valorInicial[1]);
		//$('#modalTitulos').text($('#info2 span').text());
		$('div[id^=ctrlLateral_]').css("display", "none");
		$('div[id^=promocaoi_]').css("display", "none");
		$('#btnZerar').click(function() {
			location.href = 'http://www.guiapratico.com';
		});
	}
	else {
		// Rotativo Promoção Interna
		contPromocaoi = setTimeout("mudaRotativo('promocaoi');", 0);
		$("div[id^=promocaoi]").each(function() {
			$(this).mouseover(function() {
				clearTimeout(contPromocaoi);
				contAnuncio = setTimeout("requestAjax('contador.php', 'tipo=anuncio&id=" + $(this).attr('identif') + "', 'retorno')", 2000);
			}).mouseout(function() {
				contPromocaoi = setTimeout("mudaRotativo('promocaoi')", 10000);
				clearTimeout(contAnuncio);
			});
		});
	}
	
	// Titulos mais pesquisados
	$("#ttlDestaque a").each(function() {
		$(this).click(function(event) {
			event.preventDefault();
			dados = $(this).attr("href").replace("?", "");
			$('#pt').val(dados);
			//$('#modalTitulos').text($(this).text());
			carregaAjax("busca.php", dados, "retorno");
		});
	});
	
	// Rotativo Topo
	contRotativo = setTimeout("mudaRotativo('rotativo');", 0);
	$("div[id^=rotativo_]").each(function() {
		$(this).mouseover(function() {
			clearTimeout(contRotativo);
			contAnuncio = setTimeout("requestAjax('contador.php', 'tipo=anuncio&id=" + $(this).attr('identif') + "', 'retorno')", 2000);
		}).mouseout(function() {
			contRotativo = setTimeout("mudaRotativo('rotativo')", 5000);
			clearTimeout(contAnuncio);
		});
	});
	
	// Rotativo Promoção
	if ($('#promocao_1').attr('id') == 'promocao_1') {
		contPromocao = setTimeout("mudaRotativo('promocao');", 0);
		$("div[id^=promocao_]").each(function() {
			$(this).mouseover(function() {
				clearTimeout(contPromocao);
				contAnuncio = setTimeout("requestAjax('contador.php', 'tipo=anuncio&id=" + $(this).attr('identif') + "', 'retorno')", 2000);
			}).mouseout(function() {
				contPromocao = setTimeout("mudaRotativo('promocao')", 15000);
				clearTimeout(contAnuncio);
			});
		});
	}
	else {
		$('#promocao_0').css("display", "block");
	}
	
	// Furmulário de Pesquisa
	$("#formPesquisa").submit(function(event) {
		event.preventDefault();
		carregaAjax("busca.php", $(this).serialize(), "retorno");
	});
	
	// Pesquisa por titulo
	$("#titulosRetornar").click(function(event) {
		event.preventDefault();
		if (palavra.length == 0) {
			if (colunaAparenteInicio > 1) {
				colunaAparenteInicio --;
				colunaAparenteFinal --;
				colunaMarginLeft = colunaMarginLeft - colunaTamanho;
				$("#tblPesquisaTitulo").css("margin-left", "-" + colunaMarginLeft + "px");
				efeitoBtnTitulo(palavra);
			}
		}
		else {
			if (pesquisaColunaAparenteInicio > 1) {
				pesquisaColunaAparenteInicio --;
				pesquisaColunaAparenteFinal --;
				pesquisaColunaMarginLeft = pesquisaColunaMarginLeft - colunaTamanho;
				$("#tblPesquisaTitulo").css("margin-left", "-" + pesquisaColunaMarginLeft + "px");
				efeitoBtnTitulo(palavra);
			}
		}
	});
	
	$("#titulosAvancar").click(function(event) {
		event.preventDefault();
		if (palavra.length == 0) {
			if (colunaAparenteFinal < colunasTotal) {
				colunaAparenteInicio ++;
				colunaAparenteFinal ++;
				colunaMarginLeft = colunaMarginLeft + colunaTamanho;
				$("#tblPesquisaTitulo").css("margin-left", "-" + colunaMarginLeft + "px");
				efeitoBtnTitulo(palavra);
			}
		}
		else {
			if (pesquisaColunaAparenteFinal < pesquisaColunasTotal) {
				pesquisaColunaAparenteInicio ++;
				pesquisaColunaAparenteFinal ++;
				pesquisaColunaMarginLeft = pesquisaColunaMarginLeft + colunaTamanho;
				$("#tblPesquisaTitulo").css("margin-left", "-" + pesquisaColunaMarginLeft + "px");
				efeitoBtnTitulo(palavra);
			}
		}
	});
	var tabelaListaTitulos = $("#tblPesquisaTitulo");
	$("#buscaTitulo").keyup(function() {
		palavra = $("#buscaTitulo").val();
		$("#listaTitulos").html(tabelaListaTitulos);
		if (palavra.length > 0) {
			$("#ordenarTitulo a").removeClass("destaqueTituloOrdem");
			$("#listaTitulos").text(buscaTitulo(palavra, "buscar"));
			efeitoBtnTitulo(palavra);
		}
		else {
			palavra = "";
		}
	});
	
	$("#ordenarTitulo a").each(function() {
		$(this).click(function(event) {
			$("#ordenarTitulo a").removeClass("destaqueTituloOrdem");
			event.preventDefault();
			$("#buscaTitulo").val("");
			if ($(this).attr("href") == "#TODOS") {
				$("#listaTitulos").html(tabelaListaTitulos);
				palavra = "";
				modalTituloCidade();
			}
			else {
				palavra = $(this).text();
				$(this).addClass("destaqueTituloOrdem");
				$("#listaTitulos").html(tabelaListaTitulos);
				buscaTitulo(palavra, "ordenar");
				efeitoBtnTitulo(palavra);
			}
		});
	});
	efeitoBtnTitulo(palavra);
	
	// Botões de pesquisa
	$("#btnZerar").click(function() {
		carregaAjax("busca.php", "pr=zerar:zerar", "retorno");
		$("#info2").html("<span>TODOS</span>");
		
		msgFiltroCidades();
		$("#pt").val("TODOS OS TÍTULOS");
		$("#modalTitulos").html("TODOS");
		$('#pr').val('');
		
		$("#promocao").css("display", "block");
		contPromocao = setTimeout("mudaRotativo('promocao');", 0);
		contPromocaoi = setTimeout("mudaRotativo('promocaoi');", 0);
		
		$("div[id^=promocao_]").each(function() {
			$(this).mouseover(function() {
				clearTimeout(contPromocao);
			}).mouseout(function() {
				contPromocao = setTimeout("mudaRotativo('promocao')", 15000);
			});
		});
		checkCidades(false);
	});
	
	// Botões de pesquisa por Cidade
	$("#btnCancelar").click(function(event) {
		event.preventDefault();
	});
	
	// Cidades - Checked Tudo
	$("#cddt").click(function() {
		valor = $(this).attr('checked');
		$("#dialog :checkbox").each(function() {
			$(this).attr("checked", valor);
		});
		msgFiltroCidades();
	});
	
	// Cidades - Checked Estados
	$('input[id^=cdduf]').each(function() {
		$(this).click(function() {
			if (this.checked == true) {
				$('input[id^=cdd_' + this.value + ']').each(function() {$(this).attr('checked', true);});
			}
			else {
				$('#cddt').attr('checked', false);
				$('input[id^=cdd_' + this.value + ']').each(function() {$(this).attr('checked', false);});
			}
			msgFiltroCidades();
		});
	});
	
	// Checked Cidades
	$('input[id^=cdd_]').each(function() {
		$(this).click(function() {
			varExp = $(this).attr('name').split('_');
			if (this.checked) {
				checkedCidades(this);
			}
			else {
				$('#cddt').attr('checked', false);
				$('input[id^=cdduf' + varExp[1] + ']').each(function() {
					$(this).attr('checked', false);
				});
			}
			msgFiltroCidades();
		});
	});
	
	$('#pesquisaTodosOsTitulos').click(function(event) {
		event.preventDefault();
		$('#mask').hide();
		$('.window').hide();
		dados = $(this).attr("id").replace("pesquisaTitulo", "");
		$("#modalTitulos").text('TODOS');
		$("#pt").val('TODOS OS TÍTULOS');
		carregaAjax("busca.php", $("#formPesquisa").serialize(), "retorno");
	});
});

/*
 * Início das Funções
 */
// Requisição Ajax
pagina     = "";
dados      = "";
divRetorno = "";
function requestAjax(pagina, dados, divRetorno) {
	varErro = false;
	
//	if ($("#pr").val().length < 1 && $("#pt").val() == "TODOS OS TÍTULOS" && divRetorno != 'localizacao') {
	if ($("#pr").val().length < 1 && $("#pt").val() == "TODOS OS TÍTULOS" && divRetorno != 'localizacao' && dados.search('&cg=') == -1) {
		$("#aviso").css("display", "block");
		$("#aviso").text("Informe um valor a ser pesquisado.");
		varErro = true;
	}
	else if ($("#pr").val().length > 0 && $("#pr").val().length < 3) {
		$("#aviso").css("display", "block");
		$("#aviso").text("A Pesquisa por Empresa deve ter no mínimo 3 dígitos.");
		varErro = true;
	}
	
	if (varErro == false) {
		$.ajax({
			type: "POST",
			url: pagina,
			data: dados,
			async: false,
			success: function(resultado) {
				$("#" + divRetorno).html(resultado);
			},
			complete: function(resultado) {
				titulosRelacionados();
				return true;
			}
		});
	}
}

function carregaAjax(pagina, dados, divRetorno) {
	$("#loading").css("display", "block");
	$("#aviso").css("display", "none");
	$("#promocao").css("display", "none");
	$('div[id^=promocaoi_]').css("display", "none");
	$('div[id^=ctrlLateral_]').css("display", "none");
	$("#localizacao").css("display", "none");
	$("#gratuita").empty();
	
	clearTimeout(contPromocaoi);
	requestAjax(pagina, dados, divRetorno);
	
	retornoInformacoes();
	retornoAnuncios();
	retornoGratuitas();
	
	$("#loading").css("display", "none");
}

// Function para preencher campos
campo = "";
function checkedCidades(campo) {
	varCddOk = true;
	varQtdOk = $("input[id^=cdd_]").length;
	
	$("input[id^=cdd_]").each(function() {
		if (this.checked != true) {
			varCddOk = false;
			varQtdOk --;
		}
	});
	
	if (varCddOk != false) {
		$("input[id^=cdd]").each(function() {
			$(this).attr("checked", true);
		});
		$("#modal").html("TODAS AS CIDADES");
		$("#modal").css("background", "#FFF");
	}
	
	varCddOk = true;
	
	$("input[id^=cdd_" + varExp[1] + "]").each(function() {
		if (this.checked != true)
			varCddOk = false;
	});
	
	if (varCddOk != false) {
		$("input[id^=cdduf" + varExp[1] + "]").each(function() {
			$(this).attr("checked", true);
		});
	}
}

// Retorno Informações
function retornoInformacoes() {
	//$('#modalTitulos').text($('#info2 span').text());
	if ($("#info2 a").attr("href")) {
		$("#info2 a").click(function(event) {
			event.preventDefault();
			$("#pr").val('');
			dados = $(this).attr("href").split("?ct=");
			$("#pt").val(dados[1]);
			dados = dados[1];
			carregaAjax("busca.php", 'ct=' + dados, "retorno");
		});
	}
}

// Retorno Gratuitas
function retornoGratuitas() {
	$("#tblGratuita tr").each(function() {
		$(this).mouseover(function() {
			$(this).css("background", "#FFFFCC");
		}).mouseout(function() {
			$(this).css("background", "#FFFFFF");
		});
	});
	
	$("a[id^=linkGratuita], a[id^=cddGratuita]").each(function() {
		$(this).click(function(event) {
			event.preventDefault();
			varIdGratuita = $(this).attr("id").split("_");
			
			//$('#cddGratuita_' + varIdGratuita[1] + '_' + varIdGratuita[2]).parent('td').attr('bgcolor', '#FFFFCC');
			//$('#linkGratuita_' + varIdGratuita[1] + '_' + varIdGratuita[2]).parent('td').attr('bgcolor', '#FFFFCC');
			
			$('#divCddGratuita_' + varIdGratuita[2]).css({'background':'#FFFFCC', 'height':'38px'});
			$('#conteudo_gratuita_' + varIdGratuita[2]).css('background', '#FFFFCC');
			
			//$("#linkGratuita_" + varIdGratuita[1] + "_" + varIdGratuita[2]).css("background", "#FFFFCC");
			//$("#linkGratuita_" + varIdGratuita[1] + "_" + varIdGratuita[2]).css("min-height", "32px");
			
			$("#gratuita_" + varIdGratuita[2]).css("display", "block");
			dados = "posicao=" + varIdGratuita[1] + "&cg=" + varIdGratuita[2];
			requestAjax("busca.php", dados, "retorno");
			retornoAnuncios();
			retornoInformacoes();
			
			$(
				'#conteudo_gratuita_' + varIdGratuita[2] + ' .op_tel_editar,' +
				'#conteudo_gratuita_' + varIdGratuita[2] + ' .op_tel_nao_atende,' +
				'#conteudo_gratuita_' + varIdGratuita[2] + ' .op_tel_errado'
			).each(function() {
				$(this).css('opacity', 0.4).mouseover(function() {
					$(this).css('opacity', 1);
				}).mouseout(function() {
					$(this).css('opacity', 0.4);
				}).click(function(event) {
					if ($(this).attr('class') == 'op_tel_editar') {
						event.preventDefault();
						
						var tel = prompt('Por favor, digite o número correto abaixo.', '');
						if (tel) {
							$.ajax({
								type: 'GET',
								url: 'app-process/atualiza-cadastro.php?n=atualiza&i=' + varIdGratuita[2] + '&t=' + tel,
								async: true,
								success: function(resultado) {
									$('#retorno').html(resultado);
								},
								complete: function(resultado) {
									return true;
								}
							});
							
							alert('Muito obrigado!!!\n\nEm breve entraremos em contato com o número informado para efetuarmos as alterações.\n\nO Guia Prático agradece a sua colaboração!');
						}
					}
					else if ($(this).attr('class') == 'op_tel_nao_atende') {
						event.preventDefault();
						
						$.ajax({
							type: 'GET',
							url: 'app-process/atualiza-cadastro.php?n=nao_atende&i=' + varIdGratuita[2],
							async: true,
							success: function(resultado) {
								$('#retorno').html(resultado);
							},
							complete: function(resultado) {
								return true;
							}
						});
						
						alert('Muito obrigado!!!\n\nSua notificação de que este telefone não está atendendo vai ser verificada por nossa equipe.');
					}
					else if ($(this).attr('class') == 'op_tel_errado') {
						event.preventDefault();
						
						$.ajax({
							type: 'GET',
							url: 'app-process/atualiza-cadastro.php?n=errado&i=' + varIdGratuita[2],
							async: true,
							success: function(resultado) {
								$('#retorno').html(resultado);
							},
							complete: function(resultado) {
								return true;
							}
						});
						
						alert('Muito obrigado!!!\n\nSua notificação de que este telefone está errado vai ser verificada para uma possível remoção.');
					}
				});
			});
		});
	});
}

// Retorno Anúncios
function retornoAnuncios() {
	$("div[id^=ctrlTopo]").each(function(i) {
		$(this).mouseover(function() {
			$("#bannerTopo" + (i + 1)).css("display", "block");
			//contAnuncio = setTimeout("requestAjax('contador.php', 'tipo=anuncio&id=" + $(this).attr('identif') + "', 'retorno')", 2000);
			id_anuncio = $(this).attr('identif');
			contAnuncio = setTimeout('$(\'#retorno\').load(\'contador.php?tipo=anuncio&id=\' + id_anuncio);', 2000);
			$("#retorno").load("contador.php?id=" + $("img", this).attr("id"));
		}).mouseout(function() {
			$("#bannerTopo" + (i + 1)).css("display", "none");
			clearTimeout(contAnuncio);
		});
	});
	
	$("div[id^=ctrlLateral]").each(function(i) {
		$(this).mouseover(function() {
			$("#bannerLateral" + (i + 1)).css("display", "block");
			//contAnuncio = setTimeout("requestAjax('contador.php', '&tipo=anuncio&id=" + $(this).attr('identif') + "', 'retorno')", 2000);
			id_anuncio = $(this).attr('identif');
			contAnuncio = setTimeout('$(\'#retorno\').load(\'contador.php?tipo=anuncio&id=\' + id_anuncio);', 2000);
		}).mouseout(function() {
			$("#bannerLateral" + (i + 1)).css("display", "none");
			clearTimeout(contAnuncio);
		});
	});
	
	$("a[id^=localizacao_]").each(function(i) {
		$(this).click(function(event) {
			event.preventDefault();
			dados = $(this).attr('href').split('?');
            dados = dados[1];
			requestAjax("localizacao.php", dados, "localizacao");
			$("#localizacao").css("display", "block");
		});
	});
}

// Rotativos
varRotativoPrincipal = -1;
varRotativoPromocao  = -1;
varRotativoPromocaoi = -1;
function mudaRotativo(varDiv) {
	// Rotativo Principal
	if (varDiv == "rotativo") {
		varRotativoPrincipal ++;
		if (varRotativoPrincipal >= $("div[id^=" + varDiv + "_]").length)
			varRotativoPrincipal = 0;
		varPosicao = varRotativoPrincipal;
		contRotativo = setTimeout("mudaRotativo('rotativo')", 5000);
	}
	
	// Rotativo Promoção
	if (varDiv == "promocao") {
		varRotativoPromocao ++;
		if (varRotativoPromocao >= $("div[id^=" + varDiv + "_]").length)
			varRotativoPromocao = 0;
		varPosicao = varRotativoPromocao;
		contPromocao = setTimeout("mudaRotativo('promocao')", 15000);
	}
	
	// Rotativo Promoção Interna
	if (varDiv == "promocaoi") {
		varRotativoPromocaoi ++;
		if (varRotativoPromocaoi >= $("div[id^=" + varDiv + "_]").length)
			varRotativoPromocaoi = 0;
		varPosicao = varRotativoPromocaoi;
		contPromocaoi = setTimeout("mudaRotativo('promocaoi')", 10000);
	}
	
	$("div[id^=" + varDiv + "_]").each(function() {
		if ($(this).attr("id") != $("#" + varDiv + "_" + varPosicao).attr("id"))
			$(this).css('display', 'none');
		else {
			$("#retorno").load("contador.php?id=" + $("img", this).attr("id"));
			$(this).css("display", "block");
		}
	});
}

function efeitoBtnTitulo(palavra) {
	if (palavra.length == 0) {
		if (colunaAparenteInicio <= 1)
			$("#titulosRetornar").css({opacity: "0.3"});
		else
			$("#titulosRetornar").css({opacity: "1"});
		
		if (colunaAparenteFinal == colunasTotal)
			$("#titulosAvancar").css({opacity: "0.3"});
		else
			$("#titulosAvancar").css({opacity: "1"});
	}
	else {
		if (pesquisaColunaAparenteInicio <= 1)
			$("#titulosRetornar").css({opacity: "0.3"});
		else
			$("#titulosRetornar").css({opacity: "1"});
		
		if (pesquisaColunaAparenteFinal == pesquisaColunasTotal)
			$("#titulosAvancar").css({opacity: "0.3"});
		else
			$("#titulosAvancar").css({opacity: "1"});
	}
}

function titulosRelacionados() {
	$("#titulosRelacionados a").each(function() {
		$(this).click(function(event) {
			event.preventDefault();
			dados = $(this).attr("href").split("?");
			dados = dados[1].replace("pt=", "");
			$("#pt").val(dados);
			$("#pr").val("");
			//$("#modalTitulos").text($(this).text());
			dados = $("#formPesquisa").serialize();
			carregaAjax("busca.php", dados, "retorno");
		});
	});
}

var retorno = "";
var teste = 0;
function buscaTitulo(palavra, selecao) {
	teste ++;
	
	palavra = palavra.toUpperCase();
	selecao = selecao;
	
	palavra = palavra.replace("Á", "A");
	palavra = palavra.replace("À", "A");
	palavra = palavra.replace("Ã", "A");
	palavra = palavra.replace("Â", "A");
	palavra = palavra.replace("É", "E");
	palavra = palavra.replace("Ê", "E");
	palavra = palavra.replace("Í", "I");
	palavra = palavra.replace("Ó", "O");
	palavra = palavra.replace("Ô", "O");
	palavra = palavra.replace("Õ", "O");
	palavra = palavra.replace("Ú", "U");
	palavra = palavra.replace("Ü", "U");
	palavra = palavra.replace("Ç", "U");
	palavra = palavra.replace(";", "");
	
	var qtdeResultado = 0;
	var titulos = new Array();
	var qtdeTitulosColuna = 1;
	var tabelaWidth = 0;
	pesquisaColunasTotal = 0;
	
	$("a[id^=pesquisaTitulo]").each(function() {
		if ($(this).attr("href").indexOf(palavra) >= 0 && selecao == "buscar") {
			if (qtdeTitulosColuna == 1) {
				retorno = retorno + "<td width=\"290\" valign=\"top\">";
				tabelaWidth = tabelaWidth + 290;
				pesquisaColunasTotal ++;
			}
			
			titulos[qtdeResultado] = "<a href=\"" + $(this).attr("href") + "\" id =\"" + $(this).attr("id") + "\" class=\"close\" style=\"text-align:left;\">";
			titulos[qtdeResultado] = titulos[qtdeResultado] + $(this).text() + "</a>";
			
			retorno = retorno + titulos[qtdeResultado];
			
			qtdeResultado ++;
			qtdeTitulosColuna ++;
			
			if (qtdeTitulosColuna > 12) {
				retorno = retorno + "</td>";
				qtdeTitulosColuna = 1;
			}
		}
		
		if ($(this).attr("href").indexOf(palavra) == 1 && selecao == "ordenar") {
			if (qtdeTitulosColuna == 1) {
				retorno = retorno + "<td width=\"290\" valign=\"top\">";
				tabelaWidth = tabelaWidth + 290;
				pesquisaColunasTotal ++;
			}
			
			titulos[qtdeResultado] = "<a href=\"" + $(this).attr("href") + "\" id =\"" + $(this).attr("id") + "\" class=\"close\" style=\"text-align:left;\">";
			titulos[qtdeResultado] = titulos[qtdeResultado] + $(this).text() + "</a>";
			
			retorno = retorno + titulos[qtdeResultado];
			
			qtdeResultado ++;
			qtdeTitulosColuna ++;
			
			if (qtdeTitulosColuna > 12) {
				retorno = retorno + "</td>";
				qtdeTitulosColuna = 1;
			}
		}
	});
	
	if (retorno != "") {
		pesquisaColunaAparenteInicio = 1;
		
		if (pesquisaColunasTotal >= 2) {
			pesquisaColunaAparenteFinal = 2;
		} else {
			pesquisaColunaAparenteFinal = 1;
		}
		
		pesquisaColunaMarginLeft = 0;
		
		retorno = "<table id=\"tblPesquisaTitulo\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"" + tabelaWidth + "\"><tr>" + retorno + '</tr></table>';
		$("#listaTitulos").html(retorno);
		modalTituloCidade();
		
		$("#tblPesquisaTitulo a").each(function() {
			$(this).addClass("close");
			$(this).click(function() {
				//$("#modalTitulos").html($(this).text());
			})
		});
	} else {
		$("#listaTitulos").html("Nenhum registro encontrado que contenha: <b>" + palavra + "</b> no nome");
	}
	retorno = "";
}

/*
 * CHECK CIDADES
 * 
 * atribui um valor true/false em todos os checkeds
 */
function checkCidades(valor) {
	$("#modal").html("TODAS AS CIDADES");
	$("#modal").css("background", "#FFF");
	
	$('input[id^=cdd]').each(function() {
		$(this).attr('checked', valor);
	});
}

/*
 * MSG FILTRO CIDADES
 * 
 * exibe a quantidade de cidades selecionadas
 */
function msgFiltroCidades() {
	varQtdOk1 = $("input[id^=cdd_]").length;
	varQtdOk2 = varQtdOk1;
	$("input[id^=cdd_]").each(function() {
		if (this.checked != true) {
			varQtdOk2 --;
		}
	});
	if (varQtdOk2 == 0 || varQtdOk2 == varQtdOk1) {
		$("#modal").html("TODAS AS CIDADES").css("background", "#FFF");
		if (varQtdOk2 == varQtdOk1) {
			checkCidades(true);
		}
	} else {
		if (varQtdOk2 > 1) {
			mensagem = varQtdOk2 + ' CIDADES';
		} else {
			mensagem = 'UMA CIDADE';
		}
		$("#modal").html("<font color='#CC0000'><b>" + mensagem + "</b></font>").css("background", "#FFC");
	}
}

function modalTituloCidade() {
	$('#listaTitulos .window, #listaTitulos .close').each(function() {
		$(this).click(function(event) {
			event.preventDefault();
			if ($(this).attr("href").length != 0) {
				dados = $(this).attr("id").replace("pesquisaTitulo", "");
				if ($(this).text() == 'LIMPAR BUSCA') {
					$("#modalTitulos").text('TODOS');
					$("#pt").val('TODOS OS TÍTULOS');
				} else {
					//$("#modalTitulos").text($(this).text());
					$("#pt").val(dados);
				}
			}
			$('#mask').hide();
			$('.window').hide();
			carregaAjax("busca.php", $("#formPesquisa").serialize(), "retorno");
	   });
	});
}
