function Select( e ){
	var eRoot = e.parentNode.parentNode.parentNode;
	$A( eRoot.getElementsByTagName( "A" ) ).each(function (eNode){
		eNode.className = "";
	});
	e.className = "Selected";
}



var iDays = 30;
var iCompoundPercent = 0;
var iAmount;
var hMonthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var hHolidays = new Array("January 1","January 2","January 15","February 19","April 6","April 9","May 1","May 28","July 4","September 3","October 8","November 12","November 22","December 25","December 31");



function Calculate( hParams ){
	if( hParams.iDays ){
		iDays = eval(hParams.iDays);
		var eAmount = $( "idAmount" );
		var hAmount = new Object();
		switch( iDays ){
			case 30:
				hAmount.min = 50;
				hAmount.max = 999;
				break;
			case 90:
				hAmount.min = 100;
				hAmount.max = 10000;
				break;
			case 180:
				hAmount.min = 100;
				hAmount.max = 10000;
				break;
		}
		if( eAmount.value == "" || eAmount.value == "50" || eAmount.value == "100" ) eAmount.value = hParams.iAmount = hAmount.min;
		$( "idAmountComment" ).innerHTML = "(" + hAmount.min + " &mdash; " + hAmount.max + ")";
	}
	if( hParams.iCompoundPercent ) iCompoundPercent = eval(hParams.iCompoundPercent);
	if (hParams.iCompoundPercent == '0') iCompoundPercent = 0;
	//if (iCompoundPercent>0 && iDays==30) iCompoundPercent = 0
	
	if( hParams.iAmount ) iAmount = eval(hParams.iAmount);
	if( typeof(iDays) == "number" && typeof(iCompoundPercent) == "number" && typeof(iAmount) == "number" ) CalculateProcess();
}



function CalculateProcess(){
	var sPlan = "&mdash;";
	var iProfit = 0.0;
	var iBonus = 0;
	switch( iDays ){
		case 30:
			if( iAmount >= 50 && iAmount <= 99){
				sPlan = "Test";
				iProfit = 0.5;
			} else if( iAmount >= 100 && iAmount <= 299 ){
				sPlan = "Start";
				iProfit = 0.8;
			} else if( iAmount >= 300 && iAmount <= 999 ){
				sPlan = "Standard";
				iProfit = 1.2;
			} else {
				return CalculateReset();
			}
			break;
		case 90:
			if( iAmount >= 50 && iAmount <= 300 ){
				sPlan = "Start";
				iProfit = 1.0;
			} else if( iAmount >= 300 && iAmount <= 999 ){
				sPlan = "Standard";
				iProfit = 1.4;
				iBonus = 0.1;
			} else if( iAmount >= 1000 && iAmount <= 10000 ){
				sPlan = "Expert";
				iProfit = 1.9;
				iBonus = 0.12;
			} else {
				return CalculateReset();
			}
			break;
		case 180:
			if( iAmount >= 100 && iAmount <= 299 ){
				sPlan = "Start";
				iProfit = 1.2;
				iBonus = 0.07;
			} else if( iAmount >= 300 && iAmount <= 999 ){
				sPlan = "Standard";
				iProfit = 1.6;
				iBonus = 0.12;
			} else if( iAmount >= 1000 && iAmount <= 10000 ){
				sPlan = "Expert";
				iProfit = 2.1;
				iBonus = 0.15;
			} else {
				return CalculateReset();
			}
			break;
	}
/* wrong 
	iBonus = eval(iAmount * iBonus);
	var iPrincipal = iAmount + iBonus;
	_iSumm = eval( iPrincipal * iCompoundPercent ) / 100;
	iSumm = _iSumm;
	var iIncome = 0;
	for( i = 1; i <= iDays; i++ ) {
		iIncome += iProfit * iSumm / 100;
		iSumm = _iSumm + iIncome;
	}
	var iCompound = iIncome;
	var iNonCompound = ( 100 - iCompoundPercent ) * iPrincipal / 100 * iDays * iProfit / 100;
	var iTotal = iCompound + iNonCompound + iPrincipal;
*/
	iBonus = eval(iAmount * iBonus);
	var iPrincipal = iAmount + iBonus;
	//_iSumm = eval( iPrincipal * iCompoundPercent ) / 100;
	iSumm = iPrincipal;
	var iCompound = 0;
	var iNonCompound = 0
	var iIncome = 0;
	for( i = 1; i <= iDays; i++ ) {
		iIncome = iProfit * iSumm / 100;
		iCompound = iCompound + (iIncome * iCompoundPercent) / 100
		iNonCompound = iNonCompound + iIncome * ( 100 - iCompoundPercent ) / 100
		iSumm = iSumm + (iIncome * iCompoundPercent) / 100;
	}
	//var iCompound = iIncome;
	//var iNonCompound = ( 100 - iCompoundPercent ) * iPrincipal / 100 * iDays * iProfit / 100;
	var iTotal = iCompound + iNonCompound + iPrincipal;
	var dtNow = new Date();
	var dtEnd = new Date();
	var iCounter = 0;
	while( iCounter < iDays ){
  dtEnd.setDate( dtEnd.getDate() + 1 );
  if( dtEnd.getDay() != 0 && dtEnd.getDay() != 6 ){
   var bIncrement = true;
   hHolidays.each(function( e ){
    var dtHoliday = new Date( e + ", " + dtNow.getFullYear() );
    if( dtHoliday.getFullYear() == dtEnd.getFullYear() && dtHoliday.getMonth() == dtEnd.getMonth() && dtHoliday.getDate() == dtEnd.getDate() ) bIncrement = false;
   })
   if( bIncrement) iCounter++;
  }
 }

	$( "idAmountToDeposit" ).innerHTML = "$ " + iAmount.toFixed(2);
	$( "idInvestmentPlan" ).innerHTML = sPlan;
	$( "idDepositBonus" ).innerHTML = "$ " + iBonus.toFixed(2);
	$( "idPrincipal" ).innerHTML = "$ " + iPrincipal.toFixed(2);
	$( "idCompoundProfit" ).innerHTML = "$ " + iCompound.toFixed(2);
	$( "idNonCompoundProfit" ).innerHTML = "$ " + iNonCompound.toFixed(2);
	$( "idDate" ).innerHTML =
		hMonthNames[dtNow.getMonth()] + " " + dtNow.getDate() + ", " + dtNow.getFullYear()
		+ " &mdash; " +
		hMonthNames[dtEnd.getMonth()] + " " + dtEnd.getDate() + ", " + dtEnd.getFullYear()
	$( "idResult" ).innerHTML = "$ " + iTotal.toFixed(2);
}



function CalculateReset(){
	var sEmpty = "&mdash;";
	$( "idAmountToDeposit" ).innerHTML = sEmpty;
	$( "idInvestmentPlan" ).innerHTML = sEmpty;
	$( "idDepositBonus" ).innerHTML = sEmpty;
	$( "idPrincipal" ).innerHTML = sEmpty;
	$( "idCompoundProfit" ).innerHTML = sEmpty;
	$( "idNonCompoundProfit" ).innerHTML = sEmpty;
	$( "idDate" ).innerHTML = sEmpty;
	$( "idResult" ).innerHTML = sEmpty;
	return false;
}
