var countTelaMapaFonte = 1;
var timeoutIdMapaFonte;
var pausedMapaFonte = false;

var countTelaMapaFonteDefesa = 1;
var timeoutIdMapaFonteDefesa;
var pausedMapaFonteDefesa = false;

var countTelaMapaFonteVarios = 1;
var timeoutIdMapaFonteVarios;
var pausedMapaFonteVarios = false;

var countTelaMercadoFinanceiro = 1;
var timeoutIdMercadoFinanceiro;
var pausedMercadoFinanceiro = false;

var countTelaClippingWeb = 1;
var timeoutIdClippingWeb;
var pausedClippingWeb = false;

var countTelaSlideShowGenerico = 1;
var timeoutIdSlideShowGenerico;
var pausedSlideShowGenerico = false;

var countTelaCases = 1;
var timeoutIdCases;
var pausedCases = false;

function iniciar(obj, total, ajax){
	if(obj=='mapaFonte'){
		if(pausedMapaFonte) {
			imgpause='on';
			altpause='alt="Ligar" title="Ligar"';
		} else {
			imgpause='offred';
			altpause='alt="Parar" title="Parar"';
		}
	} else if(obj=='mapaFonteDefesa'){
		if(pausedMapaFonteDefesa) {
			imgpause='on';
			altpause='alt="Ligar" title="Ligar"';
		} else {
			imgpause='offred';
			altpause='alt="Parar" title="Parar"';
		}
	} else if(obj=='mapaFonteVarios'){
		if(pausedMapaFonteVarios) {
			imgpause='on';
			altpause='alt="Ligar" title="Ligar"';
		} else {
			imgpause='offred';
			altpause='alt="Parar" title="Parar"';
		}
	}else if(obj=='mercadoFinanceiro'){
		if(pausedMercadoFinanceiro) {
			imgpause='on';
			altpause='alt="Ligar" title="Ligar"';
		} else {
			imgpause='offred';
			altpause='alt="Parar" title="Parar"';
		}
	}else if(obj=='clippingWeb'){
		if(pausedClippingWeb) {
			imgpause='on';
			altpause='alt="Ligar" title="Ligar"';
		} else {
			imgpause='offred';
			altpause='alt="Parar" title="Parar"';
		}
	}else if(obj=='slideShowGenerico'){
		if(pausedSlideShowGenerico) {
			imgpause='on';
			altpause='alt="Ligar" title="Ligar"';
		} else {
			imgpause='offred';
			altpause='alt="Parar" title="Parar"';
		}
	}else if(obj=='cases'){
		if(pausedCases) {
			imgpause='on';
			altpause='alt="Ligar" title="Ligar"';
		} else {
			imgpause='offred';
			altpause='alt="Parar" title="Parar"';
		}
	}
	
	if( ajax != "true" ) {
		document.write('<div style="width:100%; text-align:center; margin-top: -20px;">')
		document.write('	<a href= javascript:changeBox(-1,"'+obj+'",'+total+')>');
		document.write('	<img src="images/esqred.gif" border="0"/>');
		document.write('	<font class="moduloPortal"><b> anterior </b></font><a/>');
		document.write('	<img src="images/pause-'+imgpause+'.gif" height="10" onclick="pauseSlide(\''+obj+'\','+total+')" id="pause-'+obj+'" '+altpause+' />');
		document.write('	<a href= javascript:changeBox(1,"'+obj+'",'+total+')><font class="moduloPortal"><b> proximo </b></font>');
		document.write('	<img src="images/dirred.gif" border="0"/><a/>');
		document.write('</div>')
	}
	
	if(obj=='mapaFonte'){
		timeoutIdMapaFonte=setTimeout("changeBox('1','"+obj+"',"+total+")", 10000);
	} else if(obj=='mapaFonteVarios'){
		timeoutIdMapaFonteVarios=setTimeout("changeBox('1','"+obj+"',"+total+")", 10000);
	} else if(obj=='mapaFonteDefesa'){
		timeoutIdMapaFonteDefesa=setTimeout("changeBox('1','"+obj+"',"+total+")", 10000);
	}else if(obj=='mercadoFinanceiro'){
		timeoutIdMercadoFinanceiro=setTimeout("changeBox('1','"+obj+"',"+total+")", 10000);
	}else if(obj=='clippingWeb'){
		timeoutIdClippingWeb=setTimeout("changeBox('1','"+obj+"',"+total+")", 10000);
	}else if(obj=='slideShowGenerico'){
		timeoutIdSlideShowGenerico=setTimeout("changeBox('1','"+obj+"',"+total+")", 10000);
	}else if(obj=='cases'){
		timeoutIdCases=setTimeout("changeBox('1','"+obj+"',"+total+")", 10000);
	}
	changeContent(obj, total);
}

