// VALIDA O LOGIN PARA USER
function validar_form_login_user( theForm )
{
	theForm = document.getElementById( theForm );
		
	if(!isBlank(theForm.loginEmail)) 
	{
		if(!isMail(theForm.loginEmail)) 
		{
			alert("Formato de e-Mail incorreto");
      		jQuery("input#loginEmail").focus();
			return false;
		} 
	}
	else
	{
		alert("Preencha o campo e-Mail");
		jQuery("input#loginEmail").focus();
		return false;
	}
	
	if (isBlank(theForm.loginSenha)) 
	{
		alert("Digite uma senha");
		jQuery("input#loginSenha").focus();
		return false;	
	}
	
	var email = escape( theForm.loginEmail.value );
	var senha = escape( theForm.loginSenha.value );
	var parametros = '?email='+email+'&senha='+senha

	chamarAjax( 'target', '../../__user/index/script_login_user.php', parametros, true );
}

// VALIDA CÓDIGO PARA CADASTRO DE FORMANDO - PÁGINA INDEX!
function validar_codigo_turma( theForm ) 
{
	theForm = document.getElementById( theForm );
	
	if(isBlank(theForm.codigo)) 
	{
		alert("É necessário informar o código de acesso. Para isso, entre em contato com a comissão da sua formatura.");
		jQuery("input#codigo").focus(); 
		return false;
	}
	
	// PARAMETROS
	var codigo = escape( theForm.codigo.value );
	var parametros = '?codigo='+codigo
	
	chamarAjax( 'target', 'cadastro_aluno/script_cadastro.php', parametros, true );
}

function validar_form_cadastro_aluno( theForm )
{	
	theForm = document.getElementById( theForm );
		
	if (isBlank(theForm.nome))
	{
		alert("Preencha o campo Nome");
		jQuery("input#nome").focus(); 
		return false; 
	}
	
	if(!isBlank(theForm.email)) 
	{
		if(!isMail(theForm.email)) 
		{
			alert("Formato de e-Mail incorreto");
      		jQuery("input#email").focus(); 
			return false;
		} 
	}
	else
	{
		alert("Preencha o campo e-Mail");
		jQuery("input#email").focus();
		return false;
	}
	
	if (isBlank(theForm.senha))
	{
		alert("Preencha o campo senha");
		jQuery("input#senha").focus(); 
		return false; 
	}
	
	if (theForm.listEstados.value == 0)
	{
		alert("Selecione um Estado");
		jQuery("select#listEstados").focus();
		return false; 
	}	
	
	if (theForm.listCidades.value == 0)
	{
		alert("Selecione uma Cidade");
		jQuery("select#listCidades").focus();
		return false; 
	}	
	
	// PREPARA STRING DE PARAMETROS
	var nome = escape( theForm.nome.value );
	var email = escape( theForm.email.value );
	var senha = escape( theForm.senha.value );
	var estado = escape( theForm.listEstados.value );
	var cidade = escape( theForm.listCidades.value );
	var parametros = '?nome='+nome+'&email='+email+'&senha='+senha+'&estado='+estado+'&cidade='+cidade; 

	
	return parametros;
	//chamarAjax( 'target', 'cadastro_aluno/script_insere.php', parametros, true );
}

function validar_form_cadastro_turma( theForm )
{	
	theForm = document.getElementById( theForm );
		
	if (isBlank(theForm.curso))
	{
		alert("Preencha o nome de seu curso");
		jQuery("input#curso").focus(); 
		return false; 
	}
	
		if (isBlank(theForm.inst))
	{
		alert("Preencha o nome da instituição");
		jQuery("input#inst").focus(); 
		return false; 
	}
	
	if (isBlank(theForm.ingresso))
	{
		alert("Preencha o ano de ingresso da sua turma");
		jQuery("input#ingresso").focus(); 
		return false; 
	}
	
	if (isBlank(theForm.nome))
	{
		alert("Preencha seu nome");
		jQuery("input#nome").focus(); 
		return false; 
	}
	
	if(!isBlank(theForm.email)) 
	{
		if(!isMail(theForm.email)) 
		{
			alert("Formato de e-Mail incorreto");
      		jQuery("input#email").focus(); 
			return false;
		} 
	}
	else
	{
		alert("Preencha o campo e-Mail");
		jQuery("input#email").focus();
		return false;
	}
	
	if (isBlank(theForm.senha))
	{
		alert("Preencha o campo senha");
		jQuery("input#senha").focus(); 
		return false; 
	}
	
	if (theForm.listEstados.value == 0)
	{
		alert("Selecione um estado");
		jQuery("select#listEstados").focus();
		return false; 
	}	
	
	if (theForm.listCidades.value == 0)
	{
		alert("Selecione uma cidade");
		jQuery("select#listCidades").focus();
		return false; 
	}	
	
	// PREPARA STRING DE PARAMETROS
	var curso = escape( theForm.curso.value );
	var inst = escape( theForm.inst.value );
	var ingresso = escape( theForm.ingresso.value );
	var nome = escape( theForm.nome.value );
	var email = escape( theForm.email.value );
	var senha = escape( theForm.senha.value );
	var estado = escape( theForm.listEstados.value );
	var cidade = escape( theForm.listCidades.value );
	var parametros = '?curso=' + curso + '&inst=' + inst + '&ingresso=' + ingresso + '&nome=' + nome +
					 '&email=' + email + '&senha=' + senha + '&estado=' + estado + '&cidade=' + cidade; 

	chamarAjax( 'target', '../../__user/cadastro_turma/script_insere.php', parametros, true );
}

// HABILITA CADASTRO ALUNO
function abilita(val)
{
	if(val == 1)
		document.fm.Submit.disabled = 0;
	else 
		document.fm.Submit.disabled = 1;
}



