	function ajaxLoader( _id ) {
		$( '#'+_id ).html( ajax_loader );
	}
	
	function ajaxSuccess( _id ) {
		$( '#'+_id ).html( ajax_success );
	}
	
/* Funções Admin */	

// Instituicoes ------------------------------------------------------------------------------------------------------
	function aprovarInstituicaoAjax( id , codigo ) {
		var opcao = '0';
		
		if ( $( '#'+id ).is( ':checked' ) ) { opcao = '1'; }
		
		var _type	= 'GET';
		var _url 	= 'instituicao-truckids-status-atualizar.asp';
		var _pars	= 'id=' + codigo + '&opcao=' + opcao;
		
		ajaxLoader( 'carregando' );
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				ajaxSuccess( 'carregando' );
				setTimeout( function(){ $( '#carregando' ).html( '' ) } , 3000 );
			}
		} );
	}
// Instituicoes ------------------------------------------------------------------------------------------------------

// Imprensa ------------------------------------------------------------------------------------------------------
	function aprovarCredenciamentoAjax( id , codigo ) {
		var opcao = '0';
		
		if ( $( '#'+id ).is( ':checked' ) ) { opcao = '1'; }
		
		var _type	= 'GET';
		var _url 	= 'credenciamento-status-atualizar.asp';
		var _pars	= 'id=' + codigo + '&opcao=' + opcao;
		
		ajaxLoader( 'carregando' );
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				ajaxSuccess( 'carregando' );
				setTimeout( function(){ $( '#carregando' ).html( '' ) } , 3000 );
			}
		} );
	}
// Imprensa ------------------------------------------------------------------------------------------------------

// Notícia -----------------------------------------------------------------------------------------------
	function carregaComentario( noticia , truckids ) {
		var _type	= 'GET';
		var _url 	= 'comentario-lista.asp';
		var _pars	= 'noticia=' + noticia +'&truckids='+ truckids;
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				var htmlRetorno = _retornoAjax;
				$( '#comentarios' ).html( htmlRetorno ) ;
			}
		} );
	}
	
	function aprovarComentarioAjax( id , codigo , truckids ) {
		var opcao = '0';
		
		if ( $( '#'+id ).is( ':checked' ) ) { opcao = '1'; }
		
		var _type	= 'GET';
		var _url 	= 'comentario-status-atualizar.asp';
		var _pars	= 'id=' + codigo + '&opcao=' + opcao + '&truckids=' + truckids;
		
		ajaxLoader( 'carregando' );
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				ajaxSuccess( 'carregando' );
				setTimeout( function(){ $( '#carregando' ).html( '' ) } , 3000 );
			}
		} );
	}
// Notícia -----------------------------------------------------------------------------------------------

// Classificacao -----------------------------------------------------------------------------------------------	
	function carregaClassificacao( temporada , campeonato , origem ) {
		var _anchor = document.URL.split( '#' );
		var _type	= 'GET';
		var _url 	= 'classificacao-tabela.asp';
		var _pars	= 'temporada=' + temporada +'&campeonato='+ campeonato;
		var id		= '';
		
		if ( origem == 'home' ) {
			_url = 'classificacao-tabela-home.asp';
		} else {
			id = '-'+ temporada +'-'+ campeonato;
		}

		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				var htmlRetorno = _retornoAjax;
				if ( htmlRetorno != '' ) {
					if ( origem == 'home' ) {
						$( '.aba .active' ).removeAttr( 'class' );
						$( '#'+ campeonato ).attr( 'class' , 'active' );
						
						$( '#classificacao' + id ).fadeOut( 'slow' , function(){
							$( '#classificacao' + id ).html( htmlRetorno );
							$( '#classificacao' + id ).fadeIn( 'slow' , function(){} )
						} );
					} else {
						$( '#classificacao' + id ).html( htmlRetorno );

						if ( _anchor[ 1 ] == 'marcas' ) {
							$( 'html , body' ).animate( {
								scrollTop: $( '#titulo-' + temporada + '-' + campeonato  ).offset().top
							} , 500 );
						}
					}
				}
			}
		} );
	}
// Classificacao -----------------------------------------------------------------------------------------------

// News ------------------------------------------------------------------------------------------------------
	function buscarProduto( codigo ) {
		var _type	= 'GET';
		var _url 		= 'produto-lista-detalhe.asp';
		var _pars	= 'id=' + codigo;
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				var htmlRetorno = _retornoAjax;
				if ( htmlRetorno != '' ) {
					$( '#lista' ).html( $( '#lista' ).html() + htmlRetorno ) ;
				}
			}
		} );
	}