function pauseSlide(obj, total){
	if(obj=='mapaFonte'){
		if(pausedMapaFonte){
			document.getElementById('pause-'+obj).src='images/pause-offred.gif';
			document.getElementById('pause-'+obj).title='Parar'; document.getElementById('pause-'+obj).alt = 'Parar';
			pausedMapaFonte=false;
			timeoutIdMapaFonte=setTimeout("changeBox(1,'"+obj+"',"+total+")", 10000);
		}else{
			pausedMapaFonte = true;
			document.getElementById('pause-'+obj).src='images/pause-on.gif';
			document.getElementById('pause-'+obj).title='Ligar'; document.getElementById('pause-'+obj).alt = 'Ligar';
			clearTimeout(timeoutIdMapaFonte);
		}
	} else if(obj=='mapaFonteDefesa'){
		if(pausedMapaFonteDefesa){
			document.getElementById('pause-'+obj).src='images/pause-offred.gif';
			document.getElementById('pause-'+obj).title='Parar'; document.getElementById('pause-'+obj).alt = 'Parar';
			pausedMapaFonteDefesa=false;
			timeoutIdMapaFonteDefesa=setTimeout("changeBox(1,'"+obj+"',"+total+")", 10000);
		}else{
			pausedMapaFonteDefesa = true;
			document.getElementById('pause-'+obj).src='images/pause-on.gif';
			document.getElementById('pause-'+obj).title='Ligar'; document.getElementById('pause-'+obj).alt = 'Ligar';
			clearTimeout(timeoutIdMapaFonteDefesa);
		}
	} else if(obj=='mapaFonteVarios'){
		if(pausedMapaFonteVarios){
			document.getElementById('pause-'+obj).src='images/pause-offred.gif';
			document.getElementById('pause-'+obj).title='Parar'; document.getElementById('pause-'+obj).alt = 'Parar';
			pausedMapaFonteVarios=false;
			timeoutIdMapaFonteVarios=setTimeout("changeBox(1,'"+obj+"',"+total+")", 10000);
		}else{
			pausedMapaFonteVarios = true;
			document.getElementById('pause-'+obj).src='images/pause-on.gif';
			document.getElementById('pause-'+obj).title='Ligar'; document.getElementById('pause-'+obj).alt = 'Ligar';
			clearTimeout(timeoutIdMapaFonteVarios);
		}
	}else if(obj=='mercadoFinanceiro'){
		if(pausedMercadoFinanceiro){
			document.getElementById('pause-'+obj).src='images/pause-offred.gif';
			document.getElementById('pause-'+obj).title='Parar'; document.getElementById('pause-'+obj).alt = 'Parar';
			pausedMercadoFinanceiro=false;
			timeoutIdMercadoFinanceiro=setTimeout("changeBox(1,'"+obj+"',"+total+")", 10000);
		}else{
			pausedMercadoFinanceiro = true;
			document.getElementById('pause-'+obj).src='images/pause-on.gif';
			document.getElementById('pause-'+obj).title='Ligar'; document.getElementById('pause-'+obj).alt = 'Ligar';
			clearTimeout(timeoutIdMercadoFinanceiro);
		}
	}else if(obj=='clippingWeb'){
		if(pausedClippingWeb){
			document.getElementById('pause-'+obj).src='images/pause-offred.gif';
			document.getElementById('pause-'+obj).title='Parar'; document.getElementById('pause-'+obj).alt = 'Parar';
			pausedClippingWeb=false;
			timeoutIdClippingWeb=setTimeout("changeBox(1,'"+obj+"',"+total+")", 10000);
		}else{
			pausedClippingWeb = true;
			document.getElementById('pause-'+obj).src='images/pause-on.gif';
			document.getElementById('pause-'+obj).title='Ligar'; document.getElementById('pause-'+obj).alt = 'Ligar';
			clearTimeout(timeoutIdClippingWeb);
		}
	}else if(obj=='slideShowGenerico'){
		if(pausedSlideShowGenerico){
			document.getElementById('pause-'+obj).src='images/pause-offred.gif';
			document.getElementById('pause-'+obj).title='Parar'; document.getElementById('pause-'+obj).alt = 'Parar';
			pausedSlideShowGenerico=false;
			timeoutIdSlideShowGenerico=setTimeout("changeBox(1,'"+obj+"',"+total+")", 10000);
		}else{
			pausedSlideShowGenerico = true;
			document.getElementById('pause-'+obj).src='images/pause-on.gif';
			document.getElementById('pause-'+obj).title='Ligar'; document.getElementById('pause-'+obj).alt = 'Ligar';
			clearTimeout(timeoutIdSlideShowGenerico);
		}
	}else if(obj=='cases'){
		if(pausedCases){
			document.getElementById('pause-'+obj).src='images/pause-offred.gif';
			document.getElementById('pause-'+obj).title='Parar'; document.getElementById('pause-'+obj).alt = 'Parar';
			pausedCases=false;
			timeoutIdCases=setTimeout("changeBox(1,'"+obj+"',"+total+")", 10000);
		}else{
			pausedCases = true;
			document.getElementById('pause-'+obj).src='images/pause-on.gif';
			document.getElementById('pause-'+obj).title='Ligar'; document.getElementById('pause-'+obj).alt = 'Ligar';
			clearTimeout(timeoutIdCases);
		}
	}
}

