// JavaScript Document
var browser = navigator.appName;
var dsplTable;
var dsplTr;
var dsplTd;
if(browser == 'Netscape'){
	dsplTable = 'table';
	dsplTr =	'table-row';
	dsplTd =	'table-cell';
}else{
	dsplTable = 'block';
	dsplTr =	'block';
	dsplTd =	'block';
}

//validaData(dt)
function validaData(dt){
	if(dt.length != 0){
		var dia = dt.substr(0, dt.indexOf('/'));
		var mes = dt.substr(dt.indexOf('/')+1, (dt.lastIndexOf('/')-1) - dt.indexOf('/'))
		var ano = dt.substr(dt.lastIndexOf('/')+1);

		if(dia == '' || isNaN(dia) || dia > 31 || dia < 1 || mes == '' || isNaN(mes) || mes < 1 || mes > 12 || ano == '' || isNaN(ano) || ano < 1900){
			return false;
		}
	}

	return true;
}

//function validaFuncionario(frm){
function validaFuncionario(frm){
	var msg = 'Preencha corretamente os campos abaixo:\n';
	var erro = false;

	//usuario
	if(frm.nmFuncionario.value == '' ){
		msg += ' - Nome\n';
		if(!erro){
			erro = true;
			frm.nmFuncionario.focus();
		}
	}

	//email
	if(frm.email.value == '' || !validaEmail(frm.email.value)){
		msg += ' - E-mail\n';
		if(!erro){
			erro = true;
			frm.email.focus();
		}
	}

	//endereço
	if(frm.endereco.value == '' ){
		msg += ' - Endereço\n';
		if(!erro){
			erro = true;
			frm.endereco.focus();
		}
	}

	//cep
	var cep = frm.cep.value.replace('-', '');
	if(cep == '' || isNaN(cep) || cep.length < 8){
		msg += ' - Cep (99999-999)\n';
		if(!erro){
			erro = true;
			frm.cep.select();
		}
	}

	// valida o ddd
	var dddTelefone = frm.dddTelefone.value;
	if(dddTelefone != '' && (isNaN(dddTelefone) || dddTelefone.length < 3)){
		msg += ' - DDD do telefone (999)\n';
		if(!erro){
			erro = true;
			frm.dddTelefone.select();
		}
	}

	// tel
	var telefone = frm.telefone.value;
	if(telefone != '' && (isNaN(telefone) || telefone.length < 8)){
		msg += ' - Telefone (99999999)\n';
		if(!erro){
			erro = true;
			frm.telefone.select();
		}
	}

	if(erro){
		alert(msg);
		return false;
	}else{
		return true;
	}
}

//validaUnidade(frm)
function validaUnidade(frm){

	var msg = 'Preencha corretamente os campos abaixo:\n';
	var erro = false;

	//unidade
	if( frm.nmUnidade.value == ''){
		msg += ' - Unidade\n';
		if(!erro){
			erro = true;
			frm.nmUnidade.focus();
		}
	}

	//endereço
	if(frm.endereco.value == '' ){
		msg += ' - Endereço\n';
		if(!erro){
			erro = true;
			frm.endereco.focus();
		}
	}

	//cep
	var cep = frm.cep.value.replace('-', '');
	if(cep != '' && (isNaN(cep) || cep.length < 8)){
		msg += 'Cep\n';
		if(!erro){
			erro = true;
			frm.cep.focus();
		}
	}

	// DDDtelefone1
	var dddTelefone1 = frm.dddTelefone1.value;
	if(dddTelefone1 != '' && (isNaN(dddTelefone1) || dddTelefone1.length < 3)){
		msg += 'DDD do telefone (3 dígitos numéricos!)\n';
		if(!erro){
			erro = true;
			frm.dddTelefone1.select();
		}
	}

	//Telefone1
	var telefone1 = frm.telefone1.value;
	if(telefone1 != '' && (isNaN(telefone1) || telefone1.length < 8)){
		msg += 'Telefone (3 dígitos numéricos!)\n';
		if(!erro){
			erro = true;
			frm.telefone1.select();
		}
	}

	//DDDtelefone2
	var dddTelefone2 = frm.dddTelefone2.value;
	if(dddTelefone2 != '' && (isNaN(dddTelefone2) || dddTelefone2.length < 3)){
		msg += 'DDD do telefone (3 dígitos numéricos!)\n';
		if(!erro){
			erro = true;
			frm.dddTelefone2.select();
		}
	}

	//Telefone2
	var telefone2 = frm.telefone2.value;
	if(telefone2 != '' && (isNaN(telefone2) || telefone2.length < 8)){
		msg += 'Telefone (3 dígitos numéricos!)\n';
		if(!erro){
			erro = true;
			frm.telefone2.select();
		}
	}

	if(erro){
		alert(msg);
		return false;
	}else{
		return true;
	}
}

//validaCliente
function validaCliente(frm){
	var msg = 'Preencha corretamente os campos abaixo:\n';
	var erro = false;

	//usuario
	if(frm.nmCliente.value == '' ){
		msg += ' - Nome Completo\n';
		if(!erro){
			erro = true;
			frm.nmCliente.focus();
		}
	}

	//email
	if(frm.email.value == '' || !validaEmail(frm.email.value)){
		msg += ' - E-mail\n';
		if(!erro){
			erro = true;
			frm.email.focus();
		}
	}

	//Senha
	var senha = frm.senha.value;
	var cSenha = frm.cSenha.value;

	if(frm.senha.value == '' || (senha != cSenha)){
		msg += ' - Senha\n';
		if(!erro){
			erro = true;
			frm.senha.focus();

		}
	}

	//CPF
	if(frm.cpf.value == '' || !validaCpf(frm.cpf.value)){
			msg += ' - CPF\n';
			if(!erro){
				erro = true;
				frm.cpf.focus();
			}
		}

	//DDD Telefone
	var dddTelefone = frm.dddTelefone.value;
	if(dddTelefone == '' || isNaN(dddTelefone) || dddTelefone.length < 3){
		msg += ' - DDD do telefone (3 dígitos Numéricos)\n';
		if(!erro){
			erro = true;
			frm.dddTelefone.select();
		}
	}

	//Telefone
	var telefone = frm.telefone.value;
	if(telefone == '' || isNaN(telefone) || telefone.length < 8){
		msg += ' - Telefone (8 dígitos Numéricos)\n';
		if(!erro){
			erro = true;
			frm.telefone.select();
		}
	}

	//DDD Celular
	var dddCelular = frm.dddCelular.value;
	if(dddCelular != '' && (isNaN(dddCelular) || dddCelular.length < 3)){
		msg += ' - DDD do telefone (3 dígitos Numéricos)\n';
		if(!erro){
			erro = true;
			frm.dddCelular.select();
		}
	}

	//Celular
	var celular = frm.celular.value;
	if(celular != '' && (isNaN(celular) || celular.length < 8)){
		msg += ' - Telefone (8 dígitos Numéricos)\n';
		if(!erro){
			erro = true;
			frm.celular.select();
		}
	}

	//DDD Comercial
	var dddComercial = frm.dddComercial.value;
	if(dddComercial != '' && (isNaN(dddComercial) || dddComercial.length < 3)){
		msg += ' - DDD do telefone (3 dígitos Numéricos)\n';
		if(!erro){
			erro = true;
			frm.dddComercial.select();
		}
	}

	//Comercial
	var comercial = frm.comercial.value;
	if(comercial != '' && (isNaN(comercial) || comercial.length < 8)){
		msg += ' - Telefone (8 dígitos Numéricos)\n';
		if(!erro){
			erro = true;
			frm.comercial.select();
		}
	}

	//Endereço
	if(frm.endereco.value == '' ){
		msg += ' - Endereço\n';
		if(!erro){
			erro = true;
			frm.endereco.focus();
		}
	}

	if(erro){
		alert(msg);
		return false;
	}else{
		return true;
	}
}

//validaClienteJuridico
function validaClienteJuridico(frm){
	var msg = 'Preencha corretamente os campos abaixo:\n';
	var erro = false;

	//Razao Social
	if(frm.razaoSocial.value == '' ){
		msg += ' - Razão Social\n';
		if(!erro){
			erro = true;
			frm.razaoSocial.focus();
		}
	}

	//CNPJ
	if(frm.cnpj.value == '' || !isCnpj(frm.cnpj.value)){
		msg += ' - CNPJ\n';
		if(!erro){
			erro = true;
			frm.cnpj.focus();
		}
	}

	// valida o ddd
	var dddComercial = frm.dddComercial.value;
	if(dddComercial == '' || isNaN(dddComercial) || dddComercial.length < 3){
		msg += ' - DDD do telefone (3 dígitos Numéricos)\n';
		if(erro){
			erro = true;
			frm.dddComercial.select();
		}
	}
	// tel
	var comercial = frm.comercial.value;
	if(comercial == '' || isNaN(comercial) || comercial.length < 8){
		msg += ' - Telefone (8 dígitos Numéricos)\n';
		if(erro){
			erro = true;
			frm.comercial.select();
		}
	}

	//Nome
	if(frm.nmCliente.value == '' ){
		msg += ' - Nome\n';
		if(!erro){
			erro = true;
			frm.nmCliente.focus();
		}
	}

	//email
	if(frm.email.value == '' || !validaEmail(frm.email.value)){
		msg += ' - E-mail\n';
		if(!erro){
			erro = true;
			frm.email.focus();
		}
	}

	//Senha
	var senha = frm.senha.value;
	var cSenha = frm.cSenha.value;

	if(frm.senha.value == '' || (senha != cSenha)){
		msg += ' - Senha\n';
		if(!erro){
			erro = true;
			frm.senha.focus();

		}
	}

	if(erro){
		alert(msg);
		return false;
	}else{
		return true;
	}
}

