function setupSchool(theDistrict)
{
	
	
	if (theDistrict.selectedIndex > 0)
	{
		//alert(theDistrict.options[theDistrict.selectedIndex].text);
		new Ajax.Updater('fillSchool','getSchool.cfm',{parameters: {did: theDistrict.value}});
	}
	else
	{
		
		$('fillSchool').innerHTML = "Please Choose a district firstxx!";
	} 
}
function CarInfo(isActive)
{
	if (isActive == 1)
	{
		$('id_car_info').style.display = 'inline';
		$('id_carrequired').value = "1";
	}
	else
	{
		$('id_car_info').style.display = 'none';
		$('id_carrequired').value = "0";
	}
}
function GetDirections(intheLoc,intheBuild, intheDir)
{
	//alert(intheLoc);
	new Ajax.Updater('fill_theDirections','getDirection.cfm',{parameters: {theloc: intheLoc,thebuild: intheBuild,thedir: intheDir}});
}

function Validate(theForm)
{
	var hasErrors = false;
	var noTID = true;
	var errorColor = '#ffdddd';
	var backColor = '#ffffff';
	var pZip = /^[0-9]+$/;
	var pN3 = /^[0-9]{3}$/;
	var pN4 = /^[0-9]{4}$/;
	
	var message = '<hr />';
	message += '<p>Please fix the following error before continuing. (Error(s) Highlighted in red)</p>';
	message += '<ul>';
	if (theForm.fname.value.length < 1)
	{
		hasErrors = true;
		message += '<li>First name is blank!</li>';
		$('id_th_fname').style.backgroundColor=errorColor;
		$('id_td_fname').style.backgroundColor=errorColor;
	}
	else
	{
		$('id_th_fname').style.backgroundColor=backColor;
		$('id_td_fname').style.backgroundColor=backColor;
		
	}
	if (theForm.lname.value.length < 1)
	{
		hasErrors = true;
		message += '<li>Last name is blank!</li>';
		$('id_th_lname').style.backgroundColor=errorColor;
		$('id_td_lname').style.backgroundColor=errorColor;
	}
	else
	{
		$('id_th_lname').style.backgroundColor=backColor;
		$('id_td_lname').style.backgroundColor=backColor;
	}
	
	if (theForm.address1.value.length < 1)
	{
		hasErrors = true;
		message+= '<li>Home address 1 is blank!</li>';
		
		$('id_th_address1').style.backgroundColor=errorColor;
		$('id_td_address1').style.backgroundColor=errorColor;
	}
	else
	{
		$('id_th_address1').style.backgroundColor=backColor;
		$('id_td_address1').style.backgroundColor=backColor;
		
	}
	if (theForm.city.value.length < 1)
	{
		hasErrors = true;
		message+= '<li>City is blank!</li>';
		
		$('id_th_city').style.backgroundColor=errorColor;
		$('id_td_city').style.backgroundColor=errorColor;
	}
	else
	{
		$('id_th_city').style.backgroundColor=backColor;
		$('id_td_city').style.backgroundColor=backColor;
		
	}
	if (theForm.state.selectedIndex < 1)
	{
		hasErrors = true;
		message+= '<li>Please choose a state!</li>';
		
		$('id_th_state').style.backgroundColor=errorColor;
		$('id_td_state').style.backgroundColor=errorColor;
	}
	else
	{
		$('id_th_state').style.backgroundColor=backColor;
		$('id_td_state').style.backgroundColor=backColor;
		
	}
	if ((theForm.zip.value.length < 1) || (pZip.test(theForm.zip.value) == false))
	{
		hasErrors = true;
		message+= '<li>Zip is blank or not filled out correctly!<br /> Please use numbers only!</li>';
		
		$('id_th_zip').style.backgroundColor=errorColor;
		$('id_td_zip').style.backgroundColor=errorColor;
	}
	else
	{
		$('id_th_zip').style.backgroundColor=backColor;
		$('id_td_zip').style.backgroundColor=backColor;
		
	}
	if ((pN3.test(theForm.phoneareacode.value) == false) || (pN3.test(theForm.phoneprefix.value) == false) || (pN4.test(theForm.phonesuffix.value) == false)) 
	{
		hasErrors = true;
		message += '<li>Home phone is not filled out correctly!<br />Only number are allowed.</li>';
		$('id_th_phone').style.backgroundColor=errorColor;
		$('id_td_phone').style.backgroundColor=errorColor;
	}
	else
	{
		$('id_th_phone').style.backgroundColor=backColor;
		$('id_td_phone').style.backgroundColor=backColor;
		
	}
	if (theForm.district.selectedIndex < 1)
	{
		hasErrors = true;
		message += '<li>Please choose a district!</li>';
		$('id_th_district').style.backgroundColor=errorColor;
		$('id_td_district').style.backgroundColor=errorColor;
	}
	else
	{
		$('id_th_district').style.backgroundColor=backColor;
		$('id_td_district').style.backgroundColor=backColor;
		
	}
	if (theForm.district.selectedIndex > 0)
	{
		if (theForm.school != undefined)
		{
			if (theForm.school.selectedIndex < 1)
			{
				
				hasErrors = true;
				message += '<li>Please choose a school!</li>';
				$('id_th_school').style.backgroundColor=errorColor;
				$('id_td_school').style.backgroundColor=errorColor;
			}
			else
			{
				$('id_th_school').style.backgroundColor=backColor;
				$('id_td_school').style.backgroundColor=backColor;
				
			}
		}
	}
	if (theForm.position.selectedIndex < 1)
	{
		hasErrors = true;
		message += '<li>Please choose a school position!</li>';
		$('id_th_position').style.backgroundColor=errorColor;
		$('id_td_position').style.backgroundColor=errorColor;
	}
	else
	{
		$('id_th_position').style.backgroundColor=backColor;
		$('id_td_position').style.backgroundColor=backColor;
		
	}
	if (theForm.tid.length == undefined)
	{
		//alert(!theForm.tid.checked);
		if (!theForm.tid.checked)
		{
			hasErrors = true;
			$('tblsessions').style.backgroundColor=errorColor;
		}
		else
		{
			$('tblsessions').style.backgroundColor=backColor;
			
		}
	}
	else
	{
		noTID = true;
		//alert("Number of radio Buttons " + theForm.tid.length);
		for (var i = 0;i<theForm.tid.length; i++)
		{
			//alert(i + " : " + theForm.tid[i].checked);
			if (theForm.tid[i].checked)
			{
				noTID = false;
			}
		}
		if (noTID)
		{
			hasErrors = true;
			message += '<li>Please choose a training Session!</li>';
			$('tblsessions').style.backgroundColor=errorColor;
			//message += "Please choose a training before continuing!\n";
		}
		else
		{
			$('tblsessions').style.backgroundColor=backColor;
		}
	}
	
	
	if (theForm.carrequired.value == "1")
	{
		if (theForm.carmake.value.length < 1)
		{
			hasErrors = true;
			message += '<li>Car Make is blank!</li>';
			$('id_th_carmake').style.backgroundColor=errorColor;
			$('id_td_carmake').style.backgroundColor=errorColor;
		}
		else
		{
			$('id_th_carmake').style.backgroundColor=backColor;
			$('id_td_carmake').style.backgroundColor=backColor;
			
		}
		
		if (theForm.carcolor.value.length < 1)
		{
			hasErrors = true;
			message += '<li>Car color is blank!</li>';
			$('id_th_carcolor').style.backgroundColor=errorColor;
			$('id_td_carcolor').style.backgroundColor=errorColor;
		}
		else
		{
			$('id_th_carcolor').style.backgroundColor=backColor;
			$('id_td_carcolor').style.backgroundColor=backColor;
			
		}
		if (pN4.test(theForm.caryear.value) == false)
		{
			hasErrors = true;
			message += '<li>Car year is not filled in correctly!<br />Please use numbers only.</li>';
			$('id_th_caryear').style.backgroundColor=errorColor;
			$('id_td_caryear').style.backgroundColor=errorColor;
		}
		else
		{
			$('id_th_caryear').style.backgroundColor=backColor;
			$('id_td_caryear').style.backgroundColor=backColor;
			
		}
		if (theForm.carplate.value.length < 1)
		{
			hasErrors = true;
			message += '<li>Car plate is blank!</li>';
			$('id_th_carplate').style.backgroundColor=errorColor;
			$('id_td_carplate').style.backgroundColor=errorColor;
		}
		else
		{
			$('id_th_carplate').style.backgroundColor=backColor;
			$('id_td_carplate').style.backgroundColor=backColor;
			
		}
	}
	/**/
	
	// Validation Return Code
	if (hasErrors == true)
	{
		
		message += '</ul><hr />';
		$('error_message').innerHTML = message;
		$('id_error_message').style.backgroundColor = errorColor;
		return false;
	}
	else
	{
		$('error_message').innerHTML = "";
		$('id_error_message').style.backgroundColor = backColor;
		return true;
	}
}


