function myAlert(title, text)
{
	$("#alert_dialog").attr("title",title);
	$("#alert_dialog").html(text);
	$("#alert_dialog").dialog({
			draggable: false,
			resizable: false,
			bgiframe: true,
			height: 140,
			modal: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.3
				}
			
			});	
	$("#alert_dialog").dialog("open");
}

$("#open_login_dialog").click(function(){
	$('#login_dialog').remove();
	$('body').append('<table id="login_dialog" style="margin:auto auto;height:330px;display:none;"><tr><td></td></tr></table>');
	$("#login_dialog").dialog({
			draggable: false,
			resizable: false,
			bgiframe: true,
			height: 330,
			modal: true,
			overlay: {
				background: '#000',
				opacity: 0.3
				}
			});
	$.post('/user/do/',{action:'getUserBlock'},function(data){
		if(data.result){
			$("#login_dialog td:eq(0)").append(data.html);
		}
	},'json');
	$("#login_dialog").dialog("open");
	$("#login_dialog").parent('.ui-dialog').css('overflow','visible');
	document.getElementById('login_dialog').onkeyup = function (e){ 
		if(isEnterPressed(e)) $('.button_login').trigger('click');
	};
	return false;
});



$("#do_logout").click(function(){
	var data_array = {	
		'action': 'logout'
	}
	$.ajax({
			url: '/scripts/user.php',
			type: 'POST',
			datatype: 'json',				
			data: data_array,
			error: function(){
				alert('Ошибка получения данных');
			},
			success: function(response_json){
				var response_arr = eval("("+response_json+")");
				
				if(response_arr['err'] != "ok")
				{
					myAlert("Ошибка", response_arr['err'])
					return false;
				}
				else
				{
					location.reload()
				}
		  		
		  			
		  		

			}
		});	
})


function do_login(mail, pwd, remember)
{
	var data_array = {	
		'mail'	: mail,
		'pwd'	: pwd,
		'remember'	: remember,
		'action': 'login'
	}
	$.ajax({
			url: '/scripts/user.php',
			type: 'POST',
			datatype: 'json',				
			data: data_array,
			error: function(){
				alert('Ошибка получения данных');
			},
			success: function(response_json){
				var response_arr = eval("("+response_json+")");
				
				if(response_arr['err'] != "ok")
				{
					$("#login_dialog td.error").html(response_arr['err']);
					$("#login_dialog").attr("title","Ошибка");
					return false;
				}
				else
				{
					$("#register_dialog").dialog("close");
					location.reload()
				}
		  		
		  			
		  		

			}
		});	
}


