
function validate_get_premium(){
	//first fix up some vars
	document.mod_rttitle_calc_form.policy_amount.value = document.mod_rttitle_calc_form.policy_amount.value.replace( /,/g, "" );
	return get_premium( document.mod_rttitle_calc_form.policy_amount.value );
}

function get_premium( amount ){
	//alert( "get_premium("+amount+")" );
	var result = "";
	if( amount >= 100001 && amount <= 1000000 ){
		//alert( amount+" >= 100001 && "+amount+" <= 1000000" );
		result = (amount - 100000) * 0.00534;
		result = Math.round( result );
		result += 843;
	}
	else if( amount >= 1000001 && amount <= 5000000 ){
		//alert( amount+" >= 1000001 && "+amount+" <= 5000000" );
		result = (amount - 1000000) * 0.00439;
		result = Math.round( result );
		result += 5649;
	}
	else if( amount >= 5000001 && amount <= 15000000 ){
		//alert( amount+" >= 5000001 && "+amount+" <= 15000000" );
		result = (amount - 5000000) * 0.00362;
		result = Math.round( result );
		result += 23209;
	}
	else if( amount >= 15000001 && amount <= 25000000 ){
		//alert( amount+" >= 15000001 && "+amount+" <= 25000000" );
		result = (amount - 15000000) * 0.00257;
		result = Math.round( result );
		result += 59409;
	}
	else if( amount > 25000000 ){
		//alert( amount+" > 25000000" );
		result = (amount - 25000000) * 0.00154;
		result = Math.round( result );
		result += 85109;
	}
	else result = do_lookup( amount );
	result = Math.round( result );
	document.mod_rttitle_calc_form.premium.value = result;
}

function do_lookup( amount ){
	//alert( "do_lookup("+amount+")" );
	if( amount <= 10000 ) return 237;
	var table = new Object();
	table[10000] = 229;
	table[10500] = 233;
	table[11000] = 235;
	table[11500] = 239;
	table[12000] = 243;
	table[12500] = 246;
	table[13000] = 250;
	table[13500] = 254;
	table[14000] = 257;
	table[14500] = 260;
	table[15000] = 262;
	table[15500] = 266;
	table[16000] = 270;
	table[16500] = 274;
	table[17000] = 277;
	table[17500] = 281;
	table[18000] = 285;
	table[18500] = 287;
	table[19000] = 290;
	table[19500] = 293;
	table[20000] = 298;
	table[20500] = 301;
	table[21000] = 305;
	table[21500] = 308;
	table[22000] = 312;
	table[22500] = 315;
	table[23000] = 318;
	table[23500] = 321;
	table[24000] = 325;
	table[24500] = 328;
	table[25000] = 332;
	table[25500] = 335;
	table[26000] = 339;
	table[26500] = 342;
	table[27000] = 345;
	table[27500] = 348;
	table[28000] = 352;
	table[28500] = 355;
	table[29000] = 359;
	table[29500] = 362;
	table[30000] = 366;
	table[30500] = 369;
	table[31000] = 373;
	table[31500] = 376;
	table[32000] = 379;
	table[32500] = 383;
	table[33000] = 386;
	table[33500] = 390;
	table[34000] = 393;
	table[34500] = 397;
	table[35000] = 400;
	table[35500] = 404;
	table[36000] = 407;
	table[36500] = 410;
	table[37000] = 413;
	table[37500] = 417;
	table[38000] = 421;
	table[38500] = 425;
	table[39000] = 427;
	table[39500] = 431;
	table[40000] = 434;
	table[40500] = 438;
	table[41000] = 440;
	table[41500] = 445;
	table[42000] = 448;
	table[42500] = 452;
	table[43000] = 454;
	table[43500] = 458;
	table[44000] = 461;
	table[44500] = 465;
	table[45000] = 469;
	table[45500] = 472;
	table[46000] = 475;
	table[46500] = 479;
	table[47000] = 481;
	table[47500] = 485;
	table[48000] = 489;
	table[48500] = 493;
	table[49000] = 496;
	table[49500] = 499;
	table[50000] = 503;
	table[50500] = 506;
	table[51000] = 508;
	table[51500] = 512;
	table[52000] = 516;
	table[52500] = 520;
	table[53000] = 523;
	table[53500] = 527;
	table[54000] = 530;
	table[54500] = 533;
	table[55000] = 536;
	table[55500] = 539;
	table[56000] = 544;
	table[56500] = 547;
	table[57000] = 550;
	table[57500] = 554;
	table[58000] = 558;
	table[58500] = 560;
	table[59000] = 564;
	table[59500] = 567;
	table[60000] = 571;
	table[60500] = 575;
	table[61000] = 578;
	table[61500] = 581;
	table[62000] = 585;
	table[62500] = 589;
	table[63000] = 591;
	table[63500] = 594;
	table[64000] = 598;
	table[64500] = 602;
	table[65000] = 605;
	table[65500] = 608;
	table[66000] = 612;
	table[66500] = 617;
	table[67000] = 620;
	table[67500] = 621;
	table[68000] = 625;
	table[68500] = 629;
	table[69000] = 632;
	table[69500] = 635;
	table[70000] = 640;
	table[70500] = 644;
	table[71000] = 647;
	table[71500] = 649;
	table[72000] = 652;
	table[72500] = 656;
	table[73000] = 660;
	table[73500] = 663;
	table[74000] = 667;
	table[74500] = 671;
	table[75000] = 674;
	table[75500] = 676;
	table[76000] = 680;
	table[76500] = 683;
	table[77000] = 687;
	table[77500] = 690;
	table[78000] = 694;
	table[78500] = 698;
	table[79000] = 702;
	table[79500] = 703;
	table[80000] = 707;
	table[80500] = 711;
	table[81000] = 715;
	table[81500] = 717;
	table[82000] = 721;
	table[82500] = 725;
	table[83000] = 729;
	table[83500] = 731;
	table[84000] = 734;
	table[84500] = 739;
	table[85000] = 742;
	table[85500] = 745;
	table[86000] = 748;
	table[86500] = 752;
	table[87000] = 756;
	table[87500] = 759;
	table[88000] = 762;
	table[88500] = 766;
	table[89000] = 770;
	table[89500] = 772;
	table[90000] = 775;
	table[90500] = 779;
	table[91000] = 783;
	table[91500] = 787;
	table[92000] = 789;
	table[92500] = 793;
	table[93000] = 797;
	table[93500] = 801;
	table[94000] = 802;
	table[94500] = 806;
	table[95000] = 811;
	table[95500] = 814;
	table[96000] = 816;
	table[96500] = 820;
	table[97000] = 824;
	table[97500] = 828;
	table[98000] = 830;
	table[98500] = 834;
	table[99000] = 838;
	table[99500] = 841;
	table[100000] = 843;
	
	ceiled_amount = Math.ceil( amount/Math.pow(10,3) ) * Math.pow(10,3);
	ceiled_amount_minus_500 = ceiled_amount - 500;
	while( amount <= ceiled_amount_minus_500 ){
		ceiled_amount = ceiled_amount_minus_500;
		ceiled_amount_minus_500 -= 500;
	}
	return table[ceiled_amount];
}


