// JavaScript Document
function Mascara(campo, teclaPress) 
{
	if (window.event)
	{
		var tecla = teclaPress.keyCode;
	} 
	else 
	{
		tecla = teclaPress.which;
	}
 
	var s = new String(campo.value);
	// Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
	s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
 
	tam = s.length + 1;
 
	if ( tecla != 9 && tecla != 8 ) 
	{
		if (tam > 2 && tam < 4)
			campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
		if (tam > 4 && tam < 11)
			campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
	}
}

function validaData(campo,valor) 
{
	var date=valor;
	var ardt=new Array;
	var ExpReg=new RegExp("(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[12][0-9]{3}");
	
	ardt = date.split("/");
	erro=false;
	
	if (date.search(ExpReg)==-1){
		erro = true;
		}
	else if (((ardt[1]==4)||(ardt[1]==6)||(ardt[1]==9)||(ardt[1]==11))&&(ardt[0]>30))
		erro = true;
	else if ( ardt[1]==2) {
		if ((ardt[0]>28)&&((ardt[2]%4)!=0))
			erro = true;
		if ((ardt[0]>29)&&((ardt[2]%4)==0))
			erro = true;
	} 
	
	if (erro) {
		alert("\"" + valor + "\" não é uma data válida.");
		//campo.focus();
		campo.value = "";
		return false;
	}
	return true;
}

function popupTabela() {
	window.open( "./tabela.php", "myWindow", "scrollbars=1, height = 600, width = 850" )
}

function formatar(src, mask)
{
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i);
	
	if (texto.substring(0,1) != saida)
	{
		src.value += texto.substring(0,1);
	}
}

var win = null;
function WinGraficos(mypage,myname,w,h)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height=' + h + ',width=' + w + ',top=' + TopPosition + ',left=' + LeftPosition +',scrollbars=yes';
	win = window.open(mypage,myname,settings);
}

function toogleFaq(id)
{
	document.getElementById('faq-res-' + id).style.display = (document.getElementById('faq-res-' + id).style.display != 'block') ? 'block' : 'none';
	document.getElementById('faq-title-' + id).className = (document.getElementById('faq-title-' + id).className != 'selected') ? 'selected' : '';
	void(0);
}

function hideComunicado()
{
	document.getElementById('txtComunicado').style.display = 'none';
}