/*
 * STEP 1
 */
function enter_zip()
{
	if($F('zip') == "")
		return false;
	else if(!validateZip($F('zip')))
		return false;
		
	var url = 'strayer-university-ajax.php';
	var param = 'action=zip&form_step=1&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]/, '');
	degree_type = $('program_id').options[$('program_id').selectedIndex].getAttribute('degree');
	$('email').value = fixEmail($F('email'));
	
	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('employer') == "")
	{
		alert("Please enter an employer");
		$('employer').focus();
		return false;
	}
	else if(getCheckedValue(document.form_step1.military) == "")
	{
		alert("Please select your military affiliation");
		return false;
	}
	else if($F('education_level') == "")
	{
		alert("Please select the Highest Level of Education Completed");
		$('education_level').focus();
		return false;
	}
	else if($F('education_level') == 8)
	{
		alert("You must have a high school education to attend Strayer University");
		$('education_level').focus();
		return false;
	}
	else if($F('degree') == "")
	{
		alert("Please select a Degree of Interest");
		$('degree').focus();
		return false;
	}
	else if($('program_id').options.length == 0 || $F('program_id') == "")
	{
		alert("Please select a Program of Interest");
		$('program_id').focus();
		return false;
	}
	else if($('optin').checked == false)
	{
		alert("Please consent to being contacted by Strayer University");
		$('optin').focus();
		return false;
	}

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

	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');
	
	get_program_description(programId);
}


function get_program_description(programId)
{
	var url = 'strayer-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
		}
	);
}

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

	param += 'action=program_list&program_id='+programId+'&';
	param += 'alt_id='+escape($F('degree'))+'&state='+escape($F('state'))+'&';
	param += 'education_level='+escape($F('education_level'));

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

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