
var obj_session = new Object;
var str_login_results = "";
var str_login_mode = "login";
var interval_admin_dashboard_refresh = "";
var int_admin_dashboard_refresh_rate = 6e4;
var x_position_mouse = 0;
var y_position_mouse = 0;
var previous_on_change_value = "";
$(document).ready(function () {
    set_the_ui();
   
    ui_combobox();
    
    $("#common-quick-tools-handle").live("click", function () {
        var a = $("#common-quick-tools").css("left");
        var b = a.split("px");
        var c = b[0] < 0 ? 0 : -305;
        $("#common-quick-tools").animate({
            left: c
        }, 200, "linear", function () {})
    });
    $(".common-accordion").accordion({
        animated: "slide",
        autoHeight: false
    });
    $("#main_container,#banner").live("click", function () {
        $("#common-quick-tools").animate({
            left: -305
        }, 200, "linear", function () {})
    });
    $(document).mouseup(function (a) {
        x_position_mouse = a.pageX;
        y_position_mouse = a.pageY
    });
    if (VIEW == "admin_list_run_slips") {
        set_up_admin_run_slip_manage();
        $(".run_slip_file_queue").each(function () {
            live;
            var run_slip_id = $(this).attr("id").replace("run_slip_file_queue", "");
            $("#admin_run_slip_uploadify" + run_slip_id).uploadify({
                uploader: PUBLIC_URL + "/flash/uploadify.swf",
                script: "/json/admin_run_slip_uploadify",
                scriptData: {
                    run_slip_id: run_slip_id,
                    session_id_hack: SESSION_ID
                },
                cancelImg: PUBLIC_URL + "/skins/document_archiving/cancel.png",
                folder: "uploads",
                queueID: "run_slip_file_queue" + run_slip_id,
                auto: true,
                multi: true,
                onComplete: function (event, queueID, fileObj, response, data) {
                    var obj_response = eval("(" + response + ")");
                    $("#table_files" + obj_response.post.run_slip_id).append(obj_response.row)
                }
            })
        });
        $("#admin_run_slip_uploadify").uploadify({
            uploader: PUBLIC_URL + "/flash/uploadify.swf",
            script: BASE_PROJECT_W_SLASH + "json/run_slip_uploadify",
            scriptData: {
                session_id_hack: SESSION_ID
            },
            cancelImg: PUBLIC_URL + "/skins/document_archiving/cancel.png",
            folder: "uploads",
            queueID: "run_slip_file_queue",
            auto: true,
            multi: true,
            onComplete: function (event, queueID, fileObj, response, data) {
                var info = eval("(" + response + ")");
                $("#table_files10").append(info.str_results)
            }
        })
    }
    if (VIEW == "advanced_user_list_files") {
        file_submission_refresh_status_interval()
    }
    if (VIEW == "admin_dashboard") {
        refresh_admin_dashboard();
        interval_admin_dashboard_refresh = window.setInterval("refresh_admin_dashboard()", int_admin_dashboard_refresh_rate)
    }
    if (VIEW == "admin_list_e_files" || VIEW == "user_my_files" || VIEW == "user_list_e_files") {
        try {
            $("#browser0,#browser,#browser2").treeview({
                toggle: function () {
                    console.log("%s was toggled.", $(this).find(">span").text())
                }
            });
            $("#add").click(function () {
                var a = $("<li><span class='folder'>New Sublist</span><ul>" + "<li><span class='file'>Item1</span></li>" + "<li><span class='file'>Item2</span></li></ul></li>").appendTo("#browser");
                $("#browser").treeview({
                    add: a
                })
            })
        } catch (err) {}
    }
    if (VIEW == "user_edit_profile") {
        if (typeof SESSION_ID == "undefined") {}
        $("#uploadify_avatar").uploadify({
            buttonText: "Upload Picture",
            fileDesc: "jpg,gif,png",
            fileExt: "*.jpg;*.gif;*.png",
            width: 140,
            height: 50,
            uploader: PUBLIC_URL + "/flash/uploadify.swf",
            script: BASE_PROJECT_W_SLASH + "json/uploadify_avatar",
            scriptData: {
                session_id_hack: SESSION_ID
            },
            cancelImg: PUBLIC_URL + "/skins/document_archiving/cancel.png",
            folder: "uploads",
            queueID: "uploadify_avatar_file_queue",
            auto: true,
            multi: false,
            onComplete: function (event, queueID, fileObj, response, data) {
                var info = eval("(" + response + ")");
                if (info.is_success) {
                    $("#profile_avatar").attr("src", info.avatar_source);
                    $("#profile_image_results").hide()
                } else {
                    $("#profile_image_results").show();
                    $("#profile_image_results").html(info.str_results.Filedata)
                }
            }
        });
        if ($.browser.safari) {
            $(".cms-edit").show();
            $(".cms-display").hide();
            setTimeout("profile_set_editors()", 500)
        } else {
            profile_set_editors()
        }
    }
    if (VIEW == "user_edit_run_slip" || VIEW == "user_list_run_slips") {
        $(".run_slips_instruction_selection_order").each(function () {
            arr_run_slip_instructions[$(this).attr("id")] = parseInt($(this).val())
        });
        $("#run_slip_uploadify").uploadify({
            uploader: PUBLIC_URL + "/flash/uploadify.swf",
            script: BASE_PROJECT_W_SLASH + "json/run_slip_uploadify",
            scriptData: {
                session_id_hack: SESSION_ID
            },
            cancelImg: PUBLIC_URL + "/skins/document_archiving/cancel.png",
            folder: "uploads",
            queueID: "run_slip_file_queue",
            auto: true,
            multi: true,
            sizeLimit: 31457280,
            onComplete: function (event, queueID, fileObj, response, data) {
                var info = eval("(" + response + ")");
                $("#run_slip_e_files").append(info.str_results)
            }
        })
    }
    if (VIEW == "user_list_run_slips" || VIEW == "user_show_runslip_test") {
        set_up_user_run_slip_manage()
    }
    $(".common-button").button();
    $(".common-dropdown").menu();
    $(".fileQueue").each(function () {
        file_submission_id = $(this).attr("id").replace("fileQueue", "");
        $("#uploadify" + file_submission_id).uploadify({
            uploader: PUBLIC_URL + "/flash/uploadify.swf",
            script: "/json/uploadify",
            scriptData: {
                file_submission_id: file_submission_id
            },
            cancelImg: "cancel.png",
            folder: "uploads",
            queueID: "fileQueue" + file_submission_id,
            auto: true,
            multi: true,
            onComplete: function (event, queueID, fileObj, response, data) {
                var obj_response = eval("(" + response + ")");
                $("#table_files" + obj_response.file_submission_id).append(obj_response.row)
            }
        })
    });
    $(".run_slip_print").live("click", function () {
        o = new Object;
        o.width = 760;
        o.height = 500;
        var a = $(this).attr("id").replace("run_slip_print", "");
        o.str_url = BASE_PROJECT_W_SLASH + "document_archiving/run_slip_print/" + a + "/1";
        popup_window(o);
        return false
    });
    $("#button_beta").live("mouseup", function () {
        beta_mode()
    });
    $("#btn_contact_form_submit").live("click", function () {
        contact_form_submit();
        return false
    });
    $("#btn_files_get_upload_processing_form").live("click", function () {
        files_get_upload_processing_form();
        return false
    });
    $("#locations-country_id").live("change", function () {
        zone_options($(this).val());
        return false
    });
    $("#logo").live("click", function () {
        window.location = BASE_PROJECT_W_SLASH
    });
    $("#submit_form_file_code").live("click", function () {
        form_id = $(this).attr("id").replace("submit_", "");
        edit_form_file_code(form_id);
        return false
    });
    $(".ajax_event_requester").live("click", function () {
        ajax_event_request($(this).attr("id"));
        return false
    });
    $(".common-form-clear").live("click", function () {
        var obj_params = eval("(" + $(this).attr("rel") + ")");
        try {
            $("#" + obj_params.form_id)[0].reset()
        } catch (err) {
            alert("You must pass the form's id in the rel tag of the clear button, such as rel=\"form_id:'form123';\"")
        }
    });
    $('.common-remove').live("click", function () {
        $(this).remove();
        obj_params = eval('(' + $(this).attr("rel") + ')');
        $(obj_params.element_to_remove).remove();
    });    
    $(".function_requester").live("click", function () {
        var obj_params = eval("(" + $(this).attr("rel") + ")");
        var temp_func = eval(obj_params.function_name);
        temp_func(obj_params);
        return false
    });
    $(".function_requester_mouseover").live("mouseover", function () {
        var obj_params = eval("(" + $(this).attr("rel") + ")");
        var temp_func = eval(obj_params.function_name);
        temp_func(obj_params);
        return false
    });
    $(".function_requester_change").live("change", function () {
        var obj_params = eval("(" + $(this).attr("rel") + ")");
        var temp_func = eval(obj_params.function_name);
        temp_func(obj_params);
        return false
    });
    $(".dialog").dialog({
        autoOpen: false,
        width: 550,
        height: 350,
        buttons: {
            Ok: function () {
                $(this).dialog("close")
            },
            Cancel: function () {
                $(this).dialog("close")
            }
        }
    });
    $(".dialog_link").live("click", function () {
        id = $(this).attr("id").replace("dialog_link", "");
        $("#dialog" + id).dialog("open");
        return false
    });
    $(".dialog_content").live("mouseup", function () {
        var str_element_id = $(this).attr("id");
        var obj_params = eval("(" + $(this).attr("rel") + ")");
        var o = new Object;
        if (typeof obj_params.is_simplemodal == "undefined") {
            obj_params.is_simplemodal = false
        }
        if (typeof obj_params.width == "undefined") {
            obj_params.width = 500
        }
        if (typeof obj_params.height == "undefined") {
            obj_params.height = 200
        }
        if (typeof obj_params.is_effect == "undefined") {
            obj_params.is_effect = false
        }
        if (typeof obj_params.title == "undefined") {
            obj_params.title = "Information"
        }
        if (typeof obj_params.content == "undefined") {
            obj_params.content = "processing..."
        }
        if (obj_params.is_simplemodal == false) {
            if (typeof obj_params.id == "undefined") {
                obj_params.id = "simple_update"
            }
        } else {
            if (typeof obj_params.id == "undefined") {
                obj_params.id = "simple_modal"
            }
        }
        var obj_id = obj_params.id;
        if (obj_params.is_simplemodal) {
            var int_title_height = 30;
            if (document.getElementById("simplemodal-instance")) {
                $("#simplemodal-instance").remove()
            }
            $("body").append('<div id="simplemodal-instance" ><div class="simplemodal-border" > </div><div class="simplemodal-title common-gradient">' + obj_params.title + ' <div class="simplemodal-close simplemodal-close-button" title="close"  >X</div> </div><div class="simplemodal-content">' + obj_params.content + "</div></div>");
            $(".simplemodal-content").html(obj_params.content);
            $("#simplemodal-instance").draggable({
                handle: $(".simplemodal-title")
            });
            $(".simplemodal-border").css({
                width: obj_params.width,
                height: obj_params.height
            });
            $(".simplemodal-title").css({
                width: obj_params.width - 43
            });
            $(".simplemodal-content").css({
                width: obj_params.width - 48,
                height: obj_params.height - (48 + int_title_height)
            });
            $("#simplemodal-instance").css({
                width: obj_params.width,
                height: obj_params.height
            }).modal({
                position: [100],
                onOpen: function (a) {
                    a.overlay.fadeIn(450);
                    try {
                        $(".simplemodal-border").fadeTo("slow", .5, function () {})
                    } catch (b) {
                        $(".simplemodal-border").fadeIn(200)
                    }
                    a.container.fadeIn(200, function () {
                        a.data.fadeIn(100)
                    })
                },
                onClose: function (a) {
                    $(".simplemodal-border,.simplemodal-content,.simplemodal-title").fadeOut(300, function () {
                        a.overlay.fadeOut(300, function () {
                            $.modal.close()
                        })
                    })
                }
            })
        } else {
            $("#dialog_" + obj_id).remove();
            $("body").append('<div id="dialog_' + obj_id + '" class="dialog" style="display:none;" title="Information Update"></div>');
            obj_id = "dialog_" + obj_id;
            if (obj_params.is_effect) {
                obj_effect = {
                    effect: "drop",
                    options: {
                        direction: "down"
                    },
                    speed: 1e3
                }
            } else {
                obj_effect = ""
            }
            $("#" + obj_id).html(obj_params.content);
            $("#" + obj_id).dialog({
                autoOpen: false,
                modal: false,
                show: obj_effect,
                width: obj_params.width,
                height: obj_params.height,
                title: obj_params.title,
                buttons: {
                    Close: function () {
                        $(this).dialog("close");
                        $(this).remove();
                        $("#" + obj_id).remove()
                    }
                }
            });
            $("#" + obj_id).dialog("open")
        }
        if (typeof obj_params.content_name != "undefined" || typeof obj_params.str_func != "undefined") {
            obj_params.data.dialog_id = obj_id;
            if (typeof obj_params.content_name != "undefined") o.str_func = "get_" + obj_params.content_name;
            if (typeof obj_params.str_func != "undefined") o.str_func = obj_params.str_func;
            o.data = obj_params.data;
            if (typeof obj_params.function_on_complete != "undefined") {
                o.str_on_complete = obj_params.function_on_complete
            } else {
                o.str_on_complete = "get_content_on_complete"
            }
            get_content(o)
        }
        return false
    });
    $(".dialog_content_reference_not_used").live("click", function () {
        var obj_params = eval("(" + $(this).attr("rel") + ")");
        alert(obj_params.height);
        return false;
        var caller_id = $(this).attr("id");
        var params = $(this).attr("rel");
        params = params.split("|");
        var arr_defaults = Array("height", "width", "form_name", "content");
        for (i in params) {
            for (j in arr_defaults) {
                temp_str = arr_defaults[j];
                try {
                    if (typeof eval(arr_defaults[j]) == "undefined") {
                        eval("var " + arr_defaults[j] + " = false")
                    }
                } catch (err) {
                    eval("var " + arr_defaults[j] + " = false")
                }
                if (eval(arr_defaults[j]) == 0) {
                    myKey = eval("/" + temp_str + "/");
                    myStringVar = params[i];
                    myMatch = myStringVar.search(myKey);
                    if (myMatch != -1) {
                        arr_temp = myStringVar.split("=");
                        eval(arr_defaults[j] + " = " + arr_temp[1])
                    }
                }
            }
        }
        if (width == 0) {
            width = 450
        }
        if (height == 0) {
            height = 430
        }
        $("#dialog_simple_update").html("Please Wait. Getting Form");
        $("#dialog_simple_update").dialog({
            autoOpen: false,
            width: width,
            height: height,
            buttons: {
                Close: function () {
                    $(this).dialog("close")
                }
            }
        });
        $("#dialog_simple_update").dialog("open");
        if (form_name != 0) {
            alert(form_name)
        } else {};
    });
    $(".dialog_company_location").live("click", function () {
        var a = $(this).attr("id").replace("dialog_company_location", "");
        $("#dialog_company_location").html("Please Wait. Getting Form");
        $("#dialog_simple_update").dialog({
            autoOpen: false,
            width: 550,
            height: 435,
            buttons: {
                Close: function () {
                    $(this).dialog("close")
                }
            }
        });
        $("#dialog_simple_update").dialog("open");
        var b = new Object;
        b.str_func = "get_form_company_location";
        b.data = {
            location_id: a
        };
        b.str_on_complete = "get_form_company_location_on_complete";
        get_content(b);
        return false
    });
    $(".dialog_phone_number_update").live("click", function () {
        var a = $(this).attr("id").replace("dialog_phone_number_update", "");
        $("#dialog_simple_update").html("Please Wait. Getting Form");
        $("#dialog_simple_update").dialog({
            autoOpen: false,
            width: 550,
            height: 335,
            buttons: {
                Close: function () {
                    $(this).dialog("close")
                }
            }
        });
        $("#dialog_simple_update").dialog("open");
        var b = new Object;
        b.str_func = "get_form_phone_number_update";
        b.data = {
            phone_number_id: a
        };
        b.str_on_complete = "get_form_phone_number_update_on_complete";
        get_content(b);
        return false
    });
    $(".form_run_slips_is_printed_checkbox").live("click change", function () {
        var a = $(this).attr("id").replace("form_run_slip_is_printed_checkbox", "");
        $("#form_run_slip_is_printed_" + a + "results").html("processing...");
        form_id = $(this).parent().attr("id");
        if ($(this).attr("checked") == true || $(this).attr("checked") == "checked") {
            $(this).val(1);
            $(this).attr("checked", "checked")
        } else {
            $(this).val(0)
        }
        if (has_numbers(form_id) == true) {
            str_on_complete = form_id.substring(0, form_id.length - (form_id.length - form_id.lastIndexOf("_"))) + "_on_complete"
        } else {
            str_on_complete = form_id + "_on_complete"
        }
        o = new Object;
        o.hide_form_on_success = false;
        form_submit(form_id, str_on_complete, o);
        return false
    });
    $(".btn_delete_e_file").live("click", function () {
        var a = $(this).attr("id").replace("btn_delete_e_file", "");
        delete_e_file(a);
        return false
    });
    $(".form_run_slips_status_radio").live("mouseup", function () {
        $(this).attr("checked", "checked");
        form_id = $(this).parent().attr("id");
        if (has_numbers(form_id) == true) {
            str_on_complete = form_id.substring(0, form_id.length - (form_id.length - form_id.lastIndexOf("_"))) + "_on_complete"
        } else {
            str_on_complete = form_id + "_on_complete"
        }
        o = new Object;
        o.hide_form_on_success = false;
        form_submit(form_id, str_on_complete, o);
        return false
    });
    $(".form_submit_checkbox").live("change click", function () {
        form_id = $(this).parent().attr("id");
        if (has_numbers(form_id) == true) {
            str_on_complete = form_id.substring(0, form_id.length - (form_id.length - form_id.lastIndexOf("_"))) + "_on_complete"
        } else {
            str_on_complete = form_id + "_on_complete"
        }
        o = new Object;
        o.hide_form_on_success = false;
        form_submit(form_id, str_on_complete, o);
        return false
    });
    $(".form_submit").live("click", function () {
        $(".tinymce_editor").each(function () {
            var a = $(this).attr("id");
            var b = tinyMCE.get(a);
            tinymce_on_change(b)
        });
        var o = eval("(" + $(this).attr("rel") + ")");
        if (typeof o != "undefined") {
            if (typeof o.form_id == "undefined") {
                form_id = $(this).attr("id").replace("submit_", "")
            } else {
                form_id = o.form_id
            }
            if (typeof o.is_form_hidden == "undefined") o.is_form_hidden = false;
            if (typeof o.is_submitter_hidden == "undefined") o.is_submitter_hidden = false;
            if (typeof o.controller == "undefined") o.controller = "json"
        } else {
            var o = new Object;
            if ($(this).hasClass("is_form_hidden-false")) {
                o.is_form_hidden = false
            }
            form_id = $(this).attr("id").replace("submit_", "")
        }
        if (has_numbers(form_id) == true) {
            str_on_complete = form_id.substring(0, form_id.length - (form_id.length - form_id.lastIndexOf("_"))) + "_on_complete"
        } else {
            str_on_complete = form_id + "_on_complete"
        }
        form_submit(form_id, str_on_complete, o);
        return false
    });
    $(".form_submit_onblur").live("blur", function () {
        form_submit_listener($(this).attr("id"))
    });
    $(".form_submit_onchange").live("change", function () {
        form_submit_listener($(this).attr("id"))
    });
    $(".form_submit_test").live("click", function () {
        form_id = $(this).attr("id").replace("submit_", "");
        if (has_numbers(form_id) == true) {
            str_on_complete = form_id.substring(0, form_id.length - (form_id.length - form_id.lastIndexOf("_"))) + "_on_complete"
        } else {
            str_on_complete = form_id + "_on_complete"
        }
        form_submit_test(form_id);
        return false
    });
    $(".form_submit_radio").live("mouseup", function () {
        $(this).attr("checked", "checked");
        form_id = $(this).parent().attr("id");
        if (has_numbers(form_id) == true) {
            str_on_complete = form_id.substring(0, form_id.length - (form_id.length - form_id.lastIndexOf("_"))) + "_on_complete"
        } else {
            str_on_complete = form_id + "_on_complete"
        }
        o = new Object;
        o.hide_form_on_success = false;
        form_submit(form_id, str_on_complete, o);
        return false
    });
    $(".manage_content").hide();
    $(".submit_form_file_submission_update_simple").live("click", function () {
        var a = $(this).attr("id").replace("submit_form_file_submission_update_simple", "");
        file_submission_update_simple(a);
        return false
    });
    $(".radio_file_manage_status").live("click", function () {
        var a = $(this).attr("value");
        var b = $(this).attr("id");
        var c = b.replace("status_" + a.replace(" ", "_"), "");
        file_manage_update_status(c, a)
    });
    $(".admin_instructions_edit").live("blur", function () {
        var a = $(this).attr("value");
        var b = $(this).attr("id").replace("admin_instructions_edit", "");
        file_submission_update_admin_instructions(b, a)
    });
    $(".btn_file_delete").live("click", function () {
        var a = $(this).attr("id").replace("btn_file_delete", "");
        file_manage_delete_file(a)
    });
    $(".btn_font_resize").live("click", function () {
        var o = eval("(" + $(this).attr("rel") + ")");
        $("body").css("font-size", o.font_size);
        $.ajax({
            url: BASE_URL + "/json/preferences_update",
            type: "POST",
            dataType: "json",
            data: {
                main: {
                    css: {
                        body: {
                            font_size: o.font_size
                        }
                    }
                }
            },
            success: function (a) {},
            error: function (a) {
                alert("font resize data error")
            }
        })
    });
    $(".btn_send_for_file_processing").live("click", function () {
        var a = $(this).attr("id").replace("btn_send_for_file_processing", "");
        file_submission_send_for_file_processing(a)
    });
    get_session_object();
    $("#login_padlock_unlocked").hide();
    $("#btn_login").live("click", function () {
        login_submit();
        return false
    });
    $("#btn_password_reset_submit").live("click", function () {
        password_reset_submit();
        return false
    });
    $("#btn_password_update_submit").live("click", function () {
        login_password_update_submit();
        return false
    });
    $("#btn_login_cancel, #btn_password_reset_cancel").live("click", function () {
        close_login_form()
    });
    $("#link_login_get_form").live("click", function () {
        login_get_form()
    });
    $("#link_show_form_password_reset").live("click", function () {
        show_form_password_reset()
    });
    $("#link_show_form_login").live("click", function () {
        show_form_login()
    });
    $("#link_register_get_form").click(function () {
        register_get_form()
    });
    $("#btn_register_submit").live("click", function () {
        register_submit();
        return false
    })
})