//validaQuadras
function validaQuadras(frm){
	var msg = 'Preencha corretamente os campos abaixo:\n';
	var erro = false;

	//Nome Quadra
	if(frm.nmQuadra.value == '' ){
		msg += ' - Nome\n';
		if(!erro){
			erro = true;
			frm.nmQuadra.focus();
		}
	}
	if(erro){
		alert(msg);
		return false;
	}else{

		return true;
	}
}

//validaPreco
function validaPreco(frm){
	var msg = 'Preencha o preço da quadra\n';
	var erro = false;

	//UNIDADE
	var unidades = frm.unidades.value;
	if(unidades == 'NULL' || unidades == 'Selecione' ){
		msg  +=' - Unidade\n';
		if(!erro){
			erro = true;
			frm.unidades.focus();
		}
	}

	//modalidade
	var modalidade = frm.modalidade.value;
	if(modalidade == 'NULL' || modalidade == 'Selecione'){
		msg  +=' - Modalidade\n';
		if(!erro){
			erro = true;
			frm.modalidade.focus();
		}
	}

	//quadra
	var quadra = frm.quadra.value;
	if(quadra == 'NULL' || quadra == 'Selecione'){
		msg  +=' - Quadra\n';
		if(!erro){
			erro = true;
			frm.quadra.focus();
		}
	}

	//quadra
	var diaSemana = frm.diaSemana.value;
	if(diaSemana == 'NULL' || diaSemana == 'Selecione'){
		msg  +=' - Dia da semana\n';
		if(!erro){
			erro = true;
			frm.diaSemana.focus();
		}
	}

	//Preco
	var preco_1h = frm.preco_1h.value.replace(/\./g, '');
	preco_1h = preco_1h.replace(/,/g, '');

	if(preco_1h != '' && isNaN(preco_1h)){
		msg  +=' - Preço (Somente valor monetário ex.: 9.999,99)\n';
		if(!erro){
			erro = true;
			frm.preco_1h.focus();
		}
	}

	var preco_1h30 = frm.preco_1h30.value.replace(/\./g, '');
	preco_1h30 = preco_1h30.replace(/,/g, '');

	if(preco_1h30 != '' && isNaN(preco_1h30)){
		msg  +=' - Preço (Somente valor monetário ex.: 9.999,99)\n';
		if(!erro){
			erro = true;
			frm.preco_1h30.focus();
		}
	}

	var preco_2h = frm.preco_2h.value.replace(/\./g, '');
	preco_2h = preco_2h.replace(/,/g, '');

	if(preco_2h != '' && isNaN(preco_2h)){
		msg  +=' - Preço (Somente valor monetário ex.: 9.999,99)\n';
		if(!erro){
			erro = true;
			frm.preco_2h.focus();
		}
	}

	if(preco_1h == '' && preco_1h30 == '' && preco_2h == ''){
		msg  +=' - É necessario pelo menos um do campo preço estar preenchido\n';
		if(!erro){
			erro = true;
			frm.preco_2h.focus();
		}
	}

	if(erro){
		alert(msg);
		return false;
	}else{
		return true;
	}
}

var msgTb=''; //é necessario uma variavel global para a funcao validateHours

//validaReserva
function validaReserva(frm){
	var msg = 'Preencha corretamente os campos abaixo:\n';
	var erro = false;
	msgTb=''; 

	//UNIDADE
	var unidades = frm.unidades.value;
	if(unidades == 'NULL' || unidades == 'Selecione' ){
		msg  +=' - Unidade\n';
		if(!erro){
			erro = true;
			frm.unidades.focus();
		}
	}

	//clientes
	var clientes = frm.clientes.value;
	if(clientes == 'NULL'){
		msg  +=' - Cliente\n';
		if(!erro){
			erro = true;
			frm.clientes.focus();
		}
	}

	if(document.getElementById('avulso').checked){
		//desconto
		var desconto = frm.desconto.value.replace(/\./g, '');
		desconto = desconto.replace(/,/g, '');
		if(desconto != '' && isNaN(desconto)){
			msg  +=' - Desconto (Somente valor monetário ex.: 9.999,99)\n';
			if(!erro){
				erro = true;
				frm.clientes.focus();
			}
		}
	}else{
		//desconto
		var valorContrato = frm.valorContrato.value.replace(/\./g, '');
		valorContrato = valorContrato.replace(/,/g, '');
		if(valorContrato == '' || isNaN(valorContrato)){
			msg  +=' - Valor do contrato (Somente valor monetário ex.: 9.999,99)\n';
			if(!erro){
				erro = true;
				frm.valorContrato.focus();
			}
		}
	}

	//locacao
	var selecionado = false;
	if(document.getElementById('avulso').checked){
		if(frm.contadorDeRegistro){
			//alert(frm.contadorDeRegistro.value);
			//return false;
			for(var x=1; x <=frm.contadorDeRegistro.value; x++ ){
				if (document.getElementById('agendar'+x).checked){
					selecionado = true;
					break;
				}
			}
		}
		if(!selecionado){
			msg  +=' - Um horário para locação\n';
			if(!erro){
				erro = true;
			}
		}

	}else{
		if(!validateHours()){
			if(!erro){
				erro = true;
			}
		}
	}

	if(erro){
		alert(msg+msgTb);
		return false;
	}else{
		document.getElementById('acao').value = 'makeAllocate';
		document.getElementById('form').action = 'procDados.asp';
		return true;
	}
}

//validalistaAlocacao()
function validalistaAlocacao(){
	var frm = document.getElementById('form');
	var msg = 'Preencha corretamente os campos abaixo:\n';
	var erro = false;

	//UNIDADE
	var unidades = frm.unidades.value;
	if(unidades == 'NULL' || unidades == 'Selecione' ){
		msg  +=' - Unidade\n';
		if(!erro){
			erro = true;
			frm.unidades.focus();
		}
	}

	//calendario
	var calendar = frm.calendar.value;
	if(calendar == ''){
		msg  +=' - Selecione um dia para consulta\n';
		erro = true;
	}

	if(erro){
		alert(msg);

	}else{
		document.getElementById('listaParaReservas').innerHTML ='<table style="float:left; margin-left:250px; *margin-left:125px;">'+
															'	<tr>'+
															'		<td>'+
															'			<img src="../imagens/icones/aguarde1.gif" id="aguardeimg" alt="Aguarde" />'+
															'		</td>'+
															'	</tr>'+
															'</table>';
		listaLocacaoAjax();
	}
}

//resetaConsulta
function resetaConsulta(){
	while(document.getElementById('diaSelecionado')){
		document.getElementById('diaSelecionado').style.background = "#FFF";
		document.getElementById('diaSelecionado').id = '';
	}
	document.getElementById('calendar').value = '';
	document.getElementById('listaParaReservas').innerHTML = '';
}

//updCliente(idCliente)
function updCliente(idCliente, tipo){
	document.getElementById('acao').value = 'alterarCliente';
	document.getElementById('idCliente').value = idCliente;
	document.getElementById('tipo').value = tipo;
	if(tipo == 'juridico'){
		document.getElementById('form').action= 'cadClientesPessoaJuridica.asp';
	}else{
		document.getElementById('form').action= 'cadCliente.asp';
	}
	document.form.submit();
}

//delCliente(idCliente)
function delCliente(idCliente){
	if(confirm('Deseja realmente excluir este cliente?')){
		document.getElementById('acao').value = 'deletarCliente';
		document.getElementById('idCliente').value = idCliente;
		document.form.action = 'procDados.asp';
		document.form.submit();
	}
}

//updFuncionario(idFuncionario)
function updFuncionario(idFuncionario){
	document.getElementById('acao').value = 'alterarFuncionario';
	document.getElementById('idFuncionario').value = idFuncionario;
	document.getElementById('form').action = 'cadFuncionario.asp';
	document.form.submit();
}

//delFuncionario(idFuncionario)
function delFuncionarios(idFuncionario){
	if(confirm('Deseja realmente excluir este cliente?')){
		document.getElementById('acao').value = 'deletarFuncionario';
		document.getElementById('idFuncionario').value = idFuncionario;
		document.form.action = 'procDados.asp';
		document.form.submit();
	}
}

//updUnidade(idUnidade)
function updUnidade(idUnidade){
	document.getElementById('acao').value = 'alterarUnidade';
	document.getElementById('idUnidade').value = idUnidade;
	document.form.action = 'cadUnidade.asp';
	document.form.submit();
}

