function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}



function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}



function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}



function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

function MM_jumpMenu(targ,selObj,restore){ //v3.0

  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");

  if (restore) selObj.selectedIndex=0;

}



function show_hide(pcObjeto) {

	var poObj = document.getElementById(pcObjeto);

	if (poObj) {

		if (poObj.style.display == "") {

			poObj.style.display = "none";

		} else {

			poObj.style.display = "";

		}

	}

}



function habilita_campo_formulario(poFormulario, pnHabilita) {

	var f = poFormulario;

	for (var i = 0; i < f.length; i++) {

		if ((f[i].type != "hidden") && (f[i].type != "image")) {

			f[i].disabled = (pnHabilita != 1);

			if (pnHabilita != 1) {

				f[i].style.background = "#F1F1F1";

			} else {

				f[i].style.background = "#FFFFFF";

			}

		}

	}

}



// Carrega um conteudo dentro de uma camada via Ajax

function CarregaCamada(pcPagina, pcCamada) {

	var req = null;

	// Procura por um objeto nativo (Mozilla/Safari)

	if (window.XMLHttpRequest) {

		req = new XMLHttpRequest();

		req.onreadystatechange = processReqChange;

		req.open("GET", pcPagina, true);

		req.send(null);

	// Procura por uma versao ActiveX (IE)

	} else if (window.ActiveXObject) {

		req = new ActiveXObject("Microsoft.XMLHTTP");

		if (req) {

			req.onreadystatechange = processReqChange;

			req.open("GET", pcPagina, true);

			req.send();

		}

	}

	

	document.getElementById(pcCamada).innerHTML = '<div align="center" style="height:17px">Carregando...</div>';

	

	function processReqChange() {

		if (req.readyState == 4) {

			if ((req.status == 200) && ((req.responseText) != "UNKNOWN")) {

				if (document.getElementById(pcCamada)) {

					document.getElementById(pcCamada).innerHTML = req.responseText;

				}

			} else {

				//alert("Houve um problema ao obter os dados:\n" + req.statusText);

			}

		}

	}

}



function muda_fundo(poObjeto, pcCor) {

	poObjeto.style.background = pcCor;

}



function valida_newsletter(pnAcao, poFormulario) {

	var f = poFormulario;

	f.txtOperacao.value = pnAcao;

	if (f.txtNome) {

		if ((f.txtNome.value == "") || (f.txtNome.value == "Seu nome")) {

			alert("Digite seu nome para cadastrar.");

			f.txtNome.focus();

			return false;

		}

	}

	if ((f.txtEmail.value == "") || (f.txtEmail.value == "Seu e-mail")) {

		alert("O Email é obrigatório.");

		f.txtEmail.focus();

		return false;

	}

	else {

		if (ValidaEmail(f.txtEmail) == false) {

			return false;

		}

	}

	f.submit();

	f.reset();

}



function mostra_data() {

	var now = new Date();

	var hours = now.getHours();

	var minutes = now.getMinutes();

	var timeValue = hours; //"" + ((hours >12) ? hours -12 :hours)

	timeValue += ((minutes < 10) ? ":0" : ":") + minutes

	//timeValue += (hours >= 12) ? " PM" : " AM"

	timerRunning = true;

	

	mydate = new Date();

	day = mydate.getDate();

	month = mydate.getMonth() + 1;

	weekday= mydate.getDay();

	year= mydate.getYear();

	

	document.getElementById('data_hora').innerHTML = day + "/" + month + "/" + year + " - " + timeValue;

	setTimeout("mostra_data()", 2000);

}



// Verifica a quantidade de dias em fereveiro

function DiasInFevereiro (pnAno) {

    return (  ((pnAno % 4 == 0) && ( (!(pnAno % 100 == 0)) || (pnAno % 400 == 0) ) ) ? 29 : 28 );

}



// Validar Data

