/**
 * @fileOverview defines utility class LoginUtil which provides static helper methods.
 * @author neal.fu
 * @version 1.0
 * @since 6.40, 2010-06-10
 */

/**
 * Creates an instance of LoginUtil.
 * @constructor
 * @this {PopupWindow}
 */
function LoginUtil() {
}

/**
 * This method create a LoginLightBox, and display it.
 * @param {Array}       lightboxProp        Parameter array.
 */
LoginUtil.openLoginLightbox = function (lightboxProp) {
    var lightbox = new LoginLightBox(lightboxProp);
    lightbox.open();
}

/**
 * Executes <code>callbackOnLogin</code> if user is logged in, else <code>callbackOnNotLogin</code>.
 * @param {Function}    callbackOnLogin     Call back function when user is logged on.
 * @param {Function}    callbackOnNotLogin  Call back function when user is not logged on.
 */
LoginUtil.processOnUserStatus = function (callbackOnLogin, callbackOnNotLogin) {
    $j.ajax({
        type: "get",
        url: loginLightboxCommProps.checkStatusUrl,
        dataType: 'json',
        success: function(data) {
            if (data && data != "LOGIN_ACTIVE") {
                callbackOnLogin(data);
            } else {
                callbackOnNotLogin();
            }
        }
    });
}

/**
 * Submits form <code>formName<code> to <code>actionUrl</code>.
 * @param {String}      formName            The form name , must be unique.
 * @param {String}      actionUrl           The action URL where the form will be submitted to.
 */
LoginUtil.submitForm = function (formName, actionUrl) {
    var form = window.document.getElementsByName(formName)[0];
    form.action = actionUrl;
    form.submit();
}

