// - expressão regular para validação de e-mail
expressao_email = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/

// rotina de validação do formulário de contatos
function checkForm(qual) {
	if(qual.nome.value=='') { 
		alert("Favor informar seu nome completo.")
		qual.nome.focus();
		return false ;
	}
	else if(!expressao_email.test(qual.email.value)) { 
		alert("Favor fornecer seu e-mail, para contatos")
		qual.email.focus();
		return false;
	}
	else if(qual.assunto.value=='') { 
		alert("Favor informar o assunto de sua mensagem.");
		qual.assunto.focus();
		return false;
	}	
	else if(qual.mensagem.value=='') { 
		alert("Favor digitar a sua mensagem.");
		qual.mensagem.focus();
		return false; 
	}	
	else {
		qual.submit();
	}
}

// rotina de validação do formulário de Imprensa
function form_press(qual) {
	if(qual.titulo.value=='') { 
		alert("Favor digitar o título da matéria.")
		qual.titulo.focus();
		return false ;
	}
	else if(qual.materia.value=='') { 
		alert("Favor digitar o conteúdo da matéria.");
		return false; 
	}
	else if(qual.materia.value != ''){
		var htmlCode = qual.materia.value;
		if (htmlCode.substr(0, 8).toUpperCase() == '<P CLASS'){
			str = 'Não é permitida a cópia direta de textos provinientes de arquivos do WORD\n\n';
			str += 'Dica:\n';
			str += '1º - copie o texto e cole-o no Bloco de Notas.\n';
			str += '2º - copie o texto do Bloco de Notas e cole-o, agora, no campo apropriado.';
			alert(str);
			return false;
		}	
	}
	else {
		qual.submit();
	}
}
// rotina de validação dos formulários de login no módulo administrativo
function Form_Validator(theForm){
	if (theForm.modulo.value == "") {
		alert("Escolha o módulo.");
		theForm.modulo.focus();
		return (false);
	}
	if (theForm.login.value == "") {
		alert("Entre com seu Login");
		theForm.login.focus();
		return (false);
	}
	if (theForm.senha.value == "") {
		alert("Entre com sua Senha");
		theForm.senha.focus();
		return (false);
	}
	var checkOK = "0123456789-";
	var checkStr = theForm.senha.value;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
			break;
		if (j == checkOK.length){
			allValid = false;
			break;
		}
		allNum += ch;
	}
	if (!allValid){
		alert("Favor digitar apenas números para o campo Senha");
		theForm.senha.focus();
		return (false);
	}
	return (true);
}

// rotina de validação do formulário de novo login, no módulo administrativo
function loginValidation(theForm){
 if (theForm.nome.value == ""){
  alert("Favor digitar o NOME");
	theForm.nome.focus();
  return (false);	
 }
 if (theForm.username.value == ""){
  alert("Favor digitar o USERNAME");
	theForm.username.focus();
  return (false);
 }
  if (theForm.password.value == ""){
		alert("Entre com sua Senha");
		theForm.password.focus();
		return (false);
	}
	var checkOK = "0123456789-";
	var checkStr = theForm.password.value;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
			break;
		if (j == checkOK.length){
			allValid = false;
			break;
		}
		allNum += ch;
	}
	if (!allValid){
		alert("Favor digitar apenas números para o campo Senha");
		theForm.password.focus();
		return (false);
	}
}

// rotina de validação de checkbox
function checkbox_checker(){
	var checkbox_choices = 0;		
	if(typeof(FORM1.reg.length)=="undefined"){
		if (FORM1.reg.checked){
			checkbox_choices = checkbox_choices + 1;
		}
	}
	for (counter = 0; counter < FORM1.reg.length; counter++){		
		if (FORM1.reg[counter].checked){
			checkbox_choices = checkbox_choices + 1;
		}
	}
	
	if (checkbox_choices == 0){
		alert("Pelo menos 1 registro deve ser selecionado.")
		return (false);		
	}	
	return (true);
}

// seleciona todos checkboxes
function check(acao){
	e = document.FORM1.elements;
	if(!acao){
		document.checkers.elements[0].checked = false;
	}else{
		document.checkers.elements[1].checked = false;
	}
	for(i=0;i<e.length;i++){
		if(e[i].type == "checkbox") e[i].checked = acao;		
	}	
}
function lastModified(){

	var dayArray = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var monthArray = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var lastUpdate = new Date(document.lastModified);
	var thisDay=dayArray[lastUpdate.getDay()];
	var thisDate=lastUpdate.getDate() < 10 ? '0'+lastUpdate.getDate() : lastUpdate.getDate();
	var thisMonth=monthArray[lastUpdate.getMonth()];
	var thisMonthNum=lastUpdate.getMonth()+1 < 10 ? '0'+ (lastUpdate.getMonth()+1) : lastUpdate.getMonth()+1;
	var thisFullYear=String(lastUpdate.getFullYear());
	var thisYear= thisFullYear.charAt(2) + thisFullYear.charAt(3);
	
	document.write("Última Atualização: ");
	document.write(thisDate + '/' + thisMonthNum + '/' + thisFullYear);
}

// rotina de validação do formulário de Downloads
function downValidation(theForm){
 if (theForm.arquivo.value == ""){
  alert("Forneça a rota do arquivo, dentro do seu equipamento. \n\n\Atenção! O nome do arquivo não pode conter acentos e espaços entre as palavras.\nUna as palavras com urderline ( _ ), por exemplo: teste_facil.zip. \n\n\Observe também que só é possível fazer UpLoad de arquivos compactados, com extenção .ZIP.");
	theForm.arquivo.focus();
  return (false);	
 }else{
 		myString = theForm.arquivo.value
		myString = myString.toLowerCase()
		splitString = myString.substring(myString.length-3,myString.length)
		if (splitString !='zip' && splitString !='pdf'){
			alert("Só é possível fazer UpLoad de arquivos compactados, com extenção .ZIP ou PDF.");
			theForm.Descricao.focus();
		  return (false);
		}
 }
 if (theForm.Descricao.value == ""){
  alert("Favor fornecer descrição sucinta do conteúdo do arquivo");
	theForm.Descricao.focus();
  return (false);
 }
}
// rotina de validação do formulário de Downloads
function downValidation2(theForm){
 if (theForm.Descricao.value == ""){
  alert("Favor fornecer descrição sucinta do conteúdo do arquivo");
	theForm.Descricao.focus();
  return (false);
 }
}
// rotina de validação do formulário de INFORMATIVOS
function infoValidation(theForm){
 if (theForm.arquivo.value == ""){
  alert("Forneça a rota do arquivo, dentro do seu equipamento. \n\n\Atenção! O nome do arquivo não pode conter acentos e espaços entre as palavras.\nUna as palavras com urderline ( _ ), por exemplo: teste_facil.pdf. \n\n\Observe também que só é possível fazer UpLoad de arquivos com extenção .PDF.");
	theForm.arquivo.focus();
  return (false);	
 }else{
 		myString = theForm.arquivo.value
		myString = myString.toLowerCase()
		splitString = myString.substring(myString.length-3,myString.length)
		if (splitString !='pdf'){
			alert("Só é possível fazer UpLoad de arquivos com extenção .PDF.");
			theForm.Descricao.focus();
		  return (false);
		}
 }
 if (theForm.Descricao.value == ""){
  alert("Favor fornecer descrição sucinta do conteúdo do arquivo");
	theForm.Descricao.focus();
  return (false);
 }
}
// rotina de validação do formulário de INFORMATIVOS - EDIÇÃO
function infoValidation2(theForm){
 if (theForm.Descricao.value == ""){
  alert("Favor fornecer descrição sucinta do conteúdo do arquivo");
	theForm.Descricao.focus();
  return (false);
 }
}
// rotina de validação do formulário da Galeria de Fotos