function postValidate(theForm)
{
	var hasErrors = false;
	var noTID = true;
	var errorColor = '#ffdddd';
	var backColor = '#ffffff';
	var pZip = /^[0-9]+$/;
	var pN3 = /^[0-9]{3}$/;
	var pN4 = /^[0-9]{4}$/;
	
	var message = '<hr />';
	message += '<p>Please fix the following error before continuing. (Error(s) Highlighted in red)</p>';
	message += '<ul>';
	
	if (theForm.tid.length == undefined)
	{
		//alert(!theForm.tid.checked);
		if (!theForm.tid.checked)
		{
			hasErrors = true;
			$('tblsessions').style.backgroundColor=errorColor;
		}
		else
		{
			$('tblsessions').style.backgroundColor=backColor;
			
		}
	}
	else
	{
		noTID = true;
		//alert("Number of radio Buttons " + theForm.tid.length);
		for (var i = 0;i<theForm.tid.length; i++)
		{
			//alert(i + " : " + theForm.tid[i].checked);
			if (theForm.tid[i].checked)
			{
				noTID = false;
			}
		}
		if (noTID)
		{
			hasErrors = true;
			message += '<li>Please choose a training Session!</li>';
			$('tblsessions').style.backgroundColor=errorColor;
			//message += "Please choose a training before continuing!\n";
		}
		else
		{
			$('tblsessions').style.backgroundColor=backColor;
		}
	}
	
	
	if (theForm.carrequired.value == "1")
	{
		if (theForm.carmake.value.length < 1)
		{
			hasErrors = true;
			message += '<li>Car Make is blank!</li>';
			$('id_th_carmake').style.backgroundColor=errorColor;
			$('id_td_carmake').style.backgroundColor=errorColor;
		}
		else
		{
			$('id_th_carmake').style.backgroundColor=backColor;
			$('id_td_carmake').style.backgroundColor=backColor;
			
		}
		
		if (theForm.carcolor.value.length < 1)
		{
			hasErrors = true;
			message += '<li>Car color is blank!</li>';
			$('id_th_carcolor').style.backgroundColor=errorColor;
			$('id_td_carcolor').style.backgroundColor=errorColor;
		}
		else
		{
			$('id_th_carcolor').style.backgroundColor=backColor;
			$('id_td_carcolor').style.backgroundColor=backColor;
			
		}
		if (pN4.test(theForm.caryear.value) == false)
		{
			hasErrors = true;
			message += '<li>Car year is not filled in correctly!<br />Please use numbers only.</li>';
			$('id_th_caryear').style.backgroundColor=errorColor;
			$('id_td_caryear').style.backgroundColor=errorColor;
		}
		else
		{
			$('id_th_caryear').style.backgroundColor=backColor;
			$('id_td_caryear').style.backgroundColor=backColor;
			
		}
		if (theForm.carplate.value.length < 1)
		{
			hasErrors = true;
			message += '<li>Car plate is blank!</li>';
			$('id_th_carplate').style.backgroundColor=errorColor;
			$('id_td_carplate').style.backgroundColor=errorColor;
		}
		else
		{
			$('id_th_carplate').style.backgroundColor=backColor;
			$('id_td_carplate').style.backgroundColor=backColor;
			
		}
	}
	/**/
	
	// Validation Return Code
	if (hasErrors == true)
	{
		
		message += '</ul><hr />';
		$('error_message').innerHTML = message;
		$('id_error_message').style.backgroundColor = errorColor;
		return false;
	}
	else
	{
		$('error_message').innerHTML = "";
		$('id_error_message').style.backgroundColor = backColor;
		return true;
	}
}