﻿/*** Modify at your own risk ***/

var numSchools = 1;
var arySchoolData = [];
var currSchoolIndex = 0;
var areaOfStudy;
var currStepIndex = 0;
var invalidFields = [];
var CurrentSchool;
var resultsSummary;
var Width = "784px";
//var initialHeight = "680px";

var arySteps = Array('<div class="nav-button" id="nav-schools"><span>Schools & Programs</span></div>',
'<div class="nav-button" id="nav-cost"><span>Cost of Attendance</span></div>',
'<div class="nav-button" id="nav-grants"><span>Grants & Scholarships</span></div>',
'<div class="nav-button" id="nav-work"><span>Work Study</span></div>',
'<div class="nav-button" id="nav-loans"><span>Loans</span></div>',
'<div class="nav-button" id="nav-aid"><span>Other Aid</span></div>',
'<div class="nav-button" id="nav-results"><span>Results!</span></div>');

var arySchoolColors = [];
arySchoolColors.push({ "color": "#0b1f50", "backgroundColor": "white" });
arySchoolColors.push({ "color": "#1C2456", "backgroundColor": "white" });

jQuery.fn.fadeIn = function(speed, callback) {
     return this.animate({
          opacity: 'show' }, speed, function() {
               if (jQuery.browser.msie)
                    this.style.removeAttribute('filter');
               if (typeof callback == 'function')
                    callback();
     });
};

jQuery.fn.fadeOut = function(speed, callback) {
     return this.animate({
           opacity: 'hide' }, speed, function() {
               if (jQuery.browser.msie)
                    this.style.removeAttribute('filter');
               if (typeof callback == 'function') callback();
     });
};

jQuery.fn.fadeTo = function(speed,to,callback) {
     return this.animate({opacity: to }, speed, function() {
          if (to == 1 && jQuery.browser.msie)
               this.style.removeAttribute('filter');
          if (typeof callback == 'function') callback();
     });
}; 

$(document).ready(function()
{
    for (i = 0; i < arySteps.length; i++)
        $("#Steps").append((arySteps[i]));

    arySchoolData[0] = { "School": null };

    CurrentSchool = document.getElementById("CurrentSchool");

    initialHeight = $("div.Panel").height() + 100;

    $("div.Panel, div.Shell, div.SlideWrapper").css("width", Width);
    $("div.SlideSet, div.SlideShell, div.SlideWrapper, div.Loading").css("height", initialHeight);

    $("div.GrantConditions > div").addClass("GrantCondition");
    $("div.FieldCheckBox > div").css("marginBottom", "10px");
    $("div.FieldSet > div").addClass("Field");

    var jLoanListLabels = $("div.LoanList div.FieldLargeLabel");

    jLoanListLabels.click(function()
    {
        if ($(this).siblings("div.HelpHover").is(":hidden"))
        {
            jLoanListLabels.css("color", "#1C2456");
            $("div.HelpHover").hide();
            $(this).css("color", "#000000").siblings("div.HelpHover").fadeIn(200);
        }
        else
            $(this).siblings("div.HelpHover").fadeOut(200);
    });

    $("div.HelpHover").click(function() { jLoanListLabels.css("color", "#1C2456"); $(this).fadeOut(200); });

    $("div.HelpHover").prepend("<img src='awardtool/images/arrow_left_help.gif' />").append("<br /><br /><i><b>Close Window</b></i>").corner("15px");

    $("div.SchoolFieldList").html($("#SchoolsFieldListSource").html());

    SetButtonStyles();

    $("#CurrentSchool").change(function() { 
		//$("div.Panel").eq(currStepIndex).fadeTo("fast", 0, function() {
			SwitchStep(currStepIndex + 1);
			//$(this).fadeTo("fast", 1, function() {
			/*	if ($.browser.msie) {
					this.style.removeAttribute("filter"); 
				}*/
			//}); 
		//});
	});

    var jStep = $(".Steps .nav-button");
    jStep.click(function() { SwitchStep(jStep.index(this) + 1);});
	
    $("div.SlideSet").css("visibility", "visible");

    $("input[type=text], input[type=password]").focus(function() { $(this).addClass("Hover"); });
    $("input[type=text], input[type=password]").blur(function() { $(this).removeClass("Hover"); });

    $("input.Watermark").click(function() { ClearWatermark($(this)); });

    BindStep1Events();
	
	var curPanel = $(".Panel")[0];
	
	$(".Panel").hide(100, function () {$(curPanel).fadeIn("fast");SetHeight();});
	//alert($(".Panel")[4]);

});



