﻿	function ajaxLoader( _id ) {
		$( '#'+_id ).html( ajax_loader );
	}
	
	function ajaxSuccess( _id ) {
		$( '#'+_id ).html( ajax_success );
	}
	
/* Funções Admin */
	
// Cadastro ------------------------------------------------------------------------------------------------------	
	function liberaInscricaoAjax( id , codigo ) {
		var opcao = '0';
		
		if ( $( '#'+id ).is( ':checked' ) ) { opcao = '1'; }
		
		var _type	= 'GET';
		var _url 	= 'inscricao-status-atualizar-ajax.asp';
		var _pars	= 'codigo=' + codigo + '&opcao=' + opcao;
		
		ajaxLoader( 'carregando' );
		
		if ( !confirm( 'Deseja confirmar esta inscrição?' ) ) {
			$( '#carregando' ).html( '' );
			return false;
		}
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				ajaxSuccess( 'carregando' );
				setTimeout( function(){ $( '#carregando' ).html( '' ) } , 3000 );
			}
		} );
	}
	
/* Funções Site */

// Cadastro ------------------------------------------------------------------------------------------------------

	function buscaCidade( estado , cidade ) {
		if ( ( estado != '' ) && ( estado != '0' ) ) {
			
			var _type	= 'GET';
			var _url 		= 'cadastro-cidade-ajax.asp';
			var _pars	= 'estado=' + estado;
			
			var requisicaoAjax = jQuery.ajax( {
				dataType: 'xml',
				type: _type,
				data: _pars,
				url: _url,
				success: function( _retornoAjax ) {
					var xmlRetorno	= _retornoAjax;
					var myOptions		= null;
					var cd_cidade		= null;
					var nm_cidade		= null;
					
					myOptions += '<option value="0" title="- SELECIONE -">- SELECIONE -</option>';
					
					$( xmlRetorno ).find( 'registro' ).each( function() {
						
						cd_cidade = $( this ).find( 'cd_cidade' ).text();
						nm_cidade = $( this ).find( 'nm_cidade' ).text();
						
						myOptions += '<option value="'+ cd_cidade +'" title="'+ nm_cidade +'">'+ nm_cidade +'</option>';
					} );
				
					$( '#cidade' ).html( myOptions );
					$( '#estado' ).val( estado );
					
					if ( ( cidade != '' ) && ( cidade != '0' ) ) {
						$( '#cidade' ).val( cidade );
					}
				}
			} );
		}
	}
	
	function buscaCep( cep ) {
		if ( cep.length >= 8 ) {
			
			var _type	= 'GET';
			var _url 		= 'cadastro-cep-ajax.asp';
			var _pars	= 'cep=' + cep;

			var requisicaoAjax = jQuery.ajax( {
				dataType: 'xml',
				type: _type,
				data: _pars,
				url: _url,
				success: function( _retornoAjax ) {
					var xmlRetorno = _retornoAjax;
					
					$( xmlRetorno ).find( 'registro' ).each( function() {
						
						var endereco	= $( this ).find( 'endereco' ).text();
						var bairro		= $( this ).find( 'bairro' ).text();
						var cidade		= $( this ).find( 'cidade' ).text();
						var estado		= $( this ).find( 'estado' ).text();
						
						$( '#endereco' ).val( endereco );
						$( '#bairro' ).val( bairro );
						$( '#numero' ).focus();

						buscaCidade( estado , cidade );
					} );
				}
			} );
		}
	}

// Cadastro ------------------------------------------------------------------------------------------------------
