var Login = {
	
		logar : function (){ 

		$.ajax({
			type	: 'POST',
			url		: 'php/serviceLogin.php',
			data	: 'login='+$("#login").val()+'&senha='+$("#senha").val(),
			cache	: false,
			beforeSend	: function(){$("#divLogar").empty().html('')},
			success	: function(html){Login.responseLogin(html);}

		});
		
		return false;
	},

/* ********************************************************************************************** */	
                                   
	responseLogin: function(p){
		var logado = '';
		if(p == 'null'){
		
					$.blockUI({ 
						message: 'LOGIN OU SENHA INVÁLIDA!',
					css: { 
						border: 'none',
						fontSize: '15px', 
						fontFamily: 'Verdana, Geneva, sans-serif',
						padding: '15px', 
						backgroundColor: '#000', 
						'-webkit-border-radius': '10px', 
						'-moz-border-radius': '10px', 
						opacity: .5, 
						color: '#fff' 
					} });  
					$("#login").val('');
					$("#senha").val('')
					setTimeout($.unblockUI, 3000); 
			return false;
			
		}
			
		// pega variavel na url
			var L=location.href;
			var d=L.substring(L.indexOf("?")+1);
			var c=v=new Array(); c=d.split("&");
			for(i=0;i<c.length&&c.length>0;i++) {
			v=c[i].split("="); if(v.length>1)
			eval(v[0]+"=unescape('"+v[1].replace(/\+/g," ")+"')");}
		//fim
		
		struct = eval('(' + p + ')');
		
		if(v[1]==undefined){

			$("#divUsuario").empty().html('<div id="txtLogin"><b>BEM VINDO</b></div><br>');
			$("#divSenha").empty().html('<div id="txtLogin">'+struct[0].name_user+'</div><br>');
			$("#divBotoes").empty().html('<div id="divBotaoLogar"><input name="logar" type="image" src="images/layout_r7_c62.jpg" onclick="Login.deslogar()"></div>');
		
		}else{
			var noticiaSel	= '<br>';
			noticiaSel	+= '<div>';
			noticiaSel	+= '	<div class="txtComentario">FAÇA UM COMENTÁRIO:</div>';
			noticiaSel	+= '	<div><textarea class="textareaComentario" id="msgComentario" name="msgComentario" rows="0" cols="0"></textarea></div>';
			noticiaSel	+= '</div>';
			
			noticiaSel	+= '<div id="divBotaoComentario">';
            noticiaSel	+= '	<input name="enviar" type="image" src="images/comentarios_r4A_c4.jpg" onclick="jqueryComentarios.envioComentario()">';
            noticiaSel	+= '</div>';
			
			noticiaSel	+= '<div id="listaComentarios"></div>';
			
			$("#divComentarios").empty().html(noticiaSel);
		}
			jqueryComentarios.getComentarios();
	},
	
	
/* ********************************************************************************************** */	
/* ********************************************************************************************** */	
	
	verificaLogin : function (){ 

		$.ajax({
			type	: 'POST',
			url		: 'php/serviceLogin.php',
			data	: 'vLogin=1',
			cache	: false,
			beforeSend	: function(){$("#divLogar").empty().html('')},
			success	: function(html){Login.responseVLogin(html);}

		});
		
		return false;
	},

/* ********************************************************************************************** */	
                                   
	responseVLogin: function(p){
	
		// pega variavel na url
			var L=location.href;
			var d=L.substring(L.indexOf("?")+1);
			var c=v=new Array(); c=d.split("&");
			for(i=0;i<c.length&&c.length>0;i++) {
			v=c[i].split("="); if(v.length>1)
			eval(v[0]+"=unescape('"+v[1].replace(/\+/g," ")+"')");}
		//fim
	
		var logado = '';
		if(p == 'null')
			return false;
			
		struct = eval('(' + p + ')');
		
		if(v[1]==undefined){
			$("#divUsuario").empty().html('<div id="txtLogin">BEM VINDO</div><br>');
			$("#divSenha").empty().html('<div id="txtLogin"><b>'+struct[0].name_user+'</b></div><br>');
			$("#divBotaoLogar").empty().html('<input name="logar" type="image" src="images/layout_r7_c62.jpg" onclick="Login.deslogar()">');
		}else{
			var noticiaSel	= '<br>';
			noticiaSel	+= '<div>';
			noticiaSel	+= '	<div class="txtComentario">FAÇA UM COMENTÁRIO:</div>';
			noticiaSel	+= '	<div><textarea class="textareaComentario" id="msgComentario" name="msgComentario" rows="0" cols="0"></textarea></div>';
			noticiaSel	+= '</div>';
			
            noticiaSel	+= '<div id="divBotaoComentario">';
            noticiaSel	+= '	<input name="enviar" type="image" src="images/comentarios_r4A_c4.jpg" onclick="jqueryComentarios.envioComentario()">';
            noticiaSel	+= '</div>';
			
			noticiaSel	+= '<div id="listaComentarios"></div>';

			$("#divComentarios").empty().html(noticiaSel);
		}
		
		//jqueryComentarios.getComentarios();

	},

/* ********************************************************************************************** */	
/* ********************************************************************************************** */	
	
	deslogar : function (){ 

		$.ajax({
			type	: 'POST',
			url		: 'php/serviceLogin.php',
			data	: 'vLogin=2',
			cache	: false,
			beforeSend	: function(){$("#divBotaoLogar").empty().html('')},
			success	: function(html){Login.responseDeslogar();}

		});
		
		return false;
	},

/* ********************************************************************************************** */	
                                   
	responseDeslogar: function(){
		$("#divUsuario").empty().html('<div id="txtLogin">LOGIN:</div><div id="inputNome"><input class="inputLogin" name="login"  id="login" type="text"></div>');
		$("#divSenha").empty().html('<div id="txtLogin">SENHA:</div><div id="inputNome"><input class="inputLogin" name="senha"  id="senha" type="password"></div>');
		
		var botoes ='';
		
		 
         botoes +='<div id="divLinks">';
         botoes +='		<div id="cadastrar"><a class="cadastrar" href="index.php?pagina=html/form-cadastro.html">CADASTRE AGORA</a></div>';
         botoes +='     <div id="esqueciSenha"><a class="cadastrar" href="index.php?pagina=html/form-esqueciSenha.html">ESQUECI MINHA SENHA</a></div>';
		 botoes +='</div>';
         botoes +='<div id="divBotaoLogar">';
         botoes +='		<input name="logar" type="image" src="images/layout_r7_c6.jpg" onclick="Login.logar()">';
         botoes +='</div>';

			 
		$("#divBotoes").empty().html(botoes);

	},
	
}

$(document).ready(function(){
	Login.verificaLogin()
})
