function checkNumber(contents){
 if (isNaN(contents)){return true;}
 return false;
}
function numberRange(object_value, min_value, max_value){
 if (min_value != null)
  if (object_value < min_value) return false;
 if (max_value != null)
  if (object_value > max_value) return false;
 return true;
}
function checkCreditCard(object_value){
 var white_space = " -";
 var creditcard_string="";
 var check_char;
 if (object_value.length == 0) return false;
  // squish out the white space
  for (var i = 0; i < object_value.length; i++){
   check_char = white_space.indexOf(object_value.charAt(i))
   if (check_char < 0) creditcard_string += object_value.substring(i, (i + 1));
  }	
  // if all white space return error
  if (creditcard_string.length == 0) return true;
  // make sure number is a valid integer
  if (creditcard_string.charAt(0) == "+") return true;
  if (checkNumber(creditcard_string)) return true;
  // now check mod10
  var doubledigit = creditcard_string.length % 2 == 1 ? false : true;
  var checkdigit = 0;
  var tempdigit;
  for (var i = 0; i < creditcard_string.length; i++){
   tempdigit = eval(creditcard_string.charAt(i))
   if (doubledigit){
    tempdigit *= 2;
    checkdigit += (tempdigit % 10);
    if ((tempdigit / 10) >= 1.0) checkdigit++;
     doubledigit = false;
   }
   else{
    checkdigit += tempdigit;
    doubledigit = true;
  }
 }
 return (checkdigit % 10) == 0 ? false : true;
}
function checkDate(inputStr){
 if (inputStr != ""){
  if (!(inputStr.length==10 && inputStr.indexOf('/')==2 && inputStr.indexOf('/',3)==5)) return true;
  var mm = parseInt(inputStr.substring(0,2),10);
  var dd = parseInt(inputStr.substring(3,5),10);
  var yyyy = parseInt(inputStr.substring(6,10),10);
  if (isNaN(mm)||isNaN(dd)||isNaN(yyyy)||mm==0||dd==0||yyyy==0) return true;
  if (mm<1||mm>12||dd<1||dd>31) return true;
 }
 else return true;
 return false;
}
function checkEmail(inputStr){
 var atsign = 0;
 var period = 0;
 var domainperiod = 0;
 var badchar = 0;
 var LastCharPos = inputStr.length - 1;
 for (var i = 0; i < inputStr.length; i++) {
  var oneChar = inputStr.charAt(i);
  if (oneChar == "@"){
   atsign = atsign + 1;
   continue;
  }
  if (oneChar == "."){
   if (atsign > 0) domainperiod = 1;
   period = period + 1;
   continue;
  }
  if (oneChar == " " || oneChar == "\"" || oneChar == "\," || oneChar == "\;" || oneChar == "\:" || oneChar == "\(" || oneChar == "\)" || oneChar == "\[" || oneChar == "\]" || oneChar == "\{" || oneChar == "\}" || oneChar == "\<" || oneChar == "\>" || oneChar == "\=" || oneChar == "\+" || oneChar == "\?" || oneChar == "\&" || oneChar == "\^" || oneChar == "\%" || oneChar == "\`" || oneChar == "\*" || oneChar == "\'" || oneChar == "\!" || oneChar == "\#" || oneChar == "\$" || oneChar == "\|" || oneChar == "\\" || oneChar == "\/"){
   badchar = badchar + 1;
   continue;
  }
 }
 if (inputStr.indexOf("@.") >= 0) return true;
 else if (inputStr.indexOf(".@") >= 0) return true;
 else if(inputStr.charAt(0) == ".") return true;
 else if(inputStr.charAt(0) == "@") return true;
 else if(inputStr.charAt(LastCharPos) == ".") return true;
 else if(inputStr.charAt(LastCharPos-1) == ".") return true;
 else if(inputStr.charAt(LastCharPos) == "@") return true;
 else if(atsign == 1 && period > 0 && domainperiod > 0 && badchar == 0) return false;
 else return true;
}
function checkPhone(object_value){
 if (object_value.length == 0) return false;
 if (object_value.length != 12) return true;
 if (checkNumber(object_value.substring(0,3))) return true;
 else if (!numberRange((eval(object_value.substring(0,3))), 100, 1000)) return true;
 if (object_value.charAt(3) != "-") return true
 if (checkNumber(object_value.substring(4,7))) return true;
 else if (!numberRange((eval(object_value.substring(4,7))), 100, 1000)) return true;
 if (object_value.charAt(7) != "-") return true;
 if (object_value.charAt(8) == "-" || object_value.charAt(8) == "+") return true;
 else return (checkNumber(object_value.substring(8,12)));
}
function checkDblQuotes(TextBoxName){
 temptext = TextBoxName.value;
 temptext.toString();
 while(temptext.indexOf("\"") >= 0){
  pos = temptext.indexOf("\"");
  tempnew = temptext.substring(0,pos);
  tempnew = tempnew + "'";
  tempnew = tempnew + temptext.substring(pos+1,temptext.length);
  TextBoxName.value = tempnew;
  temptext = TextBoxName.value;
 }
}
function checkHtmlTags(TextBoxName){
 temptext = TextBoxName.value;
 temptext.toString();
 if(temptext.indexOf("<") >= 0){
  if(temptext.indexOf(">") >= 0) return true;
 }
 return false;
}
function replaceCommas(TextBoxName){
 var temptext = "";
 var tempnew = "";
 temptext = TextBoxName.value;
 temptext.toString();
 while(temptext.indexOf(",") >= 0){
  pos = temptext.indexOf(",");
  tempnew = temptext.substring(0,pos);
  tempnew = tempnew + "^69^69^";
  tempnew = tempnew + temptext.substring(pos+1,temptext.length);
  TextBoxName.value = tempnew;
  temptext = TextBoxName.value;
 }
}
function poundRid(TextBoxName){
 var temptext = "";
 var tempnew = "";
 temptext = TextBoxName.value;
 temptext.toString();
 while(temptext.indexOf("#") >= 0){
  pos = temptext.indexOf("#");
  tempnew = temptext.substring(0,pos);
  tempnew = tempnew;
  tempnew = tempnew + temptext.substring(pos+1,temptext.length);
  TextBoxName.value = tempnew;
  temptext = TextBoxName.value;
 }
}