﻿var myRules = 
{
    'form#frmLogin' : function(elmt)
    {
        Event.observe(elmt, 'submit', Login);
    }
    ,'input#btnLogin' : function(elmt)
    {
        Event.observe(elmt, 'click', Login);
    }
};

window.onload = function()
{
    Behavior.register(myRules);
    $('txtUserCode').focus();
}

function Login(e)
{
    Event.stop(e);
    $('btnLogin').disabled = true;
    
    new Ajax.Request('login.aspx?USR_Number=' + $F('txtUserCode'), 
        {
            onSuccess: Login_Response
            ,onlyLatestOfClass: 'Login'
        });
}

function Login_Response(t)
{
    var HasFailed = t.responseXML.getElementsByTagName('failed');
    if(HasFailed.length > 0)
    {
        $('failed').style.display = 'block';
        $('btnLogin').disabled = false;
        $('txtUserCode').activate();
    }
    else
    {
        var Progress = t.responseXML.getElementsByTagName('succeeded');

        /*switch(parseInt(Progress[0].firstChild.nodeValue))
        {
            case 1:
                location.href = 'email/instructions.htm';
                break;

            case 2:
                location.href = '../Quiz/2_Vocab/vocab.htm';
                break;

            case 3:
                location.href = '../Quiz/3_au1/au.htm';
                break;

            case 4:
                location.href = '../Quiz/4_Stroop/stroop.htm';
                break;

            case 5:
                location.href = '../Quiz/5_GNG/gng.htm';
                break;

            case 6:
                location.href = '../test_complete/test_complete.htm';
                break;
        }*/
        location.href = 'email/instructions.htm';
    }
}