window.onload = function()
{
    SetTrackerStep();
    $("div.Loading").fadeOut(1000);
};

function SetButtonStyles()
{
    $("div.ButtonSet input:first-child").attr("class", "Secondary");
    $("div.ButtonSet input:last-child").attr("class", "Primary");

    var currPrimaryButtonColors = [];

    $("div.ButtonSet input:last-child").hover(function()
    {
        currPrimaryButtonColors.BackgroundColor = $(this).css("backgroundColor");
        currPrimaryButtonColors.Color = $(this).css("color");
        $(this).css({ "backgroundColor": "#3c9906", "color": "#ffffff" });
    },
    function() { $(this).css({ "backgroundColor": currPrimaryButtonColors.BackgroundColor, "color": currPrimaryButtonColors.Color }); });
}

function ClearWatermark(obj)
{
    if (obj.hasClass("Watermark"))
    {
        obj.val("");
        obj.removeClass("Watermark");
    }
}

//window.onbeforeunload = function() { return "If you navigate away you will loose your information."; }

function ToggleForwardLink()
{
    var jForward = $("div.ForwardLink");

    if (jForward.is(":hidden"))
        jForward.fadeIn("slow");
    else
        jForward.fadeOut("slow");     
}

function PrintResults()
{
    window.frames[0].document.getElementById("content").innerHTML = resultsSummary;
    document.getElementById("printFrame").contentWindow.window.focus();
    document.getElementById("printFrame").contentWindow.window.print();
}

function ValidateSchools()
{
    var isValid = true;
    invalidFields.length = 0;

    $("div.SchoolFieldList input[type='text']").each(function()
    {
        if ($(this).val() == "" || $(this).val().toUpperCase() == "ENTER SCHOOL NAME")
        {
            isValid = false;
            $(this).addClass("Invalid");
            invalidFields.push("School #" + eval($("div.SchoolFieldList input[type='text']").index(this) + 1) + "'s name is empty");
        }
        else
            $(this).removeClass("Invalid");
    });

    if ($("input[name='TypeOfStudy']:checked").length == 0)
    {
        alert("Please select your Program of Study");
        isValid = false;
    }

    return isValid;
}

function SaveSchoolData()
{
    if (ValidateSchools())
    {
        var totalSchools = $("div.SchoolFieldList > div").length;

        if (totalSchools == 1)
            $("div.CurrentSchool").fadeOut("slow");
        else
        {
            CurrentSchool.length = 0;
            $("div.CurrentSchool").fadeIn("slow");
        }

        $("div.SchoolFieldList input[type='text']").each(function()
        {
            var schoolIndex = $("div.SchoolFieldList input[type='text']").index(this);
            var schoolName = $(this).val();

            if (!arySchoolData[schoolIndex]) // if not created, make a new entry
                arySchoolData[schoolIndex] = { "School": schoolName };
            else
                arySchoolData[schoolIndex].School = schoolName;

            AddSelectOption("CurrentSchool", schoolIndex, schoolName);
        });

        areaOfStudy = $("input[name='TypeOfStudy']:checked").val();

        if (currSchoolIndex == totalSchools)
        {
            currSchoolIndex = totalSchools - 1;
            $("#CurrentSchool").val(currSchoolIndex);
        }

        return true;
    }
    else
        return false;
}

function SaveGrants()
{
    var aryGrants = [];
    var isValid = true;

    $("div.GrantsFieldList > div").each(function()
    {
        var grantRenewable, grantDivId;
        var aryGrantConditions = [];

        grantRenewable = $(this).find("#GrantRepayable").val();

        if (grantRenewable == "YES")
            grantDivId = "GrantYes";
        else if (grantRenewable == "NO")
            grantDivId = "GrantNo";
        else
            grantDivId = "GrantMaybe";


        $(this).find("#" + grantDivId + " input:checked").each(function()
        {
            aryGrantConditions.push({
                "ConditionId": $(this).attr("id"),
                "ConditionName": $(this).attr("title"),
                "ConditionValue": $(this).val()
            });
        });

        var grantName = $(this).find("#GrantName").val();
        var grantAmount = $(this).find("#GrantAmount").val();

        if (grantName.length > 0 && grantAmount.length == 0)
        {
            $(this).find("#GrantAmount").addClass("Invalid");
            isValid = false;
        }
        else
        {
            $(this).find("#GrantAmount").removeClass("Invalid");
            
            aryGrants.push({
                "GrantName": grantName,
                "GrantAmount": grantAmount,
                "GrantRenewable": grantRenewable,
                "GrantConditions": aryGrantConditions
            });
        }
    });

    arySchoolData[currSchoolIndex].Grants = aryGrants;

    return isValid;
}

