/**
 * @author jon.merchant
 */
function slide_up(div) {
	$(div).slideUp("slow");
}
function slide_up2(div,img) {
	$(div).slideUp("slow",function(){
		$(img).fadeOut("fast");
	});
}
function load_branch() {
	$("#br-loader").html("<img src='../site_core/images/small-loader.gif' alt='Loading Branch...'/>");
        $("#br-loader").fadeIn("slow");
        branch = $("#br_sel").val();
        div = "#branch_info";
        if (branch.length < 1) {
            alert("Please select a Branch from the list to continue.");
        } else {
            if ($("#branch_info").is(":hidden")) {
                
                $.ajax({
                    type: "POST",
                    url: "../site_core/libs/ajax_load_branch.php",
                    data: ({branch_code:branch,div:div}),
                    dataType: "json",
                    success: function(data) {
                        $("#br-loader").fadeOut("slow");
                        $("#branch_info").html(data.html);
                        $("#branch_info").slideDown("slow");
                    },
                    error: function(){
                        $("#br-loader").fadeOut("slow");
                        alert("There was an error communicating with the server, please try again.");
                    }
                })
                

            } else {
                $("#branch_info").slideUp("slow",function(){
                    $.ajax({
                        type: "POST",
                        url: "../site_core/libs/ajax_load_branch.php",
                        data: ({branch_code:branch,div:div}),
                        dataType: "json",
                        success: function(data) {
                            $("#br-loader").fadeOut("slow");
                            $("#branch_info").html(data.html);
                            $("#branch_info").slideDown("slow");
                        },
                        error: function(){
                            $("#br-loader").fadeOut("slow");
                            alert("There was an error communicating with the server, please try again.");
                        }
                    })
                });
                
            }
        }
        return false;
}
function load_lo() {
    $("#lo-loader").html("<img src='../site_core/images/small-loader.gif' alt='Loading Loan Officer...'/>");
    $("#lo-loader").fadeIn("slow");
    lo = $("#lo-sel :selected").val();
    div = "#lo_info";
    if (lo.length < 1) {
        alert("Please select a Loan Officer from the list to conitue.");
    } else {
        if ($("#lo_info").is(":hidden")) {
            $.ajax({
                type: "POST",
                url: "../site_core/libs/ajax_load_lo.php",
                data: ({lo:lo,div:div}),
                dataType: "json",
                success: function(data) {
                    $("#lo-loader").fadeOut("slow");
                    $("#lo_info").html(data.html);
                    $("#lo_info").slideDown("slow");
                },
                error: function(){
                    $("#lo-loader").fadeOut("slow");
                    alert("There was an error communicating with the server, please try again.");
                }
            })
        } else {
            $("#lo_info").slideUp("slow",function(){
                $.ajax({
                    type: "POST",
                    url: "../site_core/libs/ajax_load_lo.php",
                    data: ({lo:lo,div:div}),
                    dataType: "json",
                    success: function(data) {
                        $("#lo-loader").fadeOut("slow");
                        $("#lo_info").html(data.html);
                        $("#lo_info").slideDown("slow");
                    },
                    error: function(){
                        $("#lo-loader").fadeOut("slow");
                        alert("There was an error communicating with the server, please try again.");
                    }
                })
            })
        }
    }
    return false;
}
function search_for_lo() {
	$("#search-loader").html("<img src='../site_core/images/small-loader.gif' alt='Finding Loan Officer...'/>");
        $("#search-loader").fadeIn("slow");
	lo = $("#search_lo").val();
        div = "'#s_lo_info'";
	
	if (!lo) {
		$("#search-loader").html("");
		alert("Please type in a name to begin your search.");
	} else {
            if ($("#s_lo_info").is(":hidden")) {
                $.ajax({
                    type: "POST",
                    url: "../site_core/libs/ajax_search_for_lo.php",
                    data: ({lo:lo,div:div}),
                    dataType: "json",
                    success: function(data){
                        $("#search-loader").fadeOut("slow");
                        $("#s_lo_info").html(data.html);
                        $("#s_lo_info").slideDown("slow");
                    },
                    error: function() {
                        $("#search-loader").fadeOut("slow");
                        alert("There was an error communicating with the server, please try again.");
                    }
                })
            } else {
                $("#s_lo_info").slideUp("slow",function(){
                    $.ajax({
                        type: "POST",
                        url: "../site_core/libs/ajax_search_for_lo.php",
                        data: ({lo:lo,div:div}),
                        dataType: "json",
                        success: function(data){
                            $("#search-loader").fadeOut("slow");
                            $("#s_lo_info").html(data.html);
                            $("#s_lo_info").slideDown("slow");
                        },
                        error: function() {
                            $("#search-loader").fadeOut("slow");
                            alert("There was an error communicating with the server, please try again.");
                        }
                    })
                })
            }
		
	}
	return false;
}
