<!--
var strHTML = "";

function incomeChanged(item)
{
	if (isNaN(item.value))
	{
		item.value = "";
	}
	processInAndOut('income');
}

function numberCreditorsChanged(item)
{
	if (isNaN(item.value))
	{
		item.value = "";
	}
	else
	{
		if (item.value <= 20)
		{
			var theCreditorLabel;
			var theCreditorInput;
			var theOwedLabel;
			var theOwedInput;
			var theMonthlyPaymentLabel;
			var theMonthlyPaymentInput;
		
			for (intPos = 1; intPos <= 20; intPos++)
			{
				var spanCreditorLabel = eval('spanCreditorLabel' + intPos);
				var spanCreditorInput = eval('spanCreditorInput' + intPos);
				var spanOwedLabel = eval('spanOwedLabel' + intPos);
				var spanOwedInput = eval('spanOwedInput' + intPos);
				var spanMonthlyPaymentLabel = eval('spanMonthlyPaymentLabel' + intPos);
				var spanMonthlyPaymentInput = eval('spanMonthlyPaymentInput' + intPos);
			
				if (parseInt(item.value) >= intPos)
				{
					theCreditorLabel = " - Creditor";
					theCreditorInput = "<INPUT class=\"bodytext\"  type=\"text\" name=\"inpCreditor" + intPos + "\" id=\"inpCreditor" + intPos + "\" onkeyup=\"creditorNameChanged(this);\">";
					theOwedLabel = " Amount Owed";
					theOwedInput = "<INPUT style=\"text-align:right\" class=\"formrightalign\"  type=\"text\" size=\"10\" name=\"inpOwed" + intPos + "\" id=\"inpOwed" + intPos + "\" onkeyup=\"amountOwedChanged(this);\">";
					theMonthlyPaymentLabel = "Monthly Payment";
					theMonthlyPaymentInput = "<INPUT style=\"text-align:right\" class=\"formrightalign\"  type=\"text\" size=\"10\" name=\"inpMonthlyPayment" + intPos + "\" id=\"inpMonthlyPayment" + intPos + "\" onkeyup=\"monthlyPaymentChanged(this);\">";
				}
				else
				{
					var theCreditorLabel = "";
					var theCreditorInput = "";
					var theOwedLabel = "";
					var theOwedInput = "";
					var theMonthlyPaymentLabel = "";
					var theMonthlyPaymentInput = "";
				}
				
				spanCreditorLabel.innerHTML = theCreditorLabel;
				spanCreditorInput.innerHTML = theCreditorInput;
				spanOwedLabel.innerHTML = theOwedLabel;
				spanOwedInput.innerHTML = theOwedInput;
				spanMonthlyPaymentLabel.innerHTML = theMonthlyPaymentLabel;
				spanMonthlyPaymentInput.innerHTML = theMonthlyPaymentInput;
			}
		}
	}
}

function expenditureChanged(item)
{
	if (isNaN(item.value))
	{
		item.value = "";
	}
	processInAndOut('expenditure');
}

function creditorNameChanged(item)
{
	var theID = "hid_" + item.name;
	eval('document.frmCalculator.' + theID).value = item.value;
}

function amountOwedChanged(item)
{
	if (isNaN(item.value))
	{
		item.value = "";
	}
	
	var theID = "hid_" + item.name;
	eval('document.frmCalculator.' + theID).value = item.value;
	
	processAmountOwed();
}

function monthlyPaymentChanged(item)
{
	if (isNaN(item.value))
	{
		item.value = "";
	}
	
	var theID = "hid_" + item.name;
	eval('document.frmCalculator.' + theID).value = item.value;
	
	processMonthlyPayments();
}

