//Informa a data do dia

function Data(){

	var hoje = new Date();
	var numdia = hoje.getDay();
	var nummes = hoje.getMonth();
	
	var dia = new Array(7);

	dia[0]= "Domingo";
	dia[1]= "Segunda-feira";
	dia[2]= "Ter&ccedil;a-feira";
	dia[3]= "Quarta-feira";
	dia[4]= "Quinta-feira";
	dia[5]= "Sexta-feira";
	dia[6]= "S&aacute;bado";


	var mes = new Array(12);

	mes[0] = "janeiro";
	mes[1] = "fevereiro";
	mes[2] = "mar&ccedil;o";
	mes[3] = "abril";
	mes[4] = "maio";
	mes[5] = "junho";
	mes[6] = "julho";
	mes[7] = "agosto";
	mes[8] = "setembro";
	mes[9] = "outubro";
	mes[10]= "novembro";
	mes[11]= "dezembro";

	if (hoje.getDate() < 10){
		DiaMes = "0" + hoje.getDate();
	}
	else{
		DiaMes = hoje.getDate();
	}
	
	document.write(dia[numdia]+ ", " + DiaMes + " de " + mes[nummes] + " " + hoje.getYear()); 

}

//Termina a execução do Programa
function TerminaPrograma(){
	//document.close();
	window.close();
}


	function FtrataBackSpace(dado, NumDecimal){

		zeros = Math.pow(10,NumDecimal) 
		NumDecimal = parseInt(NumDecimal);
	   NumDig = dado.value;
	   TamDig = NumDig.length;
	   TamDig--;
	   Contador = 0;
	   
	   if ((TamDig >= 0) && (event.keyCode == 8)){
			numer = "";
	      for (i = TamDig; (i >= 0); i--){

				if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)){
					Contador++;
					//alert(NumDig.substr(i, 1) + " Contador = " + Contador+ " numer = '"+ numer+ "' TamDig = " +TamDig + " i = " + i );
					if ((Contador == NumDecimal+1) && ((TamDig -i) < (NumDecimal+2))){
						numer = ","+numer;
	               Contador = 0;
					}
					else if ((Contador == 3) && (numer.length > NumDecimal)){
						numer = "."+numer;
						//numer = ""+numer; //não coloca a vírgula para não dar erro no SQL
						Contador = 0;
					}

					numer = NumDig.substr(i, 1)+numer;
				}
			}
			
			zeros = zeros.toString();

			if (numer == zeros.substring(1))
			    numer="";		
			if (numer.length == NumDecimal )
			    numer= "0," + numer;

			dado.value = numer;
		};
	   if ((TamDig >= 0) && (event.keyCode == 46)){
			//46 = Del
			numer = dado.value;
			if(numer.substr(0,1)== "."){
				numer = numer.substr(1);
				dado.value = numer;
			}
			else if(numer.substr(0,1)== ","){
				numer = "0" + numer.substr(0);
				dado.value = numer;
			}

			numer = dado.value;

			if(numer.substr(numer.length-1, 1) == "." ||
					numer.substr(numer.length-1, 1) == ","){

				dado.value = numer.substr(0, numer.length-1);
				return true;
			}
				
			
	   }
	}

	
	function FmascTempoReal(ConteudoCampo, NumDecimal){
	
		NumDecimal = parseInt(NumDecimal);
		
	   if (event.keyCode == 13) return true;
	   
		if (((event.keyCode) > 47) && ((event.keyCode) < 58)){
			NumDig = ConteudoCampo.value;
			TamDig = NumDig.length;

			//trocando o valor selecionado
			aa = document.selection.createRange();
			if (aa.text != ""){
				return true;
			}
			//Ignora os numeros após TamDig > que a largura do campo.
			if(TamDig == ConteudoCampo.maxLength) return false;

			Contador = 0;
			if (TamDig >= 1){
				numer = "";
				for (i = TamDig; (i >= 0); i--){
					if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)){
						Contador++;
						//Aumentou o nº de decimais de 2 para 3
						if ((Contador == NumDecimal) && ((TamDig -i) < (NumDecimal+2))){
							numer = ","+numer;
							Contador = 0;
						}
						else if (Contador == 3 && numer.length > NumDecimal){
							numer = "."+numer;
							Contador = 0;
						}
						numer = NumDig.substr(i, 1)+numer;
					}
				}
				ConteudoCampo.value = numer;
			};

			return(true)
		}
		else return(false)
	}


	/* Rotinas para formatar data, só aceita nº.
	 * Alcides
	 */
	function FmascData(ConteudoCampo){
		NumDig = ConteudoCampo.value;
		if (event.keyCode == 13 || NumDig.length == 10){
			return true;
		}
		if (((event.keyCode) > 47) && ((event.keyCode) < 58)){
			//NumDig = ConteudoCampo.value;
			TamDig = NumDig.length;

			Contador = 0;
			numer = "";
			for (i = 0; i <= TamDig; i++, ++Contador){
				if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)){
						
		         numer += NumDig.substr(i, 1);

					if (Contador == 1 || Contador == 4){
						numer += "/";
					}
				}
			}
			
		   ConteudoCampo.value = numer;
		   
			return(true)
		}
		else return(false)
	}

	/* Rotinas para verificar se é uma data válida
	 * Alcides
	 */
	function DataValida(ConteudoCampo, Verifica){
		var numer
		var dia, mes, ano

		numer = ConteudoCampo.value;
		
		if(Verifica == "") Verifica = false;
		
		if(Verifica && (numer.length < 10 && numer.length > 1)){
			alert("Data inválida!");
			ConteudoCampo.value = "";
			return false;
		}

		if(numer.length == 10 || Verifica){
			
			dia = parseFloat(numer.substring(0,2));
			mes = parseFloat(numer.substring(3,5));
			ano = parseFloat(numer.substring(6,10));

			if(mes < 1 || mes > 12 || dia < 1 || ano == 0){
				alert("Data inválida!");
				ConteudoCampo.value = "";
				return false;
			}

			switch (mes) {
				case 2:
					if(((ano%4==0 && ano%400 != 0) || ano%100==0) && dia > 29){
						alert("Data inválida!");
						ConteudoCampo.value = ""
						return false;
					}else{
						if(!((ano%4==0 && ano%400 != 0) || ano%100==0) && dia > 28){
							alert("Data inválida!");
							ConteudoCampo.value = "";
							return false;
						}
					}
					break;
				case 1:
				case 3:
				case 5:
				case 7:
				case 8:
				case 10:
				case 12:
					if(dia > 31){
						alert("Data inválida!");
						ConteudoCampo.value = "";
						return false;
					}
					break;
				case 4:
				case 6:
				case 9:
				case 11:
					if(dia > 30){
						alert("Data inválida!");
						ConteudoCampo.value = "";
						return false;
					}
					break;
				
				default:
					if(ConteudoCampo.value != ""){
						alert("Data inválida!");
						ConteudoCampo.value = "";
						return false;
					}

			}
		}
		return true;
	}
	
	/* Rotinas para verificar se as duas datas foram digitadas e
	 * se a primeira data é menor que a segunda
	 * Alcides
	 */
	function VerificaData(DataIni, DataFim){
		var dia, mes, ano, data1, data2

		data2 = DataFim.value;

		if(DataIni.value == "" || 
				DataFim.value == ""){
			alert("Informe as datas!");
			return false;
		}

		dia = DataIni.substring(0,2);
		mes = DataIni.substring(3,5);
		ano = DataIni.substring(6,10);
		
		data1	= new Date(ano, mes-1, dia);

		dia = DataFim.substring(0,2);
		mes = DataFim.substring(3,5);
		ano = DataFim.substring(6,10);

		data2	= new Date(ano, mes-1, dia);
		
		if(data1 > data2){
			alert("A data inicial deve ser menor que a data final!");
			return false;
		}
	}

