﻿ejungle.runtime.controls.courseSearch = {};

ejungle.runtime.controls.courseSearch.filter = {
    timeOfDay: "all",
    isOnlineOnly: false,
    isCertificateProgram: false,
    daysOfWeek: ""
};

ejungle.runtime.controls.courseSearch.subjectListType = "TwoLevels";

ejungle.runtime.controls.courseSearch.updateFilter = function(data) {
    ejungle.runtime.controls.courseSearch.filter = $.extend(ejungle.runtime.controls.courseSearch.filter, data || {});
};


/* Initializes the page */
ejungle.runtime.controls.courseSearch.init = function() {
    this.initFilters();
    this.initCallOuts();
    this.initSubjectList();
    this.initProgramAndCourseList();
    $(".right-content-repository").html($(".right-content").html());

    var element = $(".course-search .subjects .subjects-list");
    element.find("> ul > li").each(function(index) {
        var onElement = $(this).find("a.on");
        if (onElement.length > 0) {
            element.accordion('activate', index);

            onElement.addClass("on").append(ejungle.settings.checkmark);
            onElement.find("img.bullet").attr("src", "/assets/images/course-search/bullet-red.gif");
            ejungle.runtime.controls.courseSearch.initProgramAndCourseList(true);
        }
    });

    element = $(".course-search .program-course-list");
    element.find("> ul > li").each(function(index) {
        var onElement = $(this).find("a.on");
        if (onElement.length > 0) {
            element.accordion('activate', index);

            onElement.addClass("on").append(ejungle.settings.checkmark);
            onElement.find("img.bullet.change").attr("src", "/assets/images/course-search/bullet-red.gif");
        }
    });
    this.initProgramCourseInfo();


    if ($(".sectionId-value").length > 0) {
        var sectionId = $(".sectionId-value").val();
        $(".program-course-info .section-table a").each(function() {
            var self = $(this);
            if (self.find(".sectionid").text() == sectionId) {
                self.addClass("on");
            }
        });
    }

};

