/* ----- find a program dropdown-----------*/
$(document).ready(function() {
	 var ptype = "ugrad";			 
	 //hide non-active dropdown menus
	 $("#findprogram-dropdown > .dropdown:not(.active)").hide(); 
   $("#findprogram-links > li > a").click(function(){															
			//change the active tab
			$("#findprogram-links > li.active").removeClass("active");			
			$("#findprogram-dropdown > span.active").removeClass("active");
	 		$("#findprogram-dropdown > .dropdown").hide(); 
			$(this).parent().addClass("active");			
			//display the correct dropdown menu			
			if(this.id == "UG") {$("#findprogram-dropdown > #ugrad-options").addClass("active").show();ptype = "ugrad";}
			if(this.id == "GRAD") {$("#findprogram-dropdown > span#grad-options").addClass("active").show();ptype="grad"}
			if(this.id == "ONLINE"){ $("#findprogram-dropdown > #online-options").addClass("active").show();	ptype="online"}
			return false;
	 });	 
	 //check that a program is selected and if yes redirect to the correct program page
	 $("#FindProgramForm").submit(function() { 
			switch(ptype) {
				case "ugrad": 
					if($("#FindProgramForm #program-ugrad").val() == ""){
						alert("Select a program");
						return false;
					}
					break;
				case "grad":
					if($("#FindProgramForm #program-grad").val() == ""){
						alert("Select a program");
						return false;
					}
					break;
				case "online":
					if($("#FindProgramForm #program-online").val() == ""){
						alert("Select a program");
						return false;
					}
					break;
				default:
					return false;
			}				
			var driverPath = "/drivers/GoToProgramPage.cfm?pid=" + $("select#program-"+ptype+" option:selected").val() + "&ptype=" + ptype ;
			window.location=driverPath;
      return false;
    });
});