function zone_options(a) {
    str_data = {
        countries_id: a
    };
    $.ajax({
        type: "POST",
        url: BASE_URL + "/" + PROJECT_W_SLASH + "json/zone_options",
        data: str_data,
        dataType: "json",
        success: function (a) {
            if (a.is_success == true) {
                $("select#locations-zone_id").html(a.str_results);
                if (a.str_results == "") {
                    $("#locations-alt_zone").show();
                    $("select#locations-zone_id").hide();
                } else {
                    $("#locations-alt_zone").hide();
                    $("select#locations-zone_id").show();
                }
            } else {
                alert("error");
            }
        },
        error: function (a) {
            alert("error")
        }
    })
}
function tinymce_on_change(a) {
    var b = tinyMCE.get(a.id);
    var c = b.getContent();
    slen = c.length;
    $("#" + a.id).val(c);
}


function password_reset_submit() {
    $("#btn_password_reset_submit").fadeOut();
    $str_data = $("#form_password_reset").serialize();
    $str_data = $str_data.replace(/%5B/gi, "[");
    $str_data = $str_data.replace(/%5D/gi, "]");
    $.ajax({
        type: "POST",
        url: BASE_PROJECT_W_SLASH + "json/login_password_reset_submit",
        data: $str_data,
        dataType: "json",
        success: function (a) {
            if (a.is_success == true) {
                str_login_mode = "password_reset_success"
            } else {
                str_login_mode = "password_reset_fail"
            }
            get_session_object()
        },
        error: function (a) {
            alert("error");
            $("#login_submit").show(300)
        }
    })
}
function show_form_password_reset() {
    str_login_mode = "show_form_password_reset";
    _set_login_interface()
}
function show_form_login() {
    str_login_mode = "login";
    _set_login_interface()
}
function set_up_user_run_slip_manage() {
    $(".tabs").each(function () {
        element_id = $(this).attr("id");
        var tabs = $("#" + element_id).tabs({
            select: function (event, ui) {
                var id = ui.panel.id;
                tab_id = ui.tab.id;
                if ($("#" + tab_id).attr("rel") > "") {
                    obj_params = eval("(" + $("#" + tab_id).attr("rel") + ")")
                } else {
                    obj_params = new Object
                }
                if (typeof obj_params.data == "undefined") {
                    obj_params.data = ""
                }
                obj_params.data.container_id = id;
                if (typeof obj_params.str_func != "undefined") {
                    $("#" + id).html("processing");
                    get_content(obj_params)
                }
            }
        })
    })
}
function set_up_user_run_slip_attachments() {
    $("#run_slip_uploadify_attachments").uploadify({
        uploader: PUBLIC_URL + "/flash/uploadify.swf",
        script: BASE_PROJECT_W_SLASH + "json/run_slip_uploadify_attachments",
        scriptData: {
            session_id_hack: SESSION_ID
        },
        cancelImg: PUBLIC_URL + "/skins/document_archiving/cancel.png",
        folder: "uploads",
        queueID: "run_slip_file_queue_attachments",
        auto: true,
        multi: true,
        sizeLimit: 31457280,
        onComplete: function (event, queueID, fileObj, response, data) {
            var info = eval("(" + response + ")");
            $("#run_slip_attachments").append(info.str_results)
        }
    })
}
function set_up_admin_run_slip_manage() {
    $(".tabs").each(function () {
        var a = $(this).attr("id");
        var b = $("#" + a).tabs({
            select: function (b, c) {
                a = c.panel.id;
                var d = new Object;
                str = a.substring(0, a.length - (a.length - a.lastIndexOf("_")));
                str = str.replace("tabs-", "");
                d.str_func = "admin_" + str;
                if (d.str_func == "admin_attachment_content" || d.str_func == "admin_bills_content" || d.str_func == "admin_invoice_content" || d.str_func == "admin_e_file_content" || d.str_func == "admin_run_slip_content") {
                    run_slip_id = a.substring(a.length - (a.length - a.lastIndexOf("_") - 1), a.length);
                    $("#" + a).html("processing");
                    d.str_on_complete = "admin_" + str + "_on_complete";
                    d.data = {
                        run_slip_id: run_slip_id,
                        id: a
                    };
                    get_content(d)
                }
            }
        })
    })
}
function set_up_admin_file_attachments() {
    $("#file_uploadify_attachments").uploadify({
        uploader: PUBLIC_URL + "/flash/uploadify.swf",
        script: BASE_PROJECT_W_SLASH + "json/file_uploadify_attachments",
        scriptData: {
            session_id_hack: SESSION_ID
        },
        cancelImg: PUBLIC_URL + "/skins/document_archiving/cancel.png",
        folder: "uploads",
        queueID: "admin_file_queue_attachments",
        auto: true,
        multi: true,
        sizeLimit: 31457280,
        onComplete: function (event, queueID, fileObj, response, data) {
            $("#file_uploadify_attachmentsUploader,#file_uploadify_attachments_cancel").hide();
            var info = eval("(" + response + ")");
            $("#file_attachments").append(info.str_results);
            set_the_ui()
        }
    })
}
function set_the_ui() {
    $("button,.button, input:submit, input:button").button();
    $("input:text, textarea").addClass("ui-widget ui-widget-content ui-corner-left ui-corner-right");
    $(".datepicker").datepicker({
        changeMonth: true,
        changeYear: true,
        showAnim: "fadeIn"
    });
    $("#dialog_link, ul#icons li").hover(function () {
        $(this).addClass("ui-state-hover")
    }, function () {
        $(this).removeClass("ui-state-hover")
    })
}
function save_scratch_paper(a) {
    var b = $("#common-quick-tools-scratch-paper").val();
    $.ajax({
        type: "POST",
        url: BASE_PROJECT_W_SLASH + "json/save_scratch_paper",
        data: {
            scratch_paper: b
        },
        dataType: "json",
        success: function (a) {},
        error: function (a) {
            alert("error");
            $("#login_submit").show(300)
        }
    })
}
function get_session_object() {
    $.ajax({
        type: "POST",
        url: BASE_URL + "/" + PROJECT_W_SLASH + "json/session_get",
        data: {
            str_login_mode: ""
        },
        dataType: "json",
        success: function (a) {
            obj_session = a;
            _set_login_interface()
        },
        error: function (a) {}
    })
}
function login_password_update_submit() {
    $("#btn_password_update_submit").fadeOut();
    if ($("#user_password").val() == $("#user_password2").val()) {
        $("#password_update_results").html("");
        $str_data = $("#form_password_update").serialize();
        $str_data = $str_data.replace(/%5B/gi, "[");
        $str_data = $str_data.replace(/%5D/gi, "]");
        $.ajax({
            type: "POST",
            url: BASE_URL + "/" + PROJECT_W_SLASH + "json/login_password_update",
            data: $str_data,
            dataType: "json",
            success: function (a) {
                if (a.is_success == true) {
                    $("#password_update_results").html("The password was updated successfully.");
                    $("#form_password_update").hide()
                } else {
                    $("#password_update_results").html(a.errors.user.password);
                    $("#btn_password_update_submit").fadeIn()
                }
            },
            error: function (a) {
                alert("error");
                $("#btn_password_update_submit").fadeIn()
            }
        })
    } else {
        $("#password_update_results").html("The password fields do not match.");
        $("#password_update_results").show();
        $("#btn_password_update_submit").fadeIn()
    }
}
function close_login_form() {
    $("#simplemodal-container").fadeOut(300, function () {
        $.modal.close();
        $("#" + PrevEmploymentSectionOne).fadeIn(500);
        $("#login_form_container").html($("#dialog").html());
        $("#dialog").hide()
    })
}
function _set_login_interface() {
    if (typeof obj_session.login != "undefined") {
        var a = obj_session.login.int_attempts;
        var b = obj_session.login.int_attempts_max;
        var c = b - a
    } else {
        var a = 0;
        var b = 20;
        var c = 20
    }
    switch (str_login_mode) {
    case "login":
        if (a > 0) {
            $("#login_results").show();
            $str_attempts = c == 1 ? "attempt" : "attempts";
            $("#login_results").html('<span class="error">You have ' + c + " Login " + $str_attempts + "  remaining.</span>")
        }
        if (c > 0) {
            $("#form_password_reset").hide();
            $("#form_login").show();
            $("#btn_login").fadeIn(300)
        } else {
            $("#form_login").hide();
            $("#form_password_reset").show();
            $("#link_show_form_login").hide()
        }
        break;
    case "password_reset_fail":
        $("#login_results").html("That Email and User Role pair does not match our records.");
        $("#form_login").hide();
        $("#form_password_reset").show();
        $("#btn_password_reset_submit").stop(true, true);
        $("#btn_password_reset_submit").show();
        break;
    case "password_reset_success":
        $("#login_results").html("Your password confirmation was sent to your email.");
        $("table.login_form").hide();
        $("#link_show_form_login").hide();
        $("#btn_password_reset_submit").hide();
        $("#btn_password_reset_cancel").val("CLOSE");
        break;
    case "show_form_password_reset":
        $("#form_login").hide();
        $("#form_password_reset").show();
        $("#btn_password_reset_submit").show();
        break
    }
}
function ui_combobox() {
    $.widget("ui.combobox", {
        _create: function () {
            var a = this;
            var b = this.element.hide();
            var c = this.element.attr("id");
            var d = this.element.val();
            var e = "";
            if (c > "") {
                e = $("#" + c + ' option[value="' + d + '"]').text()
            }
            var f = $("<input>").insertAfter(b).autocomplete({
                source: function (a, c) {
                    var d = new RegExp(a.term, "i");
                    c(b.children("option").map(function () {
                        var b = $(this).text();
                        if (!a.term || d.test(b)) return {
                            id: $(this).val(),
                            label: b.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + a.term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"),
                            value: b
                        }
                    }))
                },
                delay: 0,
                select: function (c, d) {
                    if (!d.item) {
                        $(this).val("");
                        return false
                    }
                    $(this).focus();
                    b.val(d.item.id);
                    a._trigger("selected", null, {
                        item: b.find("[value='" + d.item.id + "']")
                    })
                },
                minLength: 0
            }).addClass("ui-widget ui-widget-content ui-corner-left").val(e);
            $("<a title='select'> </a>").insertAfter(f).button({
                icons: {
                    primary: "ui-icon-triangle-1-s"
                },
                text: false
            }).removeClass("ui-corner-all").addClass("ui-corner-right ui-button-icon").position({
                my: "left center",
                at: "right center",
                of: f,
                offset: "-1 0"
            }).css("top", "").click(function () {
                if (f.autocomplete("widget").is(":visible")) {
                    f.autocomplete("close");
                    return
                }
                f.autocomplete("search", "");
                f.focus()
            })
        }
    });
    $("select.autocomplete").combobox()
}
function toggle_multiple_elements(a) {
    $id = $("#" + a.id);
    if (a.settings == undefined) {
        a.settings = new Object;
        a.settings.duration = 300
    }
    if (a.toggle_text == undefined) {
        a.toggle_text = new Array;
        a.toggle_text[0] = "Show";
        a.toggle_text[1] = "Hide"
    }
    count = 0;
    while (count < a.elements.length) {
        $obj = $("#" + a.elements[count]);
        obj_to_toggle = a.elements[count];
        if ($id.attr("value")) {
            if (a.id != undefined) {
                $obj.css("display") != "none" ? $id.val(a.toggle_text[0]) : $id.val(a.toggle_text[1])
            }
        } else {
            if (a.id != undefined) {
                $obj.css("display") != "none" ? $id.html(a.toggle_text[0]) : $id.html(a.toggle_text[1])
            }
        }
        $obj.toggle(a.settings.duration);
        count++
    }
}
function toggle_confirm_and_cancel(a) {
    $("#common-delete-confirm-" + a.suffix).fadeToggle("fast", "linear");
    $("#common-cancel-confirm-" + a.suffix).fadeToggle("fast", "linear")
}
function run_slip_uploadify_setup(o) {
    $("#admin_run_slip_uploadify" + o.run_slip_id).uploadify({
        uploader: PUBLIC_URL + "/flash/uploadify.swf",
        script: "/json/admin_run_slip_uploadify",
        scriptData: {
            run_slip_id: o.run_slip_id,
            session_id_hack: SESSION_ID
        },
        cancelImg: PUBLIC_URL + "/skins/document_archiving/cancel.png",
        folder: "uploads",
        queueID: "run_slip_file_queue" + o.run_slip_id,
        auto: true,
        multi: true,
        onComplete: function (event, queueID, fileObj, response, data) {
            var obj_response = eval("(" + response + ")");
            $("#table_files" + obj_response.post.run_slip_id).append(obj_response.row)
        }
    })
}
function register_get_form() {
    $("#content").html($("#registration_form_container").html());
    $("#registration").show()
}
function register_submit() {
    $str_data = $("#form_register").serialize();
    $str_data = $str_data.replace(/%5B/gi, "[");
    $str_data = $str_data.replace(/%5D/gi, "]");
    $("#btn_register_submit").hide();
    $.ajax({
        type: "POST",
        url: BASE_URL + "/" + PROJECT_W_SLASH + "json/register_submit",
        data: $str_data,
        dataType: "json",
        success: function (a) {
            if (a.is_success == true) {
                alert("success");
                $("#form_register").hide();
                $("#register_success").show()
            } else {
                $user_section_errors = "";
                $contact_section_errors = "";
                $("#validation_contact").html("");
                if (a.errors["user"]) {
                    if (a.errors["user"]["username"]) {
                        $user_section_errors += a.errors["user"]["username"] + "<br />"
                    }
                    if (a.errors["user"]["password"]) {
                        $user_section_errors += a.errors["user"]["password"] + "<br />"
                    }
                    if (a.errors["user"]["email"]) {
                        $contact_section_errors += a.errors["user"]["email"] + "<br />"
                    }
                }
                if (a.errors["people"]) {
                    if (a.errors["people"]["name_first"]) {
                        $contact_section_errors += a.errors["people"]["name_first"] + "<br />"
                    }
                    if (a.errors["people"]["name_last"]) {
                        $contact_section_errors += a.errors["people"]["name_last"] + "<br />"
                    }
                }
                $("#validation_user").html($user_section_errors);
                $("#validation_contact").html($contact_section_errors);
                $("#btn_register_submit").show()
            }
        },
        error: function (a) {
            alert("error")
        }
    })
}
function refresh_admin_dashboard_toggle(a) {
    if (typeof a.element_id == "undefined") {
        alert("must pass element id")
    }
    if (typeof a.str_on == "undefined") {
        a.str_on = "on"
    }
    if (typeof a.str_off == "undefined") {
        a.str_on = "off"
    }
    if ($("#" + a.element_id).val() == a.str_on) {
        interval_admin_dashboard_refresh = window.setInterval("refresh_admin_dashboard()", int_admin_dashboard_refresh_rate);
        refresh_admin_dashboard();
        $("#" + a.element_id).val(a.str_off)
    } else {
        window.clearInterval(interval_admin_dashboard_refresh);
        $("#" + a.element_id).val(a.str_on)
    }
}
function refresh_admin_dashboard() {
    var a = new Object;
    a.str_func = "get_admin_unread_run_slips";
    a.data = {
        container_id: "widget_run_slips_rows"
    };
    a.str_on_complete = "get_admin_unread_run_slips_on_complete";
    get_content(a);
    var a = new Object;
    a.str_func = "get_admin_unread_e_files";
    a.data = {
        container_id: "widget_e_files_rows"
    };
    a.str_on_complete = "get_admin_unread_e_files_on_complete";
    get_content(a);
    var a = new Object;
    a.str_func = "get_admin_unread_cooper_castle_escrow_run_slips";
    a.data = {
        container_id: "widget_cooper_castle_escrow_run_slips_rows"
    };
    a.str_on_complete = "get_admin_unread_cooper_castle_escrow_run_slips_on_complete";
    get_content(a);
    if (typeof get_unread_messages_for_staff == "function") {
        get_unread_messages_for_staff()
    }
    $("#admin_dashboard_refresh").delay(800).fadeIn(400).delay(800).fadeOut(400, function () {
        var a = setTimeout('$("button,.button, input:submit").button()', 200)
    })
}
function profile_set_editors() {
    $(".cms-edit").hide();
    $(".cms-display").show()
}
function print_r(a) {
    if (a.constructor == Array || a.constructor == Object) {
        document.write("<ul>");
        for (var b in a) {
            if (a[b].constructor == Array || a[b].constructor == Object) {
                document.write("<li>[" + b + "] => " + typeof a + "</li>");
                document.write("<ul>");
                print_r(a[b]);
                document.write("</ul>")
            } else {
                document.write("<li>[" + b + "] => " + a[b] + "</li>")
            }
        }
        document.write("</ul>")
    }
}
function popup_window(a) {
    a.str_url = a.str_url === undefined ? "http://www.google.com" : a.str_url;
    a.str_name = a.str_name === undefined ? "default" : a.str_name;
    a.toolbar = a.toolbar === undefined ? "yes" : a.toolbar;
    a.width = a.width === undefined ? 300 : a.width;
    a.height = a.height === undefined ? 300 : a.height;
    a.left = a.left === undefined ? 100 : a.left;
    a.top = a.top === undefined ? 100 : a.top;
    pop_up_window = open(a.str_url, a.str_name, "toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=" + a.width + ",height=" + a.height + ",left=" + a.left + ", top=" + a.top + ",screenX=" + a.left + ",screenY=" + a.top + "")
}
function login_submit() {
    $("#btn_login").fadeOut();
    $str_data = $("#form_login").serialize();
    $str_data = $str_data.replace(/%5B/gi, "[");
    $str_data = $str_data.replace(/%5D/gi, "]");
    $.ajax({
        type: "POST",
        url: BASE_URL + "/" + PROJECT_W_SLASH + "json/login_submit",
        data: $str_data,
        dataType: "json",
        success: function (a) {
            if (a.is_success == true) {
                if (VIEW != "log_out") {
                    if (a.is_staff == true) {
                        location.reload()
                    } else {
                        document.location.href = BASE_PROJECT_W_SLASH + CONTROLLER + "/user_dashboard"
                    }
                } else {
                    if (a.is_staff == true) {
                        document.location.href = BASE_PROJECT_W_SLASH + CONTROLLER + "/admin_dashboard"
                    } else {
                        document.location.href = BASE_PROJECT_W_SLASH + CONTROLLER + "/user_dashboard"
                    }
                }
            }
            get_session_object()
        },
        error: function (a) {
            alert("error");
            $("#login_submit").show(300)
        }
    })
}
function is_object_in_existance(a, b) {
    if (b) {
        if (window.opener.document.getElementById(a) != null) {
            return true
        } else {
            return false
        }
    } else {
        if (document.getElementById(a) != null) {
            return true
        } else {
            return false
        }
    }
}
function is_array(a) {
    if (a.constructor.toString().indexOf("Array") == -1) return false;
    else return true
}
function has_numbers(a) {
    return /\d/.test(a)
}
function get_post_data(data) {
    str = "";
    for (i in data.post) {
        temp = eval("data.post." + i);
        for (j in temp) {
            val = eval("data.post." + i + "." + j);
            str += i + ": " + j + "=" + val + "\n"
        }
    }
    return str
}
function get_form_phone_number_update_on_complete(a) {
    if (a.is_success) {
        $("#dialog_simple_update").html(a.str_results)
    }
}
function get_form_company_location_on_complete(a) {
    if (a.is_success) {
        $("#dialog_simple_update").html(a.str_results)
    }
}