//Valida o CGC, aceitando somente números, com o tamanho de 14 caracteres
function ValidaCGC(ConteudoCampo){
	NumDig = ConteudoCampo.value;
	if (event.keyCode == 13 || NumDig.length == 14){
		return true;
	}
	if (((event.keyCode) > 47) && ((event.keyCode) < 58)){
		NumDig = ConteudoCampo.value;
		TamDig = NumDig.length;

		numer = "";
		for (i = 0; i <= TamDig; i++){
			if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)){
						
	         numer += NumDig.substr(i, 1);

			}
		}
			
	   ConteudoCampo.value = numer;
		   
		return(true)
	}
	else return(false)
	
}

//Verifica se o CGC possui tamanho de 14 caracteres
function VerificaCGC(){
	dado = document.form1.CGC.value;
	if(dado.length < 14){
		alert("O CGC informado é inválido!");
		return false;
	}
	return true;
}


//Valida a entrada de dados aceitando somente números, 
//com o tamanho especificado de caracteres
function SoNumero(ConteudoCampo, largura){
	NumDig = ConteudoCampo.value;
	if (event.keyCode == 13 || NumDig.length == largura){
		return true;
	}
	if (((event.keyCode) > 47) && ((event.keyCode) < 58)){
		NumDig = ConteudoCampo.value;
		TamDig = NumDig.length;

		numer = "";
		for (i = 0; i <= TamDig; i++){
			if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)){
						
	         numer += NumDig.substr(i, 1);

			}
		}
			
	   ConteudoCampo.value = numer;
		   
		return(true)
	}
	else return(false)
	
}