function processInAndOut(direction)
{
	var fltTotalIncome = getTotalIncome();
	var fltTotalExpenditure = getTotalExpenditure();
	var fltDisposableIncome = parseFloat(fltTotalIncome) - parseFloat(fltTotalExpenditure);

	if (direction == "income")
	{	
		document.frmCalculator.inpTotalIncome.value = formatCurrency2(fltTotalIncome);
	}
	else
	{
		document.frmCalculator.inpTotalExpenditure.value = formatCurrency2(fltTotalExpenditure);
	}
	document.frmCalculator.hidDisposableIncome.value = formatCurrency2(fltDisposableIncome);
	disposableIncomeDiv.innerHTML = formatCurrency(fltDisposableIncome);
}

function processAmountOwed()
{
	var fltTotalAmountOwed = getTotalOwed();

	document.frmCalculator.inpTotalDebts.value = formatCurrency2(fltTotalAmountOwed);
	totalOwedCreditorsDiv.innerHTML = formatCurrency(fltTotalAmountOwed);
}

function processMonthlyPayments()
{
	var fltMonthlyPayments = getTotalMonthlyPayments();

	document.frmCalculator.inpTotalPayments.value = formatCurrency2(fltMonthlyPayments);
	monthlyPaymentsCreditorsDiv.innerHTML = formatCurrency(fltMonthlyPayments);
}

//generic donkey functions (adding and formatting):

function getTotalIncome()
{
	var fltYourTakeHomePay = parseFloat("0" + document.frmCalculator.inpYourTakeHomePay.value);
	var fltPartnersTakeHomePay = parseFloat("0" + document.frmCalculator.inpPartnersTakeHomePay.value);
	var fltOtherTakeHomePay = parseFloat("0" + document.frmCalculator.inpOtherTakeHomePay.value);
	var fltAddTakeHomePay1 = parseFloat("0" + document.frmCalculator.inpAddTakeHomePay1.value);
	var fltAddTakeHomePay2 = parseFloat("0" + document.frmCalculator.inpAddTakeHomePay2.value);
			
	var fltTotalIncome = fltYourTakeHomePay + fltPartnersTakeHomePay + fltOtherTakeHomePay + fltAddTakeHomePay1 + fltAddTakeHomePay2;
	return fltTotalIncome;
}

function getTotalExpenditure()
{
	var fltMortgageRent = parseFloat("0" + document.frmCalculator.inpMortgageRent.value);
	var fltSecuredLoan = parseFloat("0" + document.frmCalculator.inpSecuredLoan.value);
	var fltInsurance = parseFloat("0" + document.frmCalculator.inpInsurance.value);
	var fltFoodHousekeeping = parseFloat("0" + document.frmCalculator.inpHousekeeping.value);
	var fltCouncilTax = parseFloat("0" + document.frmCalculator.inpCouncilTax.value);
	var fltWaterRates = parseFloat("0" + document.frmCalculator.inpWaterRates.value);
	var fltElectricity = parseFloat("0" + document.frmCalculator.inpElectricity.value);
	var fltGas = parseFloat("0" + document.frmCalculator.inpGas.value);
	var fltTelephone = parseFloat("0" + document.frmCalculator.inpTelephone.value);
	var fltMobile = parseFloat("0" + document.frmCalculator.inpMobile.value);
	var fltTVLicence = parseFloat("0" + document.frmCalculator.inpTVLicence.value);
	var fltLifePolicy = parseFloat("0" + document.frmCalculator.inpLifePolicy.value);
	var fltPersonalPension = parseFloat("0" + document.frmCalculator.inpPersonalPension.value);
	var fltCarPetrol = parseFloat("0" + document.frmCalculator.inpCarPetrol.value);
	var fltCarServicing = parseFloat("0" + document.frmCalculator.inpCarServicing.value);
	var fltCarInsurance = parseFloat("0" + document.frmCalculator.inpCarInsurance.value);
	var fltCarRoadTax = parseFloat("0" + document.frmCalculator.inpCarRoadTax.value);
	var fltCarHP = parseFloat("0" + document.frmCalculator.inpCarHP.value);
	var fltPublicTransport = parseFloat("0" + document.frmCalculator.inpPublicTransport.value);
	var fltChildcare = parseFloat("0" + document.frmCalculator.inpChildcare.value);
	var fltMedicalDental = parseFloat("0" + document.frmCalculator.inpMedicalDental.value);
	var fltClothing = parseFloat("0" + document.frmCalculator.inpClothing.value);
	var fltHousekeepingMaintenance = parseFloat("0" + document.frmCalculator.inpHouseholdMaintenance.value);
	var fltAddExpenditure1 = parseFloat("0" + document.frmCalculator.inpAddExpenditure1.value);
	var fltAddExpenditure2 = parseFloat("0" + document.frmCalculator.inpAddExpenditure2.value);

	var fltTotalExpenditure = fltMortgageRent + fltSecuredLoan + fltInsurance + fltFoodHousekeeping + fltCouncilTax + fltWaterRates + fltElectricity + fltGas + fltTelephone + fltMobile + fltTVLicence + fltLifePolicy + fltPersonalPension + fltCarPetrol + fltCarServicing + fltCarInsurance + fltCarRoadTax + fltCarHP + fltPublicTransport + fltChildcare + fltMedicalDental + fltClothing + fltHousekeepingMaintenance + fltAddExpenditure1 + fltAddExpenditure2;
	return fltTotalExpenditure;
}

