var popup = {
    defaultWindowOptions : 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,',
    openWindow : function (targetLocation, width, height) {
        var _popupOptions = this.defaultWindowOptions;
        var windowWidth = 491;
        var windowHeight = 300;

        if (width != null) {
            windowWidth = width;
        }

        if (height != null) {
            windowHeight = height;
        }

        _popupOptions += "width="+windowWidth+",height="+windowHeight;
        return window.open(targetLocation, "popupWindow", _popupOptions);
    },
    openFullWindow : function (targetLocation) {
        window.open(targetLocation);
    },
    showExitPopup : true,
    openExitForm : function (event) {
        var popupPath = "/schools/";

        var popupParams = "?pop=true";

        var popupTarget = "preconvpop.cusa";
        var windowHeight = "362";
        var windowWidth = "525";
        var inquiryComplete = isInquiryComplete;

        var parsedPath = utility.parsePath(window.location.pathname);

        if (parsedPath != undefined && parsedPath != null && parsedPath != "") {
        	popupPath = parsedPath;
        }
        if (inquiryComplete) {
            popupTarget = "postconvpop.cusa";
            windowHeight = "550";
            windowWidth = "525";
        }

        var isSelectivelySuppressed = false;

        // popup suppression control
        popupService.isPopupSuppressed({async:false, callback:function(isPopupSuppressed){
            isSelectivelySuppressed = isPopupSuppressed;
          }
        });

        if ((isSelectivelySuppressed) || (!popup.showExitPopup) || (isInquiryFraud) || forcePopupSuppression) {
            utility.suppressEvent(event);
            return;
        }

        var tmpPop = popup.openWindow(popupPath+popupTarget+popupParams, windowWidth, windowHeight);
        try {
            tmpPop.blur();
        } catch (exception) {}
    },
    closeLocal : function () {
        var isLocal = false;
        try {
            isLocal = window.opener.document.location.href.match(/\.cusa$/);
        } catch (exception){}

        if (isLocal) {
            self.close();
        } else {
            try {
                self.opener.blur();
            } catch (exception) {}
            self.focus();
        }
    }
};

var hover = {
    openHover : function (callingElement, providerId) {
        if (document.getElementById("hoverPopup") != null) {
            this.closeHover();
        }

        var distanceText = "";
        var providerDescription = "";
        var tmpDistances = new Array();
        try {
            for (key in campusDistance.parentProvider) {
                if (campusDistance.parentProvider[key].id == providerId) {
                    tmpDistances.push(campusDistance.parentProvider[key]);
                }
            }

            //Sort By Distance
            var finalDistances = new Array();
            for (key in tmpDistances) {
                for (var i=0; i<= tmpDistances.length; i++) {
                    if (finalDistances[i] == null) {
                        finalDistances[i] = tmpDistances[key];
                        break;
                    } else if (finalDistances[i].childProvider.distance
                        > tmpDistances[key].childProvider.distance) {
                            finalDistances.splice(i, 0, tmpDistances[key]);
                            break;
                    }
                }
            }

            for (key in finalDistances) {
                distanceText += "<div class='learnMoreHeader'>"+finalDistances[key].childProvider.name+"</div><em>"+
                    finalDistances[key].childProvider.distance+" miles from "+campusDistance.zipCode+"</em><br/>"+
                    campusAddress.parentProvider[finalDistances[key].childProvider.id].address1+" "+
                    campusAddress.parentProvider[finalDistances[key].childProvider.id].address2+"<br/>"+
                    campusAddress.parentProvider[finalDistances[key].childProvider.id].city+", "+
                    campusAddress.parentProvider[finalDistances[key].childProvider.id].state+" "+
                    campusAddress.parentProvider[finalDistances[key].childProvider.id].zip+"<br/><br/>";
            }
        } catch(ex){}

        for (key in descriptionList) {
            try {
                for (key2 in descriptionList[key]) {
                    if (descriptionList[key][key2].blurb == descriptionList[key][providerId].blurb) {
                        providerDescription = descriptionList[key][providerId].blurb;
                        break;
                    }
                }
                if (providerDescription.length > 0) {
                    break;
                }
            } catch (ex) {}
        }

        var newDiv = document.createElement("div");
        newDiv.id = "hoverPopup";
        newDiv.innerHTML = "<span class='hoverHeader'><div class='hoverClose' onclick='hover.closeHover();cursor.reset();'"+
                            " onmouseover='cursor.pointer();' onmouseout='cursor.reset();'></div><div class='hoverLabel'>"+
                            callingElement.firstChild.nodeValue+"<hr class='hoverRule'/></div></span>";
        newDiv.innerHTML += "<div class='learnMoreContent'>"+providerDescription+"<br/><br/>"+distanceText+"</div>";
        newDiv.innerHTML += "<div class='pageDebugInfo'>(P:"+providerId+") </div>";
        newDiv.style.zIndex = "10000";

        var currentElement = callingElement;
        var offset = new Object();
        var topOffset = 0;

        try {
            do {
                offset = this.getOffsetValues(currentElement);
                topOffset += parseInt(offset.top);
                currentElement = currentElement.offsetParent;

            } while (currentElement.offsetParent.tagName != "BODY");
        } catch (exception) { //IE 7 does not see body tag as offsetParent
        }

        newDiv.style.top = topOffset+"px";
        document.getElementById("pageContainer").appendChild(newDiv);
    },
    closeHover : function () {
        document.getElementById("hoverPopup").parentNode.removeChild(document.getElementById("hoverPopup"));
    },
    wait : function (msecs) {
        var date = new Date();
        var now  = null;

        do {
            now = new Date();
        }
        while (now - date < msecs);
    },
    getOffsetValues : function (element) {
        var offset = new Object();
        offset.top = element.offsetTop;
        offset.left = element.offsetLeft;
        return offset;
    }
};

