// JavaScript Document
	
	function paginacao( _url , _pag , _start , _querystring ) {
		var _pars = 'pag=' + _pag + '&start=' + _start + '' + _querystring;
		self.location = _url + '?' + _pars;
	}
	

/* FUNÇÕES ADMIN */

	function FCKeditorIsEmpty( id ) {
		var FCKeditorInstance = FCKeditorAPI.GetInstance( id );
		if ( ( FCKeditorInstance.GetXHTML() == '' ) || ( FCKeditorInstance.GetXHTML() == '<br />' ) ) {
			return true;
		} else {
			return false;
		}
	}
	
	function sortIt( id ) {
		var $r = $( '#' + id + ' option' );
		$r.sort( function ( a, b ) {
			if ( a.text < b.text ) return -1;
			if ( a.text == b.text ) return 0;
			return 1;
		} );
		$( $r ).remove();
		$( '#' + id ).append( $( $r ) );
	}	
	
	function crossSelect( pFrom , pTo ) {
		$( '#'+pFrom ).children( 'option' ).each( function() {
			var $this = $( this );

			if ( ( $this.attr( 'selected' ) == true ) || ( $this.attr( 'selected' ) == 'selected' ) ) {

				$this.text( $this.text().trim() );
				$this.attr( 'title' , $this.attr( 'title' ).trim() );
				
				$( '#'+pTo ).append( $this );
			}
		} );
		
		$( '#'+pFrom ).html(
			$( '#'+pFrom+' option').sort( function( a , b ) {
				if  ( $( a ).text().trim() > $( b ).text().trim() ) { return 1 }
				else if  ( $( a ).text().trim() < $( b ).text().trim() ) { return -1 }
				else { return 0 }
			} )
		);
		
		$( '#'+pTo ).html(
			$( '#'+pTo+' option').sort( function( a , b ) {
				if  ( $( a ).text().trim() > $( b ).text().trim() ) { return 1 }
				else if  ( $( a ).text().trim() < $( b ).text().trim() ) { return -1 }
				else { return 0 }
			} )
		);
	}

	function transfereValor( pOrigem , pDestino ) {
		var aOrigem = new Array();
		
		$( '#'+pOrigem ).children( 'option' ).each( function() {
			var $this = $( this ).val();
			aOrigem.push( $this );
		} );

		$( '#'+pDestino ).val( aOrigem.join( ',' ) );
	}
/* FUNÇÕES ADMIN */

/* FUNÇÕES SITE */

// Header ------------------------------------------------------------------------------------------------------

	function selecionaSubcat( codigo ) {
		$( '#div_subcat' ).html( $( '#li_select_' + codigo ).html() );
		$( '#div_subcat' ).attr( 'title' , $( '#li_select_' + codigo ).html() );
		$( '#subcat' ).val( codigo );
		
		$( '.subitem' ).attr( 'class' , 'subitem' );
		
		if ( codigo != '0' ) {
			$( '#li_select_' + codigo ).attr( 'class' , 'subitem hover' );
		}
	}

	function buscaLista( palavra_chave , subcat ) {
		var pars	= '';
		
		if ( palavra_chave != '' ) { pars += '&palavra_chave=' + palavra_chave; }
		if ( subcat != '' ) { pars += '&subcat=' + subcat; }
		
		pars = pars.substring( 1 , pars.length );

		if ( pars != '' ) {
			self.location = url_busca + '?' + pars;
		}
	}

// Header ------------------------------------------------------------------------------------------------------

