$(document).ready(function() {
	// fixes anchor tags in the main content (issue with base href)
	$("#content a[href^='#']").click(function() {
		document.location.hash = $(this).attr('href');
		return false;
	});
	
	if($("#GrantAddForm").length) {
		// auto check the "all" buttons 
		if($("#GrantAddForm .StrategicAreas :checked").length === 0) {
			$("#GrantAddForm .StrategicAreas input[type=checkbox]:first").attr('checked',true);
		}
		if($("#GrantAddForm .Program :checked").length === 0) {
			$("#GrantAddForm .Program input[type=checkbox]:first").attr('checked',true);
		}
		
		// checking the 'all' button deselects the others
		$("#GrantAddForm input[type=checkbox][value='']").click(function() {
			if($(this).attr('checked') === true) {
				$(this).parents('div.input').find("input[type=checkbox][value!='']").attr('checked',false);
			}
		});
		
		// checking any other checkbox delects the 'all' button.
		$("#GrantAddForm input[type=checkbox][value!='']").click(function() {
			if($(this).attr('checked') === true) {
				$(this).parents('div.input').find("input[type=checkbox][value='']").attr('checked',false);
			}
		});
	}
});