var cursor = {
    reset : function () {
        document.body.style.cursor = 'default';
    },
    pointer : function () {
        document.body.style.cursor = 'pointer';
    }
};

var programOptions = {
    init : function () {
		for (key in parentProviderList) {
			if(document.getElementById("Provider"+parentProviderList[key].id)){
				this.update(document.getElementById("Provider"+parentProviderList[key].id));
			}
        }
    },
    update : function (programProvider) {
        var childProviderId  = programProvider.value;
        var parentProviderId = programProvider.id.replace(/Provider(.*)/,"$1");
        parentProviderId = parentProviderId.replace(/campusSchoolCampusMap\[(.*)\]$/,"$1");
        var programSelect = document.getElementById("Programs"+parentProviderId);
        if (programSelect == null) {
            programSelect = document.getElementById("campusSchoolProgramMap["+parentProviderId+"]");
        }
        var programList = _global['cP'+childProviderId].programs;
        var highestRankProgramId = document.getElementById("highestRankProgramId");
        if (highestRankProgramId == null) {
            this.renderOptions(programList, programSelect, parentProviderId);
        } else {
            this.renderOptionsWithSelected(programList, programSelect, parentProviderId, highestRankProgramId);
        }
    },
    renderOptions : function (programList, programSelect, parentProviderId) {
        var tmpOptionIndex = 0;
        var tmpOption = programSelect.options[0];
        programSelect.options.length = 0;
        programSelect.options[0] = tmpOption;

        var selectedProdIds = new Array();
        try {
        for (key in popularCampusProgramIds) {

                  selectedProdIds.push(key);

        }
        } catch (exception){}
        for (key in programList) {
            tmpOptionIndex = (parseInt(key) + 1);
            programSelect.options[tmpOptionIndex] = new Option(programList[key].name, programList[key].id);
            try {

	           for (key2 in selectedProdIds) {

	            	if (selectedProdIds[key2] == programList[key].id) {

	                    programSelect.options[tmpOptionIndex].selected = true;

	                }


	            }

            } catch (exception) {}

        }
    },
    renderOptionsWithSelected : function (programList, programSelect, parentProviderId, highestRankProgramId) {
        var tmpOptionIndex = 0;
        var tmpOption = programSelect.options[0];
        programSelect.options.length = 0;
        programSelect.options[0] = tmpOption;

        for (key in programList) {
            tmpOptionIndex = (parseInt(key) + 1);
            programSelect.options[tmpOptionIndex] = new Option(programList[key].name, programList[key].id);

            try {
                if (highestRankProgramId.value == programList[key].id) {
                    programSelect.options[tmpOptionIndex].selected = true;
                }
            } catch (exception) {}

        }
    },
    populateSelectedPrograms : function () {
        var allSelectElements = document.getElementsByTagName("select");
        var allProgramSelectElements = new Array();
        var userSelectedPrograms = new Array();

        //get all select program option inputs
        for (key in allSelectElements) {
            try {
                if (/^Programs/.test(allSelectElements[key].id)) {
                    allProgramSelectElements.push(allSelectElements[key]);
                }
            } catch (exception){}
        }

        //add any user selected value to the programSelected list
        for (key in allProgramSelectElements) {
            if (allProgramSelectElements[key].selectedIndex != 0) {
                userSelectedPrograms.push(allProgramSelectElements[key].value);
            }
        }

        var hiddenProgramSelectionField = document.getElementById("selectedPrograms");
        for (key in userSelectedPrograms) {
            if (key != 0) {
                hiddenProgramSelectionField.value += ","+userSelectedPrograms[key];
            } else {
                hiddenProgramSelectionField.value += userSelectedPrograms[key];
            }
        }
    },
    selectedUpsellPrograms : new Array(),
    updateQuestions : function (select) {
        var providerName = select.name;
        var providerId = providerName.match(/\[(.*)\]$/)[1];

        programOptions.clearPreviousQuestions(providerId);
        for (i=0; i < upsellQuestionList.length; i++) {
            if (upsellQuestionList[i].id == select.value) {
                //add program to selected list
                var tempProvider = new cusaChildProvider(providerId, providerName);
                tempProvider.programs.push(select.value);
                programOptions.selectedUpsellPrograms.push(tempProvider);
            }
        }

        programOptions.renderQuestions();
    },
    clearPreviousQuestions : function (providerId) {
        var toDelete = new Array();
        for (i=0; i < programOptions.selectedUpsellPrograms.length; i++) {
            if (programOptions.selectedUpsellPrograms[i].id == providerId) {
                toDelete.push(i);
            }
        }

        var spliceOffset = 0;
        for (key in toDelete) {
            programOptions.selectedUpsellPrograms.splice((toDelete[key - spliceOffset]), 1);
            spliceOffset++;
        }
    },
    renderQuestions : function () {
        var dynQuestions = document.getElementById("dynamicQuestions");
        dynQuestions.innerHTML = "";
        var renderedQuestions = new Array();

        for (key in programOptions.selectedUpsellPrograms) {
            var programId = programOptions.selectedUpsellPrograms[key].programs[0];
            for (key2 in upsellQuestionList) {
                if (upsellQuestionList[key2].id == programId) {
                    for (key3 in upsellQuestionList[key2].questions) {
                        var tempQuestion = upsellQuestionList[key2].questions[key3];
                        var isDuplicateQuestion = false;
                        for (key4 in renderedQuestions) {
                            if (renderedQuestions[key4] == tempQuestion.id) {
                                isDuplicateQuestion = true;
                                break;
                            }
                        }

                        if (!isDuplicateQuestion) {
                            //create div with style class additionalQuestionRow
                            var parentDiv = document.createElement("div");
                            parentDiv.className = "additionalQuestionRow";

                            //create div inside parent div to hold question
                            var leftDiv = document.createElement("div");
                            leftDiv.className = "leftColumn";
                            leftDiv.innerHTML = tempQuestion.description;
                            parentDiv.appendChild(leftDiv);

                            //create div inside parent div to hold answers
                            var rightDiv = document.createElement("div");
                            rightDiv.className = "rightColumn inlineSelectQuestion";

							var hiddenInput = document.createElement("input");
							hiddenInput.value = tempQuestion.id;
							hiddenInput.type = "hidden";
							hiddenInput.name = "selectQuestionsIds";

							//create text input for textarea questions
							if(upsellQuestionList[key2].questions[key3].type == 'VAR_ANSWER'){
                            var select = document.createElement("input");
                            var renderSelectOption = false;
                            select.className = "extraLargeSelect";
                            select.name = "answersMap["+tempQuestion.id+"]";
							select.type = "text";
							}
							//all others use a select form element
							else {
                            var select = document.createElement("select");
                            var renderSelectOption = true;
                            select.className = "extraLargeSelect";
                            select.name = "answersMap["+tempQuestion.id+"]";
							}
                            for (key5 in tempQuestion.answerChoices) {
                                var tempAnswer = tempQuestion.answerChoices[key5];
                                var option = document.createElement("option");

                                if (tempQuestion.type == "AGE") {
                                    option.value = tempAnswer.name;
                                } else {
                                    option.value = tempAnswer.bindId+","+tempQuestion.id;
                                }

                                option.selected = tempAnswer.isDefault;
                                option.innerHTML = tempAnswer.name;
                                select.appendChild(option);

                                if (tempAnswer.isDefault) {
                                    renderSelectOption = false;
                                }

                            }

                            if (renderSelectOption) {
                                var option = new Option("---Select---", "");
                                option.selected = true;

                                try {
                                    select.add(option, select.options[0]);
                                } catch (exception) { //IE workaround
                                    select.add(option, 0);
                                }
                            }

							rightDiv.appendChild(hiddenInput);
                            rightDiv.appendChild(select);
                            parentDiv.appendChild(rightDiv);
                            dynQuestions.appendChild(parentDiv);
                            renderedQuestions.push(tempQuestion.id);
                        }
                    }
                    break;
                }
            }

        }
    }
};

