  function handleError(msg,url,line)   {
    alert('msg = ' + msg + '\n\n' + 'line = ' + line + '\n\n' + 'url = ' + url);
    return true;
  }// end function
  window.onerror = handleError;
  //=================================================================================================

  function calculate() {
    var int_sales_tax_rate = '0.065';  // sales tax is caclulated on products with this rate
    var num_of_people = parseInt(document.forms[0].Number_of_People.value);
    var obj, int_sales_tax, int_grand_total;
    var int_product_sub_total = 0; //holds the product subtotal
    var int_service_sub_total = 0; //holds the service subtotal
    var message_no_people = "One or more of the items you\'ve selected requires the Number of People.\n\nPlease enter the number of people to calculate an accurate total.";
    var no_people_shown = "no";
    if ( isNaN(num_of_people) ) {
      num_of_people = 0;
    }// end if
    var last_category = "first_run";
    var curr_category;
    var print_switch = 0;
    var category_index = 0;
    for(i=0; i < document.forms[0].length; i++) { //alert('name = ' + obj.name + '\n\n type = ' + obj.type + '\n\n value = ' + obj.value);
      obj = document.forms[0][i]; 
        if (obj.type != 'hidden') {
          if (obj.id.substr(0,7) != 'upgrade') { // SKIP THE ITEMS THAT START WITH UPGRADE
            curr_category = obj.name;
            if (curr_category != "addtl_bartending") { // IF THIS IS THE ADDTL BARTENDING ITEM SKIP OVER IT B/C IT DOES NOT FOLLOW THE FORMAT
	            if (last_category != curr_category ) {
	              //alert('last = ' + last_category + '\n curr = ' + curr_category + '\n print switch: ' + print_switch);
	              if (print_switch > 0) {
	                if ( document.getElementById('fieldset_'+last_category) ) {
	                  document.getElementById('fieldset_'+last_category).className = "do_print_cat"
	                }// end if
	              } else {
	                if ( document.getElementById('fieldset_'+last_category) ) {
	                  document.getElementById('fieldset_'+last_category).className = "do_not_print_cat"
	                }// end if
	              }// end if
	              print_switch = 0;
	              category_index = 1;
	              last_category = curr_category;
	            } else { // we are in the same category
	              category_index++;
	            }// end if
            }// end if          
          }// end if          
        }// end if          
        switch(obj.type) {
          case "radio":
            if ( obj.checked ) {
              if ( obj.value != "0.00" ) {
                document.getElementById(obj.name+'_'+category_index).className = "do_print_item";            
                if ( obj.name == 'breakfast_type' ) {
                  print_switch++;
                  if ( (num_of_people <= 0) && (no_people_shown=="no") ) {
                    alert(message_no_people);
                    no_people_shown = "yes";
                  } else {
                    int_product_sub_total = int_product_sub_total + ( num_of_people * obj.value );
                  }// end if            
                } else if ( obj.name == 'buffet_menu' ) {
                  print_switch++;
                  if ( (num_of_people <= 0) && (no_people_shown=="no") ) {
                    alert(message_no_people);
                    no_people_shown = "yes";
                  } else {
                    int_product_sub_total = int_product_sub_total + ( num_of_people * obj.value );

                    // BUFFET 2 & 3 HAVE UPGRADES THAT NEED TO BE CHECKED
                    if ( (category_index == '2') || (category_index == '3') ) {
                      tempStr = 'upgrade_1_buffet_' + category_index ;
                      if ( document.getElementById(tempStr).checked ) {
                        //alert('item: ' + tempStr + '\n adding: ' + num_of_people * document.getElementById(tempStr).value);
                        int_product_sub_total = int_product_sub_total + ( num_of_people * document.getElementById(tempStr).value );                    
                      }// end if
  
                      tempStr = 'upgrade_2_buffet_' + category_index ;
                      if ( document.getElementById(tempStr).checked ) {
                        //alert('item: ' + tempStr + '\n adding: ' + num_of_people * document.getElementById(tempStr).value);
                        int_product_sub_total = int_product_sub_total + ( num_of_people * document.getElementById(tempStr).value );                    
                      }// end if
                    }// end if

                  }// end if            
		              if ( obj.id == "buffet_2" ) {
		                document.getElementById('upgrade_1_buffet_2').disabled = false;              
		                document.getElementById('upgrade_2_buffet_2').disabled = false;              
		              } else if (obj.id == "buffet_3") {
		                document.getElementById('upgrade_1_buffet_3').disabled = false;              
		                document.getElementById('upgrade_2_buffet_3').disabled = false;              
		              }// end if
                } else if ( obj.name == 'drop_off_menu' ) {
                  print_switch++;
                  if ( (num_of_people <= 0) && (no_people_shown=="no") ) {
                    alert(message_no_people);
                    no_people_shown = "yes";
                  } else {
                    int_product_sub_total = int_product_sub_total + ( num_of_people * obj.value );
                    // DROP OFF 2 HAS UPGRADES THAT NEED TO BE CHECKED
                    if ( (category_index == '2') ) {
                      tempStr = 'upgrade_1_drop_off_' + category_index ;
                      if ( document.getElementById(tempStr).checked ) {
                        //alert('item: ' + tempStr + '\n adding: ' + num_of_people * document.getElementById(tempStr).value);
                        int_product_sub_total = int_product_sub_total + ( num_of_people * document.getElementById(tempStr).value );                    
                      }// end if
  
                      tempStr = 'upgrade_2_drop_off_' + category_index ;
                      if ( document.getElementById(tempStr).checked ) {
                        //alert('item: ' + tempStr + '\n adding: ' + num_of_people * document.getElementById(tempStr).value);
                        int_product_sub_total = int_product_sub_total + ( num_of_people * document.getElementById(tempStr).value );                    
                      }// end if
                    }// end if
                  }// end if            
		              if ( obj.id == "drop_off_2" ) {
		                document.getElementById('upgrade_1_drop_off_2').disabled = false;              
		                document.getElementById('upgrade_2_drop_off_2').disabled = false;              
		              }// end if
                }// end if
              }// end if
            } else {
              if ( document.getElementById(obj.name+'_'+category_index) ) {
                document.getElementById(obj.name+'_'+category_index).className = "do_not_print_item";            
              } else {
                alert('FAILED - This ID does not exist - ' + obj.name+'_'+category_index);
              }// end if
              if ( obj.id == "buffet_2" ) {
                document.getElementById('upgrade_1_buffet_2').checked = false;              
                document.getElementById('upgrade_2_buffet_2').checked = false;              
                document.getElementById('upgrade_1_buffet_2').disabled = true;              
                document.getElementById('upgrade_2_buffet_2').disabled = true;              
              } else if (obj.id == "buffet_3") {
                document.getElementById('upgrade_1_buffet_3').checked = false;              
                document.getElementById('upgrade_2_buffet_3').checked = false;              
                document.getElementById('upgrade_1_buffet_3').disabled = true;              
                document.getElementById('upgrade_2_buffet_3').disabled = true;              
              } else if (obj.id == "drop_off_2") {
                document.getElementById('upgrade_1_drop_off_2').checked = false;              
                document.getElementById('upgrade_2_drop_off_2').checked = false;              
                document.getElementById('upgrade_1_drop_off_2').disabled = true;              
                document.getElementById('upgrade_2_drop_off_2').disabled = true;              
              }// end if
            }// end if          
            break;
          case "checkbox":
            if ( obj.checked ) {
              if ( obj.name == 'tray' ) {
                document.getElementById(obj.name+'_'+category_index).className = "do_print_item";            
                print_switch++;
                if ( (num_of_people <= 0) && (no_people_shown=="no") ) {
                  alert(message_no_people);
                  no_people_shown = "yes";
                } else {
                  if ( (obj.id == "chocolate_fountain") && (num_of_people * obj.value < 300) ) { //IF THIS IS A CHOCHOLATE FOUNTAIN THEN THE PRICE MUST BE $300 REGARDLESS OF THE NUMBER OF PEOPLE
                    int_product_sub_total = int_product_sub_total + 300;
                  } else {
                    int_product_sub_total = int_product_sub_total + ( num_of_people * obj.value );
                  }// end if
                } //end if            
							} else if ( obj.name == 'station' ) {  //} else if ( obj.name == 'finger_foods' ) { 
                document.getElementById(obj.name+'_'+category_index).className = "do_print_item";            
                print_switch++;
                if ( (num_of_people <= 0) && (no_people_shown=="no") ) {
                  alert(message_no_people);
                  no_people_shown = "yes";
                } else {
                  if ( (obj.id == "coffee_and_desert") && (num_of_people * obj.value < 400) ) { //IF THIS IS A COFFEE AND DESER STATION THEN THE PRICE MUST BE $400 REGARDLESS OF THE NUMBER OF PEOPLE
                    int_product_sub_total = int_product_sub_total + 400;
                  } else {
                    int_product_sub_total = int_product_sub_total + ( num_of_people * obj.value );
                  }// end if
                } //end if            

              } else if ( obj.name == 'great_endings' ) {
                document.getElementById(obj.name+'_'+category_index).className = "do_print_item";
                print_switch++;
                if ( (num_of_people <= 0) && (no_people_shown=="no") ) {
                  alert(message_no_people);
                  no_people_shown = "yes";
                } else {
                  if ( (obj.id == "coffee_and_desert2") && (num_of_people * obj.value < 400) ) { //IF THIS IS A COFFEE AND DESER STATION THEN THE PRICE MUST BE $400 REGARDLESS OF THE NUMBER OF PEOPLE
                    int_product_sub_total = int_product_sub_total + 400;
                  } else {
                    int_product_sub_total = int_product_sub_total + ( num_of_people * obj.value );
                  }// end if
                } //end if            



              } else if ( obj.name == 'additional' ) { //alert(obj.name+'_'+category_index);
                document.getElementById(obj.name+'_'+category_index).className = "do_print_item";
                print_switch++;
                switch(obj.id) {
                  //case "liquor_pickup":
                    //int_service_sub_total = int_service_sub_total + parseFloat(obj.value);
                    //break;
                  case "bar_glassware":
                  case "champagne_glassware":
                    if ( (num_of_people <= 0) && (no_people_shown=="no") ) {
                      alert(message_no_people);
                      no_people_shown = "yes";
                    } else {
                      int_service_sub_total = int_service_sub_total + ( num_of_people * obj.value );
                    } //end if            
                    break;                
                  case "ice_delivered":
                    if ( (num_of_people <= 0) && (no_people_shown=="no") ) {
                      alert(message_no_people);
                      no_people_shown = "yes";
                    } else {
                      int_service_sub_total = int_service_sub_total + ( parseFloat(obj.value) * ( Math.ceil(num_of_people/100) ) );
                    } //end if            
                    break;                
                  case "bar_condoments":
                    if ( (num_of_people <= 0) && (no_people_shown=="no") ) {
                      alert(message_no_people);
                      no_people_shown = "yes";
                    } else {
                      int_service_sub_total = int_service_sub_total + ( parseFloat(obj.value) * ( Math.ceil(num_of_people/100) ) );
                    } //end if            
                    break;                
                }// end switch

              } else if ( obj.name == 'breakfast_addons' ) {
                document.getElementById(obj.name+'_'+category_index).className = "do_print_item";            
                print_switch++;
                if ( (num_of_people <= 0) && (no_people_shown=="no") ) {
                  alert(message_no_people);
                  no_people_shown = "yes";
                } else {
                  int_product_sub_total = int_product_sub_total + ( num_of_people * obj.value );
                } //end if            

              } else if ( obj.name == 'upgrade' ) {
                // THE UPGRADE CODE IS ABOVE IN RADIO BUTTON BUFFET CODE
              }// end if
            } else { //alert('starting else ' + obj.name+'_'+category_index);
                if ( document.getElementById(obj.name+'_'+category_index) ) {
                  if ( (obj.id) && (obj.name != 'great_endings') && (obj.name != 'additional') && (obj.id != 'chocolate_fountain') && (obj.id != 'coffee_and_desert') ) { //alert('checkbox id = ' + obj.id + ' NOT going to be set due to id');
                    // UNLESS THIS IS AN ADDITIONAL ITME, OR THE GREAT ENDINGS CHECK BOX, DO NOTHING OR THE BUFFET RADIO BUTTON AREA WILL BE NOT PRINTED
                  } else {
                    //alert('checkbox name = ' + obj.name + ' set ot do NOT print');
                    document.getElementById(obj.name+'_'+category_index).className = "do_not_print_item";
                  }// end if
                } else {
                  alert('FAILED - This ID does not exist - ' + obj.name+'_'+category_index);
                }// end if
                
            }// end if
            break;
          case "text":
            if ( obj.name == 'hot_items' ) {
              if ( (1 * obj.value) > 0 ) {
                document.getElementById(obj.name+'_'+category_index).className = "do_print_item";
                item_value = document.forms[0][i-1].value; // GET THE VALUE OF THE HIDDEN ELEMENT THAT IS BEFORE THIS ONE
                int_product_sub_total = int_product_sub_total + ( item_value * obj.value );
                print_switch++;
              } else {
                if ( document.getElementById(obj.name+'_'+category_index) ) {
                  //alert('GOOD - This ID is good - ' + obj.name+'_'+category_index);
                  document.getElementById(obj.name+'_'+category_index).className = "do_not_print_item";            
                } else {
                  alert('FAILED - This ID does not exist - ' + obj.name+'_'+category_index);
                }// end if
              }// end if
            } else if ( obj.name == 'finger_foods' ) {
              if ( (1 * obj.value) > 0 ) {
                //alert('show item # ' + category_index);
                document.getElementById(obj.name+'_'+category_index).className = "do_print_item";            
                item_value = document.forms[0][i-1].value; // GET THE VALUE OF THE HIDDEN ELEMENT THAT IS BEFORE THIS ONE
                int_product_sub_total = int_product_sub_total + ( item_value * obj.value );
                print_switch++;
              } else {
                if ( document.getElementById(obj.name+'_'+category_index) ) {
                  //alert('GOOD - This ID is good - ' + obj.name+'_'+category_index);
                  document.getElementById(obj.name+'_'+category_index).className = "do_not_print_item";            
                } else {
                  alert('FAILED - This ID does not exist - ' + obj.name+'_'+category_index);
                }// end if
              }// end if
            } else if ( obj.name == 'great_endings' ) {
              if ( (1 * obj.value) > 0 ) {
                //alert('show item # ' + category_index);
                document.getElementById(obj.name+'_'+category_index).className = "do_print_item";            
                item_value = document.forms[0][i-1].value; // GET THE VALUE OF THE HIDDEN ELEMENT THAT IS BEFORE THIS ONE
                int_product_sub_total = int_product_sub_total + ( item_value * obj.value );
                print_switch++;
              } else {
                if ( document.getElementById(obj.name+'_'+category_index) ) {
                  //alert('GOOD - This ID is good - ' + obj.name+'_'+category_index);
                  document.getElementById(obj.name+'_'+category_index).className = "do_not_print_item";            
                } else {
                  alert('FAILED - This ID does not exist - ' + obj.name+'_'+category_index);
                }// end if
              }// end if
            } else if ( obj.name == 'additional' ) { //IF YOU USE THIS FOR SOMETHING BESIDES BARTENDING HOURS YOU MUST TWEAK TO REMOVE ADDITIONAL HOURS CALC
              //alert('here: ' + obj.name + ' ' + category_index) ;
              if(obj.id == "small_party_fee") {
                if ( (num_of_people > 0 ) && (num_of_people <= 50) ) {
                  //alert('small party fee');
                  int_fee_1 = "100.00";
	                document.getElementById(obj.name+'_'+category_index).className = "do_print_item";
                  document.getElementById(obj.id).value = int_fee_1;
	                int_service_sub_total = int_service_sub_total + parseFloat(int_fee_1);
	                print_switch++;
                } else {
                  document.getElementById(obj.id).value = "0.00";
	                if ( document.getElementById(obj.name+'_'+category_index) ) {
	                  //alert('GOOD - This ID is good - ' + obj.name+'_'+category_index);
	                  document.getElementById(obj.name+'_'+category_index).className = "do_not_print_item";
	                } else {
	                  alert('FAILED - This ID does not exist - ' + obj.name+'_'+category_index);
	                }// end if
                }//end if
              } else {
	              if ( (1 * obj.value) > 0 ) {
	                //alert('filled');
	                document.getElementById(obj.name+'_'+category_index).className = "do_print_item";
	                item_price = document.forms[0][i-1].value; // GET THE VALUE OF THE HIDDEN ELEMENT THAT IS BEFORE THIS ONE
	                addtl_value = parseFloat(document.forms[0][i+1].value); // GET THE VALUE OF THE HIDDEN ELEMENT THAT IS AFTER THIS ONE (additional bartending)
	                int_service_sub_total = int_service_sub_total + ( item_price * (parseFloat(obj.value) + parseFloat(addtl_value)) );
	                print_switch++;
	              } else {
	                //alert('empty');
	                if ( document.getElementById(obj.name+'_'+category_index) ) {
	                  //alert('GOOD - This ID is good - ' + obj.name+'_'+category_index);
	                  document.getElementById(obj.name+'_'+category_index).className = "do_not_print_item";
	                } else {
	                  alert('FAILED - This ID does not exist - ' + obj.name+'_'+category_index);
	                }// end if
	              }// end if
              }// end if
            }// end if
            break;
        }// end switch;
    }// next

    int_sales_tax   = ( int_product_sub_total * int_sales_tax_rate );    // only charge sales tax on the product total not the service total
    int_sub_total   = ( int_product_sub_total + int_service_sub_total );
    int_grand_total = ( int_sales_tax + int_product_sub_total + int_service_sub_total );
    document.forms[0].Sub_Total.value   = format_curr(int_sub_total);
    document.forms[0].Sales_Tax.value   = format_curr(int_sales_tax);
    document.forms[0].Grand_Total.value = format_curr(int_grand_total);
  }// end function

  //=================================================================================================
  function only_numeric(string) {
    string = string.replace(/[^0-9.-]/g, ''); // strip non-digit chars
    string = parseFloat(string);
    if (isNaN(string)) string = 0;
    return string;
  }// end function

  //=================================================================================================
  function format_as_money(obj) {
    obj.value = format_curr(only_numeric(obj.value));  
  }// end function

  //=================================================================================================
  function format_curr(num) { // TAKE A STRING, STRIP TO ONLY NUMBERS, THEN FORMAT WITH "$" "," AND ".00"
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num)) num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).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));
    }// next
    return (((sign)?'':'-') + '$' + num + '.' + cents);
  }// end function

  //=================================================================================================
  function NumericCheck(val) { // ONKEYUP - MAKE SURE THE TYPED KEY IS ONLY A NUMBER. IF NOT, REMOVE IT.
    var strPass = val.value;
    var strLength = strPass.length;
    var lchar = val.value.charAt((strLength) - 1);
    var cCode = lchar.charCodeAt(0); // calculate the ASCII code of the given character
  
    // Check if the keyed in character is a number do you want alphabetic UPPERCASE only ?  or lower case only just check their respective  codes and replace the 48 and 57
    if (cCode < 48 || cCode > 57 ) {
      var myNumber = val.value.substring(0, (strLength) - 1);
      val.value = myNumber;
    }// end if
    return false;
  }// end function

  //=================================================================================================
  function ClearContents(field) {
    //alert(field.value);
    if (field.name != "Number_of_People") {
      field.value = "";
      calculate();
    }// end if
  }// End Function;

  //=================================================================================================
  function show_or_hide(expandID) {
    var new_HTML;
    if (document.getElementById('expand_' + expandID).className == "expand_show") {
      document.getElementById('expand_' + expandID).className = "expand_hide";
      new_HTML = document.getElementById('clasp_' + expandID).innerHTML.replace('- Hide Details', '+ Show Details');
      document.getElementById('clasp_' + expandID).innerHTML = new_HTML;
    } else {
      document.getElementById('expand_' + expandID).className = "expand_show";        
      new_HTML = document.getElementById('clasp_' + expandID).innerHTML.replace('+ Show Details', '- Hide Details');
      document.getElementById('clasp_' + expandID).innerHTML = new_HTML;
    }// end if
  }// end function
  //=================================================================================================
  //=================================================================================================

  function printer_friendly() {
    if (document.forms[0].Grand_Total.value == '$0.00') {
      alert('Your total is $0.00 \n\n Please finish selecting your items.');
      return false;
    }// end if
    for(i=0; i < document.forms[0].length; i++) {  // YOU MUST LOOP TROUGH ALL THE FORM FIELDS AND REGISTER THE FORM FIELD CHANGES IN THE DOM - OTHERWISE FIREFOX WILL NOT SEE ANY USER'S INPUT
      obj = document.forms[0][i]; //alert('name = ' + obj.name + '\n\n type = ' + obj.type + '\n\n value = ' + obj.value);
      switch(obj.type) {
        case "text":
        case "textarea":
          obj.setAttribute('value', obj.value);
          break;
        case "checkbox":
          if ( obj.checked ) {
            obj.setAttribute('checked', "true");
          }// end if
          break;
        case "radio":
          if ( obj.checked ) {
            obj.checked = true;
            obj.setAttribute('checked', 'true');
          }// end if
          break;
        default:
          //alert(obj.type);
          break;
      }// end switch
    }// next

    var settings = 'width=640,height='+(screen.height-200)+',top=75,left='+((screen.width/2)-(640/2))+',scrollbars=yes,location=no,directories=no,status=no,menubar=yes,toolbar=no,resizable=yes';

    var page_start = "<html>\n" +
                     "  <head>\n" +
                     "    <title>Aunt Catfish's on the River</title>\n" +
                     "    <link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"images/styles_catering.css\">\n" +
                     "    <link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"images/styles_printer_friendly.css\">\n" +
                     "  </head>\n" +
                     "<body onload='" +
                     "javascript:\n  for(i=0; i < document.forms[0].length; i++) { \n " +
                     "   obj = document.forms[0][i]; \n" +
                     "      switch(obj.type) { \n" +
                     "        case \"text\": \n" +
                     "        case \"textarea\": \n" +
                     "          obj.readOnly = true; \n" +
                     "          break; \n" +
                     "        case \"checkbox\": \n" +
                     "        case \"radio\": \n" +
                     "          obj.disabled = true; \n" +
                     "          //obj.attributes[\"onFocus\"].value = \"this.blur\" \n" +
                     "          //obj.setAttribute(\"onFocus\", this.blur()); \n" +
                     "          break; \n" +
                     "        default: \n" +
                     "          break; \n" +
                     "      } \n" +
                     " }' \n" +
                     " onkeydown=\"return false;\">\n<div id=\"page\">\n";

    var win=window.open('','',settings);
    win.document.open("text/html","replace");
    win.document.write(page_start);
    //win.document.write(document.body.innerHTML);
    win.document.write(document.getElementById('page').innerHTML);
    win.document.write("\n</div>\n</body>\n</html>");
    win.document.close();
  }// end function

  //=================================================================================================
