/*
 * STEP 1
 */
function enter_zip()
{
	if($F('zip') == "")
		return false;
	else if(!validateZip($F('zip')))
		return false;
		
	var url = 'art-institute-ajax.php';
	var param = 'action=zip&zip='+$F('zip');

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

function validate_step1()
{
	$('phone_home').value = $F('phone_home').gsub(/[^0-9]/, '');
	$('phone_work').value = $F('phone_work').gsub(/[^0-9]/, '');
	$('email').value = fixEmail($F('email'));

	if($F('programId') == "")
	{
		alert("Please select a Program of Interest");
		$('programId').focus();
		return false;
	}
	else if($F('education_level') == "")
	{
		alert("Please select your Highest Level of Education.");
		$('education_level').focus();
		return false;	
	}
	else if($F('education_level') == "SHS")
	{
		alert("You must have a High School degree to attend The Art Institute");
		$('education_level').focus();
		return false;
	}
	else if($F('high_grad_year') == "")
	{
		alert("Please select your year of High School Gradution.");
		$('high_grad_year').focus();
		return false;	
	}
	else if(!validateName($F('fname')))
	{
		alert("Please enter a valid first name");
		$('fname').focus();
		return false;
	}
	else if(!validateName($F('lname')))
	{
		alert("Please enter a valid last name");
		$('lname').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(!validateZip($F('zip')))
	{
		alert("Please enter a valid 5 digit zip code");
		$('zip').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('phone_home')))
	{
		alert("Please enter a valid home phone number including area code");
		$('phone_home').focus();
		return false;
	}
	else if($F('phone_work')!= "" && !validatePhone($F('phone_work')))
	{
		// 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 work phone number including area code");
		$('phone_work').focus();
		return false;
	}

	//popunder_loadornot("../form-quick-degree-finder/index.php?source=form-art-institute-popunder");

	return true;
}


function program_select()
{
	//var progSelIndex = $('programId').selectedIndex;
	//var programId = $F('programId').options[progSelIndex].value;

	// be sure to tell which school program was selected and save it so we can pass it into step 3
	//var sel_prog = $('programId').options[progSelIndex].getAttribute('code');

	get_program_description($F('programId'));
	return $F('programId');
}


function get_program_description(programId)
{
	var url = 'art-institute-ajax.php';
	var param = 'action=description&program_id=' + escape(programId);

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