var ajax = {
    getRequest : function () {
        var _initRequest = null;
        try {
            _initRequest = new XMLHttpRequest();
        } catch (exception) {
            try {
                _initRequest = new ActiveXObject('Msxml2.XMLHTTP');
            } catch (exception) {
                try {
                    _initRequest = new ActiveXObject('Microsoft.XMLHTTP');
                } catch (exception) {}
            }
        }

        return _initRequest;
    }
};

var utility = {
    suppressEvent : function (event) {
        if (typeof stopDefaultAction != "undefined") {
            stopDefaultAction(event);
        }

        if (event && event.preventDefault) {
            event.preventDefault();
        }
    },
    autoTab : function (event) {
        var hField = event.target;
        if (!hField) { //IE specific
            hField = event.srcElement;
        }

        // Automatically focuses the next form field if you reach the maxlength of a text input while typing.
        if ("0,8,9,16,17,18,38,39,40,46".indexOf(event.keyCode.toString()) != -1) {
            return;
        }

        if (hField.value.length < utility.getInteger(hField.getAttribute("maxlength"))) {
            return;
        }
        var form = hField.form;
        try {
            for (var i = 0; i < form.elements.length; i++) {
                if ((hField == form.elements[i]) && (i < form.elements.length - 1)) {
                    form.elements[i + 1].focus();
                    return;
                }
            }
        } catch(e) {
            try {
                var err = new Object();
                err.errorLocation = "autoTab";
                err.functionParamField = hField.name;
                err.error = e;
                lmbUtil.log(err);
            } catch(le) {}
        }
    },
    getInteger : function (vNum) {
        vNum = utility.getIntegerString(vNum.toString());
        if (vNum == "") {
            vNum = 0;
        }
        return Number(vNum);
    },
    getIntegerString : function (strIn) {
        return strIn.replace(/[^0-9]/g, "");
    },

    parsePath : function (path) {

    	return path.replace(/(\/.*?\/).*/, "$1")

    }
};