function SaveCOA()
{
    arySchoolData[currSchoolIndex].CostOfAttendance = $("#CostOfAttendance").val();
}

function SaveLoans()
{
    var aryLoans = [];

    arySchoolData[currSchoolIndex].LoansTotal = 0;

    $("#CustomLoan1Amount").attr("title", $("#CustomLoan1").val());
    $("#CustomLoan2Amount").attr("title", $("#CustomLoan2").val());
    
    $("div.LoanList input[type=text].Currency").each(function()
    {
        if ($(this).val().length > 0)
        {
            arySchoolData[currSchoolIndex].LoansTotal += eval($(this).val());
            aryLoans.push({ "LoanId": $(this).attr("id"), "LoanAmount": $(this).val(), "LoanName": $(this).attr("title") });
        }
    });

    arySchoolData[currSchoolIndex].LoanCustom1 = $("#CustomLoan1").val();
    arySchoolData[currSchoolIndex].LoanCustom2 = $("#CustomLoan2").val();

    arySchoolData[currSchoolIndex].Loans = aryLoans;
}

function SaveWorkStudy()
{
    arySchoolData[currSchoolIndex].WorkStudy = $("#WorkStudyAmount").val();
}

function SaveOtherAid()
{
    var OtherAidName = $("#OtherAidName").val();
    var OtherAidAmount = $("#OtherAidAmount").val();

    if (OtherAidName.length > 0 && OtherAidAmount.length == 0)
    {
        $("#OtherAidAmount").addClass("Invalid");
        return false;
    }
    else
    {
        $("#OtherAidAmount").removeClass("Invalid");
        arySchoolData[currSchoolIndex].OtherAidName = $("#OtherAidName").val();
        arySchoolData[currSchoolIndex].OtherAidAmount = $("#OtherAidAmount").val();

        return true;
    }
}

function BindStep1Events()
{
    // ADD button
    $("div.SchoolFieldList span:last-child").click(function()
    {
        if ($("div.SchoolFieldList > div").length >= 5)
            alert("You may only enter 5 schools");
        else
        {
            $("div.SchoolFieldList").append($("#SchoolsFieldListSource").html());
            $("div.SchoolFieldList > div:last-child").hide().slideDown("fast", function() { SetHeight(); });
            $(this).unbind("click");
            numSchools++;
            BindStep1Events();
        }
    });

    // DELETE button
    $("div.SchoolFieldList span:first-child").click(function()
    {
        var currIndex = $("div.SchoolFieldList span:first-child").index(this);
        $("div.SchoolFieldList > div").eq(currIndex).slideUp("fast", function() { $(this).remove(); SetHeight(); });
        arySchoolData.splice(currIndex, 1);
        $(this).unbind("click");
        numSchools--;
        BindStep1Events();
    });

    $("input.Watermark").click(function() { ClearWatermark($(this)); });

    var jDeleteButton = $("div.SchoolFieldList span:first-child");
    numSchools == 1 ? jDeleteButton.hide() : jDeleteButton.show();
}

