    function WB_ValidateInput()
    {
      with (document.WBCalc)
      {
        return !(isNaN(Number(frontWeight.value))  ||
                 isNaN(Number(rearWeight.value))   ||
                 isNaN(Number(fuelWeight.value))   ||
                 isNaN(Number(baggageWeight.value)));
      }
    }

    function WB_Plot(weight, moment)
    {
      // Left-margin on the graph is 65 pixels...
      var x = Math.round(1 + ((moment - 40000) / 10000) * 50) - 220;
      var y = 266 - Math.round(((weight - 1500) / 100) * 20) - 10;

	  with (document.images.crossHairImage.style)
	  {
	    left = x + 'px';
	    top  = y + 'px';
	   	visibility = "visible";
	  }
    }

    function WB_Calculate()
    {
      with (document.WBCalc)
      {
        totalWeight.value = WB_ValidateInput() ?
          (Number(emptyWeight.value) +
           Number(frontWeight.value) +
           Number(rearWeight.value)  +
           Number(fuelWeight.value)  +
		   Number(baggageWeight.value)  +
           Number(baggageWeight2.value)).toString() : "???";

        emptyMoment.value =
          (Math.round(Number(emptyWeight.value)   * Number(emptyLever.value))).toString();
        frontMoment.value =
          (Math.round(Number(frontWeight.value)   * Number(frontLever.value))).toString();
        rearMoment.value =
          (Math.round(Number(rearWeight.value)    * Number(rearLever.value))).toString();
        fuelMoment.value =
          (Math.round(Number(fuelWeight.value)    * Number(fuelLever.value))).toString();
        baggageMoment.value =
          (Math.round(Number(baggageWeight.value) * Number(baggageLever.value))).toString();
        baggageMoment2.value =
          (Math.round(Number(baggageWeight2.value) * Number(baggageLever2.value))).toString();

        totalMoment.value =
          (Number(emptyMoment.value) +
           Number(frontMoment.value) +
           Number(rearMoment.value)  +
           Number(fuelMoment.value)  +
           Number(baggageMoment.value)  +
           Number(baggageMoment2.value)).toString();

        // Show the crosshair on the graph...
        WB_Plot(Number(totalWeight.value), Number(totalMoment.value));
		
		
        // Display the Error message...
		if  (parseFloat(totalWeight.value)>2558) {
        var message = "\nBased on the provided data,\n"
        message += "this aircraft will be overweight at takeoff!\n"
        alert(message)
        inuse_flag = false
    }

    if  (parseFloat((totalMoment.value)/(totalWeight.value))>47.3) {
        var message = "\nBased on the provided data,\n"
        message += "The takeoff CG may be AFT of limits\n"
        message += "for this aircraft. Please check the\n"
        message += "CG limitations as it applies to the\n"
        message += "weight and category of your flight.\n"
        alert(message)
        inuse_flag = false
    }
	
	if  ((parseFloat((totalMoment.value)/(totalWeight.value))<35) &&
	(parseFloat(totalWeight.value)<=1950)) {
        var message = "\nBased on the provided data,\n"
        message += "The takeoff CG may be FWD of limits\n"
        message += "for this aircraft. Please check the\n"
        message += "CG limitations as it applies to the\n"
        message += "weight and category of your flight.b\n"
        alert(message)
        inuse_flag = false
    }
	
	if  (parseFloat(totalWeight.value)<=1950) {
    return true
    }
	
    if  ((parseFloat((totalMoment.value)/(totalWeight.value))-35)/ (parseFloat(totalWeight.value)-1950)<(41.0-35)/(2558-1950)) {
        var message = "\nBased on the provided data,\n"
        message += "The takeoff CG may be FWD of limits\n"
        message += "for this aircraft. Please check the\n"
        message += "CG limitations as it applies to the\n"
        message += "weight and category of your flight.\n"
        alert(message)
        inuse_flag = false
    }
   }

   }

    function WB_Reset()
    {
      with (document.WBCalc)
      {
        // Set the fields to their default values...
        emptyWeight.value   = "1698.4";
        frontWeight.value   = "180";
        rearWeight.value    = "";
        fuelWeight.value    = "210";  // Full fuel by default
        baggageWeight.value = "";
        baggageWeight2.value = "";

        emptyLever.value    = "39.54";
        frontLever.value    = "37.00";
        rearLever.value     = "73.00";
        fuelLever.value     = "48.00";
        baggageLever.value  = "95.00";
        baggageLever2.value = "123.00";
      }

      // Hide the crosshair on the graph...
//      document.images.crossHairImage.style.visibility = "hidden";

      // Calculate based on empty values...
      WB_Calculate();
    }