var pages = {
    page1 : {
        isInternational : false,
        redirectInternational : function (error) {
            var form = document.forms[0];
            var event = window.event;

            if (!error.first) {
                utility.suppressEvent(event);
                return false;
            }

            //handle Maine specific validation message to show without the international redirection box
            if (error.errorMessage != "We're sorry, but according to Maine law we are unable to collect information from minors. We suggest you contact schools directly to continue your search."){

                var response = confirm(error.errorMessage+" Click OK to return to the form.\n"+
                                       "Not residing in the U.S.? Click Cancel to see our International Programs.");
                if (!response) {
                    this.isInternational = true;
                    eventLogger.logEvent("EVENT_INTERNATIONAL");
                    lmbValidator.removeErrorListener("lmbValidationErrorDisplayer", lmbValidationErrorDisplayer.showFirstErrorAlertNoCSS);
    //                window.location = "http://www.classesusa.com/featuredschools/programs/featured_international.cap";
                    window.location = "/browse/?campusType=online&browseType=17";
                } else {
                    //suppress regular validation popup and re-enable submit button.
                    error.first = false;
                    $(form).find('input#submit')[0].disabled = false;
                }
            }
        }
    },
    suppressPopups : function () {
         popup.showExitPopup = false;
    },
    getTopPicks : function (command, inquiryId, topPickType, callbackFunction, baseURL, pageType) {
        if (inquiryId == '') {inquiryId='none';}
        var head = document.getElementsByTagName("head").item(0);
        var script = document.createElement("script");
        var remoteURL = baseURL+"?cmd="+command+"&inquiryId="+inquiryId+"&tpType="+topPickType+"&callback="+callbackFunction+"&pageType="+pageType;

        script.setAttribute("src", remoteURL);
        script.type = 'text/javascript';
        head.appendChild(script);
    }
};

