var liTermos;
var nomeOk;
var emailOk;
var loginOk;
var senhaOk;
var liOk;
var idUsuariosAssunto = new Array();
var idInteressesAssunto = new Array();
var listaEmail = new Array();

var idUsuariosPost = new Array();
function fncCriaVarUsuariosPost(IdAssunto){
	idUsuariosPost[IdAssunto] = [];	
}

var intervaloAssunto = new Array();
function fncCriaVarIntervaloAssunto(IdAssunto){
	intervaloAssunto[IdAssunto] = [];	
}

var postPvtAssunto = new Array();
function fncCriaVarPvtAssunto(IdAssunto){
	postPvtAssunto[IdAssunto] = [];	
}

var temaAssunto;
var idAssuntosMinimizados = new Array();
var statusOpcoesAssuntos = 0;
var amigos;
var amigosFavoritos;
var amigosPerfil = "Cnull";
var interessesUsuario;
var interessesPerfil = "Cnull";
var idInteressesBusca = new Array();

//Vars Conta
var IdNameConta;
var NomeConta;
var EmailConta;
var FotoConta;
var PaginaConta;

// Vars Perfil
var IdPerfil;
var IdNamePerfil;
var NomePerfil;
var SobrePerfil;
var SexoPerfil;
var AniversarioPerfil;
var RelacionamentoPerfil;
var ProfissaoPerfil;
var LocalPerfil;
var ContatoPerfil;
var AdmPerfil;

var numIniPagInteresses = 0;

var qtdFundoAcao = 0;
var statusFundoAcao = 0;

var privacidade1;
var privacidade2;
var privacidade3;

var logarUalah;

var codEspecial;

function fncAbrirFundoAcao() {
	if(statusFundoAcao == 0) {
		$("#fundoAcao").show();
		statusFundoAcao = 1;
	}
	qtdFundoAcao++;
}

function fncFecharFundoAcao() {
	qtdFundoAcao--;
	if(qtdFundoAcao == 0) {
		$("#fundoAcao").hide();;
		statusFundoAcao = 0;
	}
}

function fncInitIndex() {
	$.ajax({
		url: "interfaces/ValidaLogin.php",
		cache: false,
		
		beforeSend: function() {
			$("body").html("<img src='images/loading_bar.gif' width='220' height='19'>");
		},
		
		success: function(callback){
			
			if(callback == "E") {
				fncLoadIndex();
			}
			else {
				if(callback == "IE") {
					document.location.href="http://www.ualah.com/AtualizarBrowser.shtml";
				}
				else {
					document.location.href="Default.shtml#UaladasPublicas";
				}
			}
		}
	});
}



function fncLoadIndex() {
	

	$.ajax({
		url: "ConteudoIndex.shtml",
		cache: false,

		beforeSend: function() {
			$("body").html("<img src='images/loading_bar.gif' width='220' height='19'>");
		},

		success: function(callback){
			$("body").html(callback);
			
			var area = window.location.href.split("/");
	
			if(area[4].substr(0,15) == "index.shtml?cod") {
				var area2 = area[4].split("=");
				codEspecial = area2[1];
			}

			if(codEspecial) {
				fncAbrirFundoAcao();
				$("body").append('<div id="popConviteEspecial"><div id="balao"></div><h1>////// Cadastro</h1><h2>Cadastre-se no Ualah e participe da rede social mais comunicativa da Internet!</h2><div id="formulario"><div id="linha"><h3>Nome</h3><input type="text" id="inputNomeEspecial" /><div id="statusNomeEspecial" class="status"></div></div><div id="linha"><h3>E-mail</h3><input type="text" id="inputEmailEspecial" onblur="fncVerificaEmail(this.value)" /><div id="statusEmailEspecial" class="status"></div><h4>ex.: seuemail@seuemail.com.br</h4></div><div id="linha"><h3>Nome de usuário</h3><input type="text" id="inputLoginEspecial" onblur="fncVerificaLogin(this.value)" /><div id="statusLoginEspecial" class="status"></div><h4>Letras minúsculas e números</h4></div><div id="linha"><h3>Senha</h3><input type="text" id="inputSenhaEspecial" /><div id="statusSenhaEspecial" class="status"></div><h4>Mínimo de 6 caracteres</h4></div><div id="termos"><h5>Ler Termos de Uso</h5><div id="checkEspecial"><img src="images/icon_n_li.png" onclick="fncLiTermosEspecial()" /></div><h6>Li e aceito os termos de uso</h6></div><div id="btEnviarEspecial" onclick="fncCadastrarEspecial()"></div></div></div>');
			}

			$(function() {
				$("#conteudo").keypress(function (e) {
					if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
						fncLogar();
						return false;
					} else {
						return true;
					}
				});
			});

			$(function() {
				$("#cadastro").keypress(function (e) {
					if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
						fncCadastrar();
						return false;
					} else {
						return true;
					}
				});
			});
		}
	});
}

function fncEsqueceuSenha() {
	fncAbrirFundoAcao();
	$("body").append('<div id="popEsqueceuSenha"><div id="titulo"><h1>Esqueceu a senha?</h1><h3 onclick="fncFecharPopEsqueceuSenha()">Fechar</h3></div><div id="conteudo"><h1>Digite abaixo seu Login ou E-mail.</h1><p>Você irá receber um e-mail para trocar sua senha.</p><input type="text" id="loginemail" /><div id="btEsqueceuSenha"><img src="images/bt_ok.png" onclick="fncEnviarSenha()" /></div></div></div>');
}

function fncFecharPopEsqueceuSenha() {
	fncFecharFundoAcao();
	$("#popEsqueceuSenha").remove();
}

function fncEnviarSenha() {
	
	var loginemail = $("#loginemail").val();
	
	if(!loginemail) {
		alert("Dados incorretos.");
	}
	else {
		$.ajax({
			type: "POST",
			url: "interfaces/EsqueceuSenha.php",
			data: {_loginemail:loginemail},
			cache: false,
			
			beforeSend: function() {
				$("#btEsqueceuSenha").html("<img src='images/loading_circle_24_24_white.gif' />");
			},
			
			success: function(callback) {
				if(callback == "ErrorLogin") {
					document.location.href="index.shtml";
				}
				else {
					if(callback.indexOf("DieServer") != -1) {
						fncDieServer();
					}
					else {
						if(callback == "C") {
							$("#loginemail").val("");
							$("#btEsqueceuSenha").html("");
							alert("Dentro de instantes você receberá um e-mail com instruções para trocar sua senha. Obrigado.");
							fncFecharPopEsqueceuSenha()
						}
	
						if(callback == "E") {
							alert("Dados incorretos.");
							$("#btEsqueceuSenha").html('<img src="images/bt_ok.png" onclick="fncEnviarSenha()" />');
						}
					}
				}
			}
		});
	}
}

function fncObterDadosTrocaSenha() {
	var cod = parent.window.location.hash.substr(1);

	$.ajax({
		type: "POST",
		url: "interfaces/ObterDadosTrocaSenha.php",
		data: {_cod:cod},
		cache: false,
		
		beforeSend: function() {
			$("#statusConvidar").html("<div id='loadingPrincipal'><img src='images/loading_bar.gif' width='220' height='19'></div>");
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					var objeto = eval(callback);
					
					$("body").append('<div id="fundoAcao"></div><div id="geral"><div id="conteudo"><div id="box"><div id="infos"><div id="logo2"><a href="index.shtml"><img src="images/logo_ualah_login.png" width="272" height="176" alt="" border="0" /></a></div><div id="texto3"><h1>Ol&aacute; <strong><span id="nome"></span></strong>,<br />Digite abaixo sua nova senha.</h1><br /><div id="novaSenha"><form><table><tr><td>Nova Senha:</td><td><input type="password" id="senha" maxlength="30" class="campo" /></td><td rowspan="2"><img src="images/bt_yupi.png" class="yupi" onclick="fncTrocarSenha();" /></td></tr><tr><td>Confirmar:</td><td><input type="password" id="cfsenha" maxlength="30" class="campo" /></td></tr></table><div id="msgStatusLogin"></div></form></div></div></div></div><div id="rodape">&copy;2009 ualah</div></div></div>');
					
					if(callback != "null"){
						$("#nome").html(objeto[0].Nome);
					}
					else {
						document.location.href = "index.shtml";
					}
				}
			}
		}
	});
}

function fncTrocarSenha() {
	var cod = parent.window.location.hash.substr(1);
	var senha = $("#senha").val();
	var cfsenha = $("#cfsenha").val();

	if(cfsenha != senha) {
		$("#msgStatusLogin").html("<strong>Confirme sua senha.</strong>");
	}
	else {
		if(!cfsenha || !senha) {
			$("#msgStatusLogin").html("<strong>Preencha todos os campos.</strong>");
		}
		else {
			$.ajax({
				type: "POST",
				url: "interfaces/TrocarSenha.php",
				data: {_cod:cod, _senha:senha},
				cache: false,
				
				beforeSend: function() {
					$("#msgStatusLogin").html("<div id='loadingPrincipal'><img src='images/loading_bar.gif' width='220' height='19'></div>");
				},
				
				success: function(callback) {
					if(callback == "ErrorLogin") {
						document.location.href="index.shtml";
					}
					else {
						if(callback.indexOf("DieServer") != -1) {
							fncDieServer();
						}
						else {
							$("#msgStatusLogin").html("");
							alert("Senha alterada com sucesso!");
							document.location.href = "index.shtml";
						}
					}
				}
			});
		}
	}
}

function fncLogar() {
	var _idname = document.getElementById('idname').value;
	var _senha = document.getElementById('senha').value;
	var _salvarDados = $("input[name='salvarDados']:checked").val();
	
	if(!_idname || !_senha) {
		alert("Login ou Senha inv&aacute;lidos.");
	}
	else
	{
		fncAbrirFundoAcao();
		$("#fundoAcao").html("<div id='loadingPrincipal'><img src='images/loading_cubo.gif' /></div>");
		$.post(
			'interfaces/Logar.php',
			{idname:_idname, senha:_senha, salvarDados:_salvarDados},
			function(callback) {
				if(callback == "ErrorLogin") {
					document.location.href="index.shtml";
				}
				else {
					if(callback.indexOf("DieServer") != -1) {
						fncDieServer();
					}
					else {
						if(callback == "C") {
							$("#msgStatusLogin").html("");
							logarUalah = 1;
							document.location.href="Default.shtml";
						}
						else {
							if(callback == "EA") {
								fncFecharFundoAcao();
								$("body").append('<div id="popUpsAtivar" class="popUps"><div id="titulo"><h1 id="tituloUps">Eba!</h1></div><div id="conteudo"><h1 id="perguntaUps">Parece que você ainda não confirmou seu cadastro!</h1><h2 id="infoUps">Clique no link que enviamos ao seu e-mail e torne-se mais um ualeiro!<br /> Seja bem vindo!</h2><div id="controleUps"><img src="images/bt_ok.png" onclick="fncFecharPopUpsAtivar();" /></div></div></div>');
							}
							else {
								alert("Dados incorretos.");
								document.location.href="index.shtml";
							}
						}
					}
				}
			}
		);
	}	
}

function fncFecharPopUpsAtivar() {
	$("#popUpsAtivar").remove();
}

function fncSair() {
	
	$.ajax({
		type: "POST",
		url: "interfaces/Sair.php",
		cache: false,
		
		success: function(callback) {
			pageTracker._trackPageview("Principal/Sair");
			document.location.href = "http://www.ualah.com";
		}
	});
	
}

function fncLiTermos() {
	$("#check").html('<img src="images/icon_li.png" onclick="fncNaoLiTermos()" />');
	liTermos = true;
}

function fncLiTermosEspecial() {
	$("#checkEspecial").html('<img src="images/icon_li.png" onclick="fncNaoLiTermos()" />');
	liTermos = true;
}


function fncNaoLiTermos() {
	$("#check").html('<img src="images/icon_n_li.png" onclick="fncLiTermos()" />');
	liTermos = false;
}

function fncCadastrar() {
	var _nome = $("#inputNome").val();
	var _email = $("#inputEmail").val();
	var _login = $("#inputLogin").val();
	var _senha = $("#inputSenha").val();
	
	
	
	if(!_nome) {
		$("#statusNome").html('<img src="images/icon_form_e.png" />');
	}
	else {
		$("#statusNome").html('<img src="images/icon_form_c.png" />');
		
		// email
		if(isValidEmail(_email)) {
			$.post(
				'interfaces/VerificaEmail.php',
				{_email:_email},
				function(callback) { 
					if(callback == "C"){
						$("#statusEmail").html('<img src="images/icon_form_c.png" />');
						
						if(!_login || _login.length < 2 || _login.length > 15) {
							$("#statusLogin").html('<img src="images/icon_form_e.png" />');
						}
						else {
							$.post(
								'interfaces/VerificaLogin.php',
								{_idname:_login},
								function(callback) { 
									if(callback == "C"){
										$("#statusLogin").html('<img src="images/icon_form_c.png" />');
										
										//senha
										if(!_senha || _senha.length < 6) {
											$("#statusSenha").html('<img src="images/icon_form_e.png" />');
										}
										else {
											$("#statusSenha").html('<img src="images/icon_form_c.png" />');
											
											//termos
											if(!liTermos) {
												alert("Por favor, aceite os termos de uso.");
											}
											else {
												$.ajax({
													type: "GET",
													url: "interfaces/Cadastrar.php",
													data: {nome:_nome, email:_email, idName:_login, senha:_senha},
													cache: false,
													
													beforeSend: function() {
														fncAbrirFundoAcao();
														$("#fundoAcao").html("<div id='loadingPrincipal'><img src='images/loading_cubo.gif' /></div>");
													},
													
													
													success: function(callback) {
														if(callback == "ErrorLogin") {
															document.location.href="index.shtml";
														}
														else {
															if(callback.indexOf("DieServer") != -1) {
																fncDieServer();
															}
															else {
																if(callback == "EC") {
																	//$("#msgStatusParticipe").html("Preencha todo formulario corretamente.");
																}
											
																if(callback == "C") {
																	/*_salvarDados = 0;
																	$.post(
																		'interfaces/Logar.php',
																		{idname:_login, senha:_senha, salvarDados:_salvarDados},
																		function(callback) {
																			if(callback == "ErrorLogin") {
																				document.location.href="index.shtml";
																			}
																			else {
																				if(callback.indexOf("DieServer") != -1) {
																					fncDieServer();
																				}
																				else {
																					if(callback == "C") {
																						document.location.href="Default.shtml#UaladasPublicas";
																					}
																				}
																			}
																		}
																	);*/
																	
																	fncEnviarEmailBemVindo(_login);
																	fncFecharFundoAcao();
																	$("body").append('<div id="popUpsObrigado" class="popUps"><div id="titulo"><h1 id="tituloUps">Eba!</h1></div><div id="conteudo"><h1 id="perguntaUps">Obrigado por se cadastrar no Ualah!</h1><h2 id="infoUps">Clique no link que enviamos ao seu e-mail e torne-se mais um ualeiro!<br /> Seja bem vindo!</h2><div id="controleUps"><img src="images/bt_ok.png" onclick="fncFecharPopUpsObrigado();" /></div></div></div>');
																	
																}
											
																if(callback == "E") {
																	$("#msgStatusParticipe").html("Erro no Cadastro.");
																}
															}
														}
													}
												});
											}
										}
									}
									else {
										$("#statusLogin").html('<img src="images/icon_form_e.png" />');
									}
								}
							);
						}
						
					}
					else {
						$("#statusEmail").html('<img src="images/icon_form_e.png" />');
					}
				}
			);
		}
		else {
			$("#statusEmail").html('<img src="images/icon_form_e.png" />');
		}

	}
}

function fncCadastrarEspecial() {
	var _nome = $("#inputNomeEspecial").val();
	var _email = $("#inputEmailEspecial").val();
	var _login = $("#inputLoginEspecial").val();
	var _senha = $("#inputSenhaEspecial").val();
	
	
	
	if(!_nome) {
		$("#statusNomeEspecial").html('<img src="images/icon_form_e.png" />');
	}
	else {
		$("#statusNomeEspecial").html('<img src="images/icon_form_c.png" />');
		
		// email
		if(isValidEmail(_email)) {
			$.post(
				'interfaces/VerificaEmail.php',
				{_email:_email},
				function(callback) { 
					if(callback == "C"){
						$("#statusEmailEspecial").html('<img src="images/icon_form_c.png" />');
						
						if(!_login || _login.length < 2 || _login.length > 15) {
							$("#statusLoginEspecial").html('<img src="images/icon_form_e.png" />');
						}
						else {
							$.post(
								'interfaces/VerificaLogin.php',
								{_idname:_login},
								function(callback) { 
									if(callback == "C"){
										$("#statusLoginEspecial").html('<img src="images/icon_form_c.png" />');
										
										//senha
										if(!_senha || _senha.length < 6) {
											$("#statusSenhaEspecial").html('<img src="images/icon_form_e.png" />');
										}
										else {
											$("#statusSenha").html('<img src="images/icon_form_c.png" />');
											
											//termos
											if(!liTermos) {
												alert("Por favor, aceite os termos de uso.");
											}
											else {
												$.ajax({
													type: "GET",
													url: "interfaces/Cadastrar.php",
													data: {nome:_nome, email:_email, idName:_login, senha:_senha, cod:codEspecial},
													cache: false,
													
													beforeSend: function() {
														fncAbrirFundoAcao();
														$("#fundoAcao").html("<div id='loadingPrincipal'><img src='images/loading_cubo.gif' /></div>");
													},
													
													
													success: function(callback) {
														if(callback == "ErrorLogin") {
															document.location.href="index.shtml";
														}
														else {
															if(callback.indexOf("DieServer") != -1) {
																fncDieServer();
															}
															else {
																if(callback == "EC") {
																	//$("#msgStatusParticipe").html("Preencha todo formulario corretamente.");
																}
											
																if(callback == "C") {
																	/*_salvarDados = 0;
																	$.post(
																		'interfaces/Logar.php',
																		{idname:_login, senha:_senha, salvarDados:_salvarDados},
																		function(callback) {
																			if(callback == "ErrorLogin") {
																				document.location.href="index.shtml";
																			}
																			else {
																				if(callback.indexOf("DieServer") != -1) {
																					fncDieServer();
																				}
																				else {
																					if(callback == "C") {
																						document.location.href="Default.shtml#UaladasPublicas";
																					}
																				}
																			}
																		}
																	);*/
																	
																	fncEnviarEmailBemVindo(_login);
																	fncFecharFundoAcao();
																	$("body").append('<div id="popUpsObrigado" class="popUps"><div id="titulo"><h1 id="tituloUps">Eba!</h1></div><div id="conteudo"><h1 id="perguntaUps">Obrigado por se cadastrar no Ualah!</h1><h2 id="infoUps">Clique no link que enviamos ao seu e-mail e torne-se mais um ualeiro!<br /> Seja bem vindo!</h2><div id="controleUps"><img src="images/bt_ok.png" onclick="fncFecharPopUpsObrigado();" /></div></div></div>');
																	
																}
											
																if(callback == "E") {
																	$("#msgStatusParticipe").html("Erro no Cadastro.");
																}
															}
														}
													}
												});
											}
										}
									}
									else {
										$("#statusLoginEspecial").html('<img src="images/icon_form_e.png" />');
									}
								}
							);
						}
						
					}
					else {
						$("#statusEmailEspecial").html('<img src="images/icon_form_e.png" />');
					}
				}
			);
		}
		else {
			$("#statusEmailEspecial").html('<img src="images/icon_form_e.png" />');
		}

	}
}

function fncFecharPopUpsObrigado() {
	$("#popUpsObrigado").remove();
}

function fncEnviarEmailBemVindo(login) {
	$.post(
	'interfaces/EmailBemVindo.php',
	{_login:login},
		function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "C") {
						//document.location.href="Default.shtml#UaladasPublicas";
					}
				}
			}
		}
	);
}

function isValidEmail(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

function fncVerificaEmail(email) {
	$.post(
		'interfaces/VerificaEmail.php',
		{_email:email},
		function(callback) { 
			if(callback == "C"){
				emailOk = true;
				$("#statusEmail").html('<img src="images/icon_form_c.png" />');
			}
			else {
				emailOk = false;
				$("#statusEmail").html('<img src="images/icon_form_e.png" />');
			}
		}
	);
}

function fncVerificaLogin(idname) {
	$.post(
		'interfaces/VerificaLogin.php',
		{_idname:idname},
		function(callback) { 
			if(callback == "C"){
				loginOk = true;
				$("#statusLogin").html('<img src="images/icon_form_c.png" />');
			}
			else {
				loginOk = false;
				$("#statusLogin").html('<img src="images/icon_form_e.png" />');
			}
		}
	);
}



function fncAtualizarPerfilOnline() {
	$.ajax({
		url: "interfaces/AtualizarPerfilOnline.php",
		cache: false,
		
		success: function(callback){
			//
		}
	});
}

function fncLoadDefault() {
	$.ajax({
		url: "interfaces/ValidaLogin.php",
		cache: false,
		
		beforeSend: function() {
			$("body").html("<span class='loadBody'>Autenticando Usu&aacute;rio</span><br /><img src='images/loading_bar.gif'>");
		},
		
		success: function(callback){
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "C") {
						fncLoadVerificaIdioma("default");
					}
					else {
						document.location.href="index.shtml";
					}
				}
			}
		}
	});
}

function fncRedirecionarDefault() {
	document.location.href="index.shtml";
}

function fncDieServer() {
	document.location.href="index.shtml";
}

function fncLoadVerificaIdioma(local) {
	$.ajax({
		url: "interfaces/VerificaIdioma.php",
		cache: false,

		beforeSend: function() {
			$("body").html("<span class='loadBody'>Verificando Idioma</span><br /><img src='images/loading_bar.gif'>");
		},

		success: function(callback){
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					switch(callback) {
						case "BR":
							fncObterConfiguracoes("pt-BR",local);
						  break;    
						default:
							fncObterConfiguracoes("pt-BR",local);
					}
				}
			}
		}
	});
}

var bgPerfil;

function fncObterConfiguracoes(idioma, local) {
	var tipo;
	var IdNameConfig;
	var area = window.location.href.split("/");
	
	if(area[4].substr(0,13) == "Default.shtml") {
		tipo = "usuario";
	}
	else {
		tipo = "perfil";
		IdNameConfig = area[4];
	}
	
	$.ajax({
		url: "interfaces/ObterConfiguracoes.php",
		cache: false,
		data: {_tipo:tipo, _idNameConfig:IdNameConfig},

		beforeSend: function() {
			$("body").html("<span class='loadBody'>Carregando Configura&ccedil;&otilde;es</span><br /><img src='images/loading_bar.gif'>");
		},
		
		success: function(callback){
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback != "Cnull") {
						var objeto = eval(callback.substr(1));
						
						bgPerfil = objeto[0].bgImg;
						
						if(!bgPerfil) {
							document.body.style.background="#000 url(images/bgs_perfil/default.jpg) fixed top";
						}
						else {
							document.body.style.background="#000 url("+bgPerfil+") fixed top";
						}
						
						IdNameConta = objeto[0].idname;
						NomeConta = objeto[0].nome;
						EmailConta = objeto[0].email;
						FotoConta  = objeto[0].foto;
						PaginaConta  = objeto[0].pagina;
						
						if(!PaginaConta) {
							PaginaConta = 0;
						}
						
						privacidade1 = objeto[0].privacidade1;
						privacidade2 = objeto[0].privacidade2;
						privacidade3 = objeto[0].privacidade3;
						
						if(local == "default") {
							
							if (area[4].length == 13) {
								if(PaginaConta == 0) {
									if(logarUalah = 1) {
										document.location.href="Default.shtml#UaladasAmigos";
									}
									else {
										document.location.href="Default.shtml#UaladasPublicas";
									}
								}
								
								if(PaginaConta == 1) {
									document.location.href="Default.shtml#UaladasPublicas";
								}
								
								if(PaginaConta == 2) {
									document.location.href="Default.shtml#UaladasAmigos";
								}
								
								if(PaginaConta == 3) {
									document.location.href="Default.shtml#UaladasFavoritas";
								}
								
								if(PaginaConta == 4) {
									document.location.href = objeto[0].idname;
								}
								
								if(PaginaConta == 5) {
									document.location.href="Default.shtml#UaladasInteresses";
								}
							}
							
							if(!objeto[0].idioma) {
								fncLoadConteudoDefault(idioma);
							}
							else {
								fncLoadConteudoDefault(objeto[0].idioma);
							}
						}
						
						if(local == "perfil") {
							if(!objeto[0].idioma) {
								fncLoadConteudoPerfil(idioma);
							}
							else {
								fncLoadConteudoPerfil(objeto[0].idioma);
							}
						}
					}
				}
			}
		}
	});
}

function fncLoadConteudoDefault(idioma) {
	var intervalQtdYupis;
	var intervalQtdConvites;
	var intervalPerfilOnline;
	
	$.ajax({
		url: "ConteudoDefault_"+idioma+".shtml",
		cache: false,

		beforeSend: function() {
			$("body").html("<span class='loadBody'>Carregando Conte&uacute;do</span><br /><img src='images/loading_bar.gif'>");
		},

		success: function(callback){
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					$("body").html(callback);

					$(function() {
						$("#localBusca").keypress(function (e) {
							if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
								fncAbrirBuscaDados();
								return false;
							} else {
								return true;
							}
						});
					});
					
					$("#idNameConta").html(IdNameConta);
					$("#fotoLocalPostar").html('<img src="images/fotos_users/'+FotoConta+'" width="48" height="48" />');
					
					$("#nomeUserLocalPerfilMenu").html('<a href="'+IdNameConta+'"><h1>Perfil <strong>['+IdNameConta+']</strong></h1></a>');
					
					fncLerCacheAssuntosMinimizados();
					
					fncObterNovosYupis("qtd");
					intervalQtdYupis = window.setInterval(function() {
						fncObterNovosYupis("qtd");
					}, 30000);
					
					fncObterConvites("qtd");
					intervalQtdConvites = window.setInterval(function() {
						fncObterConvites("qtd");
					}, 30000);
					
					fncAtualizarPerfilOnline();
					intervalPerfilOnline = window.setInterval(function() {
						fncAtualizarPerfilOnline();
					}, 30000);
					
					
					var b = navigator.appName;
					var ua = navigator.userAgent.toLowerCase();

					var Browser = {};

					Browser.safari = ua.indexOf('safari') > -1;
					Browser.chrome = ua.indexOf('chrome') > -1;
					Browser.ie6 = ua.indexOf('msie 6.0') > -1;
					Browser.ie7 = ua.indexOf('msie 7.0') > -1;
					Browser.ie = ua.indexOf('msie') > -1;

					delete b;
					delete ua;
					
					//alert(ua)
					
					if(Browser.safari || Browser.chrome || Browser.ie6 || Browser.ie7) {
						fncObterHashSafariChrome();
						var tHashSafariChrome = setInterval(fncObterHashSafariChrome,100);
					}
					else {
						fncObterHash();
					}
					
				    fncObterUsuarios("amigos");
				    fncObterInteresses(IdNameConta,"usuario");
				    $('#assunto').limit('150','#charsLeft');
				    
					$("body").click(function () { 
						if(statusOpcoesAssuntos == 1){
							$("#opcoesAssuntos").remove();
						} 
					});
					
					$(function() {
						$("#assunto").keypress(function (e) {
							if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
								fncCadastrarAssunto();
								return false;
							} else {
								return true;
							}
						});
					});
				}
			}
		}
	});
}

