function val_cpf(numero2) {
	dig_1 = 0;
	dig_2 = 0;
	controle_1 = 10;
	controle_2 = 11;
	lsucesso = 1;

	var numero = numero2.substr(0,3) + numero2.substr(4,3) + numero2.substr(8,3) + numero2.substr(12,2);

	if (numero == "00000000000" || numero == "11111111111" || numero == "22222222222" || numero == "33333333333" || numero == "44444444444" || numero == "55555555555" || numero == "66666666666" || numero == "77777777777" || numero == "88888888888" || numero == "99999999999") {
		return false;
	}

	if ((numero.length != 11) && (numero.length != 0)) {
		return false;
	}
	else {
		for ( i=0 ; i < 9 ; i++) {
			dig_1 = dig_1 + parseInt(numero.substring(i, i+1) * controle_1);
			controle_1 = controle_1 - 1;
		}

		resto = dig_1 % 11;
		dig_1 = 11 - resto;
		if ((resto == 0) || (resto == 1)) {
			dig_1 = 0;
		}
		for ( i=0 ; i < 9 ; i++) {
			dig_2 = dig_2 + parseInt(numero.substring(i, i + 1) * controle_2);
			controle_2 = controle_2 - 1;
		}
		dig_2 = dig_2 + 2 * dig_1;
		resto = dig_2 % 11;
		dig_2 = 11 - resto;
		if ((resto == 0) || (resto == 1)) {
			dig_2 = 0;
		}
		dig_ver = (dig_1 * 10) + dig_2;
		if (dig_ver != parseFloat(numero.substring(numero.length-2,numero.length))) {
			return false;
		}
	}

	return true;
}

function enviarFaleConosco(ff){
	if(trimAll(ff.nome.value)==''){
		alert('O campo "nome" deve ser preenchido.');
		ff.nome.focus();
		return false;
	}	
	if(trimAll(ff.email.value)==''){
		alert('O campo "e-mail" deve ser preenchido.');
		
		ff.email.focus();
		return false;
	}else{
		if(!verifica_mail(trimAll(ff.email.value))){
			alert('e-mail inválido!');		
			ff.email.focus();
			return false;
		}
	}
	if(trimAll(ff.editor.value)==''){
		alert('Escolha um editor responsável.');
		ff.editor.focus();
		return false;
	}

	if(trimAll(ff.mensagem.value)==''){
		alert('O campo "mensagem" deve ser preenchido.');
		ff.mensagem.focus();
		return false;
	}
	ff.submit();
}


function enviarNewsletter(ff){
	if(trimAll(ff.nome.value)==''){
		alert('O campo "nome" deve ser preenchido.');
		ff.nome.focus();
		return false;
	}	
	if(trimAll(ff.email.value)==''){
		alert('O campo "e-mail" deve ser preenchido.');
		
		ff.email.focus();
		return false;
	}else{
		if(!verifica_mail(trimAll(ff.email.value))){
			alert('e-mail inválido!');		
			ff.email.focus();
			return false;
		}
	}
	ff.submit();
}

function busca(ff){
	if(trimAll(ff.chave.value)==''){
		alert('Digite a expressão a ser buscada.');
		ff.chave.focus();
		return false;
	}
	ff.submit();
}

function buscaDias(ff){
	if(trimAll(ff.dias.value)==''){
		alert('Selecione algo para buscar');
		ff.dias.focus();
		return false;
	}
	ff.submit();
}

function enquete(xx){
	if(xx.resposta.value=='0'){
		alert('escolha uma opção');
		return false;
	}
	janela('enquete_resultado.php?resposta='+xx.resposta.value+'&idEnquete='+xx.idEnquete.value,'375','350','janelaEnquete')
}

function janela(www,h,w,nome)
{
	var height = window.screen.height - 160;
	var width = window.screen.width;
	var top = (height- h)/2;
	var left = (width - w)/2;
	if(nome=='')
		nome='NOVA';
	window.open(www,nome,"top=" + top + ",left="+ left +",width="+w+",height="+h+",toolbar=no,location=no,status=no,menubar=no,scrollbars=no,scrolling=no,resizable=no")
}