function getTotalOwed()
{
	var fltTotalOwed = 0;

	for (intPos = 1; intPos <= parseInt(document.frmCalculator.inpNumberCreditors.value); intPos++)
	{
		fltTotalOwed = parseFloat("0" + fltTotalOwed) + parseFloat("0" + eval('document.frmCalculator.inpOwed' + intPos).value);
	}
	return fltTotalOwed;
}

function getTotalMonthlyPayments()
{
	var fltTotalMonthlyPayments = 0;

	for (intPos = 1; intPos <= parseInt(document.frmCalculator.inpNumberCreditors.value); intPos++)
	{
		fltTotalMonthlyPayments = parseFloat("0" + fltTotalMonthlyPayments) + parseFloat("0" + eval('document.frmCalculator.inpMonthlyPayment' + intPos).value);
	}
	return fltTotalMonthlyPayments;
}

function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	pennies = num%100;
	num = Math.floor(num/100).toString();
	if(pennies<10)
	pennies = "0" + pennies;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));

	if ((sign)?fontIs='':fontIs='#CC0000');
		
	return ('<FONT color=' + fontIs + '>' + ((sign)?'':'-') + '£' + num + '.' + pennies + '</FONT>');
}

function formatCurrency2(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	pennies = num%100;
	num = Math.floor(num/100).toString();
	if(pennies<10)
	pennies = "0" + pennies;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));

	if ((sign)?fontIs='':fontIs='#CC0000');
		
	return (((sign)?'':'-') + '£' + num + '.' + pennies);
}

function openWin()
{
	window.open("../../includes/html/collect_details.asp", "Send_To_The_Debt_Advisor", "width=420,height=220");
}

function checkCollectDetails()
{
	if (document.frmCollectDetails.inpName.value == "")
	{
		alert("Please enter your name");
		document.frmCollectDetails.inpName.focus();
		return false;
	}
	if (document.frmCollectDetails.inpTel.value == "")
	{
		alert("Please enter your telephone number");
		document.frmCollectDetails.inpTel.focus();
		return false;
	}
	if (document.frmCollectDetails.inpEmail.value == "")
	{
		alert("Please enter your email address");
		document.frmCollectDetails.inpEmail.focus();
		return false;
	}
	if (document.frmCollectDetails.chkAgree.checked)
	{
	}
	else
	{
		alert("Please agree to terms and conditions");
		return false;
	}
	parent.opener.document.frmCalculator.hidName.value = document.frmCollectDetails.inpName.value;
	parent.opener.document.frmCalculator.hidTel.value = document.frmCollectDetails.inpTel.value;
	parent.opener.document.frmCalculator.hidEmail.value = document.frmCollectDetails.inpEmail.value;
	parent.opener.document.frmCalculator.submit();
	window.close();
}
//-->