/* Initializes the call outs */
ejungle.runtime.controls.courseSearch.initFilters = function() {
    $(".btn-all-courses").click(function() {
        $(this).parent().find("li").removeClass("bold").removeClass("on");
        $(this).addClass("bold").addClass("on");

        $(".filter-dropdown").css("display", "none");
        ejungle.runtime.controls.courseSearch.updateFilter({
            timeOfDay: "all",
            isOnlineOnly: false,
            isCertificateProgram: false,
            daysOfWeek: ""
        });

        $(".secondary-nav span.title").text($(this).find("span").text());

        ejungle.runtime.ajax.loadSubjects(ejungle.runtime.controls.courseSearch.loadSubjectList);
        return false;
    });

    $(".btn-online-courses").click(function() {
        $(this).parent().find("li").removeClass("bold").removeClass("on");
        $(this).addClass("bold").addClass("on");

        $(".filter-dropdown").css("display", "none");
        ejungle.runtime.controls.courseSearch.updateFilter({
            timeOfDay: "all",
            isOnlineOnly: true,
            isCertificateProgram: false,
            daysOfWeek: ""
        });

        $(".secondary-nav span.title").text($(this).find("span").text());

        ejungle.runtime.ajax.loadSubjects(ejungle.runtime.controls.courseSearch.loadSubjectList);
        return false;
    });

    $(".btn-certificate-programs").click(function() {
        $(this).parent().find("li").removeClass("bold").removeClass("on");
        $(this).addClass("bold").addClass("on");

        $(".filter-dropdown").css("display", "none");
        ejungle.runtime.controls.courseSearch.updateFilter({
            timeOfDay: "all",
            isOnlineOnly: false,
            isCertificateProgram: true,
            daysOfWeek: ""
        });

        $(".secondary-nav span.title").text($(this).find("span").text());

        ejungle.runtime.ajax.loadSubjects(ejungle.runtime.controls.courseSearch.loadSubjectList);
        return false;
    });

    $(".btn-evening-courses").click(function() {
        $(this).parent().find("li").removeClass("bold").removeClass("on");
        $(this).addClass("bold").addClass("on");

        $(".filter-dropdown").css("display", "none");
        ejungle.runtime.controls.courseSearch.updateFilter({
            timeOfDay: "evening",
            isOnlineOnly: false,
            isCertificateProgram: false,
            daysOfWeek: ""
        });

        $(".secondary-nav span.title").text($(this).find("span").text());

        ejungle.runtime.ajax.loadSubjects(ejungle.runtime.controls.courseSearch.loadSubjectList);
        return false;
    });

    $(".btn-weekend-courses").click(function() {
        $(this).parent().find("li").removeClass("bold").removeClass("on");
        $(this).addClass("bold").addClass("on");

        $(".filter-dropdown").css("display", "none");
        ejungle.runtime.controls.courseSearch.updateFilter({
            timeOfDay: "all",
            isOnlineOnly: false,
            isCertificateProgram: false,
            daysOfWeek: "Saturday|Sunday"
        });

        $(".secondary-nav span.title").text($(this).find("span").text());

        ejungle.runtime.ajax.loadSubjects(ejungle.runtime.controls.courseSearch.loadSubjectList);
        return false;
    });

    $(".btn-advanced-search").click(function() {
        $(this).parent().find("li").removeClass("bold").removeClass("on");
        $(this).addClass("bold").addClass("on");

        $(".filter-dropdown").css("display", "block");

        $(".secondary-nav span.title").text($(this).find("span").text());

        //        document.onclick = function() {
        //            alert("here");
        //            $(".filter-dropdown").css("display", "none");
        //        };


        return false;
    });

//    $("body").click(function() {
//        //alert("close");
//        $(".filter-dropdown").css("display", "none");
//    });

//    $(".filter-dropdown, .filter-dropdown *,.btn-advanced-search, .btn-advanced-search *").click(function() {
//        $(".filter-dropdown").css("display", "block");
//    });

    var filterdropdown = $(".filter-dropdown");

    filterdropdown.find(".instruction-format").click(function() {
        if ($(this).attr("value") == "online") {
            filterdropdown.find(".days[value='']").attr('checked', true);
            filterdropdown.find(".days[value!='']").attr('disabled', true).attr('checked', false);
        }
        else {
            filterdropdown.find(".days[value!='']").removeAttr('disabled');
        }
    });

    filterdropdown.find(".days").click(function() {
        var self = $(this);

        if (self.attr("value") == "") {
            if (self.is(':checked')) {
                filterdropdown.find(".days[value!='']").attr('checked', false);
            }
        }
        else {
            filterdropdown.find(".days[value='']").attr('checked', false);
        }

        if (filterdropdown.find(".days:checked").length == 0) {
            self.attr('checked', true);
        }
    });



    filterdropdown.find(".btn-advanced-search-submit").click(function() {
        var timeOfDay = filterdropdown.find(".time-of-day:checked").val();
        var isCertificateProgram = filterdropdown.find(".education-format:checked").val() == "certificate";
        var isOnlineOnly = filterdropdown.find(".instruction-format:checked").val() == "online";

        var daysOfWeek = "";
        filterdropdown.find(".days:checked").each(function() {
            daysOfWeek += "|" + $(this).val();
        });
        daysOfWeek = daysOfWeek.substring(1);


        ejungle.runtime.controls.courseSearch.updateFilter({
            timeOfDay: timeOfDay,
            isOnlineOnly: isOnlineOnly,
            isCertificateProgram: isCertificateProgram,
            daysOfWeek: daysOfWeek
        });

        ejungle.runtime.ajax.loadSubjects(ejungle.runtime.controls.courseSearch.loadSubjectList);

        filterdropdown.css("display", "none");

        return false;
    });
};


/* Initializes the call outs */
ejungle.runtime.controls.courseSearch.loadSubjectList = function(msg) {
    $(".course-search .subjects .subjects-list").html(msg.d)
    ejungle.runtime.controls.courseSearch.initSubjectList();
    $(".right-content").html($(".right-content-repository").html());
    ejungle.runtime.controls.courseSearch.initCallOuts();

    // Fix the height
    ejungle.runtime.controls.courseSearch.setHeight();
};