function Maiuscula(){
	var letra = String.fromCharCode(event.keyCode);

	letra = letra.toUpperCase();
	letra = letra.charCodeAt(0);
	
	event.keyCode = letra;

}

///////////////////////////////////////////////////////////
//
// Funcao para validar o CPF
//
///////////////////////////////////////////////////////////

function ValidaCPF(CPF){

	var RecebeCPF, soma, resultado1, resultado2
	var Numero = new Array(11);
	var Repeticao, Digito
	RecebeCPF = CPF.value;
	

	if(RecebeCPF.length != 11 && RecebeCPF.length > 0){
		alert("É obrigatório o CPF com 11 dígitos");
		return false;
	}else if(RecebeCPF.length == 0){
		return false;
	}
	
	Digito = RecebeCPF.substr(0,1);
	for(i=1; i < 11; i++){
		if(RecebeCPF.substr(i,1) == Digito){
			Repeticao = true;
		}
		else{
			Repeticao = false;
			break;
		}
		
	}

	if(Repeticao){
		alert("CPF Inválido!");
		return false;
	}

	Numero[0]  = parseInt(RecebeCPF.substr(0,1));
	Numero[1]  = parseInt(RecebeCPF.substr(1,1));
	Numero[2]  = parseInt(RecebeCPF.substr(2,1));
	Numero[3]  = parseInt(RecebeCPF.substr(3,1));
	Numero[4]  = parseInt(RecebeCPF.substr(4,1));
	Numero[5]  = parseInt(RecebeCPF.substr(5,1));
	Numero[6]  = parseInt(RecebeCPF.substr(6,1));
	Numero[7]  = parseInt(RecebeCPF.substr(7,1));
	Numero[8]  = parseInt(RecebeCPF.substr(8,1));
	Numero[9]  = parseInt(RecebeCPF.substr(9,1));
	Numero[10] = parseInt(RecebeCPF.substr(10,1));


	soma = (10 * Numero[0]) + (9 * Numero[1]) + (8 * Numero[2]) + (7 * Numero[3]) + (6 * Numero[4]) + (5 * Numero[5]) + (4 * Numero[6]) + (3 * Numero[7]) + (2 * Numero[8])

	soma = soma -(11 * (parseInt(soma / 11)))

	if( soma == 0 || soma == 1)
		resultado1 = 0;
	else
		resultado1 = 11 - soma;

	if(resultado1 == Numero[9]){

		soma = (Numero[0] * 11) + (Numero[1] * 10) + (Numero[2] * 9) + (Numero[3] * 8) + (Numero[4] * 7) + (Numero[5] * 6) + (Numero[6] * 5) + (Numero[7] * 4) + (Numero[8] * 3) + (Numero[9] * 2)

		soma = soma -(11 * (parseInt(soma / 11)))

		if( soma == 0 || soma == 1)
			resultado2 = 0;
		else
			resultado2 = 11 - soma;

		if( resultado2 != Numero[10]){
			alert("CPF Inválido!");
			return false;
		}
		
	}else{
		alert("CPF Inválido!");
		return false;
	}
	
	return true;
	
}//end function


