  function addOne(val, outerPackQty) {
    if (Math.floor(val) == Math.ceil(val)) {
      if ((outerPackQty == undefined) ||
          (outerPackQty == 0)) {
        val = Number(val) + 1;
      } else {
        val = Math.ceil((Number(val)+1)/Number(outerPackQty))*Number(outerPackQty);
      }
    } else {
      val = Math.ceil(val);
    }
    return val;
  }

  function subOne(val, outerPackQty) {
    if (Math.floor(val) == Math.ceil(val)) {
      if ((outerPackQty == undefined) ||
          (outerPackQty == 0)) {
        val = Number(val) - 1;
      } else {
        val = Math.floor((Number(val)-1)/Number(outerPackQty))*Number(outerPackQty);
      }
    } else {
      val = Math.floor(val);
    }
    if (val <= 0) {
      val = "";
    }
    return val;
  }

  function qtyAddOne(arrPosition, outerPackQty) {
    if (document.mainform.p_orderQtyArr.length == undefined) { // only one qty in array, therefore no array
      document.mainform.p_orderQtyArr.value = addOne(Number(document.mainform.p_orderQtyArr.value), Number(outerPackQty));
    } else {
      document.mainform.p_orderQtyArr[arrPosition].value = addOne(Number(document.mainform.p_orderQtyArr[arrPosition].value), Number(outerPackQty));
    }
    return false;
  }

  function qtySubOne(arrPosition, outerPackQty) {
    if (document.mainform.p_orderQtyArr.length == undefined) { // only one qty in array, therefore no array
      document.mainform.p_orderQtyArr.value = subOne(Number(document.mainform.p_orderQtyArr.value), Number(outerPackQty));
    } else {
      document.mainform.p_orderQtyArr[arrPosition].value = subOne(Number(document.mainform.p_orderQtyArr[arrPosition].value), Number(outerPackQty));
    }
    return false;
  }

  function ask(question, action) {
    if (confirm(question)) {
      document.mainform.p_action.value = action;
      return true;
    } else {
      return false;
    }
  }

  function setAction(action) {
    document.mainform.target='';
    document.mainform.p_action.value = action;
  }

  function setActionNewPage(action) {
    document.mainform.target='_blank';
    document.mainform.p_action.value = action;
  }

  function setActionAndSubmit(action, prod_cat_code) {
    document.mainform.target='';
    document.mainform.p_action.value = action;
    document.mainform.p_action_value.value = prod_cat_code;
    document.mainform.submit();
  }

  function isValidEmail(str) { 
     return ((str.indexOf(".") > 0) && (str.indexOf("@") > 0) && (str.indexOf(" ") < 0));
  } 

  function checkEnterFromField(submitValue)
  {
    if (event.keyCode == 13) {
      document.mainform.p_action.value = submitValue;
    }
    return true;
  }

  function split_company_num_cust_code() {
    document.mainform.p_company_num.value = document.mainform.p_company_and_cust_code.value.substr(0,1);
    document.mainform.p_cust_code.value   = document.mainform.p_company_and_cust_code.value.substr(2,document.mainform.p_company_and_cust_code.value.length-2);
    return true;
  }

  function changeFields() {
    if ((document.mainform.p_list_option.value == "CreateNew") ||
        (document.mainform.p_list_option.value == "DupList")) {
      if (document.mainform.p_list_option_list_id != undefined) { 
        document.mainform.p_list_option_list_id.style.visibility="hidden"; 
      }
      document.mainform.p_list_option_dlvry_date.style.visibility="hidden";
      document.mainform.p_new_list_name.style.visibility="visible";
      document.mainform.p_new_list_name.focus();
      document.mainform.p_new_list_name.select();
    } else if ((document.mainform.p_list_option.value == "DupOrder") ||
               (document.mainform.p_list_option.value == "OrderList")) {
      if (document.mainform.p_list_option_list_id != undefined) { 
        document.mainform.p_list_option_list_id.style.visibility="hidden"; 
      }
      document.mainform.p_new_list_name.style.visibility="hidden";
      document.mainform.p_list_option_dlvry_date.style.visibility="visible";
    } else if (document.mainform.p_list_option.value == "Standing") {
      if (document.mainform.p_list_option_list_id != undefined) { 
        document.mainform.p_list_option_list_id.style.visibility="hidden"; 
      }
      document.mainform.p_new_list_name.style.visibility="hidden";
      document.mainform.p_list_option_dlvry_date.style.visibility="hidden";
    } else {
      document.mainform.p_new_list_name.style.visibility="hidden";
      document.mainform.p_list_option_dlvry_date.style.visibility="hidden";
      document.mainform.p_list_option_list_id.style.visibility="visible"; 
    };
    return true;
  }

  function statusPopup(msg,bak){
    var content="<table class=box_outer width=150 bordercolor=black cellpadding=4 cellspacing=0 rules=none "+
    "bgcolor="+bak+"><td align=center><font color=black size=2>"+msg+"</font></td></table>";
    yyy=Yoffset;
     if(ns4){skn.document.write(content);skn.document.close();skn.visibility="visible"}
     if(ns6){document.getElementById("dek").innerHTML=content;skn.display=''}
     if(ie4){document.all("dek").innerHTML=content;skn.display=''}
  }
  
  function statusPopupGetMouse(e){
    var x=(ns4||ns6)?e.pageX:event.x+document.body.scrollLeft;
    skn.left=x+Xoffset;
    var y=(ns4||ns6)?e.pageY:event.y+document.body.scrollTop;
    skn.top=y+yyy;
  }
  
  function statusPopupKill(){
    yyy=-1000;
    if(ns4){skn.visibility="hidden";}
    else if (ns6||ie4)
      skn.display="none"
  }

  function trim(s) {
    var str = s;
    while (str.substring(0,1) == ' ') {
      str = str.substring(1,str.length);
    }
    while (str.substring(str.length-1,str.length) == ' ') {
      str = str.substring(0,str.length-1);
    }
    return str;
  }

