function myShow(section, myTime) {
	var section_to_change = $('#' + section);
	section_to_change.slideToggle(myTime);
}

function myShowPosition(section, myTime) {
	var section_to_change = $('#recruiting_' + section + '_positions');
	var text_to_change = $('#position_link_' + section);
	if (text_to_change.text() == '[edit positions]') {
		text_to_change.text('[hide positions]');
	} else {
		text_to_change.text('[edit positions]');
	}
	section_to_change.slideToggle(myTime);
}

function moreVerified(show_or_hide) {
	myShow('more_verified', 200);
	if (show_or_hide == 'show') {
		$('#more_verified_link').html('<a onClick="moreVerified(\'hide\');" style="cursor:pointer;">Less...</a>');
	} else {
		$('#more_verified_link').html('<a onClick="moreVerified(\'show\');" style="cursor:pointer;">More...</a>');
	}
}

function checkAll(div_class) {
	if ($('#all_' + div_class).attr('checked') == true) {
		$('.' + div_class).attr('checked', true);
	} else {
		$('.' + div_class).attr('checked', false);
	}
}

function trim(str) {
	return ltrim(rtrim(str));
}
 
function ltrim(str) {
	var chars = "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str) {
	var chars = "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

var allowOther = false;
/**
* Function for the onchange method of the state select list to go get the 
* highschools for the highschool select list. State select list must have
* an id (or htmlId) of "highSchoolStateSelect". The high school select list 
* must have an id (or htmlId) of "highSchoolSelect".
* @param inAllowOther (optional) Whether to put the "Other" option in High School drop down.
* @return void
*/
function getHighSchools(inAllowOther) {
	if(typeof inAllowOther != "undefined") {
		allowOther = inAllowOther;
	}
	if(typeof $("#addHighSchool") != "undefined") {
		if($("#highSchoolStateSelect").val() == "") {
			$("#addHighSchool").hide("fast");
		} else {
			$("#addHighSchool").show("fast");
		}
	}
   $("#highSchoolSelect").fadeTo("fast", 0.33, _hsCallbackStart);
}

var _hsCallbackStart = function() {
	var stateIdFromSelect = $("#highSchoolStateSelect").val();
   var url = "/fasttrack/highSchool/Ajax.do";
	$.getJSON(url, { method: "ajaxGetHighSchoolsForState", stateId: stateIdFromSelect }, _hsCallbackFinish);	
}

/**
* Callback function passed to the getJSON jquery function. The callback gets run 
* when the ajax call finishes.
*/
var _hsCallbackFinish = function(data) {
	if("OK" == data.code) {
		// empty target select
		$("#highSchoolSelect").empty();
		// if the state selected is the special include all high schools from all states, then don't add the "Select High School" option.
		// -2 is defined in com.adivi.ncsa.fasttrack.common.MiscellaneousDAO.INCLUDE_ALL_STATES_ID
		if($("#highSchoolStateSelect").val() != -2) {
			$("#highSchoolSelect").append("<option value=\"\" >Select High School</option>");
		}
		if(allowOther) {
			$("#highSchoolSelect").append("<option value=\"-100\" >Other</option>");
		}
		$.each(data.highSchools, function(i,item){
			$("#highSchoolSelect").append("<option value=\"" + item.generic.ID + "\">" + item.generic.name + "</option>");
		});
	}
	// else, probably should show "no highschools found" msg
	else {
		alert("Unable to retrieve high schools. Re-select the chosen state to try again. If the error persists, please contact technical support.");
	}
   $("#highSchoolSelect").fadeTo("slow", 1.00);
};
