/******************************/
/*** ProfileRetriever Class ***/
/******************************/

var ProfileRetriever = AjaxCpx.extend({

	MAX_TOTAL_RESULTS : 10,
	KEY_CODE_ARROW_UP: 38,
	KEY_CODE_ARROW_DOWN: 40,
	KEY_CODE_ENTER : 13,

	moduleID : '',
	phrase : '',

	phraseElem : null,
	collegeSearchModuleElem : null,
	collegeSearchBoxElem : null,
	autoSuggestTargetElem : null,

	resultsSet : null,
	results : null,
	numCurrentResults : 0, // the total number of results returned
	numTotalResults : 0, // would be the total number of results, but there is a limit on the query, so this is unused
	hasAdditionalResults : false,
	resultsHTML : null,
	resultLinkURL : null, // default link to go to for each result link (modified for college
	suggestResultAnchor: null,
	resultsListPageURL : null,
	resultMeritAidProgramsClass : null,

	invisibleUnderCssDropdown : null, // set this class on elements to hide them when the dropdown opens
	schoolNotListedLink : false,
	allowShowAllSchoolsLink : true,
	allowSubmitOnEnter : true,
	showAllSchoolsInLightbox : false,
	cursorIndex : -1,
	isInCursorMode : false,

	isLastActiveModule : false,

	lastRunAt : new Date(),

	initialize : function (url, options) {

		global.trace("Begin initialize");
		global.profileRetrieverObjects.include(this);

		this.parent(url, options);

		this.moduleID = options.moduleID;
		this.phraseElem = $('phrase_' + this.moduleID);
		this.collegeSearchModuleElem = $('collegeSearchBox_' + this.moduleID);
		this.collegeSearchBoxElem = $('collegeSearchBox_' + this.moduleID);
		this.autoSuggestTargetElem = $('autoSuggestTarget_' + this.moduleID);

		this.resultLinkURL = options.resultLinkURL;
		this.suggestResultAnchor = options.suggestResultAnchor;
		this.resultsListPageURL = options.resultsListPageURL;
 		this.resultMeritAidProgramsClass = (this.resultsListPageURL.contains('/page/suggest/collegeSearchResults.jsp') ? 'resultMeritAidPrograms' : 'jsHide'); // Only show the resultMeritAidPrograms icon ($) for dropdowns that send you to a merit aid results page

		window.addEvent('domready', function() {

			// cache collection of elements to hide when the dropdown opens
			this.invisibleUnderCssDropdown = $$('.invisibleUnderCssDropdown');

			// add timestamp to autoSuggest textbox to prevent browser's autoSuggest feature. Will be removed before submitting the form
			this.phraseElem.name = 'phrase' + new Date().getTime();

			// add events to college name search box (must add to form in ie when this is embedded in a form, such as on basic/preferences)
			if (this.collegeSearchBoxElem && window.ie) { // non-8 ie

				this.collegeSearchBoxElem.addEvent('keyup', this.onKeyup.bind(this));
//				this.collegeSearchBoxElem.addEvent('keyup', function() {
//					global.trace('collegeSearchBoxElem.keyup - this.id: ' + this.id);
//				});

			} else {
				this.phraseElem.addEvent('keyup', this.onKeyup.bind(this));
			}

			this.phraseElem.addEvent('focus', function() {

				global.profileRetrieverObjects.each(function(profileRetrieverObject) {
					profileRetrieverObject.isLastActiveModule = false;
				});
				this.isLastActiveModule = true;

				this.retrieveResultSet();
				
			}.bind(this));

			this.phraseElem.addEvent('blur', function() {
				this.hideResults.delay(333, this);
			}.bind(this));

		}.bind(this));
	},

	/**
	 * If the phrase textbox has been changed and has > 1 chars, fires the ajax request and updates the lastRunAt time.
	 * A successful request results in onSuccess() being run.
	 */
	retrieveResultSet : function () {

		global.trace("Begin retrieveResultSet");

		// global.trace('retrieveResultSet this.MAX_TOTAL_RESULTS:' + this.MAX_TOTAL_RESULTS);

		// only get new results if the search string has changed, and if there are two or more characters entered
		if (this.phraseElem.value != this.phrase && this.phraseElem.value.length > 1) {

			if (new Date().getTime() - this.lastRunAt.getTime() > 10) { // ms to set timeout
				this.cancel();
			}

			this.phrase = this.phraseElem.value;
			this.options.data = {phrase : this.phrase};

			if (!this.running) {
				this.lastRunAt = new Date();
				// } else { // HACKKH: work in IE with network lag
				// 	this.cancel();
			}

			this.request();
		}
	},

	/**
	 * Update the results data from the ajax response. Generate the HTML and show the dropdown. Add events to the
	 * result links and to the showAllSchoolsLink. Checks to see if the text input has been updated again while
	 * the response was processing, and if so, attempts to retrieve a new result set.
	 */
	onSuccess : function () {

		global.trace("Begin onSuccess");

		// read resultSet
		this.resultSet = Json.evaluate(this.transport.responseText);
		this.results = this.resultSet.results;
		this.numCurrentResults = this.resultSet.numCurrentResults;
		this.numTotalResults = this.resultSet.numTotalResults;
		this.hasAdditionalResults = this.resultSet.hasAdditionalResults;

		// this.additionalResults = this.numCurrentResults - this.MAX_TOTAL_RESULTS;

		this.autoSuggestTargetElem.innerHTML = this.generateResultsHTML();

		$ES('a.resultLink', this.autoSuggestTargetElem).each(function(elem) {
			elem.addEvent('mouseover', this.resetCursorPosition.bind(this));
		}, this);
		this.showResults(); // needed in IE6 to hide SELECTs & flash the first time this first time the menu appears
		this.setResultOnClickEvents();

		// add event to show all schools link if appropriate
		if (this.hasAdditionalResults && this.allowShowAllSchoolsLink) {

			// a new link will have been created, so add the eventHandler
			$('showAllSchoolsLink_' + this.moduleID).addEvent('click', function () {
				global.trace('showAllSchoolsLink clicked');
				this.submitAsForm();
			}.bind(this));
		}

		// request again if the text field has changed since the last request was submitted (only one at a time is submitted)
		if (this.resultSet.phrase != this.phraseElem.value) {
			this.retrieveResultSet();
		}

	},

	onKeyup : function (e) {

		global.trace("Begin ProfileRetriever.onKeyup");

		var activeProfileRetrieverObject = this;

		if (window.ie8) {

			global.profileRetrieverObjects.each(function(profileRetrieverObject) {
				if (profileRetrieverObject.isLastActiveModule) {
					activeProfileRetrieverObject = profileRetrieverObject;
				}
			});

		}

		switch (e.keyCode) {

			case activeProfileRetrieverObject.KEY_CODE_ARROW_UP:

				if (activeProfileRetrieverObject.cursorIndex > -1 && $defined($('resultLink_' + activeProfileRetrieverObject.options.moduleID + '_' + activeProfileRetrieverObject.cursorIndex))) {
					$('resultLink_' + activeProfileRetrieverObject.options.moduleID + '_' + activeProfileRetrieverObject.cursorIndex).removeClass('jsHover');
					activeProfileRetrieverObject.cursorIndex--;

					if (activeProfileRetrieverObject.cursorIndex > -1 && $defined($('resultLink_' + activeProfileRetrieverObject.options.moduleID + '_' + activeProfileRetrieverObject.cursorIndex))) {
						$('resultLink_' + activeProfileRetrieverObject.options.moduleID + '_' + activeProfileRetrieverObject.cursorIndex).addClass('jsHover');
					}
				}

				activeProfileRetrieverObject.isInCursorMode = activeProfileRetrieverObject.cursorIndex > -1;
				break;

			case activeProfileRetrieverObject.KEY_CODE_ARROW_DOWN:

				var numResultsShown = Math.min(activeProfileRetrieverObject.numCurrentResults, activeProfileRetrieverObject.MAX_TOTAL_RESULTS);

				if (activeProfileRetrieverObject.cursorIndex < numResultsShown - 1) {

					if (activeProfileRetrieverObject.cursorIndex > -1 && $defined($('resultLink_' + activeProfileRetrieverObject.options.moduleID + '_' + activeProfileRetrieverObject.cursorIndex))) {
						$('resultLink_' + activeProfileRetrieverObject.options.moduleID + '_' + activeProfileRetrieverObject.cursorIndex).removeClass('jsHover');
					}

					activeProfileRetrieverObject.cursorIndex++;
					activeProfileRetrieverObject.isInCursorMode = activeProfileRetrieverObject.cursorIndex > -1;

					if ($defined($('resultLink_' + activeProfileRetrieverObject.options.moduleID + '_' + activeProfileRetrieverObject.cursorIndex))) {
						$('resultLink_' + activeProfileRetrieverObject.options.moduleID + '_' + activeProfileRetrieverObject.cursorIndex).addClass('jsHover');
					}
				}
				break;

			// NOTE: this might be performing a double-submit in FF (not IE7) because when Enter is pressed, this code is reached AND an onclick event is for some reason fired on the submit button
			case activeProfileRetrieverObject.KEY_CODE_ENTER:

				global.trace('ProfileRetriever.onKeyup: KEY_CODE_ENTER');

				activeProfileRetrieverObject.onKeyCodeEnter();

				break;

			default:

				activeProfileRetrieverObject.retrieveResultSet();

				break;

		}

		return false;
	},

	/**
	 * Runs when Enter is pressed when field is active (including when dropdown list is being traversed by up/down keypresses, which is an illusion and does not affect focus/mouseover, etc...
	 * Overridden by ProfileRetrieverList
	 */
	onKeyCodeEnter : function () {

		if (this.isInCursorMode) {
			this.phraseElem.value = this.results[this.cursorIndex].name;

			if ($defined($('resultLink_' + this.options.moduleID + '_' + this.cursorIndex))) {
				window.location = $('resultLink_' + this.options.moduleID + '_' + this.cursorIndex).href;
			}

		} else if (this.allowSubmitOnEnter){

			global.debug('ProfileRetriever.onKeyCodeEnter().submitAsForm()');

			this.submitAsForm();
		}

	},

	resetCursorPosition : function () {

		global.trace("Begin resetCursorPosition");

		if ($defined($('resultLink_' + this.options.moduleID + '_' + this.cursorIndex))) {
			$('resultLink_' + this.options.moduleID + '_' + this.cursorIndex).removeClass('jsHover');
		}
		this.isInCursorMode = false;
		this.cursorIndex = -1;
	},

	generateResultsHTML : function () {

		global.trace("Begin generateResultsHTML");

		var resultsHTML;
		//		var seeAllResultsHTML;

		resultsHTML = '<ul class="cssDropdown"><li><ul>';

		if (this.numCurrentResults > 0) {

			//			seeAllResultsHTML = '<p>Showing results 1 to ' + Math.min(this.numCurrentResults, 10) + ' of ' + this.numCurrentResults;
			//			seeAllResultsHTML += ':</p>';

			// prepare link for id= to be added inside of for loop (allows use of a url with other parameters already on the query string)
			var resultLinkURLReadyForParams;
			if (this.resultLinkURL.contains('?')) {
				resultLinkURLReadyForParams = this.resultLinkURL + '&';
			} else {
				resultLinkURLReadyForParams = this.resultLinkURL + '?';
			}

			for (var i = 0; i < this.results.length; i++) {

				// add id param to result links unless they are merely JS links

// REMOVEKH: 	var resultLinkURLWithParams = (this.resultLinkURL  == 'javascript:void(0)' ? this.resultLinkURL  : resultLinkURLReadyForParams + 'id=' + this.results[i].unitID);
//				'" href="' + resultLinkURLWithParams +
//				'" class="resultLink" onclick="return false;">' + this.results[i].name +

				// Note: this results in a link like: javascript:void(0)?id=12345, but that seems to be working fine
				resultsHTML += '<li><a id="resultLink_' + this.options.moduleID + '_' + i +
							   '" href="' + resultLinkURLReadyForParams +
							   'id=' + this.results[i].unitID + '&collegeID=' +  this.results[i].unitID +
							   (this.options.suggestResultAnchor ? ('#' + this.options.suggestResultAnchor) : '') +
							   '" class="resultLink" onclick="return false;"><span class="collegeName">' + this.results[i].name +
							   '</span><br /><span class="' + this.resultMeritAidProgramsClass +
							   '">' + this.results[i].numMeritAidPrograms +
							   '</span><span class="resultLocation">' + this.results[i].city +
							   ', ' + this.results[i].state +
							   '</span></a></li>';
			}

			if (this.hasAdditionalResults && this.allowShowAllSchoolsLink) {
				resultsHTML += '<li><a class="resultFooterLink" id="showAllSchoolsLink_' + this.moduleID + '" ' +
				' href="javascript:void(0)" onclick="return false">Show me all matching schools</a></li>';
			}


		} else {
			resultsHTML += '<li class="noResultsMsg">There are no schools that match what you\'ve entered.</li>';

		}

		if (this.schoolNotListedLink) {
			resultsHTML += '<li><a class="resultFooterLink"href="javascript:void(0)" onclick="profileRetriever_' + this.options.moduleID + '.doSchoolNotListed();return false;">I can\'t find my school</a>';
		}
		
		resultsHTML += '</ul></li></ul>';

		return resultsHTML;
	},

/**
 * Shows the results cssDropdown if the dropdown is not empty (which only occurs if nothing has been typed, in which case there is
 * at a minimum a "No results found" message).  Also hides flash videos, selects, and any other elements, as specified by the
 * .invisibleUnderCssDropdown selector.
 */
	showResults : function () {

		global.trace("Begin showResults");

		// since results are being updated here, reset the cursor to the dropdown
		this.resetCursorPosition();

		if (this.autoSuggestTargetElem.innerHTML != '') {

			this.autoSuggestTargetElem.removeClass('jsHide');

			if ($('flashTestimonialsArea')) {
				$('flashContentContainer').addClass('jsHide');
			}

			this.invisibleUnderCssDropdown.each(function (elem) {
				$(elem).addClass('jsInvisible');
			});
		}

	},

/**
 * Opposite of showResults
 */
	hideResults : function () {

		global.trace("Begin hideResults");

		this.resetCursorPosition();

		this.autoSuggestTargetElem.addClass('jsHide');

		if ($('flashTestimonialsArea')) {
			$('flashContentContainer').removeClass('jsHide');
		}
		this.invisibleUnderCssDropdown.each(function (elem) {
			$(elem).removeClass('jsInvisible');
		});
	},

/**
 * Sets the onclick event on each resultLink
 */
	setResultOnClickEvents : function () {

		global.trace("Begin setResultOnClickEvents");

		$ES('a.resultLink', this.autoSuggestTargetElem).each(function(x) {
			x.addEvent('click', function () {
				document.location = this.href;
			});
		}, this);
	},

/**
 * Submits the search as if it were a form GET
 */
	submitAsForm : function () {

		global.trace("Begin submitAsForm");

		//		var url = '/page/suggest/collegeSearchResults.jsp?';

		var url = this.resultsListPageURL;

		// remove timestamp from autoSuggest textbox before submitting the form
		this.phraseElem.name = 'phrase';

		$ES('input', this.collegeSearchModuleElem).each(function(x) {
			url += x.name + '=' + x.value + "&";
		});

		url = url.substring(0, url.length - 1);
		// strip trailing ampersand

		document.location = url;

	},

	doSchoolNotListed : function () {
		this.hideResults();
		$('inviteGCLink').removeClass('jsHide');
		new Animator().pulseElem($('inviteGCLink'));
		$('unitID').value = 0;
		if ($('hsID')) {
			$('hsID').value = 0;
		}
	}

});