var degreeLinks = {
    "pregrad" : [ {"href" : "featured_certificate.cap", "label" : "Certificates",
                        "postConvTrackingId" : 894839, "ocpTrackingId" : 894860},
                    {"href" : "featured_associate.cap", "label" : "Associate",
                        "postConvTrackingId" : 894840, "ocpTrackingId" : 894861},
                    {"href" : "featured_bachelor.cap", "label" : "Bachelor's",
                        "postConvTrackingId" : 894841, "ocpTrackingId" : 894862}
                ],
    "postgrad" : [ {"href" : "featured_certificate.cap", "label" : "Certificates",
                        "postConvTrackingId" : 894839, "ocpTrackingId" : 894860},
                    {"href" : "featured_bachelor.cap", "label" : "Bachelor's",
                        "postConvTrackingId" : 894841, "ocpTrackingId" : 894862},
                    {"href" : "featured_masters.cap", "label" : "Master's",
                        "postConvTrackingId" : 894842, "ocpTrackingId" : 894863},
                    {"href" : "featured_postgrad.cap", "label" : "Doctorate",
                        "postConvTrackingId" : 894843, "ocpTrackingId" : 894864}
                ]
};

var degrees = {
    "linkPath" : "http://www.classesusa.com/featuredschools/programs/",
    "trackingPath" : "/clickcount.cfm?id={token}",
    "getLinks" : function (inquiryId, highestLevelOfEducation, sourceId, linkTrackingType, pageType, serviceBaseUrl) {
        if (highestLevelOfEducation.length < 1) {
            highestLevelOfEducation = 2; //Default to HS
        }
        for (key in degrees.educationLevel) {
            if (degrees.educationLevel[key].id == highestLevelOfEducation) {
                for (key2 in degrees.educationLevel[key].links) {
                    var tempDiv = document.createElement("div");
                    tempDiv.className = "link";
                    var tempAnchor = document.createElement("a");
                    var tempTrackingPath = degrees.trackingPath;
                    tempTrackingPath = tempTrackingPath.replace(/\{token\}/, degrees.educationLevel[key].links[key2][linkTrackingType]);
                    tempAnchor.href = serviceBaseUrl + tempTrackingPath + "&LMBCode=" + sourceId + "&inquiryId=" + inquiryId +"&goto=" +degrees.linkPath+degrees.educationLevel[key].links[key2].href;
                    tempAnchor.innerHTML = degrees.educationLevel[key].links[key2].label;
                    tempAnchor.target = '_blank';

                    tempDiv.appendChild(tempAnchor);
                    document.getElementById("degrees").appendChild(tempDiv);
                }
                break;
            }
        }
    },
    "educationLevel" : [
        { "id" : 0,
            "links" : degreeLinks.pregrad,
            "label" : "Some High School"
        },
        { "id" : 1,
            "links" : degreeLinks.pregrad,
            "label" : "GED"
        },
        { "id" : 2,
            "links" : degreeLinks.pregrad,
            "label" : "High School"
        },
        { "id" : 3,
            "links" : degreeLinks.pregrad,
            "label" : "0-23 Credits"
        },
        { "id" : 4,
            "links" : degreeLinks.pregrad,
            "label" : "24-47 Credits"
        },
        { "id" : 5,
            "links" : degreeLinks.pregrad,
            "label" : "48+ Credits"
        },
        { "id" : 6,
            "links" : degreeLinks.pregrad,
            "label" : "Associate"
        },
        { "id" : 7,
            "links" : degreeLinks.postgrad,
            "label" : "Bachelor"
        },
        { "id" : 8,
            "links" : degreeLinks.postgrad,
            "label" : "Master's"
        },
        { "id" : 9,
            "links" : degreeLinks.postgrad,
            "label" : "Doctorate"
        }
    ]
};