//delUnidade(idUnidade)
function delUnidade(idUnidade){
	if(confirm('Deseja realmente excluir este cliente?')){
		document.getElementById('acao').value = 'deletarUnidade';
		document.getElementById('idUnidade').value = idUnidade;
		document.form.action = 'procDados.asp';
		document.form.submit();
	}
}

//updQuadra(idUnidade)
function updQuadra(idQuadra, esporte){
	document.getElementById('acao').value = 'alterarQuadras';
	document.getElementById('idQuadra').value = idQuadra;
	//document.form.action = 
	if(esporte == 'tenis' ){
		document.form.action ='cadQuadra.asp'

	} else{
		document.form.action ='cadQuadraFutebol.asp';
	}
	document.form.submit();
}

//updQuadra(updPreco)
function updPreco(idReserva){
	document.getElementById('acao').value = 'alterarPreco';
	document.getElementById('idReserva').value = idReserva;
	document.form.action = 'cadPrecoAvulso.asp'
	document.form.submit();
}

//delQuadra(idUnidade)
function delQuadra(idQuadra){
	if(confirm('Deseja realmente excluir este cliente?')){
		document.getElementById('acao').value = 'deletarQuadra';
		document.getElementById('idQuadra').value = idQuadra;
		document.form.action = 'procDados.asp';
		document.form.submit();
	}	
}

//updReserva(idReserva)
function updReserva(idPedido){
	document.getElementById('acao').value = 'alterar';
	document.getElementById('idPedido').value = idPedido;
	document.form.action = 'envioDados.asp';
	document.form.submit();
}

//delReserva(idPreco)
function delReserva(idReserva, tipo){
	if(confirm('Deseja realmente excluir este registro?')){
		document.getElementById('acao').value = 'deletar';
		document.getElementById('idReserva').value = idReserva;
		document.getElementById('pagina').value = tipo;
		document.form.action = 'procDados.asp';
		document.form.submit();
	}
}

//delListaReserva
function delListaReserva(idPedido){
	if(confirm('Deseja realmente excluir este registro?')){
		document.getElementById('acao').value = 'deletarPedido';
		document.getElementById('idPedido').value = idPedido;
		document.form.action = 'procDados.asp';
		document.form.submit();
	}	
}

//submitPag()
function submitPag(){
	document.getElementById('form').action = '';
	document.getElementById('form').submit();
}

//dsplTbPrecos(opt)
function dsplTbPrecos(opt){
	if(document.getElementById('avulso').checked){

		var tbPrecoMensal = document.getElementById('tbPrecoMensal');
		tbPrecoMensal.style.display = 'none';

		var chks = tbPrecoMensal.getElementsByTagName('input');

		for(var x=0; x<chks.length; x++){
			chks[x].checked = false;
		}

		document.getElementById('tbPrecoAvulso').style.display = dsplTable;

	}else{

		var tbPrecoAvulso = document.getElementById('tbPrecoAvulso');
		tbPrecoAvulso.style.display = 'none';

		var chks = tbPrecoAvulso.getElementsByTagName('input');

		for(var x=0; x<chks.length; x++){
			chks[x].checked = false;
		}
		document.getElementById('tbPrecoMensal').style.display = dsplTable;
	}
}

// valida jogador do ranking

//validaJogador(frm)
function validaJogador(frm){
	var msg = 'Preencha corretamente o(s) campo(s) abaixo:\n';
	var erro = false;

	if(frm.nmJogador.value == ''){
		msg += ' - Nome\n';
		erro = true;
		frm.nmJogador.focus();
	}

	if(frm.jogos.value == '' || frm.jogos.value < 0 || isNaN(frm.jogos.value)){
		msg += ' - Jogos\n';
		if(!erro){
			erro = true;
			frm.jogos.focus();
		}
	}

	if(frm.vitorias.value == '' || frm.vitorias.value < 0 || isNaN(frm.vitorias.value) || ( parseInt(frm.vitorias.value) + parseInt(frm.derrotas.value) != frm.jogos.value)) {
		msg += ' - Vitórias\n';
		if(!erro){
			erro = true;
			frm.derrotas.focus();
		}
	}

	if(frm.derrotas.value == '' || frm.derrotas.value < 0 || isNaN(frm.derrotas.value) || ( parseInt(frm.vitorias.value) + parseInt(frm.derrotas.value) != frm.jogos.value)) {
		msg += ' - Derrotas\n';
		if(!erro){
			erro = true;
			frm.derrotas.focus();
		}
	}

	if(frm.pontos.value == '' || frm.pontos.value < 0 || isNaN(frm.pontos.value)){
		msg += ' - Pontos\n';
		if(!erro){
			erro = true;
			frm.pontos.focus();
		}
	}

	if(frm.acao.value == 'alterar'){
		if (isNaN(frm.dtDesistencia.value)){
			var dia, mes, ano, anoAtual;

			dia = frm.dtDesistencia.value.substring(0, frm.dtDesistencia.value.indexOf('/'));
			mes = frm.dtDesistencia.value.substring(frm.dtDesistencia.value.indexOf('/')+1, frm.dtDesistencia.value.indexOf('/', frm.dtDesistencia.value.indexOf('/')+1));
			ano = frm.dtDesistencia.value.substr(frm.dtDesistencia.value.indexOf('/', frm.dtDesistencia.value.indexOf('/')+1)+1, 4);

			var d = new Date();
			anoAtual = d.getYear()+1900;

			if((dia < 1 || dia > 31) || (mes < 0 || mes > 12 ) || (ano < 1900 || ano > anoAtual)){
				msg += ' - Data de desistência inválida\n';
				if(!erro){
					erro = true;
					frm.dtDesistencia.select();
				}
			}
		}
	}

	if(erro){
		alert(msg);
		return false;
	}else
		if(document.getElementById('acao').value == 'alterar'){
			return true;
		}
		document.getElementById('acao').value = 'gravar';
		return true;
}

//excluirJogador(idJogador)
function excluirJogador(idJogador){
	if(confirm('Deseja realmente excluir este cliente?')){
		document.getElementById('acao').value = 'excluir';
		document.getElementById('idJogador').value = idJogador;
		document.getElementById('form').action = 'procDados.asp';
		document.getElementById('form').submit();
	}
}

//alterarJogador(idJogador)
function alterarJogador(idJogador){
	var id =document.getElementById('idJogador').value;
	if (id != ''){
		document.getElementById('trAlteracao'+id).style.display = 'none';
		document.getElementById('trDados'+id).style.display = dsplTr;
	}
	document.getElementById('trAlteracao'+idJogador).style.display = dsplTr;
	document.getElementById('trDados'+idJogador).style.display = 'none';
	document.getElementById('idJogador').value = idJogador;
}

//novoJogadorRanking()
function novoJogadorRanking(){
	document.getElementById('btNovoJogador').style.display = 'none';
	document.getElementById('quantidadeJogador').style.display = 'block';
}

//quantJogadores(tipo)
function quantJogadores(tipo){
	var quant = document.getElementById('quantJogador').value;

	if(isNaN(quant)){
		alert("Digite somente numero");
		document.getElementById('quantJogador').select();
	}else if(quant.indexOf(".")>0){
		alert("Não utilize ponto '.'");
		document.getElementById('quantJogador').select();
	}else if(quant<=0){
		alert("Insira um favor maior que 0");
		document.getElementById('quantJogador').select();
	}else if (tipo == 'desistencia'){
		document.getElementById('AddJogador').style.display = 'block';
		document.getElementById('quantCampos').value = quant;
		var lst = '<table border="0" class="tdFormulario" align="center" style="float:left; font-size:11px; margin-left:3px; ">';

		for(var i=1; i<=quant; i++){

				lst = lst+	'	<tr>'+
							'		<td style="width:20px;">';
				if (i<10){
							lst = lst+'0'+i;
				}else{
							lst = lst+i;
				}
				lst = lst+	'		<td style="width:215px;">'+
							'			<input maxlength="40" name="cadNome" id="cadNome'+i+'" type="text" class="inputText" style="width:205px;" />'+
							'		</td>'+
							'		<td style="width:90px; *width:85px;">'+
							'			<input maxlength="12" name="cadCategoria" id="cadCategoria'+i+'" type="text" class="inputText" style="width:50px;" />'+
							'		</td>'+
							'		<td style="width:75px; *width:80px;">'+
							'			<input maxlength="5" name="cadPontos" id="cadPontos'+i+'" type="text" class="inputText" style="width:30px;" />'+
							'		</td>'+
							'		<td style="width:80px; *width:70px;">'+
							'			<input name="cadDataDesistencia" id="cadDataDesistencia'+i+'" class="inputText" type="text" style="width: 100px;" onkeypress="javascript:txtBoxFormat(this, \'99/99/9999\', event);" maxlength="10"/>'+
							'		</td>'+
							'	</tr>';
		}
		lst = lst+'</table>';
		document.getElementById('lstCadastro').innerHTML = lst;
	}else{
		document.getElementById('AddJogador').style.display = 'block';
		document.getElementById('quantCampos').value = quant;
		var lst = '<table border="0" class="tdFormulario" align="center" style="float:left; font-size:11px; margin-left:3px; ">';

		for(var i=1; i<=quant; i++){

				lst = lst+	'	<tr>'+
							'		<td style="width:20px;">';
				if (i<10){
							lst = lst+'0'+i;
				}else{
							lst = lst+i;
				}
				lst = lst+	'		</td>'+
							'		<td style="width:210px;">'+
							'			<input maxlength="40" name="cadNome" id="cadNome'+i+'" type="text" class="inputText" style="width:205px;" />'+
							'		</td>'+
							'		<td style="width:70px;">'+
							'			<input maxlength="5" name="cadJogos" id="cadJogos'+i+'" type="text" class="inputText" style="width:30px;" />'+
							'		</td>'+
							'		<td style="width:80px;">'+
							'			<input maxlength="5" name="cadVitorias" id="cadVitorias'+i+'" type="text" class="inputText" style="width:30px;" />'+
							'		</td>'+
							'		<td style="width:80px; *width:70px;">'+
							'			<input maxlength="5" name="cadDerrotas" id="cadDerrotas'+i+'" type="text" class="inputText" style="width:30px;" />'+
							'		</td>'+
							'		<td style="width:70px;">'+
							'			<input maxlength="5" name="cadPontos" id="cadPontos'+i+'" type="text" class="inputText" style="width:30px;" />'+
							'		</td>'+
							'	</tr>';
		}
		lst = lst+'</table>';
		document.getElementById('lstCadastro').innerHTML = lst;
	}
}