/****************************************/
/***** ProfileRetrieverStatic Class *****/
/****************************************/

/**
 * College search dropdown that replaces itself with a static College Name and a Change link. Populates a unitID hidden field.
 */
var ProfileRetrieverStatic = ProfileRetriever.extend({

	ajaxResultsUrl : '/ajax/searchResultsAjax.jsp',
	isInputFocused : false,
	isHSSearch : false,

	initialize : function (url, options) {

		this.parent(url, options);

		this.allowShowAllSchoolsLink = true;
		this.allowSubmitOnEnter = false;

		if (this.options.isHSSearch) {
			this.isHSSearch = true;
			this.schoolNotListedLink = true;			
		}

	},

	setResultOnClickEvents : function () {

		$ES('a.resultLink', this.autoSuggestTargetElem).each(function(item) {
			var that = this;
			item.addEvent('click', function () {
				var unitID = getURLParam('collegeID', this.href); // used to look for id=; moving search module away from using just id=
				var itemTextHTML = this.innerHTML; // steal college name/location out of link HTML
				that.addStaticItem(unitID, itemTextHTML);
			});
		}, this);
	},

	addStaticItem : function (unitID, itemTextHTML) {

		this.collegeSearchBoxElem.addClass('jsHide');
		$('collegeNameText').removeClass('jsHide');
		$('collegeNameText').setHTML(itemTextHTML +
									 '<a href="#" id="collegeNameLink" onclick="profileRetriever_' + this.options.moduleID +
									 '.hideStaticCollegeName(); return false">Change</a>');
		$('collegeNameStatic').removeClass('jsHide');
		$('unitID').value = unitID; // get unitID off of url for the college page

		global.trace('ProfileRetrieverStatic.addStaticItem()');
		
		// for HS Lookup on Student Basic:
		if ($('hsID')) {
			$('hsID').value = unitID;
			retrieveGCs($('hsID').value);
			$('phraseLabel_' + this.moduleID).addClass('jsHide');
		}

		return false;
	},

	hideStaticCollegeName : function () {

		$('collegeNameStatic').addClass('jsHide');
		this.collegeSearchBoxElem.removeClass('jsHide');
		$('unitID').value = ''; // reset unitID because one is no longer "selected"

		// for HS Lookup on Student Basic:
		if ($('hsID')) {
			$('hsID').value = ''; // reset hsID because one is no longer "selected"
			$('phraseLabel_' + this.moduleID).removeClass('jsHide');
		}

	},

	/**
	 * Override function. Runs when Enter is pressed when field is active (including when dropdown list is being traversed by up/down keypresses, which is an illusion and does not affect focus/mouseover, etc...
	 */
	onKeyCodeEnter : function () {

		if (this.isInCursorMode) {

			var unitID = this.results[this.cursorIndex].unitID;
			var itemTextHTML = $('resultLink_' + this.options.moduleID + '_' + this.cursorIndex).innerHTML; // steal college name/location out of link HTML
			this.addStaticItem(unitID, itemTextHTML);

		} else if (this.allowSubmitOnEnter){

			global.debug('ProfileRetrieverStatic.onKeyCodeEnter().submitAsForm()');

			this.submitAsForm();
		}

		this.phraseElem.name = 'phrase' + new Date().getTime(); // change field name to prevent browser dropdown from appearing after enter is pressed

	},

	/**
	 * Override function. Opens search results in a lightbox.
	 */
	submitAsForm : function () {

		global.trace("Begin ProfileRetrieverStatic.submitAsForm");

		if (this.phraseElem.value.length > 3) {
			this.stickyWin = openAjaxStickyWin(this.ajaxResultsUrl +
											   '?phrase=' + this.phrase +
											   '&moduleID=' + this.options.moduleID +
											   '&isHSSearch=' + this.isHSSearch, // note: no c:url needed here
				'collegeSearchResultsTarget',
				false, 450, 400);
			this.phraseElem.fireEvent('blur'); // hide dropdown
		} else {
			$('searchModuleErrorMsg_' + this.options.moduleID).removeClass('jsHide'); // display message "Please begin typing..."
		}

		this.phraseElem.name = 'phrase' + new Date().getTime(); // change field name to prevent browser dropdown from appearing after enter is pressed

	}

});

