function isValidText(object, text){
  var str = trim(object.value);
  if (str.length > 0){
    return true;
  }
  else{
    window.alert("Please enter " + text);
    object.focus();
    return false;
  }
}

function isValidNumber(object, text){
  if (isValidText(object, text)){
    var str = trim(object.value);
    var re = new RegExp(/^[0-9]+$/);
    if (re.test(str)){
      return true;
    }
    else{
      window.alert(text + "\nPlease enter a valid number");
      object.focus();
      return false;
    }
  }
  return false;
}


function isValidEmail(object, text) {
  if (isValidText(object, text)){
    if (object.value.indexOf('@', 0) > -1) {
      return true;
    }
    window.alert(text + " is invalid");
    object.focus();
  }
  return false;
}


function trim(strText) { 
  // this will get rid of leading spaces 
  while (strText.substring(0,1) == ' ') 
      strText = strText.substring(1, strText.length); 
  // this will get rid of trailing spaces 
  while (strText.substring(strText.length-1,strText.length) == ' ') 
      strText = strText.substring(0, strText.length-1); 
  return strText; 
} 

