// Test browser level
var version = 0;
var ie = 0;
var ns = 0;
var ns6 = 0;

if ( ( (navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 3) ) 
  || ( (navigator.appName == "Microsoft Internet Explorer") &&
     (parseInt(navigator.appVersion) >= 4) ) ) 
  version = "1" ;
else 
  version = "2" ;

ns = (window.navigator.appName == "Netscape")&&(parseInt(navigator.appVersion)<5);
ns6 = (window.navigator.appName == "Netscape")&&(parseInt(navigator.appVersion)>=5);
ie = window.navigator.appName == "Microsoft Internet Explorer";

var browser;
if (ie) browser = "ie";
if (ns || ns6) browser="ns";

  var days_in_month=new Array;
  days_in_month[0]=31;
  days_in_month[1]=29;
  days_in_month[2]=31;
  days_in_month[3]=30;
  days_in_month[4]=31;
  days_in_month[5]=30;
  days_in_month[6]=31;
  days_in_month[7]=31;
  days_in_month[8]=30;
  days_in_month[9]=31;
  days_in_month[10]=30;
  days_in_month[11]=31;

// Set-up to use getMouseXY function onMouseMove
if (!ie) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

var menu_shown = 0;
var menu_seen = 0;
var msg;
var msg_no=0;
var hexa = new Array(16);
var sr,sg,sb,er,eg,eb,step,at;
var msg_count=0;
var tag;

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (ie) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  return true
}

function getLayer (id,document) {
  if(!document) 
    { 
      document = window.document; 
    }
  if (document.layers) 
    {
      var myid = id + "l";
      for (var l = 0; l < document.layers.length; l++)
        {
          if (document.layers[l].id == myid)
            return document.layers[l];
	}
      for (var l = 0; l < document.layers.length; l++) 
        {
          var result = getLayer(id, document.layers[l].document);
          if (result)
            return result;
        }
      return null;
    }
  else 
    { 
      if (document.all) 
        {
          return document.all[id];
        }
      else 
        {
	  if (document.getElementById) 
	    {
              return document.getElementById(id);
            }
	}
    }
}


function setMsg() {
  if(msg_no>(msg_count-1)) {
   msg_no = 0; 
   }
  var l = getLayer(tag,document);
  if(l) {

  if(document.layers) {
    l.open();
    l.write(msg[msg_no]);
    l.close();    
  }
  else {
    if(ie) {
      l.innerText = msg[msg_no]; 
      }
    else {
      l.innerHTML = msg[msg_no];
      }
    }
  }
  fade(0,0,0,255,255,192,100);
  msg_no++;
//  setTimeout("setMsg()",5000);
  }


function hex(i) {
	if (i < 0) return "00";
	else if (i > 255) return "ff";
	else return "" + hexa[Math.floor(i/16)] + hexa[i%16];
}

function setColor(r, g, b) {
	var hr = hex(r); var hg = hex(g); var hb = hex(b);
  var l = getLayer(tag,document);
  if(l) {
	l.style.color = "#"+hr+hg+hb;
  }
}

function setFg() {
	setColor(
		Math.floor(sr * ((step-at)/step)  + er * (at/step)),
		Math.floor(sg * ((step-at)/step) +  eg * (at/step)),
		Math.floor(sb * ((step-at)/step) +  eb * (at/step)));
	at++;
	if (at<=step) 
	  setTimeout("setFg()",1);
	else
	  setTimeout("setMsg()",250);
	}

function fade(r1,g1,b1,r2,g2,b2,s) {
  sr=r1;
  sg=g1;
  sb=b1;
  er=r2;
  eg=g2;
  eb=b2;
  step=s;
  at=0;
  setFg();
}