function BindStep3Events()
{
    // ADD button
    $("div.GrantsFieldList span:last-child").click(function()
    {
        $("div.GrantsFieldList").append($("#GrantsFieldListSource").html());
        $("div.GrantsFieldList > div:last-child").hide().slideDown("slow", function() { SetHeight(); });
        $(this).unbind("click");
        arySchoolData[currSchoolIndex].NumGrants++;

        BindStep3Events();
    });

    // DELETE button
    $("div.GrantsFieldList span:first-child").click(function()
    {
        var currIndex = $("div.GrantsFieldList span:first-child").index(this);
        $("div.GrantsFieldList > div").eq(currIndex).slideUp("slow", function() { $(this).remove(); SetHeight(); });
        $(this).unbind("click");
        arySchoolData[currSchoolIndex].NumGrants--;
        BindStep3Events();
    });

    $("div.GrantsFieldList").find("#GrantRepayable").unbind("change");

    $("div.GrantsFieldList").find("#GrantRepayable").change(function()
    {
		if (this.className == "") {
			this.className = arySchoolData[currSchoolIndex].NumGrants;
		//	alert(this.className);
		}
        var jGrant = $(this).parent().parent().parent().siblings("div.GrantConditions");
        var grantRenewable = $(this).val();
        jGrant.children("div").hide();
		var checkNum = this.className;
		jGrant.addClass("check" + checkNum);
		
		// edit: added to make the checkboxes styled checkboxes, i.e. radio buttons
		//$("body").cssRadio();

        if (grantRenewable == "YES")
            jGrant.children("#GrantYes").slideDown("slow", function() { SetHeight();makeRadioButtons("#GrantYes", checkNum); });
        else if (grantRenewable == "NO")
            jGrant.children("#GrantNo").slideDown("slow", function() { SetHeight(); makeRadioButtons("#GrantNo", checkNum); });
        else if (grantRenewable == "MAYBE")
            jGrant.children("#GrantMaybe").slideDown("slow", function() { SetHeight(); makeRadioButtons("#GrantMaybe", checkNum); });
        else
            jGrant.children("div").slideUp("slow", function() { SetHeight(); });
			
			
    });

    //$("div.GrantConditions > div").corner("14px");

    var jDeleteButton = $("div.GrantsFieldList span:first-child");
    arySchoolData[currSchoolIndex].NumGrants == 1 ? jDeleteButton.hide() : jDeleteButton.fadeIn();
}