function changeBox(id, obj, total){
	total = total*1;
	
	if(id<0){
		if(obj=='mapaFonte'){
			countTelaMapaFonte--;
			if(countTelaMapaFonte==0) countTelaMapaFonte = total;
		} else if(obj=='mapaFonteDefesa'){
			countTelaMapaFonteDefesa--;
			if(countTelaMapaFonteDefesa==0) countTelaMapaFonteDefesa = total;
		} else if(obj=='mapaFonteVarios'){
			countTelaMapaFonteVarios--;
			if(countTelaMapaFonteVarios==0) countTelaMapaFonteVarios = total;
		}else if(obj=='mercadoFinanceiro'){
			countTelaMercadoFinanceiro--;
			if(countTelaMercadoFinanceiro==0) countTelaMercadoFinanceiro = total;
		}else if(obj=='clippingWeb'){
			countTelaClippingWeb--;
			if(countTelaClippingWeb==0) countTelaClippingWeb = total;
		}else if(obj=='slideShowGenerico'){
			countTelaSlideShowGenerico--;
			if(countTelaSlideShowGenerico==0) countTelaSlideShowGenerico= total;
		}else if(obj=='cases'){
			countTelaCases--;
			if(countTelaCases==0) countTelaCases= total;
		}
	}else{
		if(obj=='mapaFonte'){
			countTelaMapaFonte++;
			if(countTelaMapaFonte==(total+1)) countTelaMapaFonte = 1;
		} else if(obj=='mapaFonteDefesa'){
			countTelaMapaFonteDefesa++;
			if(countTelaMapaFonteDefesa==(total+1)) countTelaMapaFonteDefesa = 1;
		} else if(obj=='mapaFonteVarios'){
			countTelaMapaFonteVarios++;
			if(countTelaMapaFonteVarios==(total+1)) countTelaMapaFonteVarios = 1;
		}else if(obj=='mercadoFinanceiro'){
			countTelaMercadoFinanceiro++;
			if(countTelaMercadoFinanceiro==(total+1)) countTelaMercadoFinanceiro = 1;
		}else if(obj=='clippingWeb'){
			countTelaClippingWeb++;
			if(countTelaClippingWeb==(total+1)) countTelaClippingWeb = 1;
		}else if(obj=='slideShowGenerico'){
			countTelaSlideShowGenerico++;
			if(countTelaSlideShowGenerico==(total+1)) countTelaSlideShowGenerico = 1;
		}else if(obj=='cases'){
			countTelaCases++;
			if(countTelaCases==(total+1)) countTelaCases = 1;
		}
	}
	
 
	if(document.all && navigator.userAgent.indexOf('Opera')==-1){
		try {
			oDiv = document.getElementById("to-blend-"+obj);
 			oDiv.style.filter="blendTrans(duration=0.7)";
			oDiv.filters.blendTrans.apply();
			oDiv.filters.blendTrans.play();
		} catch(e) {
		}
	} else {
		blend(obj, total);
	}
	
	if(obj=='mapaFonte'){
		clearTimeout(timeoutIdMapaFonte);
		changeContent(obj, total);
		timeoutIdMapaFonte=setTimeout("changeBox(1,'"+obj+"',"+total+")", 10000);
	} else if(obj=='mapaFonteDefesa'){
		clearTimeout(timeoutIdMapaFonteDefesa);
		changeContent(obj, total);
		timeoutIdMapaFonteDefesa=setTimeout("changeBox(1,'"+obj+"',"+total+")", 10000);
	} else if(obj=='mapaFonteVarios'){
		clearTimeout(timeoutIdMapaFonteVarios);
		changeContent(obj, total);
		timeoutIdMapaFonteVarios=setTimeout("changeBox(1,'"+obj+"',"+total+")", 10000);
	}else if(obj=='mercadoFinanceiro'){
		clearTimeout(timeoutIdMercadoFinanceiro);
		changeContent(obj, total);
		timeoutIdMercadoFinanceiro=setTimeout("changeBox(1,'"+obj+"',"+total+")", 10000);
	}else if(obj=='clippingWeb'){
		clearTimeout(timeoutIdClippingWeb);
		changeContent(obj, total);
		timeoutIdClippingWeb=setTimeout("changeBox(1,'"+obj+"',"+total+")", 10000);
	}else if(obj=='slideShowGenerico'){
		clearTimeout(timeoutIdSlideShowGenerico);
		changeContent(obj, total);
		timeoutIdSlideShowGenerico=setTimeout("changeBox(1,'"+obj+"',"+total+")", 10000);
	}else if(obj=='cases'){
		clearTimeout(timeoutIdCases);
		changeContent(obj, total);
		timeoutIdCases=setTimeout("changeBox(1,'"+obj+"',"+total+")", 10000);
	}
}