function galeryValidation(theForm){
	if (theForm.evento.value == ""){
		alert("Selecione o evento da galeria de fotos");
		theForm.evento.focus();
		return (false);
	}
	if (theForm.posicao[0].checked){
		dim1 = "96 x 128"
		dim2 = "480 x 640"
	}else{
		dim1 = "128 x 96"
		dim2 = "640 x 480"
	}
 if (theForm.arquivo_pqn.value == ""){
  alert("Forneça a rota do arquivo, dentro do seu equipamento. \n\nAtenção! O nome do arquivo não pode conter acentos e espaços entre as palavras. \n\Una as palavras com urderline ( _ ), por exemplo: cena_otima.jpg. \n\nObserve também que só é possível fazer UpLoad de arquivos que contenham \na extensão .JPG, com a dimensão de "+dim1+" pixels.");
	theForm.arquivo_pqn.focus();
  return (false);	
 }else{
 		myString = theForm.arquivo_pqn.value
		myString = myString.toLowerCase()
		splitString = myString.substring(myString.length-3,myString.length)
		if (splitString !='jpg'){
			alert("Só é possível fazer UpLoad de arquivos compactados, com extenção .JPG.");
			theForm.arquivo_pqn.focus();
		  return (false);
		}
 }
 
 if (theForm.arquivo_grd.value == ""){
  alert("Forneça a rota do arquivo, dentro do seu equipamento. \n\nAtenção! O nome do arquivo não pode conter acentos e espaços entre as palavras. \n\Una as palavras com urderline ( _ ), por exemplo: cena_otima.jpg. \n\nObserve também que só é possível fazer UpLoad de arquivos que contenham \na extensão .JPG, com a dimensão de "+dim2+" pixels");
	theForm.arquivo_grd.focus();
  return (false);	
 }else{
 		myString = theForm.arquivo_grd.value
		myString = myString.toLowerCase()
		splitString = myString.substring(myString.length-3,myString.length)		
		if (splitString !='jpg'){
			alert("Só é possível fazer UpLoad de arquivos compactados, com extenção .JPG.");
			theForm.arquivo_grd.focus();
		  return (false);
		}
 }
 
}
// rotina de validação do formulário de Upadate de Galeria de Fotos
function galeryValidation2(theForm){
/*	if (theForm.posicao[0].checked){
		dim1 = "96 x 128"
		dim2 = "480 x 640"
	}else{
		dim1 = "128 x 96"
		dim2 = "640 x 480"
	}*/
 if (theForm.Descricao.value == ""){
  alert("Favor fornecer legenda para o conteúdo da foto");
	theForm.Descricao.focus();
  return (false);
 }
}


// rotina de validação do formulário de reserva de hotel

