/**
 * Created by: mstaff
 * Date: Jul 9, 2010
 * Time: 3:57:28 PM
 *
 */

/*
 * Plug-in function to do dialog boxes on Schweser
 *
 * A tags to be named like (with dialog being the lookout value)
 *
 *     * XXX_link_XXX - A link to pass information to a specific controller like window_jquery.php
 *     * XXX_div_XXX - Div to display the dialog box
 *
 * All links must be in the form of <a class="dialog_link_XXX">Link Name</a>
 *
 * INPUT PARAMETERS:
 * d_width): int
 * d_height): int
 * d_title): string OR array
 * a
 * sql: string
 * url: string
 *
 * USAGE:
 <div id="XXX_div_XXX" class="no_display eleven_pixel_font" title="SOME NAME">
    <p id="packDescContent"></p>
 </div>

 <link type="text/css" href="/includes/ajax/jquery/css/1.7/ui.all.css" rel="stylesheet" />
 <script type="text/javascript" src="/includes/ajax/jquery_new.js"></script>
 <script type="text/javascript" src="/includes/ajax/jquery/ui_1.7/ui.core.js"></script>
 <script type="text/javascript" src="/includes/ajax/jquery/ui_1.7/ui.dialog.js"></script>
 <script>
 	$("a[id^='dialog_link']").dialog_box( 768, 576, {$sql}, {$url}, {$function} );
 </script>
 *
 * NOTE: If you want a static dialog box then you don't need to set the url or callback vars
 *       to null.
 * 		 The sql and url values are for an ajax dialog which will run your query and return the
 * 		 results.  See /products/window_jquery.php for an example controller
 *	     the callback function follows the jquery load specification and runs after a success
 *		 with response status and XMLHttpRequest objects as inputs
 */

jQuery.fn.dialog_box = function( d_width, d_height, d_title, url, callback ) {

	// Bind click event
	$(this).click(function()
	{
		// cache objects
		var $dialogContent, $dialogContainer;

		// grab product id & parse string
        var link_id = new String(this.id); 
        var name_array = link_id.split('_');
        $dialogContainer =  $('#'+name_array[0]+"_div_"+name_array[2]);
        $dialogContent = $('#packDescContent');

        // initialize the dialog box
        $dialogContainer.dialog({
			autoOpen:false,
			resizable:false,
			width: d_width,
            height: d_height,
            title: d_title,
			modal:true,
            close: function() {
				$dialogContainer.dialog('destroy');
			}
		});

        // if static dialog
        if( url === undefined )
        {
            $dialogContainer.dialog('open');
        }
        // if dynamic dialog
        else
        {
            //$dialogContent.html('<img class="global_map_loader_image" src="/images/loading.gif" />');
            $dialogContent.load(url, function(response, status, xhr){ callback; });
            $dialogContainer.dialog('open');
        }

        return false;
    });
    
    return false;
};
