function validate_required(field,alerttxt) {
	with (field) {
		if (value==null||value=="")
		  {alert(alerttxt);return false;}
		else {return true}
	}
}

function validate_form(thisform) {
  with (thisform)	{
	if (validate_required(BillingFirstName,"Billing First Name is required!")==false)
	  {BillingFirstName.focus();return false;}
	if (validate_required(BillingLastName,"Billing Last Name is required!")==false)
	  {BillingLastName.focus();return false;}
	if (validate_required(BillingAddress,"Billing Address is required")==false)
	  {BillingAddress.focus();return false;}
	if (validate_required(BillingCity,"Billing City is required")==false)
	  {BillingCity.focus();return false;}
	if (validate_required(BillingState,"Billing State is required")==false)
	  {BillingState.focus();return false;}
	if (validate_required(BillingZip,"Billing Zip is required")==false)
	  {BillingZip.focus();return false;}
	if (validate_required(BillingPhone,"Billing Phone is required")==false)
	  {BillingPhone.focus();return false;}
	if (validate_required(Grand_Total,"Please enter desired quantities for the Menu Items")==false)
	  {Grand_Total.focus();return false;}
  }
}


function checkPhone (obj) {

  var str = obj.value.replace(/[^0-9]+?/g, '');

  switch (str.length) {
   case 0:
     str = "";
     break;
   case 1:
     str = "";
     break;     
   case 10:
     str = "("+str.substr(0,3)+")"+str.substr(3,3)+"-"+str.substr(6,4);
     break;
   default:
     alert('Please enter a 10 digit phone number in the ' + obj.name + ' field.');
	 obj.blur()
	 obj.select();
     return;
  }
  obj.value = str;
}


function hideLayer(whichLayer) {
	if (document.getElementById) {
	// this is the way the standards work
	document.getElementById(whichLayer).style.visibility = "hidden";
	}
	else if (document.all) {
	// this is the way old msie versions work
	document.all[whichlayer].style.visibility = "hidden";
	}
	else if (document.layers) {
	// this is the way nn4 works
	document.layers[whichLayer].visibility = "hidden";
	}
}
 
 
function showLayer(whichLayer) {
	if (document.getElementById) {
	// this is the way the standards work
	document.getElementById(whichLayer).style.visibility = "visible";
	}
	else if (document.all) {
	// this is the way old msie versions work
	document.all[whichlayer].style.visibility = "visible";
	}
	else if (document.layers) {
	// this is the way nn4 works
	document.layers[whichLayer].visibility = "visible";
	}
}


function viewSubmitButton() {
	if (document.orderform.AgreeToTerms.checked) { 
		document.orderform.Submit.disabled=false; 
	}
	else {
		document.orderform.Submit.disabled=true;
	}
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
		cents = Math.floor((num*100+0.5)%100); 
		num = Math.floor(num).toString();
	if(cents < 10) cents = "0" + cents; 
//		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
//			num = num.substring(0,num.length-(4*i+3))+num.substring(num.length-(4*i+3));	
	return ('$' + num + '.' + cents); 
}


function formatNumber(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
		cents = Math.floor((num*100+0.5)%100); 
		num = Math.floor(num).toString();
	if(cents < 10) cents = "0" + cents; 
//		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
//			num = num.substring(0,num.length-(4*i+3))+num.substring(num.length-(4*i+3));	
	return (num + '.' + cents); 
}


