$(document).ready(function () {  
	$("#student_select_menu").change(function() {
		//finds out how many instances we currently have
		var num = $('.student_name_box').length;

		//value selected from the drop down menu
		var needed = $("#student_select_menu").attr('value');

		//there's already one input box displayed so start on the next one in line
		var current = $('.student_name_box').length;
		
		//if there are more instances than what was selected in the drop down menu
		if(current > needed){
			var i = 1;
			//number of elements we need to remove
			var tmp = num - needed;

			while(i <= tmp){
				$('.student_name_box:last').empty().remove();
				i++;
			}
		}

		var current = $('.student_name_box').length + 1;

		if(current <= needed){
			while(current <= needed){
				$("#student_1").clone().insertAfter("#student_" + (current - 1)).attr('id', "student_" + current);
				$("#student_" + current + " label:eq(0)").attr('for', "student_" + current + "_name").text("(" + current + ") *Student Name");
				current++;
			}
		}

		//update the total registration charges
		if(needed == 1){
			$("#total_charges").val(50.00);
		} else if(needed == 2){
			$("#total_charges").val(65.00);
		} else if(needed == 3){
			$("#total_charges").val(80.00);
		} else if(needed == 4){
			$("#total_charges").val(95.00);
		}
	});
});