//validaJogadorRanking()
function validaJogadorRanking(){
	var quant = document.getElementById('quantJogador').value;
	var msg = "Preencha corretamente o(s) campo(s):\n";
	var mostraAlert = false;
	var nome;
	var jogos;
	var vitorias;
	var derrotas;
	var pontos;
	for(var i=1; i<=quant; i++){
		nome = document.getElementById('cadNome'+i).value;
		jogos = document.getElementById('cadJogos'+i).value;
		vitorias = document.getElementById('cadVitorias'+i).value;
		derrotas = document.getElementById('cadDerrotas'+i).value;
		pontos = document.getElementById('cadPontos'+i).value;

		if ( (nome ==''|| nome.indexOf(",")>0) || (jogos =='' || isNaN(jogos) || jogos.indexOf(".")>0) || (vitorias =='' || isNaN(vitorias) || vitorias.indexOf(".")>0) || (derrotas =='' || isNaN(derrotas) || derrotas.indexOf(".")>0) || (pontos =='' || isNaN(pontos) || pontos.indexOf(".")>0) ){
			msg = msg+'\tLinha '+i+':\n';
			mostraAlert = true;
			if (nome ==''|| nome.indexOf(",")>0){
				msg = msg+'\t\t-Nome\n';
			}
			if (jogos =='' || isNaN(jogos) || jogos.indexOf(".")>0){
				msg = msg+'\t\t-Jogos\n';
			}
			if (vitorias =='' || isNaN(vitorias) || vitorias.indexOf(".")>0){
				msg = msg+'\t\t-Vitorias\n';
			}
			if (derrotas =='' || isNaN(derrotas) || derrotas.indexOf(".")>0){
				msg = msg+'\t\t-Derrotas\n';
			}
			if (pontos =='' || isNaN(pontos) || pontos.indexOf(".")>0){
				msg = msg+'\t\t-Pontos\n';
			}
		}
	}
	if(mostraAlert == true){
		alert(msg);
	}else{
		document.getElementById('acao').value = 'cadastroJogador';
		document.getElementById('form').action = 'procDados.asp';
		document.getElementById('form').submit();
	}
}

//validaJogadorRankingDesistente()
function validaJogadorRankingDesistente(){
	var quant = document.getElementById('quantJogador').value;
	var msg = "Preencha corretamente o(s) campo(s):\n";
	var mostraAlert = false;
	var nome;
	var categoria;
	var data;
	var pontos;
	for(var i=1; i<=quant; i++){
		nome = document.getElementById('cadNome'+i).value;
		categoria = document.getElementById('cadCategoria'+i).value;
		pontos = document.getElementById('cadPontos'+i).value;
		data = document.getElementById('cadDataDesistencia'+i).value;

		if ((nome ==''|| nome.indexOf(",")>0) || (data =='' || !(validaData(data))) || (categoria ==''|| categoria.indexOf(",")>0) || (pontos =='' || isNaN(pontos) || pontos.indexOf(".")>0)){
			msg = msg+'\tLinha '+i+':\n';
			mostraAlert = true;
			if (nome ==''|| nome.indexOf(",")>0){
				msg = msg+'\t\t-Nome\n';
			}
			if (categoria ==''|| categoria.indexOf(",")>0){
				msg = msg+'\t\t-Categoria\n';
			}
			if (pontos =='' || isNaN(pontos) || pontos.indexOf(".")>0){
				msg = msg+'\t\t-Pontos\n';
			}
			if (data =='' ||  !(validaData(data))){
				msg = msg+'\t\t-Data Desistência\n';
			}
		}
	}
	if(mostraAlert == true){
		alert(msg);
	}else{
		document.getElementById('acao').value = 'cadastroJogadorDesistencia';
		document.getElementById('form').action = 'procDados.asp';
		document.getElementById('form').submit();
	}
}

//salvarAlteracaoJogador(idJogador)
function salvarAlteracaoJogador(idJogador){
	var quant = document.getElementById('quantJogador').value;
	var msg = "Preencha corretamente o(s) campo(s):\n";
	var mostraAlert = false;
	var nome;
	var jogos;
	var vitorias;
	var derrotas;
	var pontos;
	nome = document.getElementById('nome'+idJogador).value;
	jogos = document.getElementById('jogo'+idJogador).value;
	vitorias = document.getElementById('vitorias'+idJogador).value;
	derrotas = document.getElementById('derrotas'+idJogador).value;
	pontos = document.getElementById('pontos'+idJogador).value;

	if ( (nome ==''|| nome.indexOf(",")>0) || (jogos =='' || isNaN(jogos) || jogos.indexOf(".")>0) || (vitorias =='' || isNaN(vitorias) || vitorias.indexOf(".")>0) || (derrotas =='' || isNaN(derrotas) || derrotas.indexOf(".")>0) || (pontos =='' || isNaN(pontos) || pontos.indexOf(".")>0) ){
		mostraAlert = true;
		if (nome ==''|| nome.indexOf(",")>0){ 
			msg = msg+'\t\t-Nome\n';
		}
		if (jogos =='' || isNaN(jogos) || jogos.indexOf(".")>0){
			msg = msg+'\t\t-Jogos\n';
		}
		if (vitorias =='' || isNaN(vitorias) || vitorias.indexOf(".")>0){
			msg = msg+'\t\t-Vitorias\n';
		}
		if (derrotas =='' || isNaN(derrotas) || derrotas.indexOf(".")>0){
			msg = msg+'\t\t-Derrotas\n';
		}
		if (pontos =='' || isNaN(pontos) || pontos.indexOf(".")>0){
			msg = msg+'\t\t-Pontos\n';
		}
	}
	if(mostraAlert == true){
		alert(msg);
	}else{
		document.getElementById('alteracaoNome').value = nome;
		document.getElementById('alteracaoJogos').value = jogos;
		document.getElementById('alteracaoVitorias').value = vitorias;
		document.getElementById('alteracaoDerrotas').value = derrotas;
		document.getElementById('alteracaoPontos').value = pontos;
		document.getElementById('idJogador').value = idJogador;
		document.getElementById('acao').value = 'alterarJogador';
		document.getElementById('form').action = 'procDados.asp';
		document.getElementById('form').submit();
	}
}

//alterarJogadorDesistente
function alterarJogadorDesistente(idJogador){
	var msg = "Preencha corretamente o(s) campo(s):\n";
	var mostraAlert = false;
	var nome;
	var categoria;
	var data;
	var pontos;

	nome = document.getElementById('nome'+idJogador).value;
	categoria = document.getElementById('categoria'+idJogador).value;
	pontos = document.getElementById('pontos'+idJogador).value;
	data = document.getElementById('dataDesistencia'+idJogador).value;

	if ((nome ==''|| nome.indexOf(",")>0) || (data =='' || !(validaData(data))) || (categoria ==''|| categoria.indexOf(",")>0) || (pontos =='' || isNaN(pontos) || pontos.indexOf(".")>0)){
		mostraAlert = true;
		if (nome ==''|| nome.indexOf(",")>0){ 
			msg = msg+'\t\t-Nome\n';
		}
		if (categoria ==''|| categoria.indexOf(",")>0){ 
			msg = msg+'\t\t-Categoria\n';
		}
		if (pontos =='' || isNaN(pontos) || pontos.indexOf(".")>0){
			msg = msg+'\t\t-Pontos\n';
		}
		if (data =='' ||  !(validaData(data))){
			msg = msg+'\t\t-Data Desistência\n';
		}

	}

	if(mostraAlert == true){
		alert(msg);
	}else{
		document.getElementById('idJogador').value = idJogador;
		document.getElementById('alteracaoNome').value = nome;
		document.getElementById('alteracaoCategoria').value = categoria;
		document.getElementById('alteracaoPontos').value = pontos;
		document.getElementById('alteracaoDataDesistencia').value = data;
		document.getElementById('acao').value = 'alterarJogadorDesistencia';
		document.getElementById('form').action = 'procDados.asp';
		document.getElementById('form').submit();
	}
}