function fncSuaConta() {	
	fncAbrirFundoAcao();
	$("body").append('<div id="popConta"><div id="titulo"><h1>Sua Conta</h1><h3 onclick="fncFecharSuaConta()">Fechar</h3></div><div id="conteudo"><p>Os dados de sua conta são utilizados para que você acesse todos os produtos Ualah.</p><div id="linha"><h1>Nome:</h1><input type="text" id="inputNomeConta" class="campos" /></div><div id="linha"><h1>Email:</h1><input type="text" id="inputEmailConta" class="campos" disabled /></div><div id="linha"><h1>País:</h1><select id="selectPaisConta" class="list"><option value="1">Brasil</option></select></div><div id="linha"><h1><strong>Login:</strong></h1><input type="text" id="inputLoginConta" disabled class="campos" /></div><div id="linha"><h1><strong>Senha Atual:</strong></h1><input type="password" id="inputSenhaAtual" class="campos2" /></div><div id="linha"><h1><strong>Nova Senha:</strong></h1><input type="password" id="inputNovaSenha" class="campos2" /></div><div id="btEditar"><img src="images/bt_editar.png" onclick="fncEditarConta()" /></div><p class="excluir">Caso queira desativar sua conta, <strong onclick="fncDesativarConta();">clique aqui</strong>.</p></div></div>');
	$("#inputLoginConta").val(IdNameConta);
	$("#inputNomeConta").val(NomeConta);
	$("#inputEmailConta").val(EmailConta);
	
	pageTracker._trackPageview("Principal/SuaConta");
}

function fncEditarConta() {
	var nomeConta = $("#inputNomeConta").val();
	var emailConta = $("#inputEmailConta").val();
	var paisConta = document.getElementById('selectPaisConta').value;
	var senhaAtualConta = $("#inputSenhaAtual").val();
	var novaSenhaConta = $("#inputNovaSenha").val();
	
	$.ajax({
		type: "GET",
		url: "interfaces/EditarContaUsuario.php",
		data: {_nomeConta:nomeConta, _emailConta:emailConta, _paisConta:paisConta, _senhaAtualConta:senhaAtualConta, _novaSenhaConta:novaSenhaConta}, 
		cache: false,

		beforeSend: function() {
			//fncAbrirFundoAcao();
			//$("#fundoAcao").html("<div id='loadingPrincipal'><img src='images/loading_cubo.gif' /></div>");
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						fncAbrirFundoAcao();
						$("#popConta").remove();
						$("body").append('<div id="popUpsEditarConta" class="popUps"><div id="titulo"><h1 id="tituloUps">Aviso</h1></div><div id="conteudo"><h1 id="perguntaUps">Os dados da sua conta foram alterados com sucesso.</h1><h2 id="infoUps">A página será recarregada.</h2><div id="controleUps"><img src="images/bt_ok.png" onclick="fncRedirecionarDefault();" /></div></div></div>');
					}
				}
			}
		}
	});
	
}

function fncDesativarConta() {
	$("body").append('<div id="popUpsDesativarConta" class="popUps"><div id="titulo"><h1 id="tituloUps">Ups!</h1></div><div id="conteudo"><h1 id="perguntaUps">Deseja realmente desativar sua conta no Ualah?</h1><h2 id="infoUps">Sua presença aqui é muito importante para nós</h2><div id="controleUps"><img src="images/bt_sim.png" onclick="fncConfirmarDesativarConta();" /> <img src="images/bt_nao.png" onclick="fncNaoDesativarConta();" /></div></div></div>');
}

function fncConfirmarDesativarConta() {
	$.ajax({
		type: "GET",
		url: "interfaces/DesativarContaUsuario.php", 
		cache: false,

		beforeSend: function() {
			$("#controleUps").html("<img src='images/loading_circle_24_24' />");
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						$("#perguntaUps").html("Seu pedido de desativação foi realizado.");
						$("#infoUps").html("Dentro de algumas horas sua conta será totalmente desativada, enquanto isso você ainda poderá navegar no Ualah.com.");
						$("#controleUps").html('<img src="images/bt_ok.png" onclick="fncNaoDesativarConta();" />');
					}
				}
			}
		}
	});
}

function fncNaoDesativarConta() {
	$("#popUpsDesativarConta").remove();
}

function fncFecharSuaConta() {
	fncFecharFundoAcao();
	$("#popConta").remove();
}

function fncLoadPerfil() {
	$.ajax({
		url: "interfaces/ValidaLogin.php",
		cache: false,
		
		beforeSend: function() {
			$("body").html("<span class='loadBody'>Autenticando Usu&aacute;rio</span><br /><img src='images/loading_bar.gif'>");
		},
		
		success: function(callback){
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "C") {
						fncLoadVerificaIdioma("perfil");
					}
					else {
						document.location.href="index.shtml";
					}
				}
			}
		}
	});
}

function fncLoadConteudoPerfil(idioma) {
	var intervalQtdYupis;
	var intervalQtdConvites;
	var intervalPerfilOnline;
	var area = window.location.href.split("/");
	
	$.ajax({
		url: "ConteudoPerfil_"+idioma+".shtml",
		cache: false,

		success: function(callback){
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					$("body").html(callback);
					
					$("#idNameConta").html(IdNameConta);
					$("#fotoLocalPostar").html('<img src="images/fotos_users/'+FotoConta+'" width="48" height="48" />');
					$("#nomeUserLocalPerfilMenu").html('<a href="'+IdNameConta+'"><h1>Perfil <strong>['+IdNameConta+']</strong></h1></a>');
					
					fncLerCacheAssuntosMinimizados();
					
					fncObterNovosYupis("qtd");
					intervalQtdYupis = window.setInterval(function() {
						fncObterNovosYupis("qtd");
					}, 30000);
					
					fncObterConvites("qtd");
					intervalQtdConvites = window.setInterval(function() {
						fncObterConvites("qtd");
					}, 30000);
					
					
					fncAtualizarPerfilOnline();
					intervalPerfilOnline = window.setInterval(function() {
						fncAtualizarPerfilOnline();
					}, 30000);
					
				    fncObterUsuarios("amigos");
				    fncObterInteresses(IdNameConta,"usuario");
				    
				    $('#assunto').limit('150','#charsLeft');
				    
				    fncObterDadosPessoaisPerfil(area[4]);
				    
					$("body").click(function () { 
						if(statusOpcoesAssuntos == 1){
							$("#opcoesAssuntos").remove();
						}
					});
					
					$(function() {
						$("#assunto").keypress(function (e) {
							if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
								fncCadastrarAssunto();
								return false;
							} else {
								return true;
							}
						});
					});
					
					pageTracker._trackPageview("Usuario/"+area[4]+"");
				}
			}
		}
	});
}

function fncObterDadosPessoaisPerfil(IdName, tipo){
	var block;
	var favorito;
	var sexo;
	var intervalQtdMensagensPerfil;
	
	$.ajax({
		type: "GET",
		url: "interfaces/ObterDadosPessoaisPerfil.php",
		cache: false,
		data: {_idName:IdName},

		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					
					
					if(callback.substr(0,2) == "C1") {
						
						if(tipo == "editar"){
							$("#dadoNomePerfil").html(NomePerfil);
							$("#dadoSobrePerfil").html(SobrePerfil);
							
							if(SexoPerfil == "M") {
								sexo = "Masculino";
							}
							
							if(SexoPerfil == "F") {
								sexo = "Feminino";
							}
							
							if(SexoPerfil == "0") {
								sexo = "";
							}
							
							$("#dadoSexoPerfil").html(sexo);
							$("#dadoAniversarioPerfil").html(AniversarioPerfil);
							$("#dadoRelacionamentoPerfil").html(RelacionamentoPerfil);
							$("#dadoProfissaoPerfil").html(ProfissaoPerfil);
							$("#dadoLocalPerfil").html(LocalPerfil);
							$("#dadoContatoPerfil").html(ContatoPerfil);
							$("#dadoSalvarDados").html('<div id="btEditarDados" onclick="fncObterAbaDadosPessoaisPerfil();"></div>');
						}
						else {
							var objeto = eval(callback.substr(2));
							
							IdPerfil = objeto[0].IdPerfil;
							IdNamePerfil = IdName;
							NomePerfil = objeto[0].NomePerfil;
							SobrePerfil = objeto[0].SobrePerfil;
							SexoPerfil = objeto[0].SexoPerfil;							
							AniversarioPerfil = objeto[0].Aniversario;
							RelacionamentoPerfil = objeto[0].RelacionamentoPerfil;
							ProfissaoPerfil = objeto[0].ProfissaoPerfil;
							LocalPerfil = objeto[0].LocalPerfil;
							ContatoPerfil = objeto[0].ContatoPerfil;
							AdmPerfil = objeto[0].AdmPerfil;
							
							$("#pessoais").html('<div id="fotoPerfil"></div><div id="controleBotoesPerfil"></div><h1><span id="localNomePerfil"></span><span id="localLocalidadePerfil"></span><span id="localSobrePerfil"></span></h1>');
							$("#controleBotoesPerfil").append('<div id="btTrocarFoto"><h3></h3></div>');
							
							$("#userName").html(IdName);
							
							if(!objeto[0].FotoPerfil){
								$("#fotoPerfil").html('<img src="images/0amigos.png" width="198" height="198" />');
							}
							else {
								$("#fotoPerfil").html('<img src="images/fotos_users/'+objeto[0].FotoPerfil+'" width="198" height="198" />');
							}
							
							if(objeto[0].NomePerfil != "") {
								$("#localNomePerfil").html('<strong>Nome:</strong> <span id="nomePerfil">'+objeto[0].NomePerfil+'</span><br />'); 
							}
							
							if(objeto[0].LocalPerfil != "") {
								$("#localLocalidadePerfil").html('<strong>Local:</strong> <span id="localidadePerfil">'+objeto[0].LocalPerfil+'</span><br />');
							}
							
							if(objeto[0].SobrePerfil != "") {
								$("#localSobrePerfil").html('<strong>Sobre:</strong> <span id="sobrePerfil">'+objeto[0].SobrePerfil.substr(0,100)+'...</span>');
							}							
							
							$("#menuPerfil").html('<ul><li><h1 onclick="fncObterAbaAssuntosPerfil('+"'usuarios'"+','+objeto[0].IdPerfil+',0,10);">Ualadas</h1></li><li><h1 onclick="fncObterAbaDadosPessoaisPerfil();">Dados pessoais</h1></li><li><h1 onclick="fncObterAbaAmigosPerfil('+"'perfil'"+','+objeto[0].IdPerfil+');">Ualeiros</h1></li><li><h1 onclick="fncObterAbaInteressesPerfil();">Interesses</h1></li><li><h1 onclick="fncObterAbaConvide()">Convide Amigos</h1></li></ul>');
							$("#vertodosAmigos").html('<h1 onclick="fncObterAbaAmigosPerfil('+"'perfil'"+','+objeto[0].IdPerfil+');">Ver todos</h1>');
							
							$("#user").append('<h2 onclick="fncAbrirMensagensPerfil();">(<span id="qtdMensagemPvt"></span>) Bips</h2><h3 onclick="fncConfiguracoesPerfil()">Backgrounds</h3>');
							
							new AjaxUpload('#btTrocarFoto', {
							  // Location of the server-side upload script
							  action: 'interfaces/TrocarFoto.php',
							  // File upload name
							  name: 'image',
							  // Additional data to send
							  data: {upload:''},
							  // Submit file after selection
							  autoSubmit: true,
							  // The type of data that you're expecting back from the server.
							  // Html (text) and xml are detected automatically.
							  // Only useful when you are using json data as a response.
							  // Set to "json" in that case.
							  responseType: false,
							  // Fired after the file is selected
							  // Useful when autoSubmit is disabled
							  // You can return false to cancel upload
							  // @param file basename of uploaded file
							  // @param extension of that file
							  onChange: function(file, extension){},
							  // Fired before the file is uploaded
							  // You can return false to cancel upload
							  // @param file basename of uploaded file
							  // @param extension of that file
							  onSubmit : function(file , ext){
								if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
										// extension is not allowed
										alert('Formato de imagem inv&aacute;lido.');
										// cancel upload
										return false;
								}
								$('#btTrocarFoto').html("<img src='images/loading_circle_24_24_white.gif'>");
							  },
							  // Fired when file upload is completed
							  // @param file basename of uploaded file
							  // @param response server response
							  onComplete: function(file, response) {
								//alert(response);
								if(response == "C") {
									document.location.href=""+IdNameConta+"";
								}
								else {
									alert("Desculpe, imagem muito grande.");
									document.location.href=""+IdNameConta+"";
								}
							  }
							});
							
							fncObterQtdMensagensPerfil();
							intervalQtdMensagensPerfil = window.setInterval(function() {
								fncObterQtdMensagensPerfil();
							}, 10000);
							
							
							fncObterAbaAssuntosPerfil("usuarios",objeto[0].IdPerfil,"0","10");
							fncObterInteresses(IdNamePerfil,"perfil");
						    fncObterAmigosPerfil("perfil",IdPerfil);
						}
					}
					
					if(callback.substr(0,2) == "C2" || callback.substr(0,2) == "C4") {
						var objeto = eval(callback.substr(2));
						
						
						IdPerfil = objeto[0].IdPerfil;
						IdNamePerfil = IdName;
						NomePerfil = objeto[0].NomePerfil;
						SobrePerfil = objeto[0].SobrePerfil;
						SexoPerfil = objeto[0].SexoPerfil;
						AniversarioPerfil = objeto[0].Aniversario;
						RelacionamentoPerfil = objeto[0].RelacionamentoPerfil;
						ProfissaoPerfil = objeto[0].ProfissaoPerfil;
						LocalPerfil = objeto[0].LocalPerfil;
						ContatoPerfil = objeto[0].ContatoPerfil;
						AdmPerfil = objeto[0].AdmPerfil;
						
						$("#pessoais").html('<div id="fotoPerfil"></div><div id="controleBotoesPerfil"></div><h1><span id="localNomePerfil"></span><span id="localLocalidadePerfil"></span><span id="localSobrePerfil"></span></h1>');
						$("#controleBotoesPerfil").append('<span id="opcSendPerfil"><img src="images/icon_send.png" title="Enviar mensagem privada (bip)" onclick="fncAbrirMensagensPerfil('+"'usuario'"+','+IdPerfil+','+"'"+IdNamePerfil+"'"+')" /></span> <span id="opcDelAmigo"><img src="images/icon_delamigo.png" title="Excluir Amigo" onclick="fncExcluirAmigo('+objeto[0].IdPerfil+','+"'perfil'"+')" /></span> <span id="opcFavoritar">'+favorito+'</span>');
						
						if(objeto[0].Favorito == "1"){
							$("#opcFavoritar").html('<img src="images/icon_favorito.png" onclick="fncDesfavoritarAmigo('+objeto[0].IdPerfil+','+"'perfil'"+')" title="Desfavoritar Ualeiro" />');
						}
						else {
							$("#opcFavoritar").html('<img src="images/icon_naofavorito.png" onclick="fncFavoritarAmigo('+objeto[0].IdPerfil+','+"'perfil'"+')" title="Favoritar Ualeiro" />');
						}
						
						$("#userName").html(IdName);
						
						if(!objeto[0].FotoPerfil){
							$("#fotoPerfil").html('<img src="images/0amigos.png" width="198" height="198" />');
						}
						else {
							$("#fotoPerfil").html('<img src="images/fotos_users/'+objeto[0].FotoPerfil+'" width="198" height="198" />');
						}
						
						if(objeto[0].NomePerfil != "") {
							$("#localNomePerfil").html('<strong>Nome:</strong> <span id="nomePerfil">'+objeto[0].NomePerfil+'</span><br />'); 
						}
						
						if(objeto[0].LocalPerfil != "") {
							$("#localLocalidadePerfil").html('<strong>Local:</strong> <span id="localidadePerfil">'+objeto[0].LocalPerfil+'</span><br />');
						}
						
						if(objeto[0].SobrePerfil != "") {
							$("#localSobrePerfil").html('<strong>Sobre:</strong> <span id="sobrePerfil">'+objeto[0].SobrePerfil.substr(0,100)+'...</span>');
						}
						
						$("#menuPerfil").html('<ul><li><h1 onclick="fncObterAbaAssuntosPerfil('+"'usuarios'"+','+objeto[0].IdPerfil+',0,10);">Ualadas</h1></li><li><h1 onclick="fncObterAbaDadosPessoaisPerfil();">Dados pessoais</h1></li><li><h1 onclick="fncObterAbaAmigosPerfil('+"'perfil'"+','+objeto[0].IdPerfil+');">Ualeiros</h1></li><li><h1 onclick="fncObterAbaInteressesPerfil();">Interesses</h1></li></ul>');
						$("#vertodosAmigos").html('<h1 onclick="fncObterAbaAmigosPerfil('+"'perfil'"+','+objeto[0].IdPerfil+');">Ver todos</h1>');
						
						fncObterAbaAssuntosPerfil("usuarios",objeto[0].IdPerfil,"0","10");
						fncObterInteresses(IdNamePerfil,"perfil");
					    fncObterAmigosPerfil("perfil",IdPerfil);
					}
					
					if(callback.substr(0,2) == "C3" || callback.substr(0,2) == "C5") {
						var objeto = eval(callback.substr(2));
						
						
						IdPerfil = objeto[0].IdPerfil;
						IdNamePerfil = IdName;
						NomePerfil = objeto[0].NomePerfil;
						SobrePerfil = objeto[0].SobrePerfil;
						SexoPerfil = objeto[0].SexoPerfil;
						AniversarioPerfil = objeto[0].Aniversario;
						RelacionamentoPerfil = objeto[0].RelacionamentoPerfil;
						ProfissaoPerfil = objeto[0].ProfissaoPerfil;
						LocalPerfil = objeto[0].LocalPerfil;
						ContatoPerfil = objeto[0].ContatoPerfil;
						AdmPerfil = objeto[0].AdmPerfil;
						
						$("#pessoais").html('<div id="fotoPerfil"></div><div id="controleBotoesPerfil"></div><h1><span id="localNomePerfil"></span><span id="localLocalidadePerfil"></span><span id="localSobrePerfil"></span></h1>');
						$("#controleBotoesPerfil").append('<span id="opcBlockPerfil"></span> <span id="opcFavoritar"></span> <span id="opcAmigoPerfil"></span>');
						
						//
						
						if(objeto[0].Favorito == "1"){
							$("#opcFavoritar").html('<img src="images/icon_favorito.png" onclick="fncDesfavoritarAmigo('+objeto[0].IdPerfil+','+"'perfil'"+')" title="Desfavoritar Ualeiro" />');
						}
						else {
							$("#opcFavoritar").html('<img src="images/icon_naofavorito.png" onclick="fncFavoritarAmigo('+objeto[0].IdPerfil+','+"'perfil'"+')" title="Favoritar Ualeiro" />');
						}
						
						if(objeto[0].Pendente == "1") {
							$("#opcAmigoPerfil").html('<img src="images/icon_pendente.png" title="Aguardando Confirmação" />');
						}
						else {
							$("#opcAmigoPerfil").html('<img src="images/icon_addamigo.png" title="Adicionar como Amigo" onclick="fncConvidarAmigo('+objeto[0].IdPerfil+','+"'perfil'"+')" />');
						}
						
						if(objeto[0].Block == "1") {
					    	$("#opcBlockPerfil").html('<img src="images/icon_unblock.png" title="Desbloquear este Ualeiro" onclick="fncDesbloquearAmigo('+objeto[0].IdPerfil+','+"'perfil'"+')" />');
					    }
					    else {
					    	$("#opcBlockPerfil").html('<img src="images/icon_block.png" title="Bloquear este Ualeiro" onclick="fncBloquearAmigo('+objeto[0].IdPerfil+','+"'perfil'"+')" />');
					    }
						
						
						$("#userName").html(IdName);
						
						if(!objeto[0].FotoPerfil){
							$("#fotoPerfil").html('<img src="images/0amigos.png" width="198" height="198" />');
						}
						else {
							$("#fotoPerfil").html('<img src="images/fotos_users/'+objeto[0].FotoPerfil+'" width="198" height="198" />');
						}
						
						if(objeto[0].NomePerfil != "") {
							$("#localNomePerfil").html('<strong>Nome:</strong> <span id="nomePerfil">'+objeto[0].NomePerfil+'</span><br />'); 
						}
						
						if(objeto[0].LocalPerfil != "") {
							$("#localLocalidadePerfil").html('<strong>Local:</strong> <span id="localidadePerfil">'+objeto[0].LocalPerfil+'</span><br />');
						}
						
						if(objeto[0].SobrePerfil != "") {
							$("#localSobrePerfil").html('<strong>Sobre:</strong> <span id="sobrePerfil">'+objeto[0].SobrePerfil.substr(0,100)+'...</span>');
						}
						
						$("#menuPerfil").html('<ul><li><h1 onclick="fncObterAbaAssuntosPerfil('+"'usuarios'"+','+objeto[0].IdPerfil+',0,10);">Ualadas</h1></li><li><h1 onclick="fncObterAbaDadosPessoaisPerfil();">Dados pessoais</h1></li><li><h1 onclick="fncObterAbaAmigosPerfil('+"'perfil'"+','+objeto[0].IdPerfil+');">Ualeiros</h1></li><li><h1 onclick="fncObterAbaInteressesPerfil();">Interesses</h1></li></ul>');
						$("#vertodosAmigos").html('<h1 onclick="fncObterAbaAmigosPerfil('+"'perfil'"+','+objeto[0].IdPerfil+');">Ver todos</h1>');
						
						fncObterAbaAssuntosPerfil("usuarios",objeto[0].IdPerfil,"0","10");
						fncObterInteresses(IdNamePerfil,"perfil");
					    fncObterAmigosPerfil("perfil",IdPerfil);
					}
					
					if(callback.substr(0,2) == "C6") {
						var objeto = eval(callback.substr(2));
						
						IdPerfil = objeto[0].IdPerfil;
						IdNamePerfil = IdName;
						NomePerfil = objeto[0].NomePerfil;
						SobrePerfil = objeto[0].SobrePerfil;
						SexoPerfil = objeto[0].SexoPerfil;
						AniversarioPerfil = objeto[0].Aniversario;
						RelacionamentoPerfil = objeto[0].RelacionamentoPerfil;
						ProfissaoPerfil = objeto[0].ProfissaoPerfil;
						LocalPerfil = objeto[0].LocalPerfil;
						ContatoPerfil = objeto[0].ContatoPerfil;
						AdmPerfil = objeto[0].AdmPerfil;
					    
					    $("#pessoais").html('<div id="fotoPerfil"></div><div id="controleBotoesPerfil"></div><h1><span id="localNomePerfil"></span><span id="localLocalidadePerfil"></span><span id="localSobrePerfil"></span></h1>');
					    $("#controleBotoesPerfil").append('<span id="opcSendPerfil"><img src="images/icon_send.png" title="Enviar mensagem privada (bip)" onclick="fncAbrirMensagensPerfil('+"'usuario'"+','+objeto[0].IdPerfil+','+"'"+IdNamePerfil+"'"+')" /></span> <span id="opcBlockPerfil"></span> <span id="opcFavoritar"></span> <span id="opcAmigoPerfil"></span>');
					    
					    if(objeto[0].Favorito == "1"){
							$("#opcFavoritar").html('<img src="images/icon_favorito.png" onclick="fncDesfavoritarAmigo('+objeto[0].IdPerfil+','+"'perfil'"+')" title="Desfavoritar Ualeiro" />');
						}
						else {
							$("#opcFavoritar").html('<img src="images/icon_naofavorito.png" onclick="fncFavoritarAmigo('+objeto[0].IdPerfil+','+"'perfil'"+')" title="Favoritar Ualeiro" />');
						}
					    
					    if(objeto[0].Pendente == "1") {
							$("#opcAmigoPerfil").html('<img src="images/icon_pendente.png" title="Aguardando Confirmação" />');
						}
						else {
							$("#opcAmigoPerfil").html('<img src="images/icon_addamigo.png" title="Adicionar como Amigo" onclick="fncConvidarAmigo('+objeto[0].IdPerfil+','+"'perfil'"+')" />');
						}
					    
					    if(objeto[0].Block == "1") {
					    	$("#opcBlockPerfil").html('<img src="images/icon_unblock.png" title="Desbloquear este Ualeiro" onclick="fncDesbloquearAmigo('+objeto[0].IdPerfil+','+"'perfil'"+')" />');
					    }
					    else {
					    	$("#opcBlockPerfil").html('<img src="images/icon_block.png" title="Bloquear este Ualeiro" onclick="fncBloquearAmigo('+objeto[0].IdPerfil+','+"'perfil'"+')" />');
					    }
					    
						$("#userName").html(IdName);
						
						if(!objeto[0].FotoPerfil){
							$("#fotoPerfil").html('<img src="images/0amigos.png" width="198" height="198" />');
						}
						else {
							$("#fotoPerfil").html('<img src="images/fotos_users/'+objeto[0].FotoPerfil+'" width="198" height="198" />');
						}
						
						if(objeto[0].NomePerfil != "") {
							$("#localNomePerfil").html('<strong>Nome:</strong> <span id="nomePerfil">'+objeto[0].NomePerfil+'</span><br />'); 
						}
						
						if(objeto[0].LocalPerfil != "") {
							$("#localLocalidadePerfil").html('<strong>Local:</strong> <span id="localidadePerfil">'+objeto[0].LocalPerfil+'</span><br />');
						}
						
						if(objeto[0].SobrePerfil != "") {
							$("#localSobrePerfil").html('<strong>Sobre:</strong> <span id="sobrePerfil">'+objeto[0].SobrePerfil.substr(0,100)+'...</span>');
						}
						
						$("#menuPerfil").html('<ul><li><h1 onclick="fncObterAbaAssuntosPerfil('+"'usuarios'"+','+objeto[0].IdPerfil+',0,10);">Ualadas</h1></li><li><h1 onclick="fncObterAbaDadosPessoaisPerfil();">Dados pessoais</h1></li><li><h1 onclick="fncObterAbaAmigosPerfil('+"'perfil'"+','+objeto[0].IdPerfil+');">Ualeiros</h1></li><li><h1 onclick="fncObterAbaInteressesPerfil();">Interesses</h1></li></ul>');
						$("#vertodosAmigos").html('<h1 onclick="fncObterAbaAmigosPerfil('+"'perfil'"+','+objeto[0].IdPerfil+');">Ver todos</h1>');
						
						fncObterAbaAssuntosPerfil("usuarios",objeto[0].IdPerfil,"0","10");
						fncObterInteresses(IdName,"perfil");
					    fncObterAmigosPerfil("perfil",objeto[0].IdPerfil);
					}
					
					/*
					if(callback.substr(0,3) != "CPA" && callback.substr(0,3) != "CPB"){
						var objeto = eval(callback.substr(1));
						
						$("#userName").html(IdName);
						
						IdPerfil = objeto[0].IdPerfil;
						IdNamePerfil = IdName;
						NomePerfil = objeto[0].NomePerfil;
						SobrePerfil = objeto[0].SobrePerfil;
						SexoPerfil = objeto[0].SexoPerfil;
						AniversarioPerfil = objeto[0].Aniversario;
						RelacionamentoPerfil = objeto[0].RelacionamentoPerfil;
						ProfissaoPerfil = objeto[0].ProfissaoPerfil;
						LocalPerfil = objeto[0].LocalPerfil;
						ContatoPerfil = objeto[0].ContatoPerfil;
						AdmPerfil = objeto[0].AdmPerfil;
						
						fncObterInteresses(IdNamePerfil,"perfil");
					    fncObterAmigosPerfil("perfil",IdPerfil);
					    
					    if(objeto[0].Block == "1") {
					    	block = '<img src="images/icon_unblock.png" title="Desbloquear este Ualeiro" onclick="fncDesbloquearAmigo('+objeto[0].IdPerfil+','+"'perfil'"+')" />';
					    }
					    else {
					    	block = '<img src="images/icon_block.png" title="Bloquear este Ualeiro" onclick="fncBloquearAmigo('+objeto[0].IdPerfil+','+"'perfil'"+')" />';
					    }
						
						$("#nomePerfil").html(objeto[0].NomePerfil);
						$("#localidadePerfil").html(objeto[0].LocalPerfil);
						$("#pessoais").html('<div id="fotoPerfil"></div><div id="controleBotoesPerfil"></div>');
						
						if(IdNamePerfil != IdNameConta) {
							$("#controleBotoesPerfil").append('<img src="images/icon_send.png" title="Enviar mensagem privada (bip)" onclick="fncAbrirMensagensPerfil('+"'usuario'"+','+IdPerfil+','+"'"+IdNamePerfil+"'"+')" /> <img src="images/icon_delamigo.png" title="Excluir Amigo" onclick="fncExcluirAmigo('+objeto[0].IdPerfil+','+"'perfil'"+')" /> '+block+'');
						}
						
						if(AdmPerfil == "S") {
							
						}
						
						
					}
					*/
				}
			}
		}
	});
}