function Dados(valor) {
  //verifica se o browser tem suporte a ajax
  try {
	 ajax = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  catch(e) {
	 try {
		ajax = new ActiveXObject("Msxml2.XMLHTTP");
	 }
	 catch(ex) {
		try {
		   ajax = new XMLHttpRequest();
		}
		catch(exc) {
		   alert("Esse browser não tem recursos para uso do Ajax");
		   ajax = null;
		}
	 }
  }
  //se tiver suporte ajax
  if(ajax) {
	 //deixa apenas o elemento 1 no option, os outros são excluídos
	 document.fm.listCidades1.options.length = 1;
	 
	 idOpcao  = document.getElementById("opcoes");
	 
	 ajax.open("POST", "../../__user/comum/cidades.php", true);
	 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 
	 ajax.onreadystatechange = function() {
		//enquanto estiver processando...emite a msg de carregando
		if(ajax.readyState == 1) {
		   idOpcao.innerHTML = "Carregando...!";   
		}
		//após ser processado - chama função processXML que vai varrer os dados
		if(ajax.readyState == 4 ) {
		   if(ajax.responseXML) {
			  processXML(ajax.responseXML);
		   }
		   else {
			   //caso não seja um arquivo XML emite a mensagem abaixo
			   idOpcao.innerHTML = "--Primeiro selecione o estado--";
		   }
		}
	 }
	 //passa o código do estado escolhido
	 var params = "estado="+valor;
	 ajax.send(params);
  }
}

function processXML(obj){
  //pega a tag cidade
  var dataArray   = obj.getElementsByTagName("cidade");
  
  //total de elementos contidos na tag cidade
  if(dataArray.length > 0) {
	 //percorre o arquivo XML paara extrair os dados
	 for(var i = 0 ; i < dataArray.length ; i++) {
		var item = dataArray[i];
		//contéudo dos campos no arquivo XML
		var codigo    =  item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
		var descricao =  item.getElementsByTagName("descricao")[0].firstChild.nodeValue;
		
		idOpcao.innerHTML = "--Selecione uma das op&ccedil;&otilde;es abaixo--";
		
		//cria um novo option dinamicamente  
		var novo = document.createElement("option");
			//atribui um ID a esse elemento
			novo.setAttribute("id", "opcoes");
			//atribui um valor
			novo.value = codigo;
			//atribui um texto
			novo.text  = descricao;
			//finalmente adiciona o novo elemento
			document.fm.listCidades1.options.add(novo);
	 }
  }
  else {
	//caso o XML volte vazio, printa a mensagem abaixo
	idOpcao.innerHTML = "--Primeiro selecione o estado--";
  }	  
}

function efetuarLogoff()
{
	if (confirm("Você tem certeza que deseja sair ?"))
		chamarAjax( 'menuVerticalSair', '../../__user/comum/script_efetuar_logoff.php', '', true );
}

// VALIDA O EMAIL PARA USER
function validarEmail( theForm )
{
	theForm = document.getElementById( theForm );
		
	if(!isBlank(theForm.email)) 
	{
		if(!isMail(theForm.email)) 
		{
			alert("Formato de e-Mail incorreto");
      		jQuery("input#loginEmail").focus();
			return false;
		} 
	}
	else
	{
		alert("Preencha o campo e-Mail");
		jQuery("input#loginEmail").focus();
		return false;
	}
	
	var email = escape( theForm.email.value );
	
	var parametros = '?email='+email;

	chamarAjax( 'targetReenvioEmail', '../../__user/reenviar_email/script_reenviar_email.php', parametros, true );
}

// VALIDA O EMAIL
function checkEmail( theForm, field )
{
	theForm = document.getElementById( theForm );
		
	if(!isBlank(theForm.email)) 
	{
		if(!isMail(theForm.email)) 
		{
			alert("Formato de e-Mail incorreto");
      		jQuery("input#email").focus();
			return false;
		} 
	}
	else
	{
		alert("Preencha o campo e-Mail");
		jQuery("input#email").focus();
		return false;
	}
	
	var email = escape( theForm.email.value );
	
	var parametros = '?email='+email;
	
	chamarAjax( 'target', '../../__user/senha/script_enviar_senha.php', parametros, true );
}

// VALIDA O EMAIL
function checkIndicarAmigo( theForm )
{
	theForm = document.getElementById( theForm );
		
	if (isBlank(theForm.indicador))
	{
		alert("Preencha seu nome");
		jQuery("input#indicador").focus(); 
		return false; 
	}
	
	if(!isBlank(theForm.email_indicador)) 
	{
		if(!isMail(theForm.email_indicador)) 
		{
			alert("Formato de seu e-Mail incorreto");
      		jQuery("input#email_indicador").focus();
			return false;
		} 
	}
	else
	{
		alert("Preencha o seu e-Mail");
		jQuery("input#email_indicador").focus();
		return false;
	}
	
	if (isBlank(theForm.indicado))
	{
		alert("Preencha o nome de seu amigo");
		jQuery("input#indicado").focus(); 
		return false; 
	}
	
	if(!isBlank(theForm.email_indicado)) 
	{
		if(!isMail(theForm.email_indicado)) 
		{
			alert("Formato do e-Mail de seu amigo incorreto");
      		jQuery("input#email_indicado").focus();
			return false;
		} 
	}
	else
	{
		alert("Preencha o e-Mail de seu amigo");
		jQuery("input#email_indicado").focus();
		return false;
	}
	
	var indicador = escape( theForm.indicador.value );
	var email_indicador = escape( theForm.email_indicador.value );
	var indicado = escape( theForm.indicado.value );
	var email_indicado = escape( theForm.email_indicado.value );
	
	var parametros = '?indicador='+indicador+'&email_indicador='+email_indicador+
					 '&indicado='+indicado+'&email_indicado='+email_indicado;
	
	chamarAjax( 'target', '../../__user/indicar/script_indicar.php', parametros, true );
}

// DATA: 	15-12-2009
// EMAIL: 	alfredo@ecliente.com.br
function checkEntrarContato( theForm )
{
	theForm = document.getElementById( theForm );
		
	if (isBlank(theForm.nome))
	{
		alert("Preencha seu nome");
		jQuery("input#nome").focus(); 
		return false; 
	}
	
	if(!isBlank(theForm.email)) 
	{
		if(!isMail(theForm.email)) 
		{
			alert("Formato de e-Mail incorreto");
      		jQuery("input#email").focus();
			return false;
		} 
	}
	else
	{
		alert("Preencha o seu e-Mail");
		jQuery("input#email").focus();
		return false;
	}
	
	if (isBlank(theForm.assunto))
	{
		alert("Preencha o assunto");
		jQuery("input#assunto").focus(); 
		return false; 
	}
	
	if (isBlank(theForm.mensagem))
	{
		alert("Preencha a mensagem");
		jQuery("textarea#mensagem").focus(); 
		return false; 
	}
	
	var nome = escape( theForm.nome.value );
	var email = escape( theForm.email.value );
	var assunto = escape( theForm.assunto.value );
	var mensagem = escape( theForm.mensagem.value );
	
	var parametros = '?nome='+nome+'&email='+email+
					 '&assunto='+assunto+'&mensagem='+mensagem;
	
	chamarAjax( 'target', '../../__user/contato/script_entrar_contato.php', parametros, true );
}

// DATA: 	17-12-2009
// EMAIL: 	alfredo@ecliente.com.br
function checkPerfil( theForm )
{
	theForm = document.getElementById( theForm );
	
	if (isBlank(theForm.nome))
	{
		alert("Preencha seu nome");
		jQuery("input#nome").focus(); 
		return false; 
	}

	var sexo;
	if ( theForm.sexoM.checked == 1 )
		sexo = 'M';
	else if ( theForm.sexoF.checked == 1 )
		sexo = 'F';
	else
	{
		alert("Selecione um sexo");
		theForm.sexoM.focus();
		return false; 
	}
	
	if(!isBlank(theForm.email)) 
	{
		if(!isMail(theForm.email)) 
		{
			alert("Formato de e-Mail incorreto");
      		jQuery("input#email").focus();
			return false;
		} 
	}
	else
	{
		alert("Preencha o seu e-Mail");
		jQuery("input#email").focus();
		return false;
	}
	
	if ( theForm.senha.value != theForm.checkSenha.value )
	{
		alert("Confirme sua senha novamente!");
		jQuery("input#senha").focus();
		return false;      
	}
	
	if (theForm.idListaEstados.value == 0)
	{
		alert("Selecione um Estado");
		jQuery("select#idListaEstados").focus();
		return false; 
	}	
	
	if (theForm.idListaCidades.value == 0)
	{
		alert("Selecione uma Cidade");
		jQuery("select#idListaCidades").focus();
		return false; 
	}
	
	if (isBlank(theForm.fone))
	{
		alert("Preencha seu telefone");
		jQuery("input#fone").focus(); 
		return false; 
	}
	
	// PREPARA STRING DE PARAMETROS
	var nome = escape( theForm.nome.value );
	var email = escape( theForm.email.value );
	var senha = escape( theForm.senha.value );
	var estado = escape( theForm.idListaEstados.value );
	var cidade = escape( theForm.idListaCidades.value );
	
	var fone = escape( theForm.fone.value );
	var celular = escape( theForm.celular.value );
	var cep = escape( theForm.icep.value );
	var bairro = escape( theForm.bairro.value );
	var endereco = escape( theForm.endereco.value );	
	var complemento = escape( theForm.complemento.value );
	var indicacao = escape( theForm.idIndicacao.value );
	
	
	var cep2 = escape( theForm.icep2.value );
	var bairro2 = escape( theForm.bairro2.value );
	var endereco2 = escape( theForm.endereco2.value );	
	var complemento2 = escape( theForm.complemento2.value );	
	var estado2 = escape( theForm.idListaEstados2.value );
	var cidade2 = escape( theForm.idListaCidades2.value );
	
	
	var parametros = '?nome=' + nome + '&sexo=' + sexo + '&email=' + email + 
					 '&senha=' + senha + '&estado=' + estado + '&cidade=' + cidade + 
					 '&fone=' + fone + '&celular=' + celular + '&cep=' + cep + 
					 '&bairro=' + bairro + '&endereco=' + endereco + '&complemento=' + complemento + 
					 '&indicacao=' + indicacao + '&resposta_ajax=1' +
					 '&cep2=' + cep2 + '&bairro2=' + bairro2 + '&endereco2=' + endereco2 +
					 '&complemento2=' + complemento2 + '&estado2=' + estado2 + '&cidade2=' + cidade2; 
					   
	chamarAjax( 'ajaxDadosPerfil', '../../__user/perfil/dados.php', parametros, false );
	chamarAjax( 'idBarraPerfil', '../../__user/perfil/script_barra_perfil.php', parametros, false );
}

// DATA: 	18-12-2009
// EMAIL: 	alfredo@ecliente.com.br
function checkCEP( theForm )
{
	// PREPARA VALOR DE CEP
	var cep = theForm.icep.value;
	cep = cep.replace("-","");
	cep = cep.replace(".","");

	// NO MÍNIMO 5 NÚMEROS	
	if ( cep.lenght <= 5 )
	{
		alert("Preencha seu cep ou clique para buscar!");
		jQuery("input#icep").focus(); 
		return false; 
	}
	
	// PREPARA STRING DE PARAMETROS
	cep = escape( cep );	
	
	var parametros = '?cep=' + cep + '&resposta_ajax=1'; 
		   
	chamarAjax( 'ajaxDadosPerfil', '../../__user/perfil/alterar.php', parametros, true );	
}

// DATA: 	18-12-2009
// EMAIL: 	alfredo@ecliente.com.br
function alterarFotoPerfil( theForm )
{
	theForm = document.getElementById( theForm );
	
	// PREPARA VALOR DE CEP
	var foto = theForm.idUpFoto.value;

	// NO MÍNIMO 5 NÚMEROS	
	if ( foto == "" )
	{
		alert("Escolha uma foto!");
		jQuery("input#idUpFoto").focus(); 
		return false; 
	}
	
	// PREPARA STRING DE PARAMETROS
	foto = escape( foto );	
	
	var parametros = '?foto=' + foto;
	
	chamarAjax( 'idDivFotoPerfil', '../../__user/perfil/script_alterar_foto.php', parametros, true );
}

// ESCONDE OU MOSTRA UMA DIV
function mudarVisibilidade( id, check ) 
{
	if ( check == "S" )
	{
		document.getElementById(id).style.visibility = 'visible';
		document.getElementById( "txt" + id ).focus();
	}
	else
		document.getElementById(id).style.visibility = 'hidden';
}

function checkEnterAlbum( key, posicao, id, extra )
{
	var keycode;	

	if (window.event) 
		keycode = window.event.keyCode;	

	if ( keycode == 13 || extra == "S" )
	{
		var descricao = document.getElementById( "txtidDescricao" + posicao ).value;
		var parametros = "?idFoto=" + id + 
						 "&descricao=" + descricao +
						 "&posicao=" + posicao;	
		var div = "idFoto" + posicao;		
		chamarAjax( div, '../../__user/perfil/script_alterar_descricao.php', parametros, false );
	}
}

// ATRASA O SCRIPT DE EXECUTAR EM MILISEGUNDOS
function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

// FAZ COM QUE O FOCO DA PÁGINA VÁ PARA O ELEMENTO ATRAVÉS DO ID
function ScrollToElement(theElement)
{	
	theElement = document.getElementById(theElement);	
	
	var selectedPosX = 0;
	var selectedPosY = 0;
	
	while(theElement != null)
	{
		selectedPosX += theElement.offsetLeft;
		selectedPosY += theElement.offsetTop;
		theElement = theElement.offsetParent;
	}
		  
	window.scrollTo(selectedPosX,selectedPosY);
}

// HABILITA BOTAO - PASSAR REFERENCIA DO FORM, NAME DO BOTÃO SUBMIT, TRUE OU FALSE
function abilitaBotao( theForm, theElement, status )
{	
	theElement = theForm.elements[theElement];
	
	if( status )
		theElement.disabled = 0;
	else 
		theElement.disabled = 1;	
}



// DATA: 	05-01-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkTurma( theForm )
{	
	theForm = document.getElementById( theForm );
	
	if (isBlank(theForm.instituicao))
	{
		alert("Preencha o nome de sua instituição");
		jQuery("input#instituicao").focus(); 
		return false; 
	}

	
	if (theForm.listEstados.value == 0)
	{
		alert("Selecione um Estado");
		jQuery("select#listEstados").focus();
		return false; 
	}	
	
	if (theForm.listCidades.value == 0)
	{
		alert("Selecione uma Cidade");
		jQuery("select#listCidades").focus();
		return false; 
	}
	
	if (isBlank(theForm.curso))
	{
		alert("Preencha o nome de seu curso");
		jQuery("input#curso").focus(); 
		return false; 
	}
	
	// PREPARA STRING DE PARAMETROS
	var instituicao = escape( theForm.instituicao.value );
	var curso = escape( theForm.curso.value );
	var estado = escape( theForm.listEstados.value );
	var cidade = escape( theForm.listCidades.value );
	//var valor = escape( theForm.valor.value );	
	
	var parametros = '?instituicao=' + instituicao + '&curso=' + curso + 
					 '&estado=' + estado + '&cidade=' + cidade + '&resposta_ajax=1'; //'&valor=' + valor + 
			   
	chamarAjax( 'ajaxDadosTurma', '../../__user/classe/info_turma.php', parametros, false );
}

function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}

