//<%-- ---------------------------------------------------------- --%>
//<%-- JavaScript to handle the tabbed sections,                  --%>
//<%--               popping out a new window for the large view  --%>
//<%--               and for handling the submit checks.          --%>
//<%-- ---------------------------------------------------------  --%>

var openedTab = null;
function swapTabs( tabId){
     if (openedTab)
          openedTab.style.display='none';
     openedTab = document.getElementById( tabId );
     openedTab.style.display = 'block';
}

var newwindow = '';
function popUpNewWindow(url)
{
  if (!newwindow.closed && newwindow.location)
  {
    newwindow.location.href = url;
  }
  else
  {
    newwindow=window.open(url,'name','height=400,width=400');
    if (!newwindow.opener) newwindow.opener = self;
  }
  if (window.focus) {newwindow.focus();}
}

function isNum(numericString) {
  var str = numericString;
  var digit = '';
  for (var index = 0; index < str.length; index++) {
    digit = str.substring(index, index + 1)
    if (digit < "0" || "9" < digit)
      return false;
  }
  return true;
}

var busy = false;
function Handle_Submit(form)
{
  if (!busy)
  {
    busy = true;
    var badNum=false;
    var hasQuantity="0";
    for (var i = 0; i < form.numProd.value; i++) {
      var quantity = 'quantity_' + (i + 1);
      var catentry = 'catEntryId_' + (i + 1);
      if (form[quantity].value != "")
        hasQuantity = "1";
      else
      {
        form[catentry].name = "";
        form[catentry].value = "";
      }
      if (isNum(form[quantity].value) == false)
        badNum = true;
    }

    if (badNum)
    {
      alert('<fmt:message key="MWV_VALID_QUANTITY_REQUIRED" bundle="${storeText}" />');
      busy = false;
      return false;
    }
    else
    if (hasQuantity != "1")
    {
      alert("Please enter a quantity.");
      busy = false;
      return false;
    }
    else
    {
      form.URL.value='OrderCalculate?updatePrices=1&calculationUsageId=-1&URL=OrderItemDisplay&orderId=&quantity*=';
      form.submit();
      return true;
    }
  }
}