var categories = {
    "campusPath" : "http://www.classesusa.com/schools/campus/",
    "onlinePath" : "http://www.classesusa.com/featuredschools/programs/",
    "trackingPath" : "/clickcount.cfm?id={token}",
    "setSelected" : function (categoryJSON) {
        categories.selected = categoryJSON;
    },
    "selected" : "",
        "0" : {
            "id" : 0,
            "rank" : 1,
            "label" : "Business",
            "onlineLink" : {
                "target" : "featured_business.cap",
                "postConvTrackingId" : 894845,
                "ocpTrackingId" : 894866
            },
            "campusLink" : {
                "target" : "business.html",
                "postConvTrackingId" : 894844,
                "ocpTrackingId" : 894865
            }
        },
        "1" : {
            "id" : 1,
            "rank" : 8,
            "label" : "Auto / Aero / Construction",
            "onlineLink" : {
                "target" : "",
                "postConvTrackingId" : "",
                "ocpTrackingId" : ""
            },
            "campusLink" : {
                "target" : "automotive.html",
                "postConvTrackingId" : 894846,
                "ocpTrackingId" : 894867
            }
        },
        "2" : {
            "id" : 2,
            "rank" : 4,
            "label" : "Criminal Justice / Legal / Paralegal",
            "onlineLink" : {
                "target" : "featured_criminal.cap",
                "postConvTrackingId" : 894848,
                "ocpTrackingId" : 894869
            },
            "campusLink" : {
                "target" : "lawjustice.html",
                "postConvTrackingId" : 894847,
                "ocpTrackingId" : 894868
            }
        },
        "3" : {
            "id" : 3,
            "rank" : 9,
            "label" : "Culinary Arts",
            "onlineLink" : {
                "target" : "",
                "postConvTrackingId" : "",
                "ocpTrackingId" : ""
            },
            "campusLink" : {
                "target" : "culinaryarts.html",
                "postConvTrackingId" : 894849,
                "ocpTrackingId" : 894870
            }
        },
        "4" : {
            "id" : 4,
            "rank" : 7,
            "label" : "Education",
            "onlineLink" : {
                "target" : "featured_eddegrees.cap",
                "postConvTrackingId" : 894851,
                "ocpTrackingId" : 894872
            },
            "campusLink" : {
                "target" : "education.html",
                "postConvTrackingId" : 894850,
                "ocpTrackingId" : 894871
            }
        },
        "5" : {
            "id" : 5,
            "rank" : 5,
            "label" : "IT / Science / Engineering",
            "onlineLink" : {
                "target" : "featured_it.cap",
                "postConvTrackingId" : 894853,
                "ocpTrackingId" : 894874
            },
            "campusLink" : {
                "target" : "it.html",
                "postConvTrackingId" : 894852,
                "ocpTrackingId" : 894873
            }
        },
        "6" : {
            "id" : 6,
            "rank" : 3,
            "label" : "Healthcare",
            "onlineLink" : {
                "target" : "featured_health.cap",
                "postConvTrackingId" : 894855,
                "ocpTrackingId" : 894876
            },
            "campusLink" : {
                "target" : "healthcare.html",
                "postConvTrackingId" : 894854,
                "ocpTrackingId" : 894875
            }
        },
        "7" : {
            "id" : 7,
            "rank" : 6,
            "label" : "Web / Graphic Design / Fashion",
            "onlineLink" : {
                "target" : "featured_web.cap",
                "postConvTrackingId" : 894857,
                "ocpTrackingId" : 894878
            },
            "campusLink" : {
                "target" : "design.html",
                "postConvTrackingId" : 894856,
                "ocpTrackingId" : 894877
            }
        },
        "8" : {
            "id" : 8,
            "rank" : 2,
            "label" : "Nursing",
            "onlineLink" : {
                "target" : "featured_health.cap",
                "postConvTrackingId" : 894855,
                "ocpTrackingId" : 894876
            },
            "campusLink" : {
                "target" : "nursing.html",
                "postConvTrackingId" : 894854,
                "ocpTrackingId" : 894875
            }
        }
};