///////////////////////////////////////////////////////////
// Funcao para validar o CNPJ 
//
///////////////////////////////////////////////////////////

function ValidaCNPJ(CNPJ){

	var RecebeCNPJ, soma, resultado1, resultado2
	var Numero = new Array(14)
	
	RecebeCNPJ = CNPJ.value;
	if(RecebeCNPJ.length != 14){
		alert("É obrigatório o CNPJ com 14 dígitos!");
		return false;
	
	}else if( RecebeCNPJ == "00000000000000"){
		alert("CNPJ Inválido!");
		return false;
	}

	Numero[0]  = parseInt(RecebeCNPJ.substr(0,1));
	Numero[1]  = parseInt(RecebeCNPJ.substr(1,1));
	Numero[2]  = parseInt(RecebeCNPJ.substr(2,1));
	Numero[3]  = parseInt(RecebeCNPJ.substr(3,1));
	Numero[4]  = parseInt(RecebeCNPJ.substr(4,1));
	Numero[5]  = parseInt(RecebeCNPJ.substr(5,1));
	Numero[6]  = parseInt(RecebeCNPJ.substr(6,1));
	Numero[7]  = parseInt(RecebeCNPJ.substr(7,1));
	Numero[8]  = parseInt(RecebeCNPJ.substr(8,1));
	Numero[9]  = parseInt(RecebeCNPJ.substr(9,1));
	Numero[10] = parseInt(RecebeCNPJ.substr(10,1));
	Numero[11] = parseInt(RecebeCNPJ.substr(11,1));
	Numero[12] = parseInt(RecebeCNPJ.substr(12,1));
	Numero[13] = parseInt(RecebeCNPJ.substr(13,1));

	soma = (Numero[0] * 5) + (Numero[1] * 4) + (Numero[2] * 3) + 
			(Numero[3] * 2) + (Numero[4] * 9) + (Numero[5] * 8) + 
			(Numero[6] * 7) + (Numero[7] * 6) + (Numero[8] * 5) + 
			(Numero[9] * 4) + (Numero[10] * 3) + (Numero[11] * 2);

	soma = soma -(11 * (parseInt(soma / 11)));

	if(soma == 0 || soma == 1){
		resultado1 = 0;
	}else{
		resultado1 = 11 - soma;
	}

	if(resultado1 == Numero[12]){
		soma = (Numero[0] * 6) + (Numero[1] * 5) + (Numero[2] * 4) + (Numero[3] * 3) + (Numero[4] * 2) + (Numero[5] * 9) + (Numero[6] * 8) + (Numero[7] * 7) + (Numero[8] * 6) + (Numero[9] * 5) + (Numero[10] * 4) + (Numero[11] * 3) + (Numero[12] * 2);
		soma = soma - (11 * (parseInt(soma/11)));
		
		if(soma == 0 || soma == 1){
			resultado2 = 0;
		}else{
			resultado2 = 11 - soma;
		}
		
		if(resultado2 != Numero[13]){
			alert("CNPJ inválido!");
			return false;
		}
		
	}else{
		alert("CNPJ inválido!");
		return false;
	}

	return true;
	
} //end function


	/* Rotinas para formatar MesAno, só aceita nº.
	 * Alcides
	 */
	function FmascMesAno(ConteudoCampo){
		NumDig = ConteudoCampo.value;
		if (event.keyCode == 13 || NumDig.length == 7){
			return true;
		}
		if (((event.keyCode) > 47) && ((event.keyCode) < 58)){
			//NumDig = ConteudoCampo.value;
			TamDig = NumDig.length;

			Contador = 0;
			numer = "";
			for (i = 0; i <= TamDig; i++, ++Contador){
				if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)){
						
		         numer += NumDig.substr(i, 1);

					if (Contador == 1){
						numer += "/";
					}
				}
			}
			
		   ConteudoCampo.value = numer;
		   
			return(true)
		}
		else return(false)

	}

	/* Rotinas para verificar se é um MesAno válido
	 * Alcides
	 */
	function MesAnoValido(ConteudoCampo, Verifica){
		var mes, ano

		numer = ConteudoCampo.value;
		
		if(Verifica == "") Verifica = false;
		
		if(Verifica && (numer.length < 7 && numer.length > 1)){
			alert("Mês/Ano inválido!");
			ConteudoCampo.value = "";
			return false;
		}

		if(numer.length == 7 || Verifica){
			
			mes = parseFloat(numer.substring(0,2));
			ano = parseFloat(numer.substring(3,7));

			if(mes < 1 || mes > 12 || ano == 0){
				alert("Mês/Ano inválido!");
				ConteudoCampo.value = "";
				return false;
			}

		}
		return true;
	}



