Figment.Import('Figment.EventHandler',Figment.getJSRoot() + '_framework/');
Figment.Import('Figment.DOM',Figment.getJSRoot() + '_framework/');
Figment.Import('Disney.WDPRO.IBC.UI.DynamicPleaseWait',Figment.getJSRoot() + '_global/');

Figment.Namespace('Disney.WDPRO.IBC.UI.PleaseWait');

/**
 * Attaches page submit buttons to DynamicPleaseWait's default event handler.
 *
 * @requires Figment.EventHandler
 * @requires Figment.DOM
 */
Disney.WDPRO.IBC.UI.PleaseWait = {

    main: function(evt)
    {
        var formElements = document.getElementsByTagName('INPUT');
        var i,formElement;

        var len = formElements.length;
        for( i=0; i < len; i++ )
        {
            formElement = formElements[i];
            if( formElement.type.toLowerCase()==='submit' || formElement.type.toLowerCase()==='image' )
            {
                // HACK: Remove any Events placed on the WWYC Submit button.
                //
                // PleaseWait is adding an event handler on this submit button, but
                // there is a condition when the Dynamic Please Wait layer should
                // not appear.  So I'm going to remove the already attached event
                // and replace it with my own.
                //
                // This was attached using Figment, so I'll have to do this through
                // Figment.
                if (formElement.id !== "wwycSaveShopsSubmit") {
                    // Only attach please wait to submit buttons that don't specify
                    // to turn async off
                    if( Figment.DOM.hasClassName(formElement,Disney.WDPRO.IBC.UI.DynamicPleaseWait.CLASSNAME_NO_ASYNC) === false )
                    {
                        // Add event to the form element
                        Figment.EventHandler.addEvent(formElement,'click',Disney.WDPRO.IBC.UI.DynamicPleaseWait.EVENT_input_onClick);
                    }
                }
            }
        }

        // Cleanup after ourselves
        delete formElement;
        delete formElements;
    },

    /**********************************
    *
    * These are here as a wrapper to DynamicPleaseWait, some portions of the site are calling these directly, and the file will be deprecated
    * once all instances are found.
    *
    * Only static methods are wrapped. All methods defined in Disney.WDPRO.IBC.UI.DynamicPleaseWait.Class can only be access through an object instance.
    *
    ************************************
    */

    getAsyncModuleName: function()
    {
        return Disney.WDPRO.IBC.UI.DynamicPleaseWait.getAsyncModuleName();
    },

    isRequestAsync: function(response)
    {
        return Disney.WDPRO.IBC.UI.DynamicPleaseWait.isRequestAsync(response);
    },

    isCallFinished: function(response)
    {
        return Disney.WDPRO.IBC.UI.DynamicPleaseWait.isCallFinished(response);
    },

    getStatus: function(doc)
    {
        return Disney.WDPRO.IBC.UI.DynamicPleaseWait.getStatus(doc);
    },

    findForm: function(currentElement)
    {
        return Disney.WDPRO.IBC.UI.DynamicPleaseWait.findForm(currentElement);
    },

    EVENT_input_onClick: function(evt,elem)
    {
        return Disney.WDPRO.IBC.UI.DynamicPleaseWait.EVENT_input_onClick(evt,elem);
    }
};

Figment.EntryPoint.add( Disney.WDPRO.IBC.UI.PleaseWait );

