﻿///<reference path="jquery-1.3.1-vsdoc.js" />
///<reference path="jquery.form.js" />
///<reference path="jivecommon.js" />

$(document).ready(function() {
    $("form").each(function() {
        $("#" + this.id).ajaxForm({
            dataType: 'json',
            beforeSubmit: beforeSubmit,
            success: regstrationCompleted});
    });
});


function regstrationCompleted(data) {
    hidePanel();
    switch (data.action) {
        case "ERROR":
            displayPanelID = data.formId + "_Message";
            document.getElementById(displayPanelID).innerHTML = data.errorMessage;
            break;
            
        case "REDIRECT":
            location.href = data.redirectURL;
            break;

        case "REPLACE":
            $("#" + currentFormID).replaceWith(data.displayMessage);
            break;

        case "RESET":
            $("#" + currentForm).resetForm();
            break;
    }

}

var currentFormID;
var currentForm;
function beforeSubmit(formData, jqForm, options) {
    //alert(jqForm.context.id);
    createPanel();
    currentFormID = "div" + jqForm.context.id;
    currentForm = jqForm.context.id;
    
    w3Labs.CommonFunction.DisplayProcessingPanel("aislxajslxialsi91llxa", currentFormID);
    return true;
}

function createPanel() {

    panelString = "<div id=\"aislxajslxialsi91llxa\" style=\"width:800px;height:430px;" +
        "z-index:1001;top:0px;left:0px;display:none;position:absolute;background-image:url(/Images/alpha.png);\">" +
        "<table style=\"width:100%;height:100%;\"><tr><td valign=\"middle\" style=\"text-align:center;font-family:Arial,Helvetica,sans-serif;font-size:14pt;font-weight:bold;\">" +
        "Processing ... <img alt=\"Spinner\" src=\"/Images/spinner2.gif\" style=\"vertical-align:middle;\"/></td></tr></table></div>";
    $("body").append(panelString);
    //$("body").append("<div id=\"aislxajslxialsi91llxa\" style=\"width:100px;height:100px;z-index: 1001;background:#AAAAAA none repeat-x scroll 0 0;opacity:0.3;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=30);left:0;top:0;position: absolute;\"><table width=\"100%\" height=\"100%\"><tbody><tr><td valign=\"middle\" style=\"text-align:center;\"><img src=\"/Images/spinner2.gif\"/></td></tr></tbody></table></div>");
    //$("body").append("<div id=\"aislxajslxialsi91llxa\" style=\"width:100px;height:100px;z-index: 1001;background:#AAAAAA none repeat-x scroll 0 0;opacity:0.3;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=30);display:none;\"><table width=\"100%\" height=\"100%\"><tbody><tr><td valign=\"middle\" style=\"text-align:center;\"><img src=\"/Images/spinner2.gif\"/></td></tr></tbody></table></div>");
}

function hidePanel() {
    w3Labs.CommonFunction.HideProcessingPanel("aislxajslxialsi91llxa", currentFormID);
    $("#aislxajslxialsi91llxa").remove();
}

var Client = {
    viewportWidth: function() {
//        wi = self.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth);
//        if (wi > document.width)
//            return wi;
//        else
//            return document.width;
        return self.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth);

    },

    viewportHeight: function() {
//        hi = self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
//        if (hi > document.height)
//            return hi;
//        else
//            return document.height;
        return self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
    },

    viewportSize: function() {
        return "width: " + this.viewportWidth() + "px;height: " + this.viewportHeight() + "px;";
    }
};