function SwitchStep(step) {
    var newStep = step - 1;
    var panelWidth = $("div.Panel").width() + 20;
    var slideAmount = newStep * panelWidth;

    switch (currStepIndex + 1)
    {
        case 1:

            if (newStep < 7)
                if (!SaveSchoolData())
                    return;

            break;

        case 2:
            SaveCOA();
            break;

        case 3:

            if (!SaveGrants())
                return;
                
            break;

        case 4:
            SaveWorkStudy();
            break;

        case 5:
            SaveLoans();
            break;

        case 6:

            if (!SaveOtherAid())
                return;
                
            break;
    }

    currSchoolIndex = $("#CurrentSchool").val();

    switch (step)
    {
        case 1: // Basic information
            // nothing
            break;

        case 2: // Cost of attendance
            SetFieldValue("CostOfAttendance", arySchoolData[currSchoolIndex].CostOfAttendance);
            $("#COAInfo").html(arySchoolData[currSchoolIndex].School);
            break;

        case 3: // Grants and scholarships

            if (!arySchoolData[currSchoolIndex].NumGrants)
                arySchoolData[currSchoolIndex].NumGrants = 1;

			if ($("div.GrantsFieldList").html() == "") {
				$("div.GrantsFieldList").html("");

				for (i = 0; i < arySchoolData[currSchoolIndex].NumGrants; i++) 
					$("div.GrantsFieldList").append($("#GrantsFieldListSource").html());
			}

            if (arySchoolData[currSchoolIndex].Grants)
            {
                $("div.GrantsFieldList > div").each(function()
                {
                    var indexGrant = $("div.GrantsFieldList > div").index(this);

                    try
                    {
                        var grantName = arySchoolData[currSchoolIndex].Grants[indexGrant].GrantName;
                        var grantAmount = arySchoolData[currSchoolIndex].Grants[indexGrant].GrantAmount;
                        var grantRenewable = arySchoolData[currSchoolIndex].Grants[indexGrant].GrantRenewable;
                        var aryConditions = arySchoolData[currSchoolIndex].Grants[indexGrant].GrantConditions;

                        $(this).find("#GrantName").val(grantName);
                        $(this).find("#GrantAmount").val(grantAmount);
                        $(this).find("#GrantRepayable").val(grantRenewable);

                        if (grantRenewable == "YES") {
							var yesBoxes = $(this).find("#GrantYes"); 
                            $(this).find("#GrantYes").show();
							var n = $(this).index(this) + 1
							
							makeRadioButtons(yesBoxes, n);
							}
                        else if (grantRenewable == "NO") {
							var noBoxes = $(this).find("#GrantNo");
                            $(this).find("#GrantNo").show();
							makeRadioButtons(noBoxes), $(this).index(this);
							}
                        else if (grantRenewable == "MAYBE")
                            $(this).find("#GrantMaybe").show();

                        for (index in aryConditions)
                            $(this).find("#" + aryConditions[index].ConditionId).attr("checked", "checked");
                    }
                    catch (ex)
                    {
                        alert("Oops! An error has occurred reading one of your grants. Please re-save this step.");
                    }
                });
            }

            BindStep3Events();

            break;

        case 4: // Federal work study
            SetFieldValue("WorkStudyAmount", arySchoolData[currSchoolIndex].WorkStudy);
            $("#WorkStudyInfo").html(arySchoolData[currSchoolIndex].School);
            break;

        case 5: // Loans

            $("div.LoanList input.Currency").val("");

            var aryLoans = arySchoolData[currSchoolIndex].Loans;

            for (index in aryLoans)
                $("#" + aryLoans[index].LoanId).val(aryLoans[index].LoanAmount);

            if (!$("#CustomLoan1").hasClass("Watermark"))
                SetFieldValue("CustomLoan1", arySchoolData[currSchoolIndex].LoanCustom1);

            if (!$("#CustomLoan2").hasClass("Watermark"))
                SetFieldValue("CustomLoan2", arySchoolData[currSchoolIndex].LoanCustom2);

            var jLoanList = $("div.LoanList > div");

            jLoanList.show();

            switch (areaOfStudy)
            {
                case "MEDICAL":
                    jLoanList.eq(6).hide();
                    break;

                case "DENTAL":
                    jLoanList.eq(4).hide();
                    jLoanList.eq(6).hide();
                    break;

                case "HEALTH":
                    jLoanList.eq(4).hide();
                    break;

                default:
                    jLoanList.eq(3).hide();
                    jLoanList.eq(4).hide();
                    jLoanList.eq(6).hide();
                    break;
            }

            break;

        case 6: // Other Aid

            if ($("#OtherAidName").val().length == 0)
                SetFieldValue("OtherAidName", arySchoolData[0].OtherAidName);

            if ($("#OtherAidAmount").val().length == 0)
            SetFieldValue("OtherAidAmount", arySchoolData[0].OtherAidAmount);

            if (currSchoolIndex < arySchoolData.length - 1) {
			// IE7 input CSS error requires the value to be an empty string
             //   $("#CalculateButton").val("Continue to next school...");
                $("#CalculateButton").val("");
				$("#CalculateButton").removeClass("button-calculate");
			}
            else {
              //  $("#CalculateButton").val("Calculate Results!");
                $("#CalculateButton").val("");
				$("#CalculateButton").addClass("button-calculate");
			}

            break;

        case 7:
            GenerateSummary();
            break;
    }

    if (arySchoolData[currSchoolIndex])
        $("div.SchoolName").html(arySchoolData[currSchoolIndex].School);

    if (newStep >= 0)
    {
        if (newStep < 6)
            $("#CurrentSchool").removeAttr("disabled");
        else
            $("#CurrentSchool").attr("disabled", "disabled");
    
        
        //$("div.SlideSet").animate({ "marginLeft": "-" + slideAmount + "px" }, 1000);
		
		var nextPanel = $(".Panel")[newStep];
		var curPanel = $(".Panel")[currStepIndex];
		$(curPanel).fadeOut(100, function () {
			$(nextPanel).fadeIn("fast", function () {
				currStepIndex = newStep;
				SetHeight();
				SetTrackerStep();
			});
		});

        $("div.HelpHover, div.SummaryPopup").fadeOut("fast");
    }

}

var prevStepIndex;
function SetTrackerStep() {
    if (currStepIndex != prevStepIndex) {
        var jStep = $(".Steps .nav-button");
		jStep.removeClass("nav-button-selected");
		jStep.removeClass("nav-button-completed");
		for (var i = 0; i < currStepIndex; i++) {
			jStep.eq(i).addClass("nav-button-completed");
		}
		jStep.eq(currStepIndex).toggleClass("nav-button-selected");

        prevStepIndex = currStepIndex;
    }
}

function SetFieldValue(id, value)
{
    $("#" + id).val(value ? value : "");
}

function AddSelectOption(id, value, text)
{
    var jSelect = $("#" + id)[0];

    var optionNew = document.createElement("option");
    var optionOld = jSelect.options[0];
    optionNew.value = value;
    optionNew.text = text;

    try { jSelect.add(optionNew, null); }
    catch (ex) { jSelect.add(optionNew, value); }
}

