/*
 * Validate form
 */
function validate()
{
	degree_type = $('program_id').options[$('program_id').selectedIndex].getAttribute('degree');
	$('zip').value = $F('zip').replace("-", "");
	$('zip').value = $F('zip').replace(" ", "");
	
	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($F('address1') == "")
	{
		alert("Please enter your address");
		$('address1').focus();
		return false;
	}
	if(!validateZip($F('zip')) && !validatePostalCode($F('zip')))
	{
		alert("Please enter a valid 5 digit zip code or a 6 digit postal 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('pref_phone')))
	{
		alert("Please enter a valid preferred phone number including area code");
		$('pref_phone').focus();
		return false;
	}
	else if($F('alt_phone')!= "" && !validatePhone($F('alt_phone')))
	{
		// 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 alternate phone number including area code");
		$('alt_phone').focus();
		return false;
	}
	else if(!validateEmail($F('email')))
	{
		alert("Please enter a valid email address");
		$('email').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 a nursing program requires further validation, check to see the answer
	sel_prog = $('program_id').options[$('program_id').selectedIndex].getAttribute('code');
	n = getCheckedValue($('form_step1').is_registerednurse);
	if(UOPRequiresNursingValidation(sel_prog) && n != 'Y')
	{
		alert("Thank you for your interest. This program requires an RN license. Please select another program.");
		return false;					
	}
	
	if(!$('contact_confirmation').checked)
	{
		alert("Please indicate that you understand a representitive of the University Of Phoenix will contact you.");
		$('contact_confirmation').focus();
		return false;
	}

	return true;
}



function enter_zip()
{
	if($F('zip') == "")
		return false;
	else if(!validateZip($F('zip')))
		return false;
		
	var url = 'university-of-phoenix-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);
			}
		}
	);
}



/*
 * Updates the programs description in Step 2
 */
//function update_description()
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
	$('school').value = $('program_id').options[progSelIndex].getAttribute('school_id');
	var sel_prog = $('program_id').options[progSelIndex].getAttribute('code');
	
	// hide or show the nursing question depending on the program they picked
	if(UOPRequiresNursingValidation(sel_prog))
	{
		if($('nursing_question').style.display == 'none')
			new Effect.SlideDown('nursing_question');
	}	
	else if($('nursing_question').style.display != 'none')
		new Effect.SlideUp('nursing_question');				

	var url = 'university-of-phoenix-ajax.php';
	var param = 'action=description&program_id=' + escape(programId);

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

/*
 * Update the program select list
 */
function update_program_list()
{
	var progSelIndex = $('program_id').selectedIndex;
	var programId = $('program_id').options[progSelIndex].value;
	var param = '';
	var url = 'university-of-phoenix-ajax.php';

	param += 'action=program_list&program_id='+escape(programId)+'&';
	param += 'zip='+escape($F('zip'))+'&category_id='+escape($F('category_id'))+'&';
	param += 'highesteducation='+escape($F('highesteducation'));

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