﻿
var valValidData = 0;

// Number.toFixed(n) IE5.5w bug fixing
function pad( s, n )
{
	if ( n <= 0 ) return "";
	s = s || '.';
	return (s.length > n) ? s : pad( s + '0', n );
}

Number.prototype.toDecimals=function(n)
{
	n = ( isNaN( n ) ) ? 2 : n;
	var nT = Math.pow( 10, n );

	var s = new String( Math.round( this * nT ) / nT );
	s = s.replace( /(\.\d*)?$/, pad ( "", n ) );
    
    return ( isNaN( this ) ) ? this : s;
}

function UpdateCartTotals()
{
	if(valValidData == 0) return;

	var totMon;
	var totTue;
	var totWed;
	var totThu;
	var totFri;
	var totSat;
	var totSun;
	
	totMon = 0;
	totTue = 0;
	totWed = 0;
	totThu = 0;
	totFri = 0;
	totSat = 0;
	totSun = 0;
	
	var frm = document.aspnetForm;
	
	if(frm.chkMonB.checked){ totMon += valBreakfast; }
	if(frm.chkTueB.checked){ totTue += valBreakfast; }
	if(frm.chkWedB.checked){ totWed += valBreakfast; }
	if(frm.chkThuB.checked){ totThu += valBreakfast; }
	if(frm.chkFriB.checked){ totFri += valBreakfast; }
	if(frm.chkSatB.checked){ totSat += valBreakfast; }
	if(frm.chkSunB.checked){ totSun += valBreakfast; }
	
	if(frm.chkMonMS.checked){ totMon += valMs; }
	if(frm.chkTueMS.checked){ totTue += valMs; }
	if(frm.chkWedMS.checked){ totWed += valMs; }
	if(frm.chkThuMS.checked){ totThu += valMs; }
	if(frm.chkFriMS.checked){ totFri += valMs; }
	if(frm.chkSatMS.checked){ totSat += valMs; }
	if(frm.chkSunMS.checked){ totSun += valMs; }
	
	if(frm.chkMonL.checked){ totMon += valLunch; }
	if(frm.chkTueL.checked){ totTue += valLunch; }
	if(frm.chkWedL.checked){ totWed += valLunch; }
	if(frm.chkThuL.checked){ totThu += valLunch; }
	if(frm.chkFriL.checked){ totFri += valLunch; }
	if(frm.chkSatL.checked){ totSat += valLunch; }
	if(frm.chkSunL.checked){ totSun += valLunch; }
	
	if(frm.chkMonAS.checked){ totMon += valAs; }
	if(frm.chkTueAS.checked){ totTue += valAs; }
	if(frm.chkWedAS.checked){ totWed += valAs; }
	if(frm.chkThuAS.checked){ totThu += valAs; }
	if(frm.chkFriAS.checked){ totFri += valAs; }
	if(frm.chkSatAS.checked){ totSat += valAs; }
	if(frm.chkSunAS.checked){ totSun += valAs; }
	
	if(frm.chkMonD.checked){ totMon += valDinner; }
	if(frm.chkTueD.checked){ totTue += valDinner; }
	if(frm.chkWedD.checked){ totWed += valDinner; }
	if(frm.chkThuD.checked){ totThu += valDinner; }
	if(frm.chkFriD.checked){ totFri += valDinner; }
	if(frm.chkSatD.checked){ totSat += valDinner; }
	if(frm.chkSunD.checked){ totSun += valDinner; }
	
	if(frm.chkMonES.checked){ totMon += valEs; }
	if(frm.chkTueES.checked){ totTue += valEs; }
	if(frm.chkWedES.checked){ totWed += valEs; }
	if(frm.chkThuES.checked){ totThu += valEs; }
	if(frm.chkFriES.checked){ totFri += valEs; }
	if(frm.chkSatES.checked){ totSat += valEs; }
	if(frm.chkSunES.checked){ totSun += valEs; }
	
	if(0 < totMon && totMon < valTreshhold) totMon = valTreshhold;
	if(0 < totTue && totTue < valTreshhold) totTue = valTreshhold;
	if(0 < totWed && totWed < valTreshhold) totWed = valTreshhold;
	if(0 < totThu && totThu < valTreshhold) totThu = valTreshhold;
	if(0 < totFri && totFri < valTreshhold) totFri = valTreshhold;
	if(0 < totSat && totSat < valTreshhold) totSat = valTreshhold;
	if(0 < totSun && totSun < valTreshhold) totSun = valTreshhold;
	
	var total;
	total = 0;
	
	total += totMon;
	total += totTue;
	total += totWed;
	total += totThu;
	total += totFri;
	total += totSat;
	total += totSun;
	
	totMon = (new Number(totMon * 100)).toDecimals(0) / 100;
	totTue = (new Number(totTue * 100)).toDecimals(0) / 100;
	totWed = (new Number(totWed * 100)).toDecimals(0) / 100;
	totThu = (new Number(totThu * 100)).toDecimals(0) / 100;
	totFri = (new Number(totFri * 100)).toDecimals(0) / 100;
	totSat = (new Number(totSat * 100)).toDecimals(0) / 100;
	totSun = (new Number(totSun * 100)).toDecimals(0) / 100;

	total = (new Number(total * 100)).toDecimals(0).toString(10);
	
	if(total=='0')
	{
		frm.textTotal.value = '   ';
	}
	else
	{
		if(total.length < 3) total = '00' + total;
		
		frm.textTotal.value = '$' + total.substr(0, total.length-2) + '.' + total.substr(total.length-2);
	}

	frm.lblTotMon.value = '$' + totMon;
	frm.lblTotTue.value = '$' + totTue;
	frm.lblTotWed.value = '$' + totWed;
	frm.lblTotThu.value = '$' + totThu;
	frm.lblTotFri.value = '$' + totFri;

	frm.lblTotSat.value = '$' + totSat;
	frm.lblTotSun.value = '$' + totSun;
}

