// each tab link must assign the proper 'institutionType' value
jQuery('#CommunityTab a').live('click', function(e) { assignInstitutionType(2); displayChooseCountryDialog(e); });
jQuery('#UndergradTab a').live('click', function(e) { assignInstitutionType(3); displayChooseCountryDialog(e); });
jQuery('#GraduateTab a').live('click', function(e) { assignInstitutionType(4); displayChooseCountryDialog(e); });
jQuery('#EnglishSecondLangTab a').live('click', function(e) { assignInstitutionType(1001); displayChooseCountryDialog(e); });
jQuery('#PerformingArtsTab a').live('click', function(e) { assignInstitutionType(1002); displayChooseCountryDialog(e); });


/*
 * Assigns 'newValue' to the hidden input 'institutionType' that is required for proper form submission.
 */
function assignInstitutionType(newValue) {
	var form = jQuery('#ModalRegionForm').get(0);
	form.institutionType.value = newValue;
}


/*
 * Behavior depends on the value of the hidden 'showDialog' input:
 * 		true:	Displays a modal dialog that allows the user to provide his/her country (or cancel the operation).
 * 		false:	Skips the modal dialog and submits the form with the pre-selected country (which was pulled from session token).
 * This MUST be called AFTER calling assignInstitutionType (see above).
 */
function displayChooseCountryDialog(e) {
	e.preventDefault();

	var elemCountry = jQuery('#promptCountry .CountryDropDown').get(0);
	if (elemCountry.options.selectedIndex > 0) {
		// country is pre-selected: skip dialog
		jQuery('#ModalRegionForm').submit();
		
	} else {
		// country is missing: display dialog
		jQuery('#promptCountry').modal({
			close: false
			,position: ["35%",]
		});
	}
}
