function checkForReturn(event)
{
    keycode = 0;
    if(window.event)
        keycode = window.event.keyCode;
    else
        keycode = event.which;
    if(keycode == 13)
        login($F('userName'), $F('password'));
}

function selectPassword(event)
{
    keycode = 0;
    if(window.event)
        keycode = window.event.keyCode;
    else
        keycode = event.which;
    if(keycode == 13)
        $('password').focus();
}

function login(userName, password)
{
    var pars = "userName=" + escape(userName) + "&password=" + escape(MD5(password));
    new Ajax.Request('application/actions/login.php',
    {
        parameters: pars,
        method: "get",
        onComplete: function(transport)
        {
            if(transport.responseText == "true")
                history.go();
            else
                errorBox(LworngUserWrongPassword);
        },
        onError: function (){
              errorBox(LworngUserWrongPassword);
        }
				
    } );
	
}

function changeUser()
{
    messageBar("question", LuserName + ": <input type=\"text\" id=\"userName\" /> " + Lpassword + ": <input type=\"password\" id=\"passwd\" /> ", function()
    {
        var pars = "userName=" + escape($F("userName")) + "&password=" + MD5($F('passwd'));

        new Ajax.Request('application/actions/login.php',
        {
            parameters: pars,
            method: "get",
            onComplete: function(transport)
            {
                if(trim(transport.responseText) != "true")
                {
                    errorBox(LerrorChangeUser);
                } else {
                    history.go();
                }
            },
            onError: function (){
              errorBox(LerrorChangeUser);
        }
        });
    },true, true, true);
}

function reloadUserSettings()
{
    new Ajax.Request('application/actions/reloadUserSettings.php',
    {
        onComplete: function()
        {
            history.go();
        }

    } );

}

function logout()
{
    new Ajax.Request('application/actions/logout.php',
    {
        method: "get", 
        onComplete: function()
        {
            location.href = "index.php";
        }
				
    } );
}

function clearDBCache() {
    new Ajax.Request('application/actions/clearDBCache.php',
    {
        onComplete: function(transport)
        {
            infoBox(transport.responseText);
            //history.go();
        }

    } );
}