function changeContent(obj, total){
	try {
		for(i = 1; i <= total; i++){
			document.getElementById(obj+i).style.display = "none";
		}
		
		if(obj=='mapaFonte'){
			document.getElementById(obj+countTelaMapaFonte).style.display = "block";
		} else if(obj=='mapaFonteDefesa'){
			document.getElementById(obj+countTelaMapaFonteDefesa).style.display = "block";
		} else if(obj=='mapaFonteVarios'){
			document.getElementById(obj+countTelaMapaFonteVarios).style.display = "block";
		}else if(obj=='mercadoFinanceiro'){
			document.getElementById(obj+countTelaMercadoFinanceiro).style.display = "block";
		}else if(obj=='clippingWeb'){
			document.getElementById(obj+countTelaClippingWeb).style.display = "block";
		}else if(obj=='slideShowGenerico'){
			document.getElementById(obj+countTelaSlideShowGenerico).style.display = "block";
		}else if(obj=='cases'){
			document.getElementById(obj+countTelaCases).style.display = "block";
		}
	} catch(e) {
	}
}

function goToContent(obj, pos){
	var total = 0;
	if(obj=="cases"){
		countTelaCases = pos;
		total = formX.iniciarCases.value;
	}
	
	if(document.all && navigator.userAgent.indexOf('Opera')==-1){
		try {
			oDiv = document.getElementById("to-blend-"+obj);
 			oDiv.style.filter="blendTrans(duration=0.7)";
			oDiv.filters.blendTrans.apply();
			oDiv.filters.blendTrans.play();
		} catch(e) {
		}
	} else {
		blend(obj, total);
	}
	
	if(obj=='cases'){
		clearTimeout(timeoutIdCases);
		changeContent(obj, total);
		timeoutIdCases=setTimeout("changeBox(1,'"+obj+"',"+total+")", 10000);
	}
	
}