function checkEnterClasse( key, pagina, extra )
{
	var keycode;	

	if (window.event) 
		keycode = window.event.keyCode;	

	if ( keycode == 13 || extra == "S" )
	{
		// ITENS POR PÁGINA
		var pag_views = document.getElementById( "idTxtPageViews" ).value;		
		
		// VERIFICA SE EXIBE ALUNOS DESATIVADOS!
		var alunoDT = document.getElementById( "idAlunoDesativadoT" ).checked;
		var alunoDF = document.getElementById( "idAlunoDesativadoF" ).checked;
		if ( alunoDT == 1 )
			alunosD = 'T';
		else if ( alunoDF == 1 )
			alunosD = 'F';					
		
		// FILTRO POR SEXO
		var sexo = "";
		var sexoT = document.getElementById( "idSexoT" ).checked;
		var sexoM = document.getElementById( "idSexoM" ).checked;
		var sexoF = document.getElementById( "idSexoF" ).checked;
		if ( sexoT == 1 )
			sexo = 'T';
		else if ( sexoM == 1 )
			sexo = 'M';
		else if ( sexoF == 1 )
			sexo = 'F';
		
		var parametros = "?resposta_ajax=1" + "&pag_views=" + pag_views + "&pagina=" + pagina + 
						 "&alunosD=" + alunosD + "&sexo=" + sexo;	

		chamarAjax( 'ajaxDadosClasse', '../../__user/classe/info_classe.php', parametros, true );
	}
	
	
}

function confirmar( msg, funcao )
{
	funcao = urldecode(funcao);
	
	if ( confirm( msg ) )
		executar( funcao );
	else
		return false;
}

function executar( funcao )
{
	var Emular = document.createElement('script');
	Emular.setAttribute('language','Javascript');
	Emular.text = funcao;
	document.body.appendChild( Emular );
}

function urlencode(str) {
return escape(str).replace('+', '%2B').replace('%20', '+').replace('*', '%2A').replace('/', '%2F').replace('@', '%40');
}

function urldecode(str) {
return unescape(str.replace(/\053/g, ' '));
}



// DATA: 	11-01-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkClasseCadastrarAluno( theForm )
{
	theForm = document.getElementById( theForm );
		
	if (isBlank(theForm.nome))
	{
		alert("Preencha o nome do aluno");
		jQuery("input#nome").focus(); 
		return false; 
	}
	
	if(!isBlank(theForm.email)) 
	{
		if(!isMail(theForm.email)) 
		{
			alert("Formato de e-Mail incorreto");
      		jQuery("input#email").focus();
			return false;
		} 
	}
	else
	{
		alert("Preencha o e-Mail do aluno");
		jQuery("input#email").focus();
		return false;
	}
	
	if (isBlank(theForm.senha))
	{
		alert("Preencha a senha do aluno");
		jQuery("input#senha").focus(); 
		return false; 
	}
	
	if ( isBlank( theForm.idTextoCadastro ) )
	{
		alert("Preencha um texto");
		jQuery("textarea#idTextoCadastro").focus(); 
		return false; 
	}
	
	var nome = escape( theForm.nome.value );
	var email = escape( theForm.email.value );
	var senha = escape( theForm.senha.value );
	var texto = escape( theForm.idTextoCadastro.value );
	
	var parametros = "?resposta_ajax=1" + "&nome=" + nome + "&email=" + email +
					 "&senha=" + senha + "&texto=" + texto;
	
	chamarAjax( 'ajaxCadastro', '../../__user/classe/cadastrar.php', parametros, false );
}


