function itemTotalCost(ddlQty,target,price) 
{     
    var qty   = window.document.getElementById(ddlQty).value; 
    var totalCost = qty * price; 
    document.getElementById(target).innerHTML = "$" + totalCost;

    // CALCULATE DIPS AND PLATTERS TOTAL COST
    var dipsAndPlattersTotalCost = calculateDipsAndPlatterTotalCost();
    document.getElementById('dipsAndPlatters').innerHTML = dipsAndPlattersTotalCost;
    document.reservationForm.dipsAndPlattersSubmit.value = dipsAndPlattersTotalCost;

    // CALCULATE FINGER FOODS TOTAL COST	 
    var fingerFoodsTotalCost = calculateFingerFoodsTotalCost();
    document.getElementById('fingerFoods').innerHTML = fingerFoodsTotalCost;
    document.reservationForm.fingerFoodsSubmit.value = fingerFoodsTotalCost;

    // CALCULATE DESERTS TOTAL COST	 
    var desertsTotalCost = calculateDesertsTotalCost();
    document.getElementById('deserts').innerHTML = desertsTotalCost;
    document.reservationForm.desertsSubmit.value = desertsTotalCost;
	
    // CALCULATE SALADS TOTAL COST	 
    var saladsTotalCost = calculateSaladsTotalCost();
    document.getElementById('salads').innerHTML = saladsTotalCost;
    document.reservationForm.saladsSubmit.value = saladsTotalCost;

    // CALCULATE SOUPS TOTAL COST	 
    var soupsTotalCost = calculateSoupsTotalCost();
    document.getElementById('soups').innerHTML = soupsTotalCost;
    document.reservationForm.soupsSubmit.value = soupsTotalCost;
	
    // CALCULATE SIDES TOTAL COST	 
    var sidesTotalCost = calculateSidesTotalCost();
    document.getElementById('sides').innerHTML = sidesTotalCost;
    document.reservationForm.sidesSubmit.value = sidesTotalCost;

    // CALCULATE ENTREES TOTAL COST	 
    var entreeTotalCost = calculateEntreesTotalCost();
    document.getElementById('entrees').innerHTML = entreeTotalCost;
    document.reservationForm.entreesSubmit.value = entreeTotalCost;
    
    // CALCULATE CATERING_SUB TOTAL COST	 
    var cateringSubTotalCost = calculateFoodGrandTotalCost();
    document.getElementById('cateringSubTotal').innerHTML = cateringSubTotalCost;
    document.reservationForm.cateringSubTotalSubmit.value = cateringSubTotalCost;

    // CALCULATE ATTENDANT FEE COST	 
    //var attendantFeeCost = calculateAttendantFeeCost();
    //document.getElementById('attendant').innerHTML = attendantFeeCost; 
    
    
    // CALCULATE DELIVERY FEE COST
    var deliveryFeeCost = calculateDeliveryFeeCost();   
    //document.reservationForm.deliveryFeeSubmit.value = deliveryFeeCost;
    
    // CALCULATE CATERING_GRAND TOTAL COST	 
    var cateringGrandTotalCost = calculateGrandTotalCost();
    document.getElementById('cateringGrandTotal').innerHTML = cateringGrandTotalCost;    
    document.reservationForm.cateringGrandTotalSubmit.value = cateringGrandTotalCost;
} 

function removeDollarSign(value)
{
    var numberValue = value.replace("$", "");

    return numberValue; 
}

function removeComma(value)
{
    var numberValue = value.replace(",", "");

    return numberValue; 
}

function addComma(value)
{
    var valueString = value + "";	
    var thousands = Math.floor(value/1000);
    var hundreds = valueString.replace(thousands, "");
    var commaDelimited = thousands + "," + hundreds;
 
    return commaDelimited;	
}

function calculateDipsAndPlatterTotalCost()
{
    var item1 = parseInt(removeDollarSign(document.getElementById('vegCruditeCost').innerHTML));
    var item2 = parseInt(removeDollarSign(document.getElementById('fruitCost').innerHTML));
    var item3 = parseInt(removeDollarSign(document.getElementById('hummusCost').innerHTML));
    var item4 = parseInt(removeDollarSign(document.getElementById('salsaCost').innerHTML));
    var item5 = parseInt(removeDollarSign(document.getElementById('spinachCost').innerHTML));
    var item6 = parseInt(removeDollarSign(document.getElementById('bruschettaCost').innerHTML));
    var item7 = parseInt(removeDollarSign(document.getElementById('crabDipCost').innerHTML));

    var totalCost = item1 + item2 + item3 + item4 + item5 + item6 + item7;
    
    if(totalCost > 999)
    {
	totalCost = addComma(totalCost);
	
    }	

    totalCost = "$" + totalCost;
	
    return totalCost; 
}

