var userLoginCallback = null;

function UserLogin()
{
    this.request = 'indexajax.php?action=UserLogin';
}

UserLogin.prototype.show = function(callback)
{
    tb_open_new('index.php?page=logowanie&width=420&height=240&modal=true');
	if(callback != null) {
    	userLoginCallback = callback;
    } else {
    	userLoginCallback = null;
    }
}

UserLogin.prototype.check = function() 
{
    var ajaxResponseResult;
    var ajaxResponseErrors;
    var ajaxResponseMessage;
    
    $.ajax({
        'type'     : 'get',
        'url'      : this.request + '&start=submit',
        'dataType' : 'xml',
        'async'    : false,
        'success'  : function(xml) {
            $("response > result", xml).each (
                function()
                {
                    ajaxResponseResult = ($(this).text());
                }
            );
        
            $("response > error", xml).each (
                function()
                {
                    ajaxResponseErrors = ($(this).text());
                }
            );
        
            $("response > message", xml).each (
                function()
                {
                    ajaxResponseMessage = ($(this).text());
                }
            );
        }
    });
    
    if(ajaxResponseResult && ajaxResponseResult == 1) {
        return true;
    }
    return false;
}


UserLogin.prototype.logout = function()
{
	$.ajax({
        'type'     : 'post',
        'url'      : this.request + '&start=logout',
        'dataType' : 'xml',
        'async'    : false,
        'success'  : function(xml) 
        {
        	$("response > result", xml).each (
                function()
                {
                    return ($(this).text());
                }
            );
        }
    });
}


UserLogin.prototype.login = function(login, passwd, remember_me)
{
    var ajaxResponseResult;
    var ajaxResponseErrors;
    var ajaxResponseMessage;
       
    $.ajax({
        'type'     : 'post',
        'url'      : this.request + '&start=submit',
        'dataType' : 'xml',
        'data'     : {
            'login'  : login,
            'passwd' : passwd,
            'remember_me' : remember_me
        },
        'async'    : false,
        'success'  : function(xml) {
            $("response > result", xml).each (
                function()
                {
                    ajaxResponseResult = ($(this).text());
                }
            );
        
            $("response > error", xml).each (
                function()
                {
                    ajaxResponseErrors = ($(this).text());
                }
            );
        
            $("response > message", xml).each (
                function()
                {
                    ajaxResponseMessage = ($(this).text());
                }
            );
        }
    });
    
    if(ajaxResponseResult && ajaxResponseResult == 1) {
        return true;
    }
    return false;
}