/* Initializes the call outs */
ejungle.runtime.controls.courseSearch.initCallOuts = function() {
    $(".call-out-list li").each(function() {
        var self = $(this);

        self.hover(function() {
            var color = $(".course-search").attr("ejColor") || "red";

            $(this).find(".border-default").attr("src", "/assets/images/course-search/border-call-out-" + color + ".png");
        }, function() {
            $(this).find(".border-default").attr("src", "/assets/images/course-search/border-call-out-default.png");
        });

        self.click(function() {
            var url = $(this).find(".link a").attr("href");
            document.location = url;
        });
    });
};

/* Loads the subjects */
ejungle.runtime.controls.courseSearch.initSubjectList = function() {
    var self = ejungle.runtime.controls.courseSearch;
    var element = $(".course-search .subjects .subjects-list");
    //self.fixIEHeight($(".subjects-list"));


    var levelOnes = element.find("ul.level-0 > li").addClass("level-one");
    var levelTwoUl = levelOnes.find("ul");
    var levelTwos = levelTwoUl.find("> li").addClass("level-two");

    var openers = levelTwos;

    if (ejungle.runtime.controls.courseSearch.subjectListType == "OneLevel") {
        openers = levelOnes;
    } else {
        levelTwoUl.each(function() {
            if ($(this).find("a.on").length == 0) {
                $(this).hide();
            } else {
                $(this).parent().addClass("open");
            }
        });

        levelOnes.find("> a").click(function() {
            var li = $(this).parent();
            var ul = li.find("ul");

            if (!li.hasClass("open")) {
                levelTwoUl.slideUp(500);
                levelOnes.removeClass("open");
                li.addClass("open");
                ul.slideDown(500, ejungle.runtime.controls.courseSearch.setHeight);
            }

            return false;
        });
    }



    // For all items that do not have children attach AJAX event
    openers.find("a").click(function() {
        ejungle.runtime.ajax.loadProgramsAndCourses($(this).metadata().id, function(msg) {
            $(".course-search .body .right-content").html(msg.d);
            self.initProgramAndCourseList();
            scroll(0, 0);
        });

        // Add the checkmark
        $(".subjects ul a").removeClass("on").find("img.checkmark").remove().end().find("img.bullet.change").attr("src", "/assets/images/course-search/bullet-black.gif");
        $(this).addClass("on").append(ejungle.settings.checkmark);
        $(this).find("img.bullet.change").attr("src", "/assets/images/course-search/bullet-red.gif");
        return false;
    });
};

ejungle.runtime.controls.courseSearch.fixIEHeight = function(element) {
    if ($.browser.msie) {
        var liHeight = 39;

        element.find("ul.level-0 li").css("height", jQuery.PxToEm(liHeight));
        var listItems = element.find("ul.level-0 li.selected ul.level-1 li");
        var ulHeight = liHeight * (listItems.length + 1);
        element.find("ul.level-0 li.selected").css("height", jQuery.PxToEm(ulHeight));
    }
};