var subjects = {
    renderedLinkCount : 0,
    getLinks : function ( categories, inquiryId, schoolType, sourceId, linkTrackingType, pageType, serviceBaseUrl) {
        if (schoolType.length < 1) {
            schoolType = 0; //Default to all school types.
        }
        for (key in categories.selected) {
            var tempCat = categories.selected[key];

            if ((schoolType == 0) || (schoolType == 1)) {
                if ((categories[tempCat.id].onlineLink.target.length > 0) && (subjects.renderedLinkCount < 4)) {
                    var tempDiv = document.createElement("div");
                    tempDiv.className = "subjectsLink";
                    var tempAnchor = document.createElement("a");
                    var tempTrackingPath = categories.trackingPath;
                    tempTrackingPath = tempTrackingPath.replace(/\{token\}/, categories[tempCat.id].onlineLink[linkTrackingType]);
                    tempAnchor.href = serviceBaseUrl + tempTrackingPath + "&LMBCode=" + sourceId +  "&inquiryId=" + inquiryId + "&goto=" + categories.onlinePath+categories[tempCat.id].onlineLink.target;
                    tempAnchor.innerHTML = "Online "+tempCat.name+" Programs";
                    tempAnchor.target = '_blank';

                    tempDiv.appendChild(tempAnchor);
                    document.getElementById("subjects").appendChild(tempDiv);
                    subjects.renderedLinkCount++;
                }
            }

            if ((schoolType == 0) || (schoolType == 2)) {
                if ((categories[tempCat.id].campusLink.target.length > 0) && (subjects.renderedLinkCount < 4)) {
                    var tempDiv = document.createElement("div");
                    tempDiv.className = "subjectsLink";
                    var tempAnchor = document.createElement("a");
                    var tempTrackingPath = categories.trackingPath;
                    tempTrackingPath = tempTrackingPath.replace(/\{token\}/, categories[tempCat.id].campusLink[linkTrackingType]);
                    tempAnchor.href = serviceBaseUrl + tempTrackingPath + "&LMBCode=" + sourceId + "&inquiryId=" + inquiryId + "&goto=" + categories.campusPath+categories[tempCat.id].campusLink.target;
                    tempAnchor.innerHTML = "Campus "+tempCat.name+" Programs";
                    tempAnchor.target = '_blank';

                    tempDiv.appendChild(tempAnchor);
                    document.getElementById("subjects").appendChild(tempDiv);
                    subjects.renderedLinkCount++;
                }
            }
        }

        if (subjects.renderedLinkCount < 6) {
            var additionalLinks = new Array();
            for (i=0; i<7; i++) {
                var programSelected = false;
                for (key2 in categories.selected) {
                    if (i == categories.selected[key2].id) {
                        programSelected = true;
                        break;
                    }
                }
                if (!programSelected) {
                    additionalLinks.push(categories[i]);
                }
            }

            var currentMaxRank = 1;
            while (subjects.renderedLinkCount < 4) {
                for (key2 in additionalLinks) {
                    if (additionalLinks[key2].rank == currentMaxRank) {
                        if (((schoolType == 0) || (schoolType == 1)) && (additionalLinks[key2].onlineLink.target.length > 0) && (subjects.renderedLinkCount < 4)) {
                            var tempDiv = document.createElement("div");
                            tempDiv.className = "subjectsLink";
                            var tempAnchor = document.createElement("a");
                            var tempTrackingPath = categories.trackingPath;
                            tempTrackingPath = tempTrackingPath.replace(/\{token\}/, additionalLinks[key2].onlineLink[linkTrackingType]);
                            tempAnchor.href = serviceBaseUrl + tempTrackingPath + "&LMBCode=" + sourceId + "&inquiryId=" + inquiryId + "&goto=" + categories.onlinePath+additionalLinks[key2].onlineLink.target;
                            tempAnchor.innerHTML = "Online "+additionalLinks[key2].label+" Programs";
                            tempAnchor.target = '_blank';

                            tempDiv.appendChild(tempAnchor);
                            document.getElementById("subjects").appendChild(tempDiv);
                            subjects.renderedLinkCount++;
                        }

                        if (((schoolType == 0) || (schoolType == 2)) && (additionalLinks[key2].campusLink.target.length > 0) && (subjects.renderedLinkCount < 4)) {
                            var tempDiv = document.createElement("div");
                            tempDiv.className = "subjectsLink";
                            var tempAnchor = document.createElement("a");
                            var tempTrackingPath = categories.trackingPath;
                            tempTrackingPath = tempTrackingPath.replace(/\{token\}/, additionalLinks[key2].campusLink[linkTrackingType]);
                            tempAnchor.href = serviceBaseUrl + tempTrackingPath + "&LMBCode=" + sourceId + "&inquiryId=" + inquiryId + "&goto=" + categories.campusPath+additionalLinks[key2].campusLink.target;
                            tempAnchor.innerHTML = "Campus "+additionalLinks[key2].label+" Programs";
                            tempAnchor.target = '_blank';

                            tempDiv.appendChild(tempAnchor);
                            document.getElementById("subjects").appendChild(tempDiv);
                            subjects.renderedLinkCount++;
                        }
                        break;
                    }
                }
                currentMaxRank++;
            }
        }
    }
};

