$(function(){

	calc();

	$('#calc_plan').on('change', calc);
	$('#inv_amount').bind('change keyup', calc).on('keypress', isNumberKey);

});

function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	return true;
}


function calc() {

	var plan = $('#calc_plan').val();
	var amount = $('#inv_amount').val();
	var percent;

	switch (plan) {
		case '1':
			switch (true) {
				case (amount<5):
					percent = "- Min $5 -";
					break;
				case (amount<=299):
					percent = 104.64;	
					break;
				case (amount>=300):
					percent = "- Max $299 -";
					break;
/*				case (amount<=8000):
					percent = 107;	
					break;
				case (amount<=15000):
					percent = 114;
					break;
				case (amount<=30000):
					percent = 120;	
					break;
				case (amount<=50000):
					percent = 130;*/
			}
		break;
			case '2':
			switch (true) {
				case (amount<300):
					percent = "- Min $300 -";
					break;
				case (amount<=2999):
					percent = 201.6;	
					break;
				case (amount>=3000):
					percent = "- Max $2,999 -";
					break;
/*				case (amount<=4000):
					percent = 122;
					break;
				case (amount<=8000):
					percent = 140;	
					break;
				case (amount<=15000):
					percent = 180;
					break;
				case (amount<=30000):
					percent = 250;	
					break;
				case (amount<=50000):
					percent = 350;*/
			}
		break;
			case '3':
			switch (true) {
				case (amount<3000):
					percent = "- Min $3,000 -";
					break;
				case (amount<=30000):
					percent = 360;	
					break;
				case (amount>=30001):
					percent = "- Max $30,000 -";
					break;
		/*		case (amount<=4000):
					percent = 180;
					break;
				case (amount<=8000):
					percent = 250;	
					break;
				case (amount<=15000):
					percent = 450;
					break;
				case (amount<=30000):
					percent = 600;	
					break;
				case (amount<=50000):
					percent = 1100;*/
			}
		break;
		case '4':
			switch (true) {
				case (amount<10):
					percent = "- Min $10 -";
					break;
				case (amount<=499):
					percent = 115;	
					break;
				case (amount>=500):
					percent = "- Max $499 -";
					break;
	/*			case (amount<=4000):
					percent = 400;
					break;
				case (amount<=8000):
					percent = 600;	
					break;
				case (amount<=15000):
					percent = 1000;
					break;
				case (amount<=30000):
					percent = 1500;	
					break;
				case (amount<=50000):
					percent = 3000;*/
			}
		break;
		case '5':
			switch (true) {
				case (amount<500):
					percent = "- Min $500 -";
					break;
				case (amount<=999):
					percent = 400;	
					break;
				case (amount>=1000):
					percent = "- Max $999 -";
					break;
/*				case (amount<=4000):
					percent = 800;
					break;
				case (amount<=8000):
					percent = 1000;	
					break;
				case (amount<=15000):
					percent = 1500;
					break;
				case (amount<=30000):
					percent = 2000;	
					break;
				case (amount<=50000):
					percent = 5000;*/
			}
		break;
		
		case '6':
			 switch (true) {
				case (amount<5000 ):
					percent = "- Min $5,000 -";
					break;
				case (amount<=50000):
					percent = 700;	
					break;
				case (amount>=50001):
					percent = "- Max $50,000 -";
					break;
			/*	case (amount<=3000):
					percent = 85;
					break;
				case (amount<=5000):
					percent = 130;	
					break;
				case (amount<=15000):
					percent = 2500;	
					break;
                    case (amount<=30000):
					percent = 3500;	
					break;
				case (amount<=50000):
					percent = 8000;*/
			}
		break;
			
			
	}

	$('#assign_per').val(percent+'%');
	var total = amount*percent/100;
	$('#total_return').val(total);
	$('#net_profit').val((total-amount).toFixed(2)+'$');

}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}