function openIt(x) {
 var menuitems = 7;
 menu_shown = 1;
       var yLoc=tempY-5;
       var xLoc=tempX+20;
       var tWin;
       var bWin;
       if (document.documentElement && document.documentElement.scrollTop) {
	  tWin = document.documentElement.scrollTop;
	  bWin = tWin+document.documentElement.clientHeight;
	  }
	else {
	  if (document.body) {
	    tWin = document.body.scrollTop
	    bWin = tWin+document.body.clientHeight;
	    }
          else {
	    tWin=window.pageYOffset;
	    bWin=tWin+window.innerHeight;
            }
	  }
       var hDiv=0;


       for (i=0; i<menuitems; i++) {
         if(i==x) continue;
	 if(ns) {
	 var oLayer = getLayer("layer"+i);
	 if(oLayer) {
           oLayer.visibility = "hide";
           }
         }    
     if(ns6) 
       {
         var oLayer = document.getElementById("div"+i);
	 if(oLayer) 
	   {
	     oLayer.style.visibility = "hidden";
	   }
       }    
     if(ie) {
     document.all["div"+i].style.visibility = "hidden";
//         eval("document.all.div"+i+".style.visibility = \"hidden\";");
       }
     }

     if(ns) {
       var oLayer = getLayer("layer"+x);
       if(oLayer) {
	 hDiv = oLayer.clip.height;
	 if((yLoc+hDiv)>bWin) {
           yLoc = bWin-hDiv;
	   }
       oLayer.visibility = "show";
       oLayer.top=yLoc;
       oLayer.left=xLoc;
       window.status=hDiv+" "+yLoc+" "+bWin;
       }

       }    
     if(ns6) 
       {
         var oLayer = document.getElementById("div"+x);
	 hDiv = oLayer.offsetHeight;
	 if((yLoc+hDiv)>bWin) {
           yLoc = bWin-hDiv;
	   }
         if(oLayer) 
	   {
	     var posY = yLoc;
	     var posX = xLoc;
	     oLayer.style.visibility = "visible";
	     oLayer.style.position = "absolute";
	     oLayer.style.top=posY+"px";
	     oLayer.style.left=posX+"px";
	   }
       }    
     if(ie) {
       var obj = document.all["div"+x];
       hDiv=obj.offsetHeight;
       if((yLoc+hDiv)>bWin) {
         yLoc = bWin-hDiv;
	 }
       obj.style.visibility = "visible";
       obj.style.position = "absolute";
       obj.style.top = yLoc;
       obj.style.left = xLoc;
       }
  }

function seeMenu() {
  menu_seen = 1;
}

function safeClose() {
  if(ns)
    {
      if(menu_seen)
        {
	  closeAll();
        }
     }
}

function closeAll() {
  var menuitems = 7
  menu_shown=0;
  menu_seen = 0;

  for (i=0; i<menuitems; i++) 
    {
      if(ie)
        { 
	  eval("document.all.div"+i+".style.visibility = \"hidden\";"); 
	}
       if(ns)
         { 
	   var oLayer = getLayer("layer"+i);
	   if(oLayer) {
	     oLayer.visibility = "hide";
	     }
         }
       if(ns6)
         { 
	   var oLayer = document.getElementById("div"+i);
	   if(oLayer) {
	     oLayer.style.visibility = "hidden";
	     }
         }
    }
 }

function hiLite(imgDocID,imgObjName,imgTitle) {
if(version == "1") {
document.images[imgDocID].src = eval(imgObjName + ".src")
// document.phone.number.value = imgTitle
}
}
var times = new Array();
times ={T00 : "6:00",
	T11 : "11:00",
	T12 : "11:00",
	T13 : "11:00",
	T21 : "1:30",
	T22 : "1:30",
	T23 : "1:30",
	T31 : "4:00",
	T32 : "4:00",
	T33 : "4:00",
	T41 : "6:00",
	T42 : "6:00",
	T43 : "6:00"
	};
rooms={T00 : "All",
	T11 : 1,
	T12 : 2,
	T13 : 3,
	T21 : 1,
	T22 : 2,
	T23 : 3,
	T31 : 1,
	T32 : 2,
	T33 : 3,
	T41 : 1,
	T42 : 2,
	T43 : 3
	};

function format(expr, decplaces) {
// Convert the number to a string 
str = expr.toString() 
// Get the position of the decimal point 
point = str.indexOf(".")
if(point<0) {
  str = str + '.';
  point = str.indexOf(".")
}
  str = str + '00';

// Get the substring to the correct decimal place 
newstring = str.substring(0, Number(point) + Number(decplaces) + 1) 
file://Convert the string to a number, and return 
//return(Number(newstring)) 
return(newstring) 
} 