var tipoService;

function fncObterAbaConvide() {
	$("#conteudoAbaAssuntos").hide();
	$("#conteudoAbaDadosPessoais").hide();
	$("#conteudoAbaAmigos").hide();
	$("#conteudoAbaInteresses").hide();
	$("#conteudoAbaConvite").show();
	$("#controleAbaAssuntos").html('');

	$("#conteudoAbaConvite").html('<div id="dados"><h1>Convide seus amigos para o Ualah!</h1><h2>Agora você pode convidar seus amigos para o Ualah! <br />Escolha o serviço de sua preferencia e envie convites!</h2></div><div id="convideEmail"><h1>Convites por E-mail</h1><input type="text" id="emailsIndividual" /><div id="btEnviar" onclick="fncEnviarEmailsIndiviual()"></div><h2>Digite endereços de e-mail separados por virgula, ex.: james@email.com,anne@email.com</h2></div><div id="convideContatos"><h1>Convide seus contatos</h1><h2>Carregue seus contatos, envie e gerencie convites</h2><div id="services"><ul><li class="gmail" onclick="fncTrocarService('+"'gmail'"+')">Gmail</li><li class="hotmail" onclick="fncTrocarService('+"'hotmail'"+')">Hotmail</li><li class="yahoo" onclick="fncTrocarService('+"'yahoo'"+')">Yahoo</li></ul></div><div id="form"><h1>Login:</h1> <input type="text" id="loginService" /><h1>Senha:</h1> <input type="text" id="passwordService" /><h2>O Ualah nao salvará seus dados de acesso</h2><div id="btOk" onclick="call();"></div></div></div>');
}


function fncTrocarService(tipo) {
	tipoService = tipo;
}

var mvcAction = new ualah.util.Mvc();
var params = new ualah.util.Dictionary();

function call(){
	
	fncAbrirFundoAcao();
	$("body").append('<div id="popConvide"><div id="titulo"><h1>Convide Amigos</h1><h3 onclick="fncFecharConvide()">Fechar</h3></div><div id="dados"><h1>Selecione os contatos que deseja convidar e encontre quem já está no Ualah!</h1></div><div id="opcoes"><ul><li id="opcAbaUsuarios" class="ativo"><h2 onclick="fncOpcoesConvide(1,this)">Veja quem já está no Ualah!</h2></li><li id="opcAbaConvide" class="inativo"><h2 onclick="fncOpcoesConvide(2,this)">Convide seus contatos</h2></li></ul></div><div id="conteudo"><div id="localInfos"><h1>Alguns de seus contatos já estão cadastrados no Ualah! Clique no nome escolhido e visualize o perfil.</h1><h2 id="userMailConvite"></h2><div id="marcar"></div></div><div id="localUsuariosConvite"></div><div id="localContatosConvite"></div><div id="botoesConvide"></div></div></div>');
	$("#localUsuariosConvite").show();
	$("#botoesConvide").html('<div id="btConvideAgora" onclick="fncOpcoesConvide(2)"></div>');
	
	
	$("#userMailConvite").html($("#loginService").val());
	
	$("#localUsuariosConvite").html("<div id='loadingMensagens'><img src='images/loading_cubo_white.gif' /></div>");
	$("#localContatosConvite").html("<div id='loadingMensagens'><img src='images/loading_cubo_white.gif' /></div>");

	params.Clear();
	params.Add("login", $("#loginService").val())
		  .Add("senha", $("#passwordService").val())
		  .Add("service", tipoService);
	mvcAction.Action("Connect")
			 .Controller("Invite")
			 .Parameters(params.ToQueryString())
			 .Send(function(data) {
				data = data.substring(1, data.length);
                        if(result.Message == "OK") {

							$("#localUsuariosConvite").html('<ul id="listaLocalUsuarios"></ul>');
							$("#localContatosConvite").html('<form name="f1"><ul id="listaLocalContatos"></ul></form>');

                            for(i = 0; i < result.Data.length; i++){
                                if(result.Data[i].STATUS == 1){
                                    $("#listaLocalUsuarios").append('<li><div id="foto"><img src="images/fotos_users/'+result.Data[i].FOTO+'" /></div><h1>@'+result.Data[i].EMAIL+'</h1><h2>'+result.Data[i].IDNAME+'</h2></li>');
                                }
								

								if(result.Data[i].STATUS == 2){
                                    $("#listaLocalContatos").append('<li><div id="logoh"></div> <h1 class="convidado">'+result.Data[i].EMAIL+' já foi convidado (a)! </h1></li>');
                                }
						

								if(result.Data[i].STATUS == 3){
                                    $("#listaLocalContatos").append('<li><input type="checkbox" value="'+result.Data[i].EMAIL+'"> <h1>'+result.Data[i].EMAIL+'</h1></li>');
                                }
		
                            }
                       }
					   else {
						   fncFecharFundoAcao();
							$("#popConvide").remove();
							alert("Houve um erro ao acessar este serviço, tente novamente mais tarde.");
					   }
			 });
}

function fncEnviarEmails() {
	for (i=0;i<document.f1.elements.length;i++) {
		if(document.f1.elements[i].checked == 1) {
			listaEmail.push(document.f1.elements[i].value);
		}
	}
	
	alert(listaEmail.toString())

	

	params.Add("emails", listaEmail);
		mvcAction.Action("Save") // Nome da a��o
                 .Controller("Invite") //nome do controlador
                .Parameters(params.ToQueryString())
                 .Send(function(data) {
                        var result = eval('(' + data + ')');
                        alert(result.Message);
                 });
	}
	


function fncEnviarEmailsIndiviual() {
	var listaEmailIndividual = $("#emailsIndividual").val();
	params.Add("emails", listaEmailIndividual);
		mvcAction.Action("Save") // Nome da a��o
                 .Controller("Invite") //nome do controlador
                .Parameters(params.ToQueryString())
                 .Send(function(data) {
                        var result = eval('(' + data + ')');
                        alert(result.Message);
                 });
	}



function fncFecharConvide() {
	fncFecharFundoAcao();
	$("#popConvide").remove();
}

function fncOpcoesConvide(opcao, item) {
	if(opcao == 1) {
		
		$("#marcar").html('');
		
		$("#botoesConvide").html('<div id="btConvideAgora" onclick="fncOpcoesConvide(2)"></div>');

		$("#opcAbaUsuarios").removeClass('inativo');
		$("#opcAbaUsuarios").addClass('ativo');
		$("#opcAbaConvide").removeClass('ativo');
		$("#opcAbaConvide").addClass('inativo');

		$("#localUsuariosConvite").show();
		$("#localContatosConvite").hide();
	}
	
	if(opcao == 2) {
	
		$("#marcar").html('<ul><li><input type="radio" name="marcar" onclick="selecionar_tudo()"> <h3>Marcar todos</h3></li><li><input type="radio" name="marcar" onclick="deselecionar_tudo()"> <h3>Desmarcar todos</h3></li></ul>');
		
		$("#botoesConvide").html('<div id="btEnviar" onclick="fncEnviarEmails()"></div><div id="btCancelar" onclick="fncFecharConvide()"></div>');

		$("#opcAbaUsuarios").removeClass('ativo');
		$("#opcAbaUsuarios").addClass('inativo');
		$("#opcAbaConvide").removeClass('inativo');
		$("#opcAbaConvide").addClass('ativo');
		
		$("#localUsuariosConvite").hide();
		$("#localContatosConvite").show();
	}
}

function selecionar_tudo(){
   for (i=0;i<document.f1.elements.length;i++)
      if(document.f1.elements[i].type == "checkbox")
         document.f1.elements[i].checked=1
}

function deselecionar_tudo(){
   for (i=0;i<document.f1.elements.length;i++)
      if(document.f1.elements[i].type == "checkbox")
         document.f1.elements[i].checked=0
} 


function fncObterAmigosPerfil(tipo, IdPerfil){
	$.ajax({
		type: "GET",
		url: "interfaces/ObterUsuarios.php",
		cache: false,
		data: {_tipo:tipo, _idPerfil:IdPerfil},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					var objeto = eval(callback.substr(2));
					
					amigosPerfil = callback;
					
					if(callback.substr(2,4) != "null"){						
						
						$("#qtdUaleirosPerfil").html(objeto.length);
						
						if(callback.substr(0,2) == "C1") {
							for(x = 0; x < objeto.length; x++) {
								if(x <= 11) {
									$("#itensAmigosPerfil").append('<li><a href="'+objeto[x].IdName+'"><img src="images/fotos_users/'+objeto[x].Foto+'" title="'+objeto[x].IdName+'" width="35" height="35" /></a></li>');
								}
							}
						}
						
						if(callback.substr(0,2) == "C2" || callback.substr(0,2) == "C4") {
							for(x = 0; x < objeto.length; x++) {
								if(x <= 11) {
									$("#itensAmigosPerfil").append('<li><a href="'+objeto[x].IdName+'"><img src="images/fotos_users/'+objeto[x].Foto+'" title="'+objeto[x].IdName+'" width="35" height="35" /></a></li>');
								}
							}
						}
						
						if(callback.substr(0,2) == "C3" || callback.substr(0,2) == "C5") {
							$("#conteudoAmigosPerfil").html('<div id="semAmigos"><h1>Lista Privada.</h1></div>');
						}
						
						if(callback.substr(0,2) == "C6") {
							for(x = 0; x < objeto.length; x++) {
								if(x <= 11) {
									$("#itensAmigosPerfil").append('<li><a href="'+objeto[x].IdName+'"><img src="images/fotos_users/'+objeto[x].Foto+'" title="'+objeto[x].IdName+'" width="35" height="35" /></a></li>');
								}
							}
						}
						
						
					}
					else {
						
						$("#qtdUaleirosPerfil").html("0");
						
						if(callback.substr(0,2) == "C1") {
							$("#conteudoAmigosPerfil").html('<div id="semAmigos"><h1>Lista Vazia.</h1></div>');
						}
						
						if(callback.substr(0,2) == "C2" || callback.substr(0,2) == "C4") {
							$("#conteudoAmigosPerfil").html('<div id="semAmigos"><h1>Lista Vazia.</h1></div>');
						}
						
						if(callback.substr(0,2) == "C3" || callback.substr(0,2) == "C5") {
							$("#conteudoAmigosPerfil").html('<div id="semAmigos"><h1>Lista Privada.</h1></div>');
						}
						
						if(callback.substr(0,2) == "C6") {
							$("#conteudoAmigosPerfil").html('<div id="semAmigos"><h1>Lista Vazia.</h1></div>');
						}
					}
				}
			}
		}
	});
}

var numIniPagAssunto = 0;
var cadeadoAssuntoPvtPerfil;

function fncObterAbaAssuntosPerfil(tipo, IdPerfil, LimitIni, LimitFim, local) {	
	var adm;
	
	$("#conteudoAbaAssuntos").show();
	$("#conteudoAbaDadosPessoais").hide();
	$("#conteudoAbaAmigos").hide();
	$("#conteudoAbaInteresses").hide();
	$("#conteudoAbaConvite").hide();
	
	if(local != "mais"){
		$("#conteudoAbaAssuntos").html('');
		numIniPagAssunto = 0;
	}
	
	
	$.ajax({
		type: "GET",
		url: "interfaces/ObterAssuntos.php",
		cache: false,
		data: {_tipo:tipo, _idPerfil:IdPerfil, _limitIniUsuarios:numIniPagAssunto},
		
		beforeSend: function() {
			if(local == "mais"){
				$("#controleAbaAssuntos").html("<img src='images/loading_circle_24_24_white.gif'>");
			}
			else {
				$("#conteudoAbaAssuntos").html("<img src='images/loading_circle_24_24_white.gif'>");
			}
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					
					if(local != "mais"){
						$("#conteudoAbaAssuntos").html("");
					}
					
					var objeto = eval(callback.substr(2));
					if(callback.substr(2,4) != "null"){
						//$("#controleAbaAssuntos").html('<img src="images/bt_mais.jpg" onclick="fncObterAbaAssuntosPerfil('+"'"+tipo+"'"+','+IdPerfil+','+numIniPagAssunto+',10, '+"'mais'"+')" />');
						
						if(callback.substr(0,2) == "C1") {
							for(x = 0; x < objeto.length; x++) {
								if(objeto[x].AssPvt == "1") {
									cadeadoAssuntoPvtPerfil = '<img src="images/lock.png" title="Ualada Privada." /> ';
								}
								else {
									cadeadoAssuntoPvtPerfil = '';
								}
								$("#conteudoAbaAssuntos").append('<div id="assunto"><div id="foto"><img src="images/fotos_users/'+objeto[x].FotoPerfil+'" width="35" height="35" /></div><div id="privado">'+cadeadoAssuntoPvtPerfil+'</div><div id="descricao"><p onclick="fncAbrirAssunto(' + objeto[x].IdAssunto + ', this, ' + objeto[x].IdPerfil + ', '+"'perfil'"+','+objeto[x].Favorito+','+objeto[x].Acomp+','+"'"+objeto[x].Tema+"'"+');">'+objeto[x].Descricao+'</p><div id="data">'+objeto[x].Data+' as '+objeto[x].Hora+'</div><div id="controle"><img src="images/bt_excluir.png" onclick="fncExcluirAssunto('+objeto[x].IdAssunto+', this);" /></div><div id="respostas"><h1>'+objeto[x].QtdPosts+' respostas</h1></div></div></div>');
							}
						}
						
						if(callback.substr(0,2) == "C2" || callback.substr(0,2) == "C4") {
							for(x = 0; x < objeto.length; x++) {
								$("#conteudoAbaAssuntos").append('<div id="assunto"><div id="foto"><img src="images/fotos_users/'+objeto[x].FotoPerfil+'" width="35" height="35" /></div><div id="descricao"><p onclick="fncAbrirAssunto(' + objeto[x].IdAssunto + ', this, ' + objeto[x].IdPerfil + ', '+"'perfil'"+','+objeto[x].Favorito+','+objeto[x].Acomp+','+"'"+objeto[x].Tema+"'"+');">'+objeto[x].Descricao+'</p><div id="data">'+objeto[x].Data+' as '+objeto[x].Hora+'</div><div id="controle"></div><div id="respostas"><h1>'+objeto[x].QtdPosts+' respostas</h1></div></div></div>');
							}
						}
						
						if(callback.substr(0,2) == "C3" || callback.substr(0,2) == "C5") {
							$("#conteudoAbaAssuntos").html('<div id="semAssuntos"><h1>Ualadas Privadas.</h1></div>');
						}
						
						if(callback.substr(0,2) == "C6") {
							for(x = 0; x < objeto.length; x++) {
								$("#conteudoAbaAssuntos").append('<div id="assunto"><div id="foto"><img src="images/fotos_users/'+objeto[x].FotoPerfil+'" width="35" height="35" /></div><div id="descricao"><p onclick="fncAbrirAssunto(' + objeto[x].IdAssunto + ', this,' + objeto[x].IdPerfil + ', '+"'perfil'"+','+objeto[x].Favorito+','+objeto[x].Acomp+','+"'"+objeto[x].Tema+"'"+');">'+objeto[x].Descricao+'</p><div id="data">'+objeto[x].Data+' as '+objeto[x].Hora+'</div><div id="controle"></div><div id="respostas"><h1>'+objeto[x].QtdPosts+' respostas</h1></div></div></div>');
							}
						}
						
						numIniPagAssunto = numIniPagAssunto + 10;
						
						if(objeto.length < 10){
							$("#controleAbaAssuntos").html('');
						}
						else {
							$("#controleAbaAssuntos").html('<img src="images/bt_mais.jpg" onclick="fncObterAbaAssuntosPerfil('+"'"+tipo+"'"+','+IdPerfil+','+numIniPagAssunto+',10, '+"'mais'"+')" />');
						}
					}
					else {
						if(numIniPagAssunto == 0) {
							$("#conteudoAbaAssuntos").html('<div id="semAssuntos"><h1>Este usuário ainda não possui Ualadas.</h1></div>');
						}
					}
					
					pageTracker._trackPageview("Perfil/Ualadas");
				}
			}
		}
	});
}

function fncCadastrarPrivacidade(aba){
	var privacidade = $("#privacidade"+aba+" option:selected").val();
	
	$.ajax({
		type: "POST",
		url: "interfaces/CadastrarPrivacidade.php",
		cache: false,
		data: {_aba:aba, _privacidade:privacidade},
		
		beforeSend: function() {
			//$("#loadEditarPerfil").html('<img src="images/loading_circle_24_24_white.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC"){
						fncAbrirFundoAcao();
						if(privacidade == 1) {
							$("body").append('<div id="popUpsPrivacidade" class="popUps"><div id="titulo"><h1 id="tituloUps">Ups!</h1></div><div id="conteudo"><h1 id="perguntaUps">Privacidade alterada</h1><h2 id="infoUps">Agora todos os ualeiros poderam ver estes dados.</h2><div id="controleUps"><img src="images/bt_ok.png" onclick="fncFecharPopPrivacidade();" /></div></div></div>');
							privacidade1 = 1;
						}
						else {
							$("body").append('<div id="popUpsPrivacidade" class="popUps"><div id="titulo"><h1 id="tituloUps">Ups!</h1></div><div id="conteudo"><h1 id="perguntaUps">Privacidade alterada</h1><h2 id="infoUps">Agora apenas seus amigos poderam ver estes dados.</h2><div id="controleUps"><img src="images/bt_ok.png" onclick="fncFecharPopPrivacidade();" /></div></div></div>');
							privacidade1 = 2;
						}
					}
				}
			}
		}
	});
}

function fncFecharPopPrivacidade() {
	fncFecharFundoAcao();
	$("#popUpsPrivacidade").remove();
}

function fncObterAbaDadosPessoaisPerfil() {	
	var sexom;
	var sexof;
	var opcTodos1;
	var opcAmigos1;
	
	$("#conteudoAbaAssuntos").hide();
	$("#conteudoAbaDadosPessoais").show();
	$("#conteudoAbaAmigos").hide();
	$("#conteudoAbaInteresses").hide();
	$("#conteudoAbaConvite").hide();
	$("#controleAbaAssuntos").html('');
	
	$("#conteudoAbaDadosPessoais").html('<div id="privacidade1" class="privacidade"></div> <div id="linha"><h1>Nome:</h1><div id="dadoNomePerfil"></div></div><div id="linha"><h1>Sobre você:</h1><div id="dadoSobrePerfil"></div></div><div id="linha"><h1>Sexo:</h1><div id="dadoSexoPerfil"></div></div><div id="linha"><h1>Data de aniversário:</h1><div id="dadoAniversarioPerfil"></div></div><div id="linha"><h1>Relacionamento:</h1><div id="dadoRelacionamentoPerfil"></div></div><div id="linha"><h1>Profissão:</h1><div id="dadoProfissaoPerfil"></div></div><div id="linha"><h1>Local:</h1><div id="dadoLocalPerfil"></div></div><div id="linha"><h1>Contato:</h1><div id="dadoContatoPerfil"></div></div><div id="dadoSalvarDados"></div><div id="loadEditarPerfil"></div>');
	
	if(AdmPerfil == "S"){
		
		if(privacidade1 == 1) {
			opcTodos1 = "selected";
		}
		
		if(privacidade1 == 2) {
			opcAmigos1 = "selected";
		}
		
		//$("#privacidade1").html('<h2>Quem ve estes dados?</h2><select id="privacidade1"><option value="1" '+opcTodos1+'>Todos</option><option value="2" '+opcAmigos1+'>Apenas Amigos</option></select> <input type="button" value="ok" onclick="fncCadastrarPrivacidade(1)">');
		$("#dadoNomePerfil").html('<input type="text" id="inputNomePerfil" class="campos" value="'+NomePerfil+'" />');
		if(SexoPerfil == "M") { sexom = "checked"; }
		if(SexoPerfil == "F") {	sexof = "checked"; }
		$("#dadoSobrePerfil").html('<textarea class="textarea" id="inputSobrePerfil">'+SobrePerfil+'</textarea>');
		$("#dadoSexoPerfil").html('<ul><li><input type="radio" name="inputSexoPerfil" value="M" '+sexom+'> <h1>Masculino</h1></li><li><input type="radio" name="inputSexoPerfil" value="F" '+sexof+'> <h1>Feminino</h1></li></ul>');
		$("#dadoAniversarioPerfil").html('<input type="text" id="inputAniversarioPerfil" class="campos" value="'+AniversarioPerfil+'" />');
		$("#dadoRelacionamentoPerfil").html('<input type="text" id="inputRelacionamentoPerfil" class="campos" value="'+RelacionamentoPerfil+'" />');
		$("#dadoProfissaoPerfil").html('<input type="text" id="inputProfissaoPerfil" class="campos" value="'+ProfissaoPerfil+'" />');
		$("#dadoLocalPerfil").html('<input type="text" id="inputLocalPerfil" class="campos" value="'+LocalPerfil+'" />');
		$("#dadoContatoPerfil").html('<input type="text" id="inputContatoPerfil" class="campos" value="'+ContatoPerfil+'" />');
		$("#dadoSalvarDados").html('<div id="btSalvarDados" onclick="fncEditarDadosPessoaisPerfil();"></div>');
		
		$("#inputAniversarioPerfil").mask("99/99/9999");
	}
	
	if(AdmPerfil == "N"){
		$("#dadoNomePerfil").html(NomePerfil);
		$("#dadoSobrePerfil").html(SobrePerfil);
		$("#dadoSexoPerfil").html(SexoPerfil);
		$("#dadoAniversarioPerfil").html(AniversarioPerfil);
		$("#dadoRelacionamentoPerfil").html(RelacionamentoPerfil);
		$("#dadoProfissaoPerfil").html(ProfissaoPerfil);
		$("#dadoLocalPerfil").html(LocalPerfil);
		$("#dadoContatoPerfil").html(ContatoPerfil);
	}
	
	pageTracker._trackPageview("Perfil/DadosPessoais");
}