//valorMonetario(campo, milSep, decSep, e)
function valorMonetario(campo, milSep, decSep, e){
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;

	if (whichCode == 13) return true;

	key = String.fromCharCode(whichCode);// Valor para o código da Chave

	if(key.charCodeAt(0) == 0 || key.charCodeAt(0) == 8){
		campo.value = '';
		return false;
	}

	if (strCheck.indexOf(key) == -1) return false; // Chave inválida

	len = campo.value.length;

	for(i = 0; i < len; i++){
		if ((campo.value.charAt(i) != '0') && (campo.value.charAt(i) != decSep)) break;
	}

	aux = '';

	for(; i < len; i++){
		if (strCheck.indexOf(campo.value.charAt(i))!=-1) aux += campo.value.charAt(i);
	}

	aux += key;

	len = aux.length;

	if (len == 0) campo.value = '';
	if (len == 1) campo.value = '0'+ decSep + '0' + aux;
	if (len == 2) campo.value = '0'+ decSep + aux;
	if (len > 2) {
		aux2 = '';

		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
			}

			aux2 += aux.charAt(i);
			j++;
		}

		campo.value = '';

		len2 = aux2.length;

		for (i = len2 - 1; i >= 0; i--){
			campo.value += aux2.charAt(i);
		}

		campo.value += decSep + aux.substr(len - 2, len);
	}

	return false;
}

//________________________________________________________________________________________________________________________
//insertImgSubparagraph(idSubparagraph)
function insertImgSubparagraph(idSubparagraph){
	var frm = document.form;
	var idImg = 'imagem'+idSubparagraph;
	var nameAlinhamento = 'alinhamento'+idSubparagraph;
	var nameTipoImg = 'tipoImg'+idSubparagraph;
	var imagem = document.getElementById(idImg).value;

	if(imagem.length == 0){
		alert('Escolha uma imagem com extensão .png ou .jpg!');
	}else{

		imagem.name = 'imagem';

		document.getElementById(idImg).name = 'imagem';

		var inputAlign = document.getElementById('divInsertImg'+idSubparagraph).getElementsByTagName('input');
		for(var x=0; x<inputAlign.length; x++){
			if(inputAlign[x].name == nameAlinhamento){
				inputAlign[x].name = 'alinhamento';
			}else if(inputAlign[x].name == nameTipoImg){
				inputAlign[x].name = 'tipoImg';
			}
		}

		var tipo = 'imgParagrafo'+document.getElementById('tipo').value;

		document.form.action = 'upload.asp';
		document.form.enctype = 'multipart/form-data';
		document.getElementById('tipo').value = tipo;
		//checked="checked"
		if(document.getElementById('direita'+idSubparagraph).checked){
			document.getElementById('tipoPosicaoImg').value = 'direita';
		}else{
			document.getElementById('tipoPosicaoImg').value = 'esquerda';
		}
		document.getElementById('esquerda'+idSubparagraph).name = 'posicaoImg';
		document.getElementById('direita'+idSubparagraph).name = 'posicaoImg';
		document.getElementById('cadastro').style.display = 'none';
		document.getElementById('aguarde').style.display = 'block';
		document.getElementById('acao').value = 'alterar';
		document.getElementById('idParagrafo').value = idSubparagraph;
		document.getElementById('tbCadastro').style.display = 'none';
		//document.getElementById('divFormParagrafo').style.display = 'none';
		//document.getElementById('divParagrafos').style.display = 'none';
		//document.getElementById('divAguarde').style.display = 'block';
		document.form.submit();
	}
}

//fAltImgSubparagraph()
function fAltAlignImgSubparagraph(){
	try{
		if(xmlhttp.readyState == 4){
			clearInterval(intervalo);
			intervalo = null;

			var valorRetorno = xmlhttp.responseText;
			if(valorRetorno != 'ok'){
				//alert('Erro - ' + valorRetorno);
				document.getElementById("erroAjax").innerHTML = valorRetorno;
				var idImgSubparagraph = 'imgSubparagraph'+tmpIdSubparagraph;
				var valueClassName = document.getElementById(idImgSubparagraph).className;
				document.getElementById(idImgSubparagraph).className = (valueClassName = 'imgSubparagraphRight') ? 'imgSubparagraphLeft' : 'imgSubparagraphRight';
			}
		}
	}catch(e){
		alert('Erro - ' + e);
		clearInterval(intervalo);
		intervalo = null;
	}
}

//fDelImgSubparagraph()
function fDelImgSubparagraph(){
	//try{
		if(xmlhttp.readyState == 4){
			clearInterval(intervalo);
			intervalo = null;

			var valorRetorno = xmlhttp.responseText;

			if(valorRetorno != 'ok'){
				document.getElementById("erroAjax").innerHTML = valorRetorno;
				alert('Erro - ' + tmpIdSubparagraph);
				document.getElementById(idImgSubparagraph).innerHTML = 	valorRetorno;
				var idImgSubparagraph = 'imgSubparagraph'+tmpIdSubparagraph;
				document.getElementById(idImgSubparagraph).style.display = 'block';

				//Tool Bar
				document.getElementById('imgEditTxt'+tmpIdSubparagraph).style.display = 'none';
				document.getElementById('divTabEditTxt'+tmpIdSubparagraph).style.display = 'none';
				document.getElementById('imgAlignRight'+tmpIdSubparagraph).style.display = 'block';
				document.getElementById('divTabAlignRight'+tmpIdSubparagraph).style.display = 'block';
				document.getElementById('imgAlignLeft'+tmpIdSubparagraph).style.display = 'block';
				document.getElementById('divTabAlignLeft'+tmpIdSubparagraph).style.display = 'block';
				document.getElementById('imgDelete'+tmpIdSubparagraph).style.display = 'block';
				document.getElementById('divTabDelete'+tmpIdSubparagraph).style.display = 'block';
				document.getElementById('imgShow'+tmpIdSubparagraph).style.display = 'block';

				document.getElementById('divTabShow'+tmpIdSubparagraph).style.display = 'block';
				document.getElementById('imgInsert'+tmpIdSubparagraph).style.display = 'none';
				document.getElementById('divTabInsert'+tmpIdSubparagraph).style.display = 'none';
			}
		}
	/*}catch(e){
		alert('Erro - ' + e.message);
		clearInterval(intervalo);
		intervalo = null;
	}*/
}

//alteraConteudoNoticia(txtArea, divCont)
function alteraConteudoNoticia(txtArea, divCont, e){
	/*
	var tecla;
	if (document.all){ // Internet Explorer
		tecla = event.keyCode;
	}else{ // Nestcape
		tecla = e.which;
	}

	alert(tecla);
	if(tecla == 13) {
		document.getElementById(divCont).innerHTML += '<br />';
	}
	*/
	document.getElementById(divCont).innerHTML = txtArea.value.replace(/\n/g, '<br />');
}

//altTxtSubparagraph(idSubparagraph, toolImg)
function altTxtSubparagraph(idSubparagraph, toolImg){
	if(intervalo == null){
		tmpIdSubparagraph = 'divConteudo'+idSubparagraph;

		if(toolImg.src.indexOf('changeTxt.gif') > 0){
			toolImg.src = '/ras/imagens/noticia/save.gif';
			document.getElementById(tmpIdSubparagraph).style.display = 'block';
		}else if(toolImg.src.indexOf('save.gif') > 0){
			toolImg.src = '/ras/imagens/noticia/changeTxt.gif';
			document.getElementById(tmpIdSubparagraph).style.display = 'none';

			var idConteudo = 'conteudo'+idSubparagraph;
			var conteudo = document.getElementById(idConteudo).value.replace(/\n/g, '<br />');
			/*conteudo = conteudo.replace(/'/g, 'apos;');
			conteudo = conteudo.replace(/"/g, 'quot;');
			conteudo = conteudo.replace(/&/g, 'amp;');*/
			conteudo= trataDadosAjax(conteudo);

			xmlhttp.open("GET", 'procDadosAjax.asp?acao=alterarConteudo&idParagrafo='+idSubparagraph+'&conteudo='+conteudo, true);
			xmlhttp.setRequestHeader("encoding", "utf-8");
			xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=iso-8859-1');
			xmlhttp.send(null);

			intervalo = window.setInterval(fAltTxtSubparagraph, 300);
		}
	}
}

//fAltTxtSubparagraph()
function fAltTxtSubparagraph(){
	try{
		if(xmlhttp.readyState == 4){
			clearInterval(intervalo);
			intervalo = null;

			var valorRetorno = xmlhttp.responseText;
			if(valorRetorno != 'ok') alert('Erro - ' + valorRetorno);
		}
	}catch(e){
		alert('Erro - ' + e);
		clearInterval(intervalo);
		intervalo = null;
	}
}

