	$(document).ready(function() {
		showCaixaLogin($.cookie('CookieLG'));	
	});
 	

	function showCaixaLogin(logIn){
		if ($("#fp").val()=="N"){
			top.location.href="/";
		}else{
			if (logIn){
				$("#CaixaLoginDiv").html(LogIn);
			}else{
				$("#CaixaLoginDiv").html(LogOut);
			}
			
			if ($('div#uploadFotoConcurso').length) {
				showUploadConcursoFotos();
			}
		}
	}
	
	
	function getLogIn(Accio){
		var UserName=$("#username").val();
		//var PassWord=AesCtr.encrypt($("#password").val(),$.cookie('PHPSESSID'),256);
		var PassWord=$("#password").val();
		
		$.post("/index.php", {
			resource: 	"FTPX000010",
			accio:		Accio,	
			username:	UserName,
			password:	PassWord
			}, function( xml )	{
				var username	="";
				var idavatar	="";
				var idpromocion	="";
				
				$(xml).find('usuari').each(function(){
					username	= $(this).attr('username');
					idavatar	= $(this).attr('idavatar');
					idpromocion	= $(this).attr('idpromocion');
				});
				
				if (username!=""){
					showCaixaLogin(true);
					$('#spanUsername').html(username);
					$('#CaixaLoginAvatar').attr("src",$('#CaixaLoginAvatar').attr("src")+idavatar);
					
					if (idpromocion!="") MostrarPopUpPromoUsuari(idpromocion);
				}else{
					if (Accio=="LOGIN") alert (msgLogin["Error"]);
					showCaixaLogin(false);
				}
				
		});
	}
	
	function WagetLogIn(Accio){
		var UserName=$("#username").val();
		var PassWord=$("#password").val();
		
		$.post("/index.php", {
			resource: 	"FTPX000010",
			accio:		Accio,	
			username:	UserName,
			password:	PassWord
			}, function( xml )	{
				var username	="";
				var idavatar	="";
				
				$(xml).find('usuari').each(function(){
					username	= $(this).attr('username');
					idavatar	= $(this).attr('idavatar');
				});
				
				if (username!=""){
					$('#walogin').show();
					$('#walogout').hide();
					$('#spanUsername').html(username);
					$('#CaixaLoginAvatar').hide();
					$('#CaixaLoginAvatar').attr("src",$('#CaixaLoginAvatar').attr("src")+idavatar);
					$('#CaixaLoginAvatar').show();
					slideup('mydiv3');
				}else{
					if (Accio=="LOGIN") alert (msgLogin["Error"]);
					$('#walogin').hide();
					$('#walogout').show();
				}
				
		});
		
	}
	
	/*
	function showUploadConcursoFotos(){		
		if($.cookie('CookieLG')){
			$("div#showUploadFotoConcurso").show();
			$("div#showNoUploadFotoConcurso").hide();				
			$("div#comentarFotoConcurso").show();			
		}else{
			$("div#showNoUploadFotoConcurso").show();
			$("div#showUploadFotoConcurso").hide();			
			$("div#comentarFotoConcurso").hide();
		}
	}
	*/
	function showUploadConcursoFotos(){		
		if($.cookie('CookieLG')){			
			if($.cookie('CookieLGWFC')){
				$("div#showRemoveFotoConcurso").show();
				$("div#showUploadFotoConcurso").hide();				
			}else{
				$("div#showUploadFotoConcurso").show();
				$("div#showRemoveFotoConcurso").hide();
			}
			$("div#showNoUploadFotoConcurso").hide();				
			$("div#comentarFotoConcurso").show();			
			$("#infoLogarse").hide();
		}else{
			$("div#showNoUploadFotoConcurso").show();			
			$("div#showUploadFotoConcurso").hide();			
			$("div#showRemoveFotoConcurso").hide();
			$("div#comentarFotoConcurso").hide();
			$("#infoLogarse").show();
		}
	}	
	
	function mostrarToolTip(txt){
		var content='';	
	
		content+='<table width="96%" border="0" cellpadding="0" cellspacing="0">';
		content+='<tr><td align="center" class="tooltip2" height="30">'+txt+'</td></tr>';
		content+='</table>';
		
		$("#ToolTip").html(content);
		$("#ToolTip").show();
	}
