$(document).ready(function(){
	// Needed to show gradient on right col
	if (!$("body").hasClass("home")) {
		$("#pagewidth").wrapInner("<div id='gradient'></div>");
	}
	// All external links open new windows
	$("a[href^='http']").attr("target","_blank");
	// Validate on submit
	$("form").submit(function(){
		if (!RequiredFieldsCheck("_Registration")) {return false;}
	})
	// On home page, shorten the date
	if ($("body").hasClass("home")) {
		DateShorten();
	}

	
});

function DateShorten() {
	$("p.date").each(function(){
		var currDate = $(this).text();
		var spaceLoc = currDate.indexOf(" ");
		var commaLoc = currDate.indexOf(",");
		var newDate = currDate.substr(0,3) + " " + currDate.substr(spaceLoc,commaLoc - spaceLoc) + "/";
		newDate += currDate.substr(currDate.length - 2,2);
		$(this).text(newDate);
	});
}

function RequiredFieldsCheck(formName) {
	var flag = true;
	$("form[name='" + formName + "'] input.required").each(function() {
		if ($(this).val() =="") {
			alert($(this).attr("title") + " is required.");
			$(this).focus();
			flag = false;
			return false;
		}
	});
	if (flag) {return true;}
}
