
      function checkBid(currentNext, buyPrice, minLotSize, quantityLeft){
           var form = document.getElementById("form");
           var price = form.price.value;
           var maxbid = form.maxbid.value;
           var quantity = form.quantity.value;
           if (!checkPrice(currentNext, buyPrice)){
               return false;
           }

           if (!checkQuantity(minLotSize, quantityLeft)){
               return false;
           }

           if (price.length <= 0 || quantity.length <= 0){
               alert("Bid price and quantity are required fields.");
               return false;
           }
           if (maxbid.length <= 0) {
           } else if ( (maxbid*1) < (price*1) ){
               alert("Max bid must be larger than bid price!");
               return false;
           }
           form.submit();
           return true;
      }

      function checkPrice(currentNext, buyPrice){
           var price = document.getElementById("form").price.value;

           if ( (price*1) < (currentNext*1) ){
               alert("Please enter a bid price larger than or equal to the current minimum bid "+currentNext);
               return false;
           }
           if (buyPrice > 0 && (price*1) >= (buyPrice*1) ){
               return confirm("Are you sure you want to bid higher than buy now price "+buyPrice+"?");
           }
           return true;
      }

      function checkMinQuantity(minLotSize){
           if (document.getElementById("form").quantity.value < minLotSize){
               alert("Please bid for quantity larger than "+minLotSize);
               return false;
           }
      }

      function checkQuantity(minLotSize, quantityLeft){
           var quantity = document.getElementById("form").quantity.value;

           var index = quantity.indexOf('.');
           if (index >= 0){
               var intvalue = quantity.substring(0, index);
               if ((quantity*1) != (intvalue*1)){
                   alert("Quantity must be an integer value!");
                   return false;
               }
           }

           if ( (quantity*1) < (minLotSize*1) ){
               alert("Please bid for quantity larger than "+minLotSize);
               return false;
           }
           if ( (quantity*1) > (quantityLeft*1) ){
               alert("Please bid for quantity less than current available "+quantityLeft);
               return false;
           }
           return true;
      }

      function checkContactBuyer(){
          var message = document.getElementById("form").message.value;
          if (message.length <= 0){
               alert("Please enter your message!");
               return false;
           }
           return true;
      }

      function fieldRequired(form, fieldName){
          var value = document.getElementById("fieldName").value;
          if (value.length <= 0){
               alert("Please enter data to the required field!");
               return false;
           }
           return true;
      }

      function confirmBuy(){
           var form = document.getElementById("buyForm");
           if (confirm("Please confirm you want to buy for quantity "+quantity+" at price "+price)){
               form.submit();
           } else {
               return false;
           }
      }

      function checkBuyQuantity(minLotSize, quantityLeft){
           var quantity = document.getElementById("buyForm").quantity.value;

           var index = quantity.indexOf('.');
           if (index >= 0){
               var intvalue = quantity.substring(0, index);
               if ((quantity*1) != (intvalue*1)){
                   alert("Quantity must be an integer value!");
                   return false;
               }
           }

           if ( (quantity*1) < (minLotSize*1) ){
               alert("The minimum quantity to buy is "+minLotSize);
               return false;
           }
           if ( (quantity*1) > (quantityLeft*1) ){
               alert("Please buy in less than current available "+quantityLeft);
               return false;
           }
           return true;
      }
