/* Personalization and meet-your-counselor effects (requires jQuery) */
/* by White Whale Web Services for Tulane Admission */

var sharedStates = new Array('CA','FL','NY','TX'); // states with multiple counselors

var zipcode;
$(document).ready(function() {
	zipcode = $('#zipcode');// look up zipcode input just once
	zipcode.hide().find('#student_zip').val('00000'); // hide it
	$('#student_state').change(function() { // if the state has multiple counselors, show the zip code
		if(sharedStates.join(',').indexOf($(this).val())!=-1) zipcode.find('#student_zip').val('').parent().show();
		else zipcode.hide().find('#student_zip').val('00000');
	}).keyup(function() { $(this).change(); }).change(); // onkeyup, and immediately, fire the change event
	/* Meet-Your-Counselor only */
	$('#counselor_submit').click(function() { // submit action just for the meet-your-counselor page
		if(zipcode.find('input').val().replace(/[^0-9]/g,'').length!=5) { // if not a valid zip
			alert('Please enter a valid US zip code.');
			return false; // cancel the click
		}
	});
	/* Personalize-This-Page only */
	$('#student_type').click(function() { // choose a student type
		if($(this).val()==0) $('#state').show().find('#student_state').change();
		else zipcode.add('#state').hide(); // hide zipcode and state
	}).change(function() { $(this).click(); });
	$('#interests').addClass('multiselect').find('label').each(function() { if($(this).prev().attr('checked')) $(this).addClass('selected'); }).click(function() { $(this).toggleClass('selected'); });
	$('.student_program').change(function() {
		if($(this).val()&&$(this).next().attr('class')!='student_program') $(this).after($(this).clone(true)); // add another
		else if(!$(this).val()&&$(this).next().attr('class')=='student_program') $(this).remove();
		$('.student_program').children().show().end().each(function() {
			if($(this).val()) $(this).siblings('.student_program').children('option[value='+$(this).val()+']').hide();
		});		
	}).keyup(function() { $(this).change(); });
});