com.express_scripts.dialog = {
	
	/*
	 * Creates a div for use in a jquery dialog.  If no title
	 * is passed, it attempts to get the title from the div.
	 * 
	 * Args:
	 * divTag: The div tag to create the div with. (optional)
	 * html:   The html to set into the div. (optional)
	 * title:  The title for the dialog. (optional)
	 * 
	 * Returns:
	 * The jquery div object.
	 */
	createBasicDialogDiv: function(args) {
		var divTag = null;
	    if (args.divTag == null) {
	    	divTag = "<div/>";
	    } else {
	    	divTag = args.divTag;
	    }
	    
	    var dlgDiv = $(divTag);
	    
	    if (args.html != null) {
	    	dlgDiv.html(args.html);
	    }
	    
	    var title = null;
	    if (args.title == null) {
	    	title = dlgDiv.attr("title");
	    } else {
	    	title = args.title;
	    }
/*
 * 	    if (title != null && title != "") {
	    	dlgDiv.prepend($("<h3>" + title + "</h3>"));
	    }
*/
	    
	    return dlgDiv;
	},
	
	/*
	 * Creates a dialog for use per the TPharm mocks (see modifyDialogForTPharm
	 * for details).
	 * 
	 * Args:
	 * div:     The jquery div object to create the dialog around (divTag,
	 *              html and title are ignored if specified). (optional)
	 * divTag:  The div tag to create the div with. (optional)
	 * html:    The html to set into the div. (optional)
	 * title:   The title for the dialog. (optional)
	 * width:   The width of the dialog.   (defaults to 400)
	 * height:  The width of the dialog.   (optional)
	 * buttons: The buttons for the dialog.
	 * showTitle: Optionally display the title bar (optional/boolean)
	 * 
	 * Returns:
	 * The jquery dialog object.
	 */
	createDialogForTPharm: function(args) {
		var div = args.div;
		if (div == null) {
			div = com.express_scripts.dialog.createBasicDialogDiv(args);
		}
		
		var width = 400;
		if (args.width != null) {
			width = args.width;
		}
		// modified for scroll issue QC 37032 starts
		var style = null;
	    if (args.style != null) {
	    	div.css("overflow", args.style);
	    } else {
	    	// do nothing
	    }
	    //QC 37032 ends
		//Modal should always default to true 
		var modal = true;
/*
		if (args.modal != null) {
			modal = args.modal;
		}
*/
		
		var title = '';
		if (args.title != null) {
			title = args.title;
		}
		
		var showTitle = true;
		if (args.showTitle != null) {
			showTitle = args.showTitle;
		}
		
		var dlg = div.dialog({
			autoOpen: false,
			bgiframe: true,
			width: width,
			height: args.height,
			modal: modal,
			resizable: false,
			draggable: false,
			title: title,
			buttons: args.buttons,
			minHeight: 25,
			show: args.show
		});
		
		com.express_scripts.dialog.modifyDialogForTPharm(dlg,showTitle);
		
		return dlg;
	},
	
	/*
	 * Note:
	 * The default jQuery dialogs do not match the mocks.
	 * This modifies the standard dialog to match them.
	 * 
	 * This is all very much in-flux as Corp. Comm. and
	 * Lance L. are working out the details of how
	 * these dialogs should really work.
	 * 
	 * Expect this function to change!!!
	 */
	modifyDialogForTPharm: function(dlg,showTitle) {
		var parent = dlg.parent();
		
		if (!showTitle) {
			parent.children(".ui-dialog-titlebar").css("display","none");
			parent.children(".ui-dialog-content").css("padding-bottom","0");
		}
		
		var btnBar = parent.children(".ui-dialog-buttonpane");
		if (btnBar.length > 0) {
			var btns = btnBar.children();
			var firstBtn = btnBar.children(":eq(0)");
			
			//FIXME Replace these specific styles with css classes.
			//Having specific styles is bad.  It would be better
			//to define these in a css class.
			btnBar.css("border-width", "0 0 0 0");
			btns.css("float", "left");
			btns.css("color", "#2B72AF");
			//btns.css("font-weight", "bold");
			firstBtn.css("background", "#EFC415");
			firstBtn.css("font-weight", "bold");
		}
	}
}