function changeTime(me,label_t,label_r) {
  var t=me.value;
  // The first label is the field where the time is displayed on the form
  // The second label is the hidden input that sends the time to the next page
  var target = document.getElementById(label_t);
  target.value=times[t];
  var target = document.getElementById(label_r);
  target.value=rooms[t];
}

function changeNumber(form,me,size,cost,label) {
var extra=0;
if(me.value>size)
  {
	var diff = me.value - size;
	extra = diff*cost;
  }
  extra += 0.00;
  var target = document.getElementById(label);
  target.innerHTML=format(extra,2);
  updateTotal();
}

// Set year when MakeReservation page first comes up
function loadMakeReservation() {
  var now = new Date();
  var year = now.getFullYear();

  var year_field=document.getElementById("party_year");
  year_field.value=year;
}

function changeAttendance(form,me,size,cost,label) {
var extra=0;
var kids=me.value;
if(kids>size)
  {
	var diff = me.value - size;
	extra = diff*cost;
  }
  extra += 0.00;
  var target = document.getElementById(label);
  target.innerHTML=format(extra,2);
  target = document.getElementById('goody_bags_included');
  target.innerHTML=me.value;

  target = document.getElementById('theme');
  changeTheme(target,theme,paper_goods_themed_dozen,paper_goods_themed_extra,'cost_themedpapergoods','show_cost_themedpapergoods');
  var pizzas = pizza_count;
  if(pizzas>0)
    {
      while(kids>12) {
        pizzas++;
        kids -= 16;
      } 
    }
  target = document.getElementById('pizzas_included');
  target.innerHTML=pizzas;
  changePizza(1,pizza_pie_cost,pizza_pie_topping_cost,'cost_pizzas');

  var drinks = drink_count;
  while(kids>12) {
    drinks++;
    kids -= 16;
  }
  target = document.getElementById('drinks_included');
  target.innerHTML=drinks;
  changeDrink(form,drinks,drink_cost,'cost_drinks');

  updateTotal();
}

function changeExtraCake(form,me,label) {
  var extra=0;
  if(me.selectedIndex==2) {
    extra=extra_half_cake;
    }
  if(me.selectedIndex==3) {
    extra=extra_quarter_cake;
    }
  extra += 0.00;
  var target = document.getElementById(label);
  target.innerHTML=format(extra,2);
  updateTotal();
}

function changeSelection(me,label) {
  var extra = me.options[me.selectedIndex].value;
  var target = document.getElementById(label);
  target.innerHTML=format(extra,2);
  updateTotal();
}

function changeDrink(form,limit,cost,label) {
  var count=0;
  var val;
  var extra = 0;
  var flavor;
  val = form.elements['pepsi'].value;
  if(parseInt(val) == val) {
	count += parseInt(val);
	}
  val = form.elements['dietpepsi'].value;
  if(parseInt(val) == val) {
	count += parseInt(val);
	}
  val = form.elements['sevenup'].value;
  if(parseInt(val) == val) {
	count += parseInt(val);
	}
  val = form.elements['rootbeer'].value;
  if(parseInt(val) == val) {
	count += parseInt(val);
	}
  val = form.elements['orange'].value;
  if(parseInt(val) == val) {
	count += parseInt(val);
	}
  val = form.elements['juice'].value;
  if(parseInt(val) == val) {
	count += parseInt(val);
	}
  val = form.elements['coffee'].value;
  if(parseInt(val) == val) {
	count += parseInt(val);
	}
  if(count>limit) {
    var diff = count-limit;
    extra = diff*cost;
  }
  extra += 0.00;
  var target = document.getElementById(label);
  target.innerHTML=format(extra,2);
  updateTotal();

}

function changePizza(pie_no,pie_cost,topping_cost,label) {
  var amt=0;
  var allowed_obj = document.getElementById('pizzas_included');
  var allowed = allowed_obj.innerHTML;
  var pie_count=0;
  var topping_count=0;
  var cheese_count=0;
  var pie;
  var  topping;
  pie = document.getElementById('cheesepizza');
  cheese_count = parseInt(pie.value);
  if(cheese_count != pie.value) {
    cheese_count = 0;
  }
  pie_count = cheese_count;
  for(i=1;i<=4;i++) {
    pie = document.getElementById('pizza'+i);
    topping = pie.value
    topping = (topping.replace(/^\W+/,'')).replace(/\W+$/,'');
    if(topping != "") {
      pie_count++;
      topping_count++;
    }
  }
  if(pie_count < allowed) {
    cheese_count += allowed - pie_count;
    pie = document.getElementById('cheesepizza');
    pie.value = cheese_count;
    pie_count = allowed;
  }
  amt = topping_count*(topping_cost-pie_cost);
  var a1 = topping_count*topping_cost;
  var a2;
  if(pie_count>allowed) {
    amt += (pie_count-allowed)*pie_cost;
  }

  var target = document.getElementById(label);
  target.innerHTML=format(amt,2);
  updateTotal();
}