//altAlignImgSubparagraph(idSubparagraph, valueClassName)
function altAlignImgSubparagraph(idSubparagraph, valueClassName){
	//alert(document.defaultView.getComputedStyle(document.getElementById(img), null).getPropertyValue("float"));
	//document.defaultView.getComputedStyle(document.getElementById(img), null).getPropertyValue("float");
	//alert(valueClassName);
	if(intervalo == null){
		var idImgSubparagraph = 'imgSubparagraph'+idSubparagraph;
		document.getElementById(idImgSubparagraph).className = valueClassName;

		valueClassName = (valueClassName == 'imgSubparagraphRight') ? 'direita' : 'esquerda';
		tmpIdSubparagraph = idSubparagraph;

		xmlhttp.open("GET", 'procDadosAjax.asp?acao=alterar&tipo=changeOptionSubparagraph&idParagrafo='+idSubparagraph+'&alinhamento='+valueClassName, true);
		xmlhttp.setRequestHeader("encoding", "ISO-8859-1");
		xmlhttp.send(null);

		intervalo = window.setInterval(fAltAlignImgSubparagraph, 300);
	}
}

//delImgSubparagraph(idSubparagraph, imgSubparagraph)
function delImgSubparagraph(idSubparagraph, imgSubparagraph){
	if(intervalo == null){
		if(confirm('Deseja realmente excluir a imagem deste parágrafo?')){
			var idImgSubparagraph = 'imgSubparagraph'+idSubparagraph;
			tmpIdSubparagraph = idSubparagraph;

			document.getElementById(idImgSubparagraph).style.display = 'none';

			//Tool Bar
			document.getElementById('imgEditTxt'+idSubparagraph).style.display = 'block';
			document.getElementById('divTabEditTxt'+idSubparagraph).style.display = 'block';
			document.getElementById('imgAlignRight'+idSubparagraph).style.display = 'none';
			document.getElementById('divTabAlignRight'+idSubparagraph).style.display = 'none';
			document.getElementById('imgAlignLeft'+idSubparagraph).style.display = 'none';
			document.getElementById('divTabAlignLeft'+idSubparagraph).style.display = 'none';
			document.getElementById('imgDelete'+idSubparagraph).style.display = 'none';
			document.getElementById('divTabDelete'+idSubparagraph).style.display = 'none';
			document.getElementById('imgShow'+idSubparagraph).style.display = 'none';
			document.getElementById('divTabShow'+idSubparagraph).style.display = 'none';
			document.getElementById('imgInsert'+idSubparagraph).style.display = 'block';
			document.getElementById('divTabInsert'+idSubparagraph).style.display = 'block';

			xmlhttp.open("GET", 'procDadosAjax.asp?acao=excluir&tipo=imgLinha&idParagrafo='+idSubparagraph+'&imagem='+imgSubparagraph, true);
			xmlhttp.setRequestHeader("encoding", "ISO-8859-1");
			xmlhttp.send(null);

			intervalo = window.setInterval(fDelImgSubparagraph, 300);
		}
	}
}

//dsplImgParagrafo(imgSubparagraph)
function dsplImgSubparagraph(eyeToolBar, imgSubparagraph){
	eyeToolBar.src = (eyeToolBar.src.indexOf('/visible.gif') > 0) ? '/ras/imagens/noticia/invisible.gif' : '/ras/imagens/noticia/visible.gif';
	imgSubparagraph = document.getElementById(imgSubparagraph);
	imgSubparagraph.style.display = (imgSubparagraph.style.display == 'block') ? 'none' : 'block';
}

//delSubparagraph(idSubparagraph)
function delSubparagraph(idSubparagraph){
	if(intervalo == null){
		if(confirm('Deseja realmente excluir este parágrafo?')){
			tmpIdSubparagraph = 'divBoxSubparagraph'+idSubparagraph;
			document.getElementById(tmpIdSubparagraph).style.display = 'none';

			xmlhttp.open("GET", 'procDadosAjax.asp?acao=excluir&tipo=removeParagraph&idParagrafo='+idSubparagraph, true);
			xmlhttp.setRequestHeader("encoding", "ISO-8859-1");
			xmlhttp.send(null);

			intervalo = window.setInterval(fDelSubparagraph, 300);
		}
	}
}

//fDelSubparagraph()
function fDelSubparagraph(){
	try{
		if(xmlhttp.readyState == 4){
			clearInterval(intervalo);
			intervalo = null;

			var valorRetorno = xmlhttp.responseText;
			if(valorRetorno != 'ok'){
				document.getElementById("erroAjax").innerHTML = valorRetorno;
				//alert('Erro - ' + valorRetorno);
				document.getElementById(tmpIdSubparagraph).style.display = 'block';
			}
		}
	}catch(e){
		alert('Erro - ' + e);
		clearInterval(intervalo);
		intervalo = null;
	}
}

//validaNoticia
function validaNoticia(form){
	var msg = "Preencha o(s) campo(s) corretamente:\n";
	var mostraMsg = false;
	if(form.titulo.value == ''){
		msg += '- Titulo\n';
		mostraMsg = true;
	}
	if(form.dtPublicacao.value == '' || (!validaData(form.dtPublicacao.value )) ){
		msg += '- Data de Puplicação\n';
		mostraMsg = true;
	}
	if(form.imgTitulo){
		if(form.imgTitulo.value == ''){
			msg += '- Imagem\n';
			mostraMsg = true;
		}
	}

	if(mostraMsg){
		alert(msg);
		return false;
	}else{
		document.getElementById('form').action = 'upload.asp';
		if(document.getElementById('acao').value == '') {
			document.getElementById('acao').value = 'cadNoticia';
		}
		document.getElementById('cadastro').style.display = 'none';
		document.getElementById('aguarde').style.display = 'block';
		return true;
	}
}

//addParagrafo
function addParagrafo(){
	var msg = "";
	var mostraMsg = false;
	if(document.getElementById('conteudo').value == ''){
		msg += "O conteúdo é de preenchimento obrigatório\n"
		document.getElementById('conteudo').focus();
		mostraMsg = true;
	}
	if(mostraMsg){
		alert(msg);
		return false;
	}else{
		document.getElementById('form').action = 'upload.asp';
		document.getElementById('acao').value = 'addParagrafo';
		document.getElementById('cadastro').style.display = 'none';
		document.getElementById('aguarde').style.display = 'block';
		document.getElementById('form').submit();
		return true;
	}
}

//deletarImgTitulo(idSubparagraph, imgSubparagraph)
function deletarImgTitulo(idTitle, imgTitle){
	/*alert(idSubparagraph);
	alert(imgSubparagraph);*/
	if(confirm('Deseja realmente excluir a imagem?')){
		document.getElementById('campoImagemTitulo').innerHTML = '<input type="file" id="imgTitulo" name="imgTitulo" class="inputFile" />';

		xmlhttp.open("GET", 'procDadosAjax.asp?acao=excluir&tipo=imgTitulo&idNoticia='+idTitle+'&imagem='+imgTitle, false);
		xmlhttp.setRequestHeader("encoding", "ISO-8859-1");
		xmlhttp.send(null);
	}
}

//trataDadosAjax(conteudo)
function trataDadosAjax(conteudo){
	var vetor =['|quot;','|amp;','|Aacute;','|aacute;','|acute;','|Agrave;','|agrave;','|Atilde;','|atilde;','|Ccedil;','|ccedil;','|Eacute;','|eacute;','|Ecirc;','|ecirc;','|Iacute;','|iacute;','|Ntilde;','|ntilde;','|Oacute;','|oacute;','|Ocirc;','|ocirc;','|Otilde;','|otilde;','|Uacute;','|uacute;','|Uuml;','|uuml;',];
	var caracter = ['"','&','Á','á','´','À','à','Ã','ã','Ç','ç','É','é','Ê','ê','Í','í','Ñ','ñ','Ó','ó','Ô','ô','Õ','õ','Ú','ú','Ü','ü'];
	for(var i=1; i<vetor.length; i++ ){
		do{
			conteudo = conteudo.replace(caracter[i],vetor[i]);
		}while(conteudo.indexOf(caracter[i]) >= 0 );
	}
	return conteudo;
}

//________________________________________________________________________________________________________________________

//SITE

//________________________________________________________________________________________________________________________

//validaReservaSite
function validaReservaSite(quantRegistro){
	var idReserva;
	var check = false; // Verifica se tem pelo menos um selecionado
	for (var x=1; x<=quantRegistro; x++ ){
		idReserva = 'agendar'+x;
		if(document.getElementById(idReserva).checked){
			 check = true;
			break;
		}
	}
	if(!check){
		alert('Selecione um horário para agendar');
	}else if (check){//confirm(msgHorario)
		document.getElementById('acao').value = 'makeAllocate';
		document.getElementById('form').action = '/procDados.asp';
		document.getElementById('form').submit();
	}
}