function ValidaData(field) {

	if (field.value == "") {

		return true;

	}

	var hoje = new Date();

	var anoAtual = hoje.getFullYear();

	var barras = field.value.split("/");

	if (barras.length == 3) {

		var dia = barras[0];

		var mes = barras[1];

		var ano = barras[2];

		var resultado = (!isNaN(dia) && (dia > 0) && (dia < 32)) && (!isNaN(mes) && (mes > 0) && (mes < 13)) && (!isNaN(ano) && (ano.length == 4));

		if (!resultado) {

			alert("Formato de data inválido. Ex.: (dd/mm/aaaa)");

			field.focus();

			field.select();

			return false;

		}

		if (ano.length != 4) {

			alert("O ano deve ter 4 digitos.");

			field.focus();

			field.select();

			return false;

		}

		//if (ano < anoAtual) {

		//	alert("O ano não pode ser menor que o ano atual.");

		//	field.focus();

		//	field.select();

		//	return false;

		//}

		dias = new Array(13);

		dias[1] = 31;

		dias[2] = DiasInFevereiro(ano);   // deve ser verificado o caso de anos bissextos

		dias[3] = 31;

		dias[4] = 30;

		dias[5] = 31;

		dias[6] = 30;

		dias[7] = 31;

		dias[8] = 31;

		dias[9] = 30;

		dias[10] = 31;

		dias[11] = 30;

		dias[12] = 31;

		if (dia > dias[mes]) {

			alert("Dia inválido.");

			field.focus();

			field.select();

			return false;

		}

	} else {

		alert("Formato de data inválido. Ex.: (dd/mm/aaaa)");

		field.focus();

		field.select();

		return false;

	}

}



// Valida hora e minuto

function ValidaHora(field) {

	if (field.value == "") {

		return true;

	}

	if (field.value.length != 5) {

		alert("Formato de hora inválido. Ex.: (hh:mm)");

		field.focus();

		field.select();

		return false;

	}

	var barras = field.value.split(":");

	if (barras.length == 2) {

		var hora = barras[0];

		var minuto = barras[1];

		var resultado = (!isNaN(hora) && (hora >= 0) && (hora < 24)) && (!isNaN(minuto) && (minuto >= 0) && (minuto < 60));

		if (!resultado) {

			alert("Formato de hora inválido. Ex.: (hh:mm)");

			field.focus();

			field.select();

			return false;

		}

	}

	else {

		alert("Formato da hora inválido. Ex.: (hh:mm)");

		field.focus();

		field.select();

		return false;

	}

}



// Validar tecla nos campos de Email e usuario

function ValidaTeclaEmail() {

	//letras maiúsculas

	if ( (window.event.keyCode >= 65) && (window.event.keyCode <= 90) ) {

		// tranforma letras maiúsculas em minúsculas

		window.event.keyCode = window.event.keyCode + 32;

		return true;

	}

	else {

		// letras minusculas, numeros, ponto, arroba, underline

		if ( ((window.event.keyCode >= 97) && (window.event.keyCode <= 122))

				|| ((window.event.keyCode >= 48) && (window.event.keyCode <= 57))

				|| (window.event.keyCode == 46)

				|| (window.event.keyCode == 64)

				|| (window.event.keyCode == 95) ) {

					return(true);

		}

		else {

			window.event.keyCode = 0;

			return false;

		}

	}

}



// Valida as teclas somente números

function ValidaNumero() {

	if (! ((window.event.keyCode >= 48) && (window.event.keyCode <= 57)) ) {

		window.event.keyCode = 0;

		return false;

	}

}



// Valida as teclas para numeros e virgula

function ValidaReal(poObj) {

	if (!( ((window.event.keyCode >= 48) && (window.event.keyCode <= 57)) || (window.event.keyCode == 44) )) {

		window.event.keyCode = 0;

		return false;

	} else {

		if (window.event.keyCode == 44) {

			if (poObj.value.length <= 0) {

				window.event.keyCode = 0;

			}

			if (poObj.value.indexOf(",") > 0) {

				window.event.keyCode = 0;

			}

		}

		

		if ((poObj.value.indexOf(",") > 0) && (poObj.value.length - (poObj.value.indexOf(",") + 1) >= 2)) {

			window.event.keyCode = 0;

		}

	}

}



// Valida as teclas para data e hora ( numeros : / )

function ValidaTeclaData() {

	if (!( ((window.event.keyCode >= 48) && (window.event.keyCode <= 57)) || (window.event.keyCode == 58) || (window.event.keyCode == 47) )) {

		window.event.keyCode = 0;

		return false;

	}

}



// Valida o CEP