function ativarFiltroCobrancas( key, pagina, extra )
{
	var keycode;	

	if (window.event) 
		keycode = window.event.keyCode;	

	if ( keycode == 13 || extra == "S" )
	{
		// ITENS POR PÁGINA
		var pag_views = document.getElementById( "idTxtPageViewsCob" ).value;		
		
		// FILTRO!
		var emAberto = document.getElementById( "idEmAberto" ).checked;	
		var todas = document.getElementById( "idTodas" ).checked;		
		var vencidas = document.getElementById( "idVencidas" ).checked;
		var aPagar = document.getElementById( "idAPagar" ).checked;
		var pagas = document.getElementById( "idPagas" ).checked;
		
		if ( emAberto == 1 )
			filtro = "emAberto";
		else if ( todas == 1 )
			filtro = "todas";
		else if ( vencidas == 1 )
			filtro = "vencidas";
		else if ( aPagar == 1 )
			filtro = "aPagar";
		else if ( pagas == 1 )
			filtro = "pagas";
			
		var parametros = "?resposta_ajax=1" + "&pag_views=" + pag_views + "&pagina=" + pagina + "&filtroCob=" + filtro;
	
		chamarAjax( 'ajaxCobrancas', '../../__user/classe/info_cobrancas.php', parametros, true );
	}	
}

// DATA: 	14-01-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkClasseConvidarAluno( theForm )
{
	var emails_novos = "";
	theForm = document.getElementById( theForm );	
		
	if(!isBlank(theForm.emails)) 
	{
		var emails = theForm.emails.value;
		var emails = emails.split( "," );
	
		for (var i = 0; i < emails.length; i++)
		{			
			var email = trim( emails[i] )
			
			if( !isMail2( email ) )
			{
				var num = i + 1;
				alert("O " + num + "º email está com formato incorreto:" + email );
				jQuery("input#emails").focus();
				return false;
			} 

			if ( ( i + 1 ) < emails.length )
				emails_novos += email + ",";
			else	
				emails_novos += email;			
		}
	}
	else
	{
		alert("Preencha algum e-Mail para enviar o convite!");
		jQuery("input#emails").focus();
		return false;
	}
	
	if ( isBlank( theForm.idTextoConvite ) )
	{
		alert("Preencha um texto");
		jQuery("textarea#idTextoConvite").focus(); 
		return false; 
	}		

	var emails_novos = escape( emails_novos );
	var texto = escape( theForm.idTextoConvite.value );
	
	var parametros = "?resposta_ajax=1" + "&emails=" + emails_novos + "&texto=" + texto;
	
	chamarAjax( 'ajaxConvidar', '../../__user/classe/convidar.php', parametros, false );
}

//trim completo
function trim(str) {
return str.replace(/^\s+|\s+$/g,"");
}

// DATA: 	18-01-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkClasseVisualizarCobranca( theForm )
{	
	theForm = document.getElementById( theForm );	
	
	if (isBlank(theForm.sel3))
	{
		alert("Preencha a data");
		jQuery("input#sel3").focus(); 
		return false; 
	}

	if (isBlank(theForm.idValor))
	{
		alert("Preencha um valor");
		jQuery("input#idValor").focus(); 
		return false; 
	}
	
	if ( theForm.idReceita.value == 0 )
	{
		alert("Selecione uma receita");
		jQuery("select#idReceita").focus();
		return false; 
	}	
	
	if (theForm.idAluno.value == 0)
	{
		alert("Selecione um aluno");
		jQuery("select#idAluno").focus();
		return false; 
	}	
	
	// PREPARA STRING DE PARAMETROS
	var dtPag = escape( theForm.sel3.value );
	var valor = escape( theForm.idValor.value );	
	var receita = escape( theForm.idReceita.value );	
	var aluno = escape( theForm.idAluno.value );	
	var voltar = escape( theForm.idVoltar.value );		
	var id = escape( theForm.idCobranca.value );
	
	if ( theForm.nmStatu.checked )
		var statu = "&statu=F";
	else	
		var statu = "&statu=A";
	
	if ( theForm.nmBoleto.checked || theForm.nmBoleto.value == '1'  )
		var boleto = "&boleto=1";
	else	
		var boleto = "&boleto=0";
		
	var parametros = '?dtPag=' + dtPag + '&valor=' + valor + '&receita=' + receita + 
					 '&aluno=' + aluno + '&id=' + id + '&resposta_ajax=1' + statu +
					 '&voltar=' + voltar + '&boleto=' + boleto; 
	
	chamarAjax( 'ajaxDadosCobranca', '../../__user/classe/script_alterar_cobranca.php', parametros, false );
}

/* ENQUETES */
function ativarFiltroEnquete( key, pagina, extra )
{
	var keycode;	

	if (window.event) 
		keycode = window.event.keyCode;	

	if ( keycode == 13 || extra == "S" )
	{
		// ITENS POR PÁGINA
		var pag_views = document.getElementById( "idTxtPageViews" ).value;	 
		
		// DATA INICIAL
		var dataInicial = document.getElementById( "idTxtPeriodo" ).value;	    		
		
		// FILTRO!
		var ativas = document.getElementById( "idAtivas" ).checked;	
		var todas = document.getElementById( "idTodas" ).checked;		
		var encerradas = document.getElementById( "idEncerradas" ).checked;
		
		if ( ativas == 1 )
			filtro = "ativas";
		else if ( todas == 1 )
			filtro = "todas";
		else if ( encerradas == 1 )
			filtro = "encerradas";
						
		var parametros = "?resposta_ajax=1" + "&pag_views=" + pag_views + 
						 "&pagina=" + pagina + "&filtro=" + filtro + "&dataInicial=" + dataInicial;

		chamarAjax( 'ajaxEnquete', '../../__user/enquete/info_enquete.php', parametros, true );
	}	
}

// DATA: 	18-01-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkEnqueteVisualizarEnquete( theForm )
{
	theForm = document.getElementById( theForm );	
	
	if (isBlank(theForm.idPergunta))
	{
		alert("Preencha uma pergunta");
		jQuery("input#idPergunta").focus(); 
		return false; 
	}

	if (isBlank(theForm.idDataFim))
	{
		alert("Preencha uma data para encerrar a enquete");
		jQuery("input#idDataFim").focus(); 
		return false; 
	}
	
	if ( ( isBlank( theForm.idAlternativa1 ) ) || ( isBlank( theForm.idAlternativa2 ) ) )
	{
		alert("Preencha a primeira e segunda alternativa no mínimo!");
		
		if (isBlank(theForm.idAlternativa1))
			jQuery("input#idAlternativa1").focus();
		else if (isBlank(theForm.idAlternativa2))
			jQuery("input#idAlternativa2").focus();	
			
		return false; 
	}	
	
	// PREPARA STRING DE PARAMETROS
	var pergunta = escape( theForm.idPergunta.value );
	var datafim = escape( theForm.idDataFim.value );
	var id = escape( theForm.idEnquete.value );
	
	var parametros = '?pergunta=' + pergunta + '&datafim=' + datafim + '&id=' + id + '&resposta_ajax=1'; 
	
	var alternativa1 = escape( theForm.idAlternativa1.value );	
	var alternativa2 = escape( theForm.idAlternativa2.value );	
	var alternativa3 = escape( theForm.idAlternativa3.value );	
	var alternativa4 = escape( theForm.idAlternativa4.value );	
	var alternativa5 = escape( theForm.idAlternativa5.value );

	parametros += "&alternativa1=" + alternativa1 + "&alternativa2=" + alternativa2 + 
				  "&alternativa3=" + alternativa3 + "&alternativa4=" + alternativa4 + 
				  "&alternativa5=" + alternativa5;
				  
	chamarAjax( 'ajaxDadosEnquete', '../../__user/enquete/script_alterar_enquete.php', parametros, true );
}