/* Loads courses and programs */
ejungle.runtime.controls.courseSearch.initProgramAndCourseList = function(doNotLoadCourseInfo) {
    doNotLoadCourseInfo = doNotLoadCourseInfo || false;

    var self = ejungle.runtime.controls.courseSearch;
    var element = $(".course-search .program-course-list");
    //self.fixIEHeight($(".program-course-list"));

//    element.find("ul.level-0 > li > a").addClass("ryan");
//    var animated = $.browser.msie ? false : "slide";

//    element.accordion({
//        autoHeight: false,
//        alwaysOpen: false,
//        active: false,
//        animated: animated,
//        event: "click",
//        header: "a.ryan",
//        onClick: function(element) {
//            $(".program-course-list a").removeClass("on").find("img.checkmark").remove().end().find("img.bg").remove().end().find("img.bullet").attr("src", "/assets/images/course-search/bullet-black.gif");
//            $(element).addClass("on").append("<img src='/assets/images/course-search/bg-left-nav-level-0.jpg' class='bg' alt='' />");

//            if (!doNotLoadCourseInfo) {
//                self.loadProgramCourseInfo(element);
//            }
//        },
//        onComplete: function() {
//            //self.fixIEHeight($(".program-course-list"));
//        }
//    });


    $(".program-course-list ul a.on").append(ejungle.settings.checkmark).find("img.bullet").attr("src", "/assets/images/course-search/bullet-red.gif");


    // For all items that do not have children attach AJAX event
    element.find("ul a").click(function() {
        var url = new String(document.location);
        if (url.indexOf("?") >= 0) {
            url = url.substring(0, url.indexOf("?"));
        }

        ejungle.currentUrl = url + $(this).attr("href");
        ejungle.runtime.controls.courseSearch.loadProgramCourseInfo(this);

        // Add the checkmark
        $(".program-course-list ul a").removeClass("on").find("img.checkmark").remove().end().find("img.bullet.change").attr("src", "/assets/images/course-search/bullet-black.gif");
        $(this).addClass("on").append(ejungle.settings.checkmark);
        $(this).find("img.bullet.change").attr("src", "/assets/images/course-search/bullet-red.gif");
        scroll(0, 0);
        return false;
    });
    // Fix the height
    ejungle.runtime.controls.courseSearch.setHeight();

};

/* Loads course/program information */
ejungle.runtime.controls.courseSearch.loadProgramCourseInfo = function(element) {
    var self = this;
    var metadata = $(element).metadata();

    ejungle.runtime.ajax.loadProgramCourseInfo(metadata.id, metadata.type, function(msg) {
        $(".program-course-info").removeClass("program-course-info-empty").html(msg.d);
        ejungle.runtime.controls.courseSearch.initProgramCourseInfo();
    });
};

/* Inits course/program information */
ejungle.runtime.controls.courseSearch.initProgramCourseInfo = function() {
    var self = this;
    $(".program-course-info .section-table a").click(function() {
        $(".program-course-info .section-table a").removeClass("on");

        if ($(".program-course-info .section-table a").length > 1) {
            $(this).addClass("on");
        }
        var sectionId = $(this).find(".sectionid").text();
        self.loadSectionInfo(sectionId, false);
        return false;
    });
    ejungle.runtime.controls.courseSearch.initSectionInfo();
    // Fix the height
    ejungle.runtime.controls.courseSearch.setHeight();
};

ejungle.runtime.controls.courseSearch.loadSectionInfo = function(sectionId, isBeingApproved) 
{
    var self = ejungle.runtime.controls.courseSearch;

    ejungle.runtime.ajax.loadSectionInfo
	(sectionId, isBeingApproved, function(msg) 
		{
			// Display the section data
		    $(".section-info-div").html(msg.d);

			self.initSectionInfo();
		}
	);
};