function ValidaCEP(field) {

	var lcValor = new String(field.value); 

	if (lcValor.length == 0) {

		return true;

	}

	// Último Caracter Digitado

	var lcCaracter_Digitado = lcValor.substring(lcValor.length - 1, 10);

	

	// Verifica se o usuário entrou com um caracter válido

	if ( !(lcCaracter_Digitado.charCodeAt() >=48 && lcCaracter_Digitado.charCodeAt() <= 57) ) {

		field.value = lcValor.substring(0, lcValor.length - 1);

		alert("Caracter inválido!");

		field.focus();

	}

	if (lcValor.length < 5) {

		if (lcCaracter_Digitado == "/") {

			// Remove caracter

			field.value = lcValor.substring(0, lcValor.length - 1);

			field.value = "";

			field.focus();

		}

	}

	if (lcValor.length == 5) {

		// Adiciona caracter

		field.value = poObjeto.value + "-";

		field.focus();

	}

	if (lcValor.length > 9) {

		if (lcCaracter_Digitado == "/") {

			// Remove caracter

			field.value = lcValor.substring(0, lcValor.length - 1);

			field.value = "";

			field.focus();

		}

	}

	return true;

}



// Valida CPF e CGC

function ValidaCPF(field) {

	var i = 0, k = 0; i = 0, j = 0, soma = 0, mt = 0;

	var cpf = '', cgc = '', digito = '', digitoc = '', temp = '', dg = '';

	if (field.value == '') {

 		return false;

 	}

 	else {

 		cpf = field.value;

 	}

	if ( (field.value == "00000000000") || (field.value == "11111111111") || (field.value == "22222222222") ||

	     (field.value == "33333333333") || (field.value == "44444444444") || (field.value == "55555555555") ||

		 (field.value == "66666666666") || (field.value == "77777777777") || (field.value == "88888888888") ||

		 (field.value == "99999999999") || ((field.value.length != 11) && (field.value.length != 14)) ) {

		alert("CPF inválido!");

		field.value = '';

		field.focus();

		return false;

	}

	if (((cpf.length > 13) && (cpf.length < 19)) && (cpf.substring(3,4) !='.')) {

		if (cpf.length == 18) {

			temp = cpf.substring(0,2) + cpf.substring(3,6) + cpf.substring(7,10) + cpf.substring(11,15) + cpf.substring(16,18);

		}

		if (cpf.length == 16) {

			temp = cpf.substring(0,2) + cpf.substring(2,5) + cpf.substring(5,8) + cpf.substring(9,13) + cpf.substring(14,16);

		}

		if (cpf.length == 15 && cpf.substring(12,13) == '-') {

			temp = cpf.substring(0,2) + cpf.substring(2,5) + cpf.substring(5,8) + cpf.substring(8,12) + cpf.substring(13,15);

		}

		if (cpf.length == 15 && cpf.substring(8,9) == '/') {

			temp = cpf.substring(0,2) + cpf.substring(2,5) + cpf.substring(5,8) + cpf.substring(9,13) + cpf.substring(13,15);

		}

		if (cpf.length == 14) {

			temp = cpf.substring(0,2) + cpf.substring(2,5) + cpf.substring(5,8) + cpf.substring(8,12) + cpf.substring(12,14);

		}

		cgc = temp.substring(0,12);

		digito = temp.substring(12,14);

		mult = '543298765432';

		for (j = 1; j <= 2; j++) {

			soma = 0;

			for (i = 0; i <= 11; i++) {

				k = i + 1;

				soma += parseInt((cgc.substring(i,k)) * (mult.substring(i,k)));

			}

			if (j == 2) {

				soma = soma + (2 * digitoc);

			}

			digitoc = ((soma * 10) % 11);

			if (digitoc == 10) {

				digitoc = 0;

			}

			dg += digitoc;

			mult = '654329876543';

		}

		if (dg != digito) {

			alert('O CGC informado não é válido!');

			field.value = '';

			field.focus();

			return false;

		}

		else {

			field.value=temp.substring(0,2)+'.'+temp.substring(2,5)+'.'+temp.substring(5,8)+'/'+temp.substring(8,12)+'-'+temp.substring(12,14);

			return true;

		}

	}

	else {

		if (cpf.length < 11) {

			alert( 'Tamanho do campo CPF/CGC inválido. Verifique.');

			field.value = '';

			field.focus();

			return false;

		}

		if (cpf.length == 11) {

			temp = cpf.substring(0,3) + cpf.substring(3,6) + cpf.substring(6,9) + cpf.substring(9,11);

		}

		if (cpf.length == 12) {

			temp = cpf.substring(0,3) + cpf.substring(3,6) + cpf.substring(6,9) + cpf.substring(10,12);

		}

		if (cpf.length == 14) {

			temp = cpf.substring(0,3) + cpf.substring(4,7) + cpf.substring(8,11) + cpf.substring(12,15);

		}

		cpf = temp.substring(0,9);

		digito = temp.substring(9,11);

		for (j = 1; j <= 2; j++) {

			soma = 0;

			mt = 2;

			for (i = 8 + j; i >= 1; i--) {

				soma += parseInt(cpf.charAt(i-1),10) * mt;

				mt++;

			}

			dg = 11 - (soma % 11);

			if (dg > 9) { dg = 0 };

			cpf += dg;

		}

		if (digito != cpf.substring(9,11)) {

			alert('O CPF informado não é válido!');

			field.value = '';

			field.focus();

			return true;

		}

		else {

			field.value = cpf.substring(0,3) + '.' + cpf.substring(3,6) + '.' + cpf.substring(6,9) + '-' + cpf.substring(9,11);

			return true;

		}

	} // fim if (cpf.length < 15)

	return true;

}