// DATA: 	18-01-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkEnqueteCadastrarEnquete( theForm )
{
	theForm = document.getElementById( theForm );	
	
	if (isBlank(theForm.idPergunta))
	{
		alert("Preencha uma pergunta");
		jQuery("input#idPergunta").focus(); 
		return false; 
	}

	if (isBlank(theForm.idDataFim))
	{
		alert("Preencha uma data para encerrar a enquete");
		jQuery("input#idDataFim").focus(); 
		return false; 
	}	
	
	// PREPARA STRING DE PARAMETROS
	var pergunta = escape( theForm.idPergunta.value );
	var datafim = escape( theForm.idDataFim.value );
	var idEnqueteNova = theForm.idEnqueteNova.value;
	
	if( !compararData( datafim ) )
	{		
		alert('Data deve ser igual ou maior que hoje!');
		jQuery("input#idDataFim").focus(); 
		return false; 
	}
	
	var parametros = '?pergunta=' + pergunta + '&datafim=' + datafim + '&resposta_ajax=1';
	
	if ( idEnqueteNova )
		parametros += '&idEnqueteNova=' + idEnqueteNova;	
	else
		parametros += '&inserirPergunta=1'
		
	/*
	if ( theForm.nmStatus.checked )
		parametros += "&status=1";
	else	
		parametros += "&status=0";
	*/	
	chamarAjax( 'ajaxCadastrarEnquete', '../../__user/enquete/cadastrar_enquete.php', parametros, false );
	chamarAjax( 'ajax_Menu_Enquete', '../../__user/enquete/menu_principal.php', '?resposta_ajax=1', false );
}

// DATA: 	18-01-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkVotarEnquete( theForm )
{
	theForm = document.getElementById( theForm );	
	
	var check = false;
	for ( var i = 0; i < theForm.enquete.length; i++) 
	{ 
		if ( theForm.enquete[i].checked ) 
		{ 
			var codAlt = theForm.enquete[i].value; 
			var check = true;
		} 
	}
	
	if ( check == false )
	{
		alert('Por favor selecione alguma alternativa!');
		jQuery("input#enviar").focus();	
		return false;
	}
	
	var parametros = '?resposta_ajax=1' + '&codAlt=' + codAlt + '&registrarVoto=1';	
	chamarAjax( 'ajax_Menu_Enquete', '../../__user/enquete/menu_principal.php', parametros, false );
}

// DATA: 	18-01-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkEnqueteCadastrarAlternativa( theForm )
{
	theForm = document.getElementById( theForm );	
	
	if (isBlank(theForm.idAlternativa))
	{
		alert("Preencha a alternativa");
		jQuery("input#idAlternativa").focus(); 
		return false; 
	}	
	
	var alternativa = escape( theForm.idAlternativa.value );	
	var idPergunta = theForm.idPergunta.value 
	
	var parametros = '?resposta_ajax=1' + '&alternativa=' + alternativa + '&idPergunta=' + idPergunta;
		
	chamarAjax( 'ajaxCadastrarAlternativa', '../../__user/enquete/cadastrar_alternativa.php', parametros, false );
	chamarAjax( 'ajax_Menu_Enquete', '../../__user/enquete/menu_principal.php', '?resposta_ajax=1', false );
}

// DATA: 	27-01-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkReceitaCadastrarCobranca( theForm )
{
	theForm = document.getElementById( theForm );	
	
	if (isBlank(theForm.sel3))
	{
		alert("Preencha a data");
		jQuery("input#sel3").focus(); 
		return false; 
	}

	if (isBlank(theForm.idValor))
	{
		alert("Preencha um valor");
		jQuery("input#idValor").focus(); 
		return false; 
	}
	
	if ( theForm.idReceita.value == 0 )
	{
		alert("Selecione uma receita");
		jQuery("select#idReceita").focus();
		return false; 
	}	
	
	if (theForm.idAluno.value == 0)
	{
		alert("Selecione um aluno");
		jQuery("select#idAluno").focus();
		return false; 
	}
	
	// PREPARA STRING DE PARAMETROS
	var dtPag = escape( theForm.sel3.value );
	var valor = escape( theForm.idValor.value );	
	var receita = escape( theForm.idReceita.value );	
	var aluno = escape( theForm.idAluno.value );
	
	if ( theForm.nmBoleto.checked )
		var boleto = "&boleto=1";
	else	
		var boleto = "&boleto=0";
	
	var parametros = '?dtPag=' + dtPag + '&valor=' + valor + '&receita=' + receita + 
					 '&aluno=' + aluno + '&boleto=' + boleto + '&resposta_ajax=1';
	
	chamarAjax( 'ajaxCadastrarReceitas', '../../__user/receita/cobranca.php', parametros, false );
}

// DATA: 	27-01-2010
// EMAIL: 	alfredo@ecliente.com.br
function deletarReceita( id, tipo )
{
	if ( tipo == "aberta" )
	{
		var div = "ajaxReceitasAberto";
		var url = "../../__user/receita/receitasAberto.php";
	}
	else if ( tipo == "quitada" )
	{
		var div = "ajaxReceitasQuitadas";
		var url = "../../__user/receita/receitasQuitadas.php";
	}
	else if ( tipo == 'aluno' )
	{
		var div = "ajaxReceitasAluno";
		var url = "../../__user/classe/receitasAluno.php";
	}
	else if ( tipo == 'classe' )
	{
		var div = 'ajaxDadosCobranca';
		var url = "../../__user/receita/deletar.php";
	}
	
	
	var parametros = "?deletar=1&id=" + id;
	
	chamarAjax( div, url, parametros, false );	
	chamarAjax( 'ajax_Menu_Financas', '../../__user/resumo_financeiro/script_menu_financas.php', '?resposta_ajax=1', false ); 
}

// DATA: 	27-01-2010
// EMAIL: 	alfredo@ecliente.com.br
function deletarDespesa( id, tipo )
{
	if ( tipo == "aberta" )
	{
		var div = "ajaxDespesasAberto";
		var url = "../../__user/despesa/script_abertas.php";
	}
	else if ( tipo == "quitada" )
	{
		var div = "ajaxDespesasQuitadas";
		var url = "../../__user/despesa/script_quitadas.php";
	}
	else if ( tipo == "classe" )
	{
		var div = "ajaxAlterarDespesas";
		var url = "../../__user/despesa/deletar.php";
	}
	
	
	var parametros = "?deletar=1&id=" + id;
	
	chamarAjax( div, url, parametros, false );	
	chamarAjax( 'ajax_Menu_Financas', '../../__user/resumo_financeiro/script_menu_financas.php', '?resposta_ajax=1', false ); 
}

// DATA: 	27-01-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkDespesaCadastrarDespesa( theForm )
{
	theForm = document.getElementById( theForm );	
	
	if (isBlank(theForm.sel3))
	{
		alert("Preencha a data");
		jQuery("input#sel3").focus(); 
		return false; 
	}

	if (isBlank(theForm.idValor))
	{
		alert("Preencha um valor");
		jQuery("input#idValor").focus(); 
		return false; 
	}
	
	if ( theForm.idDespesa.value == 0 )
	{
		alert("Selecione uma despesa");
		jQuery("select#idDespesa").focus();
		return false; 
	}	
	
	var descricao = escape( theForm.idDescricao.value );
	
	if ( descricao == "" )
	{
		alert("Preencha uma descrição");
		jQuery("textarea#idDescricao").focus(); 
		return false; 
	}
	
	// PREPARA STRING DE PARAMETROS
	var vencimento = escape( theForm.sel3.value );
	var valor = theForm.idValor.value;	
	var despesa = escape( theForm.idDespesa.value );
	var descricao = escape( theForm.idDescricao.value );	
	
	var parametros = '?vencimento=' + vencimento + '&valor=' + valor + '&despesa=' + despesa + 
					 '&descricao=' + descricao + '&resposta_ajax=1';
					 
	chamarAjax( 'ajaxCadastrarDespesas', '../../__user/despesa/script_cadastro.php', parametros, false );
}