function calculateFingerFoodsTotalCost()
{
    var item1 = parseInt(removeDollarSign(document.getElementById('hamburgerCost').innerHTML));
    var item2 = parseInt(removeDollarSign(document.getElementById('cheeseburgerCost').innerHTML));
    var item3 = parseInt(removeDollarSign(document.getElementById('bbqWingsCost').innerHTML));
    var item4 = parseInt(removeDollarSign(document.getElementById('buffaloWingsCost').innerHTML));
    var item5 = parseInt(removeDollarSign(document.getElementById('jerkWingsCost').innerHTML));
    var item6 = parseInt(removeDollarSign(document.getElementById('chickenfingersCost').innerHTML));
    var item7 = parseInt(removeDollarSign(document.getElementById('chickenQuesaCost').innerHTML));
    var item8 = parseInt(removeDollarSign(document.getElementById('firecrackerCost').innerHTML));
    var item9 = parseInt(removeDollarSign(document.getElementById('crabCakesCost').innerHTML));
    var item10 = parseInt(removeDollarSign(document.getElementById('shrimpCocktailCost').innerHTML));
    var item11 = parseInt(removeDollarSign(document.getElementById('meatballsCost').innerHTML));
    var item12 = parseInt(removeDollarSign(document.getElementById('mozzarellaCost').innerHTML));

    var totalCost = item1 + item2 + item3 + item4 + item5 + item6 + item7 + item8 + item9 + item10 + item11 + item12;
    
    if(totalCost > 999)
    {
		totalCost = addComma(totalCost);	
    }	

    totalCost = "$" + totalCost;
	
    return totalCost; 
}

function calculateDesertsTotalCost()
{
    var item1 = parseInt(removeDollarSign(document.getElementById('browniesCost').innerHTML));
    var item2 = parseInt(removeDollarSign(document.getElementById('cookiesCost').innerHTML));
    var item3 = parseInt(removeDollarSign(document.getElementById('cheesecakeCost').innerHTML));
 
    var totalCost = item1 + item2 + item3;
    
    if(totalCost > 999)
    {
	totalCost = addComma(totalCost);
	
    }	

    totalCost = "$" + totalCost;
	
    return totalCost; 
}

function calculateSaladsTotalCost()
{
    var item1 = parseInt(removeDollarSign(document.getElementById('greenSaladCost').innerHTML));
    var item2 = parseInt(removeDollarSign(document.getElementById('caesarSaladCost').innerHTML));
    var item3 = parseInt(removeDollarSign(document.getElementById('cobbSaladCost').innerHTML));
    var item4 = parseInt(removeDollarSign(document.getElementById('basilSaladCost').innerHTML));
 
    var totalCost = item1 + item2 + item3 + item4;
    
    if(totalCost > 999)
    {
	totalCost = addComma(totalCost);
	
    }	

    totalCost = "$" + totalCost;
	
    return totalCost; 
}

function calculateSoupsTotalCost()
{
    var item1 = parseInt(removeDollarSign(document.getElementById('chickenTortCost').innerHTML));
    var item2 = parseInt(removeDollarSign(document.getElementById('potatoChedCost').innerHTML));
 
    var totalCost = item1 + item2;
    
    if(totalCost > 999)
    {
	totalCost = addComma(totalCost);
	
    }	

    totalCost = "$" + totalCost;
	
    return totalCost; 
}

function calculateSidesTotalCost()
{
    var item1 = parseInt(removeDollarSign(document.getElementById('ricePilafCost').innerHTML));
    var item2 = parseInt(removeDollarSign(document.getElementById('coleSlawCost').innerHTML));
    var item3 = parseInt(removeDollarSign(document.getElementById('vegetablesCost').innerHTML));

    var totalCost = item1 + item2 + item3;
    
    if(totalCost > 999)
    {
	totalCost = addComma(totalCost);
	
    }	

    totalCost = "$" + totalCost;
	
    return totalCost; 
}

function calculateEntreesTotalCost()
{
    var item1 = parseInt(removeDollarSign(document.getElementById('penneCost').innerHTML));
    var item2 = parseInt(removeDollarSign(document.getElementById('pulledbbqCost').innerHTML));
    var item3 = parseInt(removeDollarSign(document.getElementById('turkeyWrapsCost').innerHTML));
    var item4 = parseInt(removeDollarSign(document.getElementById('chickenKabobCost').innerHTML));
    var item5 = parseInt(removeDollarSign(document.getElementById('steakKabobCost').innerHTML));
    var item6 = parseInt(removeDollarSign(document.getElementById('seafoodWrapsCost').innerHTML));
    var item7 = parseInt(removeDollarSign(document.getElementById('lasagneCost').innerHTML));
    var item8 = parseInt(removeDollarSign(document.getElementById('lasagneVegCost').innerHTML));

    var totalCost = item1 + item2 + item3 + item4 + item5 + item6 + item7 + item8;
    
    if(totalCost > 999)
    {
		totalCost = addComma(totalCost);
    }	

    totalCost = "$" + totalCost;
	
    return totalCost; 
}