var DateManager =
{
	initDate: null,
	endDate: null,
	check: function()
	{
		var unidade		= document.getElementById('unidades');
		var modalidade	= document.getElementById('modalidade');
		var quadra		= document.getElementById('quadra');

		try
		{
			if(unidade.value == 'NULL' || unidade.value == '')
				throw {'source': unidade, 'message': "Por favor, selecione a unidade."};

			if(modalidade.value == 'NULL' || modalidade.value == '')
				throw {'source': modalidade, 'message': "Por favor, selecione a modalidade."};

			if(quadra.value == 'NULL' || quadra.value == '')
				throw {'source': quadra, 'message': "Por favor, selecione a quadra."};

			return {unidade: unidade.value, modalidade: modalidade.value, quadra: quadra.value};

		}
		catch(e)
		{
			window.alert(e.message);
			if(e.source != null)e.source.focus();
			return false;
		}

	},
	getWeek: function(mode)
	{
		switch(mode)
		{
			case 'next':
				DateManager.initDate.setDate(DateManager.initDate.getDate() + 7);
				DateManager.endDate.setDate(DateManager.endDate.getDate() + 7);
			break;
			case 'previous':
				DateManager.initDate.setDate(DateManager.initDate.getDate() - 7);
				DateManager.endDate.setDate(DateManager.endDate.getDate() - 7);
			break;
			default:
			break;
		}

		var x;

		return {
			'start':
				((x = DateManager.initDate.getDate()) < 10 ? '0' + x : x) +  '/' +
				((x = DateManager.initDate.getMonth() + 1) < 10 ? '0' + x : x) + '/' +
				DateManager.initDate.getFullYear(),
			'end':
				((x = DateManager.endDate.getDate()) < 10 ? '0' + x : x) +  '/' +
				((x = DateManager.endDate.getMonth() + 1) < 10 ? '0' + x : x) + '/' +
				DateManager.endDate.getFullYear()
		};
	},
	getPrevious: function()
	{
		var data	= DateManager.check();
		if(data == false)return;

		var result	= DateManager.getWeek('previous');
		var request	= new getRequestObject(DateManager.parse);
		request.startRequest('POST','relatorioAjax.asp',new Array(
														new RequestParam('inicio',result.start),
														new RequestParam('termino',result.end),
														new RequestParam('unidade', data.unidade),
														new RequestParam('modalidade', data.modalidade),
														new RequestParam('quadra', data.quadra)));
	},
	getNext: function()
	{
		var data	= DateManager.check();
		if(data == false)return;

		var result = DateManager.getWeek('next');
		var request= new getRequestObject(DateManager.parse);
		request.startRequest('POST','relatorioAjax.asp',new Array(
														new RequestParam('inicio',result.start),
														new RequestParam('termino',result.end),
														new RequestParam('unidade', data.unidade),
														new RequestParam('modalidade', data.modalidade),
														new RequestParam('quadra', data.quadra)));
	},
	getCurrent: function()
	{
		var data	= DateManager.check();
		if(data == false)return false;

		var result = DateManager.getWeek();
		var request= new getRequestObject(DateManager.parse);
		request.startRequest('POST','relatorioAjax.asp',new Array(
														new RequestParam('inicio',result.start),
														new RequestParam('termino',result.end),
														new RequestParam('unidade', data.unidade),
														new RequestParam('modalidade', data.modalidade),
														new RequestParam('quadra', data.quadra)));
		return false;
	},
	parse: function(source, response)
	{
		var target		= document.getElementById('table-holder');
		target.innerHTML= response;
	}
};

//desabilita(strDsbl,input,idReserva)
function desabilita(strDsbl,input,idReserva){//quant, input, periodo
	var totalInput = document.getElementById('contadorDeRegistro').value;
	var aux = '';
	
	if(document.getElementById('agendar'+input).checked){
		for (var x=1; x<=totalInput; x++){
			aux = document.getElementById('inicioHorario'+x).value;
			if (strDsbl.indexOf(aux)>-1 && document.getElementById('idReserva'+x).value == idReserva){
				document.getElementById('agendar'+x).checked = false;
				document.getElementById('agendar'+x).disabled= true;
			}
			
	
		}
	}else{
		for (var x=1; x<=totalInput; x++){
			aux = document.getElementById('inicioHorario'+x).value;
			if (strDsbl.indexOf(aux)>-1 && document.getElementById('idReserva'+x).value == idReserva){
				document.getElementById('agendar'+x).checked = false;
				document.getElementById('agendar'+x).disabled= false;
			}
		}
	}
}

//desabilita(strDsbl,input,idReserva)
function desabilitaSite(strDsbl,input,idReserva){//quant, input, periodo
	var totalInput = document.getElementById('contadorDeRegistro').value;
	var aux = '';
	var valorTotal= 0;
	var valorQuadra;

	if(document.getElementById('agendar'+input).checked){
		for (var x=1; x<=totalInput; x++){
			aux = document.getElementById('inicioHorario'+x).value;
			if (strDsbl.indexOf(aux)>-1 && document.getElementById('idReserva'+x).value == idReserva){
				document.getElementById('agendar'+x).checked = false;
				document.getElementById('agendar'+x).disabled= true;
			}
		}
			if (document.getElementById('agendar'+x).checked){
				valorQuadra = document.getElementById('valor'+x).value;
				valorQuadra = valorQuadra.replace(',','.');
				valorQuadra = parseFloat(valorQuadra);
				valorTotal += valorQuadra;
			}

	}else{
		for (var x=1; x<=totalInput; x++){
			aux = document.getElementById('inicioHorario'+x).value;
			if (strDsbl.indexOf(aux)>-1 && document.getElementById('idReserva'+x).value == idReserva){
				document.getElementById('agendar'+x).checked = false;
				document.getElementById('agendar'+x).disabled= false;
			}
		}
			if (document.getElementById('agendar'+x).checked){
				valorQuadra = document.getElementById('valor'+x).value;
				valorQuadra = valorQuadra.replace(',','.');
				valorQuadra = parseFloat(valorQuadra);
				valorTotal += valorQuadra;
			}
	}
	valorTotal = formatanumero(valorTotal,2);

	var quantTb = document.getElementById('contadorDeTabela').value;

	quantTb = parseFloat(quantTb);
	for (var x=0; x<=quantTb; x++){
		if (document.getElementById('valorTotalTb'+x)){
			document.getElementById('valorTotalTb'+x).innerHTML = valorTotal;
		}
	}
}

//formatar nº com casas decimais
function formatanumero(numero,decimais)
{
  if (isNaN(numero)) { return 0};
  if (numero=='') { return 0};
 
  var IsNegative=(parseInt(numero)<0);
  if(IsNegative)numero=-numero;

  var snum = new String(numero);
  var sec = snum.split('.');
  var whole = parseInt(sec[0]);
  var result = '';
  if(sec.length > 1){
    var dec = new String(sec[1]);
    dec = parseInt(dec)/Math.pow(10,parseInt(dec.length-decimais-1));
Math.round(dec);
dec = parseInt(dec)/10;

if(IsNegative)
{
  var x = 0-dec;
      x = Math.round(x);
  dec = - x;
}
else
{
      dec = Math.round(dec);
}

/*
  * If the number was rounded up from 9 to 10, and it was for 1 'decimal'
  * then we need to add 1 to the 'whole' and set the dec to 0.
  */
if(decimais==1 && dec==10)
{
  whole+=1;
  dec="0";
}

    dec = String(whole) + "." + String(dec);
    var dot = dec.indexOf('.');
    if(dot == -1){
      dec += '.';
      dot = dec.indexOf('.');
    }
var l=parseInt(dot)+parseInt(decimais);
    while(dec.length <= l) { dec += '0'; }
    result = dec;
  } else{
    var dot;
    var dec = new String(whole);
    dec += '.';
    dot = dec.indexOf('.');
var l=parseInt(dot)+parseInt(decimais);
    while(dec.length <= l) { dec += '0'; }
    result = dec;
  }
  if(IsNegative)result="-"+result;
  
  result= result.replace('.', ',');
  
  return result;
}

//desabilita(strDsbl,input,idReserva)
function desabilitaMensal(strDsbl,input,idReserva, data){//quant, input, periodo
	var totalInput = document.getElementById('contadorDeRegistro').value;
	var aux = '';

	//alert(data);
	if(document.getElementById('agendar'+input).checked){
		for (var x=1; x<=totalInput; x++){
			aux = document.getElementById('inicioHorario'+x).value;
			if ((strDsbl.indexOf(aux)>-1 && document.getElementById('idReserva'+x).value == idReserva) &&document.getElementById('diaReserva'+x).value == data){
				document.getElementById('agendar'+x).checked = false;
				document.getElementById('agendar'+x).disabled=true;
			}

		}
	}else{
		for (var x=1; x<=totalInput; x++){
			aux = document.getElementById('inicioHorario'+x).value;
			if ((strDsbl.indexOf(aux)>-1 && document.getElementById('idReserva'+x).value == idReserva) &&document.getElementById('diaReserva'+x).value == data){
				document.getElementById('agendar'+x).checked = false;
				document.getElementById('agendar'+x).disabled=false;
			}
		}
	}
}