// DATA: 	18-01-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkDespesaAlterarDespesa( theForm )
{
	theForm = document.getElementById( theForm );	
	
	if (isBlank(theForm.sel3))
	{
		alert("Preencha a data");
		jQuery("input#sel3").focus(); 
		return false; 
	}

	if (isBlank(theForm.idValor))
	{
		alert("Preencha um valor");
		jQuery("input#idValor").focus(); 
		return false; 
	}	
	
	var descricao = escape( theForm.idDescricao.value );
	
	if ( descricao == "" )
	{
		alert("Preencha uma descrição");
		jQuery("textarea#idDescricao").focus(); 
		return false; 
	}
	
	// PREPARA STRING DE PARAMETROS
	var id = escape( theForm.idDespesa.value );
	var vencimento = escape( theForm.sel3.value );
	var valor = theForm.idValor.value;	
	var categoria = escape( theForm.idCatDespesa.value );
	var descricao = escape( theForm.idDescricao.value );	
	
	if ( theForm.nmStatu.checked )
		var statu = "&statu=F";
	else	
		var statu = "&statu=A";
		
	var parametros = '?id=' + id + '&vencimento=' + vencimento + '&valor=' + valor + 
					 '&categoria=' + categoria + '&descricao=' + descricao + statu + '&alterar=1';
	
	chamarAjax( 'ajaxAlterarDespesas', '../../__user/despesa/script_alterar.php', parametros, true );	
}

// DATA: 	18-01-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkNoticiaCadastrarNoticia( theForm )
{
	theForm = document.getElementById( theForm );	
	
	if (isBlank(theForm.idTitulo))
	{
		alert("Preencha um título");
		jQuery("input#idTitulo").focus(); 
		return false; 
	}	
	
	if (isBlank(theForm.idDataIniDivulgacao))
	{
		alert("Preencha a data inicial");
		jQuery("input#idDataIniDivulgacao").focus(); 
		return false; 
	}
	
	if (isBlank(theForm.idDataFimDivulgacao))
	{
		alert("Preencha a data final");
		jQuery("input#idDataFimDivulgacao").focus(); 
		return false; 
	}
	
	if ( parseInt( theForm.idDataFimDivulgacao.value.split( "/" )[2].toString() + theForm.idDataFimDivulgacao.value.split( "/" )[1].toString() + theForm.idDataFimDivulgacao.value.split( "/" )[0].toString() ) < parseInt( theForm.idDataFimDivulgacao.value.split( "/" )[2].toString() + theForm.idDataFimDivulgacao.value.split( "/" )[1].toString() + theForm.idDataFimDivulgacao.value.split( "/" )[0].toString() ) )
	{
		alert('A Data final deve ser maior que a data inicial');
		jQuery("input#idDataFimDivulgacao").focus(); 
		return false; 
	}		
		
	if ( conteudo == "" )
	{
		alert("Preencha uma descrição");
		var oFCKeditor=FCKeditorAPI.GetInstance('conteudo') ;
		oFCKeditor.Focus();
		return false; 
	}
	
	// PREPARA STRING DE PARAMETROS
	var idNoticiaNova = escape( theForm.idNoticiaNova.value );
	var titulo = escape( theForm.idTitulo.value );
	var datainidivulgacao = escape( theForm.idDataIniDivulgacao.value );
	var datafimdivulgacao = escape( theForm.idDataFimDivulgacao.value );
	var conteudo = escape( theForm.conteudo.value );	
	
	/*
	if ( theForm.nmStatus.checked )
		var ativa = "&ativa=1";
	else	
		var ativa = "&ativa=0";
	*/	
	if ( idNoticiaNova )
		var modo = '&idNoticiaNova=' + idNoticiaNova;	
	else
		var modo = '&inserirNoticia=1'
		
	var parametros = '?resposta_ajax=1' + '&idNoticiaNova=' + idNoticiaNova + '&titulo=' + titulo + 
				     '&datainidivulgacao=' + datainidivulgacao + '&datafimdivulgacao=' + datafimdivulgacao + 
					 '&conteudo=' + conteudo + modo; //ativa + 
		
	if ( idNoticiaNova )
		var div = "ajaxDadosNoticia";
	else
		var div = "ajaxCadastrarNoticia";
	
	chamarAjax( div, '../../__user/noticia/cadastrar.php', parametros, false );	
}

// DATA: 	01-02-2010
// EMAIL: 	alfredo@ecliente.com.br
function deletarEnquete( id )
{	
	var parametros = "?deletar=1&id=" + id;	
	//alert(parametros);
	//chamarAjax( 'ajaxEnquete', '../../__user/enquete/info_enquete.php', parametros, false ); 
	chamarAjax( 'ajaxCadastrarEnquete', '../../__user/enquete/deletar.php', parametros, false ); 
}

// DATA: 	01-02-2010
// EMAIL: 	alfredo@ecliente.com.br
function deletarNoticia( id )
{	
	var parametros = "?deletar=1&id=" + id;	
	chamarAjax( 'ajaxDadosNoticia', '../../__user/noticia/info_noticia.php', parametros, false ); 
}

function Verifica() 
{
	rest	= limite - document.getElementById("texto").value.length;
	
	if( ( rest + 1 ) > 0) 
	{
		//rest	= limite - document.getElementById("texto").value.length;
		antes 	= document.getElementById("texto").value;
		
		document.getElementById("falta").innerHTML = rest;
		
		// HABILITA BOTÃO SUBMIT
		document.getElementById("enviar").disabled = false;		
	} 
	else
		document.getElementById("texto").innerHTML = antes;
}

// DATA: 	18-01-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkMuralCadastrarRecado( theForm )
{
	theForm = document.getElementById( theForm );	
	
	if ( isBlank( theForm.texto ) )
	{
		alert("Preencha um texto");
		jQuery("textarea#texto").focus(); 
		return false; 
	}		
	
	var texto = escape( theForm.texto.value );
	var idTipo = escape( theForm.idTipo.value );
	
	var parametros = '?inserir=1' + '&texto=' + texto;
	if ( idTipo == 'principal' )
		chamarAjax( 'ajaxMural', '../../__user/principal/mural.php', parametros, false );	
	else
		chamarAjax( 'ajaxMural', '../../__user/mural/info_mural.php', parametros, false );	
}

// DATA: 	01-02-2010
// EMAIL: 	alfredo@ecliente.com.br
function deletarRecado( id, tipo )
{	
	var parametros = "?deletar=1&id=" + id;
	if ( tipo == 'principal' )
		chamarAjax( 'ajaxMural', '../../__user/principal/mural.php', parametros, false );	
	else
		chamarAjax( 'ajaxMural', '../../__user/mural/info_mural.php', parametros, false );	
}