function checkFormHotel(qual) {
	if(qual.nome.value=='') { 
		alert("Favor informar seu nome completo.")
		qual.nome.focus();
		return false ;
	}
	if(qual.endereco.value=='') { 
		alert("Favor informar seu endereço")
		qual.endereco.focus();
		return false ;
	}
	if(qual.cep.value=='') { 
		alert("Favor informar o Código de Endereçamento Postal, no formato: “99999-999”")
		qual.cep.focus();
		return false ;
	}
	if(qual.cep.value !=''){ 
		var procPat = /^(\d{5})(\-)(\d{3})$/;
	   	var matchArray = qual.cep.value.match(procPat);
		if (matchArray == null) {
			alert("Favor informar o Código de Endereçamento Postal, no formato: “99999-999”")
			qual.cep.focus();
			qual.cep.value='';
			return false ;
		}
	}
	if(qual.bairro.value=='') { 
		alert("Favor informar o Bairro")
		qual.bairro.focus();
		return false ;
	}
	if(qual.municipio.value=='') { 
		alert("Favor informar o Município")
		qual.municipio.focus();
		return false ;
	}
	if(qual.uf.value=='') { 
		alert("Favor informar a Unidade Federativa")
		qual.uf.focus();
		return false ;
	}
	if(qual.telefone.value=='') { 
		alert("Favor informar seu telefone")
		qual.telefone.focus();
		return false ;
	}
/*	if (qual.telefone.value != "") {
	   var procPat2 = /^(\()(\d{2})(\))(\ )(\d{2})(\-)(\d{4})$/;
	   var procPat3 = /^(\d{2})(\ )(\d{3})(\-)(\d{4})$/;
	   var procPat4 = /^(\d{2})(\ )(\d{4})(\-)(\d{4})$/;
	   
	   var matchArray2 = qual.telefone.value.match(procPat2); 
	   var matchArray3 = qual.telefone.value.match(procPat3);
	   var matchArray4 = qual.telefone.value.match(procPat4);
	   if (matchArray2 == null && matchArray3 == null && matchArray4 == null) {
	   		alert("Favor informar seu telefone, no formato “(99)##99-9999”")
	    	qual.telefone.value='';
				qual.telefone.focus();
	    	return false;
	   }
	}
*/
	if(!expressao_email.test(qual.e_mail.value) ){ 
		alert("Favor fornecer um Endereço Eletrônico válido, para que possamos enviar o protoloco eletrônico da reserva")
		qual.e_mail.value='';
		qual.e_mail.focus();
		return false ;
	}
	if(qual.hotel.value=='') { 
		alert("Favor fornecer o nome do Hotel escolhido")
		qual.hotel.focus();
		return false ;
	}

	var checkbox_choices = 0;		
	if(typeof(qual.apartamento.length)=="undefined"){
		if (qual.apartamento.checked){
			checkbox_choices = checkbox_choices + 1;
		}
	}
	for (counter = 0; counter < qual.apartamento.length; counter++){		
		if (qual.apartamento[counter].checked){
			checkbox_choices = checkbox_choices + 1;
		}
	}
	if (checkbox_choices == 0){
		alert("Favor indicar o Tipo de Apartamento escolhido")		
		return false;
	}	
	if(qual.hotel_dtchegada.value=='') { 
		alert("Favor indicar sua Data de Chegada no Hotel")
		qual.hotel_dtchegada.focus();
		return false ;
	}
	if (qual.hotel_dtchegada.value != "") {
		var datePat = /^(\d{2})(\/)(\d{2})\2(\d{4})$/;
		var matchArray = qual.hotel_dtchegada.value.match(datePat); // is the format ok?
		if (matchArray == null) {
			alert("Favor digitar a data no formato dd/mm/aaaa.")
			qual.hotel_dtchegada.focus();
			return false;
		}
		day = matchArray[1]; // parse date into variables
		month = matchArray[3];
		year = matchArray[4];
		if (day < 1 || day > 31) {
			alert("O dia deve estar entre 1 e 31.");
			qual.hotel_dtchegada.focus();
			return false;
		}
		if (month < 1 || month > 12) { // check month range
			alert("O mês deve estar entre 01 e 12.");
			qual.hotel_dtchegada.focus();
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			alert("O mês "+month+" não tem 31 dias!")
			qual.hotel_dtchegada.focus();
			return false
		}
		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap)) {
				alert("Fevereiro " + year + " não tem " + day + " dias!");
				qual.hotel_dtchegada.focus();
				return false;
			}
		}
		if (year < 1900) {
			alert("O ano é inválido.");
			qual.hotel_dtchegada.focus();
			return false;
		}
	}
	if(qual.hotel_dtsaida.value=='') { 
		alert("Favor indicar sua Data de Saída do Hotel")
		qual.hotel_dtsaida.focus();
		return false ;
	}
	if (qual.hotel_dtsaida.value != "") {
		var datePat = /^(\d{2})(\/)(\d{2})\2(\d{4})$/;
		var matchArray = qual.hotel_dtsaida.value.match(datePat); // is the format ok?
		if (matchArray == null) {
			alert("Favor digitar a data no formato dd/mm/aaaa.")
			qual.hotel_dtsaida.focus();
			return false;
		}
		day = matchArray[1]; // parse date into variables
		month = matchArray[3];
		year = matchArray[4];
		if (day < 1 || day > 31) {
			alert("O dia deve estar entre 1 e 31.");
			qual.hotel_dtsaida.focus();
			return false;
		}
		if (month < 1 || month > 12) { // check month range
			alert("O mês deve estar entre 01 e 12.");
			qual.hotel_dtsaida.focus();
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			alert("O mês "+month+" não tem 31 dias!")
			qual.hotel_dtsaida.focus();
			return false
		}
		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap)) {
				alert("Fevereiro " + year + " não tem " + day + " dias!");
				qual.hotel_dtsaida.focus();
				return false;
			}
		}
		if (year < 1900) {
			alert("O ano é inválido.");
			qual.hotel_dtsaida.focus();
			return false;
		}
	}
	var checkbox_reserva = 0;	
	var reserva ='não';	
	if(typeof(qual.reserva_passagem.length)=="undefined"){
		if (qual.reserva_passagem.checked){
			checkbox_reserva = checkbox_reserva + 1;
		}
	}
	for (counter = 0; counter < qual.reserva_passagem.length; counter++){		
		if (qual.reserva_passagem[counter].checked){
			reserva = qual.reserva_passagem[counter].value;
			checkbox_reserva = checkbox_reserva + 1;
		}
	}
	if (checkbox_reserva == 0){
		alert("Favor informar se deseja, ou não Reservar Passagem Aérea");
		return false;
	}
	if(reserva == 'sim'){
		if(qual.passagem_trecho.value=='') { 
			alert("Favor informar o Trecho de Vôo a ser percorrido");
			qual.passagem_trecho.focus();
			return false;
		}
		if(qual.passagem_dtchegada.value=='') { 
			alert("Favor informar a Data de Chegada do Vôo")
			qual.passagem_dtchegada.focus();
			return false ;
		}
		if (qual.passagem_dtchegada.value != "") {
			var datePat = /^(\d{2})(\/)(\d{2})\2(\d{4})$/;
			var matchArray = qual.passagem_dtchegada.value.match(datePat); // is the format ok?
			if (matchArray == null) {
				alert("Favor digitar a data no formato dd/mm/aaaa.")
				qual.passagem_dtchegada.focus();
				return false;
			}
			day = matchArray[1]; // parse date into variables
			month = matchArray[3];
			year = matchArray[4];
			if (day < 1 || day > 31) {
				alert("O dia deve estar entre 1 e 31.");
				qual.passagem_dtchegada.focus();
				return false;
			}
			if (month < 1 || month > 12) { // check month range
				alert("O mês deve estar entre 01 e 12.");
				qual.passagem_dtchegada.focus();
				return false;
			}
			if ((month==4 || month==6 || month==9 || month==11) && day==31) {
				alert("O mês "+month+" não tem 31 dias!")
				qual.passagem_dtchegada.focus();
				return false
			}
			if (month == 2) { // check for february 29th
				var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
				if (day>29 || (day==29 && !isleap)) {
					alert("Fevereiro " + year + " não tem " + day + " dias!");
					qual.passagem_dtchegada.focus();
					return false;
				}
			}
			if (year < 1900) {
				alert("O ano é inválido.");
				qual.passagem_dtchegada.focus();
				return false;
			}
		}
		if(qual.passagem_dtsaida.value=='') { 
			alert("Favor informar a Data de Saída do Vôo")
			qual.passagem_dtsaida.focus();
			return false ;
		}
		if (qual.passagem_dtsaida.value != "") {
			var datePat = /^(\d{2})(\/)(\d{2})\2(\d{4})$/;
			var matchArray = qual.passagem_dtsaida.value.match(datePat); // is the format ok?
			if (matchArray == null) {
				alert("Favor digitar a data no formato dd/mm/aaaa.")
				qual.passagem_dtsaida.focus();
				return false;
			}
			day = matchArray[1]; // parse date into variables
			month = matchArray[3];
			year = matchArray[4];
			if (day < 1 || day > 31) {
				alert("O dia deve estar entre 1 e 31.");
				qual.passagem_dtsaida.focus();
				return false;
			}
			if (month < 1 || month > 12) { // check month range
				alert("O mês deve estar entre 01 e 12.");
				qual.passagem_dtsaida.focus();
				return false;
			}
			if ((month==4 || month==6 || month==9 || month==11) && day==31) {
				alert("O mês "+month+" não tem 31 dias!")
				qual.passagem_dtsaida.focus();
				return false
			}
			if (month == 2) { // check for february 29th
				var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
				if (day>29 || (day==29 && !isleap)) {
					alert("Fevereiro " + year + " não tem " + day + " dias!");
					qual.passagem_dtsaida.focus();
					return false;
				}
			}
			if (year < 1900) {
				alert("O ano é inválido.");
				qual.passagem_dtsaida.focus();
				return false;
			}
		}
	}
	var checkbox_translado = 0;	
	var translado ='não';	
	if(typeof(qual.translado_reservar.length)=="undefined"){
		if (qual.translado_reservar.checked){
			checkbox_translado = checkbox_translado + 1;
		}
	}
	for (counter = 0; counter < qual.translado_reservar.length; counter++){		
		if (qual.translado_reservar[counter].checked){
			translado = qual.translado_reservar[counter].value;
			checkbox_translado = checkbox_translado + 1;
		}
	}
	if (checkbox_translado == 0){
		alert("Favor informar se deseja, ou não Reservar Translado São Paulo/Campos do Jordão/São Paulo");
		return false;
	}
	
	/*if(translado == 'sim'){
		if(qual.voo_chegada.value=='') { 
			alert("Favor indicar o Número do Vôo e a Cia. Aérea")
			qual.voo_chegada.focus();
			return false ;
		}
		if(qual.voo_saida.value=='') { 
			alert("Favor indicar o Número do Vôo e a Cia. Aérea")
			qual.voo_saida.focus();
			return false ;
		}
		
	}*/
	var checkbox_hotel = 0;	
	if(typeof(qual.hotel_pagto.length)=="undefined"){
		if (qual.hotel_pagto.checked){
			checkbox_hotel = checkbox_hotel + 1;
		}
	}
	for (counter = 0; counter < qual.hotel_pagto.length; counter++){		
		if (qual.hotel_pagto[counter].checked){
			translado = qual.hotel_pagto[counter].value;
			checkbox_hotel = checkbox_hotel + 1;
		}
	}
	if (checkbox_hotel == 0){
		alert("Favor indicar a forma de pagamento desejada para a reserva do hotel");
		return false;
	}
}

