$(function() {

  $('#slideshow').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});

	

});

function isPhone(strValue) { return /^\d{3}-\d{3}-\d{4}$/.test(strValue); }
function isEmail(strValue) { return /^[-!#\$%\*\+\/\?\|\^&{}`~\w]+(\.[-!#\$%\*\+\/\?\|\^&{}`~\w]+)*@[-\w]+(\.[-\w]+)+$/.test(strValue); } 
function isZIP(strValue) { return /(^\d{5}$)|(^\d{5}-\d{4}$)/.test(strValue); } 

function validateRegister(objForm)
{

	var strReqMsg = "";
	var strValidationMsg = "";
	
	if(objForm.fname.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - First Name\n"; }
	
	if(objForm.lname.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Last Name\n"; }

	if(objForm.age.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Age\n"; }

	var strGender = "";
	$("input[name='gender']").each(function(i) {
		if($(this).attr("checked"))
		{
			strGender = $(this).attr("value");
		}
	});

	if(strGender.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Gender\n"; }

	if(objForm.address.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Address\n"; }

	if(objForm.city.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - City\n"; }

	if(objForm.state.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - State\n"; }

	if(objForm.zip.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - ZIP\n"; }

	if(objForm.email.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Email\n"; }

	if(objForm.email.value.length && !isEmail(objForm.email.value))
	{ strValidationMsg += "    - Email must be in the format username@domain.com\n"; }
		
	if(objForm.style.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Martial Art Style\n"; }

	if(objForm.rank.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Rank\n"; }

	if(objForm.instructor.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Instructor\n"; }

	var chkEvents = false;
	$("input[name='events[]']").each(function(i) {
		if($(this).attr("checked"))
		{
			chkEvents = true;
		}
	});

	if(!chkEvents)
	{
		strReqMsg += "    - You must choose at least one event\n";
	}	

	if($("#team-members").is(":visible"))
	{
		if(objForm.team.value.replace(/\s+/g, "") == "")
		{ strReqMsg += "    - Please enter your team members\n"; }
	}

	if($("input[name='agree']").attr("checked") == false)
	{ strReqMsg += "    - You must agree to the terms\n"; }

	// Assemble all of the error messates together to display to the user
	if(strReqMsg.length || strValidationMsg.length)
	{
		var strDisplay = "";
		if(strReqMsg.length)
		{ strDisplay += "The following fields are required to be completed:\n\n" + strReqMsg; }

		if(strValidationMsg.length)
		{ strDisplay += "\nThe following fields are not filled in correctly:\n" + strValidationMsg; }

		alert(strDisplay);
		return false;
	}
	else
	{
		return true;
	}

}