function gerarListaCidades(valor) {
  //verifica se o browser tem suporte a ajax
  try {
	 ajax = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  catch(e) {
	 try {
		ajax = new ActiveXObject("Msxml2.XMLHTTP");
	 }
	 catch(ex) {
		try {
		   ajax = new XMLHttpRequest();
		}
		catch(exc) {
		   alert("Esse browser não tem recursos para uso do Ajax");
		   ajax = null;
		}
	 }
  }
  //se tiver suporte ajax
  if(ajax) {
	 //deixa apenas o elemento 1 no option, os outros são excluídos
	 var cidades = document.getElementById( 'idListaCidades' );	
	 cidades.options.length = 1;
	 
	 idOpcao  = document.getElementById("opcoes");
	 
	 ajax.open("POST", "../../__user/comum/cidades.php", true);
	 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 
	 ajax.onreadystatechange = function() {
		//enquanto estiver processando...emite a msg de carregando
		if(ajax.readyState == 1) {
		   idOpcao.innerHTML = "Carregando...!";   
		}
		//após ser processado - chama função processXML que vai varrer os dados
		if(ajax.readyState == 4 ) {
		   if(ajax.responseXML) {
			  processXMLCidades(ajax.responseXML);
		   }
		   else {
			   //caso não seja um arquivo XML emite a mensagem abaixo
			   idOpcao.innerHTML = "--Primeiro selecione o estado--";
		   }
		}
	 }
	 //passa o código do estado escolhido
	 var params = "estado="+valor;
	 ajax.send(params);
  }
}

function processXMLCidades(obj){
	var cidades = document.getElementById( 'idListaCidades' );	
  //pega a tag cidade
  var dataArray   = obj.getElementsByTagName("cidade");
  
  //total de elementos contidos na tag cidade
  if(dataArray.length > 0) {
	 //percorre o arquivo XML paara extrair os dados
	 for(var i = 0 ; i < dataArray.length ; i++) {
		var item = dataArray[i];
		//contéudo dos campos no arquivo XML
		var codigo    =  item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
		var descricao =  item.getElementsByTagName("descricao")[0].firstChild.nodeValue;
		
		idOpcao.innerHTML = "--Selecione uma das op&ccedil;&otilde;es abaixo--";
		
		//cria um novo option dinamicamente  
		var novo = document.createElement("option");
			//atribui um ID a esse elemento
			novo.setAttribute("id", "opcoes");
			//atribui um valor
			novo.value = codigo;
			//atribui um texto
			novo.text  = descricao;
			//finalmente adiciona o novo elemento
			cidades.options.add(novo);
	 }
  }
  else {
	//caso o XML volte vazio, printa a mensagem abaixo
	idOpcao.innerHTML = "--Primeiro selecione o estado--";
  }	  
}

// DATA: 	01-02-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkMasterCadastrar( theForm )
{
	theForm = document.getElementById( theForm );	
	
	if (theForm.idAlunos.value == 0)
	{
		alert("Selecione um aluno");
		jQuery("select#idAlunos").focus();
		return false; 
	}	

	if (theForm.idTurma.value == 0)
	{
		alert("Selecione uma turma");
		jQuery("select#idTurma").focus();
		return false; 
	}	
	
	var codturma = escape( theForm.idTurma.value );
	var idcadastro = escape( theForm.idAlunos.value );
	
	var parametros = '?inserir=1' + '&codturma=' + codturma + '&idcadastro=' + idcadastro;

	chamarAjax( 'ajaxMasterInc', '../../__user/master/cadastrar.php', parametros, false );	
}

// DATA: 	01-02-2010
// EMAIL: 	alfredo@ecliente.com.br
function alterarSessaoTurma( turma )
{		
	if ( turma != 0 )
	{
		var parametros = '?resposta_ajax=1' + '&turma=' + turma;
		chamarAjax( 'ajaxMaster', '../../__user/master/gerenciar_turmas.php', parametros, false );	
		chamarAjax( 'ajax_Menu_Financas', '../../__user/resumo_financeiro/script_menu_financas.php', '?resposta_ajax=1', false );
		chamarAjax( 'ajax_Menu_Enquete', '../../__user/enquete/menu_principal.php', '?resposta_ajax=1', false );
		chamarAjax( 'ajaxCbUserMaster', '../../__user/master/alterarCbUser.php', '?resposta_ajax=1', false );	
	}
}

// DATA: 	01-02-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkAlterarContaBancaria( theForm )
{
	theForm = document.getElementById( theForm );	
	
	if (isBlank(theForm.idCedente))
	{
		alert("Preencha o nome do cedente");
		jQuery("input#idCedente").focus(); 
		return false; 
	}
	
	if (isBlank(theForm.idCpfCnpjCedente))
	{
		alert("Preencha o número do CPF e CNPJ");
		jQuery("input#idCpfCnpjCedente").focus(); 
		return false; 
	}
	else
	{
		var checkCpfCnpjCedente = false;
		if ( ValidarCPF2( theForm.idCpfCnpjCedente ) )
			checkCpfCnpjCedente = true;
		else if ( ValidarCNPJ2( theForm.idCpfCnpjCedente ) )
			checkCpfCnpjCedente = true;
		else
		{
			alert('Por favor verifique o formato de seu CPF/CNPJ');
			jQuery("input#idCpfCnpjCedente").focus(); 
			return false; 
		}			
	}
	
	/*
	if (isBlank(theForm.idEndereco))
	{
		alert("Preencha o endereço do cedente");
		jQuery("input#idEndereco").focus(); 
		return false; 
	}
	*/
	
	if (theForm.idListaBanco.value == 0)
	{
		alert("Selecione um banco");
		jQuery("select#idListaBanco").focus();
		return false; 
	}
	
	if (isBlank(theForm.idAgencia))
	{
		alert("Preencha o campo agência");
		jQuery("input#idAgencia").focus(); 
		return false; 
	}
	
	if (isBlank(theForm.idConta))
	{
		alert("Preencha o campo conta");
		jQuery("input#idConta").focus(); 
		return false; 
	}
	
	if (isBlank(theForm.idCarteira))
	{
		alert("Preencha o campo carteira");
		jQuery("input#idCarteira").focus(); 
		return false; 
	}		
	
	var cedente = escape( theForm.idCedente.value );
	var cpfCnpjCedente = escape( theForm.idCpfCnpjCedente.value );
	//var endereco = escape( theForm.idEndereco.value );
	var banco = escape( theForm.idListaBanco.value );
	var agencia = escape( theForm.idAgencia.value );
	var dgAgencia = escape( theForm.idDgAgencia.value );
	var conta = escape( theForm.idConta.value );
	var dgConta = escape( theForm.idDgConta.value );
	var carteira = escape( theForm.idCarteira.value );
	var convenio = escape( theForm.idConvenio.value );
 
	var parametros = '?cadastrar=1' + '&cedente=' + cedente + '&cpfCnpjCedente=' + cpfCnpjCedente +
					 /*'&endereco=' + endereco +*/ '&banco=' + banco + '&agencia=' + agencia + 
					 '&dgAgencia=' + dgAgencia + '&conta=' + conta + '&dgConta=' + dgConta +
					 '&carteira=' + carteira + '&convenio=' + convenio + '&resposta_ajax=1';
	
	chamarAjax( 'ajaxContaBancaria', '../../__user/conta/info.inc.php', parametros, false );	
}

/******************************************************************** 	
FUNÇÃO:		IMPRIMIR BOLETO
PARÂMETROS:	ID DO BOLETO!
RETORNO:
*********************************************************************/
function imprimirBoleto( url )
{
	window.open( url, "IMPRIMIR", "height = 600, width = 600,resizable=yes,scrollbars=yes");	
}



// DATA: 	01-02-2010
// EMAIL: 	alfredo@ecliente.com.br
function gerarBoleto( idPacote )
{
	idPacote = document.getElementById( idPacote );	

	if ( idPacote.value == 0)
	{
		alert("Selecione um pacote");
		jQuery("select#idPacote").focus();
		return false; 
	}
	
	var quantidade = idPacote.value;
	
	if ( quantidade == 50 )
		var valor = 10;
	else if ( quantidade == 250 )
		var valor = 45;
	else if ( quantidade == 500 )
		var valor = 80;
	else return false;	
	
	var parametros = '?resposta_ajax=1&gerarBoleto=1' + 
					 '&quantidade=' + quantidade + '&valor=' + valor;
					 
	chamarAjax( 'ajaxCreditoBoleto', '../../__user/conta/infoCreditoBoleto.inc.php', parametros, false );	
}

// DATA: 	01-02-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkFmLoginAdm( theForm )
{
	theForm = document.getElementById( theForm );	

	if (isBlank(theForm.idLogin))
	{
		alert("Preencha o campo login");
		jQuery("input#idLogin").focus(); 
		return false; 
	}
	
	if (isBlank(theForm.idSenha))
	{
		alert("Preencha o campo senha");
		jQuery("input#idSenha").focus(); 
		return false; 
	}
	
	
	var loginAdm = escape( theForm.idLogin.value );
	var senhaAdm = escape( theForm.idSenha.value );
	
	var parametros = '?resposta_ajax=1' + 
					 '&loginAdm=' + loginAdm + '&senhaAdm=' + senhaAdm;
					 
	chamarAjax( 'idDivLoginAdm', '../../__adm/index/verificaLoginAdm.php', parametros, false );	
}


// FUNÇÃO DINÂMICA PARA GERAÇÃO DE CIDADES/ESTADOS!
function gerarListaCidadesDinamico(valor) {
  //verifica se o browser tem suporte a ajax
  try {
	 ajax = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  catch(e) {
	 try {
		ajax = new ActiveXObject("Msxml2.XMLHTTP");
	 }
	 catch(ex) {
		try {
		   ajax = new XMLHttpRequest();
		}
		catch(exc) {
		   alert("Esse browser não tem recursos para uso do Ajax");
		   ajax = null;
		}
	 }
  }
  //se tiver suporte ajax
  if(ajax) {
	 //deixa apenas o elemento 1 no option, os outros são excluídos
	 var cidades = document.getElementById( 'idListaCidades2' );	
	 cidades.options.length = 1;
	 
	 idOpcao  = document.getElementById("opcoes2");
	 
	 ajax.open("POST", "../../__user/comum/cidades.php", true);
	 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 
	 ajax.onreadystatechange = function() {
		//enquanto estiver processando...emite a msg de carregando
		if(ajax.readyState == 1) {
		   idOpcao.innerHTML = "Carregando...!";   
		}
		//após ser processado - chama função processXML que vai varrer os dados
		if(ajax.readyState == 4 ) {
		   if(ajax.responseXML) {
			  processXMLCidadesDinamico(ajax.responseXML);
		   }
		   else {
			   //caso não seja um arquivo XML emite a mensagem abaixo
			   idOpcao.innerHTML = "--Primeiro selecione o estado--";
		   }
		}
	 }
	 //passa o código do estado escolhido
	 var params = "estado="+valor;
	 ajax.send(params);
  }
}

function processXMLCidadesDinamico(obj){
	var cidades = document.getElementById( 'idListaCidades2' );	
  //pega a tag cidade
  var dataArray   = obj.getElementsByTagName("cidade");
  
  //total de elementos contidos na tag cidade
  if(dataArray.length > 0) {
	 //percorre o arquivo XML paara extrair os dados
	 for(var i = 0 ; i < dataArray.length ; i++) {
		var item = dataArray[i];
		//contéudo dos campos no arquivo XML
		var codigo    =  item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
		var descricao =  item.getElementsByTagName("descricao")[0].firstChild.nodeValue;
		
		idOpcao.innerHTML = "--Selecione uma das op&ccedil;&otilde;es abaixo--";
		
		//cria um novo option dinamicamente  
		var novo = document.createElement("option");
			//atribui um ID a esse elemento
			novo.setAttribute("id", "opcoes");
			//atribui um valor
			novo.value = codigo;
			//atribui um texto
			novo.text  = descricao;
			//finalmente adiciona o novo elemento
			cidades.options.add(novo);
	 }
  }
  else {
	//caso o XML volte vazio, printa a mensagem abaixo
	idOpcao.innerHTML = "--Primeiro selecione o estado--";
  }	  
}

// DATA: 	24-02-2010
// EMAIL: 	alfredo@ecliente.com.br
function abrirPopUp( url )
{
	window.open( url, "IMPRIMIR", "height = 600, width = 800,resizable=yes,scrollbars=yes");	
}

// DATA: 	24-02-2010
// EMAIL: 	alfredo@ecliente.com.br
function visualizarEmailCadastro( theForm )
{
	theForm = document.getElementById( theForm );
		
	if (isBlank(theForm.nome))
	{
		alert("Preencha o nome do aluno");
		jQuery("input#nome").focus(); 
		return false; 
	}
	
	if(!isBlank(theForm.email)) 
	{
		if(!isMail(theForm.email)) 
		{
			alert("Formato de e-Mail incorreto");
      		jQuery("input#email").focus();
			return false;
		} 
	}
	else
	{
		alert("Preencha o e-Mail do aluno");
		jQuery("input#email").focus();
		return false;
	}
	
	if (isBlank(theForm.senha))
	{
		alert("Preencha a senha do aluno");
		jQuery("input#senha").focus(); 
		return false; 
	}
	
	if ( isBlank( theForm.idTextoCadastro ) )
	{
		alert("Preencha um texto");
		jQuery("textarea#idTextoCadastro").focus(); 
		return false; 
	}
	
	var nome = escape( theForm.nome.value );
	var email = escape( theForm.email.value );
	var senha = escape( theForm.senha.value );
	var texto = escape( theForm.idTextoCadastro.value );
	
	var parametros = "?resposta_ajax=1" + "&nome=" + nome + "&email=" + email +
					 "&senha=" + senha + "&texto=" + texto;
					 
	var url = '../../__user/classe/visualizarEmailCadastro.php' + parametros;
	
	abrirPopUp( url );
}

// DATA: 	24-02-2010
// EMAIL: 	alfredo@ecliente.com.br
function visualizarEmailConvite( theForm )
{
	var emails_novos = "";
	theForm = document.getElementById( theForm );	
		
	if(!isBlank(theForm.emails)) 
	{
		var emails = theForm.emails.value;
		var emails = emails.split( "," );
	
		for (var i = 0; i < emails.length; i++)
		{			
			var email = trim( emails[i] )
			
			if( !isMail2( email ) )
			{
				var num = i + 1;
				alert("O " + num + "º email está com formato incorreto:" + email );
				jQuery("input#emails").focus();
				return false;
			} 

			if ( ( i + 1 ) < emails.length )
				emails_novos += email + ",";
			else	
				emails_novos += email;			
		}
	}
	else
	{
		alert("Preencha algum e-Mail para enviar o convite!");
		jQuery("input#emails").focus();
		return false;
	}
	
	if ( isBlank( theForm.idTextoConvite ) )
	{
		alert("Preencha um texto");
		jQuery("textarea#idTextoConvite").focus(); 
		return false; 
	}		

	var emails_novos = escape( emails_novos );
	var texto = escape( theForm.idTextoConvite.value );
	
	var parametros = "?resposta_ajax=1" + "&emails=" + emails_novos + "&texto=" + texto;
	var url = '../../__user/classe/visualizarEmailConvite.php' + parametros;
	
	abrirPopUp( url );
}

// DATA: 	18-01-2010
// EMAIL: 	alfredo@ecliente.com.br
function ativarEnqueteMenuPrincipal( id, status )
{		
	var parametros = '?resposta_ajax=1' + '&ativar=1' +'&idPergunta=' +  id;
	
	if ( status == 'ativar' )
		parametros += "&status=1";
	else if ( status == 'desativar' )
		parametros += "&status=0";
	
	chamarAjax( 'ajaxCadastrarAlternativa', '../../__user/enquete/cadastrar_alternativa.php', parametros, false );
	chamarAjax( 'ajax_Menu_Enquete', '../../__user/enquete/menu_principal.php', '?resposta_ajax=1', false );
}


// DATA: 	24-02-2010
// EMAIL: 	alfredo@ecliente.com.br
function checkEnqueteAlterarAlternativa( theForm )
{
	
	theForm = document.getElementById( theForm );	
	
	if (isBlank(theForm.alternativa))
	{
		alert("Preencha a alternativa");
		jQuery("input#alternativa").focus(); 
		return false; 
	}	
	
	var alternativa = escape( theForm.alternativa.value );	
	var idAlternativa = theForm.idAlternativa.value 
	
	var parametros = '?resposta_ajax=1' + '&alternativa=' + alternativa + '&id=' + idAlternativa;
	
	chamarAjax( 'ajaxVisualizarVotos', '../../__user/enquete/visualizarVotos.php', parametros, false );
	chamarAjax( 'ajax_Menu_Enquete', '../../__user/enquete/menu_principal.php', '?resposta_ajax=1', false );
}


