
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.5000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++){
		num = num.substring(0,num.length-(4*i+3))+','+
		num.substring(num.length-(4*i+3));
	}
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function calculate(){
	if(!document.forms['calcform'])return;
	var pc=[];
	pc[0]=[0,0,0,0];
    pc[1]=[0.185, 0.20, 0.22, 0.22];
    pc[2]=[0.185, 0.20, 0.22, 0.22];
    pc[3]=[0.185, 0.20, 0.22, 0.22];
    pc[4]=[0.185, 0.20, 0.22, 0.22];
	var plan1_time=6;
	var plan2_time=6;
	var plan3_time=6;
	var plan4_time=6;
	var levelStr=new Array("Regular","Mediom","Strong","Strong");

	var f=document.forms['calcform'];
	var amount=parseFloat(f.amount.value);
	amount=(isNaN(amount))?25:amount;
	f.amount.value=amount;
	var plan=f.plan.value;
	var compound=f.compound.value;
	var dailyPercentDiv=document.getElementById("dailyPercentDiv");
	var dailyAverageDiv=document.getElementById("dailyAverageDiv");
	var levelDiv=document.getElementById("levelDiv");
	//var depositDiv=document.getElementById("depositDiv");
	var incomeDiv=document.getElementById("incomeDiv");

	if(plan=='1'){
		var set=(amount<2501)?0:((amount<15001)?1:((amount<25001)?2:3));
	}else if (plan=='2'){
		var set=(amount<2501)?0:((amount<15001)?1:((amount<25001)?2:3));
	}else if (plan=='3'){
		var set=(amount<2501)?0:((amount<15001)?1:((amount<25001)?2:3));
	}else if (plan=='4'){
		var set=(amount<2501)?0:((amount<15001)?1:((amount<25001)?2:3));
	}
	var level=levelStr[set];
	var percent = pc[plan][set];
	//var days=(plan==1)?parseInt(f.days.value):Math.floor(parseInt(f.days.value)/7);
	var days=(plan==1)?plan1_time:((plan==2)?plan2_time:((plan==3)?plan3_time:plan4_time));
	var profit  = 0;

	if (compound!='0'){
		var CompoundPercent = new Number(compound);
		CompoundPercent = (CompoundPercent / 100);
		if ((CompoundPercent > 1) || (CompoundPercent < 0)){
			alert('the Compounding Percent should be from 0 to 100.');
			return;
		}
		deposit = Math.round(amount * Math.pow((1 + percent * CompoundPercent), days) * 10000) / 10000;
		for (i = 1; i <= days; i++){
			profit += amount * Math.pow(1 + percent * CompoundPercent, i-1);
		}
		profit = Math.round(profit * percent * (1 - CompoundPercent) * 100) / 100;
	}else{
		deposit = amount;
		//profit = Math.round(amount * percent * days);
		profit = amount * percent * days;
	}

	levelDiv.innerHTML=level;
	//profitDiv.innerHTML=formatCurrency(profit);
	incomeDiv.innerHTML=formatCurrency(profit);
	dailyAverageDiv.innerHTML=formatCurrency( (profit) / days );
	//alert(deposit+' '+profit+' '+amount);
	dailyPercentDiv.innerHTML=(Math.round(percent*100*100)/100)+'%';
}


