function addRowToTable()
{
  var orders = document.getElementById("NumberOfOrders").value;
  orders = orders -1;
  for (i = 1; i <= +orders; i++) {

  var tbl = document.getElementById('order');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  
  // Name cell
  var cellLeft = row.insertCell(0);
  var el = document.createElement('input');
  el.name = 'name_' + iteration;
  el.size = 20;

  cellLeft.appendChild(el);
  
  // Chili cell
  var cellChili = row.insertCell(1);  
  cellChili.setAttribute('align', 'center');
  var el = document.createElement('input');
  el.setAttribute('type', 'checkbox');
  el.name = 'Chili_' + iteration;
  el.value = 'x';
  
  cellChili.appendChild(el);  
  
  // Broccoli cell
  var cellBroccoli = row.insertCell(2);
  cellBroccoli.setAttribute('align', 'center');
  var el = document.createElement('input');
  el.setAttribute('type', 'checkbox');
  el.name = 'Broccoli_' + iteration;
  el.value = 'x';
  
  cellBroccoli.appendChild(el);
  
  // Cheese cell
  var cellCheese = row.insertCell(3);
  cellCheese.setAttribute('align', 'center');
  var el = document.createElement('input');
  el.setAttribute('type', 'checkbox');
  el.name = 'Cheese_' + iteration;
  el.value = 'x';
  
  cellCheese.appendChild(el);
  
  // Bacon cell
  var cellBacon = row.insertCell(4);
  cellBacon.setAttribute('align', 'center');
  var el = document.createElement('input');
  el.setAttribute('type', 'checkbox');
  el.name = 'Bacon_' + iteration;
  el.value = 'x';
  
  cellBacon.appendChild(el);
  
  // salsa cell
  var cellSalsa = row.insertCell(5);
  cellSalsa.setAttribute('align', 'center');
  var el = document.createElement('input');
  el.setAttribute('type', 'checkbox');
  el.name = 'salsa_' + iteration;
  el.value = 'x';
  
  cellSalsa.appendChild(el);
  
  // Sour Cream cell
  var cellSourCream = row.insertCell(6);
  cellSourCream.setAttribute('align', 'center');
  var el = document.createElement('input');
  el.setAttribute('type', 'checkbox');
  el.name = 'SourCream_' + iteration;
  el.value = 'x';
  
  cellSourCream.appendChild(el);
  
  // butter cell
  var cellButter = row.insertCell(7);
  cellButter.setAttribute('align', 'center');
  var el = document.createElement('input');
  el.setAttribute('type', 'checkbox');
  el.name = 'butter_' + iteration;
  el.value = 'x';
  
  cellButter.appendChild(el);
  
  //Soda Cell
  var cellSoda = row.insertCell(8);
  var el = document.createElement('select');
  el.name = 'Soda_' +iteration;
  el.options[0] = new Option('None', '5');
  el.options[1] = new Option('Coke', '2');
  el.options[2] = new Option('Diet Coke', '1');
  el.options[3] = new Option('Mello Yello', '3');
  el.options[4] = new Option('Sprite', '4');
  
  cellSoda.appendChild(el);
  
  
    document.TakeOut.OrderCount.value = iteration;
    }
}

function keyPressTest(e, obj)
{
  var validateChkb = document.getElementById('chkValidateOnKeyPress');
  if (validateChkb.checked) {
    var displayObj = document.getElementById('spanOutput');
    var key;
    if(window.event) {
      key = window.event.keyCode; 
    }
    else if(e.which) {
      key = e.which;
    }
    var objId;
    if (obj != null) {
      objId = obj.id;
    } else {
      objId = this.id;
    }
    displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key);
  }
}
function removeRowFromTable()
{
  var tbl = document.getElementById('order');
  var lastRow = tbl.rows.length;
  var orderCount = 1;
  
  for (i = 1; i <= +lastRow; i++) {
  	var lastRow2 = tbl.rows.length;
  	if (lastRow2 > 2) tbl.deleteRow(lastRow2 - 1);
  }
  document.TakeOut.OrderCount.value = orderCount;
}
function openInNewWindow(frm)
{
  // open a blank window
  var aWindow = window.open('', 'TableAddRowNewWindow',
   'scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400');
   
  // set the target to the blank window
  frm.target = 'TableAddRowNewWindow';
  
  // submit
  frm.submit();
}
function validateRow(frm)
{
  var chkb = document.getElementById('chkValidate');
  if (chkb.checked) {
    var tbl = document.getElementById('tblSample');
    var lastRow = tbl.rows.length - 1;
    var i;
    for (i=1; i<=lastRow; i++) {
      var aRow = document.getElementById('txtRow' + i);
      if (aRow.value.length <= 0) {
        alert('Row ' + i + ' is empty');
        return;
      }
    }
  }
  openInNewWindow(frm);
}