/****************************************/
/****** ProfileRetrieverList Class ******/
/****************************************/

var ProfileRetrieverList = ProfileRetrieverStatic.extend({

	isParentCollege : false,
	blurDelayTime : 100,
	myCollegesElem : null,
	stickyWin : Class.empty(),
	disableEnclosingFormSubmit : false, // don't submit preferences/basics page when focused on the dropdown (also set to false when the submit button is pressed, just for good measure, since this should be fixed by the blur event anyway)

	initialize : function (url, options) {

		this.parent(url, options);

		this.isParentCollege = options.isParentCollege;

		// add empty container for list of colleges
		if (this.myCollegesElem == null) {

			this.myCollegesElem = new Element('ul');
			this.myCollegesElem.injectInside(this.collegeSearchBoxElem);

		}

		window.addEvent('domready', function () {

			if ($$('#myCollegesList li').length == 0) {
				$('myCollegesList').addClass('jsHide');
			}

			this.phraseElem.addEvent('focus', function () {
				this.disableEnclosingFormSubmit = true;
				global.trace('ProfileRetrieverList.initialize event: phrase.focused');
			}.bind(this));

			this.phraseElem.addEvent('blur', function () {
				global.trace('ProfileRetrieverList.initialize event: phrase.blurred');
				(function () {
					this.disableEnclosingFormSubmit = false;
					global.trace('ProfileRetrieverList.initialize event: phrase.blurDelayFinished');
				}.bind(this)).delay(this.blurDelayTime, this);
			}.bind(this));

			if ($('studentProfileSubmitButton')) { // this should not be necessary
				$('studentProfileSubmitButton').addEvent('mousedown', function () { // mousedown required to avoid behavior in FF where an onclick event is triggered on this button when the form is submitted (in any way)
					this.disableEnclosingFormSubmit = false;
				}.bind(this));
			}

		}.bind(this));

	},

	addStaticItem : function (unitID, itemTextHTML) {

		global.trace("Begin ProfileRetrieverList.addStaticItem");

		var itemID = unitID; // somtimes itemID is just a unitID, sometimes (for isParentCollege) it's unitID_count

		if ($('myCollege' + unitID) != null && !this.isParentCollege) {

			// don't add duplicates except for parentCollege

		} else if (this.isParentCollege){

			var thisCollegeIndex = 1;

			while ($('myCollege' + unitID + '_' + thisCollegeIndex) != null) {
				thisCollegeIndex++;
			}

				itemID = unitID + '_' + thisCollegeIndex;
		}

		$('myCollegesList').removeClass('jsHide'); // show list if (it will be hidden if it's empty)

		// HS elem
		var newHSElem = new Element('li', {
			id : 'myCollege' + itemID
		});

		newHSElem.setHTML(itemTextHTML);
		newHSElem.injectInside($('myCollegesList'));

		var hiddenElemName = this.isCollegeMajorList ? 'collegeMajorID' : 'myCollegeID';

		if (this.isForCampaigns) {
			hiddenElemName = 'INTENDED_COLLEGE_MAJORCriteria';
		}

		// Hidden input
		var newHiddenElem = new Element('input', {
			type : 'hidden',
			name : hiddenElemName,
			value : itemID
		});

		newHiddenElem.injectInside(newHSElem);

		// Parent/sibling
		if (this.isParentCollege) {

			// Label
			var newFamilySelectLabel = new Element('label', {
				'class' : 'familyCollegeSelectLabel'
			});
			newFamilySelectLabel.setHTML('Which family member attended this school?');
			newFamilySelectLabel.injectInside(newHSElem);

			// Select
			var newFamilySelect = $('dummyFamilyCollege').clone().removeClass('jsHide');
			newFamilySelect.id = '';
			newFamilySelect.name = 'familyCollege_' + itemID;
			newFamilySelect.injectInside(newHSElem);
		}
		
		// Remove link
		var newRemoveElem = new Element('a', {
			'href' : 'javascript:void(0)',
			'class' : 'myCollegesRemoveLink'
		});

		newRemoveElem.addEvent('click', function () {
			this.removeStaticCollegeName(itemID);
		}.bind(this))

		// Clearing div
		var newClearingDiv = new Element('div', {
			'class' : 'clear'
		});

		if (!this.isCollegeMajorList && !this.isParentCollege) {
			newRemoveElem.setHTML("No, don't share my profile");
		}
		newRemoveElem.injectInside(newHSElem);
		newClearingDiv.injectInside(newHSElem);

		// Show tip
		if (!this.isCollegeMajorList && $('addSearchResultTip')) {
			showTip('addSearchResultTip', 'addSearchResultTipArrow', 110, 92, 'addSearchResultTipText');
		}

		this.phraseElem.fireEvent('blur'); // hide dropdown
	},

	/**
	*	@param	itemID could be a unitID or a unitID_count (for parentCollege)
	*/
	removeStaticCollegeName : function (itemID) {

		global.trace("Begin removeStaticCollegeName");

		$('myCollege' + itemID).remove();

		if ($$('#myCollegesList li').length == 0) {
			$('myCollegesList').addClass('jsHide');
			if ($('addSearchResultTip')) {
				hideTip('addSearchResultTip', 'addSearchResultTipText');
			}
		}

	}

});