// Carrinho ------------------------------------------------------------------------------------------------------

	function fecharPedido( f , pagina ) {
		var url = url_loja;
		
		getId( f ).action = url + pagina;
		getId( f ).submit();
	}

	function alteraItem( codigo , tipo ) {
		self.location = url_loja + 'carrinho-adiciona.asp?codigo='+ codigo +'&tipo='+ tipo;
	}
	
	function entraSSL( f ) {
		f.action = url_ssl_loja + 'carrinho-passo-3-redireciona.asp';
		f.submit();
	}

	function saiSSL( f ) {
		f.action = url_loja + 'carrinho-final.asp';
		f.submit();
	}
	
	function imprimirBoleto( f ) {
		f.action = url_boleto_itau;
		f.submit();
	}
	
	function fechaPedidoFinal( f ) {
		if( !checou( f.cd_forma_pagamento ) ) {
			alert( "A forma de pagamento não foi selecionada." );
			f.cd_forma_pagamento[0].focus();
			return false;
		}
		
		f.action = 'carrinho-passo-3-envia.asp';		
		enviaDadosGeral( f );
	}
	
	function limpaDadosCartao() {
		$( '.tr_forma_pagamento' ).html( '' );
	}

// Carrinho ------------------------------------------------------------------------------------------------------

// Cadastro ------------------------------------------------------------------------------------------------------

	function enviaDadosCadastro( f ) {
		if( !checou( f.ic_tipo_cliente ) ) {
			alert( 'Selecione o tipo de cadastro (Pessoa Física ou Pessoa Jurídica).' );
			f.input_perfil[0].focus();
			return false;
		}
		
		if( !validaEmail( f.ds_email_cliente.value ) ) {
			alert( 'O campo E-mail não foi preenchido corretamente. (E-mail inválido)' );
			f.ds_email_cliente.focus();
			return false;
		}
		
		if ( f.ds_senha_cliente.length < 6 ) {
			alert( 'O campo Senha deve ter no mínimo 6 caracteres.' );
			f.ds_senha_cliente.focus();
			return false;
		}
		
		if ( f.ds_confirma_senha_cliente.value != f.ds_senha_cliente.value ) {
			alert( 'A confirmação da senha deve ser igual a senha escolhida.' );
			f.ds_confirma_senha_cliente.focus();
			return false;
		}
		
		if( f.ic_tipo_cliente[0].checked == true ) {
		
			if( !checou( f.ic_sexo_cliente ) ) {
				alert( 'O campo Sexo não foi selecionado.' );
				f.ic_sexo_cliente[0].focus();
				return false;
			}
			f.cd_cnpj_cliente.alt = '';
			f.cd_ie_cliente.alt = '';
			f.nm_fantasia_cliente.alt = '';
			f.cd_telefone1_cliente2.alt = '';
			f.nm_contato_cliente.alt = '';
			f.ds_email_contato_cliente.alt = '';
			f.cd_telefone_contato_cliente.alt = '';
		} else {
			if( !checou( f.ic_sexo_contato_cliente ) ) {
				alert( 'O campo Sexo do Contato não foi selecionado.' );
				f.ic_sexo_contato_cliente[0].focus();
				return false;
			}						
			f.cd_cpf_cliente.alt			= '';
			f.cd_telefone1_cliente.alt	= '';
		}
				
		enviaDadosGeral( f );
	}
	
	function alteraPerfil( tipo ) {
		var title = '';
		
		if ( tipo == 'cnpj' ) {
			$( '#cpf' ).css( 'display' , 'none' );
			$( '#cnpj' ).css( 'display' , '' );
			title = ' - Pessoa Jurídica';
		} else {
			$( '#cpf' ).css( 'display' , '' );
			$( '#cnpj' ).css( 'display' , 'none' );
			title = ' - Pessoa Física';
		}
		
		$( '#span_perfil' ).html( title );
	}
	
	function enviaDadosSenha( f ) {
		if ( f.ds_senha_cliente.value != f.ds_confirma_senha_cliente.value ) {
			alert( 'A confirmação da senha deve ser igual a senha escolhida.' );
			f.ds_senha_cliente_confirma.focus();
			return false;
		}
		
		enviaDadosGeral( f );
	}
	
	function abreUrlTracking( url ) {
		window.open( url , 'tracking' , '' );
	}

	function mostraDetalhes( pedido ) {
		if ( $( '#pedido' + pedido ).html() == '' ) {
			
			var pagina = '';
			var _type	= 'GET';
			
			var _url 		= url_loja + 'meus-pedidos-lista-ajax.asp';
			var _pars	= 'pedido=' + pedido;
			
			var requisicaoAjax = jQuery.ajax( {
				dataType: 'html',
				type: _type,
				data: _pars,
				url: _url,
				success: function( _retornoAjax ) {
					var htmlRetorno	= _retornoAjax;
					
					$( '.detalhes' ).html( '' );
					
					$( '#pedido' + pedido ).html( htmlRetorno );
				}
			} )
		} else {
			$( '.detalhes' ).html( '' );
		}
	}

