var queryStr;

function loginEventsOnReady()
{
    $("input#userId").focus();
	
    queryStr = getQueryString();

    var x = get_cookie("barbriesc");
    if (x != null && x != ""){
        var autologin = document.getElementById('autologin').value;
        if(autologin != "1"){
            document.getElementById('loginCookie').value = x;
            $.blockUI({message: '<h4>'+$("#spinnerImageUrl").html()+'&nbsp;Please wait while we retrieve your course registration information.</h4>'});         
            document.loginform.submit();
        }
        else{
            document.getElementById('loginCookie').value = "";
            delete_cookie("barbriesc");
        }
    }
	loginSubmitForm();
}

function loginSubmitForm(){
    $("#userId").bind('keypress', function(e) {
        if(e.keyCode==13)
        	submitLoginForm();
	});    
    $("#password").bind('keypress', function(e) {
        if(e.keyCode==13)
        	submitLoginForm();
	});    
	$("#loginBtn").click(function(){	
		submitLoginForm();
	});
}

function submitLoginForm(){
	if($("#userId").val()!='' && $("#password").val()!=''){
		$.blockUI({message: '<h4>'+$("#spinnerImageUrl").html()+'&nbsp;Please wait while we retrieve your course registration information.</h4>'});
	}	
	document.loginform.submit();				
}

function KeyDownHandler(event)
{
    if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13))
    {
        document.loginform.submit();
        return false;
    }
}

function LoginHelp(url)
{
    w = window.open(url,"LoginHelp","left=100,top=120,height=525,width=525,fullscreen=0,toolbar=0,menubar=0,titlebar=0,resizable=0,scrollbars=1");
    w.focus();
}

function firstTimeHelp(url)
{
    // check if there is parameter coming in
    window.location.href = url;
}

function get_cookie (cookie_name )
{
    var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
    if ( results )
        return ( unescape ( results[2] ) );
    else
        return null;
}

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
    var cookie_string = name + "=" + escape ( value );
    if ( exp_y )
    {
        var expires = new Date ( exp_y, exp_m, exp_d );
        cookie_string += "; expires=" + expires.toGMTString();
    }
    if ( path )
        cookie_string += "; path=" + escape ( path );
    if ( domain )
        cookie_string += "; domain=" + escape ( domain );
    if ( secure )
        cookie_string += "; secure";
    document.cookie = cookie_string;
}

function delete_cookie (cookie_name )
{
    var cookie_date = new Date();
    cookie_date.setTime ( cookie_date.getTime() - 1 );
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString() + "; path=/";
}

function getQueryString(){
    var i;
    var queryString;
    i = window.location.href.indexOf('?');
    queryString = "";
    if(i > 0) {
        queryString = window.location.href.substring(i + 1);
        var newAccount = document.getElementById('newAccount');
        if(newAccount!=null){
            newAccount.style.display = "none";
        }
    }
    return queryString;
}