var $schools_home ={};
$schools_home.majors_loaded = false;

//FUNCTIONS

$schools_home.handle_major_toggle = function(obj)
{
	var ar = obj.id.split("_");
	var id = ar[1];
	
	$("#school-ht_major > form > div").hide();
	$("#major-search_"+id).show();
	
	$("#major-search-toggle > span").removeClass("sel");
	$(obj).addClass("sel");
	
	
	//uncheck anyting taht was checked
	$('input[name=cs-major[]]').attr("checked", false);
}

//ONLOAD STUFF
$(function(){
	
	$("#list_major").hide();
	$("#list_type").hide();
	$("#major-search_browse").hide();
	
	//clear the zip field
	$("#find_zip").click(function(){
		
		if($(this).val() == "Enter ZIP Code"){$(this).val("");}
	});
	
	$("#ulFS > li > a").click(function(){
		core.handle_tabs(this, "#ulFS > li > a", ".divFindTabs > div.holder", null, "school-ht", null, core.callback.handle_region_map);
		
	});
	
	//choose what tab on load
	{
		var id_ar = location.href.split("#");
		var the_id = (!id_ar[1]) ? "location" : id_ar[1];
		
		if(the_id != "undefined" && the_id){
			core.handle_tabs(false, "#ulFS > li > a", ".divFindTabs > div.holder", null, "school-ht", the_id);
		}
	}
	
	//load the map
	swfobject.embedSWF("/swf/school_regions_map.swf", "swf-college-map", "450", "330", "9.0.0", "expressInstall.swf");

	$("#ajax-major-search").click(function(){
		var the_val = ($("#ajax-major-text").val());
		
		if(the_val != "")
		{
			core.basic_ajax("/ajax/searchMajors", "string="+the_val, "html", "#school-home-major-holder", "<p class='major-list-text'>Getting Majors...</p>");
		}
		return false;
	});
	
	
	//handle the  toggle between search and browse
	$("#major-search-toggle > span").click(function(){
		$schools_home.handle_major_toggle(this);
	});
	
	//shut off the major form, will submit if js is off (508)
	$("#school-major-search").submit(function(){
		
		var maj_ar = $(".major-search-check:checked").length;
		var r = true;
		
		if(maj_ar < 1 && $("#ajax-major-text").val() == ''){
			r = false;
			alert("Please enter a keyword or select a major from the list.");
		}
		
		return r;
	});
	
  
	//load the major list only when the "browse" link is clicked - reduces k size and load time
	$("#a-major-search_browse").click(function(){
				if(!$schools_home.majors_loaded){
								core.basic_ajax("/Ajax/allMajors", "", "html", "#major-search_browse", "<div style='margin-left:15px;text-align:left!important;'><img src='/img/ui/l-anim.gif' alt='loading' /><p>Please wait while we load the majors...</p></div>");
								$schools_home.majors_loaded = true;
				}
	});
	
	
	//validate the zip form
	$("#school-location-search").submit(function(){
		var the_val = $("#find_zip").val();
		
		if(the_val=="" || isNaN(the_val) || the_val.length < 5){
			alert("Please enter a valid zip code.");
			return false;
		}else{
			return true;
		}
		
	});
});
