<!--
var iMinTerm = 12;
var iPLoanTermCutOff = 60;

var iBorrowAmountValue = 0;
var iRepaymentTermValue = 0;

var sBorrowAmountValue = 0;
var sRepaymentTermValue = 0;
var bInsuranceValueYes = false;
var bInsuranceValueNo = false;
var bWithInsurance = false;
var bIsInSecuredRange = false;

var iMinSecuredLoanAmount = 5000;
var iMinAnyLoanAmount = 1000;

var oForm;
var oBorrowAmountValueInput;
var oRepaymentTermValue;
var oInsuranceValueYes;
var oInsuranceValueNo;

var sPoundSign = '\u00a3';

var sUserAgent = navigator.userAgent;

function submitCalc()
{
    getValues();
    return validateLoanCalcForm();
}

function getValues()
{
    oForm = document.forms[0];
    sBorrowAmountValue = 0;
    sRepaymentTermValue = 0;
    bInsuranceValueYes = false;
    bInsuranceValueNo = false;
    bWithInsurance = false;
    var arInputs = oForm.getElementsByTagName("input");
    var oInput;
    for (var iIx = 0; iIx < arInputs.length; iIx++) {
        //alert('typeof(arInputs[' + iIx + '].id) - ' + typeof(arInputs[iIx].id) + '\narInputs[iIx].id - ' + arInputs[iIx].id);
        if ('undefined' != typeof(arInputs[iIx].id)) {
            oInput = arInputs[iIx];
            if ((-1 != oInput.id.indexOf('BorrowAmountValue'))) {
                oBorrowAmountValueInput = oInput;
                sBorrowAmountValue = oInput.value;
            }
            if (-1 != oInput.id.indexOf('InsuranceValueYes')) {
                oInsuranceValueYes = oInput;
                bInsuranceValueYes = oInput.checked;
                bWithInsurance = true;
            }
            if (-1 != oInput.id.indexOf('InsuranceValueNo')) {
                oInsuranceValueNo = oInput;
                bInsuranceValueNo = oInput.checked;
                bWithInsurance = true;
            }
        }
    }
    var arSelects = oForm.getElementsByTagName("select");
    var oSelect;
    for (var iIx = 0; iIx < arSelects.length; iIx++) {
//        alert('typeof(arSelects[' + iIx + '].id) - ' + typeof(arSelects[iIx].id) + '\narSelects[iIx].id - ' + arSelects[iIx].id + '\narSelects[iIx].id.indexOf(RepaymentTermValue)' + arSelects[iIx].id.indexOf('RepaymentTermValue'));
        if ('undefined' != typeof(arSelects[iIx].id)) {
            oSelect = arSelects[iIx];
            if (-1 != oSelect.id.indexOf('RepaymentTermValue')) {
                sRepaymentTermValue = oSelect.options[oSelect.selectedIndex].value;
                oRepaymentTermValue = oSelect;
                //alert('sRepaymentTermValue - ' + sRepaymentTermValue);
            }
        }
    }
    iBorrowAmountValue = 0;
    iRepaymentTermValue = 0;
	if (!isNaN(sBorrowAmountValue)) iBorrowAmountValue = parseInt(sBorrowAmountValue,10);
	if (isNaN(iBorrowAmountValue)) iBorrowAmountValue = 0;
	if (!isNaN(sRepaymentTermValue)) iRepaymentTermValue = parseInt(sRepaymentTermValue);
	if (isNaN(iRepaymentTermValue)) iRepaymentTermValue = 0;
	bIsInSecuredRange = false;
	if ((iRepaymentTermValue > iMaxPLoanTerm) || (iBorrowAmountValue > iMaxPLoanAmount))
	{
	    bIsInSecuredRange = true;
	}
}

function validateLoanCalcForm()
{
	if (isNaN(sBorrowAmountValue))
	{
		alert('Please enter a numeric amount you want to borrow, thankyou.');
		oBorrowAmountValueInput.focus();
		return false;
	}
    
	if (isNaN(sRepaymentTermValue))
	{
		alert('Please select a loan term, thankyou.');
		oBorrowAmountValueInput.focus();
		oBorrowAmountValueInput.select();
		return false;
	}
    
	if (iBorrowAmountValue == 0)
	{
		alert('Please enter the amount you want to borrow, thankyou.');
		oBorrowAmountValueInput.focus();
		return false;
	}
    
	if (iBorrowAmountValue < iMinAmount)
	{
		alert('Loans are available from ' + sPoundSign + iMinAmount + ', please adjust the amount you want to borrow, thankyou.');
		oBorrowAmountValueInput.focus();
		oBorrowAmountValueInput.select();
		return false;
	}
    
	if (iBorrowAmountValue > iMaxAnyLoanAmount)
	{
		alert('Loans are available up to ' + sPoundSign + iMaxAnyLoanAmount + ', please adjust the amount you want to borrow, thankyou.');
		oBorrowAmountValueInput.focus();
		oBorrowAmountValueInput.select();
		return false;
	}

	if (iRepaymentTermValue == 0)
	{
		alert('Please select a loan term, thankyou.');
		oRepaymentTermValue.focus();
		return false;
	}
	if (!bIsSecured)
	{
	    if ((iRepaymentTermValue > iPLoanTermCutOff) && (iBorrowAmountValue < iMinSecuredLoanAmount))
	    {
  		    alert('Loans from ' + sPoundSign + iMinAnyLoanAmount + ' to ' + sPoundSign + (iMinSecuredLoanAmount - 1) + ' are only available over terms between ' + iMinTerm + ' and ' + iPLoanTermCutOff + ' months, please adjust your term.');
		    oRepaymentTermValue.focus();
  		    return false;
	    }
	    //alert('iRepaymentTermValue - ' + iRepaymentTermValue + '\niPLoanTermCutOff - ' + iPLoanTermCutOff + '\niBorrowAmountValue - ' + iBorrowAmountValue + '\niMaxPLoanAmount - ' + iMaxPLoanAmount);
	    if ((iRepaymentTermValue < iPLoanTermCutOff) && (iBorrowAmountValue > iMaxPLoanAmount))
	    {
  		    alert('Loans over ' + sPoundSign + iMaxPLoanAmount + ' are only available for terms of ' + iMaxPLoanTerm + ' months or over, please adjust your term.');
		    oRepaymentTermValue.focus();
  		    return false;
	    }
	    if (bWithInsurance) {
	        //alert('bInsuranceValueYes - ' + bInsuranceValueYes + '\nbInsuranceValueNo - ' + bInsuranceValueNo);
	        if (!(bInsuranceValueYes || bInsuranceValueNo)) {
		        alert('Please indicate if you want to see your loan quote with or without loan protection.');
		        return false;
	        }
	    }
	}
	return true;
}

function checkProtection() {
    getValues();
    if (!bWithInsurance) return true;
	oInsuranceValueYes.disabled = false;
	oInsuranceValueNo.disabled = false;
	oInsuranceValueYes.title = 'With loan protection';
	oInsuranceValueNo.title = 'Without loan protection';
	if (bIsInSecuredRange) {
		noProtection();
	}
}

function noProtection() {
	var sNoProtectionTitle = 'All our secured loan calculations are quoted without payment protection insurance';
	oInsuranceValueYes.checked = false;
	oInsuranceValueNo.checked = true;
	oInsuranceValueYes.disabled = true;
	oInsuranceValueNo.disabled = true;
	oInsuranceValueYes.title = sNoProtectionTitle;
	oInsuranceValueNo.title = sNoProtectionTitle;
}

//-->