function floor(number){
	return Math.floor(number*Math.pow(10,2) + 0.5)/Math.pow(10,2);
}

function dosum(){
	//first fix up vars
	document.mod_rtmortgage_calc_form.LA.value = document.mod_rtmortgage_calc_form.LA.value.replace( /,/g, "" );
	document.mod_rtmortgage_calc_form.YR.value = document.mod_rtmortgage_calc_form.YR.value.replace( /[^0-9]/g, "" );
	document.mod_rtmortgage_calc_form.IR.value = document.mod_rtmortgage_calc_form.IR.value.replace( /,/g, "" );
	document.mod_rtmortgage_calc_form.AT.value = document.mod_rtmortgage_calc_form.AT.value.replace( /,/g, "" );
	document.mod_rtmortgage_calc_form.AI.value = document.mod_rtmortgage_calc_form.AI.value.replace( /,/g, "" );

	var MI = document.mod_rtmortgage_calc_form.IR.value / 1200;
	var base = 1;
	var mbase = 1 + MI;
	for (i=0; i<document.mod_rtmortgage_calc_form.YR.value * 12; i++)
	{
		base = base * mbase
	}
	document.mod_rtmortgage_calc_form.PI.value = floor(document.mod_rtmortgage_calc_form.LA.value * MI / ( 1 - (1/base)))
	document.mod_rtmortgage_calc_form.MT.value = floor(document.mod_rtmortgage_calc_form.AT.value / 12)
	document.mod_rtmortgage_calc_form.MI.value = floor(document.mod_rtmortgage_calc_form.AI.value / 12)
	var dasum = document.mod_rtmortgage_calc_form.LA.value * MI / ( 1 - (1/base)) +
		document.mod_rtmortgage_calc_form.AT.value / 12 +
		document.mod_rtmortgage_calc_form.AI.value / 12;
	document.mod_rtmortgage_calc_form.MP.value = floor(dasum);
}


