jQuery(document).ready(function($) {
	var total = 0;
	//iterate through each textboxes and add keyup
	//handler to trigger sum event
	$(".form-text").each(function() {
		$(this).keyup(function() {
			basepay();
		});
	});

	function basepay() {
		var basic_rate = $("#edit-basic-rate").val();
		var days_worked = $("#edit-days-worked").val();
		var sales_bonus = parseInt($("#edit-sales-bonus").val());
		var remmitance = parseInt($("#edit-remmitance").val());
		var charges = parseInt($("#edit-charges").val());
		var adjustaments = parseInt($("#edit-adjustaments").val());
		if (isNaN(sales_bonus)) {
			sales_bonus = 0;
		}
		if (isNaN(remmitance)) {
			remmitance = 0;
		}
		if (isNaN(charges)) {
			charges = 0;
		}
		if (isNaN(adjustaments)) {
			adjustaments = 0;
		}
		//iterate through each textboxes and add the values
		//add only if the value is number
		if (!isNaN(basic_rate) && basic_rate.length != 0 && !isNaN(days_worked) && days_worked.length != 0) {
			rate = basic_rate * days_worked;
		} else {
			rate = 0;
		}
		//.toFixed() method will roundoff the final sum to 2 decimal places
		total = (rate + sales_bonus - remmitance - charges + adjustaments);
		$("#sum").html(total.toFixed(2));
	}
});