/**
 *
 * Copyright (c) 2007 Tom Deater (http://www.tomdeater.com)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */
 
(function($) {
	/**
	 * equalizes the heights of all elements in a jQuery collection
	 * thanks to John Resig for optimizing this!
	 * usage: $("#col1, #col2, #col3").equalizeCols();
	 */
	 
	$.fn.equalizeCols = function(){
		var height = 0;
  
		return this
			.css("height", "auto")
			.each(function() {
				height = Math.max(height, this.offsetHeight);
			})
			.css("height", height)
			.each(function() {
				var h = this.offsetHeight;
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});
			
	};
	
})(jQuery);

function ipt_normal(obj){
	$(obj).css('border','1px solid #000');
}

function select_first(obj){
	obj=$(obj).children().eq(0);
	$(obj).attr('selected','selected');
	
}
function valida_item_zoom(txt,id){
	if($.trim(txt)==''){
		$('#'+id).prev().hide();
		$('#'+id).hide();
		$('#'+id).next('br').hide();
	}else{
		$('#'+id).text($.trim(txt)); // insere o texto na div
		$('#'+id).prev().show();
		$('#'+id).show();
		$('#'+id).next('br').show();	
	}
}
/*=======================================================================*/
function baixar_acao(){
	$('.boxFoto').each(function(){
		var boxFoto = $(this).height()||0;
		var boxFotoItem  = $(this).find('.boxFotoItem').height()||0;
		var boxFotoData  = $(this).find('.boxFotoData').height()||0;
		var boxFotoAcao	 = $(this).find('.boxFotoAcao').height()||0;
		var boxPautaAcao = $(this).find('.boxPautaAcao').height()||0;
		var boxPautaItem = $(this).find('.boxPautaItem').height()||0;
		var hright_titulo= (boxFoto-boxFotoItem-boxFotoData-boxFotoAcao-boxPautaAcao-boxPautaItem)-20;
		if(hright_titulo>=0)
			$(this).find('.boxFotoTitulo').css({'height':hright_titulo+"px"});		
	});
}

function linksZoom(tag,xml,param){
	var txt=new String();
	var ct=1; 
	var array= new Array();
	$(tag,xml).each(function(){
			if($.trim($(tag,xml).text())!=''){
				if(ct==$(tag,xml).size()){
					param="";
				}
				if(tag=='editorias'){
					array = $(this).text().split('|');
					txt+='<a href="'+array[0]+'">'+array[1]+'</a>'+param+'\n';
				}else if(tag=='palavraChave'){
					txt+='<a href="javascript:void(0);" class="pcZoom">'+$(this).text()+'</a>'+param+'\n';
				}else if(tag=='pauta'){
					array = $(this).text().split('||');
					txt+='<a href="'+array[1]+'">'+array[0]+'</a>'+param+'\n';
				}
				ct++;
			}
	});
	
	return txt;
}
/*==================================== BUSCA CEP =================================================*/
function busca_cep(str, end, bairro){
	$(end).val('carregando...');
	$(bairro).val('carregando...');
	$.ajax({
		url: GP5.dirBase+'_ajax/cep.php',
		type: 'post',
		dataType:'xml',
		data: {cep: $.trim(str)},
		error: function(){
			$(bairro).val('');
			$(end).val('').focus();
			
		},
		success: function(xml){
			$(end).val( $('tp_logradouro',xml).text()+' '+$('logradouro',xml).text());
			$(bairro).val( $('bairro',xml).text());
		}
	});

}
/*================================================================================================*/
function excluir_dados_contato(obj,dados, param){
	
	$(obj).parent().parent().css('background-color','#FFF3E9');
	$.ajax({
		url: GP5.dirBase+'_ajax/cadastro/gerenciarContatos.php',
		type: 'post',
		dataType:'txt',
		data: {idItem: $.trim(dados), acao:param},
		error: function(){
			alert('Ocorreu um problema, entre em contato com o setor de informática!');
			return false;
		},
		success: function(text){
			$(obj).parent().parent().css('background-color','#FFF');
			$(obj).parent().parent().remove();
		}
	});
}
/*------------------------------------------------------------------------------------------------*/
/*================================================================================================*/
function excluir_usuario(obj,dados, param){
	$(obj).parent().parent().css('background-color','#FFF3E9');
	$.ajax({
		url: GP5.dirBase+'_ajax/cadastro/gerenciarUsuarios.php',
		type: 'post',
		dataType:'txt',
		data: {idUsuario: $.trim(dados), acao:param},
		error: function(){
			alert('Ocorreu um problema, entre em contato com o setor de informática!');
			return false;
		},
		success: function(text){
			if(text==0){
				alert('Ocorreu um problema, entre em contato com o setor de informática!');
				return false;
			}
			$(obj).parent().parent().css('background-color','#FFF');
			$(obj).parent().parent().remove();
		}
	});
}

