function validate()
{
	$('DaytimePhone').value = $F('DaytimePhone').gsub(/[^0-9]/, '');
	$('EveningPhone').value = $F('EveningPhone').gsub(/[^0-9]/, '');
	$('Email').value = fixEmail($F('Email'));

	if(!validateName($F('FirstName')))
	{
		alert("Please enter a valid first name");
		$('FirstName').focus();
		return false;
	}
	else if(!validateName($F('LastName')))
	{
		alert("Please enter a valid last name");
		$('LastName').focus();
		return false;
	}
	else if(!validateEmail($F('Email')))
	{
		alert("Please enter a valid email address");
		$('Email').focus();
		return false;
	}
	else if($F('Address1') == "")
	{
		alert("Please enter your address");
		$('Address1').focus();
		return false;
	}
	else if($F('City') == "")
	{
		alert("Please enter a city");
		$('City').focus();
		return false;
	}
	else if($F('State') == "")
	{
		alert("Please enter a state");
		$('State').focus();
		return false;
	}
	else if(!validatePhone($F('DaytimePhone')))
	{
		alert("Please enter a valid daytime phone number including area code");
		$('DaytimePhone').focus();
		return false;
	}
	else if($F('EveningPhone')!= "" && !validatePhone($F('EveningPhone')))
	{
		// keep in mind that at this point, alt_phone could have had
		// the non numeric characters stripped out, thus causing the value
		// to be "" even though something was entered, but that is fine since
		// in that situation no alt phone number will be submitted
		alert("Please enter a valid evening phone number including area code");
		$('EveningPhone').focus();
		return false;
	}

	degree_type = $('program_id').options[$('program_id').selectedIndex].getAttribute('degree');

	if($F('YearHSGED') == "")
	{
		alert("Please select a Highschool Gradution year.");
		$('YearHSGED').focus();
		return false;	
	}

	if($F('Education') == "")
	{
		alert("Please select a Level of Education.");
		$('Education').focus();
		return false;	
	}

	if($F('campus_id') == "")
	{
		alert("Please select a campus location to attend.");
		$('campus_id').focus();
		return false;	
	}
	
	var d = new Date();
	var online_grad_year = d.getFullYear() - 1;
	var aff_id = getCookie('aff_id');
	
	// if the aff_id is not set, then we don't show the campus option since all programs
	// will be listed regardless of campus
	if(!(aff_id > 0))
	{
		var selected_campus = $('campus_id').options[$('campus_id').selectedIndex].text;
		
		if(selected_campus.match(/westwood\ +online/i) && $F('YearHSGED') > online_grad_year)
		{
			alert("You must have graduated high school on or before the year "+online_grad_year+" to attend the Online Campus");
			$('YearHSGED').focus();
			return false;	
		}
	}
	
	if($('program_id').options.length == 0 || $F('program_id') == "")
	{
		alert("Please select a Program of Interest");
		$('program_id').focus();
		return false;
	}

	if(!$('ExpressConsent').checked)
	{
		alert("Please consent to being contacted by a Westwood College representative.");
		$('ExpressConsent').focus();
		return false;
	}

	return true;
}

function enter_zip()
{
	if($F('Zip') == "")
		return false;
	else if(!validateZip($F('Zip')))
		return false;
		
	var param = 'action=zip&get_campuses=1&zip='+$F('Zip');
	var url = 'westwood-college-ajax.php';
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'post',
			parameters: param,
			onSuccess: function(transport)
			{
				eval(transport.responseText);
			}
		}
	);
	
}

/*
 * Updates the programs description in Step 2
 */
function program_select()
{
	var progSelIndex = $('program_id').selectedIndex;
	var programId = $('program_id').options[progSelIndex].value;

	get_program_description(programId);
}

function get_program_description(programId, desc_type)
{
	var url = 'westwood-college-ajax.php';
	var param = 'action=description&program_id='+escape(programId)+'&type='+desc_type;

	var myAjax = new Ajax.Updater(
		'program_description',
		url,
		{
			method: 'post',
			parameters: param,
			evalScripts: true
		}
	);
}

/*
 * Update the program select list
 */
function update_program_list(programId)
{
	var param = '';
	var url = 'westwood-college-ajax.php';

	param += 'action=program_list&program_id='+programId+'&';
	param += 'zip='+escape($F('Zip'))+'&';
	param += 'YearHSGED='+escape($F('YearHSGED'))+'&';
	param += 'state='+escape($F('State'))+'&';
	param += 'campus_id='+escape($F('campus_id'));

	var myAjax = new Ajax.Request(
		url,
		{
			method: 'post',
			parameters: param,
			onSuccess: function(transport)
			{
            	eval(transport.responseText);
			}
		}
	);
}

Event.observe(window, 'load', enter_zip);