function fncEditarDadosPessoaisPerfil() {
	var nomePerfil = $("#inputNomePerfil").val();
	var sobrePerfil = $("#inputSobrePerfil").val();
	var sexoPerfil = $("input[name='inputSexoPerfil']:checked").val();
	var aniversarioPerfil = $("#inputAniversarioPerfil").val();
	var relacionamentoPerfil = $("#inputRelacionamentoPerfil").val();
	var profissaoPerfil = $("#inputProfissaoPerfil").val();
	var localPerfil = $("#inputLocalPerfil").val();
	var contatoPerfil = $("#inputContatoPerfil").val();
	
	
	
	if(!sexoPerfil) {
		sexoPerfil = 0;
	}
	
	$.ajax({
		type: "GET",
		url: "interfaces/EditarDadosPessoaisPerfil.php",
		cache: false,
		data: {nome:nomePerfil, sobre:sobrePerfil, sexo:sexoPerfil, aniversario:aniversarioPerfil, relacionamento:relacionamentoPerfil, profissao:profissaoPerfil, local:localPerfil, contato:contatoPerfil},
		
		beforeSend: function() {
			$("#loadEditarPerfil").html('<img src="images/loading_circle_24_24_white.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				//document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC"){
						$("#loadEditarPerfil").html('');
						
						NomePerfil = nomePerfil;
						SexoPerfil = sexoPerfil;
						SobrePerfil = sobrePerfil;
						AniversarioPerfil = aniversarioPerfil;
						RelacionamentoPerfil = relacionamentoPerfil;
						ProfissaoPerfil = profissaoPerfil;
						LocalPerfil = localPerfil;
						ContatoPerfil = contatoPerfil;
						
						fncObterDadosPessoaisPerfil(IdNamePerfil, "editar");
					}
				}
			}
		}
	});
}

function fncObterAbaInteressesPerfil() {	
	var adm;
	var opcTodos3;
	var opcAmigos3;
	
	$("#conteudoAbaAssuntos").hide();
	$("#conteudoAbaDadosPessoais").hide();
	$("#conteudoAbaAmigos").hide();
	$("#conteudoAbaInteresses").show();
	$("#conteudoAbaConvite").hide();
	$("#controleAbaAssuntos").html('');
	
	$("#itensAbaInteressesPerfil").html('');
	$("#conteudoAbaInteresses").html('<div id="privacidade3" class="privacidade"></div>');


	
	if(AdmPerfil == "S") {
		
		if(privacidade3 == 1) {
			opcTodos3 = "selected";
		}
		
		if(privacidade3 == 2) {
			opcAmigos3 = "selected";
		}
		
		//$("#privacidade3").html('<h2>Quem ve estes dados?</h2><select id="privacidade3"><option value="1" '+opcTodos3+'>Todos</option><option value="2" '+opcAmigos3+'>Apenas Amigos</option></select> <input type="button" value="ok" onclick="fncCadastrarPrivacidade(3)">');
		
		$("#conteudoAbaInteresses").append('<div id="adicionar"><div id="titulo"><h1>Adicionar Interesses</h1></div><div id="conteudo"><div id="linha"><h1>#</h1><input type="text" id="nomeInteresse" /></div><div id="linha"><h2>Descrição:</h2><input type="text" id="descricaoInteresse" /></div><div id="btAdicionar" onclick="fncCadastrarInteresse();"></div><div id="loadAdicionarInteresse"></div></div></div><div id="titulo"><h1>Lista de interesses</h1></div><ul id="itensAbaInteressesPerfil"></ul>');

		$(function() {
			$("#conteudoAbaInteresses").keypress(function (e) {
				if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
					fncCadastrarInteresse();
					return false;
				} else {
					return true;
				}
			});
		});

	}
	else {
		$("#conteudoAbaInteresses").append('<div id="titulo"><h1>Lista de interesses</h1></div><ul id="itensAbaInteressesPerfil"></ul>');
	}
	
	if(interessesPerfil.substr(2,4) != "null"){
	
		var objeto = eval(interessesPerfil.substr(2));
	
		if(interessesPerfil.substr(0,2) == "C1") {
			for(x = 0; x < objeto.length; x++) {
				if(AdmPerfil == "S") {
					adm = '<h2 onclick="fncExcluirInteresse('+objeto[x].InteressesId+', this);"></h2>';
				}
				else {
					adm = '';
				}
				$("#itensAbaInteressesPerfil").append('<li><h1><strong>#'+objeto[x].InteressesNome+'</strong> ['+objeto[x].InteressesDescricao+']</h1> '+adm+'</li>');
			}
		}
		
		if(interessesPerfil.substr(0,2) == "C2" || interessesPerfil.substr(0,2) == "C4") {
			for(x = 0; x < objeto.length; x++) {
				if(AdmPerfil == "S") {
					adm = '<h2 onclick="fncExcluirInteresse('+objeto[x].InteressesId+', this);"></h2>';
				}
				else {
					adm = '';
				}
				$("#itensAbaInteressesPerfil").append('<li><h1><strong>#'+objeto[x].InteressesNome+'</strong> ['+objeto[x].InteressesDescricao+']</h1> '+adm+'</li>');
			}
		}
		
		if(interessesPerfil.substr(0,2) == "C3" || interessesPerfil.substr(0,2) == "C5") {
			$("#itensAbaInteressesPerfil").html('<div id="semInteresses"><h1>Lista Privada.</h1></div>');
		}
		
		if(interessesPerfil.substr(0,2) == "C6") {
			for(x = 0; x < objeto.length; x++) {
				if(AdmPerfil == "S") {
					adm = '<h2 onclick="fncExcluirInteresse('+objeto[x].InteressesId+', this);"></h2>';
				}
				else {
					adm = '';
				}
				$("#itensAbaInteressesPerfil").append('<li><h1><strong>#'+objeto[x].InteressesNome+'</strong> ['+objeto[x].InteressesDescricao+']</h1> '+adm+'</li>');
			}
		}
	}
	else {
		if(interessesPerfil.substr(0,2) == "C1") {
			$("#itensAbaInteressesPerfil").html('<div id="semInteresses"><h1>Lista Vazia.</h1></div>');
		}
		
		if(interessesPerfil.substr(0,2) == "C2" || interessesPerfil.substr(0,2) == "C4") {
			$("#itensAbaInteressesPerfil").html('<div id="semInteresses"><h1>Lista Vazia.</h1></div>');
		}
		
		if(interessesPerfil.substr(0,2) == "C3" || interessesPerfil.substr(0,2) == "C5") {
			$("#itensAbaInteressesPerfil").html('<div id="semInteresses"><h1>Lista Privada.</h1></div>');
		}
		
		if(interessesPerfil.substr(0,2) == "C6") {
			$("#itensAbaInteressesPerfil").html('<div id="semInteresses"><h1>Lista Vazia.</h1></div>');
		}
	}
	
	pageTracker._trackPageview("Perfil/Interesses");
}

function fncCadastrarInteresse() {
	var _nomeInteresse = $("#nomeInteresse").val();
	var _descricaoInteresse = $("#descricaoInteresse").val();
	
	$.ajax({
		type: "GET",
		url: "interfaces/CadastrarInteressesPerfil.php",
		data: {_interesse:_nomeInteresse, _descInteresse:_descricaoInteresse},
		cache: false,
		
		beforeSend: function() {
			$("#loadAdicionarInteresse").html('<img src="images/loading_circle_24_24.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					fncObterInteresses(IdNamePerfil, "abaperfil");
					$("#nomeInteresse").val("");
					$("#descricaoInteresse").val("");
					$("#loadAdicionarInteresse").html('');
				}
			}
		}
	});
}

function fncExcluirInteresse(IdInteresse, item) {
	fncAbrirFundoAcao();
	var interesseItem = $(item.parentNode.childNodes[0].childNodes[0]).html();
	$("body").append('<div id="popUpsExcluirInteresse" class="popUps"><div id="titulo"><h1 id="tituloUps">Ups!</h1></div><div id="conteudo"><h1 id="perguntaUps">Deseja excluir este interesse:</h1><h2 id="infoUps">'+interesseItem+'</h2><div id="controleUps"><img src="images/bt_sim.png" onclick="fncConfirmarExcluirInteresse('+IdInteresse+');" /> <img src="images/bt_nao.png" onclick="fncNaoExcluirInteresse();" /></div></div></div>');
}

function fncNaoExcluirInteresse() {
	fncFecharFundoAcao();
	$("#popUpsExcluirInteresse").remove();
}

function fncConfirmarExcluirInteresse(IdInteresse) {
	$.ajax({
		type: "GET",
		url: "interfaces/ExcluirInteressesPerfil.php",
		data: {_idInteresse:IdInteresse}, 
		cache: false,
		
		beforeSend: function() {
			$("#controleUps").html('<img src="images/loading_circle_24_24.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						fncFecharFundoAcao();
						$("#popUpsExcluirInteresse").remove();
						fncObterInteresses(IdNamePerfil, "abaperfil");
					}
				}
			}
		}
	});
}

function fncObterAbaAmigosPerfil(tipo, IdPerfil) {	
	var opcTodos2;
	var opcAmigos2;
	
	$("#conteudoAbaAssuntos").hide();
	$("#conteudoAbaDadosPessoais").hide();
	$("#conteudoAbaAmigos").show();
	$("#conteudoAbaInteresses").hide();
	$("#conteudoAbaConvite").hide();
	$("#controleAbaAssuntos").html('');
	
	var objeto = eval(amigosPerfil.substr(2));
	
	$("#conteudoAbaAmigos").html('<div id="privacidade2" class="privacidade"></div>');
	
	if(AdmPerfil == "S"){
		if(privacidade2 == 1) {
			opcTodos2 = "selected";
		}
		
		if(privacidade2 == 2) {
			opcAmigos2 = "selected";
		}
		
		//$("#privacidade2").html('<h2>Quem ve estes dados?</h2><select id="privacidade2"><option value="1" '+opcTodos2+'>Todos</option><option value="2" '+opcAmigos2+'>Apenas Amigos</option></select> <input type="button" value="ok" onclick="fncCadastrarPrivacidade(2)">');
	}
	
	if(amigosPerfil.substr(2,4) != "null"){
		for(x = 0; x < objeto.length; x++) {			
			if(objeto[x].Fa == "1"){
				$("#conteudoAbaAmigos").append('<div id="amigo"><div id="foto"><a href="'+objeto[x].IdName+'"><img src="images/fotos_users/'+objeto[x].Foto+'" width="45" height="45" /></a></div><div id="dadosUser"><h1><a href="'+objeto[x].IdName+'">'+objeto[x].IdName+'</a></h1><h2><strong>Nome:</strong> '+objeto[x].Nome+'</h2><h3><strong>Local:</strong> '+objeto[x].Local+'</h3><div id="favoritar"><img src="images/icon_favorito.png" onclick="fncDesfavoritarAmigo('+objeto[x].IdPerfil+','+"'aba'"+', this)" title="Desfavoritar Ualeiro" /></div><div id="remover"><img src="images/icon_delamigo.png" title="Excluir Amigo" onclick="fncExcluirAmigo('+objeto[x].IdPerfil+','+"'aba'"+', this)" /></div></div></div>');
			}
			else {
				$("#conteudoAbaAmigos").append('<div id="amigo"><div id="foto"><a href="'+objeto[x].IdName+'"><img src="images/fotos_users/'+objeto[x].Foto+'" width="45" height="45" /></a></div><div id="dadosUser"><h1><a href="'+objeto[x].IdName+'">'+objeto[x].IdName+'</a></h1><h2><strong>Nome:</strong> '+objeto[x].Nome+'</h2><h3><strong>Local:</strong> '+objeto[x].Local+'</h3><div id="favoritar"><img src="images/icon_naofavorito.png" onclick="fncFavoritarAmigo('+objeto[x].IdPerfil+','+"'aba'"+', this)" title="Favoritar Ualeiro" /></div><div id="remover"><img src="images/icon_delamigo.png" title="Excluir Amigo" onclick="fncExcluirAmigo('+objeto[x].IdPerfil+','+"'aba'"+', this)" /></div></div></div>');
			}
		}
	}
	else {
		$("#conteudoAbaAmigos").append('<div id="semAmigos"><h1>Este usuário ainda não possui ualeiros.</h1></div>');
	}
	
	pageTracker._trackPageview("Perfil/Ualeiros");
}

function fncConfiguracoesPerfil() {	
	fncAbrirFundoAcao();
	$("body").append('<div id="popConfigPerfil"><div id="titulo"><h1>Backgrounds</h1><h3 onclick="fncFecharConfiguracoesPerfil()">Fechar</h3></div><div id="conteudo"><h1>Mude o background e deixe seu perfil com a sua cara.</h1><p>Escolha seu background abaixo:</p><ul><li><img src="images/bgs_perfil/thumbs/default.jpg" onclick="fncEditarConfiguracoesPerfil('+"'images/bgs_perfil/default.jpg'"+')" /></li><li><img src="images/bgs_perfil/thumbs/lua.jpg" onclick="fncEditarConfiguracoesPerfil('+"'images/bgs_perfil/lua.jpg'"+')" /></li><li><img src="images/bgs_perfil/thumbs/esportes.jpg" onclick="fncEditarConfiguracoesPerfil('+"'images/bgs_perfil/esportes.jpg'"+')" /></li><li><img src="images/bgs_perfil/thumbs/borboleta.jpg" onclick="fncEditarConfiguracoesPerfil('+"'images/bgs_perfil/borboleta.jpg'"+')" /></li><li><img src="images/bgs_perfil/thumbs/camelos.jpg" onclick="fncEditarConfiguracoesPerfil('+"'images/bgs_perfil/camelos.jpg'"+')" /></li><li><img src="images/bgs_perfil/thumbs/soldados.jpg" onclick="fncEditarConfiguracoesPerfil('+"'images/bgs_perfil/soldados.jpg'"+')" /></li></ul><p>Voc&ecirc; tamb&eacute;m pode utilizar qualquer background, digite a url da sua imagem no campo abaixo, utiliza imagens de no m&aacute;ximo 500kb</p><h2>Link do Background:</h2><input type="text" id="inputLinkBackground" /><div id="btCadastrarUrlBackground"><img src="images/bt_cadlink.png" onclick="fncEditarConfiguracoesPerfil('+"'background'"+')" /></div><h3>ex: http://www.ualah.com/images/background.jpg</h3></div></div>');
	
	pageTracker._trackPageview("Perfil/Configuracoes");
}

function fncEditarConfiguracoesPerfil(imagem) {
	if(imagem == "background") {
		if($("#inputLinkBackground").val() == "") {
			$("#inputLinkBackground").val("");
		}
		else {
			imagem = $("#inputLinkBackground").val();
			$("body").append('<div id="popUpsEditarBg" class="popUps2"><div id="titulo"><h1 id="tituloUps">Ups!</h1></div><div id="conteudo"><h1 id="perguntaUps">Deseja alterar o seu background para este:</h1><h2 id="infoUps"><img src="'+imagem+'" width="300" height="200" /></h2><div id="controleUps"><img src="images/bt_sim.png" onclick="fncConfirmarConfiguracoesPerfil('+"'"+imagem+"'"+');" /> <img src="images/bt_nao.png" onclick="fncNaoConfirmarConfiguracoesPerfil();" /></div></div></div>');
		}
	}
	else {
		$("body").append('<div id="popUpsEditarBg" class="popUps2"><div id="titulo"><h1 id="tituloUps">Ups!</h1></div><div id="conteudo"><h1 id="perguntaUps">Deseja alterar o seu background para este:</h1><h2 id="infoUps"><img src="'+imagem+'" width="300" height="200" /></h2><div id="controleUps"><img src="images/bt_sim.png" onclick="fncConfirmarConfiguracoesPerfil('+"'"+imagem+"'"+');" /> <img src="images/bt_nao.png" onclick="fncNaoConfirmarConfiguracoesPerfil();" /></div></div></div>');
	}
}

function fncConfirmarConfiguracoesPerfil(imagem) {
	var tipo = "bg";
	var dado = imagem;
	
	$.ajax({
		type: "GET",
		url: "interfaces/EditarConfiguracoes.php",
		data: {_tipo:tipo, _dado:dado},
		cache: false,
		
		beforeSend: function() {
			//$("#btResponderMensagem"+IdMensagem+"").html('<img src="images/loading_circle_24_24.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						$("#popUpsEditarBg").remove();
						fncFecharFundoAcao();
						$("#popConfigPerfil").remove();
						document.body.style.background="#000 url("+imagem+") fixed top";
					}
					else {
						alert("erro");
					}
				}
			}
		}
	});
}


function fncNaoConfirmarConfiguracoesPerfil() {
	$("#popUpsEditarBg").remove();
}

function fncFecharConfiguracoesPerfil() {
	fncFecharFundoAcao();
	$("#popConfigPerfil").remove();
}

var numIniMsg = 0;

function fncAbrirMensagensPerfil(tipo, IdPerfil, IdNamePerfil) {	
	fncAbrirFundoAcao();
	numIniMsg = 0;
	$("#popMensagens").show();
	
	if(tipo == "usuario") {
		$("#tipoPessoaMsg").html("<h2>" + IdNamePerfil + "</h2>");
		$("#yupiMensagemPvt").html('<img src="images/bt_yupi_login.png" onclick="fncCadastrarMensagem('+"'usuario'"+','+IdPerfil+');"/>');

		$(function() {
			$("#popMensagens").keypress(function (e) {
				if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
					fncCadastrarMensagem("usuario",IdPerfil);
					return false;
				} else {
					return true;
				}
			});
		});

	}
	else {
		$("#tipoPessoaMsg").html('<select name="" id="selectAmigosMensagens"></select>');
		$("#yupiMensagemPvt").html('<img src="images/bt_yupi_login.png" onclick="fncCadastrarMensagem('+"'perfil'"+');"/>');
		
		$(function() {
			$("#popMensagens").keypress(function (e) {
				if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
					fncCadastrarMensagem("perfil");
					return false;
				} else {
					return true;
				}
			});
		});

	}

	
	
	$("#localConteudoMensagensPvt").html('');
	$('#inputMensagem').limit('150','#charsLeftMensagen');
	fncObterAmigosMensagensPerfil(tipo);
	fncObterMensagensPerfil('recebidas');
	
	pageTracker._trackPageview("Perfil/Bips");
}

function fncObterAmigosMensagensPerfil(tipo) {
	var objeto = eval(amigos.substr(1));
	if(amigos != "Cnull"){
		for(x = 0; x < objeto.length; x++) {
			$("#selectAmigosMensagens").append('<option value="'+objeto[x].IdPerfil+'">'+objeto[x].IdName+'</option>');
		}
	}
	else {
		if(tipo != "usuario") {
			$("#enviarPvt").html("<div id='semAmigos'><h1></h1></div>");
		}
	}
}

function fncObterMensagensPerfil(tipo, local, LimitIni) {	
	
	var statusClass;
	var btLida;
	
	if(local == "aba") {
		numIniMsg = 0;
		$("#localConteudoMensagensPvt").html('');
	}
	
	if(tipo == "recebidas") {
		$("#opc1PopMensagens").removeClass('inativo');
		$("#opc1PopMensagens").addClass('ativo');
		$("#opc2PopMensagens").removeClass('ativo');
		$("#opc2PopMensagens").addClass('inativo');
	}
	else {
		$("#opc1PopMensagens").removeClass('ativo');
		$("#opc1PopMensagens").addClass('inativo');
		$("#opc2PopMensagens").removeClass('inativo');
		$("#opc2PopMensagens").addClass('ativo');
	}
	
	$("#maisMensagensPvt").html('');
	
	$.ajax({
		type: "GET",
		url: "interfaces/ObterMensagens.php",
		cache: false,
		data: {_tipo:tipo, _limitIni:numIniMsg},
		
		beforeSend: function() {
			if(local == "mais") {
				$("#maisMensagensPvt").html("<img src='images/loading_circle_24_24.gif' />");
			}
			else {
				$("#localConteudoMensagensPvt").html("<div id='loadingMensagens'><img src='images/loading_cubo_white.gif' /></div>");
			}
		},

		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {					
					var objeto = eval(callback.substr(1));
					
					if(callback != "Cnull"){
						
						if(local != "mais") {
							$("#localConteudoMensagensPvt").html('');
						}
						
						for(x = 0; x < objeto.length; x++) {
							if(tipo == "recebidas") {
								
								if(objeto[x].status == "1"){
									statusClass = "lida";
									btLida = '';
								}
								else {
									statusClass = "naolida";
									btLida = '<h1 onclick="fncMarcarComoLida('+objeto[x].idMsg+',this)"></h1>';
								}
								
								$("#localConteudoMensagensPvt").append('<div id="mensagem" class="'+statusClass+'"><div id="foto"><a href="'+objeto[x].idnameUser+'"><img src="images/fotos_users/' + objeto[x].fotoUser + '" width="35" height="35" /></a></div><div id="infos"><h1><a href="'+objeto[x].idnameUser+'">'+objeto[x].idnameUser+'</a></h1><h2>'+objeto[x].data+'</h2></div><div id="descricao"><h1>'+objeto[x].mensagem+'</h1></div><div id="responder'+objeto[x].idMsg+'" class="responder"><img src="images/_responder.png" onclick="fncResponderMensagem('+objeto[x].idMsg+','+objeto[x].idUser+')" /></div><div id="controle">'+btLida+'<h2 onclick="fncExcluirMensagemPerfil('+objeto[x].idMsg+', this, '+"'"+tipo+"'"+')"></h2></div></div>');
								
							}
							else {
								$("#localConteudoMensagensPvt").append('<div id="mensagem" class="lida"><div id="foto"><a href="'+objeto[x].idnameUser+'"><img src="images/fotos_users/' + objeto[x].fotoUser + '" width="35" height="35" /></a></div><div id="infos"><h1><a href="'+objeto[x].idnameUser+'">@'+objeto[x].idnameUserPara+'</a></h1><h2>'+objeto[x].data+'</h2></div><div id="descricao"><h1>'+objeto[x].mensagem+'</h1></div><div id="controle"><h2 onclick="fncExcluirMensagemPerfil('+objeto[x].idMsg+', this, '+"'"+tipo+"'"+')"></h2></div></div>');
							}
						}
						
						if(objeto.length < 4) {
							$("#maisMensagensPvt").html('');
						}
						else {
							numIniMsg = numIniMsg + 4;
							$("#maisMensagensPvt").html('<img src="images/bt_mais.jpg" onclick="fncObterMensagensPerfil('+"'"+tipo+"'"+','+"'mais'"+','+numIniMsg+')" />');
						}
						
					}
					else {
						if(numIniMsg == 0) {
							$("#localConteudoMensagensPvt").html('<div id="semMensagens"><h1>Nenhuma mensagem.</h1></div>');
						}
						if(local == "mais") {
							$("#maisMensagensPvt").html('');
						}
					}
				}
			}
		}
	});
}

function fncObterQtdMensagensPerfil() {
	var tipo = "qtd";
	$.ajax({
		type: "GET",
		url: "interfaces/ObterMensagens.php",
		data: {_tipo:tipo},
		cache: false,
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					$("#qtdMensagemPvt").html(callback.substr(1));
				}
			}
		}
	});
}

function fncResponderMensagem(IdMensagem, IdUser) {
	$("#responder"+IdMensagem+"").html('<textarea id="textResponder'+IdMensagem+'"></textarea><div id="contador"><h1 id="charsLeftMensagem'+IdMensagem+'"></h1></div><div id="btResponderMensagem"><img src="images/_responder.png" onclick="fncEnviarRespostaMensagem('+IdMensagem+','+IdUser+', this)" /></div><div id="btCancelarMensagem"><img src="images/_cancelar.png" onclick="fncCancelarMensagem('+IdMensagem+','+IdUser+')" /></div>');
	$('#textResponder'+IdMensagem+'').limit('150','#charsLeftMensagem'+IdMensagem+'');
}

function fncCancelarMensagem(IdMensagem, IdUser) {
	$("#responder"+IdMensagem+"").html('<img src="images/_responder.png" onclick="fncResponderMensagem('+IdMensagem+','+IdUser+')" />');
}

function fncEnviarRespostaMensagem(IdMensagem, IdUser, item) {
	var resposta = $("#textResponder"+IdMensagem+"").val();
	
	$.ajax({
		type: "GET",
		url: "interfaces/CadastrarMensagem.php",
		data: {_mensagem:resposta, _idPerfilPara:IdUser},
		cache: false,
		
		beforeSend: function() {
			$("#btResponderMensagem"+IdMensagem+"").html('<img src="images/loading_circle_24_24.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						fncMarcarComoLida(IdMensagem, item, "resp")
						$("#responder"+IdMensagem+"").html('<img src="images/_responder.png" onclick="fncResponderMensagem('+IdMensagem+','+IdUser+')" />');
					}
					else {
						alert("erro");
					}
				}
			}
		}
	});
}

function fncFecharMensagensPerfil() {
	fncFecharFundoAcao();
	$("#popMensagens").hide();
}

function fncCadastrarMensagem(tipo, IdPerfil) {
	
	if(tipo == "usuario") {
		var idPerfilPara = IdPerfil;
	}
	else {
		var idPerfilPara = document.getElementById('selectAmigosMensagens').value;
	}
	
	var mensagem = $("#inputMensagem").val();
	
	$.ajax({
		type: "GET",
		url: "interfaces/CadastrarMensagem.php",
		data: {_mensagem:mensagem, _idPerfilPara:idPerfilPara},
		cache: false,
		
		beforeSend: function() {
			$("#yupiMensagemPvt").html('<img src="images/loading_circle_24_24_white.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						$("#inputMensagem").val("");
						fncObterMensagensPerfil('enviadas','aba');
						$("#yupiMensagemPvt").html('<img src="images/bt_yupi_login.png" onclick="fncCadastrarMensagem();"/>');
					}
					else {
						alert("erro");
					}
				}
			}
		}
	});
}

function fncExcluirMensagemPerfil(IdMensagem, item, tipo) {
	var frase;
	fncAbrirFundoAcao();
	var idNameItem = $(item.parentNode.parentNode.childNodes[1].childNodes[0].childNodes[0]).html();
	var mensagemItem = $(item.parentNode.parentNode.childNodes[2].childNodes[0]).html();
	if(tipo == "enviadas") {
		frase = "Deseja excluir esta mensagem enviada para";
	}
	else {
		frase = "Deseja excluir esta mensagem recebida de";
	}
	$("body").append('<div id="popUpsExcluirMensagemPerfil" class="popUps"><div id="titulo"><h1 id="tituloUps">Ups!</h1></div><div id="conteudo"><h1 id="perguntaUps">'+frase+' '+idNameItem+':</h1><h2 id="infoUps">'+mensagemItem+'</h2><div id="controleUps"><img src="images/bt_sim.png" onclick="fncConfirmarExcluirMensagemPerfil('+IdMensagem+','+"'"+tipo+"'"+');" /> <img src="images/bt_nao.png" onclick="fncNaoExcluirMensagemPerfil();" /></div></div></div>');
}

function fncNaoExcluirMensagemPerfil() {
	fncFecharFundoAcao();
	$("#popUpsExcluirMensagemPerfil").remove();
}