function changePizzaTopping(pie_no,pie_cost,topping_cost,label) {
  var topping = document.getElementById('pizzatopping'+pie_no);
  var pie = document.getElementById('pizza'+pie_no);
  if(topping.value != "") {
    pie.checked = true;
  }
  else {
    pie.checked = false;
  }
  changePizzaOrder(pie_no,pie_cost,topping_cost,label);
}

function changeChips(form,me,limit,cost,label) {
  var val = 0;
  var chip_count = 0;
  var obj;
  var extra = 0;
  var target = new Array();
  target[0]='potato';
  target[1]='pretzels';
  target[2]='doritos';
  target[3]='doodles';
  var asize=4;
  var i;
  
  for(i=0;i<asize;i++) {
    var obj = document.getElementById(target[i]);
    if(obj) {
      val = parseFloat(obj.value);
      if(val != obj.value) {
        val = 0;
      }
      chip_count += val;
    }
  }
  if(chip_count>limit) {
    extra = (chip_count - limit) * cost;
  }
  var target = document.getElementById(label);
  target.innerHTML=format(extra,2);
  updateTotal();
}


function changeLatexBalloons(me,size,cost,dozen,label) {
  var extra=0;
  var val = me.value;
  var newValue=0;
  if(parseInt(val)==val) {
    newValue = parseInt(val);
    }
  var diff = me.value;
  while(diff>=12) {
    extra += dozen;
    diff -= 12;
    }
  extra += diff*cost;
  var target = document.getElementById(label);
  target.innerHTML=format(extra,2);
  updateTotal();
}


function changeMylarBalloons(form,limit,cost,label) {
  var count=0;
  var val;
  var extra = 0;
  val = form.elements['mylarballoon1'].value;
  if(parseInt(val) == val) {
	count += parseInt(val);
	}
  val = form.elements['mylarballoon2'].value;
  if(parseInt(val) == val) {
	count += parseInt(val);
	}
  if(count>limit) {
    var diff = count-limit;
    extra = diff*cost;
  }
  extra += 0.00;
  var target = document.getElementById(label);
  target.innerHTML=format(extra,2);
  updateTotal();

}

function changePinata(me,cost,label) {
var extra=0;
if(me.value != "")
  {
	extra = cost;
  }
  var target = document.getElementById(label);
  target.innerHTML=format(extra,2);
  updateTotal();
}


function changeWaitService(form,me,cost,label) {
  var target = document.getElementById(label);
  target.innerHTML=cost;
  updateTotal();
}

function changeYesNo(form,me,cost,label) {
  var target = document.getElementById(label);
  target.innerHTML=format(cost,2);
  updateTotal();
}

function transferAmount(me,label) {
  var val=parseFloat(me.value);
  if(val != me.value) {
    val = 0;
  }
  var target = document.getElementById(label);
  target.innerHTML=format(val,2);
  updateTotal();
}

function changeTheme(me,included,dozen,extra,label,label2) {
var amt=0;
// window.alert("Cost per dozen = " + dozen + ", " + extra + " for each extra");
var target = document.getElementById('count');
var count = target.value;
if(me.value != "") {
  if(included == 0) {
    if(count<12) {
      count = 12;
    }
  while(count>=12) {
    amt += dozen;
    count -= 12;
    }
  amt += count * extra;
  }
}
// window.alert("$" + amt);
target = document.getElementById(label);
target.value=format(amt,2);
target = document.getElementById(label2);
target.innerHTML=format(amt,2);
updateTotal();
}