/*
function get_document_for_dialog(a) {
    if (typeof a.width == "undefined") {
        a.width = 500
    }
    if (typeof a.height == "undefined") {
        a.height = 400
    }
    if (typeof a.controller == "undefined") {
        a.controller = "json"
    }
    if (typeof a.title == "undefined") {
        a.title = "Current Document"
    }
    if (typeof a.view == "undefined") {
        alert('You must pass "view" in your parameters for the "get_document_for_dialog" function.');
        return false
    }
    var b = create_random_element();
    $("#" + b).html("Getting the document...");
    $("#" + b).dialog({
        title: a.title,
        width: a.width,
        height: a.height,
        close: function (a, b) {
            $(this).dialog("destroy").remove()
        }
    });
    $.ajax({
        type: "POST",
        url: "/" + a.controller + "/" + a.view,
        data: a.data,
        dataType: "json",
        success: function (a) {
            if (a.is_success == true) {}
            $("#" + b).html(a.str_results);
            set_the_ui()
        },
        error: function (a) {
            alert("error")
        }
    })
}
*/

function get_content_on_complete(a) {
    if (a.is_success) {
        if (typeof a.post != "undefined") {
            if (typeof a.post.container_id != "undefined") {
                $("#" + a.post.container_id).html(a.str_results)
            } else {
                if (typeof a.post.is_simplemodal != "undefined") {
                    $(".simplemodal-content").html(a.str_results)
                } else {
                    if (typeof a.post.dialog_id != "undefined") {
                        $("#" + a.post.dialog_id).html(a.str_results)
                    } else {
                        $("#dialog_simple_update").html(a.str_results)
                    }
                }
            }
        } else {
            $("#dialog_simple_update").html(a.str_results)
        }
    }
}
function get_admin_unread_run_slips_on_complete(a) {
    if (a.is_success) {
        if (typeof a.post != "undefined") {
            if (typeof a.post.container_id != "undefined") {
                $("#widget_run_slips_int_rows").html(a.int_rows);
                $("#" + a.post.container_id).html(a.str_results)
            }
        } else {
            alert("container is not defined.")
        }
    }
}
function get_admin_unread_cooper_castle_escrow_run_slips_on_complete(a) {
    if (a.is_success) {
        if (typeof a.post != "undefined") {
            if (typeof a.post.container_id != "undefined") {
                $("#widget_cooper_castle_escrow_run_slips_int_rows").html(a.int_rows);
                $("#" + a.post.container_id).html(a.str_results)
            }
        } else {
            alert("container is not defined.")
        }
    }
}
function get_admin_unread_e_files_on_complete(a) {
    if (a.is_success) {
        if (typeof a.post != "undefined") {
            if (typeof a.post.container_id != "undefined") {
                $("#widget_e_files_int_rows").html(a.int_rows);
                $("#" + a.post.container_id).html(a.str_results)
            }
        } else {
            alert("container is not defined.")
        }
    }
}
function form_submit_test(a) {
    $(".tinymce_editor").each(function () {
        var a = $(this).attr("id");
        var b = tinyMCE.get(a);
        tinymce_on_change(b)
    });
    str_data = $("#" + a).serialize();
    str_data = str_data.replace(/%5B/gi, "[");
    str_data = str_data.replace(/%5D/gi, "]");
    alert(str_data)
}
function form_user_assign_to_companies_on_complete(a) {}
function form_login_as_user_on_complete(a) {
    if (a.is_success) {
        document.location.href = BASE_PROJECT_W_SLASH + CONTROLLER + "/user_dashboard"
    }
}
function form_submit_listener(id) {
    var o = eval("(" + $("#" + id).attr("rel") + ")");
    if (typeof o != "undefined") {
        form_id = o.form_id;
        if (typeof o.is_form_hidden == "undefined") o.is_form_hidden = false;
        if (typeof o.is_submitter_hidden == "undefined") o.is_submitter_hidden = false
    } else {
        var o = new Object;
        if ($("#" + id).hasClass("is_form_hidden-false")) {
            o.is_form_hidden = false
        }
        form_id = $("#" + id).attr("id").replace("submit_", "")
    }
    if (has_numbers(form_id) == true) {
        str_on_complete = form_id.substring(0, form_id.length - (form_id.length - form_id.lastIndexOf("_"))) + "_on_complete"
    } else {
        str_on_complete = form_id + "_on_complete"
    }
    form_submit(form_id, str_on_complete, o);
    return false
}
function form_submit(form_id, str_complete_function, o) {
    if (o == undefined) {
        o = new Object
    }
    if (o.hide_form_on_success == undefined) {
        o.hide_form_on_success = new Object;
        o.hide_form_on_success = false
    }
    if (o.is_submitter_hidden == undefined) {
        o.is_submitter_hidden = true
    }
    if (o.is_results_fade == undefined) {
        o.is_results_fade = false
    }
    if (o.is_form_hidden == undefined) {
        o.is_form_hidden = true
    }
    if (o.controller == undefined) {
        o.controller = "json"
    }
    str_data = $("#" + form_id).serialize();
    str_data = str_data.replace(/%5B/gi, "[");
    str_data = str_data.replace(/%5D/gi, "]");
    if (has_numbers(form_id)) {
        func = form_id.substring(0, form_id.length - (form_id.length - form_id.lastIndexOf("_")));
        str_results_id = form_id + "results";
        str_validater = form_id + "validate"
    } else {
        func = form_id;
        str_results_id = form_id + "_results";
        str_validater = form_id + "_validate"
    }
    if (o.is_submitter_hidden == true) {
        $("#submit_" + form_id).fadeOut(100)
    }
    $.ajax({
        type: "POST",
        url: BASE_URL + "/" + PROJECT_W_SLASH + o.controller + "/" + func,
        data: str_data,
        dataType: "json",
        success: function (data) {
            $(".validation_error").html("");
            if (o.is_submitter_hidden == true) {
                $("#submit_" + form_id).fadeIn(100)
            }
            $("#" + str_results_id).html(data.str_results);
            if ($("." + str_results_id).length) {
                $("." + str_results_id).html(data.str_results)
            }
            if (o.is_results_fade == true) {
                $("#" + str_results_id).clearQueue().fadeIn(300).delay(3e3).fadeOut(300);
                if ($("." + str_results_id).length) {
                    $("." + str_results_id).clearQueue().fadeIn(300).delay(3e3).fadeOut(300)
                }
            }
            if (data.is_success != false) {
                if (o.hide_form_on_success == true && o.is_form_hidden == true) {
                    $("#" + form_id).hide()
                }
            } else {
                if (data.errors) {
                    for (i in data.errors) {
                        var temp = "";
                        temp = eval("data.errors." + i);
                        if (typeof eval(temp) == "object" || typeof eval(temp) == "array") {
                            for (j in temp) {
                                try {
                                    var error = eval("data.errors." + i + "." + j)
                                } catch (e) {
                                    error = "undefined"
                                }
                                if (error != "undefined") {
                                    $("#" + str_validater + "_" + i + "-" + j).html(error)
                                }
                            }
                        } else {
                            var error = temp;
                            $("#" + form_id + "validate_" + i).html(error)
                        }
                    }
                }
            }
            try {
                if (typeof eval(str_complete_function) == "function") {
                    temp_func = eval(str_complete_function);
                    temp_func(data)
                }
            } catch (e) {}
        },
        error: function (a) {
            alert("error");
            $("#submit_" + form_id).fadeIn(300)
        }
    })
}
function form_e_file_viewed_by_admin_on_complete(a) {
    if (a.is_success) {
        $("#widget_e_files_int_rows").html($("#widget_e_files_int_rows").html() - 1);
        $("#widget_e_files_row_" + a.post.run_slips_files_relation.run_slips_files_relation_id).fadeOut(200);
        if (a.post.run_slips_files_relation.is_viewed_by_admin == 1) {
            $("#run_slips_files_relation-is_viewed_by_admin").attr("checked", "checked")
        }
    }
}
function form_user_run_slip_cancel_on_complete(a) {
    if (a.is_success) {
        $("#run_slip_row" + a.post.run_slips.run_slip_id).css("background-color", palette.run_slips.status.canceled)
    }
}
function form_user_notes_edit_on_complete(a) {
    if (a.is_success) {
        $(":input", "#form_user_notes_edit").not(":button, :submit, :reset, :hidden").val("").removeAttr("checked").removeAttr("selected")
    }
}
function form_simple_directory_listings_status_update_on_complete(a) {}
function form_run_slip_viewed_on_complete(a) {
    if (a.is_success) {
        $("#widget_run_slips_count").html($("#widget_run_slips_count").html() - 1);
        $("#widget_run_slips_row_" + a.post.run_slips.run_slip_id).fadeOut(200);
        if (a.post.run_slips.is_viewed == 1) {
            $("#run_slips-is_viewed").attr("checked", "checked")
        }
    }
}
function form_run_slip_viewed_by_admin_on_complete(a) {
    if (a.is_success) {
        $("#widget_run_slips_int_rows").html($("#widget_run_slips_int_rows").html() - 1);
        $("#widget_run_slips_row_" + a.post.run_slips.run_slip_id).fadeOut(200);
        if (a.post.run_slips.is_viewed_by_admin == 1) {
            $("#run_slips-is_viewed_by_admin").attr("checked", "checked")
        }
    }
}
function form_run_slip_status_on_complete(data) {
    var background = eval("palette.run_slips.status." + data.post.run_slips.status);
    $("#run_slip_row" + data.post.run_slips.run_slip_id).css("background", background);
    src = $("#run_slip" + data.post.run_slips.run_slip_id).attr("src");
    $("#run_slip" + data.post.run_slips.run_slip_id).attr("src", src)
}
function form_run_slip_is_printed_on_complete(a) {
    if (a.post.run_slips.is_printed == 1) {
        $("#is_printed" + a.post.run_slips.run_slip_id).show();
        $("#run_slip" + a.post.run_slips.run_slip_id).removeClass("run_slip_not_printed");
        $("#form_run_slip_is_printed_checkbox" + a.post.run_slips.run_slip_id).attr("checked", "checked")
    } else {
        $("#run_slip" + a.post.run_slips.run_slip_id).addClass("run_slip_not_printed");
        $("#is_printed" + a.post.run_slips.run_slip_id).hide();
        $("#form_run_slip_is_printed_checkbox" + a.post.run_slips.run_slip_id).attr("checked", "")
    }
}
function form_run_slip_edit_on_complete(a) {
    try {
        $("#run_slip" + a.run_slip_id).attr("src", $("#run_slip" + a.run_slip_id).attr("src"))
    } catch (b) {}
    $("input,div").removeClass("error");
    if (a.is_success == 1) {
        $("#form_run_slip_edit").hide()
    }
    if (a.errors) {
        $(".results").html(a.str_results);
        $(".results").css({
            color: "#ff0000",
            "font-size": "200%"
        });
        if (a.errors.run_slips) {
            if (a.errors.run_slips.advance_fee) {
                $("#form_run_slip_edit_results").append("<br /> Advance Fee: " + a.errors.run_slips.advance_fee);
                $("#run_slips-advance_fee").addClass("error")
            }
            if (a.errors.run_slips.document) {
                $("#form_run_slip_edit_results").append("<br /> document: " + a.errors.run_slips.document);
                $("#run_slips-document").addClass("error")
            }
            if (a.errors.run_slips.check_amount) {
                $("#form_run_slip_edit_results").append("<br /> check amount: " + a.errors.run_slips.check_amount);
                $("#run_slips-check_amount").addClass("error")
            }
            if (a.errors.run_slips.case_name) {
                $("#form_run_slip_edit_results").append("<br /> case name: " + a.errors.run_slips.case_name);
                $("#run_slips-case_name").addClass("error")
            }
            if (a.errors.run_slips.contact) {
                $("#form_run_slip_edit_results").append("<br /> contact: " + a.errors.run_slips.contact);
                $("#run_slips-contact").addClass("error")
            }
            if (a.errors.run_slips.file_number) {
                $("#form_run_slip_edit_results").append("<br /> File Number: " + a.errors.run_slips.file_number);
                $("#run_slips-file_number").addClass("error")
            }
        }
        if (a.errors.run_slips_city_selections) {
            $("#form_run_slip_edit_results").append("<br /> City Selection: " + a.errors.run_slips_city_selections.general);
            $("#run_slips_city_selections").addClass("error")
        }
    } else {};
}
function get_form_run_slip_attachments_on_complete(a) {
    if (a.is_success) {
        if (typeof a.post != "undefined") {
            if (typeof a.post.dialog_id != "undefined") {
                $("#" + a.post.dialog_id).html(a.str_results);
                set_up_user_run_slip_attachments()
            }
        } else {
            alert("container is not defined.")
        }
    }
}
function get_form_file_attachment_on_complete(a) {
    if (a.is_success) {
        if (typeof a.post != "undefined") {
            if (typeof a.post.dialog_id != "undefined") {
                $("#" + a.post.dialog_id).html(a.str_results);
                $("#get_file_attachment" + a.post.company_id).hide();
                $("#search_all").val("");
                set_up_admin_file_attachments()
            }
        } else {
            alert("container is not defined.")
        }
    }
}
function get_form_court_pickup_edit(a) {
    if (typeof a.json_function == "undefined") a.json_function = "get_form_court_pickup_edit";
    $("#dialog_simple_update").html("Please Wait. Getting Form now....");
    $("#dialog_simple_update").dialog({
        autoOpen: false,
        width: 500,
        height: 400,
        buttons: {
            Close: function () {
                $(this).dialog("close")
            }
        }
    });
    $("#dialog_simple_update").dialog("open");
    $.ajax({
        type: "POST",
        url: BASE_URL + "/" + PROJECT_W_SLASH + "json/" + a.json_function,
        data: a.data,
        dataType: "json",
        success: function (a) {
            if (a.is_success == true) {
                $("#dialog_simple_update").html(a.str_results);
                set_the_ui()
            }
        },
        error: function (a) {
            alert("error")
        }
    })
}
function get_form_attachment_edit(a) {
    a.json_function = "get_form_attachment_edit";
    get_form_court_pickup_edit(a)
}
function form_run_slip_update_on_complete(a) {
    src = $("#run_slip" + a.post.run_slips.run_slip_id).attr("src");
    $("#run_slip" + a.post.run_slips.run_slip_id).attr("src", src)
}
function form_profile_objective_on_complete(a) {
    if (a.is_success) {
        $("#profile_objective").html(a.post.profiles.objective)
    }
}
function form_profile_job_title_on_complete(a) {
    if (a.is_success) {
        $("#profile_job_title").html(a.post.profiles.job_title)
    }
}
function form_profile_job_description_on_complete(a) {
    if (a.is_success) {
        $("#profile_job_description").html(a.post.profiles.job_description)
    }
}
function form_profile_about_on_complete(a) {
    if (a.is_success) {
        $("#profile_about").html(a.post.profiles.about)
    }
}
function form_message_create_on_complete(a) {
    if (a.is_success == true) {
        $("#form_message_create").hide()
    }
}
function form_company_edit_on_complete(a) {
    if (a.is_success == true) {
        $("#form_company_edit").hide()
    }
}
function on_complete_admin_attachment_content(a) {
    alert(dump(a));
    if (a.is_success == true) {};
}
function on_complete_get_run_slip_column_by_id_and_field_name(a) {
    if (a.is_success) {
        $("#dialog_simple_update").html(a.str_results);
        $("#dialog_simple_update").dialog({
            autoOpen: true,
            width: 200,
            height: 100,
            title: "data",
            position: [x_position_mouse + 30, y_position_mouse - 50],
            modal: false,
            buttons: false
        })
    }
}
function on_complete_run_slip_attachment_row_remove(a) {
    if (a.is_success == true) {
        $(a.post.element).hide(200).remove()
    }
}
function on_complete_get_company_info_for_run_slip(a) {
    $("#run_slips_contact_phone").val(a.location.phone);
    $("#company_location").html(a.location.street + ", " + a.location.city + ", " + a.location.alt_zone + " " + a.location.postal_code)
}
function on_complete_delete_run_slips_files_relation(a) {
    if (a.is_success == true) {
        $(a.post.row_id).hide(500).remove()
    }
}
function form_file_code_success(a) {
    $(".file_code").append($("<option></option>").val(a.file_code_id).html(a.code + " - " + a.definition))
}
function form_errors(errors, form_id) {
    for (i in errors) {
        var temp = "";
        temp = eval("errors." + i);
        if (typeof eval(temp) == "object" || typeof eval(temp) == "array") {
            for (j in temp) {
                try {
                    var error = eval("errors." + i + "." + j)
                } catch (e) {
                    error = "undefined"
                }
                if (error != "undefined") {
                    $("#" + form_id + "validate_" + i + "-" + j).html(error)
                }
            }
        } else {
            var error = temp;
            $("#" + form_id + "validate_" + i).html(error)
        }
    }
}
function form_e_file_viewed_on_complete(a) {
    if (a.is_success) {
        $("#widget_e_files_count").html($("#widget_e_files_count").html() - 1);
        $("#widget_e_files_row_" + a.post.run_slips_files_relation.run_slips_files_relation_id).fadeOut(200);
        if (a.post.run_slips_files_relation.is_viewed == 1) {
            $("#run_slips_files_relation-is_viewed").attr("checked", "checked")
        }
    }
}
function file_submission_update_simple(a) {
    $str_data = $("#form_file_submission_update_simple" + a).serialize();
    $str_data = $str_data.replace(/%5B/gi, "[");
    $str_data = $str_data.replace(/%5D/gi, "]");
    $.ajax({
        type: "POST",
        url: BASE_URL + "/" + PROJECT_W_SLASH + "json/file_submission_update_simple",
        data: $str_data,
        dataType: "json",
        success: function (b) {
            $("#form_file_submission_update_simple_results" + a).html(b.results);
            $(".validation_error").html("");
            if (b.is_success == true) {} else {
                if (b.errors.file_submission) {
                    if (b.errors.file_submission.case_name) $("#validate_file_submission-case_name" + a).html(b.errors.file_submission.case_name);
                    if (b.errors.file_submission.document_title) $("#validate_file_submission-document_title" + a).html(b.errors.file_submission.document_title);
                    if (b.errors.file_submission.date_required) $("#validate_file_submission-date_required" + a).html(b.errors.file_submission.date_required)
                }
            }
        },
        error: function (a) {
            alert("error");
            $("#btn_password_reset_submit_simple").show(300)
        }
    })
}
function file_submission_refresh_status_interval() {
    var int_count = 0;
    var int_refresh_status = 3e4;
    var str_json = "{";
    $(".manage_controls").each(function () {
        file_submission_id = $(this).attr("id").replace("manage_controls", "");
        if (int_count > 0) str_json += ",";
        str_json += "'arr_file_submission_ids[" + int_count + "]':" + file_submission_id;
        int_count++
    });
    str_json += "}";
    var status_refresh_interval = window.setInterval(function () {
        $.ajax({
            type: "POST",
            url: BASE_URL + "/" + PROJECT_W_SLASH + "json/file_submission_refresh_status",
            data: eval("(" + str_json + ")"),
            dataType: "json",
            success: function (a) {
                if (a.arr_status != false) {
                    var b;
                    var c;
                    for (c in a.arr_status) {
                        b = a.arr_status[c];
                        file_submission_id = c;
                        $("#manage_status_box" + file_submission_id).css("background", palette["file_submission_status_" + b])
                    }
                } else {
                    alert("no success.")
                }
            },
            error: function (a) {
                alert("error")
            }
        })
    }, int_refresh_status)
}
function file_submission_send_for_file_processing(a) {
    $("#btn_send_for_file_processing" + a).fadeOut();
    $.ajax({
        type: "POST",
        url: BASE_URL + "/" + PROJECT_W_SLASH + "json/file_submission_send_for_file_processing",
        data: {
            file_submission_id: a
        },
        dataType: "json",
        success: function (b) {
            if (b.is_success == true) {
                alert("success");
                $("#btn_send_for_file_processing" + a).fadeIn()
            } else {
                alert("no success");
                $("#btn_send_for_file_processing" + a).fadeIn()
            }
        },
        error: function (b) {
            alert("error");
            $("#btn_send_for_file_processing" + a).fadeIn()
        }
    })
}
function file_manage_delete_file(a) {
    $("#btn_file_delete" + a).fadeOut();
    $.ajax({
        type: "POST",
        url: BASE_URL + "/" + PROJECT_W_SLASH + "json/file_manage_delete_file",
        data: {
            file_id: a
        },
        dataType: "json",
        success: function (b) {
            if (b.is_success == true) {
                $("#file_row" + a).fadeOut()
            } else {
                alert(b.error_message);
                $("#btn_file_delete" + a).fadeIn()
            }
        },
        error: function (a) {
            alert("error")
        }
    })
}
function file_manage_update_status(a, b) {
    $.ajax({
        type: "POST",
        url: BASE_URL + "/" + PROJECT_W_SLASH + "json/file_manage_update_status",
        data: {
            status: b,
            file_submission_id: a
        },
        dataType: "json",
        success: function (c) {
            if (c.is_success == true) {
                $("#manage_status_box" + a).css("background", palette["file_submission_status_" + b])
            } else {};
        },
        error: function (a) {
            alert("error")
        }
    })
}
function file_submission_update_admin_instructions(a, b) {
    $.ajax({
        type: "POST",
        url: BASE_URL + "/" + PROJECT_W_SLASH + "json/file_submission_update_admin_instructions",
        data: {
            admin_instructions: b,
            file_submission_id: a
        },
        dataType: "json",
        success: function (b) {
            if (b.is_success == true) {
                $("#admin_instructions_results" + a).html("updated successfully.")
            } else {
                $("#admin_instructions_results" + a).html('<span class="warning">Update Error.</span>')
            }
            $("#admin_instructions_results" + a).fadeIn(function () {
                $("#admin_instructions_results" + a).delay(1e3).fadeOut()
            })
        },
        error: function (a) {
            alert("error")
        }
    })
}
function file_submission_new_uploads_complete(a) {
    alert(a);
    $("#table_files" + a).hide()
}