ejungle.runtime.controls.courseSearch.initSectionInfo = function() 
{
    var self = ejungle.runtime.controls.courseSearch;

    $(".enroll-btn-row .btn-enroll").hover
	(
		function() 
		{
			$(this).find("img").attr("src", "/assets/images/course-search/btn-on-enroll_now.gif");
		}, 
		function() 
		{
			$(this).find("img").attr("src", "/assets/images/course-search/btn-off-enroll_now.gif");
		}
	);

    $(".section-info-div .btn-waitlist").hover
	(
		function () 
		{
			$(this).find("img").attr("src", "/assets/images/course-search/btn-on-waitlist.gif");
		}, 
		function () 
		{
			$(this).find("img").attr("src", "/assets/images/course-search/btn-off-waitlist.gif");
		}
	);

    $(".base-fee-table input:radio:first").attr("checked", true);
    $(".optional-fee-table input:radio:first").attr("checked", true);

    $(".instructor-anchor").click
	(
		function() 
		{
	        var $this	= $(this);
		    $(".popup1 h2").text($this.find("span").text());
			$(".popup1 p").html($this.find("p").text());

	        ejungle.functions.dialog($(".popup1"), "popup1");
		    return false;
		}
	);

//    $(".discount-code-submit").unbind("click");
//    $(".discount-code-submit").click(function() {
//        $(".discount-code-error").hide();
//        $(".discount-fee").remove();
//        var sectionId = $(".sectionId-value").val();
//        var code = $("#dicount-code-input").val();
//        ejungle.runtime.ajax.validateDiscountCode(sectionId, code, function(msg) {
//            var result = msg.d;
//
//            var dest = $(".fees-table tbody").length > 0 ? $(".fees-table tbody") : $(".fees-table");
//
//            if (result.length > 0) {
//                dest.append(result);
//                $(".discount-code-input").hide();
//                $(".discount-fee input:radio:first").attr("checked", true);
//            }
//            else {
//                $(".discount-code-error").show();
//            }
//        });
//
//        return false;
//    });
//
//    $(".approval-code-submit").unbind("click");
//    $(".approval-code-submit").click(function() {
//        $(".approval-code-error").hide();
//        $(".section-number").hide();
//
//        var sectionId = $(".sectionId-value").val();
//        var code = $("#approval-code-textbox").val();
//        var btn = $(".enroll-btn-row");
//        ejungle.runtime.ajax.validateApprovalCode(sectionId, code, function(msg) {
//            var result = msg.d;
//            if (msg.d == "true") {
//                btn.show();
//                $(".section-number").show();
//                $(".approval-code-input").hide();
//            } else {
//            $(".approval-code-error").show();
//                btn.hide();
//            }
//        });
//
//        return false;
//    });

    // Adjust the height to ensure that the page looks correct
    ejungle.runtime.controls.courseSearch.setHeight();
};

/* Ensures that all of the columns are the same height */
ejungle.runtime.controls.courseSearch.setHeight = function() 
{
    var courseSearch			= $(".course-search");
    var subjectList				= courseSearch.find(".subjects");
    var rightColumn				= courseSearch.find(".right-content");
    var programCourseList		= courseSearch.find(".program-course-list");
    var programCourseInfo		= courseSearch.find(".program-course-info");
    var programCourseInfoEmpty	= courseSearch.find(".program-course-info-empty");
    var body					= courseSearch.find(".body");
    var rightContent			= body.find(".right-content");
    var mainImage				= body.find(".main-image");
    var rightContentColumns		= rightContent.find(".columns");
    var rightColumn				= rightContentColumns.find(".right-column");

    var columnTitleHeight		= 55;

    var maxHeight				= 520;

    rightContent.css(			{ height: "auto" });
    subjectList.css(			{ height: "auto" });
    programCourseList.css(		{ height: "auto" });
    rightColumn.css(			{ height: "auto" });
    programCourseInfo.css(		{ height: "auto" });
    programCourseInfoEmpty.css(	{ height: "auto" });

    maxHeight = Math.max(maxHeight, rightContent.height());
    maxHeight = Math.max(maxHeight, $(".course-search .subjects .subjects-list > ul").height()	+ columnTitleHeight);
    maxHeight = Math.max(maxHeight, $(".program-course-list > ul").height()						+ columnTitleHeight);
    maxHeight = Math.max(maxHeight, ($(".program-course-info .description").outerHeight() || 0) + ($(".program-course-info .title").outerHeight() || 0) + 20);

    maxHeight = maxHeight + 30;

    //console.log("body.height(): " + body.height());
    body.css({ height: $.PxToEm(maxHeight) });


    subjectList.css({ height: $.PxToEm(body.height()) });
    subjectList.find("ul").css({ borderBottom: (subjectList.height() < body.height() ? "solid 0.1em #8a8a8a" : "none") });

    programCourseList.css({ height: $.PxToEm(body.height()) });
    programCourseList.find("ul").css({ borderBottom: (subjectList.height() < body.height() ? "solid 0.1em #8a8a8a" : "none") });

    rightContentColumns.css({ height: $.PxToEm(body.height() - mainImage.height()) });

    rightColumn.css({ height: $.PxToEm(rightContentColumns.height()) });
    rightColumn.find("ul.level-1").css({ borderBottom: (rightColumn.height() < rightContent.height() ? "solid 0.1em #c1c0c2" : "none") });
    //console.log("body.height(): " + body.height());


    programCourseInfo.css({ height: $.PxToEm(body.height()) });
    programCourseInfoEmpty.css({ height: $.PxToEm(body.height()) });
};