function blend(obj, total){
	try{
		var speed=7;
		var timer=0;
		for(i=100;i>0;i-=2)
			setTimeout('changeOpac('+obj+','+i+')', timer++ * speed);
		setTimeout('changeContent("'+obj+'",'+total+')', timer * speed);
		for(i=0;i<=100;i+=2)
			setTimeout('changeOpac('+obj+','+i+')', timer++ * speed);
	}catch(e){
	}
}

function changeOpac(obj, opacity){
	try{
		var obj = document.getElementById(obj+countTela).style;
		obj.opacity=(opacity/101);
		obj.MozOpacity=(opacity/101);
		obj.KhtmlOpacity=(opacity/101);
	}catch(e){
	}
}

// return the value of obj[selectedIndex] where obj is a option button
function getSelectedOption(obj) {
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].checked == true) {
			return obj[i].value;
		}
	}
}
function unmarkAllOption(obj) {
	for (var i = 0; i < obj.length; i++) {
		obj[i].checked = false;
	}
}

// se objOption[i].checked where obj[i].value match objField.value
function setSelectedOption(objField, obj) {
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].value == objField.value) {
			obj[i].checked = true;
			break;
		}
	}
}
function printThisPage() {
	var Browser;
	if (navigator.appName.toUpperCase().indexOf("EXPLORER") >= 0) {
		var Inicio = navigator.appVersion.indexOf(";") + 6;
		Browser = navigator.appVersion.substring(Inicio, navigator.appVersion.indexOf(";", Inicio) - 1);
		if (Browser >= 5) {
			window.print();
		} else {
			alert("Para imprimir pressione Ctrl+P");
		}
	} else {
		if (navigator.appName.toUpperCase().indexOf("NETSCAPE") >= 0) {
			Browser = navigator.appVersion.substring(0, 3);
			if (Browser >= 4.7) {
				window.print();
			} else {
				alert("Para imprimir pressione Ctrl+P");
			}
		} else {
			alert("Para imprimir pressione Ctrl+P");
		}
	}
}

