DIALOGS = {
    error_blocker : function(msg){
        $('<div id="dialog_error_message"><p style="margin-top:10px;"><b><u>Unable to continue</u><br/><br/>'+msg+'</b></p><p style="margin-top:10px">An unrecoverable error has occured. In an effort to avoid any undesired reprocussions, the system has been halted.</p></div>').dialog({
            minHeight: 80,
            height: 'auto',
            modal: true,
            resizable: false,
            draggable: false,
            title: 'Non Recoverable Error',
            open: function(event, ui) {
                $(".ui-dialog-titlebar-close").hide();
                $(this).parents(".ui-dialog:first").addClass("ui-state-highlight tiny_font");
                $(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar").addClass("ui-state-error");
            }
        });
    },

    confirm : function(msg, ttl, buttons_config){
        $('<div id="dialog_confirm_message"><p style="margin-top:10px;">'+msg+'</p></div>').dialog({
            minHeight: 80,
            height: 'auto',
            modal: true,
            resizable: false,
            draggable: false,
            title: ttl,
            close: function(ev, ui) {
                $(this).dialog("destroy");
                $(this).remove();
            },
            buttons: buttons_config,
            open: function(event, ui) {
                $(this).parents(".ui-dialog:first").addClass("tiny_font");
            }
        });
    },

    confirm_delete : function(rec_count, action_handler, tb, ids){
        var msg = "Are you sure you want to delete the "+rec_count+" record"+((rec_count>1)?"s":"")+" you have selected?<br/><br/>* file and record removal is a <b><u>non recoverable</u></b> action.";
        var ttl = "Delete "+rec_count+" Record"+((rec_count > 1)?"s":"")+" ?";
        var buttons = {
            'Yes, Delete': function() {
                $.ajax({
                    type: 'POST',
                    url: action_handler,
                    data: "do=delete&del_ids="+ids,
                    success: function(data){
                        if(UTILITY.validateXML_reply(data)){
                            NOTICES.show_info("Record(s) Deleted", "The Records Have Been Deleted From The System Successfully");
                        }
                        tb.callEvent("onClick", Array("refresh"));
                    },
                    dataType: 'xml'
                });
                $(this).dialog('close');
            },
            Cancel: function() {
                $(this).dialog('close');
            }
        };
        DIALOGS.confirm(msg, ttl, buttons);
    },

    show_screen : function(ttl, buttons_config, file, file_params, open_function, use_width){
        var dialogs_location = "/cp/data/dialogs/";
        if(!use_width){use_width = 'auto';}
        if(!open_function){
            var open_function = function(ev, ui) {
                $(".ui-dialog-titlebar-close").hide();
                $(this).parents(".ui-dialog:first").addClass("tiny_font");
            };
        }
        $.ajax({type:"POST",url:dialogs_location+file,"data":file_params,async:true,cache:false,dataType:"html",success:function(dialog_data){
            $(dialog_data).dialog({
                minHeight: 80,
                height: 'auto',
                width: use_width,
                modal: true,
                resizable: false,
                draggable: false,
                title: ttl,
                buttons: buttons_config,
                close: function(ev, ui) {
                    $(this).dialog("destroy");
                    $(this).remove();
                },
                open: open_function
            });
        }});

    },

    show_builder : function(screen_name, on_open_cb, accord){
        var diag_builder_location = "/cp/data/dialogs/diag.builder.php";
        var open_function = function(ev, ui) {
            init_builder_in_dialog();
            $(this).removeClass("tiny_font");
            $(this).find(".add_edit_panel_inner").css({'margin-left' : '10px', 'margin-right' : '10px', 'margin-top' : '10px'});
            $(this).parents(".ui-dialog:first").addClass("tiny_font");
            ADMIN.ASSETS.ADDEDITS[screen_name].display_tips();
            if(on_open_cb){
                on_open_cb();
            }
        };
        if(!accord){var accord = false;}
        $.ajax({type:"POST",url:diag_builder_location,"data":{"screen_name":screen_name,"accordion":accord},async:true,cache:false,dataType:"html",success:function(dialog_data){
            $(dialog_data).first().dialog({
                minHeight: 80,
                height: 'auto',
                width: 'auto',
                modal: true,
                resizable: false,
                draggable: false,
                title: "",
                close: function(ev, ui) {
                	ADMIN.ASSETS.destroy_addedit(screen_name);
                    $(this).dialog("destroy");
                    $(this).remove();
                },
                open: open_function
            });
        }});
    },

    show_grid : function(ttl, grid_name, w, h, edit_id, cb_xle, cb_xls, cb_check, cb_select, cb_edit, cb_init, buttons_config){
        var diag_grid_location = "/cp/data/dialogs/diag.grid.php";
        var open_function = function(ev, ui) {
            init_grid_in_dialog();
            if(cb_init){cb_init();}

            if(cb_select){dhxGrid_diag_grid.attachEvent("onRowSelect", cb_select);}
            if(cb_edit){dhxGrid_diag_grid.attachEvent("onEditCell", cb_edit);}
            if(cb_check){dhxGrid_diag_grid.attachEvent("onCheck", cb_check);}

            dhxGrid_diag_grid.attachEvent("onXLE", function(grid_obj,count){
                grid_obj.setSizes();
                var grid_div = grid_obj.entBox.id;
                $(grid_div).unmask();
                if(cb_xle){cb_xle(grid_obj,count);}
            });
            dhxGrid_diag_grid.attachEvent("onXLS", function(grid_obj){
                var grid_div = grid_obj.entBox.id;
                $(grid_div).mask("Loading....");
                if(cb_xls){cb_xls(grid_obj);}
            });

            $(this).removeClass("tiny_font");
            $(this).find(".add_edit_panel_inner").css({'margin-left' : '10px', 'margin-right' : '10px', 'margin-top' : '10px'});
            $(this).parents(".ui-dialog:first").addClass("tiny_font");
        };
        if(!edit_id){var edit_id = "";}
        if(!buttons_config){var buttons_config = {};}
        $.ajax({type:"POST",url:diag_grid_location,"data":{"grid_name":grid_name, "edit_id":edit_id},async:true,cache:false,dataType:"html",success:function(dialog_data){
            $(dialog_data).first().dialog({
                //minHeight: 80,
                height: h,
                width: w,
                modal: true,
                resizable: false,
                draggable: false,
                title: ttl,
                buttons: buttons_config,
                close: function(ev, ui) {
                    dhxGrid_diag_grid.destructor();
                    $(this).dialog("destroy");
                    $(this).remove();
                },
                open: open_function
            });
        }});
    }
}
