/**
 * Creator: Kevin Hastie
 * Date: Feb 9, 2007
 * Time: 4:31:09 PM
 * Contents are property of Cappex.com LLC, and strictly confidential.
 **/

/**
 * Associated with: retrieveHSFromZip.jsp
 **/

/********************************/
/***** DECLARE GLOBAL VARS ******/
/********************************/

var g_oldHsZip;

/********************************/
/******* DECLARE CLASSES ********/
/********************************/

/********************************/
/******** EVENT HANDLERS ********/
/********************************/

window.addEvent("domready", function() {
	retrieveSchools($("hsZip").value.toString());
	g_oldHsZip = $("hsZip").value.toString();
});

/********************************/
/********** FUNCTIONS ***********/
/********************************/

/**
 * Does an ajax call to retrieve a SELECT dropdown populated with high schools matching the zip code
 * @param hsZip - the zip code to search on
 **/

//function retrieveSchools(hsZip, command, onSuccess) {
function retrieveSchools(hsZip, command) {

//	var onSuccessCallback = function () {
//		// do nothing on success by default
//	};
//
//	if (typeof(onSuccess) == 'function') {
//		onSuccessCallback = onSuccess;
//	}

	hsZip = hsZip.toString();

	if ((hsZip != g_oldHsZip && hsZip.length == 5) || command == "FORCE_REFRESH") {

		g_oldHsZip = hsZip;

		new AjaxCpx('/ajax/retrieveHSFromZip.jsp', {
			data:'hsZip=' + hsZip + "&hsID=" + $('hsID').value + "&pageId=" + $('pageId').value,
			update: 'hsGraduatedFromTarget',
			// onSuccess: onSuccessCallback
			onSuccess : function () {
				// TAG:HS_EDITOR_ERRORS TODOKH: this could really use a refactoring
				if (typeof(hsEditDisabled) != 'undefined' && hsEditDisabled && $('hsID').value == -1) {
					hsNameEditor.toggleEditHS();					
					// hsNameEditor.loadHSInfo();
				}

				formHighlighting(); // redo formhighlighting events

				checkShowInviteGCLink();
			}
		}).request();
	}
}