function loanPurposeChange()
{
	var frm = document.applyform;
	var sIndicators = frm.StatesQuestionIndicators.value;
	var sCurrentPurpose;
	var bShouldRefresh = false;
	
	// If only first mortgages are enabled, we already
	// have the states displayed as they should be - exit
	if ( frm.onlyFirsts.value == "Y" )
	{
		return;
	}
	
	for ( var i = 0; i < frm.la_purpose.length; i++ )
	{
		if ( frm.la_purpose[i].checked )
		{
			sCurrentPurpose = frm.la_purpose[i].value;
		}
	}

	// if no change in purpose, just return
	if (sCurrentPurpose == frm.originalPurpose.value)
		return;
		
	// If the purpose has a state question associated with it, refresh to show
	if(sIndicators.indexOf(sCurrentPurpose)!= -1){
		bShouldRefresh = true;
	}
	
	// If the purpose has no question associated, but a question is currently showing, refresh to remove
	if(!bShouldRefresh && frm.StatesQuestionDisplayed.value == "Y"){
		bShouldRefresh = true;
	}

	// if loan purpose of purchase and RES is enabled, refresh to show RES question
	if (!bShouldRefresh && frm.DisplayRESQuestion.value == "Y" && (sCurrentPurpose == "1" || frm.originalPurpose.value == "1"))
	{
		bShouldRefresh = true;
	}
	
	if(bShouldRefresh){
		document.applyform.action = "/apply.asp";
		document.applyform.submit();
	}
}

function Continue()
{
	var frm = document.applyform;
	
	if ( frm.MembershipQuestionDisplayed.value == "Y" )
	{
		if ( (!frm.eligible[0].checked) && (!frm.eligible[1].checked) )
		{
			alert( "Please provide an answer for question #" + frm.MembershipQuestionNum.value + "." );
			return;
		}
		else if ( frm.eligible[1].checked )
		{
			window.location = frm.contactUsPage.value;
			return;
		}
	}
	
	var bPurposeAnswered = false;
	if (frm.la_purpose.length == undefined)
	{
		if (frm.la_purpose.checked)
		{
			bPurposeAnswered = true;
		}
	}
	else
	{
		for (var i = 0; i < frm.la_purpose.length; i++)
		{
			if (frm.la_purpose[i].checked)
			{
				bPurposeAnswered = true;
			}
		}
	}
	
	if ( bPurposeAnswered == false )
	{
		alert( "Please provide an answer for question #" + frm.PurposeQuestionNum.value + "." );
		return;
	}
	
	if ( frm.StatesQuestionDisplayed.value == "Y" )
	{
		if ( (!frm.stateCounty[0].checked) && (!frm.stateCounty[1].checked) )
		{
			alert( "Please provide an answer for question #" + frm.StatesQuestionNum.value + "." );
			return;
		}
		else if ( frm.stateCounty[1].checked )
		{
			window.location = frm.contactUsPage.value;
			return;
		}
	}
	
	frm.submit();
}

function onRESChange(response)
{
	var frm = document.applyform;
	var positiveRESAnswer = frm.PositiveRESAnswer.value;

	if (response == positiveRESAnswer)
		frm.PlaceRESOrder.value = "Y";
	else
		frm.PlaceRESOrder.value = "N";
}