function CalculatePayment()
{  
MyRate	= document.frm_Mortgage.txt_Int_Rate.value;
var str = document.frm_Mortgage.txt_Mort_Amount.value;
MyMort = str.replace(/,/,"");
MyMort = parseFloat(MyMort);
//document.frm_Mortgage.txt_Mort_Amount.value = addseps(MyMort);

if(!isNaN(MyMort) && !isNaN(MyRate))
  {if(MyMort!='' && MyRate!='') 
		{  	var L= MyMort; 						
		   	var R= MyRate;
			var Y;
for (var i=0; i<document.frm_Mortgage.Radio_Duration.length; i++)  
{  if (document.frm_Mortgage.Radio_Duration[i].checked)  {Y = document.frm_Mortgage.Radio_Duration[i].value}    } 
  			if (Y==0)  {Y = document.frm_Mortgage.txt_Mort_Duration.value}

			var C= R/1200;
			var K= C+1;
			var N= Y*12;
			
		   	var G=L*(C*(Math.pow(K,N))/(Math.pow(K,N)-1)); G=G.toFixed(2); 
			document.frm_Mortgage.txt_Pay_Monthly.value =  addseps(G);
			
			var H= G*12; H=H.toFixed(2);
			document.frm_Mortgage.txt_Pay_Yearly.value = addseps(H);
			
			var J= G*N; J=J.toFixed(2);
			document.frm_Mortgage.txt_Pay_Total.value =  addseps(J);
			
			document.frm_Mortgage.txt_Pay_No.value = N;
			
			var Z=J-(MyMort);Z=Z.toFixed(2);
			document.frm_Mortgage.txt_Int_Total.value = addseps(Z);
			
			var V=Z*100/(MyMort);
			document.frm_Mortgage.txt_Int_Per_Total.value =V.toFixed(2);
		}  
  else  {alert('Please Fill-in Mortgage Amount Field and Annual Interest Rate Field!');} 
  }
else  {alert('Please Enter ONLY Numbers into These Fields!');} 
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function CalculateMortgage()
{
MyRate	= document.frm_Mortgage.txt_Int_Rate.value;
var str = document.frm_Mortgage.txt_Pay_Monthly.value;
MyPay = str.replace(/,/,"");
MyPay = parseFloat(MyPay);
//document.frm_Mortgage.txt_Pay_Monthly.value = addseps(MyPay);

if(!isNaN(MyPay)&&!isNaN(MyRate))
  {if(MyPay!=''&&MyRate!='') 
  
		{  	var P=MyPay; 						
		   	var R=MyRate;
			var Y;
			
for (var i=0; i<document.frm_Mortgage.Radio_Duration.length; i++)  
{  if (document.frm_Mortgage.Radio_Duration[i].checked)  {Y = document.frm_Mortgage.Radio_Duration[i].value}    } 

  								if (Y==0)  {Y = document.frm_Mortgage.txt_Mort_Duration.value}
			var C=R/1200;
			var K=C+1; 
			var N=Y*12;
			
		   	var M=P*(((Math.pow(K,N))-1)/(C*(Math.pow(K,N)))); M = M.toFixed(2);
			document.frm_Mortgage.txt_Mort_Amount.value = addseps(M);

		   	var J=P*12; J=J.toFixed(2); 
			document.frm_Mortgage.txt_Pay_Yearly.value = addseps(J);
			
			var H=P*N; H=H.toFixed(2); 
			document.frm_Mortgage.txt_Pay_Total.value = addseps(H);
			
			document.frm_Mortgage.txt_Pay_No.value = N;
			
			var Z=H-M; Z=Z.toFixed(2);
			document.frm_Mortgage.txt_Int_Total.value = addseps(Z);
			
			var V=Z*100/M; V=V.toFixed(2);
			document.frm_Mortgage.txt_Int_Per_Total.value = addseps(V);

		}  
  else  {alert('Please Fill-in Monthly Payments Field and Annual Interest Rate Field!');} 
  }
else  {alert('Please Enter ONLY Numbers into The Fields!');} 
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function addseps(x) {
var x=x;								//make x a new variable
x+="";									//make x a string //or x=String(x);
iLen=x.length;							//iLen is the number of digits before any decimal point // for 45.123, iLen is 2 //iLen is the length of the number, if no decimals
pos=x.indexOf(".");
if (pos>-1){iLen=pos;} 					//If there are decimals //add the decimal point
temp="";
temp=x.substring(iLen,x.length);		//add the decimal part to begin // with 45.123, we add the .123
for (var i=iLen-1;i>=0;i--)				//iLen-1 is the rightmost non-decimal digit (5 in 98745.123)
//we add a separator when the expression (iLen-i-1)%3==0 is true...
//except when i is (iLen-1), or the first digit
//eg (98745.12). i is iLen-1, and the digit pos is next the decimal, 
//it is 5. From here, we decrement i...iLen-2, iLen-3, iLen-4 ... when i is a multiple of
//3, (i=iLen-iLen+4-1). This point is just before the number 7
if ((iLen-i-1)%3==0&&i!=iLen-1)
temp=x.charAt(i)+","+temp;
else
temp=x.charAt(i)+temp;
return temp;//end of addseps(x)
}