/*
 * STEP 1
 */
function enter_zip()
{
	if($F('zip') == "")
		return false;
	else if(!validateZip($F('zip')))
		return false;
		
	var url = 'south-university-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()
{
	$('phone_home').value = $F('phone_home').gsub(/[^0-9]/, '');
	$('phone_work').value = $F('phone_work').gsub(/[^0-9]/, '');
	$('email').value = fixEmail($F('email'));
	is_licensed = getCheckedValue(document.form_step1.is_licensed);
	
	if($('program_id').options.length == 0 || $F('program_id') == "")
	{
		alert("Please select a Program of Interest");
		$('program_id').focus();
		return false;
	}
	else if($('education_level').value == "")
	{
		alert("Please select your Highest Level of Education.");
		$('education_level').focus();
		return false;	
	}
	else if($('education_level').value == "SHS")
	{
		alert("You must have a High School degree to attend South University");
		$('education_level').focus();
		return false;
	}
	else if($('high_grad_year').value == "")
	{
		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;
	}
	else if($F('program_id') == 401 && is_licensed != "Yes")
	{
		alert("You must be a registered nurse to enroll in this program");
		return false;
	}

	return true;
}




/*
 * Updates the programs description in Step 2
 */
function program_select()
{
	var progSelIndex = $('program_id').selectedIndex;
	var programId = $('program_id').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 = $('program_id').options[progSelIndex].getAttribute('code');

	display_registered_nurse(programId);
	get_program_description(programId);
}


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

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

function display_registered_nurse(programId)
{
	var div = $('is_registered_nurse_div');

	if(div.style.display != "block" && programId == 401)
		div.style.display = "block";
	else
		div.style.display = "none";
}

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