function fncConfirmarExcluirMensagemPerfil(IdMensagem, tipo) {
	
	$.ajax({
		type: "GET",
		url: "interfaces/ExcluirMensagem.php",
		data: {_idMensagem:IdMensagem, _tipo:tipo}, 
		cache: false,
		
		beforeSend: function() {
			$("#controleUps").html('<img src="images/loading_circle_24_24.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						fncFecharFundoAcao();
						$("#popUpsExcluirMensagemPerfil").remove();
						
						if(tipo == "enviadas") {
							fncObterMensagensPerfil('enviadas','aba');
						}
						else {
							fncObterMensagensPerfil('recebidas','aba');
						}
					}
				}
			}
		}
	});
}

function fncMarcarComoLida(IdMensagem, item, tipo) {
	var lugar;
	
	if(tipo == "resp") {
		lugar = item.parentNode.parentNode.parentNode;
		$(lugar).removeClass('naolida');
		$(lugar).addClass('lida');
		$(item.parentNode.parentNode.parentNode.childNodes[4].childNodes[0]).remove();
		fncObterQtdMensagensPerfil();
	}
	else {
		lugar = item.parentNode.parentNode;
		$(lugar).removeClass('naolida');
		$(lugar).addClass('lida');
		$(item).remove();
		fncObterQtdMensagensPerfil();
	}
	
	$.ajax({
		type: "GET",
		url: "interfaces/LeuMensagem.php",
		data: {_idMensagem:IdMensagem}, 
		cache: false,
		
		beforeSend: function() {
			//$("#controleUps").html('<img src="images/loading_circle_24_24.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						
						fncObterQtdMensagensPerfil();
						
						
					}
				}
			}
		}
	});
	
}

function fncObterUsuarios(tipo) {
	var statusImage;
	$("#itensAmigosLateral").html('');
	
	$.ajax({
		type: "GET",
		url: "interfaces/ObterUsuarios.php",
		cache: false,
		data: {_tipo:tipo},
		
		beforeSend: function() {
			$("#conteudoAmigosLateral").html("<div id='loadingAmigosLateral'><img src='images/loading_cubo_white.gif' /></div>");
		},

		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					var objeto = eval(callback.substr(1));
					if(callback != "Cnull"){
						
						if(tipo == "amigos") {
							amigos = callback;
							$("#conteudoAmigosLateral").html('<ul id="itensAmigosLateral"></ul>');
						}
						
						if(tipo == "fa") {
							amigosFavoritos = callback;
							$("#conteudoAmigosLateral").html('<ul id="itensAmigosLateral"></ul>');
						}
						
						for(x = 0; x < objeto.length; x++) {
							
							if(tipo == "amigos") {
								if(objeto[x].Status == "0") {
									statusImage = '<img src="images/icon_useroff.png" />';
								}
								else {
									statusImage = '<img src="images/icon_useron.png" />';
								}
							}
							else {
								statusImage = '<img src="images/icon_userfav.png" />';
							}
							
							$("#itensAmigosLateral").append('<li><div id="fotoAmigoLateral"><a href="' + objeto[x].IdName + '"><img src="images/fotos_users/' + objeto[x].Foto + '" width="30" height="30" /></a></div><div id="statusUsuario"><a href="' + objeto[x].IdName + '">'+statusImage+'</a></div> <h1><a href="' + objeto[x].IdName + '">' + objeto[x].IdName + '</a></h1></li>');
						}
						
					}
					else {
						amigos = "Cnull";
						$("#conteudoAmigosLateral").html('<div id="semAmigos"><img src="images/0amigos.png" /><h1>Lista vazia.</h1></div>');
					}
				}
			}
		}
	});
}

function fncObterAmigosConfig() {
	var objeto = eval(amigos.substr(1));
	if(amigos != "Cnull"){
		
		for(x = 0; x < objeto.length; x++) {			
			$("#itensAmigosPrivacidade").append('<li><img src="images/fotos_users/' + objeto[x].Foto + '" width="25" height="25" /><h1>' + objeto[x].IdName + '</h1><h2 onclick="fncAddUserAssunto('+objeto[x].IdPerfil+','+"'"+objeto[x].IdName+"'"+','+"'"+objeto[x].Foto+"'"+',this)"></h2></li>');
		}
		
	}
}

function fncObterInteresses(IdName, tipo) {
	$.ajax({
		type: "GET",
		url: "interfaces/ObterInteressesPerfil.php",
		cache: false,
		data: {_idName:IdName},

		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {					
						
					if(tipo == "usuario"){
						interessesUsuario = callback;
					}
					
					if(tipo == "perfil"){
						interessesPerfil = callback;
						fncObterInteressesPerfil();
					}
					
					if(tipo == "abaperfil"){
						interessesPerfil = callback;
						fncObterAbaInteressesPerfil();
						fncObterInteressesPerfil();
					}
				}
			}
		}
	});
}

function fncObterInteressesConfig() {
	var objeto = eval(interessesUsuario.substr(2));
	
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#amizade</h1><h2 onclick="fncAddInteresseAssunto(180,'+"'amizade'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#arte</h1><h2 onclick="fncAddInteresseAssunto(206,'+"'arte'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#baladas</h1><h2 onclick="fncAddInteresseAssunto(272,'+"'baladas'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#celebridades</h1><h2 onclick="fncAddInteresseAssunto(646,'+"'celebridades'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#cidade</h1><h2 onclick="fncAddInteresseAssunto(647,'+"'cidades'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#cinema</h1><h2 onclick="fncAddInteresseAssunto(42,'+"'cinema'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#compras</h1><h2 onclick="fncAddInteresseAssunto(648,'+"'compras'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#esportes</h1><h2 onclick="fncAddInteresseAssunto(461,'+"'esportes'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#estudos</h1><h2 onclick="fncAddInteresseAssunto(649,'+"'estudos'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#games</h1><h2 onclick="fncAddInteresseAssunto(107,'+"'games'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#gastronomia</h1><h2 onclick="fncAddInteresseAssunto(650,'+"'gastronomia'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#humor</h1><h2 onclick="fncAddInteresseAssunto(232,'+"'humor'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#internet</h1><h2 onclick="fncAddInteresseAssunto(103,'+"'internet'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#moda</h1><h2 onclick="fncAddInteresseAssunto(5,'+"'moda'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#musica</h1><h2 onclick="fncAddInteresseAssunto(83,'+"'musica'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#namoro</h1><h2 onclick="fncAddInteresseAssunto(248,'+"'namoro'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#papofurado</h1><h2 onclick="fncAddInteresseAssunto(651,'+"'papofurado'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#presentes</h1><h2 onclick="fncAddInteresseAssunto(652,'+"'presentes'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#saude</h1><h2 onclick="fncAddInteresseAssunto(653,'+"'saude'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#sexo</h1><h2 onclick="fncAddInteresseAssunto(327,'+"'sexo'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#shows</h1><h2 onclick="fncAddInteresseAssunto(132,'+"'shows'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#tecnologia</h1><h2 onclick="fncAddInteresseAssunto(99,'+"'tecnologia'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#trabalho</h1><h2 onclick="fncAddInteresseAssunto(437,'+"'trabalho'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#tv</h1><h2 onclick="fncAddInteresseAssunto(654,'+"'tv'"+', this)"></h2></li>');
	$("#itensInteressesPrivacidade").append('<li class="padrao"><h1>#viagens</h1><h2 onclick="fncAddInteresseAssunto(324,'+"'viagens'"+', this)"></h2></li>');
	
	if(interessesUsuario.substr(2,4) != "null"){
		
		for(x = 0; x < objeto.length; x++) {			
			$("#itensInteressesPrivacidade").append('<li><h1>#'+ objeto[x].InteressesNome +'</h1><h2 onclick="fncAddInteresseAssunto('+ objeto[x].InteressesId +','+"'"+objeto[x].InteressesNome+"'"+', this)"></h2></li>');
		}
		
	}
}

function fncObterInteressesPerfil() {
	
	var qtd;
	
	$("#itensInteressesPerfil").html('');
	
	
	if(interessesPerfil.substr(2,4) != "null"){
		
		var objeto = eval(interessesPerfil.substr(2));
		
		$("#qtdInteressesPerfil").html(objeto.length);
		
		if(objeto.length >= 6) {
			qtd = 6;
		}
		else {
			qtd = objeto.length;
		}
		
		if(interessesPerfil.substr(0,2) == "C1") {
			for(x = 0; x < qtd; x++) {			
				$("#itensInteressesPerfil").append('<li>#'+ objeto[x].InteressesNome +'</li>');
			}
		}
		
		if(interessesPerfil.substr(0,2) == "C2" || interessesPerfil.substr(0,2) == "C4") {
			for(x = 0; x < qtd; x++) {			
				$("#itensInteressesPerfil").append('<li>#'+ objeto[x].InteressesNome +'</li>');
			}
		}
		
		if(interessesPerfil.substr(0,2) == "C3" || interessesPerfil.substr(0,2) == "C5") {
			$("#itensInteressesPerfil").html('<div id="semInteresses"><h1>Lista Privada.</h1></div>');
		}
		
		if(interessesPerfil.substr(0,2) == "C6") {
			for(x = 0; x < qtd; x++) {			
				$("#itensInteressesPerfil").append('<li>#'+ objeto[x].InteressesNome +'</li>');
			}
		}
		
	}
	else {
		
		$("#qtdInteressesPerfil").html("0");
		
		if(interessesPerfil.substr(0,2) == "C1") {
			$("#itensInteressesPerfil").html('<div id="semInteresses"><h1>Lista Vazia.</h1></div>');
		}
		
		if(interessesPerfil.substr(0,2) == "C2" || interessesPerfil.substr(0,2) == "C4") {
			$("#itensInteressesPerfil").html('<div id="semInteresses"><h1>Lista Vazia.</h1></div>');
		}
		
		if(interessesPerfil.substr(0,2) == "C3" || interessesPerfil.substr(0,2) == "C5") {
			$("#itensInteressesPerfil").html('<div id="semInteresses"><h1>Lista Privada.</h1></div>');
		}
		
		if(interessesPerfil.substr(0,2) == "C6") {
			$("#itensInteressesPerfil").html('<div id="semInteresses"><h1>Lista Vazia.</h1></div>');
		}
	}	
}



var numIniAssuntos = 0;


function fncPrevPaginaAssunto() {
	//numNextPag--;
	//alert(numNextPag)
}

function fncDepthAssunto(item,tipo) {
	if(tipo == "over") {
		$(item).css("overflow","auto")
	}
	
	if(tipo == "out") {
		$(item).css("overflow","hidden")
	}
}

var ini = 0;
var fim = 4;
var cont = 1;
var cadeadoAssuntoPvt;

function fncObterAssuntos(tipo, pais, item, local, idinteresse, interesse) {	
	var favorito;
	var acompanhar;
	var qtdColCont = 0;
	var colCont = 0;
	var qtdClicksSeta = 0;
	var d = 0;
	
	if(tipo == "buscar") {
		var descBusca = document.getElementById('assunto').value;
	}
	
	if(tipo == "relacionar") {
		var descBusca = $(item.parentNode.parentNode.childNodes[3].childNodes[0]).html();
	}
	
	if(local != "mais") {
		$("#conteudoAssuntosSite").html('<div id="assuntos"><div id="atualizar" title="Atualizar Assuntos"><div id="tagCloud" onclick="fncTagCloud('+ "'todos'" + ')" title="Ver interesses mais falados."></div> <div id="temaInteresseAssunto"></div> <div id="botao" onclick="fncObterAssuntos('+"'"+tipo+"'"+',1)"></div></div><div id="controleEsquerdo"></div><div id="localAssuntos"><div id="carosel"></div></div><div id="controleDireito"></div></div>');
	}

	if(!interesse) {
		$("#temaInteresseAssunto").html('todas ualadas');
	}
	else {
		$("#temaInteresseAssunto").html('ualadas de ' + interesse);
	}

	$("#tagCloud").css("display","block");

	
	if(tipo == "meus") {
		document.location.href=""+IdNameConta+"";
	}
	
	
		ini = 0;
		fim = 4;
		
		if(local != "mais") {
			numIniAssuntos = 0;
		}
	
	if(tipo == "publicos" || tipo == "interesses" || tipo == "amigos" || tipo == "favoritos") { 
		$.ajax({
			type: "GET",
			url: "interfaces/ObterAssuntos.php",
			cache: false,
			data: {_tipo:tipo, _pais:pais, _limitIniAssuntos:numIniAssuntos, _idInteresse:idinteresse},
			
			beforeSend: function() {
				if(local != "mais") {
					$("#carosel").html("<div id='loadingAssuntos'><img src='images/loading_cubo.gif' /></div>");
				}
				else {
					$("#assuntos").append('<div id="fundoLoadAssuntos"><div id="loadingAssuntos"><img src="images/loading_cubo.gif" /></div></div>');
				}
			},
	
			success: function(callback) {
				if(callback == "ErrorLogin") {
					document.location.href="index.shtml";
				}
				else {
					if(callback.indexOf("DieServer") != -1) {
						fncDieServer();
					}
					else {
						var objeto = eval(callback.substr(1));
						if(callback != "Cnull"){
							
							if(local != "mais") {
								$("#carosel").html('<ul id="colunasAssuntos"></ul>');
							}
							else {
								$("#fundoLoadAssuntos").remove();
							}
							
							
							for(x = 0; x < objeto.length; x++) {
								
								if(x >= ini && x <= fim) {
									
									$("#colunasAssuntos").append('<li id="listaAssuntos'+cont+'"></li>');
									//alert(fim)
									for(c = ini; c < fim; c++) {											

										//alert(ini + "---" + fim)
										//alert(c)
										
										if(c < objeto.length) {
											if(objeto[c].AssPvt == "1") {
												cadeadoAssuntoPvt = '<img src="images/lock.png" title="Ualada Privada pra você." /> ';
											}
											else {
												cadeadoAssuntoPvt = '';
											}
											$("#listaAssuntos"+cont+"").append('<div id="assunto"><div id="foto"><a href="' + objeto[c].IdName + '"><img src="images/fotos_users/' + objeto[c].FotoPerfil + '" width="35" height="35" /></a></div><div id="nome"><h1><a href="' + objeto[c].IdName + '">' + objeto[c].IdName + '</a></h1><h2>'+cadeadoAssuntoPvt+'</h2></div><div id="controle"><div id="dataHora">' + objeto[c].Data + ' as ' + objeto[c].Hora + '</div><div id="btRelacionar" onclick="fncTrocarHash('+"'UaladasRelacionadas'"+',1,this)"></div><div id="comments"><h1>'+objeto[c].QtdPosts+'</h1></div></div><div id="texto" onmouseover="fncDepthAssunto(this, '+"'over'"+')" onmouseout="fncDepthAssunto(this, '+"'out'"+')"><h1 onclick="fncAbrirAssunto(' + objeto[c].IdAssunto + ', this,' + objeto[c].IdPerfil + ', '+"'home'"+','+objeto[c].Favorito+','+objeto[c].Acomp+','+"'"+objeto[c].Tema+"'"+');">' + objeto[c].Descricao + '</h1></div></div>');
										}
											
									}
									
									
									cont = cont + 1;
									ini = ini + 4;
									fim = fim + 4;
									
								}								
							}
							
							if(objeto.length > 12) {
								$("#controleEsquerdo").css("visibility","visible")
								$("#controleDireito").css("visibility","visible")
							}
							
							var numNextPag = 0;
							var numPagAssuntos = 0;
							var numLoad = 0;
							
							numIniAssuntos = numIniAssuntos + 24;
							
							$("#controleDireito").show();
							
							if(local != "mais") {
								$("#controleEsquerdo").click(function(){
									
									if(numNextPag != 0) {
										
										qtdClicksSeta--;
										$("#controleDireito").show();
										
										numNextPag--;
										numLoad--;
										numPagAssuntos = numPagAssuntos - 225;
										$("#colunasAssuntos").css("margin-left",-numPagAssuntos+"px")
									}
								});
								
								
								
								$("#controleDireito").click(function(){
									qtdColCont = 0;
									$("#colunasAssuntos").find("li").each(function(i) {
										qtdColCont++;
							        });
									
									colCont = qtdColCont - 3;
									
									//alert(colCont)
									
									qtdClicksSeta++;
									
									//alert(colCont)
									
									if(qtdClicksSeta >= colCont) {
										$("#controleDireito").hide();
									}
									
									if(numNextPag != cont) {
										numNextPag++;
										numLoad++;
										numPagAssuntos = numPagAssuntos + 225;
										$("#colunasAssuntos").css("margin-left",-numPagAssuntos+"px")
									}
									
									if(numLoad == 3) {
										fncObterAssuntos(tipo,1,'oi','mais', idinteresse);
										numLoad = 0; 
									}
								});
							}
							
						}
						else {
							if(tipo == "favoritos") {
								if(local != "mais") {
									$("#carosel").html('<div id="semAssuntos"><h1>Você não possui ualadas favoritas.</h1></div>');
								}
								else {
									$("#fundoLoadAssuntos").remove();
								}
							}
							
							if(tipo == "amigos") {
								$("#carosel").html('<div id="semAssuntos"><h1>Você ainda não adicionou nenhum ualeiro como amigo.</h1></div>');
								$("#fundoLoadAssuntos").remove();
							}
							
							if(tipo == "interesses") {
								$("#carosel").html('<div id="semAssuntos"><h1>Cadastre interesses no seu perfil para ver apenas ualadas com interesses iguais aos seus.</h1></div>');
								$("#fundoLoadAssuntos").remove();
							}
						}
					}
				}
			}
		});
	}
	
	if(tipo == "buscar" || tipo == "relacionar") {
		$("#conteudoAssuntosSite").html('<div id="relacionados"><div id="localRelacionados"><div id="titulo"><h1>Ualadas relacionadas</h1></div><div id="assuntoBusca"><div id="fotoUser"><img src="images/fotos_users/'+FotoConta+'" width="80" height="80" /></div><h1>'+IdNameConta+'</h1><p>'+descBusca+'</p><div id="postar"><img src="images/bt_postar.png" onclick="fncCadastrarAssunto('+"'buscar'"+', this)" /></div></div><div id="resultadosBuscaRelacionados"><div id="titulo2"><h1>Resultados:</h1></div></div><div id="voltar"><img src="images/bt_voltar.png" onclick="fncTrocarHash('+"'UaladasPublicas'"+')" /></div></div>');
		
		$.ajax({
			type: "GET",
			url: "interfaces/ObterAssuntos.php",
			cache: false,
			data: {_tipo:tipo, _pais:pais, _descBusca:descBusca},
			
			beforeSend: function() {
				$("#resultadosBuscaRelacionados").html("<img src='images/loading_circle_24_24_white.gif' />");
			},
			
			success: function(callback) {
				if(callback == "ErrorLogin") {
					document.location.href="index.shtml";
				}
				else {
					if(callback.indexOf("DieServer") != -1) {
						fncDieServer();
					}
					else {
						$("#resultadosBuscaRelacionados").html('');
						var objeto = eval(callback.substr(1));
						if(callback != "Cnull") {
							for(x = 0; x < objeto.length; x++) {
								$("#resultadosBuscaRelacionados").append('<div id="resultado"><div id="foto"><a href="'+objeto[x].IdName+'"><img src="images/fotos_users/'+objeto[x].FotoPerfil+'" width="45" height="45" /></a></div><div id="dados"><h1><strong><a href="'+objeto[x].IdName+'">'+objeto[x].IdName+'</a></strong></h1><p onclick="fncAbrirAssunto(' + objeto[x].IdAssunto + ', this,' + objeto[x].IdPerfil + ', '+"'novosYupis'"+','+objeto[x].Favorito+','+objeto[x].Acomp+','+"'"+objeto[x].Tema+"'"+');">'+objeto[x].Descricao+'</p><h2>'+objeto[x].Data+' as '+objeto[x].Hora+'</h2></div><h3>'+objeto[x].QtdPosts+' respostas</h3></div></div>');
							}
						}
						else {
							$("#resultadosBuscaRelacionados").html('<div id="nenhumResultado"><h1>Nenhuma ualahda relacionada foi encontrada.</h1></div>');
						}
					}
				}
			}
		});
	}
}


function fncTagCloud(tipo) {

	if(tipo == "todos") {
		tipoFiltro = 'interessesUsuario';
	}
	else {
		tipoFiltro = 'todos';
	}

	$("#temaInteresseAssunto").html('');

	$.ajax({
		type: "GET",
		url: "interfaces/ObterInteressesPopulares.php",
		cache: false,
		data: {_tipo:tipo},
		
		beforeSend: function() {
			$("#assuntos").append('<div id="fundoLoadAssuntos"><div id="loadingAssuntos"><img src="images/loading_cubo.gif" /></div></div>');
		},

		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					var objeto = eval(callback.substr(1));
					if(callback != "Cnull"){
						
						$("#controleEsquerdo").hide();
						$("#controleDireito").hide();

						$("#fundoLoadAssuntos").remove();
						$("#localAssuntos").html('<div id="filtro" onclick="fncTagCloud('+"'"+tipoFiltro+"'"+')"></div><div id="localCloud"><div id="tags"><ul id="conteudoTags"></ul></div></div>');
						
						if(tipo == "todos") {
							$("#filtro").html('Ver meus interesses');
						}
						else {
							$("#filtro").html('Ver todos interesses');
						}

						for(x = 0; x < objeto.length; x++) {
							
							if(objeto[x].total < 1000) {
								$("#conteudoTags").append('<li class="tag1"><a href="javascript:fncObterAssuntos('+"'interesses'"+',1, null, null, ' + objeto[x].interesseId + ', '+"'"+objeto[x].interesseNome+"'"+');">' + objeto[x].interesseNome + '('+objeto[x].total+')</a></li>');
							}

							if(objeto[x].total > 1000 && objeto[x].total < 2000) {
								$("#conteudoTags").append('<li class="tag2"><a href="javascript:fncObterAssuntos('+"'interesses'"+',1, null, null, ' + objeto[x].interesseId + ', '+"'"+objeto[x].interesseNome+"'"+');">' + objeto[x].interesseNome + '('+objeto[x].total+')</a></li>');
							}

							if(objeto[x].total > 2000 && objeto[x].total < 3000) {
								$("#conteudoTags").append('<li class="tag3"><a href="javascript:fncObterAssuntos('+"'interesses'"+',1, null, null, ' + objeto[x].interesseId + ', '+"'"+objeto[x].interesseNome+"'"+');">' + objeto[x].interesseNome + '('+objeto[x].total+')</a></li>');
							}

							if(objeto[x].total > 3000 && objeto[x].total < 4000) {
								$("#conteudoTags").append('<li class="tag5"><a href="javascript:fncObterAssuntos('+"'interesses'"+',1, null, null, ' + objeto[x].interesseId + ', '+"'"+objeto[x].interesseNome+"'"+');">' + objeto[x].interesseNome + '('+objeto[x].total+')</a></li>');
							}

							if(objeto[x].total > 4000) {
								$("#conteudoTags").append('<li class="tag5"><a href="javascript:fncObterAssuntos('+"'interesses'"+',1, null, null, ' + objeto[x].interesseId + ', '+"'"+objeto[x].interesseNome+"'"+');">' + objeto[x].interesseNome + '('+objeto[x].total+')</a></li>');
							}

							
						}
	
						
					}
				}
			}
		}
	});
}

function fncCadastrarAssuntoFavorito(IdAssunto, item) {	
	$.ajax({
		type: "GET",
		url: "interfaces/CadastrarAssuntoFavorito.php",
		data: {_idAssunto:IdAssunto}, 
		cache: false,
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						$(item.parentNode).html('<img src="images/bt_favorito.png" onclick="fncExcluirAssuntoFavorito(' + IdAssunto + ',this)" />');
					}
				}
			}
		}
	});
}

function fncExcluirAssuntoFavorito(IdAssunto, item) {	
	$.ajax({
		type: "GET",
		url: "interfaces/ExcluirAssuntoFavorito.php",
		data: {_idAssunto:IdAssunto}, 
		cache: false,
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						$(item.parentNode).html('<img src="images/bt_nfavorito.png" onclick="fncCadastrarAssuntoFavorito(' + IdAssunto + ',this)" />');
					}
				}
			}
		}
	});
}

function fncCadastrarAssuntoAcompanhar(IdAssunto, item) {	
	$.ajax({
		type: "GET",
		url: "interfaces/CadastrarAssuntoAcompanhar.php",
		data: {_idAssunto:IdAssunto}, 
		cache: false,
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						$(item.parentNode).html('<img src="images/bt_acompanhar.png" onclick="fncExcluirAssuntoAcompanhar(' + IdAssunto + ',this)" />');
					}
				}
			}
		}
	});
}

function fncExcluirAssuntoAcompanhar(IdAssunto, item) {	
	$.ajax({
		type: "GET",
		url: "interfaces/ExcluirAssuntoAcompanhar.php",
		data: {_idAssunto:IdAssunto}, 
		cache: false,
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						$(item.parentNode).html('<img src="images/bt_nacompanhar.png" onclick="fncCadastrarAssuntoAcompanhar(' + IdAssunto + ',this)" />');
					}
				}
			}
		}
	});
}

var configAberto = 0;

function fncConfigAssunto(tipo) {	
	if(tipo == "abrir"){
		fncAbrirFundoAcao();
		
		if(configAberto == 0) {
			fncObterTemaAssuntos();
			$("body").append('<div id="popConfig"><div id="titulo"><h1>Configurar Ualada</h1><h3 onclick="fncConfigAssunto('+"'fechar'"+')">Fechar</h3></div><div id="opcoes"><ul><li id="opc1PopConfig" class="ativo"><h2 onclick="fncOpcoesConfig(1,this)">Tema</h2></li><li id="opc2PopConfig" class="inativo"><h2 onclick="fncOpcoesConfig(2,this)">Privacidade</h2></li><li id="opc3PopConfig" class="inativo"><h2 onclick="fncOpcoesConfig(3,this)">Interesses</h2></li></ul></div><div id="conteudo"><div id="localTemas"><div id="info">Configure o tema(background) da sua ualahda.</div><ul id="itensTemasAssunto"></ul></div><div id="localPrivacidade"><div id="info">Aqui você pode configurar quem irá ver sua ualahda.</div><div id="amigosPrivacidade"><div id="tituloAmigos"><h1>Seus amigos</h1></div><div id="listaAmigosPrivacidade"><ul id="itensAmigosPrivacidade"></ul></div><div id="listaAmigosAdicionados"><ul id="itensAmigosAdicionados"></ul></div></div></div> <div id="localInteresses"><div id="info">Escolha a(s) áreas de interesse para sua Ualada (Obrigatório).</div><div id="interessesPrivacidade"><div id="tituloInteresses"><h1>Interesses</h1></div><div id="listaInteressesPrivacidade"><ul id="itensInteressesPrivacidade"></ul></div><div id="listaInteressesAdicionados"><ul id="itensInteressesAdicionados"></ul></div></div></div> <div id="okConfig"><img src="images/bt_okconfig.png" onclick="fncConfigAssunto('+"'fechar'"+')" /></div></div></div>');
		}
		else {
			$("#popConfig").show();
		}
		
		if(idUsuariosAssunto == "") {
			if(configAberto == 0) {
				fncObterAmigosConfig();
			}
		}
		
		if(idInteressesAssunto == "") {
			if(configAberto == 0) {
				fncObterInteressesConfig();
			}
		}
		
		configAberto = 1;
	}
	
	if(tipo == "fechar"){
		fncFecharFundoAcao();
		
		if(configAberto == 0) {
			$("#popConfig").remove();
		}
		else {
			$("#popConfig").hide();
		}
	}
	
	pageTracker._trackPageview("Principal/ConfigurarUalada");
}

