
/*------------------------------------------------------------------------------------------
 * Name:         UpdateGridViewTotal
 * Description:  Function to add values in child textboxes and show the total in the total textbox.
 * Parameters:   None
 ------------------------------------------------------------------------------------------*/
function UpdateGridViewTotal(gridViewID, totalTextBoxID, childTextBoxID) {
	// Only update total if gridview control is found
	if (document.getElementById(gridViewID)) {
		var totalControlID;
		var total = 0.00;
		var inputs = document.getElementById(gridViewID).getElementsByTagName('input');
		var i = 0;
		// While there are input fields ...
		while (i < inputs.length) {
			// If the field is a textbox ...
			if (inputs[i].getAttribute('type') == 'text') {
			    // If it is the total textbox ...
			    if (inputs[i].getAttribute('id').indexOf(totalTextBoxID) > 0) {
				    totalControlID = inputs[i].getAttribute('id');
			    }
			    else {
			        // If it is one of the child textboxes ...
				    if (inputs[i].getAttribute('id').indexOf(childTextBoxID) > 0) {
						// If it has a numeric value ...
						if (inputs[i].value.length > 0 && !isNaN(inputs[i].value)) {
					        total += parseFloat(inputs[i].value);
					    }
				    }
		        }
			}
			i++;
		}
		if (document.getElementById(totalControlID)) {
			document.getElementById(totalControlID).value = total;
			FormatNumber(totalControlID, 2);
		}
	}
}