function NextSchool()
{
    if (currSchoolIndex < arySchoolData.length - 1)
    {
        currSchoolIndex++;
        $("#CurrentSchool").val(currSchoolIndex);
        SwitchStep(2);
		$("div.GrantsFieldList").html("");
		$("div.GrantsFieldList").append($("#GrantsFieldListSource").html());
    }
    else
        SwitchStep(7);
}

function StartOver()
{
    currSchoolIndex = 0;
    SwitchStep(1);
}

function GenerateSummary()
{
    var htmlTableShell = "<table id='ResultsTable' style='font-size:11px;' border='0' cellpadding='6' width='100%' cellspacing='0'>\n" +
                            "<tr>\n" +
                                "<td align='center'><b>SCHOOL</b></td>\n" +
                                "<td align='center'><b>COA</b></td>\n" +
                                "<td align='center'><b>SCHOLARSHIPS<br />& GRANTS</b></td>\n" +
                                "<td align='center' style='background:#ffffb8 url(awardtool/images/results-table-top.gif) repeat-x'><b class='net-cost'>NET COST</b></td>\n" +
                                "<td align='center'><b>WORK STUDY</b></td>\n" +
                                "<td align='center'><b>LOANS</b></td>\n" +
                            "</tr>\n" +
                            "[SUMMARY_DATA]\n" +
                        "</table>\n";

    var htmlSummaryShell = "<table id='ResultsSummary' style='font-size:11px;' border='0' width='100%'>\n[SUMMARY_DATA]</table>\n";

    var htmlSchoolDataShell = "<tr>\n" +
                                    "<td colspan='3' style='text-align:left;'><h2 style='font-size:14px;font-weight:bold;padding:0px;margin:10px 0px;>[SCHOOL_NAME]</h2></td>\n" +
                                "</tr>\n" +
                                "<tr>\n" +
                                    "<td width='50%' style='text-align:left'><b>Loans</b></td>\n" +
                                    "<td width='50%' style='text-align:left'><b>Grants & Scholarships</b></td>\n" +
                                "</tr>\n" +
                                "<tr>\n" +
                                    "<td align='center' style='text-align:left; vertical-align:middle;'>[LOAN_DATA]</td>\n" +
                                    "<td align='center' style='text-align:left; vertical-align:middle;'>[GRANT_DATA]</td>\n" +
                                "</tr>\n";

    var htmlTableData = "", emailTableData = "";
    var htmlSummary = "";
    var jResultsTable = $("#ResultsTableShell");
    var jResultsSummary = $("#ResultsSummaryShell");

    var lowestCOA, lowestNetCost, lowestLoans, highestGrants, highestWorkStudy;

    for (index in arySchoolData)
    {
        var schoolGrants = arySchoolData[index].Grants;
        var schoolLoans = arySchoolData[index].Loans;
        var totalGrantAmount = 0, totalCOA = 0, totalNetCost, totalLoans, totalWorkStudy;
        var schoolColor = arySchoolColors[index % arySchoolColors.length].color;
        var schoolBgColor = arySchoolColors[index % arySchoolColors.length].backgroundColor;

        var grantSummary = "", loanSummary = "", otherSummary = "";

        if (schoolGrants && schoolGrants[0].GrantAmount > 0)
        {
            for (grantIndex in schoolGrants)
            {
                totalGrantAmount += eval(schoolGrants[grantIndex].GrantAmount);
                grantSummary += "<div><b>" + FormatCurrency(schoolGrants[grantIndex].GrantAmount) + "</b> - " + schoolGrants[grantIndex].GrantName + "</div>";

                grantConditions = schoolGrants[grantIndex].GrantConditions;

                for (condIndex in grantConditions)
                    grantSummary += "<div style='padding-left:10px'><i>- " + grantConditions[condIndex].ConditionName + "</i></div>";
            }
        }
        else
            grantSummary = "None available"

        if (schoolLoans && schoolLoans.length > 0)
        {
            for (loanIndex in schoolLoans)
                loanSummary += "<div><b>" + FormatCurrency(schoolLoans[loanIndex].LoanAmount) + "</b> - " + schoolLoans[loanIndex].LoanName + "</div>";
        }
        else
            loanSummary = "None available";

        otherSummary = "<div><b>" + FormatCurrency(arySchoolData[index].CostOfAttendance) + "</b> - Cost of Attendance</div>" + 
                        "<div><b>" + FormatCurrency(arySchoolData[index].WorkStudy) + "</b> - Federal Work Study</b></div>" + 
                        "<div><b>" + FormatCurrency(arySchoolData[index].OtherAidAmount) + "</b> - Other Aid</div>";

        var htmlSchoolDataShellTemp = htmlSchoolDataShell;

        htmlSchoolDataShellTemp = htmlSchoolDataShellTemp.replace("[SCHOOL_NAME]", "<span style='color:" + schoolColor + "'>" + arySchoolData[index].School + "</span>");
        htmlSchoolDataShellTemp = htmlSchoolDataShellTemp.replace("[GRANT_DATA]", grantSummary);
        htmlSchoolDataShellTemp = htmlSchoolDataShellTemp.replace("[LOAN_DATA]", loanSummary);

        htmlSummary += htmlSchoolDataShellTemp;

        var htmlPopupData = "<div><h3>My Grants</h3><div>" + grantSummary + "</div></div><br />" +
                            "<div><h3>My Loans</h3><div>" + loanSummary + "</div></div><br />" +
                            "<div><h3>Other Information</h3><div>" + otherSummary + "</div></div>";

        if (arySchoolData[currSchoolIndex].OtherAidAmount)
            totalGrantAmount += eval(arySchoolData[currSchoolIndex].OtherAidAmount);

        totalCOA = arySchoolData[index].CostOfAttendance;
        totalNetCost = arySchoolData[index].CostOfAttendance - totalGrantAmount;
        totalLoans = arySchoolData[index].LoansTotal;
        totalWorkStudy = arySchoolData[index].WorkStudy;

        htmlTableData += "<tr style='background-color:" + schoolBgColor + "'>" +
                            "<td align='right'>" +
                                "<div style='color:" + schoolColor + "'><b>" + arySchoolData[index].School + "</b></div>" +
                                /*"<div class='SummaryPopup' style='display:none'>" + htmlPopupData + "</div>" + */
                            "</td>" +
                            "<td align='center'>" + FormatCurrency(totalCOA) + "</td>" +
                            "<td align='center'>" + FormatCurrency(totalGrantAmount) + "</td>" +
                            "<td align='center'>" + FormatCurrency(totalNetCost) + "</td>" +
                            "<td align='center'>" + FormatCurrency(totalWorkStudy) + "</td>" +
                            "<td align='center'>" + FormatCurrency(totalLoans) + "</td>" +
                         "</tr>";
		$(".SummaryPopupContainer").append('<div class="SummaryPopup" id="SummaryPopup' + index + '"></div>');
		$("#SummaryPopup" + index).html(htmlPopupData);
		$(".SummaryPopup").click(function (e) {
			$(this).fadeOut(100);
		});
		
        emailTableData += "<tr style='background-color:" + schoolBgColor + "'>" +
                            "<td style='text-align:left;'>" +
                                "<div style='color:" + schoolColor + "'><b>" + arySchoolData[index].School + "</b></div>" +
                            "</td>" +
                            "<td style='text-align:right; background-color:#none; font-weight:bold;'>" + FormatCurrency(totalCOA) + "</td>" +
                            "<td style='text-align:right; background-color:#none; font-weight:bold;'>" + FormatCurrency(totalGrantAmount) + "</td>" +
                            "<td style='text-align:right; background-color:#ffffb8; font-weight:bold;'>" + FormatCurrency(totalNetCost) + "</td>" +
                            "<td style='text-align:right;'>" + FormatCurrency(totalWorkStudy) + "</td>" +
                            "<td style='text-align:right;'>" + FormatCurrency(totalLoans) + "</td>" +
                         "</tr>";
    }

    var netCostInfo = "<tr><td height='3'></td><td></td><td></td><td></td><td colspan='2'></td></tr>" +
                            "<tr>" +
                                "<td colspan='6' valign='top' align='left' style='text-align:left'>" +
                                    "<div id='NetCostExplanation'>" +
                                        "<div id='NetCostLink' style='font-weight:bold; text-decoration:none;'>What does \"net cost\" mean?</div>" +
                                        "<div id='NetCostContent'>This is the cost to you of attending a school, the Cost of Attendance minus Scholarships & Grants. You can cover these remaining costs from your own resources, by earning Federal Work Study if awarded to you, and/or by borrowing student loans up to the amount you are eligible as specified by the school.</div>" +
                                    "</div>" +
                                "</td>" +
                            "</tr>";

    htmlTableData += netCostInfo;
    emailTableData += netCostInfo;
    
    htmlSummaryShell = htmlSummaryShell.replace("[SUMMARY_DATA]", htmlSummary);
    resultsSummary = htmlTableShell.replace("[SUMMARY_DATA]", emailTableData) + "<br />" + htmlSummaryShell;

    htmlTableShell = htmlTableShell.replace("[SUMMARY_DATA]", htmlTableData);
    
    jResultsTable.html(htmlTableShell);

    $("#ResultsTable").attr({ "cellspacing": "0" });
    $("#ResultsTable tr td").css({ "fontSize": "12px" });
    $("#ResultsTable tr:gt(0) td:first-child").css({ "textAlign": "left", "fontWeight": "bold", "width": "80px"});
    $("#ResultsTable tr:gt(0):not(:last) td:first-child").css({"textTransform": "capitalize", "cursor": "help" });
  //  $("#ResultsTable tr:gt(0):not(:last) td:first-child > div:first-child").css({ "textDecoration": "underline" });
  //  $("#ResultsTable td:nth-child(2), #ResultsTable td:nth-child(3)").css({ "backgroundColor": "none", "fontWeight": "bold" });
    $("#ResultsTable td:nth-child(4)").css({ "backgroundColor": "#ffffb8", "fontWeight": "bold" });
    $("#ResultsTable tr:last td").css({ "padding": "0px", "backgroundColor": "transparent" });
    $("#ResultsTable tr:first-child td:lt(4)").css({ "fontWeight": "bold", "color": "#1C2456" });

    $("#NetCostExplanation").css({ "backgroundColor": "#ffffb8", "textAlign": "left", "fontWeight": "normal", "padding": "8px", "fontSize": "11px" });

    $("#NetCostContent").css({ "marginTop": "10px" });
    $("#NetCostLink").css({ "fontSize": "11px", "cursor": "pointer" });
    $("#NetCostLink").hover(function() { $(this).css("textDecoration", "underline"); }, function() { $(this).css("textDecoration", "none"); });

    $("div.SummaryPopup").prepend("<img src='awardtool/images/arrow_left.gif' />").append("<span class=\"closer\"><i><b>Close Window</b></i></span><div class=\"clearer\"></div><div class=\"footer\"></div>").corner("15px");

    $("#NetCostLink").toggle(function() { $(this).siblings("#NetCostContent").slideDown("slow", function() { SetHeight(); }); }, function() { $(this).siblings("#NetCostContent").slideUp("slow", function() { SetHeight(); }); });

    $("#ResultsTable tr td:first-child").click(function(e)
    {
	var n = $("#ResultsTable tr").index($(this).parent()) - 1;
        //if ($(this).children("div.SummaryPopup").is(":hidden"))
        if ($("#SummaryPopup" + n).is(":hidden"))
        {
            $("div.SummaryPopup:visible").hide();
            $("#SummaryPopup" + n).fadeIn(200);
			$("#SummaryPopup" + n).css({"left": e.pageX + "px", "top": e.pageY + "px"});
        }
        else
            $("div.SummaryPopup").fadeOut(200);
    });

    var currSchoolColor = "";
    $("#ResultsTable tr:gt(0) td:first-child > div:first-child").hover(function()
    {
        currSchoolColor = $(this).css("color");
        $(this).css("color", "black");
    }, function()
    {
        $(this).css("color", currSchoolColor);
    });
}

function FormatCurrency (num)
{
    if (num)
    {
        num = num.toString().replace(/\$|\,/g, '');

        if (!isNaN(num))
        {
            sign = (num == (num = Math.abs(num)));
            num = Math.floor(num * 100 + 0.50000000001);
            cents = num % 100;
            num = Math.floor(num / 100).toString();
            if (cents < 10)
                cents = "0" + cents;

            for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
                num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));

            if (cents == "00")
                return (((sign) ? '' : '-') + '$' + num);
            else
                return (((sign) ? '' : '-') + '$' + num + '.' + cents);
        }
        else
            return "<b class='Red'>Invalid</b>";
    }
    else
        return "None";
}

function SetHeight() {
    var newHeight = eval($("div.Panel").eq(currStepIndex).height() + 0);
   // $("div.SlideShell, div.SlideWrapper").animate({ "height": newHeight + "px" }, 300);
    $("div.SlideShell, div.SlideWrapper").css("height", newHeight + "px");
}

function makeRadioButtons(elem, num) {
	var check = $(".GrantsFieldList .check" + num).children(elem);
	
	$(check).cssRadio();
}