// rotina de validação do formulário de Inscrição Eletrônica

function validaInscricao(qual){
	if(qual.nome.value=='') { 
		alert("Favor informar seu nome completo.")
		qual.nome.focus();
		return false ;
	}
	if(qual.cracha_titular.value=='') { 
		alert("Favor informar nome para crachá (até 20 caracteres).")
		qual.cracha_titular.focus();
		return false ;
	}
	if(qual.endereco.value=='') { 
		alert("Favor informar seu endereço")
		qual.endereco.focus();
		return false ;
	}
	if(qual.cep.value=='') { 
		alert("Favor informar o Código de Endereçamento Postal, no formato: “99999-999”")
		qual.cep.focus();
		return false ;
	}
	if(qual.cep.value !=''){ 
		var procPat = /^(\d{5})(\-)(\d{3})$/;
	   	var matchArray = qual.cep.value.match(procPat);
		if (matchArray == null) {
			alert("Favor informar o Código de Endereçamento Postal, no formato: “99999-999”")
			qual.cep.focus();
			qual.cep.value='';
			return false ;
		}
	}
	if(qual.bairro.value=='') { 
		alert("Favor informar o Bairro")
		qual.bairro.focus();
		return false ;
	}
	if(qual.municipio.value=='') { 
		alert("Favor informar o Município")
		qual.municipio.focus();
		return false ;
	}
	if(qual.uf.value=='') { 
		alert("Favor informar a Unidade Federativa")
		qual.uf.focus();
		return false ;
	}
	if(qual.telefone.value=='') { 
		alert("Favor informar seu telefone")
		qual.telefone.focus();
		return false ;
	}
/*	if (qual.telefone.value != "") {
	   var procPat2 = /^(\()(\d{2})(\))(\ )(\d{2})(\-)(\d{4})$/;
	   var procPat3 = /^(\d{2})(\ )(\d{3})(\-)(\d{4})$/;
	   var procPat4 = /^(\d{2})(\ )(\d{4})(\-)(\d{4})$/;
	   
	   var matchArray2 = qual.telefone.value.match(procPat2); 
	   var matchArray3 = qual.telefone.value.match(procPat3);
	   var matchArray4 = qual.telefone.value.match(procPat4);
	   if (matchArray2 == null && matchArray3 == null && matchArray4 == null) {
	   		alert("Favor informar seu telefone, no formato “(99)##99-9999”")
	    	qual.telefone.value='';
				qual.telefone.focus();
	    	return false;
	   }
	}
*/
	if(!expressao_email.test(qual.e_mail.value) ){ 
		alert("Favor fornecer um Endereço Eletrônico válido, para que possamos enviar o protoloco eletrônico da inscrição")
		qual.e_mail.value='';
		qual.e_mail.focus();
		return false ;
	}
	if(qual.nome_recibo.value=='') { 
		alert("Favor informar em nome de quem devemos emitir o recibo.")
		qual.nome_recibo.focus();
		return false ;
	}
	var checkbox_inscricao = 0;	
	if(typeof(qual.tipo_inscricao.length)=="undefined"){
		if (qual.tipo_inscricao.checked){
			checkbox_inscricao = checkbox_inscricao + 1;
		}
	}
	for (counter = 0; counter < qual.tipo_inscricao.length; counter++){		
		if (qual.tipo_inscricao[counter].checked){
			translado = qual.tipo_inscricao[counter].value;
			checkbox_inscricao = checkbox_inscricao + 1;
		}
	}
	if (checkbox_inscricao == 0){
		alert("Favor indicar que tipo(s) de inscrição(ões) devemos formalizar");
		return false;
	}
}


// rotina de validação do formulário de Inscrição Eletrônica - Administrativo