function updateTotal() {
  var target = new Array;
  target[0]='cost_time';
  target[1]='cost_children';
  target[2]='show_cost_cake';
  target[3]='cost_extra_cake';
  target[4]='cost_pizzas';
  target[5]='cost_veggie_tray';
  target[6]='cost_cheese_tray';
  target[7]='cost_subs';
  target[8]='cost_salad';
  target[9]='cost_chips';
  target[10]='cost_drinks';
  target[11]='cost_lballoons';
  target[12]='cost_mballoons';
  target[13]='cost_pinata';
  target[14]='cost_goodybags';
  target[15]='show_cost_themedpapergoods';
  target[16]='cost_magician';
  target[17]='cost_misc';
  var asize=18;
  var total=0;
  var i;

  var val;
  var month_obj = document.getElementById('party_month');
  var month_value = month_obj.value;
  var day_obj = document.getElementById('party_day');
  var day_value = day_obj.value;
  var year = party_year(month_value,day_value);
  var dow = party_dow(month_value-1,day_value);
  if((dow==0) || (dow>4)) {
    total = weekend_cost;
  }
  else {
    total = weekday_cost;
  }
  var pkgobj = document.getElementById('cost_package');
  pkgobj.innerHTML=format(total,2);


  for(i=0;i<asize;i++) {
    var obj = document.getElementById(target[i]);
    if(obj) {
      val = parseFloat(obj.innerHTML);
      if(val == obj.innerHTML) {
        total += val;
      }
    }
    else {
    //       alert(target[i] + ' not found');
    }
  }
  var obj = document.getElementById('cost_credits');
  val = parseFloat(obj.innerHTML);
  if(val == obj.innerHTML) {
    total -= val;
  }

  var loc;
  loc = document.getElementById('cost_subtotal');
  if(loc) {
    loc.innerHTML=format(total,2);
    }

  loc = document.getElementById('percentage_service_charge');
  val = 0;
  if(loc) {
    val = parseInt(loc.innerHTML);
    if(val != loc.innerHTML) {
      val = 0;
    }
  }
  else {
    alert('cannot find service_charge');
  }
  loc = document.getElementById('cost_magician');
  var magician = parseFloat(loc.innerHTML);  
  val = val*(total-magician)/100 + 0.005;
  loc = document.getElementById('cost_service_charge');
  loc.innerHTML=format(val,2);
  total += parseFloat(format(val,2));
  val = total*tax/100 + 0.005;
  loc = document.getElementById('cost_tax');
  loc.innerHTML=format(val,2);
  total += parseFloat(format(val,2));
  loc = document.getElementById('cost_total');
  loc.innerHTML=format(total,2);
  var total_cost = total;
  loc = document.getElementById('deposit');
  val = parseFloat(loc.innerHTML);
  total -= parseFloat(format(val,2));
  loc = document.getElementById('paid');
  val = parseFloat(loc.innerHTML);
  total -= parseFloat(format(val,2));
  loc = document.getElementById('balance_due');
  loc.innerHTML=format(total,2);
  return format(total_cost,2);
}

function pickCake(form) {
  if(form.cake[0].checked) {
    form.cakeflavor.disabled = false;
    form.icingflavor.disabled = false;
    }
  else
    {	
    form.cakeflavor.disabled = true;
    form.icingflavor.disabled = true;
    }
  changeCakeType(form,'cost_cake','show_cost_cake')
}

function changeCakeType(form,label,label2) {
  var cost = 0;
  if(form.cake_type[1].checked) {
    if(form.cake[0].checked) {
      // Bakery
      cost = bakery_cake_themed;
    }
    else {
      if(form.cake[1].checked) {
        // Ice cream
        cost = ice_cream_cake_themed;
      }
    }
  }
  else {
    if(form.cake_type[2].checked) {
      // Picture cake -- need to make sure we have a week
      var now = new Date();
      var nowval = now.getTime();
      earliest = nowval + 6*24*60*60*1000 + 12*60*60*1000;
      var month_obj = document.getElementById('party_month');
//      var mo = month_obj.options[month_obj.selectedIndex].value;
      var mo = month_obj.value;
      var day_obj = document.getElementById('party_day');
//      var day = day_obj.options[day_obj.selectedIndex].value;
      var day = day_obj.value;
      var year = party_year(mo,day);
      var partydate = new Date(year,mo-1,day);
      var partyval = partydate.getTime();
      if(partyval<earliest) {
	window.alert("At least one week prior notice is required to request a picture cake");
	form.cake_type[2].checked = false;
	form.cake_type[0].checked = true;
      }
      else {
        cost = picture_cake;
      }
    }
  }
  var target = document.getElementById(label);
  target.value=format(cost,2);
  var target = document.getElementById(label2);
  if(typeof(target) != "undefined") {
    target.innerHTML=format(cost,2);
  }
  else {
    window.alert("Skipping " + label2);
  }
  updateTotal();
}