function fncOpcoesConfig(opcao, item) {
	if(opcao == 1) {
		$("#opc1PopConfig").removeClass('inativo');
		$("#opc1PopConfig").addClass('ativo');
		$("#opc2PopConfig").removeClass('ativo');
		$("#opc2PopConfig").addClass('inativo');
		$("#opc3PopConfig").removeClass('ativo');
		$("#opc3PopConfig").addClass('inativo');

		$("#localTemas").show();
		$("#localPrivacidade").hide();
		$("#localInteresses").hide();
	}
	
	if(opcao == 2) {
		$("#opc1PopConfig").removeClass('ativo');
		$("#opc1PopConfig").addClass('inativo');
		$("#opc2PopConfig").removeClass('inativo');
		$("#opc2PopConfig").addClass('ativo');
		$("#opc3PopConfig").removeClass('ativo');
		$("#opc3PopConfig").addClass('inativo');
		
		$("#localPrivacidade").show();
		$("#localTemas").hide();
		$("#localInteresses").hide();
	}
	
	if(opcao == 3) {
		$("#opc1PopConfig").removeClass('ativo');
		$("#opc1PopConfig").addClass('inativo');
		$("#opc2PopConfig").removeClass('ativo');
		$("#opc2PopConfig").addClass('inativo');
		$("#opc3PopConfig").removeClass('inativo');
		$("#opc3PopConfig").addClass('ativo');
		
		$("#localInteresses").show();
		$("#localPrivacidade").hide();
		$("#localTemas").hide();
	}
}

function fncObterTemaAssuntos() {
	$.ajax({
		type: "POST",
		url: "interfaces/ObterTemaAssuntos.php",
		cache: false,
		
		beforeSend: function() {
			$("#itensTemasAssunto").html("<div id='loadingTemas'><img src='images/loading_cubo_white.gif' /></div>");
		},

		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					$("#itensTemasAssunto").html("");
					var objeto = eval(callback.substr(1));
					if(callback != "Cnull"){												
						for(x = 0; x < objeto.length; x++) {
							$("#itensTemasAssunto").append('<li><img src="images/bgs_assunto/thumbs/'+objeto[x].TemaImg+'" width="116" height="60" onclick="fncAddTemaAssunto('+objeto[x].TemaId+', this)" /><h1>'+objeto[x].TemaNome+'</h1></li>');
						}
					}
				}
			}
		}
	});
}

function fncAddTemaAssunto(IdTema, item) {
	temaAssunto = IdTema;
	$(item).css("border-color","#FF9900");
	configAberto = 1;
}

function fncAddUserAssunto(IdUsuario, IdName, FotoPerfil, item) {
	if(detectItem(idUsuariosAssunto, IdUsuario)) {
		alert("Este usuário ja esta adicionado");
	}
	else {
		$(item.parentNode).remove();
		idUsuariosAssunto.push(IdUsuario);
		$("#itensAmigosAdicionados").append('<li><img src="images/fotos_users/'+FotoPerfil+'" width="25" height="25" /><h1>'+IdName+'</h1><h2 onclick="fncExcUserAssunto('+IdUsuario+','+"'"+IdName+"'"+','+"'"+FotoPerfil+"'"+', this)"></h2></li>');
	}
	configAberto = 1;
}

function fncExcUserAssunto(IdUsuario, IdName, FotoPerfil, item) {
	$(item.parentNode).remove();
	removeItem(idUsuariosAssunto, IdUsuario)
	$("#itensAmigosPrivacidade").append('<li><img src="images/fotos_users/'+FotoPerfil+'" width="25" height="25" /><h1>'+IdName+'</h1><h2 onclick="fncAddUserAssunto('+IdUsuario+','+"'"+IdName+"'"+','+"'"+FotoPerfil+"'"+',this)"></h2></li>');
}

function fncAddInteresseAssunto(IdInteresse, InteresseNome, item) {
	// || idInteressesAssunto.length >= 2
        if(detectItem(idInteressesAssunto, IdInteresse)) {
		alert("Este usuário ja esta adicionado");
	}
	else {
		$(item.parentNode).remove();
		idInteressesAssunto.push(IdInteresse);
		$("#itensInteressesAdicionados").append('<li><h1>#'+InteresseNome+'</h1><h2 onclick="fncExcInteresseAssunto('+IdInteresse+', '+"'"+InteresseNome+"'"+', this)"></h2></li>');
	}	
}

function fncExcInteresseAssunto(IdInteresse, InteresseNome, item) {
	$(item.parentNode).remove();
	removeItem(idInteressesAssunto, IdInteresse)
	$("#itensInteressesPrivacidade").append('<li><h1>#'+InteresseNome+'</h1><h2 onclick="fncAddInteresseAssunto('+IdInteresse+', '+"'"+InteresseNome+"'"+', this)"></h2></li>');
}

function fncCadastrarAssunto(local, item) {
	
	var area = window.location.href.split("/");
	
	if(local == "buscar") {
		var assunto = $(item.parentNode.parentNode.childNodes[2]).html();
	}
	else {
		var assunto = document.getElementById('assunto').value;
	}
	
	
	var arrAmigos = idUsuariosAssunto.toString();
	var arrInteresses = idInteressesAssunto.toString();
	var pais = 1; //document.getElementById('pais2').value
	
	var tipo = $("input[name='tipoAssunto']:checked").val();
	
	$("#popConfig").remove();
	configAberto = 0;
	
	if(assunto == "") {
		$("#assunto").val("Escreva seu assunto...");
	}
	else {
		if(assunto == "Escreva seu assunto...") {
			$("#assunto").val("Escreva seu assunto...");
		}
		else {
			
			if(tipo == "cadastrar") {
				
				if(idInteressesAssunto == "") {
					fncConfigAssunto('abrir');
					
					$("#opc1PopConfig").removeClass('ativo');
					$("#opc1PopConfig").addClass('inativo');
					$("#opc2PopConfig").removeClass('ativo');
					$("#opc2PopConfig").addClass('inativo');
					$("#opc3PopConfig").removeClass('inativo');
					$("#opc3PopConfig").addClass('ativo');
					
					$("#localInteresses").show();
					$("#localPrivacidade").hide();
					$("#localTemas").hide();
					
				}
				else {
					
					$.ajax({
						type: "GET",
						url: "interfaces/CadastrarAssunto.php",
						data: {_assunto:assunto, _pais:pais, _arrIdAmigos:arrAmigos, _arrIdInteresses:arrInteresses, _idTema:temaAssunto}, 
						cache: false,
		
						beforeSend: function() {
							$("#botaoCadastrarAssunto").html('<img src="images/loading_cubo.gif" />');
						},
						
						success: function(callback) {
							if(callback == "ErrorLogin") {
								document.location.href="index.shtml";
							}
							else {
								if(callback.indexOf("DieServer") != -1) {
									fncDieServer();
								}
								else {
									if(callback == "Cblank") {
										$("#assunto").val("Escreva seu assunto...");
									}
									else {
										if(callback == "C") {
											$("#botaoCadastrarAssunto").html('<img src="images/bt_ualah.png" onclick="fncCadastrarAssunto();" />');
											
											if(area[4] == IdNamePerfil) {
												$("#assunto").val("");
												fncObterAbaAssuntosPerfil("usuarios",IdPerfil,"0","10");
											}
											else {
												$("#assunto").val("");
												
												document.location.href="http://www.ualah.com/"+IdNameConta+"";
												
												//fncObterAssuntos("publicos",1);
												
												/*
												if(PaginaConta == 0) {
													document.location.href="Default.shtml#UaladasAmigos";
												}
												
												if(PaginaConta == 1) {
													//document.location.href="Default.shtml#UaladasPublicas";
													fncObterAssuntos("publicos",1);
												}
												
												if(PaginaConta == 2) {
													document.location.href="Default.shtml#UaladasAmigos";
												}
												
												if(PaginaConta == 3) {
													document.location.href="Default.shtml#UaladasFavoritas";
												}
												*/
											}
										}
										
										if(callback == "CPF") {
											alert("Você esta tentando cadastrar várias ualadas seguidamente. Aguarde alguns segundos...");
											$("#botaoCadastrarAssunto").html('<img src="images/bt_ualah.png" onclick="fncCadastrarAssunto();" />');
										}
										
										if(callback == "CUB") {
											alert("Envie Yupis aos ualeiros antes de publicar uma nova ualada ;D");
											$("#botaoCadastrarAssunto").html('<img src="images/bt_ualah.png" onclick="fncCadastrarAssunto();" />');
										}
										
									}
								}
							}
						}
					});
				}
			}
			
			if(tipo == "buscar") {
				if(local == "buscar") {
					$.ajax({
						type: "GET",
						url: "interfaces/CadastrarAssunto.php",
						data: {_assunto:assunto, _pais:pais, _arrIdAmigos:arrAmigos, _arrIdInteresses:arrInteresses, _idTema:temaAssunto}, 
						cache: false,
		
						beforeSend: function() {
							//fncAbrirFundoAcao();
							//$("#fundoAcao").html("<div id='loadingPrincipal'><img src='images/loading_cubo.gif' /></div>");
						},
						
						success: function(callback) {
							if(callback == "ErrorLogin") {
								document.location.href="index.shtml";
							}
							else {
								if(callback.indexOf("DieServer") != -1) {
									fncDieServer();
								}
								else {
									if(callback == "Cblank") {
										$("#assunto").val("Escreva seu assunto...");
									}
									else {
										if(area[4] == IdNamePerfil) {
											$("#assunto").val("");
											fncObterAbaAssuntosPerfil("usuarios",IdPerfil,"0","10");
										}
										else {
											$("#assunto").val("");
											fncObterAssuntos("publicos",1);
										}
									}
								}
							}
						}
					});
				}
				else {
					fncObterAssuntos("buscar",1);
				}
			}
			
			pageTracker._trackPageview("Principal/Ualah");
		}
	}
}



function fncExcluirAssunto(IdAssunto, item) {
	fncAbrirFundoAcao();
	var assuntoItem = $(item.parentNode.parentNode.parentNode.childNodes[1].childNodes[0]).html();
	$("body").append('<div id="popUpsExcluirAssunto" class="popUps"><div id="titulo"><h1 id="tituloUps">Ups!</h1></div><div id="conteudo"><h1 id="perguntaUps">Deseja excluir este assunto:</h1><h2 id="infoUps">'+assuntoItem+'</h2><div id="controleUps"><img src="images/bt_sim.png" onclick="fncConfirmarExcluirAssunto('+IdAssunto+');" /> <img src="images/bt_nao.png" onclick="fncNaoExcluirAssunto();" /></div></div></div>');
}

function fncNaoExcluirAssunto() {
	fncFecharFundoAcao();
	$("#popUpsExcluirAssunto").remove();
}

function fncConfirmarExcluirAssunto(IdAssunto) {
	$.ajax({
		type: "GET",
		url: "interfaces/ExcluirAssunto.php",
		data: {_idAssunto:IdAssunto}, 
		cache: false,
		
		beforeSend: function() {
			$("#controleUps").html('<img src="images/loading_circle_24_24.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						fncFecharFundoAcao();
						$("#popUpsExcluirAssunto").remove();
						fncObterAbaAssuntosPerfil("usuarios",IdPerfil,"0","10");
					}
				}
			}
		}
	});
}

var zin = 100;

function fncZindexAssunto(IdAssunto) {
	zin++;
	$("#popAssunto"+IdAssunto+"").css("zIndex",zin);
}

function fncStringCreate(input)
{
	var input;
    return input
    .replace(/(ftp|http|https|file):\/\/[\S]+(\b|$)/gim, '<a href="$&" target="_blank">$&</a>')
    .replace(/([^\/])(www[\S]+(\b|$))/gim, '$1<a href="$2" target="_blank">$2</a>')
    .replace(/@([a-z0-9]*)/gim, '<a href="$1" target="_blank">@$1</a>');
} 

function fncConteudoAssunto(IdAssunto, IdName, IdPerfil, FotoPerfil, Assunto, fav, acomp, tema) {
	
	var favorito;
	var acompanhar;
	var responder;
	
	fncAbrirFundoAcao();
	
	if(fav == 0) {
		favorito = '<img src="images/bt_nfavorito.png" onclick="fncCadastrarAssuntoFavorito(' + IdAssunto + ',this)" />';
	}
	else {
		favorito = '<img src="images/bt_favorito.png" onclick="fncExcluirAssuntoFavorito(' + IdAssunto + ',this)" />';
	}
	
	if(acomp == 0) {
		acompanhar = '<img src="images/bt_nacompanhar.png" onclick="fncCadastrarAssuntoAcompanhar(' + IdAssunto + ',this)" />';
	}
	else {
		acompanhar = '<img src="images/bt_acompanhar.png" onclick="fncExcluirAssuntoAcompanhar(' + IdAssunto + ',this)" />';
	}
	
	if(IdName != IdNameConta) {
		responder = '<div id="responder" title="Responder" onclick="fncAddUserPost('+IdAssunto+',' + IdPerfil + ',' + "'"+IdName+"'" + ')"></div>';
	}
	else {
		responder = '';
	}
	
	$("body").append('<div id="popAssunto'+IdAssunto+'" class="popAssunto" onclick="fncZindexAssunto('+IdAssunto+');"><div id="header'+IdAssunto+'" class="header"><div id="conteudo"><div id="foto"><a href="'+IdName+'"><img src="'+FotoPerfil+'" width="48" height="48" /></a></div><div id="dados"><a href="'+IdName+'">'+IdName+'</a>'+responder+'</div><div id="botoes"><ul><li onclick="fncMinimizarAssunto(this,'+IdAssunto+')"><img src="images/bt_minimizar_assunto.jpg" /></li><li onclick="fncFecharAssunto(this,'+IdAssunto+')"><img src="images/bt_fechar_assunto.jpg" /></li></ul></div></div></div><div id="geral'+IdAssunto+'" class="geral"><div id="localAssunto"><div id="emoticons'+IdAssunto+'" class="emoticons"><h1>Emoticons:</h1><h2 onclick="fncFecharEmoticons('+IdAssunto+')">Fechar</h2><ul><li><img src="images/emoticons/1.png" onclick="fncAddEmoticon(1,'+IdAssunto+')" /></li><li><img src="images/emoticons/2.png" onclick="fncAddEmoticon(2,'+IdAssunto+')" /></li><li><img src="images/emoticons/3.png" onclick="fncAddEmoticon(3,'+IdAssunto+')" /></li><li><img src="images/emoticons/4.png" onclick="fncAddEmoticon(4,'+IdAssunto+')" /></li><li><img src="images/emoticons/5.png" onclick="fncAddEmoticon(5,'+IdAssunto+')" /></li><li><img src="images/emoticons/6.png" onclick="fncAddEmoticon(6,'+IdAssunto+')" /></li><li><img src="images/emoticons/7.png" onclick="fncAddEmoticon(7,'+IdAssunto+')" /></li><li><img src="images/emoticons/8.png" onclick="fncAddEmoticon(8,'+IdAssunto+')" /></li><li><img src="images/emoticons/9.png" onclick="fncAddEmoticon(9,'+IdAssunto+')" /></li><li><img src="images/emoticons/10.png" onclick="fncAddEmoticon(10,'+IdAssunto+')" /></li><li><img src="images/emoticons/11.png" onclick="fncAddEmoticon(11,'+IdAssunto+')" /></li><li><img src="images/emoticons/12.png" onclick="fncAddEmoticon(12,'+IdAssunto+')" /></li><li><img src="images/emoticons/13.png" onclick="fncAddEmoticon(13,'+IdAssunto+')" /></li><li><img src="images/emoticons/14.png" onclick="fncAddEmoticon(14,'+IdAssunto+')" /></li><li><img src="images/emoticons/15.png" onclick="fncAddEmoticon(15,'+IdAssunto+')" /></li><li><img src="images/emoticons/16.png" onclick="fncAddEmoticon(16,'+IdAssunto+')" /></li><li><img src="images/emoticons/17.png" onclick="fncAddEmoticon(17,'+IdAssunto+')" /></li><li><img src="images/emoticons/18.png" onclick="fncAddEmoticon(18,'+IdAssunto+')" /></li></ul></div><div id="conteudo"><h2 id="txtAssunto">'+fncStringCreate(Assunto)+'</h2><div id="controleAssunto"><ul><li>'+favorito+'</li><li>'+acompanhar+'</li></ul></div><h3>Yupis</h3><div id="listaPosts'+IdAssunto+'" class="listaPosts"></div></div><div id="localPostar"><div id="para'+IdAssunto+'" class="para"></div><div id="pvtAssuntoPost'+IdAssunto+'"></div><div id="descricao"><textarea id="inputPost'+IdAssunto+'" class="inputPost"></textarea><img src="images/bt_yupi.png" onclick="fncCadastrarPost('+IdAssunto+');" /></div><div id="emoticons"><h1>Emoticons:</h1><div id="icone"><img src="images/bt_emoticons.png" onclick="fncAbrirEmoticons('+IdAssunto+')" /></div></div><div id="contadorPost"><h1 id="charsLeftPost'+IdAssunto+'"></h1></div></div></div></div></div>');
	$('#inputPost'+IdAssunto+'').limit('150','#charsLeftPost'+IdAssunto);
	$('#popAssunto'+IdAssunto+'').draggable({ handle: '#header'+IdAssunto+'' });
	
	if(tema == "null") {
		$("#popAssunto"+IdAssunto+"").css("background-image","url(images/bgs_assunto/tecnologia.jpg)");
	}
	else {
		$("#popAssunto"+IdAssunto+"").css("background-image","url(images/bgs_assunto/"+tema+")");
	}
	
	fncObterPosts(IdAssunto);	
	
	fncCriaVarIntervaloAssunto(IdAssunto);
	
	intervaloAssunto[IdAssunto] = window.setInterval(function() {
		fncObterPosts(IdAssunto, "atualizar");
	}, 50000);
	
	
	$('#popAssunto')
    .bind('drag',function( event ){
            $( this ).css({
                    top: event.offsetY,
                    left: event.offsetX
                    });
            });
	
	$(function() {
		$("#inputPost"+IdAssunto+"").keypress(function (e) {
			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
				fncCadastrarPost(IdAssunto);
				return false;
			} else {
				return true;
			}
		});
	});
}

function fncAbrirEmoticons(IdAssunto){
	$("#emoticons"+IdAssunto+"").show();
}

function fncFecharEmoticons(IdAssunto){
	$("#emoticons"+IdAssunto+"").hide();
}

function fncAddEmoticon(emoticon, IdAssunto) {
	
	var emt;
	
	switch(emoticon) {
		case 1:
			emt = "[=)]";
		break;
		
		case 2:
			emt = "[=(]";
		break;
		
		case 3:
			emt = "[=\\]";
		break;
		
		case 4:
			emt = "[=P]";
		break;
		
		case 5:
			emt = "[=D]";
		break;
		
		case 6:
			emt = "[x_x]";
		break;
		
		case 7:
			emt = "[an]";
		break;
		
		case 8:
			emt = "[XD]";
		break;
		
		case 9:
			emt = "[=B]";
		break;
		
		case 10:
			emt = "[=S]";
		break;
		
		case 11:
			emt = "[=X]";
		break;
		
		case 12:
			emt = "[cry]";
		break;
		
		case 13:
			emt = "[=[]";
		break;
		
		case 14:
			emt = "[=*]";
		break;
		
		case 15:
			emt = "[^^]";
		break;
		
		case 16:
			emt = "[\\o/]";
		break;
		
		case 17:
			emt = "[S2]";
		break;
		
		case 18:
			emt = "[*_*]";
		break;
	}
	
	$("#inputPost"+IdAssunto+"").val($("#inputPost"+IdAssunto+"").val() + ''+emt+'');
	
	$("#emoticons"+IdAssunto+"").hide();
}

function fncAbrirAssunto(IdAssunto, item, IdPerfil, local, fav, acomp, tema) {
	
	var nome;
	var foto;
	var assunto;
	
	fncCriaVarUsuariosPost(IdAssunto);
	
	if(detectItem(idAssuntosMinimizados, IdAssunto)) {
		alert("Este assunto está minimizado.");
	}
	else {
		
		if(local == "home") {
			nome = $(item.parentNode.parentNode.childNodes[1].childNodes[0].childNodes[0]).html();
			foto = item.parentNode.parentNode.childNodes[0].childNodes[0].childNodes[0].src;
			pageTracker._trackPageview("Principal/Ualada");
		}
		
		if(local == "perfil") {
			nome = IdNamePerfil;
			foto = item.parentNode.parentNode.childNodes[0].childNodes[0].src;
			pageTracker._trackPageview("Perfil/Ualada");
		}
		
		if(local == "novosYupis") {
			nome = $(item.parentNode.childNodes[0].childNodes[0].childNodes[0]).html();
			foto = item.parentNode.parentNode.childNodes[0].childNodes[0].childNodes[0].src;
			pageTracker._trackPageview("NovosYupis/Ualada");
		}
		
		assunto = $(item).html();
		
		fncConteudoAssunto(IdAssunto, nome, IdPerfil, foto, assunto, fav, acomp, tema);
	}
}

function fncAbrirAssuntoCache(IdAssunto, IdName, FotoPerfil, Assunto, item, fav, acomp, tema) {
	
	if(detectItem(idAssuntosMinimizados, IdAssunto)) {
		alert("Este assunto está minimizado.");
	}
	else {
		
		var favorito;
		var acompanhar;
		var responder;
		
		fncCriaVarUsuariosPost(IdAssunto);
		
		fncAbrirFundoAcao();
		
	
		$(item.parentNode).remove();
		removeItem(idAssuntosMinimizados, IdAssunto);
		
		if(fav == 0) {
			favorito = '<img src="images/bt_nfavorito.png" onclick="fncCadastrarAssuntoFavorito(' + IdAssunto + ',this)" />';
		}
		else {
			favorito = '<img src="images/bt_favorito.png" onclick="fncExcluirAssuntoFavorito(' + IdAssunto + ',this)" />';
		}
		
		if(acomp == 0) {
			acompanhar = '<img src="images/bt_nacompanhar.png" onclick="fncCadastrarAssuntoAcompanhar(' + IdAssunto + ',this)" />';
		}
		else {
			acompanhar = '<img src="images/bt_acompanhar.png" onclick="fncExcluirAssuntoAcompanhar(' + IdAssunto + ',this)" />';
		}
		
		if(IdName != IdNameConta) {
			responder = '<div id="responder" title="Responder" onclick="fncAddUserPost('+IdAssunto+',' + IdPerfil + ',' + "'"+IdName+"'" + ')"></div>';
		}
		else {
			responder = '';
		}
		
		$("body").append('<div id="popAssunto'+IdAssunto+'" class="popAssunto" onclick="fncZindexAssunto('+IdAssunto+');"><div id="header'+IdAssunto+'" class="header"><div id="conteudo"><div id="foto"><a href="'+IdName+'"><img src="'+FotoPerfil+'" width="48" height="48" /></a></div><div id="dados"><a href="'+IdName+'">'+IdName+'</a>'+responder+'</div><div id="botoes"><ul><li onclick="fncMinimizarAssunto(this,'+IdAssunto+')"><img src="images/bt_minimizar_assunto.jpg" /></li><li onclick="fncFecharAssuntoCache(this,'+IdAssunto+')"><img src="images/bt_fechar_assunto.jpg" /></li></ul></div></div></div><div id="geral'+IdAssunto+'" class="geral"><div id="localAssunto"><div id="emoticons'+IdAssunto+'" class="emoticons"><h1>Emoticons:</h1><h2 onclick="fncFecharEmoticons('+IdAssunto+')">Fechar</h2><ul><li><img src="images/emoticons/1.png" onclick="fncAddEmoticon(1,'+IdAssunto+')" /></li><li><img src="images/emoticons/2.png" onclick="fncAddEmoticon(2,'+IdAssunto+')" /></li><li><img src="images/emoticons/3.png" onclick="fncAddEmoticon(3,'+IdAssunto+')" /></li><li><img src="images/emoticons/4.png" onclick="fncAddEmoticon(4,'+IdAssunto+')" /></li><li><img src="images/emoticons/5.png" onclick="fncAddEmoticon(5,'+IdAssunto+')" /></li><li><img src="images/emoticons/6.png" onclick="fncAddEmoticon(6,'+IdAssunto+')" /></li><li><img src="images/emoticons/7.png" onclick="fncAddEmoticon(7,'+IdAssunto+')" /></li><li><img src="images/emoticons/8.png" onclick="fncAddEmoticon(8,'+IdAssunto+')" /></li><li><img src="images/emoticons/9.png" onclick="fncAddEmoticon(9,'+IdAssunto+')" /></li><li><img src="images/emoticons/10.png" onclick="fncAddEmoticon(10,'+IdAssunto+')" /></li><li><img src="images/emoticons/11.png" onclick="fncAddEmoticon(11,'+IdAssunto+')" /></li><li><img src="images/emoticons/12.png" onclick="fncAddEmoticon(12,'+IdAssunto+')" /></li><li><img src="images/emoticons/13.png" onclick="fncAddEmoticon(13,'+IdAssunto+')" /></li><li><img src="images/emoticons/14.png" onclick="fncAddEmoticon(14,'+IdAssunto+')" /></li><li><img src="images/emoticons/15.png" onclick="fncAddEmoticon(15,'+IdAssunto+')" /></li><li><img src="images/emoticons/16.png" onclick="fncAddEmoticon(16,'+IdAssunto+')" /></li><li><img src="images/emoticons/17.png" onclick="fncAddEmoticon(17,'+IdAssunto+')" /></li><li><img src="images/emoticons/18.png" onclick="fncAddEmoticon(18,'+IdAssunto+')" /></li></ul></div><div id="conteudo"><h2 id="txtAssunto">'+fncStringCreate(Assunto)+'</h2><div id="controleAssunto"><ul><li>'+favorito+'</li><li>'+acompanhar+'</li></ul></div><h3>Yupis</h3><div id="listaPosts'+IdAssunto+'" class="listaPosts"></div></div><div id="localPostar"><div id="para'+IdAssunto+'" class="para"></div><div id="pvtAssuntoPost'+IdAssunto+'"></div><div id="descricao"><textarea id="inputPost'+IdAssunto+'" class="inputPost"></textarea><img src="images/bt_yupi.png" onclick="fncCadastrarPost('+IdAssunto+');" /></div><div id="emoticons"><h1>Emoticons:</h1><div id="icone"><img src="images/bt_emoticons.png" onclick="fncAbrirEmoticons('+IdAssunto+')" /></div></div><div id="contadorPost"><h1 id="charsLeftPost'+IdAssunto+'"></h1></div></div></div></div></div>');
		$('#inputPost'+IdAssunto+'').limit('150','#charsLeftPost'+IdAssunto);
		$('#popAssunto'+IdAssunto+'').draggable({ handle: '#header'+IdAssunto+'' });
		
		if(tema == "null") {
			$("#popAssunto"+IdAssunto+"").css("background-image","url(images/bgs_assunto/tecnologia.jpg)");
		}
		else {
			$("#popAssunto"+IdAssunto+"").css("background-image","url(images/bgs_assunto/"+tema+")");
		}
		
		fncObterPosts(IdAssunto);	
		
		fncCriaVarIntervaloAssunto(IdAssunto);
		
		intervaloAssunto[IdAssunto] = window.setInterval(function() {
			fncObterPosts(IdAssunto, "atualizar");
		}, 50000);
		
		
		$('#popAssunto')
	    .bind('drag',function( event ){
	            $( this ).css({
	                    top: event.offsetY,
	                    left: event.offsetX
	                    });
	            });
		
		$(function() {
			$("#inputPost"+IdAssunto+"").keypress(function (e) {
				if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
					fncCadastrarPost(IdAssunto);
					return false;
				} else {
					return true;
				}
			});
		});
	}
}