function get_content(o) {
    var controller = "json";
    if (o.str_func != undefined) {}
    if (o.controller != undefined) {
        controller = o.controller
    }
    if (o.data != undefined) {}
    $.ajax({
        type: "POST",
        url: BASE_URL + "/" + PROJECT_W_SLASH + controller + "/" + o.str_func,
        data: o.data,
        dataType: "json",
        success: function (data) {
            if (typeof eval(o.str_on_complete) == "function") {
                temp_func = eval(o.str_on_complete);
                temp_func(data)
            } else if (typeof eval(o.str_func_on_complete) == "function") {
                temp_func = eval(o.str_func_on_complete);
                temp_func(data)
            } else {
                get_content_on_complete(data)
            }
            set_the_ui()
        },
        error: function (a) {
            alert("get_content error with data return")
        }
    })
}
function dump(a, b) {
    var c = "";
    if (!b) b = 0;
    var d = "";
    for (var e = 0; e < b + 1; e++) d += "    ";
    if (typeof a == "object") {
        for (var f in a) {
            var g = a[f];
            if (typeof g == "object") {
                c += d + "'" + f + "' ...\n";
                c += dump(g, b + 1)
            } else {
                c += d + "'" + f + "' => \"" + g + '"\n'
            }
        }
    } else {
        c = "===>" + a + "<===(" + typeof a + ")"
    }
    return c
}
function delete_e_file(a) {
    $.ajax({
        type: "POST",
        url: BASE_URL + "/" + PROJECT_W_SLASH + "json/delete_e_file",
        data: {
            file_id: a
        },
        dataType: "json",
        success: function (b) {
            if (b.is_success == true) {
                $("#file_row" + a).remove()
            } else {};
        },
        error: function (a) {
            alert("error")
        }
    })
}
function create_random_element() {
    var a = "random_" + Math.ceil(Math.random() * 20);
    $("body").append('<div id="' + a + '" ></div>');
    return a
}
function contact_form_submit() {
    str_data = $("#form_contact").serialize();
    str_data = str_data.replace(/%5B/gi, "[");
    str_data = str_data.replace(/%5D/gi, "]");
    $.ajax({
        type: "POST",
        url: BASE_URL + "/" + PROJECT_W_SLASH + "json/contact_form_submit",
        data: str_data,
        dataType: "json",
        success: function (a) {
            $(".validation_error").html("");
            if (a.is_success == true) {
                $("#form_contact_results").html("Your message has been sent.");
                $("#form_contact").hide()
            } else {
                $("#form_contact_results").html("There are form errors");
                if (a.errors.request) {
                    if (a.errors.request.description) $("#validate_request-description").html(a.errors.request.description);
                    if (a.errors.request.email) $("#validate_request-email").html(a.errors.request.email);
                    if (a.errors.request.full_name) $("#validate_request-full_name").html(a.errors.request.full_name);
                    if (a.errors.request.phone_number) $("#validate_request-phone_number").html(a.errors.request.phone_number);
                    if (a.errors.request.type) $("#validate_request-type").html(a.errors.request.type)
                }
                if (a.errors.role) {
                    if (a.errors.role.role_id) $("#validate_role-role_id").html(a.errors.role.role_id)
                }
                $("#btn_password_update_submit").fadeIn()
            }
        },
        error: function (a) {
            alert("error");
            $("#btn_password_reset_submit_simple").show(300)
        }
    })
}
function beta_mode() {
    $.ajax({
        type: "POST",
        url: BASE_URL + "/" + PROJECT_W_SLASH + "json/beta_mode",
        dataType: "json",
        success: function (a) {
            if (a.is_success == true) {
                window.location.reload(true)
            } else {};
        },
        error: function (a) {
            alert("error")
        }
    })
}
function ajax_event_request(id, obj_params) {
    if (!obj_params) {
        var obj_params = eval("(" + $("#" + id).attr("rel") + ")")
    }
    if (typeof obj_params.on_initialize_function != "undefined") {
        alert("init funct")
    }
    if (typeof obj_params.dataType == "undefined") {
        obj_params.dataType = "json"
    }
    if (typeof obj_params.is_element_visibility_toggled == "undefined") {
        obj_params.is_element_visibility_toggled = true
    }
    if (typeof obj_params.url == "undefined") {
        alert("url parameter is required in the rel tag of the DOM element id " + id);
        return false
    }
    if (typeof obj_params.data == "undefined") {
        alert("data parameter is required in the rel tag of the DOM element id " + id);
        return false
    }
    if (obj_params.is_element_visibility_toggled) {
        $("#" + id).hide(300)
    }
    $.ajax({
        type: "POST",
        url: obj_params.url,
        data: obj_params.data,
        dataType: obj_params.dataType,
        success: function (data) {
            if (data.is_success == true) {} else {} if (obj_params.is_element_visibility_toggled) {
                $("#" + id).show(200)
            }
            if (typeof obj_params.results_container != "undefined") {
                $(obj_params.results_container).html(data.str_results)
            }
            if (typeof obj_params.on_complete_function != "undefined") {
                temp_func = eval(obj_params.on_complete_function);
                temp_func(data)
            }
            
            if (typeof data.javaScriptOnTheFly != "undefined")
            {
                
            	//alert( data.javaScriptOnTheFly );
            	eval( data.javaScriptOnTheFly );
            }
           
           // alert('on the fly');
        },
        error: function (a) {
            alert("An error with returning data in the ajax_event_request function.");
            if (obj_params.is_element_visibility_toggled) {
                $("#" + id).hide(100)
            }
        }
    })
}
function admin_run_slip_content_on_complete(a) {
    $("#" + a.post.id).html("");
    $("#" + a.post.id).append(a.str_results)
}
function admin_attachment_content_on_complete(a) {
    $("#" + a.post.id).html("");
    $("#" + a.post.id).append(a.str_results)
}
function admin_e_file_content_on_complete(a) {
    $("#" + a.post.id).html("");
    $("#" + a.post.id).append(a.str_results);
    var b = new Object;
    b.run_slip_id = a.post.run_slip_id;
    run_slip_uploadify_setup(b);
    ui_combobox()
}