function validaInscricaoAdm(qual){
	if(qual.nome.value=='') { 
		alert("Favor informar seu nome completo.")
		qual.nome.focus();
		return false ;
	}
	if (qual.data_nascimento.value != "") {
		var datePat = /^(\d{2})(\/)(\d{2})\2(\d{4})$/;
		var matchArray = qual.data_nascimento.value.match(datePat); // is the format ok?
		if (matchArray == null) {
			alert("Favor digitar a data no formato dd/mm/aaaa.")
			qual.data_nascimento.focus();
			return false;
		}
		day = matchArray[1]; // parse date into variables
		month = matchArray[3];
		year = matchArray[4];
		if (day < 1 || day > 31) {
			alert("O dia deve estar entre 1 e 31.");
			qual.data_nascimento.focus();
			return false;
		}
		if (month < 1 || month > 12) { // check month range
			alert("O mês deve estar entre 01 e 12.");
			qual.data_nascimento.focus();
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			alert("O mês "+month+" não tem 31 dias!")
			qual.data_nascimento.focus();
			return false
		}
		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap)) {
				alert("Fevereiro " + year + " não tem " + day + " dias!");
				qual.data_nascimento.focus();
				return false;
			}
		}
		if (year < 1900) {
			alert("O ano é inválido.");
			qual.data_nascimento.focus();
			return false;
		}
	}
	if(qual.cpf.value == '000.000.000-00') { 		
		alert("Valor invalido de CPF")
		qual.cpf.focus();
		return false ;
	}
	if(qual.cpf.value!='') { 		
		sim = cpf(qual.cpf.value)
		if (!sim) { 
			alert("Valor invalido de CPF")
			qual.cpf.focus();
			return false ;
		}else{
			qual.cpf_fmtfd.value = qual.cpf.value
		}
	}
	
	if(qual.cracha_titular.value=='') { 
		alert("Favor informar nome para crachá (até 20 caracteres).")
		qual.cracha_titular.focus();
		return false ;
	}
	if(qual.endereco.value=='') { 
		alert("Favor informar seu endereço")
		qual.endereco.focus();
		return false ;
	}
	if(qual.cep.value=='') { 
		alert("Favor informar o Código de Endereçamento Postal, no formato: “99999-999”")
		qual.cep.focus();
		return false ;
	}
	if(qual.cep.value !=''){ 
		var procPat = /^(\d{5})(\-)(\d{3})$/;
	   	var matchArray = qual.cep.value.match(procPat);
		if (matchArray == null) {
			alert("Favor informar o Código de Endereçamento Postal, no formato: “99999-999”")
			qual.cep.focus();
			qual.cep.value='';
			return false ;
		}
	}
	if(qual.bairro.value=='') { 
		alert("Favor informar o Bairro")
		qual.bairro.focus();
		return false ;
	}
	if(qual.municipio.value=='') { 
		alert("Favor informar o Município")
		qual.municipio.focus();
		return false ;
	}
	if(qual.uf.value=='') { 
		alert("Favor informar a Unidade Federativa")
		qual.uf.focus();
		return false ;
	}
	if(qual.telefone.value=='') { 
		alert("Favor informar seu telefone")
		qual.telefone.focus();
		return false ;
	}
	if(qual.e_mail.value !=''){
		if(!expressao_email.test(qual.e_mail.value) ){ 
			alert("Favor fornecer um Endereço Eletrônico válido, para que possamos enviar o protoloco eletrônico da inscrição")
			qual.e_mail.value='';
			qual.e_mail.focus();
			return false ;
		}
	}
	if(qual.nome_recibo.value=='') { 
		alert("Favor informar em nome de quem devemos emitir o recibo.")
		qual.nome_recibo.focus();
		return false ;
	}
	var checkbox_inscricao = 0;	
	if(typeof(qual.tipo_inscricao.length)=="undefined"){
		if (qual.tipo_inscricao.checked){
			checkbox_inscricao = checkbox_inscricao + 1;
		}
	}
	for (counter = 0; counter < qual.tipo_inscricao.length; counter++){		
		if (qual.tipo_inscricao[counter].checked){
			translado = qual.tipo_inscricao[counter].value;
			checkbox_inscricao = checkbox_inscricao + 1;
		}
	}
	if (checkbox_inscricao == 0){
		alert("Favor indicar que tipo(s) de inscrição(ões) devemos formalizar");
		return false;
	}
	if (qual.data_deposito.value != "") {
		var datePat = /^(\d{2})(\/)(\d{2})\2(\d{4})$/;
		var matchArray = qual.data_deposito.value.match(datePat); // is the format ok?
		if (matchArray == null) {
			alert("Favor digitar a data no formato dd/mm/aaaa.")
			qual.data_deposito.focus();
			return false;
		}
		day = matchArray[1]; // parse date into variables
		month = matchArray[3];
		year = matchArray[4];
		if (day < 1 || day > 31) {
			alert("O dia deve estar entre 1 e 31.");
			qual.data_deposito.focus();
			return false;
		}
		if (month < 1 || month > 12) { // check month range
			alert("O mês deve estar entre 01 e 12.");
			qual.data_deposito.focus();
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			alert("O mês "+month+" não tem 31 dias!")
			qual.data_deposito.focus();
			return false
		}
		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap)) {
				alert("Fevereiro " + year + " não tem " + day + " dias!");
				qual.data_deposito.focus();
				return false;
			}
		}
		if (year < 1900) {
			alert("O ano é inválido.");
			qual.data_deposito.focus();
			return false;
		}
	}
	if(qual.valor_deposito.value!=''){
		valido = isMoney(qual.valor_deposito.value)
		if(!valido){
			alert("Formato de moeda inválido. Favor preencher no formato 00,00")
			qual.valor_deposito.focus()
			return false
		}
	}
	
}
function isMoney(str) {
	var objRegExp  = /^[0-9]*,\d{2}$/;
	return objRegExp.test(str);
}


// função para desabilitar / abilitar checkbox de inscrições eletrônicas
function able(){
	if(form1.cracha_acompanhante.value==''){
		form1.tipo_inscricao[2].disabled=1
	}else{
		form1.tipo_inscricao[2].disabled=0
	}
}

function recibo(){
	form1.nome_recibo.value = form1.nome.value
}

