/*

Copyright (c) Loyola University New Orleans

FILE DESCRIPTION:
jQuery code for the Web Request Form: http://www.loyno.edu/webteam/requestform

LAST MODIFIED BY:
Niall Doherty on 20090305

NOTES:
1) Depends on jQuery core file being included beforehand on the same HTML page.

*/

$(document).ready(function(){
						   
	$('span.cluetip').cluetip();
	
	// Show the form if JS is enabled
		$("#content form.hide").removeClass("hide");
	
	// Clear all radio buttons on page load
		$("input:radio, input:checkbox").attr("checked", false);
	
	// Show/hide the request sub-areas (radio buttons)
		$(".target").hide();
		// Use click event for IE, change event for everything else
		var evt = $.browser.msie ? "click" : "change";
		// When a trigger radio button is clicked/changed...
		$(".trigger input").bind(evt, function () {
			// Give the parent a simpler name so we can call it easier
			var x = $(this).parent();
			// Uncheck any other target inputs
			x.siblings(".target").find("input").attr("checked", false);
			// Slide up any other targets
			x.siblings(".target").slideUp();
			// Uncheck any other trigger inputs
			x.siblings(".trigger").find("input").attr("checked", false);
			// Slide down the current target
			x.next(".target").slideDown();
			// Fire the function to enable/disable the date requested field
			toggleDateReq();
		});
		
	// When one of the target radio buttons is clicked...
		$("input[name=request_type]").click(function () {
			// Fire the function to enable/disable the date requested field
			toggleDateReq();
		});
		
	// Give additional E-mail option if user ticks Admissions / IA box
		var admissions_ia = $("#area-of-request div.target:eq(1) label:last");
		admissions_ia.hide();
		$("#admissions_ia").click(function() {
        var chk = $("#admissions_ia")[0];
        var val = chk.checked;
        if (val == true) {
					//alert("Aye, tis true!"); 
					admissions_ia.show();
				} else {
					//alert("No, it be false!");
					admissions_ia.hide();
				};
		});

});

	function toggleDateReq() {
		var request_type = $("input[name=request_type]:checked").val();
		if ( request_type != undefined ) {
			// load real, passing it the variable for delivery_date
			var url = "request_form_date.php?request_type=" + request_type;
			$("tr#delivery-date").removeClass("temp").load(url);
		} else {
			// load temp
			$("tr#delivery-date").addClass("temp").load("request_form_date_temp.php");
			$("#job-detail span.hint").html("");
			$("tr#newsletter-account").remove();
		};
	};