function fncFecharAssunto(item, IdAssunto) {
	$(item.parentNode.parentNode.parentNode.parentNode.parentNode).remove();
	fncFecharFundoAcao();
	clearInterval(intervaloAssunto[IdAssunto]);
}

function fncFecharAssuntoCache(item, IdAssunto) {
	$(item.parentNode.parentNode.parentNode.parentNode.parentNode).remove();
	fncFecharFundoAcao();
	clearInterval(intervaloAssunto[IdAssunto]);
	
	$.ajax({
		type: "POST",
		url: "interfaces/ExcluirCacheAssuntosMinimizados.php",
		data: {_idAssunto:IdAssunto},
		cache: false,
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					//sucess
				}
			}
		}
	});
}

function fncMinimizarAssunto(item, idassunto) {	
	var descricao;
	var nome;
	var foto;
	if(detectItem(idAssuntosMinimizados, idassunto)) {
		alert("assunto ja minimizado");
	}
	else {
		
		idAssuntosMinimizados.push(idassunto);
		descricao = $(item.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[1].childNodes[0].childNodes[1].childNodes[0]).text();
		nome = $(item.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[0].childNodes[0].childNodes[1].childNodes[0]).html();
		foto = item.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].src;
		
		//alert(foto)
		$(item.parentNode.parentNode.parentNode.parentNode.parentNode).hide();
		$("#itensMinimizados").append('<li><h2 onclick="fncMaximizarAssunto(' + idassunto + ',' + "'"+nome+"'" + ',' + "'"+foto+"'" + ',' + "'"+descricao+"'" + ', this)">' + descricao.substr(0,15) + '...</h2><h3 onclick="fncFecharMinimizado(this, ' + idassunto + ')"></h3></li>');
		fncFecharFundoAcao();
		
		$.ajax({
			type: "POST",
			url: "interfaces/GravarCacheAssuntosMinimizados.php",
			data: {_idAssunto:idassunto, _descricao:descricao, _nome:nome, _foto:foto},
			cache: false,
			
			success: function(callback) {
				if(callback == "ErrorLogin") {
					document.location.href="index.shtml";
				}
				else {
					if(callback.indexOf("DieServer") != -1) {
						fncDieServer();
					}
					else {
						//sucess
					}
				}
			}
		});
		
	}
}

function fncLerCacheAssuntosMinimizados() {
	$.ajax({
		//type: "GET",
		url: "interfaces/LerCacheAssuntosMinimizados.php",
		cache: false,
		//data: {_tipo:tipo, _dadoUsuario:dadoUsuario, _interesses:idInteressesBusca},

		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					var objeto = eval(callback);
					if(callback != "null"){												
						for(x = 0; x < objeto.length; x++) {
							if(objeto[x].IdAssunto != "0000") {
								$("#itensMinimizados").append('<li><h2 onclick="fncAbrirAssuntoCache(' + objeto[x].IdAssunto + ',' + "'"+objeto[x].Nome+"'" + ',' + "'"+objeto[x].Foto+"'" + ',' + "'"+objeto[x].Descricao+"'" + ', this, ' + "'"+objeto[x].Fav+"'" + ',' + "'"+objeto[x].Acomp+"'" + ',' + "'"+objeto[x].Tema+"'" + ')">' + objeto[x].Descricao.substr(0,15) + '...</h2><h3 onclick="fncFecharMinimizadoCache(this, ' + objeto[x].IdAssunto + ')"></h3></li>');
							}
						}
					}
				}
			}
		}
	});
}



function fncMaximizarAssunto(IdAssunto, IdName, FotoPerfil, Assunto, item) {
	zin++;
	$(item.parentNode).remove();
	removeItem(idAssuntosMinimizados, IdAssunto);
	fncAbrirFundoAcao();
	$("#popAssunto"+IdAssunto+"").css("zIndex",zin);
	$("#popAssunto"+IdAssunto+"").show();
	
	$.ajax({
		type: "POST",
		url: "interfaces/ExcluirCacheAssuntosMinimizados.php",
		data: {_idAssunto:IdAssunto},
		cache: false,
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					//sucess
				}
			}
		}
	});

	//fncConteudoAssunto(IdAssunto, IdName, FotoPerfil, Assunto);
}

function fncFecharMinimizado(item, IdAssunto) {
	$(item.parentNode).remove();
	removeItem(idAssuntosMinimizados, IdAssunto);
	$("#popAssunto"+IdAssunto+"").remove();
	
	$.ajax({
		type: "POST",
		url: "interfaces/ExcluirCacheAssuntosMinimizados.php",
		data: {_idAssunto:IdAssunto},
		cache: false,
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					//sucess
				}
			}
		}
	});
}

function fncFecharMinimizadoCache(item, IdAssunto) {
	$(item.parentNode).remove();
	removeItem(idAssuntosMinimizados, IdAssunto);
	$("#popAssunto"+IdAssunto+"").remove();
	
	$.ajax({
		type: "POST",
		url: "interfaces/ExcluirCacheAssuntosMinimizados.php",
		data: {_idAssunto:IdAssunto},
		cache: false,
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					//sucess
				}
			}
		}
	});
}

function fncAddUserPost(IdAssunto, IdUsuario, IdName) {
	
	if(postPvtAssunto[IdAssunto] != 1) {
		fncCriaVarPvtAssunto(IdAssunto);
	}

	if(detectItem(idUsuariosPost[IdAssunto], IdUsuario)) {
		alert("Este usuário ja esta adicionado");
	}
	else {
		idUsuariosPost[IdAssunto].push(IdUsuario);
		
		if(postPvtAssunto[IdAssunto] == "") {
			$("#pvtAssuntoPost"+IdAssunto+"").html('<div id="privado"><input type="checkbox" name="pvtPost'+IdAssunto+'" value="1" /><h3>Privado</h3></div>');
		}
		
		$("#para"+IdAssunto+"").append('<div id="usuario"><h1>' + IdName + '</h1><h2 onclick="fncExcUserPost('+IdAssunto+',this,'+IdUsuario+')">x</h2></div>');
		
		postPvtAssunto[IdAssunto].push("1");
		
		//alert(idUsuariosPost.toString()); 
	}
	
}

function fncExcUserPost(IdAssunto, item, idusuario) {
	$(item.parentNode).remove();
	removeItem(idUsuariosPost[IdAssunto], idusuario);
	
	if(idUsuariosPost[IdAssunto].length == "0") {
		postPvtAssunto[IdAssunto] = [];
		$("#pvtAssuntoPost"+IdAssunto+"").html("");
	}
}

function fncObterPosts(idassunto,tipo) {
	var lock;
	var me;
	var resp;
	
	$.ajax({
		type: "POST",
		url: "interfaces/ObterPosts.php",
		cache: false,
		data: {_idAssunto:idassunto},
		
		beforeSend: function() {
			if(tipo != "atualizar") {
				$("#listaPosts"+idassunto+"").html("<div id='loadingPosts'><img src='images/loading_cubo_white.gif' /></div>");
			}
		},

		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					$("#listaPosts"+idassunto+"").html("");
					var objeto = eval(callback.substr(1));
					if(callback != "Cnull"){												
						for(x = 0; x < objeto.length; x++) {
							
							if(objeto[x].PVT == "1") {
								lock = '<img src="images/lock.png" />';
							}
							else {
								lock = '';
							}
							
							if(objeto[x].ME == "1") {
								me = 'me';
							}
							else {
								me = '';
							}
							
							if(objeto[x].idnameUser == IdNameConta) {
								resp = '';
							}
							else {
								resp = '<img src="images/icon_resp.png" onclick="fncAddUserPost('+idassunto+',' + objeto[x].idUser + ',' + "'"+objeto[x].idnameUser+"'" + ')" />';
							}
							
							$("#listaPosts"+idassunto+"").append('<div id="post" class="'+me+'"><div id="dados"><div id="foto"><a href="'+objeto[x].idnameUser+'"><img src="images/fotos_users/' + objeto[x].fotoUser + '" width="35" height="35" /></a></div><div id="descricao"><p>'+lock+'&nbsp;<strong><a href="'+objeto[x].idnameUser+'">' + objeto[x].idnameUser + '</a></strong> <span class="users">' + objeto[x].Users + '</span> ' + objeto[x].descricaoPost + '</p><div id="data">'+objeto[x].data+' as '+objeto[x].hora+'</div><div id="controle"></div></div></div><div id="opcoes">'+resp+'</div></div>');
						}
						
						
					}
					else {
						$("#listaPosts"+idassunto+"").append('<h1>Nenhuma resposta cadastrada, seja o primeiro a postar.</h1>');
					}
				}
			}
		}
	});
}

function fncCadastrarPost(IdAssunto) {
	var post = document.getElementById('inputPost'+IdAssunto).value;
	var pvt = $("input[name='pvtPost"+IdAssunto+"']:checked").val();
	
	if(!pvt) {
		pvt = "0";
	}
	
	if(post == "") {
		$("#inputPost"+IdAssunto+"").val("Escreva seu post...");
	}
	else {
		if(post == "Escreva seu post...") {
			$("#inputPost"+IdAssunto+"").val("Escreva seu post...");
		}
		else {
			$.ajax({
				type: "POST",
				url: "interfaces/CadastrarPost.php",
				data: {_post:post, _idAssunto:IdAssunto, _idUsuariosPost:idUsuariosPost[IdAssunto].toString(), _pvt:pvt},
				cache: false,
				
				success: function(callback) {
					if(callback == "ErrorLogin") {
						document.location.href="index.shtml";
					}
					else {
						if(callback.indexOf("DieServer") != -1) {
							fncDieServer();
						}
						else {
							if(callback == "C") {
								idUsuariosPost[IdAssunto] = [];
								postPvtAssunto[IdAssunto] = [];
								$("#para"+IdAssunto+"").html("");
								$("#pvtAssuntoPost"+IdAssunto+"").html("");
								$("#inputPost"+IdAssunto+"").val("");
								fncObterPosts(IdAssunto, "atualizar");
								pageTracker._trackPageview("Principal/Yupi");
							}
							
							if(callback == "CPF") {
								alert("Você esta tentando cadastrar vários yupis seguidamente. Aguarde alguns segundos...");
							}
						}
					}
				}
			});
		}
	}
}

function fncBuscarUsuario(tipoBusca) {
	var tipo = "buscausuario";
	var dados;
	var dadoUsuario = document.getElementById('inputDadoUsuario').value;
	var dadoUsuarioPop = document.getElementById('inputDadoUsuarioPop').value;
	
	if(tipoBusca == 1) {
		if(!dadoUsuarioPop){
			dadoUsuario = dadoUsuario;
		}
		else {
			dadoUsuario = dadoUsuarioPop;
		}
		dados = dadoUsuario;
	}
	
	if(tipoBusca == 2) {
		dados = idInteressesBusca;
	}
	
	if(dados == "") {
		alert("Sem informações para realizar a busca.");
	}
	else {
		$("#resultadosBusca").show();
		$("#qtdResultadosBusca").html("0");
		$.ajax({
			type: "GET",
			url: "interfaces/ObterUsuarios.php",
			cache: false,
			data: {_tipo:tipo, _dadoUsuario:dadoUsuario, _interesses:idInteressesBusca},
			
			beforeSend: function() {
				$("#conteudoBusca").html("<div id='loadingPosts'><img src='images/loading_cubo_white.gif' /></div>");
			},
	
			success: function(callback) {
				if(callback == "ErrorLogin") {
					document.location.href="index.shtml";
				}
				else {
					if(callback.indexOf("DieServer") != -1) {
						fncDieServer();
					}
					else {
						$("#conteudoBusca").html("");
						var objeto = eval(callback.substr(1));
						if(callback != "Cnull"){												
							for(x = 0; x < objeto.length; x++) {
								$("#conteudoBusca").append('<div id="resultado"><div id="foto"><a href="' + objeto[x].IdName + '"><img src="images/fotos_users/' + objeto[x].Foto + '" width="35" height="35" /></a></div><div id="dados"><h1><a href="' + objeto[x].IdName + '">' + objeto[x].Nome + '</a></h1></div><div id="controle"><h1><a href="' + objeto[x].IdName + '">Ver Perfil</a></h1></div></div>');
							}
							$("#qtdResultadosBusca").html(x);
						}
						else {
							$("#conteudoBusca").append('<div id="nenhum">Nenhum usuário encontrado.</div></h1>');
						}
					}
				}
			}
		});
	}
}

function fncAbrirBuscaDados(tipo) {	
	if(tipo == "2") {
		$("#localBuscaPop").show();
		$("#interesses").hide();
		$("#resultadosBusca").hide();
		document.getElementById('inputDadoUsuarioPop').value = "";
		idInteressesBusca = [];
	}
	else {
		if(!document.getElementById('inputDadoUsuario').value){
			document.getElementById('inputDadoUsuario').value = "";
		}
		else {
			fncAbrirFundoAcao();
			$("body").append('<div id="popBusca"><div id="titulo"><h1>Busca de usuários</h1><h3 onclick="fncFecharBusca()">Fechar</h3></div><div id="opcoes"><ul><li id="opc1PopBusca" class="ativo"><h2 onclick="fncAbrirBuscaDados(2)">por nome</h2></li><li id="opc2PopBusca" class="ativo"><h2 onclick="fncAbrirBuscaAfinidade(2)">por afinidade</h2></li></ul></div><div id="localBuscaPop"><input type="text" id="inputDadoUsuarioPop" /><img src="images/icon_busca.jpg" onclick="fncBuscarUsuario(1)" /></div><div id="interesses"><div id="tituloInteresses"><h1>Pessoas com interesses em comum aos meus</h1></div><div id="listaInteressesBusca"><ul id="itensInteressesBusca"></ul></div><div id="listaInteressesBuscaAdicionados"><ul id="itensInteressesBuscaAdicionados"></ul></div><div id="btFiltrar" onclick="fncBuscarUsuario(2)"></div></div><div id="resultadosBusca"><div id="tituloResultado"><div id="conteudo"><h1>Resultados da busca</h1><h2>Foram encontrados (<span id="qtdResultadosBusca"></span>) resultados</h2></div></div><div id="conteudoBusca"></div></div></div>');
			$("#localBuscaPop").show();
			$("#interesses").hide();
			document.getElementById('inputDadoUsuarioPop').value = document.getElementById('inputDadoUsuario').value;
			document.getElementById('inputDadoUsuario').value = "";
			fncBuscarUsuario(1);
			
			$(function() {
				$("#localBuscaPop").keypress(function (e) {
					if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
						fncBuscarUsuario("1");
						return false;
					} else {
						return true;
					}
				});
			});

		}	
	}
	$("#opc1PopBusca").removeClass('inativo');
	$("#opc1PopBusca").addClass('ativo');
	$("#opc2PopBusca").removeClass('ativo');
	$("#opc2PopBusca").addClass('inativo');
	
	pageTracker._trackPageview("Principal/BuscaDados");
}

function fncAbrirBuscaAfinidade(tipo) {
	if(tipo == "2") {
		$("#localBuscaPop").hide();
		$("#interesses").show();
		$("#resultadosBusca").hide();
		document.getElementById('inputDadoUsuarioPop').value = "";
		$("#itensInteressesBusca").html("");
		$("#itensInteressesBuscaAdicionados").html("");
		idInteressesBusca = [];
		fncObterInteressesBusca();
	}
	else {
		fncAbrirFundoAcao();
		document.getElementById('inputDadoUsuario').value = "";
		$("body").append('<div id="popBusca"><div id="titulo"><h1>Busca de usuários</h1><h3 onclick="fncFecharBusca()">Fechar</h3></div><div id="opcoes"><ul><li id="opc1PopBusca" class="ativo"><h2 onclick="fncAbrirBuscaDados(2)">por nome</h2></li><li id="opc2PopBusca" class="ativo"><h2 onclick="fncAbrirBuscaAfinidade(2)">por afinidade</h2></li></ul></div><div id="localBuscaPop"><input type="text" id="inputDadoUsuarioPop" /><img src="images/icon_busca.jpg" onclick="fncBuscarUsuario(1)" /></div><div id="interesses"><div id="tituloInteresses"><h1>Pessoas com interesses em comum aos meus</h1></div><div id="listaInteressesBusca"><ul id="itensInteressesBusca"></ul></div><div id="listaInteressesBuscaAdicionados"><ul id="itensInteressesBuscaAdicionados"></ul></div><div id="btFiltrar" onclick="fncBuscarUsuario(2)"></div></div><div id="resultadosBusca"><div id="tituloResultado"><div id="conteudo"><h1>Resultados da busca</h1><h2>Foram encontrados (<span id="qtdResultadosBusca"></span>) resultados</h2></div></div><div id="conteudoBusca"></div></div></div>');
		$("#localBuscaPop").hide();
		$("#interesses").show();
		fncObterInteressesBusca();
	}
	$("#opc1PopBusca").removeClass('ativo');
	$("#opc1PopBusca").addClass('inativo');
	$("#opc2PopBusca").removeClass('inativo');
	$("#opc2PopBusca").addClass('ativo');
	
	pageTracker._trackPageview("Principal/BuscaAfinidade");
}

function fncFecharBusca() {
	fncFecharFundoAcao();
	$("#popBusca").remove();
	idInteressesBusca = [];
}

function fncObterInteressesBusca() {
	var objeto = eval(interessesUsuario.substr(2));
	if(interessesUsuario != "Cnull"){
		
		for(x = 0; x < objeto.length; x++) {			
			$("#itensInteressesBusca").append('<li><h1>#'+ objeto[x].InteressesNome +'</h1><h2 onclick="fncAddInteresseBusca('+ objeto[x].InteressesId +','+"'"+objeto[x].InteressesNome+"'"+', this)"></h2></li>');
		}
		
	}
}

function fncAddInteresseBusca(IdInteresse, InteresseNome, item) {
	if(detectItem(idInteressesBusca, IdInteresse)) {
		alert("Este interesse ja esta adicionado");
	}
	else {
		$(item.parentNode).remove();
		idInteressesBusca.push(IdInteresse);
		$("#itensInteressesBuscaAdicionados").append('<li><h1>#'+InteresseNome+'</h1><h2 onclick="fncExcInteresseBusca('+IdInteresse+', '+"'"+InteresseNome+"'"+', this)"></h2></li>');
	}	
}

function fncExcInteresseBusca(IdInteresse, InteresseNome, item) {
	$(item.parentNode).remove();
	removeItem(idInteressesBusca, IdInteresse)
	$("#itensInteressesBusca").append('<li><h1>#'+InteresseNome+'</h1><h2 onclick="fncAddInteresseBusca('+IdInteresse+', '+"'"+InteresseNome+"'"+', this)"></h2></li>');
}

function fncOpenOpcoesAssuntos() {
	statusOpcoesAssuntos = 0;
	
	var pag1;
	var pag2;
	var pag3;
	var pag4;
	var pag5;
	
	if(PaginaConta == 1) {pag1 = "ativo";} else { pag1 = "inativo";}
	if(PaginaConta == 2) {pag2 = "ativo";} else { pag2 = "inativo";}
	if(PaginaConta == 3) {pag3 = "ativo";} else { pag3 = "inativo";}
	if(PaginaConta == 4) {pag4 = "ativo";} else { pag4 = "inativo";}
	if(PaginaConta == 5) {pag5 = "ativo";} else { pag5 = "inativo";}
	if(PaginaConta == 0) {pag2 = "ativo";}
	
	$("body").append('<div id="opcoesAssuntos" onmouseout="fncCloseOpcoesAssuntos()"><ul><li><h1 onclick="fncTrocarHash('+"'UaladasInteresses'"+')">Ualadas por Interesses</h1><h2 onclick="fncSetPagDefault(5)" class="'+pag5+'" title="Definir Ualadas por Interesses como minha página principal."></h2></li><li><h1 onclick="fncTrocarHash('+"'UaladasPublicas'"+')">Ualadas Públicas</h1><h2 onclick="fncSetPagDefault(1)" class="'+pag1+'" title="Definir Ualadas Públicas como minha página principal."></h2></li><li><h1 onclick="fncTrocarHash('+"'UaladasAmigos'"+')">Ualadas de Amigos</h1><h2 onclick="fncSetPagDefault(2)" class="'+pag2+'" title="Definir Ualadas de Amigos como minha página principal."></h2></li><li><h1 onclick="fncTrocarHash('+"'UaladasFavoritas'"+')">Ualadas Favoritas</h1><h2 onclick="fncSetPagDefault(3)" class="'+pag3+'" title="Definir Ualadas Favoritas como minha página principal."></h2></li><li><h1 onclick="fncObterAssuntos('+"'meus'"+')">Minhas Ualadas</h1><h2 onclick="fncSetPagDefault(4)" class="'+pag4+'" title="Definir Minhas Ualadas como minha página principal."></h2></li></ul></div>');
}

function fncCloseOpcoesAssuntos() {
	statusOpcoesAssuntos = 1;
}

function fncSetPagDefault(pag) {
	var tipo = "pagina";
	var dado = pag;
	
	$.ajax({
		type: "GET",
		url: "interfaces/EditarConfiguracoes.php",
		data: {_tipo:tipo, _dado:dado},
		cache: false,
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						PaginaConta = pag;
					}
					else {
						alert("erro");
					}
				}
			}
		}
	});
}

function fncFavoritarAmigo(IdPerfilAmigo, local, item) {
	var area = window.location.href.split("/");
	
	$.ajax({
		type: "GET",
		url: "interfaces/FavoritarAmigo.php",
		data: {_idPerfilAmigo:IdPerfilAmigo},
		cache: false,
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(local == "perfil") {
						document.location.href=""+area[4]+"";
					}
					else {
						alert("Amigo Favoritado");
						//alert(item.parentNode.id)
						$(item.parentNode).html('<img src="images/icon_favorito.png" onclick="fncDesfavoritarAmigo('+IdPerfilAmigo+','+"'aba'"+', this)" title="Desfavoritar Ualeiro" />');
					}
				}
			}
		}
	});
}

function fncDesfavoritarAmigo(IdPerfilAmigo, local, item) {
	var area = window.location.href.split("/");
	
	$.ajax({
		type: "GET",
		url: "interfaces/DesfavoritarAmigo.php",
		data: {_idPerfilAmigo:IdPerfilAmigo},
		cache: false,
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(local == "perfil") {
						document.location.href=""+area[4]+"";
					}
					else {
						alert("Amigo Desfavoritado");
						$(item.parentNode).html('<img src="images/icon_naofavorito.png" onclick="fncFavoritarAmigo('+IdPerfilAmigo+','+"'aba'"+', this)" title="Desfavoritar Ualeiro" />');
					}
				}
			}
		}
	});
}

function fncConvidarAmigo(IdPerfilAmigo, local) {
	var area = window.location.href.split("/");
	
	$.ajax({
		type: "GET",
		url: "interfaces/ConvidarAmigo.php",
		data: {_idPerfilAmigo:IdPerfilAmigo},
		cache: false,
		
		beforeSend: function() {
			//$("#loadAdicionarInteresse").html('<img src="images/loading_circle_24_24.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(local == "perfil") {
						document.location.href=""+area[4]+"";
					}
				}
			}
		}
	});
}

var itemAmigoPerfil;

function fncExcluirAmigo(IdPerfilAmigo, local, item) {
	fncAbrirFundoAcao();

	itemAmigoPerfil = item;

	var IdNameAmigo;
	
	if(local == "perfil") {
		IdNameAmigo = $("#userName").html();
	}
	else {
		IdNameAmigo = $(item.parentNode.parentNode.parentNode.childNodes[1].childNodes[0].childNodes[0]).html()
	}
	$("body").append('<div id="popUpsExcluirAmigo" class="popUps"><div id="titulo"><h1 id="tituloUps">Ups!</h1></div><div id="conteudo"><h1 id="perguntaUps">Deseja excluir este amigo:</h1><h2 id="infoUps">'+IdNameAmigo+'</h2><div id="controleUps"><img src="images/bt_sim.png" onclick="fncConfirmarExcluirAmigo('+IdPerfilAmigo+','+"'"+local+"'"+');" /> <img src="images/bt_nao.png" onclick="fncNaoExcluirAmigo();" /></div></div></div>');
}