// check functions
function checkText(key) {
}
function checkLong(key) {
	if (event.keyCode < 48 || event.keyCode > 57) {
		event.keyCode = null;
	}
}
function checkDouble(e) {
	if (e.keyCode < 48 || e.keyCode > 57) {
		if (e.keyCode == 44) {
			e.keyCode = 46;
		}
		if (e.keyCode != 46) {
			e.keyCode = null;
		}
	}
}
function checkDate(key) {
	if (event.keyCode != 45 && (event.keyCode < 47 || event.keyCode > 57)) {
		event.keyCode = null;
	}
}
function checkTime(key) {
	if (event.keyCode != 58 && (event.keyCode < 47 || event.keyCode > 57)) {
		event.keyCode = null;
	}
}
function isEmpty(obj) {
	if (obj.value.trim() == "") {
		return true;
	}
	return false;
}
function selectAllItem(listSource) {
	l1 = listSource.length;
	for (i = 0; i < l1; i++) {
		listSource.options[i].selected = true;
	}
}
function moveListItem(listSource, listDest) {
	l1 = listSource.length;
	for (i = 0; i < l1; i++) {
		if (listSource.options[i].selected == true) {
			l2 = listDest.length;
			achou = false;
			for (j = 0; j < l2; j++) {
				if (listSource.options[i].value == listDest.options[j].value) {
					achou = true;
					break;
				}
			}
			if (!achou) {
				listDest.options[l2] = new Option(listSource.options[i].text);
				listDest.options[l2].value = listSource.options[i].value;
			}
		}
	}
	for (i = l1 - 1; i >= 0; i--) {
		if (listSource.options[i].selected == true) {
			listSource.options[i] = null;
		}
	}
}
function moveAllListItem(listSource, listDest) {
	l1 = listSource.length;
	for (i = 0; i < l1; i++) {
		l2 = listDest.length;
		listDest.options[l2] = new Option(listSource.options[i].text);
		listDest.options[l2].value = listSource.options[i].value;
	}
	for (i = l1 - 1; i >= 0; i--) {
		listSource.options[i] = null;
	}
}
function readList(listSource, hiddenField) {
	l1 = listSource.length;
	r = "";
	for (i = 0; i < l1; i++) {
		r += listSource.options[i].value;
		if (i < (l1 - 1)) {
			r += ";";
		}
	}
	hiddenField.value = r;
}
function readListText(listSource, hiddenField) {
	l1 = listSource.length;
	r = "";
	for (i = 0; i < l1; i++) {
		r += listSource.options[i].text;
		if (i < (l1 - 1)) {
			r += ";";
		}
	}
	hiddenField.value = r;
}
function readListFull(listSource, hiddenField) {
	l1 = listSource.length;
	r = "";
	for (i = 0; i < l1; i++) {
		r += listSource.options[i].value + ";" + listSource.options[i].text;
		if (i < (l1 - 1)) {
			r += ";";
		}
	}
	hiddenField.value = r;
}
function open_help(page) {
	var janela = window.open(page, "help", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=no,width=500,height=480");
	janela.focus();
}

function maisDetalhes( div ) {
	if( document.getElementById(div).style.display == "none" ) {
		document.getElementById(div).style.display="block";
	} else {
		menosDetalhes(div);
	}
}
function menosDetalhes( div ) {
	document.getElementById(div).style.display="none";
}
function maisDetalhes2( div ) {
	document.getElementById(div).style.height="auto";
}

function desabilitarTela() {
	try {
		var h=document.body.clientHeight;
		if (document.body.scrollHeight > document.body.clientHeight) {
			h=document.body.scrollHeight;
		}
		
	    document.getElementById("graybox").style.height = h+"px";
		document.getElementById("graybox").style.visibility="visible";
	} catch (e) {
	}
}
function habilitarTela() {
	try {
		document.getElementById("graybox").style.visibility="hidden";
	} catch (e) {
	}
}

function desabilitarTela2() {
	try {
		var h=document.body.clientHeight;
		if (document.body.scrollHeight > document.body.clientHeight) {
			h=document.body.scrollHeight;
		}
		
		document.getElementById("graybox2").style.height = h+"px";
		document.getElementById("graybox2").style.visibility="visible";
	} catch (e) {
	}
}
function desabilitarTelaNoticia() {
	try {
		var h=document.body.clientHeight;
		if (document.body.scrollHeight > document.body.clientHeight) {
			h=document.body.scrollHeight;
		}
	    document.getElementById("grayBoxNoticia").style.height = h+"px";
		document.getElementById("grayBoxNoticia").style.visibility="hidden";
	} catch (e) {
	}
}
function habilitarTela2() {
	try {
		document.getElementById("graybox2").style.visibility="hidden";
	} catch (e) {
	}
}

function noNumber(e){
	var keynum;
	var keychar;
	var numcheck;
	
	if(window.event){ // IE
		keynum = e.keyCode;
	}else if(e.which){ // Netscape/Firefox/Opera
		keynum = e.which;
	}
	keychar = String.fromCharCode(keynum);
	numcheck = /\d/;
	return !numcheck.test(keychar);
}

function noChar(e){
	var keynum;
	var keychar;
	var numcheck;
	
	if(window.event){ // IE
		keynum = e.keyCode;
	}else if(e.which){ // Netscape/Firefox/Opera
		keynum = e.which;
	}

	if(keynum == 8 || keynum == 46 || keynum == 44 || keynum == null){
		return true;
	}else{
		keychar = String.fromCharCode(keynum);
		numcheck = /\D/;
		return !numcheck.test(keychar);
	}
}

function verifica_email(txtEmail){
	var email = txtEmail.value;
	var regex = new RegExp("^[a-zA-Z\\d\\._-]*@[a-zA-Z0-9-]*(\\.[a-zA-Z]*)(\\.[a-zA-Z]*)?(\\.[a-zA-Z]{2})?");

	if(!regex.test(email))
		return false;
	
	email = email.replace(regex, "");
	if(email.length>=1){
		return false;
	}

	return true;
}

function verifica_data(txtData){
	var data = txtData.value;
	var date = new Date()
	var ano_atual = date.getFullYear();
	
	if (data.length == 0){
		return true;
	}				
	if (data.length != 10 && data.length != 0){
		alert("Data preenchida incorretamente.");
		txtData.value = "";
		txtData.focus();
		return false;
	}
	
	dia = new Number(data.substring(0,2));
	mes = new Number(data.substring(3,5));
	ano = new Number(data.substring(6));
	situacao = "";
	
	if (data.substring(2,3) != "/" || data.substring(5,6) != "/"){
		situacao = "falsa";
	}
	// verifica o dia valido para cada mes
	if (dia < 1 || ((dia < 01 || dia > 30) && (  mes == 4 || mes == 6 || mes == 9 || mes == 11 )) || dia > 31) {
		situacao = "falsa";
	}
	// verifica se o mes e valido
	if (mes < 1 || mes > 12 ) {
		situacao = "falsa";
	}
	// verifica se e ano bissexto
	if (mes == 2 && ( dia < 1 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) {
		situacao = "falsa";
	}
	// verifica ano
	if(ano > ano_atual){
		situacao = "falsa";
	}
		
	if (situacao == "falsa") {
		alert("Data preenchida incorretamente.");
		txtData.value = "";
		txtData.focus();
		return false;
	}
	
	// verifica idade
	if(ano < (ano_atual - 100)){
		alert("Data muito antiga.");
		txtData.value = "";
		txtData.focus();
		return false;
	}
	return true;
}
function limparSalario(valor, validos) {
// retira caracteres invalidos da string
	var result = "";
	var aux;
	for (var i=0; i < valor.length; i++) {
		aux = validos.indexOf(valor.substring(i, i+1));
		if (aux>=0) {
			result += aux;
		}
	}
	return result;
}
//Formata número tipo moeda usando o evento onKeyDown
function formataSalario(campo,tammax,teclapres,decimal) {
	var tecla;
	if(window.event) tecla = teclapres.keyCode;
	else tecla = teclapres.which;
	vr = limparSalario(campo.value,"0123456789");
	tam = vr.length;
	dec=decimal

	if (tam < tammax && tecla != 8){ 
		tam = vr.length + 1 ; 
	}

	if (tecla == 8 ){
		tam = tam - 1 ; 
	}
	
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= dec ){
			campo.value = vr ; 
		}
		if ( (tam > dec) && (tam <= 5) ){
			campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; 
		}
		if ( (tam >= 6) && (tam <= 8) ){
			campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
		}
		if ( (tam >= 9) && (tam <= 11) ){
			campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
		}
		if ( (tam >= 12) && (tam <= 14) ){
			campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
		}
		if ( (tam >= 15) && (tam <= 17) ){
			campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;
		}
	} else{
		return false;
	}
}