//Paginação dos Tabs
	function fnTabClick( nTab )
	{
		nTab = parseInt(nTab);
		var oTab;
		var prevTab = nTab-1;
		var nextTab = nTab+1;
		event.cancelBubble = true;
		el = event.srcElement;

		for (var i = 0; i < newsContent.length; i++)
		{
			oTab = tabs[i];
			oTab.className = "clsTab";
			oTab.style.borderLeftStyle = "";
			oTab.style.borderRightStyle = "";
			newsContent[i].style.display = "none";
		}
		newsContent[nTab].style.display = "block";
		tabs[nTab].className = "clsTabSelected";
		oTab = tabs[nextTab];
		if (oTab) oTab.style.borderLeftStyle = "none";
		oTab = tabs[prevTab];
		if (oTab) oTab.style.borderRightStyle = "none";
		event.returnValue = false;
	}

	function fnSaveState() {
		var iTabSelected = 0;
		var iLength = tabs.length;
		alert(iLength);
		for (var i = 0; i < iLength; i++) {
			if (tabs[i].className == "clsTabSelected") iTabSelected = i;
		}
		idTabs.setAttribute("tabstate", iTabSelected);
	}

	function fnGetState() {
		var iTabSelected = idTabs.getAttribute("tabstate");
		var iLength = tabs.length;
		for (var i = 0; i < iLength; i++) {
			if ( i != iTabSelected) {
				tabs[i].className = "clsTab";
				if (newsContent[i]) newsContent[i].style.display = "none";
			} else {
				tabs[i].className = "clsTabSelected";
				if (newsContent[i]) newsContent[i].style.display = "block";
			}
		}
	}
//Fim Paginação dos Tabs
	/* Rotinas para formatar Hora, só aceita nº.
	 * Alcides
	 */
	function FmascHora(ConteudoCampo){
		NumDig = ConteudoCampo.value;
		if (event.keyCode == 13 || NumDig.length == 5){
			return true;
		}
		if (((event.keyCode) > 47) && ((event.keyCode) < 58)){
			//NumDig = ConteudoCampo.value;
			TamDig = NumDig.length;

			Contador = 0;
			numer = "";
			for (i = 0; i <= TamDig; i++, ++Contador){
				if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)){
						
		         numer += NumDig.substr(i, 1);

					if (Contador == 1){
						numer += ":";
					}
				}
			}
			
		   ConteudoCampo.value = numer;
		   
			return(true)
		}
		else return(false)
	}

	/* Rotinas para verificar se é uma hora válida
	 * Alcides
	 */
	function HoraValida(ConteudoCampo, Verifica){
		var numer
		var Hora, Min

		numer = ConteudoCampo.value;
		
		if(Verifica == "") Verifica = false;
		
		if(Verifica && (numer.length < 5 && numer.length >= 1)){
			alert("Hora inválida!");
			ConteudoCampo.value = "";
			return false;
		}

		if(numer.length == 5 || Verifica){
			
			Hora = parseFloat(numer.substring(0,2));
			Min = parseFloat(numer.substring(3,5));

			if(Hora > 23 || Min > 59){
				alert("Hora inválida!");
				ConteudoCampo.value = "";
				return false;
			}

		}
		return true;
	}


	/*
	*	Rotina para contagem do tempo de seção
	*/
	
	var up,down;var min1,sec1;
	var cmin1,csec1,cmin2,csec2;

	function Minutes(data) {
		for(var i=0;i<data.length;i++) 
			if(data.substring(i,i+1)==":") 
				break;  
		return(data.substring(0,i)); 
	}

	function Seconds(data) {        
		for(var i=0;i<data.length;i++) 
			if(data.substring(i,i+1)==":") 
				break;  
		return(data.substring(i+1,data.length)); 
	}

	function Display(min,sec) {     
		var disp;       

		if(min<=9) 
			disp=" 0";   
		else 
			disp=" ";  
		
		disp+=min+":";  

		if(sec<=9) 
			disp+="0"+sec;       
		else 
			disp+=sec; 
		
		return(disp); 
	}


	function Down(vMin) {       
		//cmin2=1*Minutes("00:00");
		cmin2=1*vMin;
		csec2=0+Seconds("00:00");
		DownRepeat(); 
	}

	function DownRepeat() { 
		csec2--;        
		if(csec2==-1) { 
			csec2=59; 
			cmin2--; 
		}

		DisplayTimeSection.innerHTML=Display(cmin2,csec2) + " min";

		if((cmin2==0)&&(csec2==0)){
			aa = document.location.pathname;

			//for(i=0; i < aa.length; i++){
			//Pega a substring até a segunda "/"
			for(i=0; i < 2; i++){
				
				if(aa.indexOf("/", i) >= 0){
					indice = aa.indexOf("/", i);
					i = indice;
				}
				else{
					break;
				}
				
			}

			document.location.href = aa.substring(0, indice+1) + "index.asp";
				
		}
		else 
			down=setTimeout("DownRepeat()",1000); 
		
	}