/****************************************/
/********* MajorRetriever Class *********/
/****************************************/

var MajorRetrieverList = ProfileRetrieverList.extend({

	isCollegeMajorList : true, // could add this to the top level class but seems unnecessary to do so
	ajaxResultsUrl : '/ajax/majorsResultsAjax.jsp',
	isForCampaigns : false,

	initialize : function (url, options) {

		this.parent(url, options);

		this.isForCampaigns = this.options.isForCampaigns;

		window.addEvent('domready', function() {
			if (typeof(collegeMajor_cpxSlider) != 'undefined' && $$('#myCollegesList li').length > 0) {
				collegeMajor_cpxSlider.bumpSlider(true);
			}
		});
	},

	generateResultsHTML : function () {

		global.trace("Begin MajorRetriever.generateResultsHTML");

		var resultsHTML;

		resultsHTML = '<ul class="cssDropdown"><li><ul>';

		if (this.numCurrentResults > 0) {

			// prepare link for id= to be added inside of for loop (allows use of a url with other parameters already on the query string)
			var resultLinkURLReadyForParams;
			if (this.resultLinkURL.contains('?')) {
				resultLinkURLReadyForParams = this.resultLinkURL + '&';
			} else {
				resultLinkURLReadyForParams = this.resultLinkURL + '?';
			}

			for (var i = 0; i < this.results.length; i++) {

				// add id param to result links unless they are merely JS links

				// Note: this results in a link like: javascript:void(0)?id=12345, but that seems to be working fine
				resultsHTML += '<li><a id="resultLink_' + this.options.moduleID + '_' + i +
							   '" href="' + resultLinkURLReadyForParams +
							   'id=' + this.results[i].unitID + '&collegeID=' +  this.results[i].unitID +
							   '" class="resultLink" onclick="return false;">' + this.results[i].name +
							   '</a></li>';
			}

			if (this.hasAdditionalResults && this.allowShowAllSchoolsLink) {
				resultsHTML += '<li id="showAllMajorsContainer">Showing first ten matches <a id="showAllSchoolsLink_' + this.moduleID + '" href="javascript:void(0)" onclick="return false">Show me all matching majors</a><br/></li>';
				/* NB: javascript:void(0) was causing link to fire incorrectly in IE6!!! */
				// REMOVEKH (no longer getting total results back): resultsHTML += '<li><a id="showAllSchoolsLink_' + this.moduleID + '" href="javascript:void(0)" onclick="$(\'collegeSearchModule\').submit()">Show me all ' + this.totalResults + ' matching colleges</a>';
			}

			if (this.schoolNotListedLink) {
				resultsHTML += '<li><a class="resultLink" href="/?id=-99" onclick="return false">My major is not listed</a>';
			}

		} else {
			resultsHTML += '<li class="noResultsMsg">There are no majors that match what you\'ve entered.</li>';
			if (this.schoolNotListedLink) {
				resultsHTML += '<li><a class="resultLink" href="/?id=-99" onclick="return false">My major is not listed </a>';
			}
		}

		resultsHTML += '</ul></li></ul>';

		return resultsHTML;
	},

	addStaticItem : function (unitID, itemTextHTML) {

		this.parent(unitID, itemTextHTML);

		global.log('MajorRetriever.addStaticItem');

		if ($$('#myCollegesList li').length > 4 && $('addSearchResultTip')) {
			showTip('addSearchResultTip', 'addSearchResultTipArrow', 110, 119, 'addSearchResultTipText');
		}

		if (typeof(collegeMajor_cpxSlider) != 'undefined') {
			collegeMajor_cpxSlider.bumpSlider();
		}
	}

});