// Cadastro ------------------------------------------------------------------------------------------------------

// Inscrição ------------------------------------------------------------------------------------------------------

	function enviaDadosInscricao( f ) {

	if (f.nm_inscricao.value != ''){
		if( !validaEmail( f.ds_email.value ) ) {
			alert( 'O campo E-mail não foi preenchido corretamente. (E-mail inválido)' );
			f.ds_email.focus();
			return false;
		}
	}
		
		enviaDadosGeral( f );
	}

// Inscrição ------------------------------------------------------------------------------------------------------

// Contato ------------------------------------------------------------------------------------------------------

	function enviaDadosContato( f, v ) {
		if ( ( f.departamento.value == '' ) || ( f.departamento.value == '0' ) ) {
			alert( 'O campo "Departamento" não foi selecionado.' );
			f.nm_contato_site.focus();
			return false;			
		}
		
		if( !validaEmail( f.ds_email.value ) ) {
			alert( 'O campo E-mail não foi preenchido corretamente. (E-mail inválido)' );
			f.ds_email.focus();
			return false;
		}
		if ( $( '#recaptcha_response_field' ).val().trim() == '' ) {
				$( '#recaptcha_response_field' ).focus();
				alert( 'O campo de verificação de palavras é obrigatório!' );
				e.preventDefault();
				return false;
		}				
		enviaDadosGeral( f );
	}

// Contato ------------------------------------------------------------------------------------------------------

// Formulário Pop up ------------------------------------------------------------------------------------------------------
	function enviaDadosContato2( f ) {
		if ( ( f.nm_contato_ligacao.value == '' ) ) {
			alert( 'O campo "Nome" não foi preenchido.' );
			f.nm_contato_ligacao.focus();
			return false;	
		}

		if ( ( f.ddd_contato_ligacao.value == '' ) ) {
			alert( 'O campo "DDD" não foi preenchido.' );
			f.ddd_contato_ligacao.focus();
			return false;			
		}

		if ( ( f.nr_contato_ligacao.value == '' ) ) {
			alert( 'O campo "Telefone" não foi preenchido.' );
			f.nr_contato_ligacao.focus();
			return false;			
		}
				
		enviaDadosGeral( f );
	}

// Formulário Pop up ------------------------------------------------------------------------------------------------------

// Geral ------------------------------------------------------------------------------------------------------

	function verificaCadastro( f , email_padrao , senha_padrao ) {
		
		if ( f.ds_email_cliente.value == email_padrao ) {
			alert( 'O campo E-mail não foi preenchido' );
			f.ds_email_cliente.focus();
			return false;
		}

		if ( f.ds_senha_cliente.value == senha_padrao ) {
			alert( 'O campo Senha não foi preenchido' );
			f.ds_senha_cliente.focus();
			return false;
		}
				
		f.action	= 'cliente-autentica.asp';
		enviaDadosGeral( f );
	}
	
	function criaCadastro( f ) {
		f.ds_email_cliente.alt	= '';
		f.ds_senha_cliente.alt	= '';
		f.action	= 'cadastro.asp';
		f.submit();
	}
	
// Geral ------------------------------------------------------------------------------------------------------	
	
/* FUNÇÕES SITE */