function cpf(pcpf){
	pcpf = pcpf.replace( " ", "" );
	pcpf = pcpf.replace( ".", "" );
	pcpf = pcpf.replace( ".", "" );
	pcpf = pcpf.replace( "-", "" );
	if (pcpf.length != 11) {
 		sim=false
	}
	else {
		sim=true
	}
	if (sim ) {// valida o primeiro digito
	  	for (i=0;((i<=(pcpf.length-1))&& sim); i++){
		   	val = pcpf.charAt(i)
		   	if((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4")&&(val!="5")&&(val!="6")&&(val!="7")&&(val!="8")){
				sim=false
			}
	   	}
		if (sim){
		    soma = 0
		    for (i=0;i<=8;i++){
		     val = eval(pcpf.charAt(i))
		     soma = soma + (val*(i+1))
		    }
	    	resto = soma % 11
		    if (resto>9) dig = resto -10
		    else  dig = resto
		    if (dig != eval(pcpf.charAt(9))) { 
				sim=false 
			}
		 	else { // valida o segundo digito
				soma = 0
				for (i=0;i<=7;i++){
		    		val = eval(pcpf.charAt(i+1))
		    		soma = soma + (val*(i+1))
				}
			soma = soma + (dig * 9)
		    resto = soma % 11
		    if (resto>9) dig = resto -10
		    else  dig = resto
		   	if (dig != eval(pcpf.charAt(10))) { 
				sim = false 
			}
	    	else sim = true
	   	}
	}
 }
 return sim;
}
// rotina de validação do formulário de produção científica (End User e ADM) 

function checkPDCeu(qual) {

	if(qual.desc.value=='') { 
		alert("É necessário fornecer o Título do trabalho científico - máx.: 255 caracteres")
		qual.desc.focus();
		return false ;
	}	
	if(qual.desc2.value=='') { 
		alert("É necessário apresentar Síntese (resumo) sobre o que versa o trabalho científico - máx.: 2500 caracteres");
		qual.desc2.focus();
		return false;
	}
	if(qual.rota.value=='') { 
		alert("É necessário apresentar o Arquivo do trabalho científico no formato PDF ou DOC");
		qual.rota.focus();
		return false;
	}
	else{
 		myString = qual.rota.value
		myString = myString.toLowerCase()
		splitString = myString.substring(myString.length-3,myString.length)
		if ((splitString !='pdf')&&(splitString !='doc')){
			alert("Só é possível fazer UpLoad de arquivos com extenção .PDF ou .DOC.");
			qual.rota.focus();
		  return false;
		}
	}
}


function checkPDC(qual) {
	if(qual.desc.value=='') { 
		alert("É necessário fornecer o Título do trabalho científico - máx.: 255 caracteres")
		qual.desc.focus();
		return false ;
	}	
	if(qual.desc2.value=='') { 
		alert("É necessário apresentar Síntese (resumo) sobre o que versa o trabalho científico - máx.: 2500 caracteres");
		qual.desc2.focus();
		return false;
	}
	if(qual.rota.value=='') { 
		alert("É necessário apresentar o Arquivo do trabalho científico no formato PDF");
		qual.rota.focus();
		return false;
	}
	else{
 		myString = qual.rota.value
		myString = myString.toLowerCase()
		splitString = myString.substring(myString.length-3,myString.length)
		if (splitString !='pdf'){
			alert("Só é possível fazer UpLoad de arquivos com extenção .PDF.");
			qual.rota.focus();
		  return false;
		}
	}
}
//Fim da rotina de validação do formulário de produção científica (End User e ADM) 
function CheckLen(target){
	MAXCHARACTERS = 512;
	CharsLeft = MAXCHARACTERS;
	StrLen = target.value.length;
	if (target.name == "desc"){
		if (StrLen == 1 && document.form1.desc.value.substring(0,1) == " "){
	    	document.form1.desc.value = "";
	    	StrLen = 0;
	    }
		StrLen = StrLen + document.form1.callback.value.length ;
		if (StrLen > MAXCHARACTERS){
	   		document.form1.desc.value = document.form1.desc.value.substring(0,document.form1.desc.value.length-1);
	   		CharsLeft = 0;
	   	}
	   	else{
	  		CharsLeft = CharsLeft - StrLen;
		}
	}		
	else{
		if (StrLen == 1 && document.form1.callback.value.substring(0,1) == " "){
    		document.form1.callback.value = "";
    		StrLen = 0;
		}
		StrLen = StrLen + document.form1.desc.value.length ;
		if (StrLen > MAXCHARACTERS){
		    document.form1.callback.value = document.form1.callback.value.substring(0,document.form1.callback.value.length-1);
		    CharsLeft = 0;
		}
		else{
    		CharsLeft = CharsLeft - StrLen;
		}
	}
	document.form1.totalCounter.value = CharsLeft;
}

function CheckLen2(target){
	MAXCHARACTERS = 4000;
	CharsLeft = MAXCHARACTERS;
	StrLen = target.value.length;
	if (target.name == "desc"){
		if (StrLen == 1 && document.form1.desc2.value.substring(0,1) == " "){
	    	document.form1.desc2.value = "";
	    	StrLen = 0;
	    }
		StrLen = StrLen + document.form1.callback2.value.length ;
		if (StrLen > MAXCHARACTERS){
	   		document.form1.desc2.value = document.form1.desc2.value.substring(0,document.form1.desc2.value.length-1);
	   		CharsLeft = 0;
	   	}
	   	else{
	  		CharsLeft = CharsLeft - StrLen;
		}
	}		
	else{
		if (StrLen == 1 && document.form1.callback2.value.substring(0,1) == " "){
    		document.form1.callback2.value = "";
    		StrLen = 0;
		}
		StrLen = StrLen + document.form1.desc2.value.length ;
		if (StrLen > MAXCHARACTERS){
		    document.form1.callback2.value = document.form1.callback2.value.substring(0,document.form1.callback2.value.length-1);
		    CharsLeft = 0;
		}
		else{
    		CharsLeft = CharsLeft - StrLen;
		}
	}
	document.form1.totalCounter2.value = CharsLeft;
}

// rotina para abrir pop-up padrão
function abrir(URL) {
	window.open(URL,'', 'width=500, height=350, top=99, left=99, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, fullscreen=no');
}

// rotina de validação do formulário de Guia de Restaurantes e Hoteis
function validaGuia(qual) {
	if(!(qual.tipo[0].checked)&&!(qual.tipo[1].checked)){
		alert("Favor informar o tipo do estabelecimento.")
		return false ;
	}
	if(qual.estabelecimento.value=='') { 
		alert("Favor informar o nome do estabelecimento.")
		qual.estabelecimento.focus();
		return false ;
	}
	if(qual.endereco.value=='') { 
		alert("Favor informar seu endereço")
		qual.endereco.focus();
		return false ;
	}
	if(qual.bairro.value=='') { 
		alert("Favor informar o Bairro")
		qual.bairro.focus();
		return false ;
	}
	if(qual.municipio.value=='') { 
		alert("Favor informar o Município")
		qual.municipio.focus();
		return false ;
	}
	if(qual.conceito.value=='') { 
		alert("Classifique o estabelecimento.")
		qual.conceito.focus();
		return false ;
	}
}

// rotina para formatar data
function MascaraData (campo,teclapres){
	separador = '/'; 
	conjunto1 = 2;
	conjunto2 = 5;
	var tecla = teclapres.keyCode;
	vr = event.srcElement.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;

	if (tam < 10 && tecla != 8){ tam = vr.length + 1 ; }
	if (tecla == 8 ){ tam = tam - 1 ; }
	if ( tecla == 8 || tecla >= 48 && tecla <= 57){
		if (campo.value.length == conjunto1){
			campo.value = campo.value + separador;
		}
		if (campo.value.length == conjunto2){
			campo.value = campo.value + separador;
		}
	}else{
		event.keyCode = '127';
	}
}

function Mascara(src, teclapres, mask){
	switch (mask){
		case 'DATA':
			mask = '##/##/####';
			maskSize = 9
		break
		case 'TIME':
			mask = '##:##';
			maskSize = 5
		break
		case 'CPF':
			mask = '###.###.###-##';
			maskSize = 13
		break;
		case 'CEP':
			mask = '#####-###';
			maskSize = 7
		break;
		case 'CNPJ':
			mask = '##.###.###/####-##';
			maskSize = 17
		break;
		default:
			mask
			maskSize = mask.length - 1
		break;
	}
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i);
	var tecla = teclapres.keyCode;
	var vr = event.srcElement.value;
	var tam = vr.length;
	if(tam > maskSize) event.keyCode = '127';
	
		if (tam < 10 && tecla != 8)	tam = vr.length + 1 ;
		if (tecla == 8 ) tam = tam - 1 ;
		if (tecla >= 48 && tecla <= 57){
			if (texto.substring(0,1) != saida)
				src.value += texto.substring(0,1);
		}else{
			event.keyCode = '127';
		}
}