// following functions were moved here from SectionInfo.ascx 
// because they were being dropped by IE when the page was rendered.
function saveCourse(tid, sid, nm, dtSt, dtEnd, accTp, cat, isAdm, isLateFeeWaived) 
{
    // used on SectionInfo.ascx
    var data =
			{
			    typeID: tid - 0,
			    pkId: sid - 0,
			    Name: nm,
			    DateStart: dtSt,
			    DateEnd: dtEnd,
			    AccountingType: accTp - 0,
			    Category: cat,                          //CES: Add Category
			    IsAdmin: isAdm,
			    IsLateFeeWaived: isLateFeeWaived        //CES: Added to support by admin late fee override - DCM, CES
			};

    // Base fee
    data.fee = $(".base-fee-table input:checked").attr("amount") || 0;
    data.feeID = $(".base-fee-table input:checked").attr("feeID") || 0;

    if ($(".late-fee-table input:checked").val() !== undefined) {
        data.IsLateFeeWaived = false;
    }
    else {
        data.IsLateFeeWaived = true;
    }

    // Optional fees
    data.optionalFees = getOptionalFees();

    ejungle.ajax
			(
				{
				    url: "/WebServices/FindCourse.asmx/AddItemToShoppingCart",
				    data: $.arrayToString(data),
				    success: function (msg) {
				        document.location = "/Pages/Store/Cart.aspx";
				    }
				}
			);
}

        function waitlistSection(sID) 
		{	// used on SectionInfo.ascx
            var data = 
			{
                sectionID: sID
            };

            ejungle.ajax
			(
				{
					url:  "/WebServices/FindCourse.asmx/WaitlistSection",
	                data: $.arrayToString(data),
		            success: function(msg) 
					{
					    // document.location = "/Pages/Account/MyCoursesAndPrograms.aspx?page=classes";
                        // CES: 10/14/11 instead of going to my courses, take student to wait list confirmation page
					    document.location = "/Pages/Store/Checkout/ConfirmationWaitList.aspx";
					}
				}
			);
        }

		function getOptionalFees()
		{	// used on SectionInfo.ascx
            // Creates the XML for the Optional fees ...
			// If this is changed, code must also be changed for the Express Registration control.
            var optfees		= "<optionalFees>";
            $(".optional-fee-table input:checked").each
			(
				function() 
				{
					var $this	= $(this);
					optfees		+= "<fee amount='" + $this.attr("amount") + "' feeId='" + $this.attr("feeID") + "' label='" + $this.attr("label") + "' />";
				}
			);
            optfees				+= "</optionalFees>";
			return optfees;
		}

		function acKeyUp(ctl)
		{	// used on SectionInfo.ascx
			// ctl is sent so its id can be parsed; iNo is the index number of the ExpressRegistration form.
			// parse the control's id to find the name of the associated submit link
			var idxOf		= ctl.id.indexOf("approvalCodeTextbox");
			firstPart		= ctl.id.substring(0, idxOf);
			var idxLast		= ctl.id.indexOf("_", idxOf + 1);
			var iNo			= ctl.id.substring(idxLast	+ 1);
			var full		= firstPart + "ApprovalCodeSubmit_" + iNo;
			var theLink		= document.getElementById(full);

			$(".approval-code-error" + iNo).hide();

			if (ctl.value.length > 0)
			{
				$(theLink).show();
			}
			else
			{
				$(theLink).hide();
			}
		}

		function dcKeyUp(ctl)
		{	// used on SectionInfo.ascx
			// ctl is sent so its id can be parsed; iNo is the index number of the ExpressRegistration form.
			// parse the control's id to find the name of the associated submit link
			var idxOf		= ctl.id.indexOf("discountCodeTextbox");
			firstPart		= ctl.id.substring(0, idxOf);
			var idxLast		= ctl.id.indexOf("_", idxOf + 1);
			var iNo			= ctl.id.substring(idxLast + 1);
			var full		= firstPart + "DiscountCodeSubmit_" + iNo;
			var theLink		= document.getElementById(full);

			$(".discount-code-error"	+ iNo).hide();
			$(".discount-code-success"	+ iNo).hide();

			if (ctl.value.length > 0)
			{
				$(theLink).show();
			}
			else
			{
				$(theLink).hide();
			}
		}

		function acClick(ctl)
		{	// used on SectionInfo.ascx	
			// ctl is sent so its id can be parsed; iNo is the index number of the ExpressRegistration form.
			// handles approval code submit clicks
			var idxOf		= ctl.id.indexOf("ApprovalCodeSubmit");
			var firstPart	= ctl.id.substring(0, idxOf);
			var idxLast		= ctl.id.indexOf("_", idxOf + 1);
			var iNo			= ctl.id.substring(idxLast + 1);
			var full		= firstPart + "approvalCodeTextbox_" + iNo;
			var theBox		= document.getElementById(full);
			var btn			= $(".enroll-btn-row");
			var code		= theBox.value;
			var sectionId = $(".sectionId-value" + iNo).val();
            var schNumber = $(".section-number");

			 $(".approval-code-error" + iNo).hide();
			ejungle.runtime.ajax.validateApprovalCode(sectionId, code, function(msg) 
			{
				var result	= msg.d;
				if (result == "true") 
				{
					btn.show();
					$(".approval-code-input" + iNo).hide();
                    //CES: 4/26/2011 Display Schedule Number when approval code is correct
					$(".section-number").css("display", "inline");
				} 
				else 
				{
					$(".approval-code-error" + iNo).show();
					btn.hide();
				}
			});
			return false;
		}

		function dcClick(ctl)
		{	// used on SectionInfo.ascx
			// ctl is sent so its id can be parsed; iNo is the index number of the ExpressRegistration form.
			// handles discount code submit clicks
			var idxOf		= ctl.id.indexOf("DiscountCodeSubmit");
			var firstPart	= ctl.id.substring(0, idxOf);
			var idxLast		= ctl.id.indexOf("_", idxOf + 1);
			var iNo			= ctl.id.substring(idxLast  + 1);
			var full		= firstPart + "discountCodeTextbox_" + iNo;	
			var theBox		= document.getElementById(full);
			var btn			= $(".enroll-btn-row");
			var code		= theBox.value;
			var sectionId	= $(".sectionId-value" + iNo).val();

			$(".discount-code-success"	+ iNo).hide();
			$(".discount-code-error"	+ iNo).hide();
			$(".discount-fee"			+ iNo).remove();

			ejungle.runtime.ajax.validateDiscountCode(sectionId, iNo, code, function(msg) 
			{
				var result	= msg.d;
				if (result.length > 0) 
				{
					var dest = $(".fees-table" + iNo + " tbody").length > 0 ? $(".fees-table" + iNo + " tbody") : $(".fees-table" + iNo);
					dest.append(result);
					$(".discount-code-input" + iNo).hide();
					$(".discount-fee input:radio:first").attr("checked", true);
					$(".discount-code-success" + iNo).show();
					//CES 4/23/2011: comment line below because register button is tied to approval code, not discount code
					//btn.show(); 
					

				} 
				else 
				{
				    $(".discount-code-error" + iNo).show();
				    //CES 4/23/2011: comment line below because register button is tied to approval code, not discount code
					//btn.hide();
				}
				//alert(result);
			});
			return false;
		}

		function clickFirstFee()
		{	// used on SectionInfo.ascx 
			// ensures the 1st fee's radio button is checked
			for (var iNo = 0; iNo < 12; iNo++)
			{
				var dest = $(".fees-table" + iNo + " tbody").length > 0 ? $(".fees-table" + iNo + " tbody") : $(".fees-table" + iNo);
				$(".discount-fee input:radio:first").attr("checked", true);
			}
		}

