<!-- Calculate Housing Loan 

function removeCommas( strValue ) {

  var objRegExp = /,/g; //search for commas globally
 
  //replace all matches with empty strings
  return strValue.replace(objRegExp,'');
}

function addCommas( strValue ) {

  var objRegExp  = new RegExp('(-?[0-9]+)([0-9]{3})'); 

    //check for match to search criteria
    while(objRegExp.test(strValue)) {
       //replace original string with first group match, 
       //a comma, then second group match
       strValue = strValue.replace(objRegExp, '$1,$2');
    }
  return strValue;
}

function chkEmpty()
{
	if((document.forms.HomeDD_Borrow.elements.i1.value=="")
		||(document.forms.HomeDD_Borrow.elements.i3.value=="")
		||(document.forms.HomeDD_Borrow.elements.i4.value==""))	{
		alert('¡ÃØ³ÒãÊè Income, Tenor áÅÐ Interest Rate.');
		return false;
	}
	ErrorPrompt();
}

function ErrorPrompt()
{
	if (DigitCheck(removeCommas(document.forms.HomeDD_Borrow.elements.i1.value)) == "false")	{
		alert("¡ÃØ³ÒãÊè Income ãËé¶Ù¡µéÍ§")
		return false
	}
	if (DigitCheck(removeCommas(document.forms.HomeDD_Borrow.elements.i2.value)) == "false")	{
		alert("¡ÃØ³ÒãÊè Other Income ãËé¶Ù¡µéÍ§")
		return false
	}
	if (DigitCheck(document.forms.HomeDD_Borrow.elements.i3.value) == "false")	{
		alert("¡ÃØ³ÒãÊè Tenor ãËé¶Ù¡µéÍ§")
		return false
	}
	if (DigitCheck(document.forms.HomeDD_Borrow.elements.i4.value) == "false")	{
		alert("¡ÃØ³ÒãÊè Interest Rate ãËé¶Ù¡µéÍ§")
		return false
	}
	CalculateNow();
}

function CalculateNow()
{
	inIncome=parseFloat(removeCommas(document.forms.HomeDD_Borrow.elements.i1.value));
	inOtherIncome=parseFloat(removeCommas(document.forms.HomeDD_Borrow.elements.i2.value));
	inTenor=parseFloat(document.forms.HomeDD_Borrow.elements.i3.value);
	inInterest=parseFloat(document.forms.HomeDD_Borrow.elements.i4.value);

	income=inIncome+inOtherIncome;
	incomeChk="" + income;
	if (incomeChk.indexOf('NaN')>(-1))
		income=inIncome;
		Tenor=inTenor;
		intRate=inInterest;	
		PMT=income*0.35;
		n=Tenor*12;
		i=intRate/1200;
		Result = PMT*((1-(1/Math.pow((i+1),n)))/i);
		Pv =  twoPoint("" + Result);
		Pv = addCommas(Pv)
		PMT = "" + PMT;
		PMT = addCommas(PMT)
	if (Pv.indexOf('NaN')>(-1))
		document.forms.HomeDD_Borrow.elements.o1.value="Invalid Input";
	else
		document.forms.HomeDD_Borrow.elements.o1.value=Pv ;
		document.forms.HomeDD_Borrow.elements.o2.value=PMT ;

}

function DigitCheck(myValue)
{
	i=0
	sValue = "" + myValue
	for(i=0;i<sValue.length;i++)	{
		aChar=sValue.substring(i,i+1)
		if (aChar != "." && (aChar < '0'  || aChar > '9'))	{
		        return "false"
		}
	}
}

function twoPoint(value){
	finaltotal = "" + value;
	getPoint=finaltotal.indexOf(".");
	getLength=finaltotal.length;
	if((getPoint > 0) && (getLength > getPoint+3)) 
	{
	 	if(parseInt((finaltotal.substring(getPoint+4,getPoint+5))) >= 5);
		{
			extenPoint = finaltotal.substring(getPoint+3,getPoint+4);
			finaltotal=finaltotal.substring(0,getPoint+3);
			if (parseInt(extenPoint) >= 5)
			{
				finaltotal=parseFloat(finaltotal) + 0.01;
				finaltotal="" + finaltotal;
			}
			else
				finaltotal="" + finaltotal;
			finaltotal=finaltotal.substring(0,getPoint+3);
		}
	}
	if (finaltotal.indexOf(".")<0)
		finaltotal=finaltotal+".00"
	return finaltotal;
}

function ClearForm(form){
document.HomeDD_Borrow.i1.value="";
document.HomeDD_Borrow.i2.value="";
document.HomeDD_Borrow.i3.value="";
document.HomeDD_Borrow.i4.value = "";
document.HomeDD_Borrow.o1.value = "";
document.HomeDD_Borrow.o2.value = "";
}

-->
