var IsSecureFix = false;
var LoanType = '';

function showlayer(nextfld, fldID) 
{
	if ( document.getElementById("fldPurpose").value == "1_Purchase" && document.getElementById("fldBorrow").value >= 10000 && fldID == "layerSecurity" )
	{
		document.getElementById("layerRepayments_1").style.visibility = "hidden";
		document.getElementById(fldID).style.visibility = "visible";
	}  
	else if ( fldID == "layerSecurity" )
	{
		document.getElementById(fldID).style.visibility = "hidden";
		document.getElementById("layerRepayments_1").style.visibility = "visible";

		document.getElementById("layerRepayments_1").style.top = "-40px";
		document.getElementById("layerRepayments_2").style.top = "-40px";
		document.getElementById("layerRepayments_3").style.top = "-40px";

		document.getElementById("layerIndex_4").innerHTML = "<b>3. </b>";
		document.getElementById("layerIndex_5").innerHTML = "<b>4. </b>";
		document.getElementById("layerIndex_6").innerHTML = "<b>5. </b>";
	}
	else
	{
		if ( document.getElementById("fldSecurity").value == "3_Yes" )
		{
			LoanType = "FRS";
			document.getElementById("lblLoanType").innerHTML = " <b>Car Loan (Fixed Rate Secured)</b>";
			document.getElementById("lblLoanTypeSummary").innerHTML = "<p align='justify'><b>Car Loan (Fixed Rate Secured):</b><br />With a Commonwealth Bank Car Loan (Fixed Rate Secured) Loan you can borrow from $10,000 (with no maximum borrowing amount)  to buy your dream car with terms of 1, 2, 3, 4 or 5 years. This is a secured Fixed Rate Loan which means that we would take security over your purchased vehicle.</p>";
			document.getElementById("layerResult").style.visibility = "visible";
			IsSecureFix = true;
			document.getElementById(nextfld).disabled = true;
			document.getElementById("btnSubmit").value=" Select Again ";
			document.getElementById("btnRedirect").style.visibility='visible';
			document.getElementById("btnCrs").style.visibility='visible';

			return;
		} 
		else if (document.getElementById("fldSecurity").value == "3_NotSure")
		{
			IsSecureFix = true;
		}
		else if (document.getElementById("fldSecurity").value == "3_No")
		{
			IsSecureFix = false;
		}

		if ( document.getElementById("fldRepayments_1").value == "4_Yes" || document.getElementById("fldRepayments_2").value == "5_No" || document.getElementById("fldRepayments_3").value == "6_No" )
		{
			if (IsSecureFix == true)
			{
				LoanType = "FRS";
				document.getElementById("lblLoanType").innerHTML = " <b>Car Loan (Fixed Rate Secured)</b>";
				document.getElementById("lblLoanTypeSummary").innerHTML = "<p align='justify'><b>Car Loan (Fixed Rate Secured):</b><br />With a Commonwealth Bank Car Loan (Fixed Rate Secured) Loan you can borrow from $10,000 (with no maximum borrowing amount)  to buy your dream car with terms of 1, 2, 3, 4 or 5 years. This is a secured Fixed Rate Loan which means that we would take security over your purchased vehicle.</p>";
				document.getElementById("layerResult").style.visibility = "visible";
				document.getElementById("btnCrs").style.visibility='visible';
				document.getElementById("btnApplyNow").style.visibility='visible';
			} 
			else 
			{
				LoanType = "FR";
				document.getElementById("lblLoanType").innerHTML = " <b>Fixed Rate Personal Loan</b>";
				document.getElementById("lblLoanTypeSummary").innerHTML = "<p align='justify'><b>Fixed Rate Personal Loan:</b><br />With a Commonwealth Bank Fixed Rate Personal Loan you can borrow from $5000 ($50,000 maximum) with terms of 1, 2, 3, 4, 5, 6  7 years. This is an unsecured Fixed Rate Personal Loan.</p>";
				document.getElementById("layerResult").style.visibility = "visible";
				document.getElementById("btnCrs").style.visibility='visible';
				document.getElementById("btnApplyNow").style.visibility='visible';
			}

			document.getElementById(nextfld).disabled = true;
			document.getElementById("btnSubmit").value=" Select Again ";
			document.getElementById("btnRedirect").style.visibility='visible';
			document.getElementById("btnApplyNow").style.visibility='visible';

			return;
		}
		else if (document.getElementById("fldRepayments_1").value == "4_No" || document.getElementById("fldRepayments_2").value == "5_Yes" || document.getElementById("fldRepayments_3").value == "6_Yes" || document.getElementById("fldRepayments_3").value == "6_NotSure")
		{
			LoanType = "VR";
			document.getElementById("lblLoanType").innerHTML = " <b>Variable Rate Personal Loan</b>";
			document.getElementById("lblLoanTypeSummary").innerHTML = "<p align='justify'><b>Variable Rate Personal Loan:</b><br />With a Commonwealth Bank Variable Rate Personal Loan you can borrow from $5000 ($50,000 maximum) with terms of 1, 2, 3, 4, 5, 6  7 years. This is an unsecured Variable Rate Personal Loan with no deposit requirements and no early repayment fee.</p>";
			document.getElementById("layerResult").style.visibility = "visible";
			document.getElementById(nextfld).disabled = true;
			document.getElementById("btnSubmit").value=" Select Again ";
			document.getElementById("btnRedirect").style.visibility='visible';
			document.getElementById("btnCrs").style.visibility='visible';
			document.getElementById("btnApplyNow").style.visibility='visible';

			return;
		}

		document.getElementById(fldID).style.visibility = "visible";
		document.getElementById("layerResult").style.visibility = "hidden";
		document.getElementById(nextfld).disabled = false;
	}
}

function Page_Redirect() 
{
	switch (LoanType)
	{
		case "FRS":
			window.open("/Personal/PersonalLending/FixedRateSecured.asp", target="_blank");
			break;
		case "FR":
			window.open("/Personal/PersonalLending/FixedRate.asp", target="_blank");
			break;
		case "VR":
			window.open("/Personal/PersonalLending/VariableRate.asp", target="_blank");
			break;
		default:
			alert("Please first select the product.");
	}
}

function Open_CRS(VR_webaddress, FR_webaddress, FRS_webaddress) 
{
	switch (LoanType)
	{
		case "FRS":
			window.open("/schedule/"+FRS_webaddress, target="_blank");
			break;
		case "FR":
			window.open("/schedule/"+FR_webaddress, target="_blank");
			break;
		case "VR":
			window.open("/schedule/"+VR_webaddress, target="_blank");
			break;
		default:
			alert("Please first select the product.");
	}
}

function isNumeric(fld) 
{
	var numb = '0123456789';
	fldval = fld.value;
	if (fldval <= 499 || fldval >= 1000001)
	{
		alert("Please enter a value between $500 and $1,000,000.");
		fld.focus();
		fld.select();

		return false;
	}

	for (i = 0; i < fldval.length; i++) 
	{
		if (numb.indexOf(fldval.charAt(i),0) == -1)
		{
			alert("The amount you wish to borrow must be numeric.");
			fld.focus();
			fld.select();

			return false;
		}
	}
    showlayer('fldSecurity', 'layerSecurity');
	fld.disabled = true;

	return true;
}