/*
*	Calcula a idade da pessoa de acordo com a data do sistema.
*	Parametro: dd/mm/yyyy
*/
function CalculaIdade(DtNasc, IdadeEmAnos){
	var Dia, Mes, Ano
	var birthday, birthdayEntrada, today, years, meses, dias

	if(DtNasc == "")
		return false;
	
	if(IdadeEmAnos == "")		//Se IdadeEmAnos for verdadeiro, a
		IdadeEmAnos = false;		//função retorna um inteiro, referente
										//a idade em ANOS.  Senão, retorna uma
										//string com a idade, até em dias.


	// Establish larger units based on milliseconds.
	msecondsPerMinute = 1000 * 60;
	msecondsPerHour = msecondsPerMinute * 60;
	msecondsPerDay = msecondsPerHour * 24;

	Dia = parseFloat(DtNasc.substring(0,2));
	Mes = parseFloat(DtNasc.substring(3,5))-1;
	Ano = DtNasc.substring(6,10);
	
	birthday = new Date(Ano, Mes, Dia);
	birthdayEntrada = new Date(Ano, Mes, Dia);
	today = new Date();

	years = today.getFullYear() - birthday.getFullYear();
	meses = today.getMonth() - birthday.getMonth();

	//Se mês igual e ano diferente, então...
	if(today.getMonth() == birthday.getMonth() && today.getFullYear() != birthday.getFullYear()){
		meses = 12;
	}

	birthday.setYear( today.getFullYear() );

	// Se o seu aniversário ainda não aconteceu este ano, diminui 1.
	if(today < birthday){
		years-- ;
	}
	if(today.getDate() < birthday.getDate()){
		meses--;
	}

	if(! IdadeEmAnos){
		if(years > 0){
			if(years > 1){
				return (years + " anos");
			}
			else
				return (years + " ano");
	
		}else if(meses > 0){
			if(meses > 1)
				return (meses + " meses");
			else
				return (meses + " mes");
		}else{
			dias = Math.floor((today.getTime() - birthday.getTime()) / msecondsPerDay);

			if(dias > 1)
				return  (dias + " dias");
			else
				return  (dias + " dia");
		}
	}
	else{
		return years;
	}
	
}
	
