﻿<!-- 
function iA(){
 	this.length=iA.arguments.length;
 	for (var i=0;i<this.length;i++){
  		this[i]=iA.arguments[i];
  	}
 }
 
var pwr=new iA(10);  									
var dec=new iA(16);	
 									
pwr[0]=1;

for (var i=0;i<9;i++){
 	pwr[i+1]=pwr[i]*10;  									
}

dec[0]=.1;
dec[1]=.01;
dec[2]=.001;
dec[3]=.0001;
dec[4]=.00001;
dec[5]=.000001;
dec[6]=.0000001;
dec[7]=.00000001;
dec[8]=.000000001;
dec[9]=.0000000001;
dec[10]=.00000000001;
dec[11]=.000000000001;
dec[12]=.0000000000001;
dec[13]=.00000000000001;
dec[14]=.000000000000001;
dec[15]=.0000000000000001;								
 
var ns="01234567890";
var cr="";
var str="";

function floor(number){
	return Math.floor(number*Math.pow(10,2))/Math.pow(10,2);
}

function stn(){											//converts string to number by converting each character of the array into the 
 	num=0;												//corresponding placeholder value and adding the next converted character
 	pos=str.indexOf(".");								//ie "232150" converted into 200000 + 30000 + 2000 + 100 + 50 + 0 = 232150				
 	sfx="";		
														//this function also permits the user to enter decimal numbers
 	if (pos>-1){							
  		sfx=str.substring(pos+1,str.length); 	
  		str=str.substring(0,pos);				
  	}
	
 	strl=str.length;						
 	for (var i=strl-1;i>-1;i--){
  		cr=str.substring(i,i+1);				
  		pos=ns.indexOf(cr);
  		num+=pos*pwr[strl-i-1];				
  	}
	
  	if (sfx!=""&&sfx.length>dp){			
   		pos=ns.indexOf(sfx.charAt(dp+1));
   		if (pos>4){
    		pos=ns.indexOf(sfx.charAt(dp));
    		sfx=sfx.substring(0,dp-1)+(pos+1);
    	}
   	}
	
  	if (sfx!=""){
   		for (var i=0;i<dp;i++){
    		cr=sfx.substring(i,i+1);
    		pos=ns.indexOf(cr);
    		num+=pos*dec[i];
    	}
   	}
 }
 
function removeCommas(x) {
/****	freeware written and compiled by Réal Gagnon ©1998-2002
 		http://www.rgagnon.com/jsdetails/js-0063.html			****/
	var objRegExp = /,/g; 				  	  	//search for commas globally
  	var y = x.replace(objRegExp,'');  			//replace all matches with empty strings
  	return y;
}

function dosum(){
	var mi = $("#calc_txtInterestRate").val() / 1200;
	var base = 1;
	var mbase = 1 + mi;

	for (i=0; i<$("#calc_txtLoanLength").val() * 12; i++){
		base = base * mbase;
	}
	
	var bwd = 0;
	str=removeCommas($("#calc_txtLoanAmount").val());		//strip commas from the txtLoanAmount form field and assign to str
	bl=str.length+3;										//set "bl" equal to the length of "str" plus 3
	dp=2;													//account for strings with 2 decimal places
	stn();													//transform str into a numeric value
	bwd=str;												//assign bwd the value of str
	
	$("#calc_txtResult").val(floor(bwd * mi / ( 1 - (1/base))));
	//document.main.PI.value = floor(String(document.main.txtLoanAmount.value).replace(/\D/g,'') * mi / ( 1 - (1/base)));

}

function centerWindow(a,b) {
    if (document.all) {
        var xMax = screen.width;
		var yMax = screen.height;
   		var xOffset = (xMax - a)/2;
		var yOffset = (yMax - b)/2;

   	 	window.resizeTo(a,b);
		window.moveTo(xOffset,yOffset);
	}
}	
// -->

