function MPI_Validator()
{


  var checkOK = "0123456789-.,";
  var checkStr = MPI.PoundsMilk.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  var poundsmilk = MPI.PoundsMilk.value;
 
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Pounds Milk / Cow Day\" field.");
    MPI.PoundsMilk.value = "";
    MPI.PoundsMilk.focus();
    return (false);
  }

  if (decPoints > 1)
  {
    alert("Please enter a valid number in the \"PoundsMilk\" field.");
    MPI.PoundsMilk.value = "";
    MPI.PoundsMilk.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = MPI.MailboxMilkPrice.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  var mailbox = MPI.MailboxMilkPrice.value;

  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Settlement Milk Price\" field.");
    MPI.MailboxMilkPrice.value = "";
    MPI.MailboxMilkPrice.focus();
    return (false);
  }

  if (decPoints > 1)
  {
    alert("Please enter a valid number in the \"MailboxMilkPrice\" field.");
    MPI.MailboxMilkPrice.value = "";
    MPI.MailboxMilkPrice.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = MPI.FeedCost.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  var feedcost = MPI.FeedCost.value;

  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Feed Cost / Cow / Day\" field.");
    MPI.FeedCost.value = "";
    MPI.FeedCost.focus();
    return (false);
  }

  if (decPoints > 1)
  {
    alert("Please enter a valid number in the \"FeedCost\" field.");
    MPI.FeedCost.value = "";
    MPI.FeedCost.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = MPI.PoundsDryMatter.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  var poundsdry = MPI.PoundsDryMatter.value;

  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Pounds Dry Matter\" field.");
    MPI.PoundsDryMatter.value = "";
    MPI.PoundsDryMatter.focus();
    return (false);
  }

  if (decPoints > 1)
  {
    alert("Please enter a valid number in the \"PoundsDryMatter\" field.");
    MPI.PoundsDryMatter.value = "";
    MPI.PoundsDryMatter.focus();
    return (false);
  }
  if (poundsmilk == "")
  {
    alert("Please enter a value for \"Pounds Milk / Cow Day\".");
    MPI.PoundsMilk.focus();
    return (false);
  }
   if (mailbox == "")
  {
    alert("Please enter a value for \"Settlement Milk Price\".");
    MPI.MailboxMilkPrice.focus();
    return (false);
  }
  if (feedcost == "")
  {
    alert("Please enter a value for \"Feed Cost / Cow / Day\".");
    MPI.FeedCost.focus();
    return (false);
  }
  if (poundsdry == "")
  {
    alert("Please enter a value for \"Pounds Dry Matter\".");
    MPI.PoundsDryMatter.focus();
    return (false);
  }
 //*************Start the calculations Here*****************************
 
 var nDME = (poundsmilk/poundsdry);
 
 var nDM = (feedcost/poundsdry);
 
 var nIOFC = ((poundsmilk*(mailbox/100))-feedcost);
 
 var ttlMPI = (nIOFC*(100/7));
 
 //***************Round the Numbers***************************************
  
  MPI.DME.value = round(nDME,2);
  MPI.DM.value = round(nDM,3);
  MPI.IOFC.value = round(nIOFC,2);
  MPI.MPI.value = round(ttlMPI,1);

 
}


function round(number,X) 
{
// rounds number to X decimal places, defaults to 2
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