// News ------------------------------------------------------------------------------------------------------

// Cadastro ------------------------------------------------------------------------------------------------------
	function alterarStatusAjax( id , codigo , campo ) {
		var opcao = '0';
		
		if ( $( '#'+id ).is( ':checked' ) ) { opcao = '1'; }
		
		var _type	= 'GET';
		var _url 	= 'cliente-status-atualizar.asp';
		var _pars	= 'id=' + codigo + '&opcao=' + opcao +'&campo=' + campo;
		
		ajaxLoader( 'carregando' );
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				ajaxSuccess( 'carregando' );
				setTimeout( function(){ $( '#carregando' ).html( '' ) } , 3000 );
			}
		} );
	}
// Cadastro ------------------------------------------------------------------------------------------------------

// Produtos	------------------------------------------------------------------------------------------------------
	
	function alteraStatusAtributoProduto( codigo , opcao , tipo ) {
		
		if ( !opcao ) {
			opcao = '0';
		} else {
			opcao = '1';
		}
				
		var _type	= 'GET';
		var _url 	= 'estoque-cor-status-atualizar.asp';
		var _pars	= 'codigo=' + codigo + '&opcao=' + opcao;

		ajaxLoader( 'carregando' );
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				ajaxSuccess( 'carregando' );
				setTimeout( function(){ $( '#carregando' ).html( '' ) } , 3000 );
			}
		} );		
	}
	
	function alteraQtdMinimaAviso( codigo , qtd , tipo ) {
		var _type	= 'GET';
		var _url 	= 'estoque-cor-aviso-atualizar.asp';
		var _pars	= 'codigo=' + codigo + '&qtd=' + qtd;
		
		ajaxLoader( 'carregando' );
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				ajaxSuccess( 'carregando' );
				setTimeout( function(){ $( '#carregando' ).html( '' ) } , 3000 );
			}
		} );
	}
	
	function alteraEstoqueAtual( codigo , qtd , tipo ) {
		var _type	= 'GET';
		var _url 	= 'estoque-cor-atualizar.asp';
		var _pars	= 'codigo=' + codigo + '&qtd=' + qtd;
		
		ajaxLoader( 'carregando' );
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				
				var htmlRetorno = _retornoAjax;
				
				htmlRetorno = htmlRetorno.split( '|' )
				$( '#atual_' + htmlRetorno[0] ).html( htmlRetorno[1] );
				
				ajaxSuccess( 'carregando' );
				setTimeout( function(){ $( '#carregando' ).html( '' ) } , 3000 );
			}
		} );
	}

	function alteraProdutoHomeAjax( id , codigo ) {
		var _type	= 'GET';
		var _url 	= 'produto-home-atualizar.asp';
		var _pars	= 'codigo=' + codigo + '&ordem=' + $( '#' + id ).val();
		
		ajaxLoader( 'carregando' );
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'xml',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				var xmlRetorno = _retornoAjax;
				var cd_produto			= null;
				var cd_ordem_produto	= null;
				
				$(xmlRetorno).find( 'registro' ).each( function() {
					cd_produto				= $( this ).find( 'cd_produto' ).text();
					cd_ordem_produto	= $( this ).find( 'cd_ordem_produto' ).text();
					
					if ( $( '#cd_ordem_produto' + cd_produto ).length > 0 ) {
						$( '#cd_ordem_produto' + cd_produto ).val( cd_ordem_produto );
					}
					
					ajaxSuccess( 'carregando' );
					setTimeout( function(){ $( '#carregando' ).html( '' ) } , 3000 );
				} );
			}
		} );
	}
	
	function mostraProdutoAjax( id , codigo ) {
		var opcao = '0';
		
		if ( $( '#'+id ).is( ':checked' ) ) { opcao = '1'; }
		
		var _type	= 'GET';
		var _url 		= 'produto-mostra-atualizar.asp';
		var _pars	= 'codigo=' + codigo + '&opcao=' + opcao;
		
		ajaxLoader( 'carregando' );
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				ajaxSuccess( 'carregando' );
				setTimeout( function(){ $( '#carregando' ).html( '' ) } , 3000 );
			}
		} );
	}
	
	function mostraProdutoInstitucionalAjax( id , codigo ) {
		var opcao = '0';
		
		if ( $( '#'+id ).is( ':checked' ) ) { opcao = '1'; }
		
		var _type	= 'GET';
		var _url 		= 'produto-institucional-mostra-atualizar.asp';
		var _pars	= 'codigo=' + codigo + '&opcao=' + opcao;
		
		ajaxLoader( 'carregando' );
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				ajaxSuccess( 'carregando' );
				setTimeout( function(){ $( '#carregando' ).html( '' ) } , 3000 );
			}
		} );
	}
	
	function alteraOrdemImagemAjax( id , codigo ) {
		var _type	= 'GET';
		var _url 		= 'produto-foto-ordem-atualizar.asp';
		var _pars	= 'codigo=' + codigo + '&ordem=' + $( '#'+id ).val();
		
		ajaxLoader( 'carregando' );
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'xml',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				var xmlRetorno = _retornoAjax;
				var cd_produto			= null;
				var cd_ordem_produto	= null;
				
				$( xmlRetorno ).find( 'registro' ).each( function() {
					cd_imagem_produto				= $(this).find( 'cd_imagem_produto' ).text();
					cd_ordem_imagem_produto	= $(this).find( 'cd_ordem_imagem_produto' ).text();
					
					if ( $( '#cd_ordem_imagem_produto_' + cd_imagem_produto ).length > 0 ) {
						$( '#cd_ordem_imagem_produto_' + cd_imagem_produto ).val( cd_ordem_imagem_produto );
					}
					
					ajaxSuccess( 'carregando' );
					setTimeout( function(){ $( '#carregando' ).html( '' ) } , 3000 );
				} );
			}
		} );
	}
	
	function destacaImagemAjax( id , codigo ) {
		var _type	= 'GET';
		var _url 		= 'produto-foto-destaca-atualizar.asp';
		var _pars	= 'codigo=' + codigo;
		
		ajaxLoader( 'carregando' );
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				ajaxSuccess( 'carregando' );
				setTimeout( function(){ $( '#carregando' ).html( '' ) } , 3000 );
			}
		} );
	}
	
	function carregaFotos( id , codigo ) {
		var _type	= 'GET';
		var _url 		= 'produto-foto-lista.asp';
		var _pars	= 'codigo=' + codigo;
		
		ajaxLoader( 'carregando' );
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				$( '#' + id ).html( _retornoAjax );
				ajaxSuccess( 'carregando' );
				setTimeout( function(){ $( '#carregando' ).html( '' ) } , 3000 );
			}
		} );
	}
	