function calculateAttendantFeeCost()
{
    var totalFee = parseInt(removeDollarSign(document.getElementById('attendantFee').innerHTML));
    
    if(totalFee > 999)
    {
		totalFee = addComma(totalFee);
    }	

    totalFee = "$" + totalFee;
    document.reservationForm.attendantFeeSubmit.value = totalFee;
	
    return totalFee; 
}

function calculateDeliveryFeeCost()
{
	var deliveryRequestedRB = document.reservationForm.deliveryRequestedRB;
	var totalFoodCost = 0;
	var deliveryCost = 0;
	
    // VERIFY THAT DELIVERY HAS BEEN REQUESTED (IS CHECK BOX CHECKED?)
    if(deliveryRequestedRB[0].checked == true)
    {
		totalFoodCost = calculateFoodGrandTotalCost();
		totalFoodCost = removeComma(removeDollarSign(totalFoodCost));
		
		// ORDERS BETWEEN $0 - $500
		if(totalFoodCost <= 500)
		{
			deliveryCost = 35;
		}
		// ORDERS BETWEEN $501 - $1000
		else if(totalFoodCost <= 1000)
		{
			deliveryCost = 50;
		}
		// ORDERS GREATER THAN $1000
		else
		{
			deliveryCost = 100;
		}
    }
    document.getElementById('deliveryFee').innerHTML = " $" + deliveryCost;
    document.reservationForm.deliveryFeeSubmit.value =  " $" + deliveryCost;
    
    // CALCULATE CATERING_GRAND TOTAL COST	 
    var cateringGrandTotalCost = document.getElementById('cateringGrandTotal').innerHTML;
    cateringGrandTotalCost = parseInt(removeDollarSign(removeComma(cateringGrandTotalCost)));
    var revisedGrandTotal = cateringGrandTotalCost + deliveryCost;
    
    if(revisedGrandTotal > 999)
    {
		revisedGrandTotal = addComma(revisedGrandTotal);
    }	
    
    document.getElementById('cateringGrandTotal').innerHTML = " $" + revisedGrandTotal;
    
    return deliveryCost; 
}

function calculateFoodGrandTotalCost()
{
    var item1 = parseInt(removeDollarSign(removeComma(calculateDipsAndPlatterTotalCost())));
    var item2 = parseInt(removeDollarSign(removeComma(calculateFingerFoodsTotalCost())));
    var item3 = parseInt(removeDollarSign(removeComma(calculateDesertsTotalCost())));
    var item4 = parseInt(removeDollarSign(removeComma(calculateSaladsTotalCost())));
    var item5 = parseInt(removeDollarSign(removeComma(calculateSoupsTotalCost())));
    var item6 = parseInt(removeDollarSign(removeComma(calculateSidesTotalCost())));
    var item7 = parseInt(removeDollarSign(removeComma(calculateEntreesTotalCost())));
    
    var totalCost = item1 + item2 + item3 + item4 + item5 + item6 + item7;
    
    if(totalCost > 999)
    {
		totalCost = addComma(totalCost);
    }	

    totalCost = " $" + totalCost;
    	
    return totalCost; 
}

function calculateGrandTotalCost()
{
    var item1 = parseInt(removeDollarSign(removeComma(calculateDipsAndPlatterTotalCost())));
    var item2 = parseInt(removeDollarSign(removeComma(calculateFingerFoodsTotalCost())));
    var item3 = parseInt(removeDollarSign(removeComma(calculateDesertsTotalCost())));
    var item4 = parseInt(removeDollarSign(removeComma(calculateSaladsTotalCost())));
    var item5 = parseInt(removeDollarSign(removeComma(calculateSoupsTotalCost())));
    var item6 = parseInt(removeDollarSign(removeComma(calculateSidesTotalCost())));
    var item7 = parseInt(removeDollarSign(removeComma(calculateEntreesTotalCost())));
    var item8 = parseInt(removeComma(removeDollarSign(calculateAttendantFeeCost())));
    var item9 = parseInt(calculateDeliveryFeeCost());
    //alert("Delivery Fee: " + item9);

    var totalCost = item1 + item2 + item3 + item4 + item5 + item6 + item7 + item8 + item9;
    
    if(totalCost > 999)
    {
		totalCost = addComma(totalCost);
    }	

    totalCost = " $" + totalCost;
	
    return totalCost; 
}