function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function verifica_mail(email){
	var campo = email;
	//se a "@" não existe e é o primeiro caractere
	if (campo.indexOf("@") < 1) return false
	//se o caracter antes da "@" é "."
	if(campo.charAt(campo.indexOf("@")-1) == ".") return false;
	//se a última incidência de "." está antes da @
	if (campo.lastIndexOf(".") <= campo.indexOf("@")) return false;
	//se o último caracter é ponto,
	if (campo.lastIndexOf(".")  == (campo.length-1)) return false;

	return true;
}
function trocaCidade(nCidade) 
{	
	var dados=nCidade.split(';');		
	var cidade=dados[0];
	var emissora=dados[1];
	
	getPage('cidade.php?id='+emissora,'cidade');	
	var so = new SWFObject("images/mapa_ms.swf", "Flash", "262", "262", "8", "#FFFFFF");
	so.addParam("wmode", "transparent");
	so.addParam("allowScriptAccess", "sameDomain");
	so.addParam("menu", "false");
	so.addVariable("nCod", cidade);
	so.addParam("scale", "noscale");
	so.write("mapa_ms_flash");
}

function getPage(url, campo){
	var browser = navigator.appName;

	if(browser == "Microsoft Internet Explorer"){
		request = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request = new XMLHttpRequest();
	}
	request.open("GET", url, false);
	request.send(null);
	parent.document.getElementById(campo).innerHTML= request.responseText;
	/*var xmlhttp = createRequestObject();
	//Exibe o texto carregando no div conte?do

	var conteudo=document.getElementById(campo);
	// conteudo.innerHTML='<div class="carregando">carregando...</div>';
	//Abre a url

	xmlhttp.open("GET", url,false);

	//Executada quando o navegador obtiver o c?digo

	xmlhttp.onreadystatechange=function() {

	if (xmlhttp.readyState==4){
	//L? o texto
	var texto=xmlhttp.responseText;
	//Desfaz o urlencode
	texto=texto.replace(/\+/g," ");
	texto=unescape(texto);
	texto = (texto);
	//            alert(texto);
	//Exibe o texto no div conte?do
	var conteudo=document.getElementById(campo);
	conteudo.innerHTML = (texto);
	conteudo.innerHTML = (texto);
	}
	}
	xmlhttp.send(null)*/
}
function comentario(ff){
	if(trimAll(ff.nome.value)==''){
		alert('digite o nome');	
		ff.nome.focus();
		return false;
	}
	if(trimAll(ff.email.value)==''){
		alert('informe o e-mail');	
		ff.email.focus();
		return false;	
	}else{
		if(!verifica_mail(ff.email.value)){
			alert('e-mail inválido!');
			ff.email.focus();
			return false;
		}	
	}	
	if(trimAll(ff.texto.value)==''){
		alert('digite a mensagem');	
		ff.texto.focus();
		return false;
	}
	ff.submit();
}
function fechaJanela(obj){
	obj.close();
}
function getText(url,div){
	var browser = navigator.appName;

	if(browser == "Microsoft Internet Explorer"){
		request = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request = new XMLHttpRequest();
	}
	
	request.open("GET", url, false);
	request.send(null);
	
	document.getElementById(div).innerHTML =  request.responseText;
}

function selecionaBotao(id) {
	document.getElementById("link1").className = "botao_n_sel";
	document.getElementById("link2").className = "botao_n_sel";
	document.getElementById("link3").className = "botao_n_sel";
	document.getElementById("link"+id).className = 'botao_sel';
	//
	document.getElementById("html1").style.display = "none";
	document.getElementById("html2").style.display = "none";
	document.getElementById("html3").style.display = "none";
	document.getElementById("html"+id).style.display = "block";
	//
	//document.getElementById("html"+id).focus();
}
function trocaImagem(img){
	parent.document.getElementById("imgGalGrande").src = img;
}
//
var myTime;
function scrollUp(){
	window.frameGal.scrollBy(-5,0);//sobe a barra de rolagem
	myTime = setTimeout('scrollUp()', 5);//myTime objeto q mantém a recursividade
}

function scrollDown(){
	window.frameGal.scrollBy(5,0);//desce a barra de rolagem
	myTime = setTimeout('scrollDown()', 5);//myTime objeto q mantém a recursividade
}
function escondeFiltroMsg(){
	document.getElementById("formularioMensagens").style.display = 'none';
	document.getElementById("botaoEscondeMsg").style.display = 'none';
	document.getElementById("botaoMostraMsg").style.display = 'block';
}
function mostraFiltroMsg(){
	document.getElementById("formularioMensagens").style.display = '';
	document.getElementById("botaoEscondeMsg").style.display = 'block';
	document.getElementById("botaoMostraMsg").style.display = 'none';
}

