/***********************************
* modal-window.js
*
* Contains configuration for modal
* window genration along with an abstraction
* for populating the modal window with content
* retrieved via AJAX request
*
* @author eculver
* @version 1.0
* @since 07/11/08
************************************/

// Modal Window Default Values
var mw_id = "mw";
var mw_underlay = "shadow";
var mw_modal = true;
var mw_close = true;
var mw_visible = false;
var mw_fixedcenter = true;
var mw_contraintoviewport = true;
var mw_effect = {effect:YAHOO.widget.ContainerEffect.FADE, duration: 0.5};
var mw_zindex = "1000";

// Global Modal Window
var modal_window = new YAHOO.widget.Panel(mw_id,
    {    underlay:mw_underlay,
        modal:mw_modal,
        close:mw_close,
        visible:mw_visible,
        fixedcenter:mw_fixedcenter,
        constraintoviewport:mw_contraintoviewport,
        effect:mw_effect,
        zIndex: mw_zindex
    }
);

// IE6 width hack for modal window, sets width to be a fixed 300px.
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
if(IE6)
    modal_window.cfg.setProperty("width", "300px");    

/***********************************
* openModalWindow
*
* Grabs content via asynchronous 
* HTTP request to passed in url and 
* postData and displays response in
* a modal window. Assumes that the 
* call returns valid HTML
* 
* @author eculver
* @param url - non-remote url to retrieve modal window content from
* @param postData
* @param caption
************************************/
function openModalWindow(url, postData, caption) {
    var handleSuccess = function(o){ 
        if(o.responseText !== undefined){ 
            // set up the dialog and show it.
            modal_window.setHeader(caption);
            modal_window.setBody(o.responseText);
            modal_window.render(document.body);
            modal_window.show();
        } 
        else showAlert('Sorry, there was an error, please try again.');
    }
    var handleFailure = function() { showAlert('Request Failed'); }
    var callback = { success:handleSuccess, failure: handleFailure }; 
    var request = YAHOO.util.Connect.asyncRequest('POST', url, callback, postData);
}

/***********************************
* closeModalWindow
*
* Just closes the modal window. For 
* consistent API calls.
************************************/
function closeModalWindow() {
    modal_window.hide();
}
