// ------------------------------------------ /
//  Validation java script				   
//  Aurhor: Ranga Sep 2000				   
// ------------------------------------------ /
var whitespace = " \t\n\r";
var decimalPointDelimiter = "."
var pEntryPrompt = "Please enter a "
var defaultEmptyOK = false;

function isEmpty(s){
  return ((s == null) || (s.length == 0));
}

function isWhitespace (s){
  var i;
  if (isEmpty(s))
    return true;
  for (i = 0; i < s.length; i++){
    var c = s.charAt(i);
    if (whitespace.indexOf(c) == -1)
      return false;
  }
  return true;
}

function stripCharsInBag(s, bag){
  var i;
  var returnString = "";
  for (i = 0; i < s.length; i++){
    // Check that current character isn't whitespace.
    var c = s.charAt(i);
    if (bag.indexOf(c) == -1) returnString += c;
  }
  return returnString;
}

function stripWhitespace (s){
  return stripCharsInBag (s, whitespace);
}

function charInString (c, s){
  for (i = 0; i < s.length; i++){
    if (s.charAt(i) == c) return true;
  }
  return false;
}
function stripInitialWhitespace (s){
  var i = 0;
  while ((i < s.length) && charInString (s.charAt(i), whitespace))
    i++;
  return s.substring (i, s.length);
}

function isLetter (c){
  return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) );
}

function isDigit (c){
  return ((c >= "0") && (c <= "9"));
}

function isInteger (s){
  var i;
  if (isEmpty(s)){
    if (isInteger.arguments.length == 1)
      return defaultEmptyOK;
    else
      return (isInteger.arguments[1] == true);
  }
  for (i = 0; i < s.length; i++){
    var c = s.charAt(i);
    if (!isDigit(c)) return false;
  }
  return true;
}

function isDecimal(fieldValue) {

decallowed = 2;  // how many decimals are allowed?

if (isNaN(fieldValue) || fieldValue == "") {
return false;
}
else {
if (fieldValue.indexOf('.') == -1) fieldValue += ".";
dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);

if (dectext.length > decallowed)
{
alert ("Oops!  Please enter a number with up to " + decallowed + " decimal places.  Please try again.");
return false;
}
else {
return true;
      }
   }
}

function prompt (s){
  window.status = s;
}

function promptEntry (s){
  window.status = pEntryPrompt + s;
}

function myalert(s){
  if(s == FormerMsg){
    FormerMsg = "	";
    return false;
  }
  else
    FormerMsg = s;
  alert(FormerMsg);
  return false;
}

function warnEmpty (theField, s){
  theField.focus()
    myalert(mPrefix + s + mSuffix)
    return false;
}

function warnInvalid (theField, s){
  theField.focus();
  theField.select();
  myalert(s);
  return false;
}

function IsValidFatValue(vFat){
	if ( isNaN(vFat) ) return false;
	if (vFat<0 || vFat>9999){
		return false
	}
	return true
}

function IsValidCalorieValue(vCalories){
	if ( isNaN(vCalories) ) return false;
	if (vCalories<0 || vCalories>9999){
		return false
	}
	return true
}
function IsValidFiberValue(vFiber){
	if ( isNaN(vFiber) ) return false;
	if (vFiber<0 || vFiber>9999){
		return false
	}
	return true
}