/*
*	Função para mostrar a hora do sistema
*/	
function Relogio() {
	var hours, minutes, seconds;
	var intHours, intMinutes, intSeconds;
	var today;

	today = new Date();

	intHours = today.getHours();
	intMinutes = today.getMinutes();
	intSeconds = today.getSeconds();

	if (intHours < 10) { 
	   hours = "0" + intHours+":";
	} else {
	   hours = intHours + ":";
	}

	if (intMinutes < 10) {
	   minutes = "0"+intMinutes+":";
	} else {
	   minutes = intMinutes+":";
	}

	if (intSeconds < 10) {
	   seconds = "0"+intSeconds+" ";
	} else {
	   seconds = intSeconds+" ";
	} 

	timeString = hours+minutes+seconds;
	document.write(timeString);
	window.setTimeout("tick();", 100);
}

//Função para arredondar valores
function Arredonda(paramValue,decimal){
	var str, str2, strDec, xx = new String();
	var x, i, a;
	var xDec, xValue;

	str = paramValue + "";
	x = str.indexOf(".");

	if(x > 0){
		str = paramValue + "00000";
	}

	strDec = "";

	strDec = str.substr(x+1, decimal+1);

	xValue = parseFloat(str);

	a = "";
	if(x > -1){
		xx = str.substr(x+1, decimal+1);

		strDec = str.substr(x+1, decimal+1);

		if(xx.length > decimal){
				
			a = parseInt(xx.substr(decimal,1));

			if(a >= 5){

				if(xValue < 0){
					xValue -= ((1/Math.pow(10,decimal))-(a/Math.pow(10,decimal+1)));
				}else{
					xValue += parseFloat((1/Math.pow(10,decimal))-(a/Math.pow(10,decimal+1)));
				}
			}
		}
		strDec = xValue;
		for(i = 0; i < decimal; i++){
			strDec += "0";
		}
			
		str2 = str.substring(0,x) + "." + strDec.substring(0,decimal);
		str2 = strDec.substring(0,x+decimal+1);

		return str2;
	}else{
		strDec = str + ".";
		for(i = 0; i < decimal; i++){
			strDec += "0";
		}

		return strDec;
	}

}//Fim Arredonda


function Down(vMin) {       
	cmin2=1*vMin;
	csec2=0+Seconds("00:00");
	DownRepeat(); 
}

function DownRepeat() { 
	csec2--;        
	if(csec2==-1) { 
		csec2=59; 
		cmin2--; 
	}

	if((cmin2==0)&&(csec2==0)){
		top.document.location.href = "/novo/seguranca/sair.asp?idUsuario=<%=Session.SessionID%>";
	}
	else 
		down=setTimeout("DownRepeat()",1000); 
	
}

function popup()
{
    window.open('/novo/includes/usuarioOnline.asp', "janela", "toolbar=no,location=no,directories=no,status=yes,menubar=no,titlebar=no,scrollbars=yes,resizable=no,width=530,height=320, top=220, left=230");
}

//***************************************************************************************
//FUNCAO PARA MASCARAR CAMPOS HH:MM
/* 
 * @author: Sérgio Chaves - Mestra Informática 2003 
*/
//onkeypress="return mascaraHora(this, event)"  

function mascaraHora(objeto, e){
	var key = '';
	var strCheck = '0123456789';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	if (whichCode == 8) return true;  // BackSpace
	if (whichCode == 0) return true;  // Del
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1){ 
		return false;  // Not a valid key		
		}
		else{
			if (objeto.value.indexOf(":") == -1 && objeto.value.length > 5){ objeto.value = ""; }
			if (objeto.value.length == 2){
			objeto.value += ":";
		}
	}
}


//***************************************************************************************
//FUNCAO PARA VALIDAR CAMPOS HH:MM 
/* 
 * @author: Sérgio Chaves - Mestra Informática 2003 
*/
//onblur="validaHora(this)" 

function validaHora(Campo){
	var hora, minuto

	numer = Campo.value;
		
	if(numer != ""){
		if(numer.length < 5 && numer.length >= 1){
			alert("Hora inválida!");
			Campo.value = "";
			Campo.focus();
			return false;
		}
	
		if(numer.length == 5){
			
			hora = parseFloat(numer.substring(0,2));
			minuto = parseFloat(numer.substring(3,5));
	
			if(hora > 23 || minuto > 59){
				alert("Hora inválida!");
				Campo.value = "";
				Campo.focus();
				return false;
			}
	
		}
		return true;
	}
}
