function CalculateTotal(frm) {
    var order_total = 0
    var order_taxable = 0
	var order_tax = 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
		
        // Is it a "product" field?
        if (form_name.substring(0,4) == "PROD") {
			
            // If so, extract the price from the name
            item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1))
						
            // Update the order total
            if (form_field.checked) {
                order_total += item_price
                order_taxable += item_price
            }
        }
        
        // Is it a "service" field?
        else if (form_name.substring(0,4) == "SERV") {
        
       		 // If so, extract the price from the name
            item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1))           
			
            // Update the order total
            if (form_field.checked) {
                order_total += item_price
            }
        }
        
        else if (form_field.type == "radio" && form_field.value.substring(0,4) == "PROD") {
	        
	        // If so, extract the price from the name
            item_price = parseFloat(form_field.value.substring(form_field.value.lastIndexOf("_") + 1))
						
            // Update the order total
            if (form_field.checked) {
                order_total += item_price
                order_taxable += item_price
            }
        }
    }
	
	if (frm.CATAX && frm.CATAX.checked) {
		order_tax = order_taxable * 0.0975
		order_total += order_tax
	}
	
	if(frm.TAX){
		frm.TAX.value = formatNumber(order_tax, 2,',','.','$','','-','')
	}
	
    // Display the total rounded to two decimal places
    frm.TOTAL.value = formatNumber(order_total, 2,',','.','$','','-','')
}

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) 
{
	var x = Math.round(num * Math.pow(10,dec));
	if (x >= 0) n1=n2='';
	var y = (''+Math.abs(x)).split('');
	var z = y.length - dec; if (z<0) z--;
	for(var i = z; i < 0; i++) y.unshift('0');
	if (z<0) z = 1; y.splice(z, 0, pnt);
	if(y[0] == pnt) y.unshift('0');
	while (z > 3) {
		z-=3; y.splice(z,0,thou);
	}
	var r = curr1+n1+y.join('')+n2+curr2;
	return r;
}