function calcTotals() {
	var Subtotal = 0.00
	var Adj_Subtotal = 0.00
	var Grand_Total = 0.00
	var Deposit = 0.00

	//--- Strawberry ---
	if (isNaN(parseInt(document.orderform.Strawberry_12.value))) {
		Strawberry_12 = 0;
	} else {
		Strawberry_12 = parseInt(eval(document.orderform.Strawberry_12.value) + 0.5);
		document.orderform.Strawberry_12.value = parseInt(Strawberry_12);
	}
	if (isNaN(parseInt(document.orderform.Strawberry_16.value))) {
		Strawberry_16 = 0;
	} else {
		Strawberry_16 = parseInt(eval(document.orderform.Strawberry_16.value) + 0.5);
		document.orderform.Strawberry_16.value = parseInt(Strawberry_16);
	}
	if (isNaN(parseInt(document.orderform.Strawberry_20.value))) {
		Strawberry_20 = 0;
	} else {
		Strawberry_20 = parseInt(eval(document.orderform.Strawberry_20.value) + 0.5);
		document.orderform.Strawberry_20.value = parseInt(Strawberry_20);
	}		
	document.orderform.Strawberry_Qty.value = parseInt(Strawberry_12) + parseInt(Strawberry_16) + parseInt(Strawberry_20);
	Strawberry_Total = (parseInt(Strawberry_12) * 3.00) + (parseInt(Strawberry_16) * 3.50) + (parseInt(Strawberry_20) * 4.00);
	document.orderform.Strawberry_Total.value = formatCurrency(Strawberry_Total);
	Subtotal = Subtotal + parseFloat(Strawberry_Total);

	
	//--- Baynana ---
	if (isNaN(parseInt(document.orderform.Baynana_12.value))) {
		Baynana_12 = 0;
	} else {
		Baynana_12 = parseInt(eval(document.orderform.Baynana_12.value) + 0.5);
		document.orderform.Baynana_12.value = parseInt(Baynana_12);
	}
	if (isNaN(parseInt(document.orderform.Baynana_16.value))) {
		Baynana_16 = 0;
	} else {
		Baynana_16 = parseInt(eval(document.orderform.Baynana_16.value) + 0.5);
		document.orderform.Baynana_16.value = parseInt(Baynana_16);
	}
	if (isNaN(parseInt(document.orderform.Baynana_20.value))) {
		Baynana_20 = 0;
	} else {
		Baynana_20 = parseInt(eval(document.orderform.Baynana_20.value) + 0.5);
		document.orderform.Baynana_20.value = parseInt(Baynana_20);
	}		
	document.orderform.Baynana_Qty.value = parseInt(Baynana_12) + parseInt(Baynana_16) + parseInt(Baynana_20);
	Baynana_Total = (parseInt(Baynana_12) * 3.00) + (parseInt(Baynana_16) * 3.50) + (parseInt(Baynana_20) * 4.00);
	document.orderform.Baynana_Total.value = formatCurrency(Baynana_Total);	
	Subtotal = Subtotal + parseFloat(Baynana_Total);

	
	//--- Peach ---
	if (isNaN(parseInt(document.orderform.Peach_12.value))) {
		Peach_12 = 0;
	} else {
		Peach_12 = parseInt(eval(document.orderform.Peach_12.value) + 0.5);
		document.orderform.Peach_12.value = parseInt(Peach_12);
	}
	if (isNaN(parseInt(document.orderform.Peach_16.value))) {
		Peach_16 = 0;
	} else {
		Peach_16 = parseInt(eval(document.orderform.Peach_16.value) + 0.5);
		document.orderform.Peach_16.value = parseInt(Peach_16);
	}
	if (isNaN(parseInt(document.orderform.Peach_20.value))) {
		Peach_20 = 0;
	} else {
		Peach_20 = parseInt(eval(document.orderform.Peach_20.value) + 0.5);
		document.orderform.Peach_20.value = parseInt(Peach_20);
	}		
	document.orderform.Peach_Qty.value = parseInt(Peach_12) + parseInt(Peach_16) + parseInt(Peach_20);
	Peach_Total = (parseInt(Peach_12) * 3.00) + (parseInt(Peach_16) * 3.50) + (parseInt(Peach_20) * 4.00);
	document.orderform.Peach_Total.value = formatCurrency(Peach_Total);	
	Subtotal = Subtotal + parseFloat(Peach_Total);
	
	
	//--- Raspberry ---
	if (isNaN(parseInt(document.orderform.Raspberry_12.value))) {
		Raspberry_12 = 0;
	} else {
		Raspberry_12 = parseInt(eval(document.orderform.Raspberry_12.value) + 0.5);
		document.orderform.Raspberry_12.value = parseInt(Raspberry_12);
	}
	if (isNaN(parseInt(document.orderform.Raspberry_16.value))) {
		Raspberry_16 = 0;
	} else {
		Raspberry_16 = parseInt(eval(document.orderform.Raspberry_16.value) + 0.5);
		document.orderform.Raspberry_16.value = parseInt(Raspberry_16);
	}
	if (isNaN(parseInt(document.orderform.Raspberry_20.value))) {
		Raspberry_20 = 0;
	} else {
		Raspberry_20 = parseInt(eval(document.orderform.Raspberry_20.value) + 0.5);
		document.orderform.Raspberry_20.value = parseInt(Raspberry_20);
	}		
	document.orderform.Raspberry_Qty.value = parseInt(Raspberry_12) + parseInt(Raspberry_16) + parseInt(Raspberry_20);
	Raspberry_Total = (parseInt(Raspberry_12) * 3.00) + (parseInt(Raspberry_16) * 3.50) + (parseInt(Raspberry_20) * 4.00);
	document.orderform.Raspberry_Total.value = formatCurrency(Raspberry_Total);	
	Subtotal = Subtotal + parseFloat(Raspberry_Total);
	
	
	//--- Mango ---
	if (isNaN(parseInt(document.orderform.Mango_12.value))) {
		Mango_12 = 0;
	} else {
		Mango_12 = parseInt(eval(document.orderform.Mango_12.value) + 0.5);
		document.orderform.Mango_12.value = parseInt(Mango_12);
	}
	if (isNaN(parseInt(document.orderform.Mango_16.value))) {
		Mango_16 = 0;
	} else {
		Mango_16 = parseInt(eval(document.orderform.Mango_16.value) + 0.5);
		document.orderform.Mango_16.value = parseInt(Mango_16);
	}
	if (isNaN(parseInt(document.orderform.Mango_20.value))) {
		Mango_20 = 0;
	} else {
		Mango_20 = parseInt(eval(document.orderform.Mango_20.value) + 0.5);
		document.orderform.Mango_20.value = parseInt(Mango_20);
	}		
	document.orderform.Mango_Qty.value = parseInt(Mango_12) + parseInt(Mango_16) + parseInt(Mango_20);
	Mango_Total = (parseInt(Mango_12) * 3.00) + (parseInt(Mango_16) * 3.50) + (parseInt(Mango_20) * 4.00);
	document.orderform.Mango_Total.value = formatCurrency(Mango_Total);	
	Subtotal = Subtotal + parseFloat(Mango_Total);
	
	
	//--- Bluesberries ---
	if (isNaN(parseInt(document.orderform.Bluesberries_12.value))) {
		Bluesberries_12 = 0;
	} else {
		Bluesberries_12 = parseInt(eval(document.orderform.Bluesberries_12.value) + 0.5);
		document.orderform.Bluesberries_12.value = parseInt(Bluesberries_12);
	}
	if (isNaN(parseInt(document.orderform.Bluesberries_16.value))) {
		Bluesberries_16 = 0;
	} else {
		Bluesberries_16 = parseInt(eval(document.orderform.Bluesberries_16.value) + 0.5);
		document.orderform.Bluesberries_16.value = parseInt(Bluesberries_16);
	}
	if (isNaN(parseInt(document.orderform.Bluesberries_20.value))) {
		Bluesberries_20 = 0;
	} else {
		Bluesberries_20 = parseInt(eval(document.orderform.Bluesberries_20.value) + 0.5);
		document.orderform.Bluesberries_20.value = parseInt(Bluesberries_20);
	}		
	document.orderform.Bluesberries_Qty.value = parseInt(Bluesberries_12) + parseInt(Bluesberries_16) + parseInt(Bluesberries_20);
	Bluesberries_Total = (parseInt(Bluesberries_12) * 3.50) + (parseInt(Bluesberries_16) * 4.00) + (parseInt(Bluesberries_20) * 4.50);
	document.orderform.Bluesberries_Total.value = formatCurrency(Bluesberries_Total);	
	Subtotal = Subtotal + parseFloat(Bluesberries_Total);
	
	
	//--- PineApple ---
	if (isNaN(parseInt(document.orderform.PineApple_12.value))) {
		PineApple_12 = 0;
	} else {
		PineApple_12 = parseInt(eval(document.orderform.PineApple_12.value) + 0.5);
		document.orderform.PineApple_12.value = parseInt(PineApple_12);
	}
	if (isNaN(parseInt(document.orderform.PineApple_16.value))) {
		PineApple_16 = 0;
	} else {
		PineApple_16 = parseInt(eval(document.orderform.PineApple_16.value) + 0.5);
		document.orderform.PineApple_16.value = parseInt(PineApple_16);
	}
	if (isNaN(parseInt(document.orderform.PineApple_20.value))) {
		PineApple_20 = 0;
	} else {
		PineApple_20 = parseInt(eval(document.orderform.PineApple_20.value) + 0.5);
		document.orderform.PineApple_20.value = parseInt(PineApple_20);
	}		
	document.orderform.PineApple_Qty.value = parseInt(PineApple_12) + parseInt(PineApple_16) + parseInt(PineApple_20);
	PineApple_Total = (parseInt(PineApple_12) * 3.00) + (parseInt(PineApple_16) * 3.50) + (parseInt(PineApple_20) * 4.00);
	document.orderform.PineApple_Total.value = formatCurrency(PineApple_Total);	
	Subtotal = Subtotal + parseFloat(PineApple_Total);
	
	
	//--- ChickenSandwich ---
	if (isNaN(parseInt(document.orderform.ChickenSandwich.value))) {
		ChickenSandwich = 0;
	} else {
		ChickenSandwich = parseInt(eval(document.orderform.ChickenSandwich.value) + 0.5);
		document.orderform.ChickenSandwich.value = parseInt(ChickenSandwich);
	}
	ChickenSandwich_Total = (parseInt(ChickenSandwich) * 7.00);
	document.orderform.ChickenSandwich_Total.value = formatCurrency(ChickenSandwich_Total);	
	Subtotal = Subtotal + parseFloat(ChickenSandwich_Total);
	
	
	//--- ChickenSalad ---
	if (isNaN(parseInt(document.orderform.ChickenSalad.value))) {
		ChickenSalad = 0;
	} else {
		ChickenSalad = parseInt(eval(document.orderform.ChickenSalad.value) + 0.5);
		document.orderform.ChickenSalad.value = parseInt(ChickenSalad);
	}
	ChickenSalad_Total = (parseInt(ChickenSalad) * 7.00);
	document.orderform.ChickenSalad_Total.value = formatCurrency(ChickenSalad_Total);	
	Subtotal = Subtotal + parseFloat(ChickenSalad_Total);
		

	//--- CaesarSalad ---
	if (isNaN(parseInt(document.orderform.CaesarSalad.value))) {
		CaesarSalad = 0;
	} else {
		CaesarSalad = parseInt(eval(document.orderform.CaesarSalad.value) + 0.5);
		document.orderform.CaesarSalad.value = parseInt(CaesarSalad);
	}
	CaesarSalad_Total = (parseInt(CaesarSalad) * 5.00);
	document.orderform.CaesarSalad_Total.value = formatCurrency(CaesarSalad_Total);	
	Subtotal = Subtotal + parseFloat(CaesarSalad_Total);
		
	
	//--- BaguetHotDog ---
	if (isNaN(parseInt(document.orderform.BaguetHotDog.value))) {
		BaguetHotDog = 0;
	} else {
		BaguetHotDog = parseInt(eval(document.orderform.BaguetHotDog.value) + 0.5);
		document.orderform.BaguetHotDog.value = parseInt(BaguetHotDog);
	}
	BaguetHotDog_Total = (parseInt(BaguetHotDog) * 3.00);
	document.orderform.BaguetHotDog_Total.value = formatCurrency(BaguetHotDog_Total);
	Subtotal = Subtotal + parseFloat(Baynana_Total);
	
	
	//--- PitaChips ---
	if (isNaN(parseInt(document.orderform.PitaChips.value))) {
		PitaChips = 0;
	} else {
		PitaChips = parseInt(eval(document.orderform.PitaChips.value) + 0.5);
		document.orderform.PitaChips.value = parseInt(PitaChips);
	}
	PitaChips_Total = (parseInt(PitaChips) * 1.50);
	document.orderform.PitaChips_Total.value = formatCurrency(PitaChips_Total);
	Subtotal = Subtotal + parseFloat(PitaChips_Total);
	

	//--- HealthBar ---
	if (isNaN(parseInt(document.orderform.HealthBar.value))) {
		HealthBar = 0;
	} else {
		HealthBar = parseInt(eval(document.orderform.HealthBar.value) + 0.5);
		document.orderform.HealthBar.value = parseInt(HealthBar);
	}
	HealthBar_Total = (parseInt(HealthBar) * 1.50);
	document.orderform.HealthBar_Total.value = formatCurrency(HealthBar_Total);	
	Subtotal = Subtotal + parseFloat(PitaChips_Total);
		
	
	//--- Snowcones ---
	if (isNaN(parseInt(document.orderform.Snowcones_8.value))) {
		Snowcones_8 = 0;
	} else {
		Snowcones_8 = parseInt(eval(document.orderform.Snowcones_8.value) + 0.5);
		document.orderform.Snowcones_8.value = parseInt(Snowcones_8);
	}
	if (isNaN(parseInt(document.orderform.Snowcones_12.value))) {
		Snowcones_12 = 0;
	} else {
		Snowcones_12 = parseInt(eval(document.orderform.Snowcones_12.value) + 0.5);
		document.orderform.Snowcones_12.value = parseInt(Snowcones_12);
	}
	Snowcones_Total = (parseInt(Snowcones_8) * 1.50) + (parseInt(Snowcones_12) * 2.00);
	document.orderform.Snowcones_Total.value = formatCurrency(Snowcones_Total);	
	Subtotal = Subtotal + parseFloat(Snowcones_Total);
		

	//--- Coffee ---
	if (isNaN(parseInt(document.orderform.Coffee_8.value))) {
		Coffee_8 = 0;
	} else {
		Coffee_8 = parseInt(eval(document.orderform.Coffee_8.value) + 0.5);
		document.orderform.Coffee_8.value = parseInt(Coffee_8);
	}
	if (isNaN(parseInt(document.orderform.Coffee_12.value))) {
		Coffee_12 = 0;
	} else {
		Coffee_12 = parseInt(eval(document.orderform.Coffee_12.value) + 0.5);
		document.orderform.Coffee_12.value = parseInt(Coffee_12);
	}
	Coffee_Total = (parseInt(Coffee_8) * 1.50) + (parseInt(Coffee_12) * 2.00);
	document.orderform.Coffee_Total.value = formatCurrency(Coffee_Total);	
	Subtotal = Subtotal + parseFloat(Coffee_Total);
		
	
	//--- Espresso ---
	if (isNaN(parseInt(document.orderform.Espresso_8.value))) {
		Espresso_8 = 0;
	} else {
		Espresso_8 = parseInt(eval(document.orderform.Espresso_8.value) + 0.5);
		document.orderform.Espresso_8.value = parseInt(Espresso_8);
	}
	if (isNaN(parseInt(document.orderform.Espresso_12.value))) {
		Espresso_12 = 0;
	} else {
		Espresso_12 = parseInt(eval(document.orderform.Espresso_12.value) + 0.5);
		document.orderform.Espresso_12.value = parseInt(Espresso_12);
	}
	Espresso_Total = (parseInt(Espresso_8) * 2.50) + (parseInt(Espresso_12) * 3.00);
	document.orderform.Espresso_Total.value = formatCurrency(Espresso_Total);	
	Subtotal = Subtotal + parseFloat(Espresso_Total);
		

	//--- Set Subtotal ---
	document.orderform.Subtotal.value = formatCurrency(Subtotal);


	//--- Determine Adjusted Subtotal ---
	if (Subtotal <= 200) {
	Adj_Subtotal = Subtotal + 100;
	document.orderform.Adj_Subtotal.value = formatCurrency(Adj_Subtotal);
	}
	
	if (Subtotal > 200 && Subtotal < 300) {
	Adj_Subtotal = 300;
	document.orderform.Adj_Subtotal.value = formatCurrency(Adj_Subtotal);	
	}

	if (Subtotal >= 300) {
	Adj_Subtotal = Subtotal;
	document.orderform.Adj_Subtotal.value = formatCurrency(Adj_Subtotal);	
	}


	//--- Determine Sales Tax ---
	CASalesTax = formatNumber(Adj_Subtotal * .0825)
	document.orderform.CASalesTax.value = formatCurrency(CASalesTax);	


	//-- Determine Grand Total ---
	Grand_Total = parseFloat(Adj_Subtotal) + parseFloat(CASalesTax)
	document.orderform.Grand_Total.value = formatCurrency(Grand_Total);


	//--- Determine Deposit ---
	Deposit = formatNumber(parseFloat(Grand_Total) / 2)
	document.orderform.Deposit.value = formatCurrency(Deposit);
	document.orderform.dblDeposit.value = Deposit;	
	
	
	//--- Check Billing Fields ---
	
	
	
}