/*
function menuOpen(menuID, menuName) {
  document.getElementById('menu' + menuID).style.display = "block";
  document.getElementById('clasp' + menuID).innerHTML="<a href=\"javascript:menuClose('" + menuID + "', '"+ menuName +"');\"><h2>" + menuName + "</h2></a>";
}
function menuClose(menuID, menuName) {
document.getElementById('menu' + menuID).style.display = "none";
document.getElementById('clasp' + menuID).innerHTML="<a href=\"javascript:menuOpen('" + menuID + "','"+ menuName +"');\"><h2>" + menuName + "</h2></a>";
}

function menuToggle(menuID){
  var theMenuBlock = document.getElementById(menuID).style.display;
  if (theMenuBlock == 'block') {
    theMenuBlock = "none";
  } else {
    theMenuBlock = "block";
  }
}
*/


function toggleMenu(elm) {
  elm.parentNode.className = (elm.parentNode.className == 'show-sub') ? 'hide-sub' : 'show-sub';
  return false;
}

function toggleSubMenu(elm) {
  elm.parentNode.className = (elm.parentNode.className == 'show-item') ? 'hide-item' : 'show-item';
  return false;
}

function updateMenuSelection(fieldCount) {
  var totalAmount = 0;
  var tempName = "";
  menuString = '<h2>Pre Order</h2>';
  var menuSectionStarters = "";
  var menuSectionMains = "";
  var menuSectionWines = "";
  var menuSectionDeserts = "";
  var emailString = "";
  var emailSectionStarters ="";
  var emailSectionMains = "";
  var emailSectionDeserts = "";
  var emailSectionWines = "";
  var tempStr = "";
  var tempCutStr = "";
  var tempQty = 0;
  var tempPrice = 0;
  var classificationStr;
  var cr = "\r\n";
  
  fieldCount ++;
  
  for (var i = 0; i < fieldCount; i ++){
    tempName = "qty_" + i;
    tempQty = parseInt(document.getElementById(tempName).value);
    if (tempQty > 0){
      tempName  = "item_cost" + i;
      tempPrice = parseFloat((tempQty * parseFloat(document.getElementById(tempName).value)).toFixed(2));
      totalAmount += tempPrice;
 
      tempName = "item_title" + i;
      tempStr = document.getElementById(tempName).value;
      if (tempStr.length > 11){
        tempCutStr = tempStr.substring(0,11) + "...";
      } else {
        tempCutStr = tempStr;
      }
      
      
      
      tempName = "item_classification" + i;
      classificationStr = document.getElementById(tempName).value;
      switch(classificationStr)
      {
        case "Starter":
          menuSectionStarters += '<dl><dt class="menu-item">' + tempCutStr + '</dt><dd class="menu-quantity">x' + tempQty + '</dd><dd class="menu-price">$' + tempPrice.toFixed(2) + '</dd></dl>';
          emailSectionStarters += tempStr + ' x' + tempQty + ' $' + tempPrice.toFixed(2) + cr;
          break;
        case "Main":
          menuSectionMains += '<dl><dt class="menu-item">' + tempCutStr + '</dt><dd class="menu-quantity">x' + tempQty + '</dd><dd class="menu-price">$' + tempPrice.toFixed(2) + '</dd></dl>';
          emailSectionMains += tempStr + ' x' + tempQty + ' $' + tempPrice.toFixed(2) + cr;
          break;
 
        case "Desert":
          menuSectionDeserts += '<dl><dt class="menu-item">' + tempCutStr + '</dt><dd class="menu-quantity">x' + tempQty + '</dd><dd class="menu-price">$' + tempPrice.toFixed(2) + '</dd></dl>';
          emailSectionDeserts += tempStr + ' x' + tempQty + ' $' + tempPrice.toFixed(2) + cr;
          break;       
              
      }

    }
  }
  
  totalAmount = totalAmount.toFixed(2);
  
  menuSectionMains += menuSectionDeserts;
  
  if (menuSectionStarters == ''){
    menuSectionStarters = '<dl><dt class="menu-item">None Selected</dt></dl>';
  }
  
    if (menuSectionMains == ''){
    menuSectionMains = '<dl><dt class="menu-item">None Selected</dt></dl>';
  }
  
 //   if (menuSectionWines == ''){
 //   menuSectionWines = '<dl><dt class="menu-item">None Selected</dt></dl>';
 // }
  
  emailString = 'Starters:' + cr + emailSectionStarters + cr + cr + 'Mains:' + cr + emailSectionMains + emailSectionDeserts + cr;
  document.getElementById('emailOrder').value = emailString;
  
  menuString += '<div class="menu-type"><h3>Starters</h3>' + menuSectionStarters + '</div><div class="menu-type"><h3>Mains</h3>' + menuSectionMains + '</div><div class="menu-total"><dl><dt class="menu-item">Total</dt><dd class="menu-price">$' + totalAmount + '</dd></dl></div>' ;
  document.getElementById('preorderRightBar').innerHTML=menuString;
}