/* Copyright (c) 2003-2010, SearchFit, Inc. All rights reserved. */
if (typeof SFUI == "undefined" || !SFUI) { var SFUI = {}; }

SFUI.Ajax =
{
    waitPanelInstance:null,
    dynamicPanelInstance:null,

    showDynamicPanel:function(isDynamicPage, wsWebsiteEndpoint, args) {
        var isPanelModal = args.isPanelModal != null ? args.isPanelModal : true;
        this.showLoadingWindow("Loading, Please Wait...", isPanelModal);

        // construct the web service request
        var wsRequest = "action=" + args.action + "&wsParams[multipart_result]=isDynamicPage=" + isDynamicPage;
        wsRequest += ",clientWidth=" + YAHOO.util.Dom.getViewportWidth() + ",clientHeight=" + YAHOO.util.Dom.getViewportHeight();
        wsRequest += ",uid=" + args.uid;
        if (args.params != null && args.params != "") { wsRequest += "," + args.params.replace(/&/g, ","); }

        // construct the callback
        var asyncResponseCallback_showDynamicPanel = {
            success: function(o) {
                var resultContent = getMultipartResultById(o.responseText, "multipart_result");
                if (resultContent == "") { resultContent = geWsErrorDescription(o.responseText, true); }
                SFUI.Ajax.hideLoadingWindow();
    
                // construct and show the dynamic panel
                if (SFUI.Ajax.dynamicPanelInstance == null) { SFUI.Ajax.dynamicPanelInstance = new YAHOO.widget.Panel("dynamicPanelContainer", { zindex:1001, visible:false, fixedcenter:true, draggable:true, close:true, modal:isPanelModal, constraintoviewport:true } ); }
                SFUI.Ajax.dynamicPanelInstance.setHeader(args.header);
                SFUI.Ajax.dynamicPanelInstance.setBody(resultContent);
                SFUI.Ajax.dynamicPanelInstance.render(document.body);
                SFUI.Ajax.dynamicPanelInstance.show();

                // execute response JavaScript after the response text is shown
                launchJavascript(o.responseText);
            },
            failure: function(o) { SFUI.Ajax.hideLoadingWindow(); alert("Failed showDynamicPanel (" + o.status + " " + o.statusText + ")"); }
        }

        // make the AJAX call
        var transaction = YAHOO.util.Connect.asyncRequest('POST', wsWebsiteEndpoint, asyncResponseCallback_showDynamicPanel, wsRequest);
        if (transaction == null) { SFUI.Ajax.hideLoadingWindow(); }
    },
    hideDynamicPanel:function() {
        if (this.dynamicPanelInstance != null) { this.dynamicPanelInstance.hide(); }
    },

    showLoadingWindow:function(loadingMessage, isPanelModal) {
        if (this.dynamicPanelInstance != null) { this.dynamicPanelInstance.hide(); }
        if (this.waitPanelInstance == null) {
            if (isPanelModal == null) { isPanelModal = true; }
            var localLoadingImgSrc = typeof(loadingImgSrc) != "undefined" && loadingImgSrc != null ? loadingImgSrc : "http://www.searchfit.com/scart/public/images/anim_indicator_big.gif";
            this.waitPanelInstance = new YAHOO.widget.Panel("waitPanelContainer", { width:175, fixedcenter:true, close:false, draggable:false, zindex:9999, modal:isPanelModal, visible:false } );
            this.waitPanelInstance.setHeader(loadingMessage);
            this.waitPanelInstance.setBody('<table border="0" align="center" cellspacing="0" cellpadding="20"><tr><td align="center"><img src="' + localLoadingImgSrc + '" border="0" /></td></tr></table>');
            this.waitPanelInstance.render(document.body);
        }
        this.waitPanelInstance.show();
    },
    hideLoadingWindow:function() {
        if (this.waitPanelInstance != null) { this.waitPanelInstance.hide(); }
    }
}