function fncNaoExcluirAmigo() {
	fncFecharFundoAcao();
	$("#popUpsExcluirAmigo").remove();
}

function fncConfirmarExcluirAmigo(IdPerfilAmigo, local, item) {

	var area = window.location.href.split("/");
	
	$.ajax({
		type: "GET",
		url: "interfaces/ExcluirAmigo.php",
		data: {_idPerfilAmigo:IdPerfilAmigo},
		cache: false,
		
		beforeSend: function() {
			//$("#loadAdicionarInteresse").html('<img src="images/loading_circle_24_24.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(local == "perfil") {
						fncFecharFundoAcao();
						$("#popUpsExcluirAmigo").remove();
						document.location.href=""+area[4]+"";
					}
					else{
						alert("Amigo Excluido");
						fncFecharFundoAcao();
						$("#popUpsExcluirAmigo").remove();
						$(itemAmigoPerfil.parentNode.parentNode.parentNode).remove();
					}
				}
			}
		}
	});
}

function fncBloquearAmigo(IdPerfilAmigo, local) {
	fncAbrirFundoAcao();
	
	var IdNameAmigo;
	
	if(local == "perfil") {
		IdNameAmigo = $("#userName").html();
	}
	$("body").append('<div id="popUpsBloquearAmigo" class="popUps"><div id="titulo"><h1 id="tituloUps">Ups!</h1></div><div id="conteudo"><h1 id="perguntaUps">Deseja bloquear este amigo:</h1><h2 id="infoUps">'+IdNameAmigo+'</h2><div id="controleUps"><img src="images/bt_sim.png" onclick="fncConfirmarBloquearAmigo('+IdPerfilAmigo+','+"'"+local+"'"+');" /> <img src="images/bt_nao.png" onclick="fncNaoBloquearAmigo();" /></div></div></div>');
}

function fncNaoBloquearAmigo() {
	fncFecharFundoAcao();
	$("#popUpsBloquearAmigo").remove();
}

function fncConfirmarBloquearAmigo(IdPerfilAmigo, local) {
	var area = window.location.href.split("/");
	$.ajax({
		type: "GET",
		url: "interfaces/BloquearAmigo.php",
		data: {_idPerfilAmigo:IdPerfilAmigo},
		cache: false,
		
		beforeSend: function() {
			//$("#loadAdicionarInteresse").html('<img src="images/loading_circle_24_24.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(local == "perfil") {
						fncFecharFundoAcao();
						$("#popUpsBloquearAmigo").remove();
						document.location.href=""+area[4]+"";
					}
				}
			}
		}
	});
}

function fncDesbloquearAmigo(IdPerfilAmigo, local) {
	fncAbrirFundoAcao();
	
	var IdNameAmigo;
	
	if(local == "perfil") {
		IdNameAmigo = $("#userName").html();
	}
	$("body").append('<div id="popUpsDesbloquearAmigo" class="popUps"><div id="titulo"><h1 id="tituloUps">Ups!</h1></div><div id="conteudo"><h1 id="perguntaUps">Deseja desbloquear este amigo:</h1><h2 id="infoUps">'+IdNameAmigo+'</h2><div id="controleUps"><img src="images/bt_sim.png" onclick="fncConfirmarDesbloquearAmigo('+IdPerfilAmigo+','+"'"+local+"'"+');" /> <img src="images/bt_nao.png" onclick="fncNaoDesbloquearAmigo();" /></div></div></div>');
}

function fncConfirmarDesbloquearAmigo(IdPerfilAmigo, local) {
	var area = window.location.href.split("/");
	$.ajax({
		type: "GET",
		url: "interfaces/DesbloquearAmigo.php",
		data: {_idPerfilAmigo:IdPerfilAmigo},
		cache: false,
		
		beforeSend: function() {
			//$("#loadAdicionarInteresse").html('<img src="images/loading_circle_24_24.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(local == "perfil") {
						fncFecharFundoAcao();
						$("#popUpsDesbloquearAmigo").remove();
						document.location.href=""+area[4]+"";
					}
				}
			}
		}
	});
}

function fncNaoDesbloquearAmigo() {
	fncFecharFundoAcao();
	$("#popUpsDesbloquearAmigo").remove();
}

function fncAbrirConvites(tipoAba, tipoDado) {
	if(tipoAba == 1 && tipoDado == 1) {
		fncAbrirFundoAcao();
		$("body").append('<div id="popConvites"><div id="titulo"><h1>Convites</h1><h3 onclick="fncFecharConvites()">Fechar</h3></div><div id="opcoes"><ul><li id="opc1PopConvites" class="ativo"><h2 onclick="fncAbrirConvites(2,1)">recebidos</h2></li><li id="opc2PopConvites" class="inativo"><h2 onclick="fncAbrirConvites(2,2)">enviados</h2></li></ul></div><div id="resultadosConvites"><div id="tituloResultado"><div id="conteudo"><h1>Ualeiros</h1><h2><span id="qtdConvitesPop"></span></h2></div></div><div id="conteudoConvites"></div></div></div>');
		fncObterConvites(1);
	}
	
	if(tipoAba == 2 && tipoDado == 1){
		$("#opc1PopConvites").removeClass('inativo');
		$("#opc1PopConvites").addClass('ativo');
		$("#opc2PopConvites").removeClass('ativo');
		$("#opc2PopConvites").addClass('inativo');
		fncObterConvites(1);
	}
	
	if(tipoAba == 2 && tipoDado == 2){
		$("#opc1PopConvites").removeClass('ativo');
		$("#opc1PopConvites").addClass('inativo');
		$("#opc2PopConvites").removeClass('inativo');
		$("#opc2PopConvites").addClass('ativo');
		fncObterConvites(2);
	}
}

function fncObterConvites(tipo) {
	$("#qtdConvitesPop").html("");
	$.ajax({
		type: "GET",
		url: "interfaces/ObterConvites.php",
		data: {_tipo:tipo},
		cache: false,
		
		beforeSend: function() {
			if(tipo != "qtd") {
				$("#conteudoConvites").html('<img src="images/loading_circle_24_24.gif" />');
			}
		},

		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {					
					if(tipo == 1 || tipo == 2) {
						$("#conteudoConvites").html('');
						var objeto = eval(callback.substr(1));
						if(callback != "Cnull"){
							$("#qtdConvitesPop").html("convites(" + objeto.length + ")");
							for(x = 0; x < objeto.length; x++) {
								if(tipo == 1) {
									$("#conteudoConvites").append('<div id="resultado"><div id="foto"><img src="images/fotos_users/'+objeto[x].FotoAmigo+'" width="35" height="35" /></div><div id="dados"><h1>'+objeto[x].NomeAmigo+'</h1></div><div id="controle"><h1><a href="'+objeto[x].IdNameAmigo+'">Ver Perfil</a></h1><h2 onclick="fncAceitarConvite('+objeto[x].IdPerfilAmigo+')">Aceitar</h2><h3 onclick="fncRecusarConvite('+objeto[x].IdPerfilAmigo+')">Recusar</h3></div></div>');
								}
								else {
									$("#conteudoConvites").append('<div id="resultado"><div id="foto"><img src="images/fotos_users/'+objeto[x].FotoAmigo+'" width="35" height="35" /></div><div id="dados"><h1>'+objeto[x].NomeAmigo+'</h1></div><div id="controle"><h1><a href="'+objeto[x].IdNameAmigo+'">Ver Perfil</a></h1><h3 onclick="fncCancelarConvite('+objeto[x].IdConvite+')">Cancelar</h3></div></div>');
								}
							}
						}
						else {
							$("#conteudoConvites").append('<div id="nenhum"><h1>Nenhum convite.</h1></div>');
						}
					}
					if(tipo == "qtd") {
						$("#qtdConvitesLateral").html(callback.substr(1));
					}
				}
			}
		}
	});
}

function fncAceitarConvite(IdPerfilAmigo) {
	$.ajax({
		type: "GET",
		url: "interfaces/AceitarConvite.php",
		data: {_idPerfilAmigo:IdPerfilAmigo},
		cache: false,
		
		beforeSend: function() {
			//$("#loadAdicionarInteresse").html('<img src="images/loading_circle_24_24.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC"){
						fncObterConvites(1);
					}
				}
			}
		}
	});
}

function fncRecusarConvite(IdPerfilAmigo) {
	$.ajax({
		type: "GET",
		url: "interfaces/RecusarConvite.php",
		data: {_idPerfilAmigo:IdPerfilAmigo},
		cache: false,
		
		beforeSend: function() {
			//$("#loadAdicionarInteresse").html('<img src="images/loading_circle_24_24.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC"){
						fncObterConvites(1);
					}
				}
			}
		}
	});
}

function fncCancelarConvite(IdConvite) {
	$.ajax({
		type: "GET",
		url: "interfaces/CancelarConvite.php",
		data: {_idConvite:IdConvite},
		cache: false,
		
		beforeSend: function() {
			//$("#loadAdicionarInteresse").html('<img src="images/loading_circle_24_24.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC"){
						fncObterConvites(2);
					}
				}
			}
		}
	});
}

function fncFecharConvites() {
	fncFecharFundoAcao();
	$("#popConvites").remove();
}

var numIniFeeds = 0;

function fncObterBlogFeeds(LimitIni) {
	
	var mais;
	
	$("#localBlogFeeds").remove();
	
	$("body").append('<div id="localBlogFeeds"><h1>Ultimos posts</h1><h2 onclick="fncFecharBlogFeeds()">Fechar</h2><ul id="listaBlogFeeds"></ul></div>');
	
	$.ajax({
		type: "GET",
		url: "interfaces/ObterBlogFeeds.php",
		data: {_limitIni:numIniFeeds},
		cache: false,
		
		beforeSend: function() {
			$("#listaBlogFeeds").html('<div id="loadingFeeds"><img src="images/loading_cubo.gif" /></div>');
		},

		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					$("#listaBlogFeeds").html('');
					var objeto = eval(callback.substr(1));
					if(callback != "Cnull"){												
						for(x = 0; x < objeto.length; x++) {
							$("#listaBlogFeeds").append('<li title="'+objeto[x].Data+' '+objeto[x].Hora+' - '+objeto[x].id+'"><a href="'+objeto[x].idName+'"><img src="images/fotos_users/'+objeto[x].FotoPerfil+'" width="35" height="35" /></a><h1><a href="'+objeto[x].idName+'">'+objeto[x].idName+'</a></h1><p><a href="'+objeto[x].link+'" target="_blank">'+objeto[x].titulo+'</a></p></li>');
						}
					
					
						numIniFeeds = numIniFeeds + 8;
						
						mais = '<div id="mais" onclick="fncObterBlogFeeds('+numIniFeeds+')"><img src="images/bt_mais2.png" /></div>';
						
						$("#listaBlogFeeds").append('<div id="cadastre"><img src="images/bt_cadblog.png" onclick="fncAbrirConfigurarBlog()" /></div>'+mais+'');
					}
				}
			}
		}
	});
}

function fncFecharBlogFeeds() {
	fncFecharFundoAcao();
	numIniFeeds = 0;
	$("#localBlogFeeds").remove();
}

function fncAbrirConfigurarBlog() {
	fncAbrirFundoAcao();
	$("body").append('<div id="popBlog"><div id="titulo"><h1>Configure seu Blog no Ualah!</h1><h3 onclick="fncFecharPopBlog()">Fechar</h3></div><div id="conteudo"><h1>Quer ajuda para divulgar seu Blog?</h1><p>Cadastre o RSS do seu blog abaixo, e a cada atualiza&ccedil;&atilde;o seus feeds ser&atilde;o postados aqui no Ualah! &Eacute; uma inovadora forma de divulga&ccedil;&atilde;o e compartilhamento de blogs.</p><h2>Link do RSS:</h2><input type="text" id="inputLinkRss" /><div id="btCadastrarUrlRssBlog"></div><h3>ex: http://feeds.feedburner.com/GarotasNerds?format=xml</h3></div></div>');
	
	$.ajax({
		type: "POST",
		url: "interfaces/ObterUrlBlogFeed.php",
		cache: false,
		
		beforeSend: function() {
			$("#inputLinkRss").val("carregando...");
		},
		
		success: function(callback) {
			
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback.substr(1) != "") {
						if(callback.substr(1) == "E") {
							$("#inputLinkRss").val("");
							$("#btCadastrarUrlRssBlog").html('<img src="images/bt_cadlink.png" onclick="fncCadastrarUrlRssBlog()" />');
						}
						else {
							$("#inputLinkRss").val(callback.substr(1));
							$("#btCadastrarUrlRssBlog").html('<img src="images/bt_removerlink.png" onclick="fncRemoverUrlRssBlog()" />');
						}
						
					}
				}
			}
		}
	});
}

function fncCadastrarUrlRssBlog() {

	var urlRssBlog = $("#inputLinkRss").val();

	$.ajax({
		type: "POST",
		url: "interfaces/CadastrarUrlBlogFeed.php",
		data: {_urlRssBlog:urlRssBlog},
		cache: false,
		
		beforeSend: function() {
			$("#btCadastrarUrlRssBlog").html('<img src="images/loading_circle_24_24_white.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						$("#btCadastrarUrlRssBlog").html('<img src="images/bt_removerlink.png" onclick="fncRemoverUrlRssBlog()" />');
					}
					else {
						alert("Não foi possível cadastrar esta url.");
						$("#btCadastrarUrlRssBlog").html('<img src="images/bt_cadlink.png" onclick="fncCadastrarUrlRssBlog()" />');
					}
				}
			}
		}
	});
}

function fncRemoverUrlRssBlog() {
	$("body").append('<div id="popUpsExcluirUrlRssBlog" class="popUps"><div id="titulo"><h1 id="tituloUps">Ups!</h1></div><div id="conteudo"><h1 id="perguntaUps">Deseja excluir o seu blog do Ualah?</h1><h2 id="infoUps">Todos os seus feeds cadastrados no Ualah serão excluidos.</h2><div id="controleUps"><img src="images/bt_sim.png" onclick="fncConfirmarRemoverUrlRssBlog();" /> <img src="images/bt_nao.png" onclick="fncNaoExcluirUrlRssBlog();" /></div></div></div>');
}

function fncNaoExcluirUrlRssBlog() {
	fncFecharFundoAcao();
	$("#popUpsExcluirUrlRssBlog").remove();
}

function fncConfirmarRemoverUrlRssBlog() {
	$.ajax({
		type: "POST",
		url: "interfaces/ExcluirUrlBlogFeed.php",
		cache: false,
		
		beforeSend: function() {
			$("#controleUps").html('<img src="images/loading_circle_24_24.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						$("#inputLinkRss").val("");
						$("#popUpsExcluirUrlRssBlog").remove();
						$("#btCadastrarUrlRssBlog").html('<img src="images/bt_cadlink.png" onclick="fncCadastrarUrlRssBlog()" />');
					}
				}
			}
		}
	});
}

function fncFecharPopBlog() {
	fncFecharFundoAcao();
	$("#popBlog").remove();
}

var qtdNovosYupis;
var arrIdAssuntosLeu = new Array();
var cadeadoAssuntoPvtNovosYupis;

function fncObterNovosYupis(tipo, IdAssunto) {
	if(tipo == "assuntos") {
		$("#conteudoAssuntosSite").html('<div id="novosYupis"><div id="atualizar" title="Atualizar Novos Yupis"><div id="botao" onclick="fncObterNovosYupis('+"'assuntos'"+')"></div></div><div id="localUalahdas"><div id="titulo"><h1>Ualadas</h1></div><div id="resultadosYupis"></div><div id="voltarNovosYupis"><img src="images/bt_voltar.png" onclick="fncTrocarHash('+"'UaladasPublicas'"+')" /></div></div>');
	}
	
	$.ajax({
		type: "GET",
		url: "interfaces/ObterNovosYupis.php",
		data: {_tipo:tipo, _idAssunto:IdAssunto},
		cache: false,
		
		beforeSend: function() {
			if(tipo == "assuntos") {
				$("#resultadosYupis").html('<img src="images/loading_circle_24_24_white.gif" />');
			}
		},

		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {					
					if(callback != "Cnull"){
						if(tipo == "assuntos") {
							$("#resultadosYupis").html("");
							var objeto = eval(callback.substr(1));
							for(x = 0; x < objeto.length; x++) {
								
								if(objeto[x].AssPvt == "1") {
									cadeadoAssuntoPvtNovosYupis = '<img src="images/lock.png" title="Ualada Privada." /> ';
								}
								else {
									cadeadoAssuntoPvtNovosYupis = '';
								}

								$("#resultadosYupis").append('<div id="ualahda"><div id="foto"><a href="'+objeto[x].IdName+'"><img src="images/fotos_users/'+objeto[x].FotoPerfil+'" width="50" height="50" /></a></div><div id="dados"><div id="privado">'+cadeadoAssuntoPvtNovosYupis+'</div><h1><strong><a href="'+objeto[x].IdName+'">'+objeto[x].IdName+'</a></strong></h1><p onclick="fncAbrirAssunto(' + objeto[x].IdAssunto + ', this, ' + objeto[x].IdPerfil + ', '+"'novosYupis'"+','+objeto[x].Favorito+','+objeto[x].Acomp+','+"'"+objeto[x].Tema+"'"+');">'+objeto[x].Ualahda+'</p><h2>'+objeto[x].Data+' as '+objeto[x].Hora+'</h2><div id="verNovos'+objeto[x].IdAssunto+'" class="verNovos" onclick="fncVerNovosYupis(this,' + objeto[x].IdAssunto + ')"><div id="qtd">'+ objeto[x].QtdNovos +'</div></div></div><h3>'+ objeto[x].QtdPosts +' yupis</h3><div id="localYupis'+objeto[x].IdAssunto+'" class="localYupis"></div></div>');
								arrIdAssuntosLeu.push(objeto[x].IdAssunto);
							}
							$("#voltarNovosYupis").append('<img src="images/litudo.png" onclick="fncLeuNovosYupisTodos('+"'LerTodos'"+')" />');
						}
						if(tipo == "qtd") {
							$("#qtdNovosYupis").html(callback.substr(1));
							qtdNovosYupis = callback.substr(1);
							if(qtdNovosYupis == 0){
								$("#resultadosYupis").html('<div id="semNovos"><h1>Não há novos Yupis.</h1></div>');
								$("#voltarNovosYupis").html('<img src="images/bt_voltar.png" onclick="fncTrocarHash('+"'UaladasPublicas'"+')" />');
							}
						}
					}
					else {
						$("#resultadosYupis").html('<div id="semNovos"><h1>Não há novos Yupis.</h1></div>');
					}
				}
			}
		}
	});
}

function fncVerNovosYupis(item, IdAssunto) {
	
	var tipo = "posts";
	
	$(item).hide();
	$("#localYupis"+IdAssunto+"").show();
	
	$.ajax({
		type: "GET",
		url: "interfaces/ObterNovosYupis.php",
		data: {_tipo:tipo, _idAssunto:IdAssunto},
		cache: false,
		
		beforeSend: function() {
			$("#localYupis"+IdAssunto+"").html('<img src="images/loading_circle_24_24_white.gif" />');
		},

		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					$("#localYupis"+IdAssunto+"").html('');
					var objeto = eval(callback.substr(1));
					if(callback != "Cnull"){
						
						$("#localYupis"+IdAssunto+"").append('<div id="novos">'+ objeto[0].QtdNovos +' novos</div>');
						
						for(x = 0; x < objeto.length; x++) {							
							$("#localYupis"+IdAssunto+"").append('<div id="yupi"><div id="fotoYupi"><a href="'+objeto[x].IdName+'"><img src="images/fotos_users/'+objeto[x].FotoPerfil+'" width="35" height="35" /></a></div><h1><strong><a href="'+objeto[x].IdName+'">'+objeto[x].IdName+'</a></strong> '+objeto[x].Yupi+'</h1></div>');
						}
						
						$("#localYupis"+IdAssunto+"").append('<div id="lidos" onclick="fncLeuNovosYupis('+"'LerAssunto'"+','+IdAssunto+', this)"><div id="qtd">'+ objeto[0].QtdNovos +'</div></div><div id="cancelar" onclick="fncFecharNovosYupis(this,' + IdAssunto + ')"></div>');
						
					}
				}
			}
		}
	});
}

function fncLeuNovosYupis(tipo, IdAssunto, item) {
	
	$.ajax({
		type: "GET",
		url: "interfaces/LeuNovosPosts.php",
		data: {_tipo:tipo, _idAssunto:IdAssunto},
		cache: false,
		
		beforeSend: function() {
			//$("#btCadastrarUrlRssBlog").html('<img src="images/loading_circle_24_24_white.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						$(item.parentNode.parentNode).remove();
						fncObterNovosYupis("qtd");
					}
					else {
						//
					}
				}
			}
		}
	});
}

function fncLeuNovosYupisTodos(tipo) {
	
	//alert(arrIdAssuntosLeu.toString())
	
	$.ajax({
		type: "GET",
		url: "interfaces/LeuNovosPosts.php",
		data: {_tipo:tipo, _arrIdAssuntos:arrIdAssuntosLeu.toString()},
		cache: false,
		
		beforeSend: function() {
			//$("#btCadastrarUrlRssBlog").html('<img src="images/loading_circle_24_24_white.gif" />');
		},
		
		success: function(callback) {
			if(callback == "ErrorLogin") {
				document.location.href="index.shtml";
			}
			else {
				if(callback.indexOf("DieServer") != -1) {
					fncDieServer();
				}
				else {
					if(callback == "CC") {
						$("#resultadosYupis").html('<div id="semNovos"><h1>Não há novos Yupis.</h1></div>');
						$("#voltarNovosYupis").html('<img src="images/bt_voltar.png" onclick="fncTrocarHash('+"'UaladasPublicas'"+')" />');
						fncObterNovosYupis("qtd");
					}
					else {
						//
					}
				}
			}
		}
	});
}


function fncFecharNovosYupis(item, IdAssunto) {
	//$(item).hide();
	$("#localYupis"+IdAssunto+"").hide();
	$("#verNovos"+IdAssunto+"").show();
}

var LocalDescBusca;

function fncTrocarHash(tipo, pais, local) {
	document.location.href="Default.shtml#" + tipo + "";
	
	LocalDescBusca = local;
	
	if(tipo == "UaladasRelacionadas") {
		fncObterAssuntos('relacionar',pais,LocalDescBusca);
	}
	
	pageTracker._trackPageview("Principal/" + tipo + "");
}

function fncObterHash() {
	function pageload(hash) {
		if(hash) {
			
			if(hash == "UaladasInteresses") {
				fncObterAssuntos("interesses",1);
				$("#tituloLocalPagina").html("(por Interesses)");
			}
			
			if(hash == "UaladasPublicas") {
				fncObterAssuntos("publicos",1)
				$("#tituloLocalPagina").html("(Públicas)");
			}
			
			if(hash == "UaladasAmigos") {
				fncObterAssuntos("amigos",1)
				$("#tituloLocalPagina").html("(Amigos)");
			}
			
			if(hash == "UaladasFavoritas") {
				fncObterAssuntos("favoritos",1)
				$("#tituloLocalPagina").html("(Favoritas)");
			}
			
			/*
			if(hash == "UaladasRelacionadas") {
				alert(LocalDescBusca)
				fncObterAssuntos('relacionar',1,LocalDescBusca);
				$("#tituloLocalPagina").html("");
			}
			*/
			
			if(hash == "NovosYupis") {
				fncObterNovosYupis("assuntos");
				$("#tituloLocalPagina").html("");
			}
			
		} else {
			// start page
			$("#load").empty();
		}
	}

	$(document).ready(function(){
		// Initialize history plugin.
		// The callback is called at once by present location.hash. 
		$.historyInit(pageload);
		
		// set onlick event for buttons
		$("a[rel='history']").click(function(){
			// 
			var hash = this.href;
			hash = hash.replace(/^.*#/, '');
			// moves to a new page. 
			// pageload is called at once. 
			// hash don't contain "#", "?"
			$.historyLoad(hash);
			return false;
		});
	});
}

var pag;

function fncObterHashSafariChrome() {	
	
	var area = window.location.href.split("#");
	
	if(area[1] == "UaladasInteresses" && pag != "UaladasInteresses") {
		fncObterAssuntos("interesses",1);
		$("#tituloLocalPagina").html("(por Interesses)");
	}
	
	if(area[1] == "UaladasPublicas" && pag != "UaladasPublicas") {
		fncObterAssuntos("publicos",1)
		$("#tituloLocalPagina").html("(Públicas)");
	}
	
	if(area[1] == "UaladasAmigos" && pag != "UaladasAmigos") {
		fncObterAssuntos("amigos",1)
		$("#tituloLocalPagina").html("(Amigos)");
	}
	
	if(area[1] == "UaladasFavoritas" && pag != "UaladasFavoritas") {
		fncObterAssuntos("favoritos",1)
		$("#tituloLocalPagina").html("(Favoritas)");
	}
	
	if(area[1] == "NovosYupis" && pag != "NovosYupis") {
		fncObterNovosYupis("assuntos");
		$("#tituloLocalPagina").html("");
	}
	
	pag = area[1];
}

function fncLogoUalah() {
	if(PaginaConta == 0) {
		document.location.href="Default.shtml#UaladasAmigos";
	}
	
	if(PaginaConta == 1) {
		document.location.href="Default.shtml#UaladasPublicas";
	}
	
	if(PaginaConta == 2) {
		document.location.href="Default.shtml#UaladasAmigos";
	}
	
	if(PaginaConta == 3) {
		document.location.href="Default.shtml#UaladasFavoritas";
	}
	
	if(PaginaConta == 4) {
		document.location.href = objeto[0].idname;
	}
}

//remove item (string or number) from an array
function removeItem(originalArray, itemToRemove) {
	var j = 0;
	while (j < originalArray.length) {
	//	alert(originalArray[j]);
		if (originalArray[j] == itemToRemove) {
			originalArray.splice(j, 1);
	} else { j++; }
}
	//	assert('hi');
return originalArray;
}


function detectItem(originalArray, itemToDetect) {
	var j = 0;
	while (j < originalArray.length) {
		if (originalArray[j] == itemToDetect) {
			return true;
		} else { j++; }		
	}
	return false;
}
