addToOnLoad("TIAtotaliser");
String.prototype.isInt = function()
{
	return Trim(this) % 1 == 0 && Trim(this) != "";
}

function initTAI()
{	
	elmTAI = document.getElementById("appmodule-row-total");
}

function TIAtotaliser()
{
	// Check if joint app is selected
	var whichitem = 0;
	while (whichitem < document.affordCalc.jointApp.length) {

	    if (document.affordCalc.jointApp[whichitem].checked) {
	      var theitem = whichitem + 1;
	      }
	      whichitem++;
    	}
    	
    	// if theitem == 2 then it is a joint app
    	// make sure the totals only take into account applicant 2 values for a joint mortgage
    
	var form = document.affordCalc;
	var total = 0;
	if (form.annualSalary1.value.isInt())
	{
		total += parseInt(form.annualSalary1.value.replace(/\,/gi,''));
	}
	if (form.annualSalary2.value.isInt() && theitem == 2)
	{
		total += parseInt(form.annualSalary2.value.replace(/\,/gi,''));
	}
	if (form.otherIncome1.value.isInt())
	{
		total += parseInt(form.otherIncome1.value.replace(/\,/gi,''));
	}
	if (form.otherIncome2.value.isInt() && theitem == 2)
	{
		total += parseInt(form.otherIncome2.value.replace(/\,/gi,''));
	}
	elmTAI = document.getElementById("total-annual-income");
	elmTAI.innerHTML = ""; //Have to do this to stop ie5 breaking
	elmTAI.innerHTML = total;
}

function Trim(orgString){
  return LTrim(RTrim(orgString))
}
function LTrim(orgString){
  return orgString.replace(/\,/gi,'').replace(/^\s+/,'');
}

function RTrim(orgString){
  return orgString.replace(/\,/gi,'').replace(/\s+$/,'')
}


document.write('<sty'+  'le> .design-1a #appmodule-row-total {display:block;} !important </st'+ 'yle>');