// Verifica o email

function ValidaEmail(field) {

	var mail='';

	if (field.value == '') { return false; }

	else { mail = field; }

	

	if (mail.value == "") {

		alert("Informe seu e-mail.");

		mail.focus();

		mail.select();

		return false;

	}

	else {

		prim = mail.value.indexOf("@")

		if (prim < 2) {

			alert("O e-mail informado parece não estar correto.");

			mail.focus();

			mail.select();

			return false;

		}

		if (mail.value.indexOf("@",prim + 1) != -1) {

			alert("O e-mail informado parece não estar correto.");

			mail.focus();

			mail.select();

			return false;

		}

		if (mail.value.indexOf(".") < 1) {

			alert("O e-mail informado parece não estar correto.");

			mail.focus();

			mail.select();

			return false;

		}

		if (mail.value.indexOf(" ") != -1) {

			alert("O e-mail informado parece não estar correto.");

			mail.focus();

			mail.select();

			return false;

		}

		if (mail.value.indexOf("zipmeil.com") > 0) {

			alert("O e-mail informado parece não estar correto.");

			mail.focus();

			mail.select();

			return false;

		}

		if (mail.value.indexOf("hotmeil.com") > 0) {

			alert("O e-mail informado parece não estar correto.");

			mail.focus();

			mail.select();

			return false;

		}

		if (mail.value.indexOf(".@") > 0) {

			alert("O e-mail informado parece não estar correto.");

			mail.focus();

			mail.select();

			return false;

		}

		if (mail.value.indexOf("@.") > 0) {

			alert("O e-mail informado parece não estar correto.");

			mail.focus();

			mail.select();

			return false;

		}

		if (mail.value.indexOf(".com.br.") > 0) {

			alert("O e-mail informado parece não estar correto.");

			mail.focus();

			mail.select();

			return false;

		}

		if (mail.value.indexOf("/") > 0) {

			alert("O e-mail informado parece não estar correto.");

			mail.focus();

			mail.select();

			return false;

		}

		if (mail.value.indexOf("[") > 0) {

			alert("O e-mail informado parece não estar correto.");

			mail.focus();

			mail.select();

			return false;

		}

		if (mail.value.indexOf("]") > 0) {

			alert("O e-mail informado parece não estar correto.");

			mail.focus();

			mail.select();

			return false;

		}

		if (mail.value.indexOf("(") > 0) {

			alert("O e-mail informado parece não estar correto.");

			mail.focus();

			mail.select();

			return false;

		}

		if (mail.value.indexOf(")") > 0) {

			alert("O e-mail informado parece não estar correto.");

			mail.focus();

			mail.select();

			return false;

		}

		if (mail.value.indexOf("..") > 0) {

			alert("O e-mail informado parece não estar correto.");

			mail.focus();

			mail.select();

			return false;

		}

	}

	return true;

}



// Efetua pesquisa

function pesquisar() {

	var f = document.frmPesquisa;

	if (f.inc.value != "") {

		lcFiltro = window.prompt("Digite uma parte do texto para procurar:", "");

		if (lcFiltro != null) {

			window.open("", "pesquisa", "width=600,height=400,scrollbars=yes");

			f.action = "pesquisa.php";

			f.target = "pesquisa";

			f.txtFiltro.value = lcFiltro;

			f.submit();

		}

	}

}



// Mostra o Editor de Texto

function editor(poCampo, pcTitulo) {

	var f = document.frmEditor;

	f.txtCampo.value = "document." + poCampo.form.name + "." + poCampo.name;

	f.txtTitulo.value = pcTitulo;

	f.txtTexto.value = poCampo.value;

	window.open("", "editor", "width=525,height=450");

	f.submit();

}