///////////////////////////////////////////////////
//         THIS IS A SHARED FILE
//
//         THIS IS A SHARED FILE
//
//         THIS IS A SHARED FILE
///////////////////////////////////////////////////

/*  Registration Scripts
    Authors: John Wiberg, Geoff Elliott
    Updated: February, 2004
*/

var regWindow;
var openerPage;

// these variables are set in register.html
var userName = "unknown";
var cancelled = true;
var sessionTimeout = false;
var userType = "new";
var password;
var newPassword;
var email;
var newEmail;

function regWindowOpen(nextPage) { // nextPage is not used at present
  openerPage = location.pathname;
  var start = openerPage.lastIndexOf("/");
  if (start != -1) {
    openerPage = openerPage.substr(start+1);
  }

  regWindow = window.open("signIn.jsp",'checkRegistration','scrollbars,resizable,width=745,height=460');
}

function regWindowClose() {
    if (sessionTimeout) {
        regWindow.close();
        top.location.href = "sessionTimeout.html";
    }
    else if (cancelled) {
        regWindow.close();
    }
    else {
        regWindow.close();
        location = openerPage + "?fromPage=signIn.jsp"; // fromPage needs to be here so Welcome.jsp doesn't reinitialize session objects.
  }
}

function doLoad() {

    if (error != "SUCCESS" && error != "LOGIN_SUCCESS") {
        switch (error) {
            case "AUTHENTICATION_FAILED": // username not found
                alert("Your username or password was incorrect.\nPlease try again.");
                document.forms[0].email.focus();
                break;
            case "ACCOUNT_ALREADY_UPDATED_LOGGED_IN_WITH_OLD_ID":
                alert("Your account was previously updated to use your email to login.  Please try logging in again using your email address.");
            	break;
            case "INVALID_SESSION":
                top.location.href = "sessionTimeout.html";
                break;
        }
    }
}

function doUnload() {
    if ((regWindow != null) && (!regWindow.closed)) regWindow.close();
}

function checkLoginInputs() {
    var checksOut = false;
    if(document.getElementById('email').value == "") {
        alert("Please enter your email address.");
        document.getElementById('email').focus();
    }
    else if(document.getElementById('password').value == "") {
        alert("Please enter your password.");
        document.getElementById('password').focus();
    }
    else
        checksOut = true;

    return checksOut;
}

function logIn() {
	document.forms[0].action = "Login";
    document.forms[0].submit();
}