// construindo o calendário
function popdate(obj,div,tam,ddd){
	if (ddd){
		day = ""
		mmonth = ""
		ano = ""
		c = 1
		char = ""
	  for (s=0;s<parseInt(ddd.length);s++){
	  	char = ddd.substr(s,1)
	    if (char == "/"){
	    	c++; 
	      s++; 
	      char = ddd.substr(s,1);
			}
	    if (c==1) day    += char
	    if (c==2) mmonth += char
	    if (c==3) ano    += char
		}
		ddd = mmonth + "/" + day + "/" + ano
	}
	
	if(!ddd) {today = new Date()} else {today = new Date(ddd)}
	date_Form = eval (obj)
	if (date_Form.value == "") { date_Form = new Date()} else {date_Form = new Date(date_Form.value)}
	
	ano = today.getFullYear();
	mmonth = today.getMonth ();
	day = today.toString ().substr (8,2)
	
	umonth = new Array ("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro")
	days_Feb = (!(ano % 4) ? 29 : 28)
	days = new Array (31, days_Feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
	
	if ((mmonth < 0) || (mmonth > 11))  alert(mmonth)
	if ((mmonth - 1) == -1) {month_prior = 11; year_prior = ano - 1} else {month_prior = mmonth - 1; year_prior = ano}
	if ((mmonth + 1) == 12) {month_next  = 0;  year_next  = ano + 1} else {month_next  = mmonth + 1; year_next  = ano}
	txt  = "<table bgcolor='#efefff' style='border:solid #999999; border-width:2' cellspacing='0' cellpadding='3' border='0' width='"+tam+"' height='"+tam*1.1 +"'>"
	txt += "<tr bgcolor='#FFFFFF'><td colspan='7' align='center'><table border='0' cellpadding='0' width='100%' bgcolor='#FFFFFF'><tr>"
	txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+((mmonth+1).toString() +"/01/"+(ano-1).toString())+"') class='Cabecalho_Calendario' title='Ano Anterior'><<</a></td>"
	txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+( "01/" + (month_prior+1).toString() + "/" + year_prior.toString())+"') class='Cabecalho_Calendario' title='Mês Anterior'><</a></td>"
	txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+( "01/" + (month_next+1).toString()  + "/" + year_next.toString())+"') class='Cabecalho_Calendario' title='Próximo Mês'>></a></td>"
	txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+((mmonth+1).toString() +"/01/"+(ano+1).toString())+"') class='Cabecalho_Calendario' title='Próximo Ano'>>></a></td>"
	txt += "<td width=20% align=right><a href=javascript:force_close('"+div+"') class='Cabecalho_Calendario' title='Fechar Calendário'><b>X</b></a></td></tr></table></td></tr>"
	txt += "<tr><td colspan='3' bgcolor='#F2F5F8' class='mes'><a href=javascript:pop_month('"+obj+"','"+div+"','"+tam+"','" + ano + "') class='mes'>" + umonth[mmonth] + "</a> <div id='popd' style='position:absolute'></div></td>"
	txt += "<td colspan='4' align='right' bgcolor='#F2F5F8' class='mes'><a href=javascript:pop_year('"+obj+"','"+div+"','"+tam+"','" + (mmonth+1) + "') class='mes'>" + ano.toString() + "</a></td></tr>"
	txt += "<tr bgcolor='#999999'><td width='14%' class='dia' align=center><b>Dom</b></td><td width='14%' class='dia' align=center><b>Seg</b></td><td width='14%' class='dia' align=center><b>Ter</b></td><td width='14%' class='dia' align=center><b>Qua</b></td><td width='14%' class='dia' align=center><b>Qui</b></td><td width='14%' class='dia' align=center><b>Sex<b></td><td width='14%' class='dia' align=center><b>Sab</b></td></tr>"
	today1 = new Date((mmonth+1).toString() +"/01/"+ano.toString());
	diainicio = today1.getDay () + 1;
	week = d = 1
	start = false;
	
	for (n=1;n<= 42;n++){
		if (week == 1)  txt += "<tr bgcolor='#efefff' align=center>"
		if (week==diainicio) {start = true}
		if (d > days[mmonth]) {start=false}
		if (start){
			dat = new Date((mmonth+1).toString() + "/" + d + "/" + ano.toString())
			day_dat   = dat.toString().substr(0,10)
			day_today  = date_Form.toString().substr(0,10)
			year_dat  = dat.getFullYear ()
			year_today = date_Form.getFullYear ()
			colorcell = ((day_dat == day_today) && (year_dat == year_today) ? " bgcolor='#FFCC00' " : "" )
			mesFim = (mmonth+1).toString()			
			if(mesFim.length==1)
				mesFim = '0' + mesFim
			
			diaFim = d.toString()
			
			if(diaFim.length==1)
				diaFim = '0' + diaFim
			
			txt += "<td"+colorcell+" align=center><a href=javascript:block('"+ diaFim + "/" + mesFim + "/" + ano.toString() +"','"+ obj +"','" + div +"') class='data'>"+ d.toString() + "</a></td>"
			d ++ 
		}else{ 
			txt += "<td class='data' align=center> </td>"
		}
		week ++
		if (week == 8){ 
			week = 1; txt += "</tr>"
		} 
	}
	txt += "</table>"
	div2 = eval (div)
	div2.innerHTML = txt 
}
  
// função para exibir a janela com os meses
function pop_month(obj, div, tam, ano){
  txt  = "<table bgcolor='#CCCCFF' border='0' width=80>"
  for (n = 0; n < 12; n++) { txt += "<tr><td align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+("01/" + (n+1).toString() + "/" + ano.toString())+"')>" + umonth[n] +"</a></td></tr>" }
  txt += "</table>"
  popd.innerHTML = txt
}

// função para exibir a janela com os anos
function pop_year(obj, div, tam, umonth){
  txt  = "<table bgcolor='#CCCCFF' border='0' width=160>"
  l = 1
  for (n=1991; n<2012; n++){  
		if (l == 1) txt += "<tr>"
     txt += "<td align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+(umonth.toString () +"/01/" + n) +"')>" + n + "</a></td>"
     l++
     if (l == 4) 
        {txt += "</tr>"; l = 1 } 
  }
  txt += "</tr></table>"
  popd.innerHTML = txt 
}

// função para fechar o calendário
function force_close(div){ 
	div2 = eval (div); div2.innerHTML = ''
}
    
// função para fechar o calendário e setar a data no campo de data associado
function block(data, obj, div){ 
    force_close (div)
    obj2 = eval(obj)
    obj2.value = data 
}

function valida_hora(hora, minuto) { 
	if(hora == "" || minuto == "") { 
		alert("Favor digitar a hora no formato HH:MM.")
		return false; 
	} 
	if(isNaN(hora) || isNaN(minuto)) { 
		alert("Favor digitar a hora no formato HH:MM.")
		return false; 
	} 
	if (hora < 0 || hora > 23 || minuto < 0 || minuto > 59) { 
		alert("Favor digitar a hora no formato HH:MM.")
		return false; 
	} 
	return true; 
} 


function validaData(pData){
	if (pData != "") {
		var datePat = /^(\d{2})(\/)(\d{2})\2(\d{4})$/;
		var matchArray = pData.match(datePat); // is the format ok?
		if (matchArray == null) {
			alert("Favor digitar a data no formato dd/mm/aaaa.")
			return false;
		}
		day = matchArray[1]; // parse date into variables
		month = matchArray[3];
		year = matchArray[4];
		if (day < 1 || day > 31) {
			alert("O dia deve estar entre 1 e 31.");
			return false;
		}
		if (month < 1 || month > 12) { // check month range
			alert("O mês deve estar entre 01 e 12.");
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			alert("O mês "+month+" não tem 31 dias!")
			return false
		}
		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap)) {
				alert("Fevereiro " + year + " não tem " + day + " dias!");
				return false;
			}
		}
		if (year < 1900) {
			alert("O ano é inválido.");
			return false;
		}
		return true
	}else{
		return false;
	}
}