function get_document_for_dialog(obj_params) {

    //default parameters if they were not passed
    if (typeof obj_params.width == 'undefined') {
        obj_params.width = 500;
    }

    if (typeof obj_params.is_fixed == 'undefined') {
        obj_params.is_fixed = false;
    }

    if (typeof obj_params.x == 'undefined') {
        obj_params.x = 'center';
    }

    if (typeof obj_params.y == 'undefined') {
        obj_params.y = 'center';
    }

    if (typeof obj_params.height == 'undefined') {
        obj_params.height = 400;
    }

    if (typeof obj_params.controller == 'undefined') {
        obj_params.controller = 'json';
    }

    if (typeof obj_params.title == 'undefined') {
        obj_params.title = 'Current Document';
    }

    if (typeof obj_params.view == 'undefined') {
        alert('You must pass "view" in your parameters for the "get_document_for_dialog" function.');
        return false;
    }


    var id = create_random_element();
    $('#' + id).html('Getting the document...');

    if (obj_params.is_fixed == true) {
        obj_params.autoOpen = false;
    } else {
        obj_params.autoOpen = true;
    }

    $('#' + id).dialog({
        autoOpen: obj_params.autoOpen,
        title: obj_params.title,
        width: obj_params.width,
        height: obj_params.height,
        position: [obj_params.x, obj_params.y],
        close: function (event, ui) {
            $(this).dialog('destroy').remove();
        }
    });

    if (obj_params.is_fixed == true) {
        $('#' + id).parent().css({
            position: "fixed"
        }).end().dialog('open');
    }

    $.ajax({
        type: "POST",
        url: '/' + obj_params.controller + '/' + obj_params.view,
        data: obj_params.data,
        dataType: "json",
        success: function (data) {
            //alert( dump(data) );
            if (data.is_success == true) {

                //$('.ad_categories-ad_category_id-'+data.post.ad_categories.ad_category_id).html( data.post.ad_categories.name );
            }

            $('#' + id).html(data.str_results);

            set_the_ui();
        },
        error: function (data) {
            alert('error');
        }

    });

}

