  var marketingPrefixRE = /[a-zA-Z]{3}\-/;
  var productNumberRE = /[a-zA-Z]{0,1}\d+\-?\d+[a-zA-Z]{0,}/;

  var spaceRE = /\s/;
  var domain = document.domain;  
  domain = domain.toLowerCase();
  
  function qo()
  {  
    if (doQO())
    {
      document.qo.submit();

      var domain = document.domain;  
      domain = domain.toLowerCase();
    }
  }

  function doQO()
  {    
    var flag = 0;
    document.qo.item.value = "";
    for (var i = 1; i <= document.tp.line_number.value; i++)
    {
      var name = 'document.tp.item_' + i + '.value';
      var item = "";
      item = eval(name).replace(/\s/,"");
      item = item.toUpperCase();
      if (item.length > 0)
      {
        flag++;
        if (flag == 1)
          document.qo.item.value = item;
        else
          document.qo.item.value = document.qo.item.value + "/" + item;
      }
    }
    if (flag == 0)
    {
      if (domain.indexOf("chproductos") != -1)
        alert("Entre por favor su Artículo #.");        
      else
        alert("Please enter your Item #.   ");
      return false;
    }
    document.qo.line_number.value = document.tp.line_number.value;
    document.qo.template.value = "quickorder2";
    document.qo.tran_id.value = "81";
    return true;
  }

  function lg()
  {  
    if (submitlg())
      document.lg.submit();
  }

  function os()
  {
    // Get the order and cust numbers from the form
    var order_no = document.order_search.order_no.value;
    var cust_no = document.order_search.cust_no.value;
    
    var errorDiv = document.getElementById('order_search_error');
    errorDiv.innerHTML = '';
    var errorMsg = '';
    var isError = false;
    if (order_no == '')
    {
      errorMsg = 'Order # must be entered.';
      isError = true;
    }
    if (cust_no == '')
    {
      errorMsg = 'Account # must be entered.';
      isError = true;
    }
      
    // Get the cust number from the document
    var cust_no_ori = document.search.cust_no.value;
    var userId = document.order_search.user_id.value;
    var shipId = document.order_search.ship_no.value;
    
    if (cust_no != cust_no_ori)
    {
      userId = "";
      shipId = "-1";
    }
    // PFI has different processing
    var tranId = 53;
    if (domain.indexOf("productsforindustry") != -1)
    {
      tranId = 48;
    }
    if (isError)
    {
      if (errorMsg != '')
      {
        errorDiv.innerHTML = errorMsg;
        window.scroll(0,0);
      }
      return false;
    }
    else
    {
    // Redirect to the search 
// TODO: change back to https when put into production
    location.href = "https://" + document.domain + "/ecommerce/eComm?template=order&cust_no="+cust_no+
//    location.href = "http://" + document.domain + "/ecommerce/eComm?template=order&cust_no="+cust_no+
        "&user_id="+userId+"&ship_no="+shipId+"&tran_id="+tranId+"&order_no="+order_no+"&msg_id=os";
    }
  }

  function submitlg()
  {
    if (document.lg.button_name.value == "enter")
    {
      if (document.lg.user_id.value.length < 6)
      {
        if (domain.indexOf("chproductos") != -1)
          alert("Favor de poner un nombre de usuario de más de 6 caracteres.")  
        else
          alert("Please use a user id at least 6 characters long");
        return false;
      }
      if (document.lg.pwd.value.length < 6)
      {
        if (domain.indexOf("chproductos") != -1)
          alert("Favor de poner una contraseña de más de 6 caracteres.")  
        else
          alert("Please use a password at least 6 characters long");
        return false;
      }
      document.lg.tran_id.value = "10";
      document.lg.template.value='product_group';
      document.lg.action = "https://" + document.domain + "/ecommerce/eComm";
      //document.lg.action = "http://" + document.domain + "/ecommerce/eComm";
      return true;
    }
    else 
      return false;
  }

  function doQuickOrder1()
  {
    var flag = 0;
    document.quick_order1.item.value = "";
    for (var i = 1; i <= document.temp.line_number.value; i++)
    {
      var name = 'document.temp.item_' + i + '.value';
      var item = eval(name);
      item = item.toUpperCase();
      item = item.split('-').join("");

      if (item.length != 0)
      {
        flag++;
        if (flag == 1)
          document.quick_order1.item.value = item;
        else
          document.quick_order1.item.value = document.quick_order1.item.value + "/" + item;
      }
    }
    if (flag == 0)
    {
      if (domain.indexOf("chproductos") != -1)
        alert("Entre por favor su Artículo #.");        
      else
        alert("Please enter your Item #.   ");
      return false;
    }
    document.quick_order1.line_number.value = document.temp.line_number.value;
    document.quick_order1.template.value = "quickorder2";
    document.quick_order1.tran_id.value = "81";
    return true;
  }

  function doQuickOrder2()
  {
    if (document.quick_order2.msg_id.value == "Back_to_Step_1") 
    {
      document.quick_order2.method = "GET";
      document.quick_order2.template.value = "quickorder1";
      document.quick_order2.tran_id.value = "";
      return true;
    }

    var stock_no_all = "";
    var unit_price_all = "";
    var ord_qty_all = "";
    var prod_name_all = "";

    for(var nRow = 1; nRow <= document.temp.item_counter.value; nRow++)
    {
      var name = 'document.temp.ord_qty_' + nRow + '.value';
      var ord_qty = eval(name);
       name = 'document.temp.stock_no_' + nRow + '.value';
      var stock_no = eval(name);
       name = 'document.temp.select_' + nRow + '.value';
      var select = eval(name);

      var idx = 0;
      if (select == "T")  //  there is a specification list
      {
        name = 'document.temp.stock_no_' + nRow + '.selectedIndex';
        idx = eval(name);
      }
       name = 'document.temp.prod_name_' + nRow + '_' + idx + '.value';
      var prod_name = eval(name);
       name = 'document.temp.unit_price3_' + nRow + '_' + idx + '.value';
      var unit_price3 = eval(name);
       name = 'document.temp.unit_price4_' + nRow + '_' + idx + '.value';
      var unit_price4 = eval(name);
       name = 'document.temp.unit_price5_' + nRow + '_' + idx + '.value';
      var unit_price5 = eval(name);
       name = 'document.temp.unit_price6_' + nRow + '_' + idx + '.value';
      var unit_price6 = eval(name);
       name = 'document.temp.unit_qty3_' + nRow + '_' + idx + '.value';
      var unit_qty3 = eval(name);
       name = 'document.temp.unit_qty4_' + nRow + '_' + idx + '.value';
      var unit_qty4 = eval(name);
       name = 'document.temp.unit_qty5_' + nRow + '_' + idx + '.value';
      var unit_qty5 = eval(name);
       name = 'document.temp.unit_qty6_' + nRow + '_' + idx + '.value';
      var unit_qty6 = eval(name);

      if (isNaN(ord_qty))
      {
        if (domain.indexOf("chproductos") != -1)
          alert("La cantidad inválida de la orden para el artículo " + stock_no + " \nVerifíquelo por favor y entre un número válido");            
        else
          alert("Invalid order quantity for item " + stock_no + " \nPlease check it and enter a valid number");
        return false;        
      }
      else if (ord_qty < 1 && document.quick_order2.template.value != "reorder2")      
      {
        if (domain.indexOf("chproductos") != -1)
          alert("Ordene la cantidad para el artículo " + stock_no + " deben ser más que 0.");
        else
          alert("Order quantity for item " + stock_no + " must be greater than 0.");
        return false;
      }
      else if (ord_qty%unit_qty3 != 0 || (ord_qty/unit_qty3 < 1 && document.quick_order2.template.value != "reorder2"))
      {
        var phoneNo = "1-800-558-9966";

        if (domain.indexOf("chproductos") != -1)  
          phoneNo = "001-877-448-0703";          
        else if (domain.indexOf("productsforindustry") != -1)
          phoneNo = "1-800-548-4430";
        else if (domain.indexOf("p4i") != -1)
          phoneNo = "";

        if (domain.indexOf("p4i") != -1)
          alert("The item " + stock_no + " is sold in quantities of " + unit_qty3 + 
            " only. Please order in multiples of " + unit_qty3 + ".")
        else if (domain.indexOf("chproductos") != -1)
          alert("El artículo " + stock_no + " son vendidos en cantidades de " + unit_qty3 + 
            " sólo. Ordene por favor en múltiplos de " + unit_qty3 + 
            ".\nPara la ayuda adicional, por favor nos llama en "+ phoneNo +" alcanzar a un representante de servicio de atención al cliente.")
        else
          alert("The item " + stock_no + " is sold in quantities of " + unit_qty3 + 
            " only. Please order in multiples of " + unit_qty3 + 
            ".\nFor further assistance, please call us at "+ phoneNo +" to reach a customer service representative.")
        return false;
      }

      if (ord_qty >= new Number(unit_qty6) && (unit_price6 > 0))
      {
        unit_price3 = unit_price6;
      }
      else if (ord_qty >= new Number(unit_qty5) && (unit_price5 > 0))
      {
        unit_price3 = unit_price5;
      }
      else if (ord_qty >= new Number(unit_qty4) && (unit_price4 > 0))
      {
        unit_price3 = unit_price4;
      }

      if (stock_no.length == 5 && domain.indexOf("chproductos") != -1)
        stock_no = stock_no + "00";

      if (document.quick_order2.template.value != "reorder2")
      {
        if(nRow == 1)
        {
          stock_no_all = stock_no;
          unit_price_all = unit_price3;
          ord_qty_all = ord_qty;
          prod_name_all = prod_name;
        }
        else
        {
          stock_no_all = stock_no_all+"/"+stock_no;
          unit_price_all = unit_price_all+"/"+unit_price3;
          ord_qty_all = ord_qty_all+"/"+ord_qty;
          prod_name_all = prod_name_all+"/"+prod_name;
        }
      }
      else
      {
        if (ord_qty >= 1)
        {
          if (stock_no_all == "")
          {
            stock_no_all = stock_no;
            unit_price_all = unit_price3;
            ord_qty_all = ord_qty;
            prod_name_all = prod_name;        
          }
          else
          {
            stock_no_all = stock_no_all+"/"+stock_no;
            unit_price_all = unit_price_all+"/"+unit_price3;
            ord_qty_all = ord_qty_all+"/"+ord_qty;
            prod_name_all = prod_name_all+"/"+prod_name;        
          }
        }
      }
    }

    document.quick_order2.stock_no_all.value = stock_no_all;
    document.quick_order2.unit_price_all.value = unit_price_all;
    document.quick_order2.ord_qty_all.value = ord_qty_all;
    document.quick_order2.prod_name_all.value = prod_name_all;

    if (document.quick_order2.stock_no_all.value == "")
    {
      if (domain.indexOf("chproductos") != -1)
        alert("Ordene la cantidad para el artículo " + stock_no + " deben ser más que 0.");      
      else
        alert("At least one quantity must be greater than 0.");
      return false;    
    }
    document.quick_order2.template.value = "ship_to";
    document.quick_order2.tran_id.value = "26";
    if (domain.indexOf("productsforindustry") != -1 || domain.indexOf("p4i") != -1)
    {
      document.quick_order2.tran_id.value = "21";
    }
    document.quick_order2.msg_id.value = "Catalog_Quick_Order";
    return true;
  }

  function tempReset()
  {
    document.temp.reset();
    var resetIsDone = "true";
    for (var i = 1; i <= document.temp.line_number.value; i++)
    {
      var name = 'document.temp.item_' + i + '.value';
      var item = eval(name);
      if (item.length != 0)
      {
        resetIsDone = "false";
        break;        
      }
    }
    if (resetIsDone == "false")
    {
      window.location.href = "eComm?template=quickorder1&cust_no="+document.quick_order1.cust_no.value+"&user_id="+document.quick_order1.user_id.value+"&ship_no="+document.quick_order1.ship_no.value;
    }
  }

  function updatePriceQty(bb, id1, id2)
  {
    var name = 'document.temp.stock_no_'+bb+'.selectedIndex';
    var indx = eval(name);//alert(indx);
    name = 'document.temp.price_text_' + bb + '_' + indx + '.value';
    var price_text = eval(name);//alert(name);

    name = 'document.temp.unit_qty3_' + bb + '_' + indx + '.value';
    var ord_qty_init = eval(name);//alert(name);
    if (document.quick_order2.template.value == "reorder2")
      ord_qty_init = 0;

    if (document.getElementById)
    {
      x = document.getElementById(id1);
      x.innerHTML = '<font style=\"font-size:10pt\" COLOR=\"#666666\">' + price_text + '</font>';
      y = document.getElementById(id2); 
      y.innerHTML = '<INPUT style=\"font-size:9pt\" TYPE=\"text\" name=\"ord_qty_' + bb + '\" SIZE=3 MAXLENGTH=10 VALUE=\"' + ord_qty_init + '\">';
    }
    else if (document.all)
    {
      x = document.all[id1];
      x.innerHTML = '<font style=\"font-size:10pt\" COLOR=\"#666666\">' + price_text + '</font>';
      y = document.all[id2];
      y.innerHTML = '<INPUT style=\"font-size:9pt\" TYPE=\"text\" name=\"ord_qty_' + bb + '\" SIZE=3 MAXLENGTH=10 VALUE=\"' + ord_qty_init + '\">';
    }
    else if (document.layers)
    {
      x = document.layers[id1];
      x.document.open();
      x.document.write('<font style=\"font-size:10pt\" COLOR=\"#666666\">' + price_text + '</font>');
      x.document.close();
      y = document.layers[id2];
      y.document.open();
      y.document.write('<INPUT style=\"font-size:9pt\" TYPE=\"text\" name=\"ord_qty_' + bb + '\" SIZE=3 MAXLENGTH=10 VALUE=\"' + ord_qty_init + '\">');
      y.document.close();
    }
  }

  function checkBlankGroup()
  {

    if (document.search.three_to_two.value == "3to2blank")
    {
      if (domain.indexOf("chproductos") != -1)
        document.write("<font face=arial size=2>No hay actualmente productos en esta categoría. Oprima por favor <a href='javascript:history.back()'>aquí</a> para volver a la ventana anterior.</font>");
      else
        document.write("<font face=arial size=2>Currently there are no products in this category. Please click <a href='javascript:history.back()'>here</a> to return to the previous window.</font>");
    }
  }

  function loadCategoryIcon()    //  Now just used by PFI/P4I sites
  {
    if (document.search.prod_cat_name.value == "Save" || document.search.msg_id.value == "Save")
    {
      document.category_icon.src = "/images/SaveLogo.gif";
      document.category_icon.height = 30;
      document.category_icon.width = 49;
    }
    else if (document.search.prod_cat_name.value == "New")
    {
      document.category_icon.src = "/images/NewLogo.gif";
      document.category_icon.height = 30;
      document.category_icon.width = 49;
    }
    else if (document.search.prod_cat_name.value == "HIPAA")
    {
      document.category_icon.src = "/images/HIPAA_Logo.gif";
      document.category_icon.height = 81;
      document.category_icon.width = 81;
      
       document.writeln("<p class=\"Note\">What is HIPAA? The first-ever federal privacy standards that protect patients’ medical records and<br>other health information provided to health plans, doctors, hospitals, and other health care providers.</p>");
       document.writeln("<p class=\"Note\">What does HIPAA require? That health plans and providers secure patient records so that they are not<br>readily available to those who do not need them.</p>");
       document.writeln("<p class=\"Note\">Who must comply? All healthcare organizations that maintain or transmit health information.</p>");
       document.writeln("<p class=\"Note\">When is the date of compliance? Most had to comply by April 14, 2003. However, small health plans<br>have until April 14, 2004.</p>");
       document.writeln("<p class=\"Note\">We have highlighted the following products to help you comply with the federal HIPAA regulations.</p>");
      
    }
  }

  function viewItemDetails(url)  //  For reorder2 page
  {
    window.open(url, '', 'toolbar=no,scrollbars=yes,resizable=yes,width=825,height=650,screenX=100,screenY=25,top=25,left=100');
  }
  
  function doCancelQuickOrder()
  {
      document.quick_order2.method = "GET";
      document.quick_order2.template.value = "quickorder1";
      document.quick_order2.tran_id.value = "";
      document.quick_order2.submit();
  }
  
  function doQuickOrderP4I()
  {
    var stock_no_all = "";
    var unit_price_all = "";
    var ord_qty_all = "";
    var prod_name_all = "";

    for(var nRow = 1; nRow <= document.temp.item_counter.value; nRow++)
    {
      var name = 'ord_qty_' + nRow;
      var ord_qty = document.temp.elements[name].value;
       name = 'stock_no_' + nRow;
      var stock_no = document.temp.elements[name].value;
       name = 'select_' + nRow;
      var select = document.temp.elements[name].value;

      var idx = 0;
      if (select == "T")  //  there is a specification list
      {
        name = 'stock_no_' + nRow;
        idx = document.temp.elements[name].selectedIndex;
      }
       name = 'prod_name_' + nRow + '_' + idx;
      var prod_name = document.temp.elements[name].value;
       name = 'unit_price3_' + nRow + '_' + idx;
      var unit_price3 = document.temp.elements[name].value;
       name = 'unit_price4_' + nRow + '_' + idx;
      var unit_price4 = document.temp.elements[name].value;
       name = 'unit_price5_' + nRow + '_' + idx;
      var unit_price5 = document.temp.elements[name].value;
       name = 'unit_price6_' + nRow + '_' + idx;
      var unit_price6 = document.temp.elements[name].value;
       name = 'unit_qty3_' + nRow + '_' + idx;
      var unit_qty3 = document.temp.elements[name].value;
       name = 'unit_qty4_' + nRow + '_' + idx;
      var unit_qty4 = document.temp.elements[name].value;
       name = 'unit_qty5_' + nRow + '_' + idx;
      var unit_qty5 = document.temp.elements[name].value;
       name = 'unit_qty6_' + nRow + '_' + idx;
      var unit_qty6 = document.temp.elements[name].value;

      if (isNaN(ord_qty))
      {
        alert("Invalid order quantity for item " + stock_no + " \nPlease check it and enter a valid number");
        return false;        
      }
      else if (ord_qty < 1)      
      {
        alert("Order quantity for item " + stock_no + " must be greater than 0.");
        return false;
      }
      else if (ord_qty%unit_qty3 != 0 || ord_qty/unit_qty3 < 1)
      {
          alert("The item " + stock_no + " is sold in quantities of " + unit_qty3 + 
            " only. Please order in multiples of " + unit_qty3 + ".")
        return false;
      }

      if (ord_qty >= new Number(unit_qty6) && (unit_price6 > 0))
      {
        unit_price3 = unit_price6;
      }
      else if (ord_qty >= new Number(unit_qty5) && (unit_price5 > 0))
      {
        unit_price3 = unit_price5;
      }
      else if (ord_qty >= new Number(unit_qty4) && (unit_price4 > 0))
      {
        unit_price3 = unit_price4;
      }

        if (ord_qty >= 1)
        {
          if (stock_no_all == "")
          {
            stock_no_all = stock_no;
            unit_price_all = unit_price3;
            ord_qty_all = ord_qty;
            prod_name_all = prod_name;        
          }
          else
          {
            stock_no_all = stock_no_all+"/"+stock_no;
            unit_price_all = unit_price_all+"/"+unit_price3;
            ord_qty_all = ord_qty_all+"/"+ord_qty;
            prod_name_all = prod_name_all+"/"+prod_name;        
          }
        }
     }

    document.quick_order2.stock_no_all.value = stock_no_all;
    document.quick_order2.unit_price_all.value = unit_price_all;
    document.quick_order2.ord_qty_all.value = ord_qty_all;
    document.quick_order2.prod_name_all.value = prod_name_all;

    if (document.quick_order2.stock_no_all.value == "")
    {
        alert("At least one quantity must be greater than 0.");
      return false;    
    }
    document.quick_order2.template.value = "ship_to";
    document.quick_order2.msg_id.value = "Catalog_Quick_Order";
    document.quick_order2.submit();
  }
  