
// --- Menu Control Program ---

// --- Programming and Code Copyright Notice:
// Developed by LCC Enterprises, 2009
// Contains original JavaScript programming code
// ©2009 by LCC Enterprises.   All rights reserved.
// ---
// This installation under license for use by Tiki Terrace d/b/a Chicago Luaus

// --- Description:
// Processes all events and processing for the Menu pages.
// This program dynamically builds the content of the menu web pages
// from the menu database


// -------------------------------------------------------------------------
// --- Dependencies:

// This program requires that the following program files be loaded after loading this program file
//     > menudescriptionfile.js
//           Which contains the following functions called from this program"
//                          getMenuSizes
//                          initMenuDatabase


// -------------------------------------------------------------------------
// Prerequisite Initialization Calls
// -------------------------------------------------------------------------


// -------------------------------------------------------------------------
// Define global variables:

  // Valid menu names are depicted below:

  var MenuLast_starters = 0;
  var MenuLast_maincourses = 0;
  var MenuLast_sidedishes = 0;
  var MenuLast_dessertspecial = 0;
  var MenuLast_decorrental = 0;

  var MenuFilename_starters = new Array();
  var MenuTitletxt_starters = new Array();
  var MenuDescript_starters = new Array();

  var MenuFilename_maincourses = new Array();
  var MenuTitletxt_maincourses = new Array();
  var MenuDescript_maincourses = new Array();

  var MenuFilename_sidedishes = new Array();
  var MenuTitletxt_sidedishes = new Array();
  var MenuDescript_sidedishes = new Array();

  var MenuFilename_dessertspecial = new Array();
  var MenuTitletxt_dessertspecial = new Array();
  var MenuDescript_dessertspecial = new Array();

  var MenuFilename_decorrental = new Array();
  var MenuTitletxt_decorrental = new Array();
  var MenuDescript_decorrental = new Array();


// -------------------------------------------------------------------------
// FUNCTION DECLARATIONS - 
// For subroutine functions called only from this script
// -------------------------------------------------------------------------

// -------------------------------------------------------------------------
// Test if an integer is even - Return true if even, false if odd
// -------------------------------------------------------------------------
  function mathEven(integer) {
    var numEven = false;
    if (Math.ceil((integer)/2) == Math.floor((integer)/2)) {
      numEven = true;
    }
    return numEven;
  }

// -------------------------------------------------------------------------
// Initialize the Menu Database System
// -------------------------------------------------------------------------
  function initMenuSystem() {
      getMenuSizes ();
      initMenuDatabase ();
  }

// -------------------------------------------------------------------------
// FUNCTION DECLARATIONS - 
// For functions called directly from web page
// -------------------------------------------------------------------------


// -------------------------------------------------------------------------
// Menu Web Page Content Builder
// -------------------------------------------------------------------------
  function BuildMenu(MenuName) {

    var fileName = null;
    var entryTitle = null;
    var entryDescription = null;
    var lastEntryNum = 0;

    // determine last entry number for menu being processed
    lastEntryNum = eval("MenuLast_"+MenuName);

    // Create the menu entries on the web page as table rows

    for (entryIndex = 0; entryIndex <= lastEntryNum; entryIndex++) {

      document.writeln ("<table class=\"menudetailentriestable\" cellspacing=\"0\"><tr>\n");  // Write the beginning of table and row tag

      // Build the cell in the row
      // 1) Construct the entry filename, title, description. and style classes
      fileName = eval("MenuFilename_"+MenuName+"["+entryIndex+"]")+".jpg";
      entryTitle = eval("MenuTitletxt_"+MenuName+"["+entryIndex+"]");
      entryDescription = eval("MenuDescript_"+MenuName+"["+entryIndex+"]");
      // 2) Determine Right or Left Image position depending on whether entry is even or odd and construct appropriate line
      if (mathEven(entryIndex)) {
        documentLine = "<td class=\"menudetailentrycelltextleft\"><span class=\"menuentrytitle\">"+entryTitle+"</span>"+entryDescription+"</td><td class=\"menudetailentrycellimageright\"><img class=\"menuentryimage\" title=\""+entryTitle+"\" src=\""+fileName+"\"></td>\n";
      }
      else {
        documentLine = "<td class=\"menudetailentrycellimageleft\"><img class=\"menuentryimage\" title=\""+entryTitle+"\" src=\""+fileName+"\"></td><td class=\"menudetailentrycelltextright\"><span class=\"menuentrytitle\">"+entryTitle+"</span>"+entryDescription+"</td>\n";
      }
      // 3) Now write the line
      document.writeln (documentLine);

      document.writeln ("</tr></table>");  // Write the end of row and table tag

    }

  }


// -------------------------------------------------------------------------
// BEGIN: Main Line Processing - Runs as soon as the script file has been read
// -------------------------------------------------------------------------

      initMenuSystem();

// -------------------------------------------------------------------------
// END: Main Line Processing
// -------------------------------------------------------------------------





