function CalculateTotal(frm, strParent) {
    var order_total = 0;
    // Run through all the form fields
    for (var i=0; i < frm.elements.length; ++i) {

        // Get the current field
        form_field = frm.elements[i];
      
        // Get the field's name
        form_name = form_field.name;
        
        parent_name = "TOTAL" + strParent;
        
        if (form_name==parent_name) {
        	parent_id = i;
        }
        
        subInt 	  = parseInt(form_name.substring(0,5));
		
		if (subInt > strParent && subInt < strParent + 20) {
		
	        // Get the quantity
	        item_quantity = parseInt(form_field.value);
	
			
	
	        // Update the order total
	        if (item_quantity >= 0) {
	            order_total += item_quantity;
	        }
        }
    }
   if (order_total == 0) {
   		order_total = "0";
   }
   frm.elements[parent_id].value = order_total; 
}

function CalculateTotalEvaluation(frm, strParent) {
    var order_total = 0;
    var average = 0.00;
   
    // Run through all the form fields

    for (var i=0; i < frm.elements.length; ++i) {

        // Get the current field
        form_field = frm.elements[i];
      
        // Get the field's name
        form_name = form_field.name;
        
        parent_name = "TOTAL" + strParent;
        avg_parent 	= "AVG" + (strParent - 6);
      	
        child5 = strParent - 6 + 5;
        child5 = child5 + "_" + child5 
        child4 = strParent - 6  + 4;
        child4 = child4 + "_" + child4 
        child3 = strParent - 6  + 3;
        child3 = child3 + "_" + child3 
        child2 = strParent - 6  + 2;
        child2 = child2 + "_" + child2 
        child1 = strParent - 6  + 1;
        child1 = child1 + "_" + child1 
        
        if (form_name==child5) {
        	child5_value = parseInt(form_field.value);
        	
        	if (child5_value>0) {
        		child5_value *= 5;
        	} else {
        		child5_value =0;
        	}
        }
        
        if (form_name==child4) {
        	child4_value = parseInt(form_field.value);
        	if (child4_value>0) {
        		child4_value *= 4;
        	} else {
        		child4_value =0;
        	}
        }
        
        if (form_name==child3) {
        	child3_value = parseInt(form_field.value);
        	if (child3_value>0) {
        		child3_value *= 3;
        	} else {
        		child3_value =0;
        	}
        }
        
        if (form_name==child2) {
        	child2_value = parseInt(form_field.value);
        	if (child2_value>0) {
        		child2_value *= 2;
        	} else {
        		child2_value =0;
        	}
        }
        
        if (form_name==child1) {
        	child1_value = parseInt(form_field.value);
        	if (child1_value>0) {
        		child1_value *= 1;
        	} else {
        		child1_value =0;
        	}
        }
        
        if (form_name==parent_name) {
        	parent_id = i;
        }
        
        if (form_name==avg_parent) {
        	avg_parent_id = i;
        }
        
        subInt 	  = parseInt(form_name.substring(0,6));
		
		if (subInt < strParent && subInt + 6 > strParent) {
		
	        // Get the quantity
	        item_quantity = parseInt(form_field.value);
	
	        // Update the order total
	        if (item_quantity >= 0) {
	            order_total += item_quantity;
	        }
        }
    }
   if (order_total == 0) {
   		order_total = "0";
   }
	 
   var temp_sum = 0.00;
	 
   if (order_total > 0 ) {
   
   average = child5_value + child4_value + child3_value + child2_value + child1_value;
   temp_sum = average / order_total;
   temp_sum = temp_sum.toFixed(3);
   } else {
   temp_sum = 0.00;
   }
   
   frm.elements[parent_id].value = order_total; 
   frm.elements[avg_parent_id].value = temp_sum;    
}