function CheckTime(str){
	if (str != '')
		hora=str
		if (hora.length!=5) {
			alert("A datadeve ter o formato HH:MM");
			return false
		}
		a=hora.charAt(0) //<=2
		b=hora.charAt(1) //<4
		c=hora.charAt(2) //:
		d=hora.charAt(3) //<=5
		if ((a==2 && b>3) || (a>2)) {
			alert("A hora deve estar entre 00 e 23");
			return false;
		}
		if (d>5) {
			alert("Os minutos devem estar entre 00 e 59");
			return false
		}
	else{
		return true
	}
}

function cursor(qual){
	qual.style.cursor= 'hand';
}	

function redirect(url){
	document.location = url;
}

function redirect_new(url){
	window.open(url);
}

// validar login
function Login_Validator(theForm){
  if (theForm.login.value == "") {
    alert("Informe seu Login");
    theForm.login.focus();
    return (false);
  }
  if (theForm.senha.value == "") {
    alert("Informe sua Senha");
    theForm.senha.focus();
    return (false);
  }
   return (true);
 }

// todas minusculas
function Lcase(qual){
	qual.value = qual.value.toLowerCase();
}	

// todas maiúsculas
function Ucase(qual){
	qual.value = qual.value.toUpperCase();
}	

// validação de radio buttons

function varreRadio(qual, msn){
	var valid = false;
	for(i=0;i<qual.length;i++){
		if(qual[i].checked){
			modo = qual[i].value;
			valid = true;
		} 
	}
	if (!valid) {				
		alert(msn);
		return false;
	}else 
		return true
}


// ****************************** Funções do Menu dinâmico
function getposOffset(what, offsettype){
			var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
			var parentEl=what.offsetParent;
			while (parentEl!=null){
				totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
				parentEl=parentEl.offsetParent;
			}
			return totaloffset;
		}
		
		
		function showhide(obj, e, visible, hidden, menuwidth){
			if (ie4||ns6)
				dropmenuobj.style.left=dropmenuobj.style.top=-500
			dropmenuobj.widthobj=dropmenuobj.style
			dropmenuobj.widthobj.width=menuwidth
			if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
				obj.visibility=visible
			else if (e.type=="click")
				obj.visibility=hidden
		}
		
		function iecompattest(){
			return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
		}
		
		function clearbrowseredge(obj, whichedge){
			var edgeoffset=0
			if (whichedge=="rightedge"){
				var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
				dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
				if (windowedge-dropmenuobj.x-obj.offsetWidth < dropmenuobj.contentmeasure)
					edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth
				}
				else{
					var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
					var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
					dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
					if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move menu up?
						edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
					if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either? (position at top of viewable window then)
						edgeoffset=dropmenuobj.y
				}
			}
			return edgeoffset
		}
		
		function populatemenu(what){
			if (ie4||ns6)
			dropmenuobj.innerHTML=what.join("")
		}		
		
		function dropdownmenu(obj, e, menucontents, menuwidth){
			if (window.event) event.cancelBubble=true
			else if (e.stopPropagation) e.stopPropagation()
			clearhidemenu()
			dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
			populatemenu(menucontents)
			
			if (ie4||ns6){
				showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
				dropmenuobj.x=getposOffset(obj, "left")
				dropmenuobj.y=getposOffset(obj, "top")
				dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+horizontaloffset+"px"
				dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
			}
			
			return clickreturnvalue()
		}
		
		function clickreturnvalue(){
			if (ie4||ns6) return false
			else return true
		}
		
		function contains_ns6(a, b) {
			while (b.parentNode)
				if ((b = b.parentNode) == a)
					return true;
		return false;
		}
		
		function dynamichide(e){
			if (ie4&&!dropmenuobj.contains(e.toElement))
				delayhidemenu()
			else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
				delayhidemenu()
		}
		
		function hidemenu(e){
			if (typeof dropmenuobj!="undefined"){
			if (ie4||ns6)
				dropmenuobj.style.visibility="hidden"
			}
		}
		
		function delayhidemenu(){
			if (ie4||ns6)
				delayhide=setTimeout("hidemenu()",disappeardelay)
		}
		
		function clearhidemenu(){
			if (typeof delayhide!="undefined")
			clearTimeout(delayhide)
		}

// ******************************

/*    Funções da barra de login   */

function logout(){
	if(confirm('Você realmente deseja encerrar o reservado? ')){
		document.location = "/2006/scripts/logoff.asp"
	}
}

var g_iCount = new Number();
var g_mCount = new Number();
var g_iCount = 1;
var g_mCount = 90;

function startCountdown(){
	if((g_mCount) >= 0){
		if((g_iCount - 1) >= 0){
			g_iCount = g_iCount - 1;
	
			if((g_iCount) >= 10)
				if((g_mCount) >= 10)
	    		numberCountdown.innerText = g_mCount + ':' + g_iCount;
				else
					numberCountdown.innerText = '0' +  g_mCount + ':' + g_iCount;
			else
				if((g_mCount) >= 10)
	    		numberCountdown.innerText = g_mCount + ':0' + g_iCount;
				else
					numberCountdown.innerText = '0' + g_mCount + ':0' + g_iCount;
	
	  	if((g_iCount) == 0){
				g_iCount = 60
				g_mCount = g_mCount - 1
			}
			setTimeout('startCountdown()',1000);
		}
	}else{
		alert('Sessão Expirada!');
		document.location = "/2006/scripts/logoff.asp"
	}
}

// funções para alterar mensagens na barra de status 

function statusON(msg){
	top.window.status = msg; 
	return true;
}

function statusOFF(){
	top.window.status='.:: Tratar Acesso ::.'; 
	return true
}		

// Função para mostrar ou esconder uma div,tr, etc.
function showDiag(obj,mostra){
	mostra = (mostra) ? eval(obj).style.display = 'block' : eval(obj).style.display = 'none';
}
// ******************************

/*******************************/
/*******************************/
//Conjunto de Funções para realizar a comunicação através de AJAX
/*******************************/
/*******************************/

function createXMLHTTP(){
	var ajax;
	try{
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e){
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
			alert(ajax);
		}
		catch(ex){
			try{
				ajax = new XMLHttpRequest();
			}
			catch(exc){
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax = null;
			}
		}
		return ajax;
	}
	var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
	for (var i=0; i < arrSignatures.length; i++){
		try{
			var oRequest = new ActiveXObject(arrSignatures[i]);
			return oRequest;
		} 
		catch (oError){
		}
	}
	throw new Error("MSXML is not installed on your system.");
}

// ******************************

// Funções para retornar valores em InnerHTML para montagem dinâmica de páginas

var http_request = false;
var field;
function makeRequest(url, sField) {
	http_request = false;
	field = sField;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		// See note below about this line
		}
	}else 
		if (window.ActiveXObject) { // IE
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = alertContents;
	http_request.open('GET', url, true);
	http_request.send(null);
}

function alertContents() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			document.getElementById(field).innerHTML = http_request.responseText;
		} else {
			alert('There was a problem with the request.');
		}
	}
}
//************************************************************
 