// Produtos	------------------------------------------------------------------------------------------------------

// Frete ------------------------------------------------------------------------------------------------------

	function atualizaValorAjax( codigo , valor , tipo ) {
		$( '#cd_frete_' + codigo ).attr( 'class' , 'loading' );
		
		var pagina = '';
		var _type	= 'GET';
		
		var _url 		= 'frete-tabela-atualizar.asp';
		var _pars	= 'codigo=' + codigo + '&valor=' + valor + '&tipo=' + tipo;
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'xml',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				var xmlRetorno	= _retornoAjax;
				var cd_frete		= null;
				
				$( xmlRetorno ).find( 'registro' ).each( function() {
					cd_frete	= $( this ).find( 'cd_frete' ).text();
					$( '#cd_frete_' + cd_frete ).removeAttr( 'class' );
				} );
			}
		} );
	}
	
// Frete ------------------------------------------------------------------------------------------------------

/* Funções Admin */	

/* Funções Site */

// Carrinho ------------------------------------------------------------------------------------------------------
	
	function calculaCarrinho() {
		var envio	= $( '#input_forma_envio' ).val();
		var cep		= $( '#input_cep' ).val();
		
		if ( envio == '' ) { envio = '0'; }
		if ( cep == '' ) { cep = '0'; }
		
		var pagina	= '';
		var _type	= 'GET';
		
		var _url 	= 'carrinho-total-ajax.asp';
		var _pars	= 'envio=' + envio + '&cep=' + cep;
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				var htmlRetorno		= _retornoAjax;
				var valor_subtotal	= null;
				var valor_total		= null;
				var valor_frete		= null;
				
				htmlRetorno = htmlRetorno.split( '[#]' );
				
				valor_subtotal	= htmlRetorno[0];
				valor_frete		= htmlRetorno[1];
				valor_total		= htmlRetorno[2];
				
				$( '#input_valor_subtotal' ).val( valor_subtotal );
				$( '#input_valor_frete' ).val( valor_frete );
				$( '#input_valor_total' ).val( valor_total );
				
				$( '#strong_valor_subtotal' ).html( 'R$ ' + valor_subtotal );
				$( '#strong_valor_frete' ).html( 'R$ ' + valor_frete );
				$( '#strong_valor_total' ).html( 'R$ ' + valor_total );
			}
		} );
	}
	
	function alteraQtd( codigo , tipo ) {
		var qtd = $( '#input_qtd_' + codigo ).val();
		
		if ( qtd == '' ) { qtd = 1; }
		
		if ( tipo == '-' ) {
			tipo = 'menos';
		} else {
			if ( tipo == '+' ) {
				tipo = 'mais';
			} else {
				tipo = '';
			}
		}

		var pagina	= '';
		
		var _type	= 'GET';
		var _url 	= 'carrinho-quantidade-ajax.asp';
		var _pars	= 'codigo=' + codigo + '&tipo=' + tipo + '&qtd=' + qtd;
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				var htmlRetorno	= _retornoAjax;
				var cd_produto	= null;
				var qt_produto	= null;
				var vl_produto	= null;
				
				htmlRetorno = htmlRetorno.split( '[#]' );
				
				cd_produto			= htmlRetorno[0];
				qt_produto			= htmlRetorno[1];
				vl_unitario_produto	= htmlRetorno[2];
				vl_total_produto	= htmlRetorno[3];
				
				$( '#input_qtd_' + cd_produto ).val( qt_produto );
				$( '#input_valor_' + cd_produto ).val( vl_produto );
				
				$( '#strong_valor_unitario_' + cd_produto ).html( 'R$ ' + vl_unitario_produto );
				$( '#strong_valor_total_' + cd_produto ).html( 'R$ ' + vl_total_produto );
				
				calculaCarrinho();
			}
		} );
	}
	
	function calculaFrete( cep ) {
		var pagina = '';
		var _type	= 'GET';
		
		var _url 		= 'carrinho-frete-ajax.asp';
		var _pars	= 'cep=' + cep;
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				var htmlRetorno	= _retornoAjax;
				var cd_produto	= null;
				var qt_produto	= null;
				var vl_produto		= null;
				
				$( '#div_frete' ).css( 'display' , '' );
				$( '#div_frete' ).html( htmlRetorno );
			}
		} );
	}
	
	function retornaDadosCartao( codigo ) {
		var pagina = '';
		var _type	= 'GET';
		
		var _url 		= 'carrinho-dados-cartao-ajax.asp';
		var _pars	= 'codigo=' + codigo;
		
		var requisicaoAjax = jQuery.ajax( {
			dataType: 'html',
			type: _type,
			data: _pars,
			url: _url,
			success: function( _retornoAjax ) {
				var htmlRetorno	= _retornoAjax;
				$( '.tr_forma_pagamento' ).html( '' );
				$( '#tr_forma_pagamento_' + codigo ).html( htmlRetorno );
			}
		} );
	}

// Carrinho ------------------------------------------------------------------------------------------------------

// Cadastro ------------------------------------------------------------------------------------------------------

	function buscaCidade( estado , cidade ) {
		if ( ( estado != '' ) && ( estado != '0' ) ) {
			
			ajaxLoader( 'carregando' );
			
			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;
					
					$( '#carregando' ).html( '' );
					
					$( 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>';
					} );
				
					$( '#cd_cidade' ).html( myOptions );
					$( '#cd_estado' ).val( estado );
					
					if ( ( cidade != '' ) && ( cidade != '0' ) ) {
						$( '#cd_cidade' ).val( cidade );
					}
				}
			} );
		}
	}
	
	function buscaCep( cep ) {
		
		$( '#carregando' ).html( '' );
		
		if ( cep.length >= 9 ) {
			ajaxLoader( 'carregando' );
			
			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;

					$( '#carregando' ).html( '' );
					
					$( 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();
						
						$( '#ds_cliente_endereco' ).val( endereco );
						$( '#nm_bairro_cliente_endereco' ).val( bairro );
						$( '#cd_numero_cliente_endereco' ).focus();

						buscaCidade( estado , cidade );
					} );
				}
			} );
		}
	}

// Cadastro ------------------------------------------------------------------------------------------------------
