function save_broker() {
    var e = $("#main_page").val(),
        a = $("#main_type").val(),
        o = $("#main_action").val(),
        t = $("#main_id").val(),
        n = $("#broker_form");
    n.find("select:disabled").removeAttr("disabled"), n.find(":input:disabled").removeAttr("disabled");
    var i = $("#broker_form").serialize(),
        r = i + "&action=" + encodeURIComponent(o) + "&mainid=" + encodeURIComponent(t);
    $.post("./ajax/broker.php", r, function (o) {
        var t = $.parseJSON(o);
        1 == t.output ? (bootbox.alert("Successfully Saved ..."), window.setTimeout(function () {
            window.location.href = "index.php?pg=" + e + "&type=" + a
        }, 1e3)) : bootbox.alert("Failed in saving.")
    })
}

function delete_broker(e) {
    var a = "broker",
        o = $("#main_page").val(),
        t = $("#main_type").val(),
        n = "mainid=" + encodeURIComponent(e) + "&transaction=" + encodeURIComponent(a);
    $.post("./ajax/delete_transaction.php", n, function (e) {
        var a = $.parseJSON(e);
        1 == a.output ? (bootbox.alert("Successfully Deleted ..."), window.setTimeout(function () {
            window.location.href = "index.php?pg=" + o + "&type=" + t
        }, 1e3)) : (bootbox.alert("Failed in Deleting ..."), window.setTimeout(function () {
            window.location.href = "index.php?pg=" + o + "&type=" + t
        }, 1e3))
    })
}

function load_broker() {
    var e = ($("#main_page").val(), $("#main_type").val(), $("#main_action").val()),
        a = $("#main_id").val(),
        o = "action=" + encodeURIComponent(e) + "&mainid=" + encodeURIComponent(a);
    $.post("./ajax/load_broker.php", o, function (a) {
        var o = $.parseJSON(a),
            t = o.data[0].broker,
            n = o.data[0].contactno,
            i = o.data[0].email,
            r = o.data[0].address,
            m = o.data[0].contact_person,
            p = o.data[0].landline,
            da = o.data[0].date_accredited,
            pr = o.data[0].prcno,
            co = o.data[0].coordinator;
        $("#broker_broker").val(t), $("#broker_contact").val(n), $("#broker_email").val(i), $("#broker_address").val(r), $("#broker_contact_person").val(m), $("#broker_landline").val(p), $("#broker_coordinator").val(co), $("#broker_prc_no").val(pr), $("#broker_date_accredited").val(da), "view" == e && ($("input").attr("disabled", !0), $("textarea").attr("disabled", !0), $("select").attr("disabled", !0), $(".glyphicon-trash").hide(), $(".glyphicon-plus").hide())
    })
}

var action 		=	$('#main_action').val();
var types 		=	$('#main_type').val(); 

if((action=="edit" || action=="view") && types=="broker"){
	load_broker();
}