$('.form_submitted').live("submit", function () {
    //alert('submit');
    form_submit_listener($(this).children('input[type="submit"]').attr('id'));
    return false;
});


/*
$(".form_enter_submitter").keyup(function(e) 
{
	alert('key');
	if(e.keyCode == 13) 
	{
		$(this).closest('form').submit();
		//$("#loginform").submit();

	}
}); 
*/

function show_confirm_and_cancel_buttons(obj_params) {
    $('.cancel_' + obj_params.id).fadeIn(200, function () {
        $('.confirm_' + obj_params.id).fadeIn(200);
    });
}

function hide_confirm_and_cancel_buttons(obj_params) {
    $('.confirm_' + obj_params.id).fadeOut(200, function () {
        $('.cancel_' + obj_params.id).fadeOut(200);
    });
}

$.fn.clearForm = function () {
    return this.each(function () {
        var type = this.type,
            tag = this.tagName.toLowerCase();
        if (tag == 'form') return $(':input', this).clearForm();
        if (type == 'text' || type == 'password' || tag == 'textarea') this.value = '';
        else if (type == 'checkbox' || type == 'radio') this.checked = false;
        else if (tag == 'select') this.selectedIndex = -1;
    });
};

function common_error_message(message) {
    $('.common-error-message').remove();

    var str = '<div class="ui-widget common-error-message" style="padding-top:0.7em; width:880px; display:none; position:absolute; z-index:100; "><div style="padding: 0 .7em;"  class="ui-state-error ui-corner-all"> <p>' + message + ' <span class="common-link common-remove" rel={element_to_remove:".common-error-message"}  >close</span></p></div></div>';
    $('#content').prepend(str);

    $('.common-error-message').fadeIn(1000);
    //.delay(4000).fadeOut(2000);
}