function formata(campo,estilo,sonum,e) {
	if(estilo == 'cnpj')
		estilo = '##.###.###/####-##';
		
	if(estilo == 'cep')
		estilo = '#####-###';
		
	if(estilo == 'tel')
		estilo = '####-####';
		
	if(estilo == 'rg')
		estilo = '##.###.###-#';
		
	if(estilo == 'cpf')
		estilo = '###.###.###-##';
		
	if(estilo == 'data')
		estilo = '##/##/####';
		
	if(estilo == 'hora')
		estilo = '##:##:##';
		
	if(estilo == 'horaMin')
		estilo = '##:##';
		
	if(estilo == 'ie' && document.cadastro.estado.value == ""){
		document.cadastro.estado.focus();
		estilo = '#';
	}
	
	if(estilo == 'ie' && document.cadastro.estado.value == 'AC')
		estilo = '##.###.###/###-##';

	if(estilo == 'ie' && (document.cadastro.estado.value == 'AL' || document.cadastro.estado.value == 'AP'
												|| document.cadastro.estado.value == 'CE' || document.cadastro.estado.value == 'ES'
												|| document.cadastro.estado.value == 'MA' || document.cadastro.estado.value == 'MS'
												|| document.cadastro.estado.value == 'PA' || document.cadastro.estado.value == 'PB'
												|| document.cadastro.estado.value == 'PI'))
		estilo = '##.######-#';
			
	if(estilo == 'ie' && document.cadastro.estado.value == 'AM')
		estilo = '##.###.###-#';
		
	if(estilo == 'ie' && document.cadastro.estado.value == 'BA')
		estilo = '###.###-##';
		
	if(estilo == 'ie' && document.cadastro.estado.value == 'DF')
		estilo = '##.######.###-##';

	if(estilo == 'ie' && (document.cadastro.estado.value == 'GO' || document.cadastro.estado.value == 'RN'))
		estilo = '##.###.###-#';
		
	if(estilo == 'ie' && document.cadastro.estado.value == 'MT')
		estilo = '####.######-#';
	
	if(estilo == 'ie' && document.cadastro.estado.value == 'MG')
		estilo = '###.###.###/####';
		
	if(estilo == 'ie' && (document.cadastro.estado.value == 'SP' || document.cadastro.estado.value == '0'))
		estilo = '###.###.###.###';
	
	if(estilo == 'ie' && document.cadastro.estado.value == 'PR')
		estilo = '###.#####-##';
		
	if(estilo == 'ie' && document.cadastro.estado.value == 'PE')
		estilo = '##.#.###.#######-#';
		
	if(estilo == 'ie' && document.cadastro.estado.value == 'RJ')
		estilo = '##.###.##-#';
		
	if(estilo == 'ie' && document.cadastro.estado.value == 'RS')
		estilo = '###/######-#';
		
	if(estilo == 'ie' && document.cadastro.estado.value == 'RO')
		estilo = '#############-#';
	
	if(estilo == 'ie' && (document.cadastro.estado.value == 'RR' || document.cadastro.estado.value == 'SE'))
		estilo = '########-#';
		
	if(estilo == 'ie' && document.cadastro.estado.value == 'SC')
		estilo = '###.###.###';

	if(estilo == 'ie' && document.cadastro.estado.value == 'TO')
		estilo = '##########-#';			


	var keycode;
	if(window.event)
		keycode = e.keyCode;
	else if(e.which)
		keycode = e.which;
	
	if(keycode == 8 || keycode == 46 || keycode == null){
		return true;
	}else{
		cnum = false;
		
		for(i=48;i<=57;i++){
			if(keycode == i)
				cnum = true;
		}
		
		for(i=96;i<=105;i++){
			if(keycode == i)
				cnum = false;
		}
	
		if(sonum && !cnum)
			return false;
	
		retorno = "";
	
		for(i=0;i<=campo.value.length;i++){
			if(i < estilo.length){
				if(estilo.charAt(i) == '#')
					retorno += campo.value.charAt(i);
				else
					retorno += estilo.charAt(i);
			}
			else{
				return false;
			}
		}
	
		campo.value = retorno;
	}
}