function pickCake2(me,cost,label) {
  var flavorobj = document.getElementById('extracakeflavor');
  var icingobj = document.getElementById('extraicingflavor');
  if((me.value == "bakeryhalf")||(me.value == "bakeryquarter")) {
    flavorobj.disabled = false;
    icingobj.disabled = false;
    }
  else
    {	
    flavorobj.disabled = true;
    icingobj.disabled = true;
    }
  var target = document.getElementById(label);
  target.innerHTML=format(cost,2);
  updateTotal();
}

function checkReserveForm(form) {
  if(form.lastname.value == "") {
    window.alert("Please enter last name");
    return false;
  }
  if(form.firstname.value == "") {
    window.alert("Please enter first name");
    return false;
  }
  if(form.street1.value == "") {
    window.alert("Please enter street address");
    return false;
  }
  if(form.city.value == "") {
    window.alert("Please enter city");
    return false;
  }
  if(form.state.value == "") {
    window.alert("Please enter state");
    return false;
  }
  if(form.zip.value == "") {
    window.alert("Please enter zipcode");
    return false;
  }
  if(form.phone.value == "") {
    window.alert("Please enter phone number");
    return false;
  }
  var box = form.elements['package'];
  var pkg = box.options[box.selectedIndex].value;
  if(pkg == -1) {
    window.alert("Please select a party package.");
    return false;
  }		
  box = form.elements['party_month'];
  var mo = box.options[box.selectedIndex].value;
  if((mo<1)||(mo>12)) {
    window.alert("Please select a month for the party.");
    return false;
  }		
  box = form.elements['party_day'];
  var day = box.options[box.selectedIndex].value;
  if((day<1)||(day>days_in_month[mo-1])) {
    window.alert("Please select a valid day for the party.");
    return false;
  }
  if(form.email.value == "") {
    cont = confirm("Please ask if customer wants email confirmation.  If email confirmation is requested, press cancel and ask for the email address.  To continue without email confirmation, press OK.");
    if(!cont) {	
      return false;
    }
  }
  if(form.childname.value == "") {
    cont = confirm("No name has been entered for the Birthday Child.  If this is OK, press OK.  Otherwise press cancel and enter the Birthday Child's name.");
    if(!cont) {	
      return false;
    }
  }
  return true;
}

