$(function () {
	function ieSelectWidthFix() {
		if (jQuery.browser.msie) {
			$('select').each(function () {
				$(this).data("originalWidth", $(this).css('width'));
			});
			
			$('select').mouseenter(function () {
				$(this).css('width', "auto");
				$(this).data("resizedWidth", $(this).attr('offsetWidth'));
				
				if (parseInt($(this).data("resizedWidth")) < parseInt($(this).data("originalWidth").replace(/px/, ""))) {
					$(this).css('width', $(this).data("originalWidth"));		
				} else {
					$(this).addClass('expanded');	
				}
			});
			
			$('select').change(function () {
				$(this).css('width', $(this).data("originalWidth"));
				$(this).removeClass('expanded');
			});
			
			$(':input').focus(function () {
				if ($(this).attr('class') != 'expanded') {
					$('.expanded').each(function () {
						$(this).css('width', $(this).data("originalWidth"));
						$(this).removeClass('expanded');
					});
				}
			});
		}
	}
	
	function qualifyCheck () {
		if ($('#education_level_code').val() != "") {
			$('#defaultProgram').removeAttr('selected');
			$('#program_code option:first').attr('selected', "selected");
			
			$('#program_code option:first').replaceWith('<option value="">Choose a Program first&hellip;</option>');
			$('#program_code').attr('disabled', 'disabled');
			
			var setDefault = false;
			
			switch ($('#education_level_code').val()) {
				case "GED":
				case "HS":
					setDefault = true;
				break;
			}
			
			if (setDefault) {
				$('#selectCategory').load('includes/selectCategory.php', function () {
					$('#defaultCategory').attr('selected', "selected");
				});
				
				$('#selectProgramCode').load('includes/selectProgramCode.php', function () {
					$('#defaultProgram').attr('selected', "selected");
				});	
			} else {
				$('#selectCategory').load('includes/selectCategory.php', {eduLevel: $('#education_level_code').val()}, function () {
					ieSelectWidthFix();
					$('#category option:first').replaceWith('<option value="">Choose One</option>');
					
					$('#category').change(function () {
						$('#selectProgramCode').load('includes/selectProgramCode.php', {program: $('#category').val()}, function () {
							ieSelectWidthFix();
							switch ($('#category').val()) {
								case "BA/Business Administration":
								case "BA/Health Care Studies":
								case "BA/Organizational Management":
								case "BA/Social Science":
								case "MA/Education":
								case "MA/Organizational Management":
								case "MBA":
									$('#program_code option:first').replaceWith('<option value="">Choose One</option>');
								break;
								
								
								default:
									// Do nothing
								break;
							}
						});
					});
				});
			}
		}
	}

	$('#education_level_code').change(function () {
		qualifyCheck();									   
	});	
	
	$('#program_code').attr('disabled', 'disabled');
	
	ieSelectWidthFix();
});