function login(tp){
	$('#lErro_1,#lErro_2,#lErro_3,#lErro_4').hide();
	$('#ipt_cpf').css('border', '1px solid #000') ;
	//if (isCpfCnpj($('#ipt_cpf').val()) && $('#ipt_cpf').val().length==11 ){
	//if (isCpfCnpj($('#ipt_cpf').val())){
	if ($('#ipt_cpf').val()!=""){
		
		$.post(	GP5.dirBase+'login'+tp+'.php',  
				{cpf: $('#ipt_cpf').val(), senha: $('#ipt_senha').val()},
				function(response){   
					if(response==5){
						window.location=GP5.redir;
					}
					$('#lErro_'+response).show();							
					
				}
			)
	}else{
		$('#ipt_cpf').css('border', '1px solid #FF0000') ;
	}	
}

function logout(tp){
	$.ajax({
			url: GP5.dirBase+'logout'+tp+'.php',
			type: 'GET',
			error: function(){
				alert("Ocorreu um problema no sistema! Por favor entre em contato com o setor de informática!");
			},
			success: function(){
				tp=='Usuario' ? tp='usuarios' : tp='cadastro';
				window.location=GP5.dirBase+tp+'/meusdados/';
			}
	});	
}
/*------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------*/
$(document).ready( function()
	{
		
			
		/* solução para o carregamento com cache do smarty   */	
		$(window).load(function () {
      		$('.boxFoto, #acervo .boxModeloPequeno').equalizeCols();
			$('#home .boxModeloPequeno').equalizeCols();
			baixar_acao();
						
			if(GP5.local[0]=='cadastro' && GP5.local[1]=='meusdados' && GP5.download!=''){
				window.location=GP5.download;	
			}			
			
			//===========================================================
			$('#faixa_baixo_box').clipregion2({
				'itemHeight':90,
				'itemWidth' :95,
				'totalItems':$('ul > li',$('#faixa_baixo_box')).size(),
				'itemsToShow':Math.round($('#faixa_baixo').width()/110),
				'itemStep':false
			});
			$('#geBtNext').click(function(){ 
				
				$.clipregion2.next();
			});
			$('#geBtPrev').click(function(){
									  
				$.clipregion2.prev();
			});
			//===========================================================
			//===========================================================
			$('.mesa_foto').hover(
				function(){ 
					$(this).css('background-color','#FFF'); 
				},
				function(){
					$(this).css('background-color','#CCC'); 	
				}
			);
			
	   	});// FIM LOAD
		
	
		
		$('#bt_noticiasRetorno').click(function(){
			$('#frm_buscaNoticias').submit();
		});
		
		$('.lk_eng').click( function()
			{ 
				var aux = window.location.href.split('/');
				if(aux[aux.length-2]=='contato'){
					window.location.href=window.location.href+'eng/';
				}else{
					$('#portugues, .portugues').hide('fast'); 
					$('#ingles, .ingles').show('fast');  
				}
				
			}
		);
		$('.lk_pt').click( function()
			{ 
				var aux = window.location.href.split('/');
				aux.splice(aux.length-2,1)
				if(aux[aux.length-2]=='contato'){
					window.location.href=aux.join('/');
				}else{
					$('#ingles, .ingles').hide('fast'); 
					$('#portugues, .portugues').show('fast');
				}
			}
		);
		
	  /*------------------------------------------------------------------*/
/* --------------------------- LOGIN CLIENTE----------------------------------------------*/	
	$('input#entrarCliente').click(function(){	
		// validacao de cpf do douglas
			login('Cliente');
	});
/* --------------------------- LOGIN CLIENTE----------------------------------------------*/	
	$('input#entrarUsuario').click(function(){	
		// validacao de cpf do douglas
			login('Usuario');
	});
/* FIM LOGIN ------------------------------------------------------------------------------*/	
	  
/*--------------------------------------------------------------------------------------------*/
/*-------------------- LOGOUT do sistema por ajax---------------------------------------------*/	
	$('#bt_logoutCliente').click(function(){	
		logout('Cliente');
	});
	$('#bt_logoutUsuario').click(function(){	
		logout('Usuario');
	});
	
/*-- FIM ajax logout -----------------------------------------------------------------------*/	
/*------------------- seleciona cadastrar email --------------------------------------------*/
    $('#bt_cad').click(function(){	
		$('#boletimAcao').val(1);
		$(this).css({backgroundColor: "#CCC"});
		$('#bt_descad').css({backgroundColor: "#EAEAEA"});
	});
	
/*-------------------------------------------------------------------------------------------*/
/*-------------------- seleciona descadastrar email -----------------------------------------*/
	  $('#bt_descad').click(
			function() 
			{
				$('#boletimAcao').val(0);
				$(this).css({backgroundColor: "#CCC"});
				$('#bt_cad').css('background-color',"#EAEAEA");
			}
	  );
/*-------------------------------------------------------------------------------------------*/
/*-------------------- trata eventos no campo de email do boletim ---------------------------*/	 
	$('#emailBoletim').focus(function(){ 
		$(this).val(' ');
	});
	  
	$('#emailBoletim').blur(function(){
		if($(this).val=='') {
			$(this).val('(seu e-mail)');	
		}
	});

/*-------------------------------------------------------------------------------------------*/
/*-------------------- envia e valida o cadastro de email para boletim- ---------------------*/	 	
	$('#submit_email').click(function() 
			{	$('#email_msg').text('');
				if(!validaEmail($.trim($('#emailBoletim').val()))){
					$('#emailBoletim').css('border','1px solid #FF9900');
					$('#email_msg').css('color','#FF9900');
					
					window.setTimeout("ipt_normal($('#emailBoletim'))",2000);
					$('#emailBoletim').focus();
					return false;
				}
				$('#email_msg').html('<img src="'+GP5.dirBase+'imagens/ajax-loader4.gif" alt="load" />');
				$.ajax({
						url: GP5.dirBase+'_ajax/boletim.php',
						type: 'post',
						data: {email:$('#emailBoletim').val(), acao:$('#boletimAcao').val() },
						error: function(){
							alert('Ocorreu um problema, entre em contato com o setor de informática!');
							return false;
						},
						success: function(r){ // RESPOSTA NO MENU
							if(r==1){
								$('#email_msg').css('color','#FF9900');
								$('#emailBoletim').css('border','1px solid #FF9900');
								$('#email_msg').text('E-mail já cadastrado!');
							}else if(r==2||r==3){
								$('#email_msg').css('color','#006600');
								$('#emailBoletim').css('border','1px solid #006600');
								$('#email_msg').text('E-mail cadastrado com sucesso!');
								$('#emailBoletim').val('');
							}else if(r==4){
								$('#email_msg').css('color','#006600');
								$('#emailBoletim').css('border','1px solid #006600');
								$('#email_msg').text('E-mail descadastrado!');
								$('#emailBoletim').val('');
							}else if(r==5){
								$('#email_msg').css('color','#FF9900');
								$('#emailBoletim').css('border','1px solid #FF9900');
								$('#email_msg').text('E-mail já descadastrado!');
							}
							
							
						}		
					});
			}
	);

/*-------------------------------------------------------------------------------------------*/
/*-------------------- carrega os detalhes da foto na galeria do editor ---------------------*/		  
	  $(".mesa_foto").click(function()
			{	var obj=$(this);
				$('#geFoto').css({marginTop:'100px'});
				$('#geFoto').attr('src',GP5.dirBase+'imagens/ajax-loader.gif');
				$.ajax({
						url: GP5.dirBase+'_ajax/galeriadoeditor.php',
						type: 'post',
						dataType:'xml',
						data: {idFoto:$(obj).attr('id')},
						error: function(){
							alert('Ocorreu um problema, entre em contato com o setor de informática!');
							return false;
						},
						success: function(xml){
								$('#geFoto').css({marginTop:'0px'});
								$('#geFoto').attr('src', $('imgSRC', xml).text());
								$('#geFoto').attr('title', $('imgTitle', xml).text());
								$('#geTitulo').text($('titulo', xml).text());
								$('#geLegenda').text($('legenda', xml).text());
								if($.trim($('fotografo', xml).text())){
									$('#geCredito').text($('fotografo', xml).text()+" / "+$('agenciaNome', xml).text());
								}else{
									$('#geCredito').text($('agenciaNome', xml).text());
								}
						}
					});
			}
	  );
	
	
	

/*===========================================================================================*/

/*-------------------------------------------------------------------------------------------*/
/*-------------------- CARREGAR o ESTADO assim que o país é selecionado ----------------------*/	
	$('#slc_pais').change(function(){
		$('#slc_estado').children().slice(1).remove();
		$('#slc_cidade').children().slice(1).remove();
		var tp = 'estados';
		var auxEspecial = '';
		var obj = $(this);
		if(GP5.local=='busca'){
			auxEspecial= 'busca';
		}
		if(obj.val()!=1){
			$('.regCidade_1').hide();
			$('.regCidade_2').show();
			$('#slc_estado,#ipt_cep1,#ipt_cep2,#slc_cidade').attr({disabled:true}).val('');
			$('#ipt_cidade').attr({disabled:false});
			
			if(GP5.local=='busca'){
				tp = 'cidades';
				$('#slc_cidade').attr({disabled:false});
				$('<img src="'+GP5.dirBase+'imagens/ajax[select].gif" alt="load" />').insertAfter('#slc_cidade');
				$('#slc_cidade').next().css('margin-left','4px');
			}
		}else{
			$('.regCidade_1').show();
			$('.regCidade_2').hide();
			$('#slc_estado,#ipt_cep1,#ipt_cep2,#slc_cidade').attr({disabled:false}).val('');
			$('<img src="'+GP5.dirBase+'imagens/ajax[select].gif" alt="load" />').insertAfter('#slc_estado');
			$('#slc_estado').next().css('margin-left','4px');
			//$('#slc_estado').next().css('float','left');
		}
		$.ajax({
			url: GP5.dirBase+'_ajax/regiao.php',
			type: 'post',
			dataType:'xml',
			data: {idPais:obj.val(), tipo:tp, especial:auxEspecial },
			error: function(){
				alert('Ocorreu um problema, entre em contato com o setor de informática!');
			},
			success: function(xml){
				
				$('item',xml).each(function(){
					if(tp=='cidades'){
						$("#slc_cidade").append("<option value='"+$('codigo',$(this)).text()+"'>"+$('valor',$(this)).text()+"</option>");
					}else{
						$("#slc_estado").append("<option value='"+$('codigo',$(this)).text()+"'>"+$('valor',$(this)).text()+"</option>");
					}
				});
				
				if(tp='cidades'){
					$('#slc_cidade').next().remove();
					select_first($("#slc_cidade"));
				}
				if(obj.val()==1){
					$('#slc_estado').next().remove();
					select_first($("#slc_estado"));
					$('#slc_estado').attr({disabled:false});
				}
				
			}
		});
		/*$("#slc_estado option:selected").attr({selected:'selected'});*/
	});
/*-------------------------------------------------------------------------------------------*/
/*-------------------- CARREGAR a CIDADE assim que o estado é selecionado --------------------*/	 
	$('#slc_estado').change(function(){
		$('#slc_cidade').children().slice(1).remove();
		if($(this).val()==0){
			return false;	
		}
		
		var auxEspecial= "";
		
		if(GP5.local=='busca'){
				auxEspecial= 'busca';
		}
		$('<img src="'+GP5.dirBase+'imagens/ajax[select].gif" alt="load" />').insertAfter('#slc_cidade');
		$('#slc_cidade').next().css('margin-left','4px');
		$('#slc_cidade').attr({disabled:true});
		
		$.ajax({
			url: GP5.dirBase+'_ajax/regiao.php',
			type: 'post',
			dataType:'xml',
			data: {idPais:$('#slc_pais').val(), idEstado:$(this).val(), tipo:'cidades', especial:auxEspecial },
			error: function(xml){
				alert('Ocorreu um problema, entre em contato com o setor de informática!');
			},
			success: function(xml){
				$('item',xml).each(function(){
					$("#slc_cidade").append("<option value='"+$('codigo',$(this)).text()+"'>"+$('valor',$(this)).text()+"</option>");
				});
				$('#slc_cidade').next().remove();
				$('#slc_cidade').attr({disabled:false});
				select_first($("#slc_cidade"));
			}
		});
	});
/*===========================================================================================*/
/*-------------------------------------------------------------------------------------------*/
/*-------------------- habilita e desabilita o campo de email do boletim --------------------*/	
	$('.enable_email').click(function(){ 
		$("#ipt_emailBoletim").attr({disabled:true});
		$("#ipt_emailBoletim").css('background-color', '#CCC');
	});
	$('.disable_email').click(function(){ 
		$("#ipt_emailBoletim").attr({disabled:false}); 
		$("#ipt_emailBoletim").css('background-color', '#FFF');
	});
/*-------------------------------------------------------------------------------------------*/
/*-------------------- evento disparado quando a AGÊNCIA é selecionada ---------------------*/
	$('#slc_agencia').change(function(){
			$('#slc_fotografo').children().slice(1).remove();
			if($(this).val()!=1){
				$('#slc_fotografo').attr({disabled:true});
				return false;
			}else{
				$('#slc_fotografo').attr({disabled:false});
			}
			
			$.ajax({
						url: GP5.dirBase+'_ajax/fotografos.php',
						type: 'post',
						dataType:'xml',
						error: function(){
							alert('Ocorreu um problema, entre em contato com o setor de informática!');
						},
						success: function(xml){
							$('item',xml).each(function(){
								$("#slc_fotografo").append("<option value='"+$('codigo',$(this)).text()+"'>"+$('valor',$(this)).text()+"</option>");
							});
							select_first($("#slc_fotografo"));
							
						}
	 		});
	 });

	
/*---------------------------------------------------------------------------------------------*/
/*--------------- listagem de editorias -------------------------------------------------------*/
	$('#list_edits').click(function(){
		$("#busca_editorias").children().remove();
		$.ajax({
				url: GP5.dirBase+'_ajax/editorias.php',
				type: 'post',
				dataType:'text',
				error: function(){
					alert('Ocorreu um problema, entre em contato com o setor de informática!');
				},
				success: function(txt){
					$("#busca_editorias").append(txt);
					$("#browser").treeview();
					/*===== MUITO IMPORTANTE ==========================*/
					$('.hitarea').append('<img src="'+GP5.dirBase+'imagens/treeview/fake_colapse.gif" border="1" />');
					/*=================================================*/
					config.corCamada='2';
					camadaAbre();
					$("#busca_editorias").fadeIn();
					$("#box_editorias").fadeIn();
					
				}
	 		});							
	});
	
/*---------------------------------------------------------------------------------------------*/
/*--------------- carrega detalhes das fotos --------------------------------------------------*/
	$('.boxFotoItem, .zoom').click(function(){
			var obj = $(this);
			camadaAbre();
			if($.browser.msie && parseInt($.browser.version)<7){
				$('#camada').height(document.getElementById('newbody').scrollHeight);
			}
			if($(this).hasClass('zoom')){
				objId=$(obj).children('img').attr('src').split(':')[1];
			}else{
				objId=$(obj).attr('id');
			}
			$.ajax({
						url: GP5.dirBase+'_ajax/fotos.php',
						type: 'post',
						dataType:'xml',
						data:{idFoto:objId},
						error: function(xml){
							alert('Ocorreu um problema, entre em contato com o setor de informática!');
							camadaFecha();
						},
						success: function(xml){
							
							$('.limpar').empty(); // limpa tudo
							
							$('#codigo').text(objId).text() !='' ? $('#codigo').prev().andSelf().show() : $('#codigo').prev().andSelf().hide();
							
							/*$('dados',xml).children().each(function(){
								$('#'+this.nodeName).text($(this).text()).text() !='' ? $('#'+this.nodeName).prev().andSelf().show() : $('#'+this.nodeName).prev().andSelf().hide();
								return false;
							});*/
							
							$('#data').text($('data',xml).text());
							//-----
							$('#editorias').append(linksZoom('editorias',xml,'&nbsp;-&nbsp;'));
							//-----
							$('#pautas').append(linksZoom('pauta',xml,'&nbsp;-&nbsp;'));
							//-----
							$('#tipo').text($('tipo',xml).text());
							//-----
							$('#titulo').text($('titulo',xml).text());
							//-----
							$('#legenda').text($('legenda',xml).text());
							//-----
							$('#palavraChave').append( linksZoom('palavraChave',xml,',&nbsp;'));
							//-----
							$('#gold').append($('gold',xml).text()==1?' <img src="'+GP5.dirBase+'imagens/foto[gold].gif" border="0" alt="foto" />' : 'não' );
							//-----
							$('#peso').text($('peso',xml).text());
							//-----
							$('#orientacao').text($('orientacao',xml).text());
							//-----
							$('#cor').text($('cor',xml).text());
							//-----
							$('#tamanho').text($('tamanho',xml).text());
							//-----
							$('#original').text($('original',xml).text());
							//-----
							if($.trim($('fotografo',xml).text())){
								$('#fotografo').text($('fotografo',xml).text()+" / "+$('agenciaNome',xml).text());
							}else{
								$('#fotografo').text($('agenciaNome',xml).text());
							}
							//-----
							valida_item_zoom($('lugar',xml).text(),'lugar');
							//-----
							$('#agenciaLogo').append('<img class="agenciaLogo" src="'+GP5.dirBase+'upload/'+$('agenciaLogo',xml).text()+'" title="'+$('fotografo',xml).text()+" / "+$('agenciaNome',xml).text()+'"/>') ;
							//-----
							valida_item_zoom($('pais',xml).text(),'pais');
							//-----
							valida_item_zoom($('estado',xml).text(),'estado');
							//-----
							valida_item_zoom($('cidade',xml).text(),'cidade');
							//-----
							$('.zoomDownloadJPG').attr('id',objId+'/'+$('hash',xml).text()+'/jpg');
							$('.zoomDownloadZIP').attr('id',objId+'/'+$('hash',xml).text()+'/zip');
							//-----
							
							var strSrc=new String(obj.children().filter('img').attr('src'));
							var src = strSrc.substr(0,strSrc.length-2)+':2';
							
							if($.browser.msie && parseInt($.browser.version)<7){
								$('.fotoZoom').css("margin-top",document.getElementById('newbody').scrollTop+70);
							}else{
								$('.fotoZoom').css("margin-top",$(window).scrollTop()+70);
							}
							$('.fotoZoomConteudo').prepend('<img class="fotoZoomImg" src="'+src+'" border="0" alt="foto" title="'+$('legenda',xml).text()+'" />');
							$('.fotoZoom').fadeIn('fast');
							//---------------------------------------------
							$('.pcZoom').click(function(){
								$('#ipt_keywords').val($.trim( $(this).text() ) );
								//---------------------------------------
								$('.fotoZoom').fadeOut('fast');
								camadaFecha();
								$('.fotoZoomImg').remove();
								$('#agenciaLogo').children().remove();
								$('#editorias').children().remove();
								//----------------------------------------
								$('#frm_buscaRapida').submit();
							});
							//---------------------------------------------
						}
				});								 
	});

	$('#fotoZoomFechar').click(function(){
		$('.fotoZoom').fadeOut('fast');
		camadaFecha();
		$('.fotoZoomImg').remove();
		$('#agenciaLogo').children().remove();
		$('#editorias').children().remove();
	});
	
	$('#box_editoriasFechar').click(function(){
		$('#box_editorias').hide();
		camadaFecha();
	});
	
/*========================= DOWNLOADS =======================================================*/
	$('.downloadPacote').click(function(){
		if(confirm("Deseja realmente fazer o dowload deste pacote especial?"))
			window.location=GP5.dirBase + 'pacotesespeciais/' + $(this).attr('id')+'/';
	});
	$('.downloadFoto').click(function(){
		if(confirm("Deseja realmente fazer o dowload desta(s) foto(s)?"))
			window.location=GP5.dirBase + 'fotos/download/' + $(this).attr('id')+'/';
	});
	
/*===========================================================================================*/


/*
***    CADASTRE-SE ---------------------------------------------------------------------------||
 */
/*-------------------------------------------------------------------------------------------*/
/*-------------------- ALTERNAR ENTRE PESSOA FÍSICA E JURÍDICA ------------------------------*/		  
	$('#tp_fis').click(function(){
		$('#fd_pessoaJuridica').children().attr({disabled:true});
		$(this).addClass('selecionado');
		$('#tp_jur').removeClass('selecionado');					  
		$("#fd_pessoaFisica").show();
		$("#fd_pessoaJuridica").hide();
		$('#ipt_tipo').val('F');
	});
	$('#tp_jur').click(function(){
		$('#fd_pessoaJuridica').children().attr({disabled:false});
		$(this).addClass('selecionado');
		$('#tp_fis').removeClass('selecionado');
		$("#fd_pessoaFisica").hide();
		$("#fd_pessoaJuridica").show();
		$('#ipt_tipo').val('J');
	});
	$('#tp_jur').click();
/*--------------------------------------------------------------------------------------------*/
/*-------------------- BUSCA CEP CADASTRE-SE --------------------------------------------------*/
	$('#ipt_cep2').blur(function(){
		busca_cep($('#ipt_cep1').val()+$(this).val(),'#ipt_endereco','#ipt_bairro');
	});
/*
 *  FIM  CADASTRE-SE ---------------------------------------------------------------------------||
 */ 
 
 
/*----------------------------------------------------------------------------------------------*/
/*----------------------------- EXCLUIR CONTATO ------------------------------------------------*/
	$('.gContatoExcluirC').click(function(){
		if(confirm("Deseja realmente excluir este contato?"))
			excluir_dados_contato($(this),$(this).attr('id'),'excluirContato');
	});
	$('.gContatoExcluirT').click(function(){
		if(confirm("Deseja realmente excluir este telefone do contato?"))
			excluir_dados_contato($(this),$(this).attr('id'),'excluirTelefone');
	});
	
/*----------------------------------------------------------------------------------------------*/
/*----------------------------- EXCLUIR USUARIO ------------------------------------------------*/
	$('.gcExcluirU').click(function(){
		if(confirm("Deseja realmente excluir este usuário?"))
			excluir_usuario($(this),$(this).attr('id'),'excluir');
	});

/*----------------------------------------------------------------------------------------------*/
// ---------------------------- AUTO COMPLETAR ---------------------------------------------------
	$("#ipt_cidade").keyup(function(event){
		var position = $(this).position();
		objIpt=this;
		$.ajax({
				url: GP5.dirBase+'_ajax/regiao.php',
				type: 'post',
				dataType:'xml',
				data:{	especial:'', 
						tipo:'cidades', 
						idPais:$('#slc_pais').val(),
						suggest:1, 
						nomeCidade:$("#ipt_cidade").val()
				},
				error: function(){
					alert('Ocorreu um problema, entre em contato com o setor de informática!');
					return false;
				},
				success: function(xml){
					$('.sugestao ol').empty();
					if($('item',xml).size()>0){
						$('.sugestao').css({
							'margin-top':position.top+25+'px',
							'margin-left':position.left+'px',
							'width':$(objIpt).width()
						}).show();
						$('item',xml).each(function(){
							$('.sugestao ol').append('<li>'+$('valor',this).text()+'</li>');
							$('.sugestao ol li').click(function(){
								$(objIpt).val($(this).text());
								
							});
						});
					}
				}
	 	});	
		$("#ipt_cidade").blur(function(){
			$('.sugestao').hide('slow');
		});
	});
//==============================================================================================
});
