function save_agent() {
    var a = $("#main_page").val(),
        e = $("#main_type").val(),
        t = $("#main_action").val(),
        n = $("#main_id").val(),
        i = $("#agent_form");

    i.find("select:disabled").removeAttr("disabled"), i.find(":input:disabled").removeAttr("disabled");

    var o = $("#agent_form").serialize(), d = o + "&action=" + encodeURIComponent(t) + "&mainid=" + encodeURIComponent(n);
    
    $.post("./ajax/agent.php", d, function (t) {
        var n = $.parseJSON(t);
        1 == n.output ? (bootbox.alert("Successfully Saved ..."), window.setTimeout(function () {
            window.location.href = "index.php?pg=" + a + "&type=" + e
        }, 1e3)) : bootbox.alert("Failed in saving.")
    })
}

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

function load_agent() {
    var a = ($("#main_page").val(), $("#main_type").val(), $("#main_action").val()),
        e = $("#main_id").val(),
        t = "action=" + encodeURIComponent(a) + "&mainid=" + encodeURIComponent(e);
    $.post("./ajax/load_agent.php", t, function (e) {
        var t = $.parseJSON(e),
            n = t.data[0].agent,
            i = (t.data[0].broker, t.data[0].contactno),
            o = t.data[0].email,
            d = t.data[0].address,
            pr = t.data[0].agent_pr;
        $("#agent_agent").val(n), $("#agent_pr").val(pr), $("#agent_contact").val(i), $("#agent_email").val(o), $("#agent_address").val(d), "view" == a && ($("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=="agent"){
	load_agent();
}