//validateHours
function validateHours(){
	var divListaParaReservas = document.getElementById('listaParaReservas');
	var tbs = divListaParaReservas.getElementsByTagName('table');
	var chks;
	var tbsOk = false;
	var tbSemCheck = false;
	var msg = 'Escolha pelo menos um horário das datas abaixo:\n';

	var tr;

	if(tbs.length == 0 ){
		msgTb= 'É necessario esolher ter uma data e que tenha horarios disponíveis para locar uma quadra';

		return false;
	}else if(tbs.length > 1){
		for(var x=0; x<tbs.length; x++){
			tbsOk = false;
			chks = tbs[x].getElementsByTagName('input');

			if(chks.length > 1){
				for(var y=0; y<chks.length; y++){
					if(chks[y].type == 'checkbox'){
						if(chks[y].checked){
							tbsOk = true;
							break;
						}
					}
				}
			}else{
				if(chks.type == 'checkbox'){
					if(chks.checked){
						tbsOk = true;
					}
				}
			}

			if(!tbsOk){
				msg += '- '+tbs[x].id+'\n';
				tbSemCheck = true;
			}
		}
	}else if(tbs.length > 0){
		//alert(tbs[1]);
		//return false;
		chks = tbs[0].getElementsByTagName('input');
		if(chks.length > 1){
			for(var y=0; y<chks.length; y++){
				if(chks[y].type == 'checkbox'){
					if(chks[y].checked){
						tbsOk = true;
						break;
					}
				}
			}
		}else{
			if(chks.type == 'checkbox'){
				if(chks.checked){
					tbsOk = true;
				}
			}
		}
		if(!tbsOk){
			msg += '- '+tbs[0].id+'\n';
			tbSemCheck = true;
		}
	}

	if(tbSemCheck){
		msgTb =msg;
		return false;
	}else{
		msgTb= '';
		return true;
	}
}

//resetaConsultaTipo
function resetaConsultaTipo(){
	while(document.getElementById('diaSelecionado')){
		document.getElementById('diaSelecionado').style.background = "#FFF";
		document.getElementById('diaSelecionado').id = '';
	}

	if(document.getElementById('avulso').checked){
		//Oculta os dados da reserva mensal
		document.getElementById('trDtInicioContrato').style.display = 'none';
		document.getElementById('trDtFimContrato').style.display = 'none';
		document.getElementById('trDiaSemana').style.display = 'none';
		document.getElementById('trValorContrato').style.display = 'none';
		document.getElementById('tbTipoReserva').style.display = 'none';
		//Mostra os dadosda reserva avulsa
		document.getElementById('trDesconto').style.display = dsplTr;

	}else{
		//Mostra os dados da reserva mensal
		document.getElementById('trDtInicioContrato').style.display = dsplTr;
		document.getElementById('trDtFimContrato').style.display = dsplTr;
		document.getElementById('trDiaSemana').style.display = dsplTr;
		document.getElementById('trValorContrato').style.display = dsplTr;
		document.getElementById('tbTipoReserva').style.display = dsplTb;
		//Oculta os dadosda reserva avulsa
		document.getElementById('trDesconto').style.display = 'none';
	}
	document.getElementById('calendar').value = '';
	document.getElementById('listaParaReservas').innerHTML = '';
}

//selecionaCadReserva(unidadeRel,modalidadeRel,quadraRel,tipoRel,horarioRel,dataRel)
function selecionaCadReserva(unidadeRel,modalidadeRel,quadraRel,tipoRel,horarioRel,dataRel){
	//alert(unidadeRel+'\n'+modalidadeRel+'\n'+quadraRel+'\n'+tipoRel+'\n'+horarioRel+'\n'+dataRel);
	document.getElementById('unidadeRel').value = unidadeRel;
	document.getElementById('modalidadeRel').value = modalidadeRel;
	document.getElementById('quadraRel').value = quadraRel;
	document.getElementById('tipoRel').value = tipoRel;
	document.getElementById('horarioRel').value = horarioRel;
	document.getElementById('dataRel').value = dataRel;
	document.getElementById('acao').value = 'cadRelatorio';
	document.getElementById('form').action = 'cadReserva.asp';
	document.getElementById('form').submit();
}
//SITE
//________________________________________________________________________________________________________________________

//retirarPedidoLocacao
function retirarPedidoLocacao(idAgenda){
	document.getElementById('idAgenda').value = idAgenda;
	document.getElementById('acao').value = 'deletarAgendaLocacao';
	document.getElementById('form').action = 'procDados.asp';
	document.getElementById('form').submit();
}

//verReservaAnterior
function verReservaAnterior(idReserva){
	document.getElementById('idReservaAnterior').value = idReserva;
	document.getElementById('form').action = '/locacao/reserva.asp';
	document.getElementById('form').submit();
}

//verPropostaMensalAnterior
function verPropostaMensalAnterior(idReservaMensal){
	document.getElementById('idReservaMensal').value = idReservaMensal;
	document.getElementById('form').action = '/locacao/reserva_mensal.asp';
	document.getElementById('form').submit();
}

//validaBuscaSite
function validaBuscaSite(frm){
	var msg = 'É necessario escolher:\n';
	var erro = false;

	//Unidade
	if(frm.unidade.value == 'NULL' ){
		msg += ' - Unidade\n';
		if(!erro){
			erro = true;
			frm.unidade.focus();
		}
	}

	//Unidade
	if(frm.modalidade.value == 'NULL' ){
		msg += ' - Modalidade\n';
		if(!erro){
			erro = true;
			frm.modalidade.focus();
		}
	}

	//verifica se é mensal
	if(frm.Mensal.checked){
		if(frm.diaSemana.value == '0' ){
			msg += ' - Dia semana\n';
			if(!erro){
				erro = true;
				frm.modalidade.focus();
			}
		}

		if(frm.periodo.value == '0' ){
			msg += ' - Período\n';
			if(!erro){
				erro = true;
				frm.periodo.focus();
			}
		}

		frm.acao.value = 'propostaMensal';
		frm.action = '/locacao/procDados.asp';
	}

	if(erro){
		alert(msg);
		return false;
	}else{

		return true;
	}
}

//confirmaReservaSite(frm)
function confirmaReservaSite(frm){
	/*
	frm.acao.value = 'confirmaReserva';
	frm.action = 'procDados.asp';
	return true;
	*/
	
	try{
		//sendXmlHttpRequest('procDadosAjax.asp?acao=confirmarPedido&idPedido='+idPedido, true, false);

		if(1 == 1){
			//document.getElementById('btnCancelar').innerHTML = '';

			if(document.getElementById('itauShopline').checked){
				document.form.action = 'pagamento/itauShopline.asp';
				document.form.target = 'mpg_popup';
				carregabrw();

			}else if(document.getElementById('visa').checked || document.getElementById('visaElectron').checked){
				document.form.action = '../ras/reservas/visanet/visanet.asp';
				document.form.target = 'mpg_popup';
				fabrewin();				

			}else{
				alert('Selecione uma forma de pagamento!');
				return false;
			}

			return true;
		}else{
			alert('Não foi possível concluir a solicitação!');
			return false;
		}
	}catch(e){
		alert(e);
		return false;
	}
}

//carregabrw()
function carregabrw(){
	mpg_popup = window.open("", "mpg_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,screenX=0,screenY=0,left=0,top=0,width=765,height=440");
	return true;
}

//fabrewin()
function fabrewin(){
	if(navigator.appName.indexOf("Netscape") != -1){
		mpg_popup = window.open("", "mpg_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,screenX=0,screenY=0,left=0,top=0,width=765,height=440");
	}else{
		mpg_popup = window.open("", "mpg_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,screenX=0,screenY=0,left=0,top=0,width=765,height=440");
	}

	return true;
}

//bloquear(idCLiente, img)
function bloquear(idCliente, bloqueado){
	document.form.action = 'procDados.asp?acao=bloquear&idCliente='+idCliente+'&bloqueado='+bloqueado;
	document.form.submit();
}

//selecionaTipoReserva(tipo)
function selecionaTipoReserva(tipo){
	if (tipo == 'mensal'){
		document.getElementById('trData').style.display = 'none';
		document.getElementById('trHorarioPreferencial').style.display = 'none';
		document.getElementById('trDiaSemana').style.display = dsplTr;
		document.getElementById('trPeriodo').style.display = dsplTr;
		document.getElementById('btnSubmit').value='Proposta';
	}else{
		document.getElementById('trData').style.display = dsplTr;
		document.getElementById('trHorarioPreferencial').style.display = dsplTr;
		document.getElementById('trDiaSemana').style.display = 'none';
		document.getElementById('trPeriodo').style.display = 'none';
		document.getElementById('btnSubmit').value='Buscar';
	}
}

//visualizarContrato()
function visualizarContrato(){
	document.getElementById('divBtnConf').style.display = 'block';
	document.form.acao.value = 'download';
	document.form.pasta.value = '/locacao/pdf';
	document.form.arquivo.value = 'Modelo_Contrato_Locacao.pdf';	
	document.form.action = '/funcao/asp/download.asp';
	document.form.submit();
}

//finalizaReservaMensal()
function finalizaReservaMensal(){
	document.form.acao.value = 'confirmaProposta';
	document.form.action = 'procDados.asp';
	//document.form.submit();

	window.location.href = 'procDados.asp?acao=confirmaProposta';
}