function checkCollectForm(form) {
	var obj;
	var i = 0;
	if(typeof(document.resform.oldtime) == "undefined") {
  	  while(i<12) {	   	
	    if(typeof(document.resform.time[i]) != "undefined") {
	      if(document.resform.time[i].checked) {	
//		  window.alert(i + " is checked");
	         break;	
	      }	
            }
	    i++;
	  }
        }
  if(i>=12) {
    if((typeof(document.resform.time) == "undefined") || (!document.resform.time.checked)) {
      window.alert("Please check a party time");
      return false;
    }
  }

// Check child count and theme
  if(form.count.value == "") {
    window.alert("Please enter the number of children attending");
    return false;
  }
  if((theme>0)&&(form.theme.value == "")) {
    window.alert("Please enter the party theme");
    return false;
  }

// Check the cake choices
  obj = document.resform;
  if(typeof(obj.cake) != "undefined"){
    if(obj.cake[0].checked) {		
      // This is a bakery cake
      obj = document.getElementById('cakeflavor');  
      if(obj.options[obj.selectedIndex].value == "-1") {	
        window.alert("Please select bakery cake flavor");
        return false;
      }
      obj = document.getElementById('icingflavor');  
      if(obj.options[obj.selectedIndex].value == "-1") {	
        window.alert("Please select bakery cake icing flavor");
        return false;
      }
    }
  else {
    if(!obj.cake[1].checked) {		
        window.alert("Please select bakery or ice cream cake");
        return false;
    }
  }
 }
  obj = document.resform;
    if((obj.extracake[0].checked)||(obj.extracake[1].checked)) {		
      // Extra bakery cake
      obj = document.getElementById('extracakeflavor');  
      if(obj.options[obj.selectedIndex].value == "-1") {	
        window.alert("Please select additional bakery cake flavor");
        return false;
      } 
      obj = document.getElementById('extraicingflavor');  
      if(obj.options[obj.selectedIndex].value == "-1") {	
        window.alert("Please select additional bakery cake icing flavor");
        return false;
      }
    }
 
// Check drinks
  var drinkcount = 0;
drinkcount += form.dietpepsi.value;
  drinkcount += form.pepsi.value;
  drinkcount += form.sevenup.value;
  drinkcount += form.rootbeer.value;
  drinkcount += form.orange.value;
  drinkcount += form.juice.value;
  drinkcount += form.coffee.value;
  if(drinkcount < drink_count) {
    var needed = drink_count - drinkcount;
    window.alert("Please select " + needed + " more drink(s)");
    return false;
    }
  if(!form.refill[0].checked && !form.refill[1].checked) {
  window.alert("Is Auto-Refill requested?");
  return false;
  }

// Check chips
// Check that snack counts match the number allowed
  var c_target = new Array(); 
  c_target[0]='potato';
  c_target[1]='pretzels';
  c_target[2]='doritos';
  c_target[3]='doodles';
  var c_size=4;
  var c_count = 0;
  
  for(i=0;i<c_size;i++) {
    var obj = document.getElementById(c_target[i]);
    if(obj) {
      var val = parseFloat(obj.value);
      if(val != obj.value) {
        val = 0;
      }
      c_count += val;
    }
  }
  if(c_count<chip_count) {
      alert("Please make " + chip_count + " chip choices");
      return false;
  }

// Check Wait Service
  if(!document.resform.waitservice[0].checked && !document.resform.waitservice[1].checked) {
  window.alert("Is the Wait Service requested?");
  return false;
  }

// Check Magician
  if(!document.resform.magician[0].checked && !document.resform.magician[1].checked) {
  window.alert("Is the Magician requested?");
  return false;
  }

// Check Order taken by field
  if(form.takenby.value == "") {
    window.alert("Please enter the \"Order Taken By\" field");
    return false;
  }
	     	
  var party_total = updateTotal();
var monthno = document.getElementById('party_month');
var dayno = document.getElementById('party_day');
var timeval = "";
for (i = 0; i < form.time.length; i++)
{
if (form.time[i].checked)
    timeval = form.time[i].value;
}
  if(timeval == "") {
    var oldtime = document.getElementById('oldtime');
    if(typeof(oldtime) != "undefined") {    
      timeval = oldtime.value;
    }
  }
  var deposit_loc = document.getElementById('deposit');
  var deposit_val = parseFloat(deposit_loc.innerHTML);

var confirmation_message = "Please confirm that you wish to make a reservation on " + months[monthno.value-1] + " " + dayno.value + " at " + times[timeval] + " in room " + rooms[timeval] + ". The cost this party is \$"  + party_total + " and a deposit of \$" + deposit_val + " has been paid.  Press OK to confirm reservation.  Press Cancel to continue collecting party information";

  cont = confirm(confirmation_message);
      if(!cont) {
        return false;
	}
return true;
}

function party_year(month,day) {
    now = new Date();
    nowval = now.getDate();
    year = now.getFullYear();
//create an epoch time assuming the party is this year
    partydate = new Date(year,month,day);
    partyval = partydate.getDate();
    if(partyval<nowval) {
//	# if the month/day has already passed this year, the party
//	# must be for next year
	year++;
    }
    return year;
}

function party_dow(month,day) {
    now = new Date();
    nowval = now.getTime();
    year = now.getFullYear();
// create an epoch time assuming the party is this year
    partydate = new Date(year,month,day);
    partyval = partydate.getTime();
    if(partyval < nowval) {
//	# if the month/day has already passed this year, the party
//	# must be for next year
//    alert(partyval + " is less than " + nowval);
        year++;
        partydate = new Date(year,month,day);
    }
    return partydate.getDay();
}
