// JavaScript Document

function advise_employment_length(value)
{
	notify_area = document.getElementById("js_employment_length");
	
	if (value == "Less Than 1 Year")
	{
		notify_area.innerHTML = "You must be employed for at least 2 years. It can be with different employers in the same line of work. If you attended college prior to employment, most Lenders find that acceptable.";
	}
	else
	{
		notify_area.innerHTML = "";
	}
}

function help(div)
{
	var target = document.getElementById(div);
	
	$(target).slideToggle("slow");
}

function quick_change()
	{
		var loan_type = document.getElementById('loan_type').value;
		var url = "";
		
		switch(loan_type)
		{
			case 'FHA Purchase':
				url = 'https://ratesarehot.com/application/fha-purchase';
				break;    
			case 'FHA Refinance':
				url = 'https://ratesarehot.com/application/fha-refinance';
				break;
			case 'Purchase A Home':
				url = 'https://ratesarehot.com/application/purchase';
				break; 
			case 'Lower Your Rate':
				url = 'https://ratesarehot.com/application/refinance';
				break;    
			case 'Cash Out Refinance':
				url = 'https://ratesarehot.com/application/cash-out';
				break;
			case 'Debt Consolidation':
				url = 'https://ratesarehot.com/application/debt-consolidation';
				break;    
			default:
				url = 'https://ratesarehot.com/application/purchase';
		}
		
		document.getElementById('quick_link').action = url;  
		document.getElementById('quick_link').submit();
	}
	
function backbutton(step)
{
	document.back_button.submit();
}

function next_phone(x, y)
{
	if (y.length == x.maxLength)
	{
		var next = x.tabIndex;
		if (next < document.getElementById("mortgage_form").length)
		{
			document.getElementById("mortgage_form").elements[next].focus();
		}
	}
}

function validate_gross_income()
{
	var gross_income = document.mortgage_form.gross_income.value;
	
	// characters being replaced
	bad_chars = /\$|-|,/g;
	
	// replace the characters with nothing
	gross_income = gross_income.replace(bad_chars, '');
	
	if (gross_income > 10000)
	{
		if (confirm("You have reported your monthly income as being greater than $10,000. Are you sure this is accurate?"))
		{
			if (validate_co_gross_income())
			{
				return true;
			}
			else
			{
				return false;
			}
			
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return true;
	}
}

function validate_co_gross_income(co_gross_income)
{
	var co_gross_income = document.mortgage_form.co_gross_income.value;
	
	// characters being replaced
	bad_chars = /\$|-|,/g;
	
	// replace the characters with nothing
	co_gross_income = co_gross_income.replace(bad_chars, '');
	
	if (co_gross_income > 10000)
	{
		if (confirm("You have reported your co-borrower's monthly income as being greater than $10,000. Are you sure this is accurate?"))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return true;
	}
}