var links = {
    addOnClickEvent : function (element, event) {
        //search within element for any links and attach onclick event
        var anchors = links.findNodeByNodeName(element, "A");
        for (key in anchors) {
            anchors[key].onclick = event;
        }

    },
    collectedNodes : new Array(),
    findNodeByNodeName : function (element, nodeName) {
        for (key in element.childNodes) {
            if (element.childNodes[key].nodeType == 1) {
                if (element.childNodes[key].nodeName == nodeName) {
                    links.collectedNodes.push(element.childNodes[key]);
                } else if (element.childNodes[key].childNodes && (element.childNodes[key].childNodes.length > 0)) {
                    links.findNodeByNodeName(element.childNodes[key], nodeName);
                }
            }

        }
        return links.collectedNodes;
    }
};

//Provider Objects
function cusaProgram(id, name) {
    try {
        this.id = id;
        this.name = name;
        this.questions = new Array();
    } catch (exception) {}
}

function cusaQuestion(id, name) {
    try {
        this.id = id;
        this.name = name;
        this.answerChoices = new Array();
        this.type = "";
    } catch (exception) {}
}

function cusaAnswer(id, name) {
    try {
        this.id = id;
        this.name = name;
        this.isDefault = false;
        this.description = "";
        this.bindId = "";
    } catch (exception) {}
}

function cusaChildProvider(id, name) {
    this.programs = new Array();
    try {
        this.id = id;
        this.name = name;
    } catch (exception) {}
}

function cusaParentProvider(id, name) {
    try {
        this.id = id;
        this.name = name;
        this.childProviders = new Array();
    } catch (exception) {}
}

cusaParentProvider.prototype.addChildProvider =
    function (childProvider) {
        try {
            this.childProviders[childProvider.id] = childProvider;
        } catch (exception) {}
    }


var parentProviderList = new Array();
var upsellQuestionList = new Array();
var descriptionList = new Array();
