function isInt(elm) {
	var elmstr = elm.value + "";
	if (elmstr == "") {
		return false;
	}  for (var i = 0; i < elmstr.length; i++) {
		if (elmstr.charAt(i) < "0" ||
			elmstr.charAt(i) > "9") {
			return false;
		}  }  return true;
}  function validateZIP(elm) {
	var valid = "0123456789-";
	var hyphencount = 0;

	if (elm.length!=5 && elm.length!=10) {
	alert("Please enter your 5 digit zip code.");
	return false;
	}
	for (var i=0; i < elm.length; i++) {
	temp = "" + elm.substring(i, i+1);
	if (temp == "-") hyphencount++;
	if (valid.indexOf(temp) == "-1") {
	alert("Invalid characters in your zip code.  Please try again.");
	return false;
	}
	if ((hyphencount > 1) || ((elm.length==10) && ""+elm.charAt(5)!="-")) {
	alert("A '5 digit + 4' zip code should be entered like '12345-0123'. Please try again.");
	return false;
	   }
	}
	return true;
} function isEmail(elm) {
	if (elm.value.indexOf("@") + "" != "-1" &&
		elm.value.indexOf(".") + "" != "-1" &&
		elm.value != "") {
		return true;
	}  else return false;
} function isNotEmail(elm) {	
	if (elm.value.indexOf("@") + "" != "-1" || 
		elm.value.indexOf(".") + "" != "-1" || 		
		elm.value.indexOf("*") + "" != "-1") {		
		return false;
	} else return true;	
} function isPhone(elm) {
	if (elm.value.length == 8) {
		return true;
	}  else return false;
} function textIsFilled(elm) {
	if (elm.value == "" || elm.value == null) {
		return false;
	} else {
		var reWhitespace = /^\s+$/		
		if (elm.length == 0 || reWhitespace.test(elm)) {
			return false;
		}else{
			return true;
		}
	}		
} function textIsLength(elm, min, max) {
	if (elm.value.length < min) {
		return false;
	} else {
		if (elm.value.length > max) {
			return false;
		}  }  return true;
} function dropDownChosen(sIndex) {
	if (sIndex == 0 ) {
		return false;
	} else {
		return true;
	} 
} function radioChosen(elm) {
	for (var i = 0; i < elm.length; i++) {
		if (elm[i].checked) {
			return true;
		}  }  return false;
} function whichRadioChosen(elm) {
	for (var i = 0; i < elm.length; i++) {
		if (elm[i].checked) {
			return i;
		}  }  return -1;
} function checkboxChosen(elm) {
	if (elm.checked) {
		return true;
	} else {
		return false;
	} } function getPhoneNum(elm) {
	elmstr = elm.value;
	newstr = "";
	 for (var i=0; i <= elmstr.length; i++) {
		if (elmstr.charAt(i) < "0" ||
			elmstr.charAt(i) > "9") {
			 } else {
			newstr += elmstr.charAt(i);
		}  }  if (newstr.charAt(0) == "1") {
		 newstr = newstr.substring(1, newstr.length);
	}  if (newstr.length > 14) {
		 newstr = newstr.substring(0, 14);
	}  return newstr;
} function getNum(elm) {
	elmstr = elm.value;
	newstr = "";
	 for (var i=0; i <= elmstr.length; i++) {
		if (elmstr.charAt(i) < "0" ||
			elmstr.charAt(i) > "9") {
			 } else {
			newstr += elmstr.charAt(i);
		}  }  return newstr;
} function isMonth(elm) {
	if (elm.value.length == 2 && elm.value.substring(0,1) == "0") {
		elm.value = elm.value.substring(1,elm.value.length);
	}  num = parseInt(elm.value);
	if (num >= 1 && num <= 12) {
		if (num < 10) {
			elm.value = "0" + elm.value;
		}  return true;
	} else {
		return false;
	} } function flipSlashes(elmstr) {
	newstr = "";
	 for (var i=0; i <= elmstr.length; i++) {
		if (elmstr.charAt(i) == "\\") {
			 newstr += "/";
		} else {
			newstr += elmstr.charAt(i);
		}  }  return newstr;
} function is2DigitInt(elm) {
	var elmstr = elm.value + "";
	if (elmstr == "") {
		return false;
	}  for (var i = 0; i < elmstr.length; i++) {
		if (elmstr.charAt(i) < "0" ||
			elmstr.charAt(i) > "9") {
			return false;
		}  }   if (elmstr.length < 2) {
		 elm.value = "0" + elmstr;
	}  return true;	
}  function isMoney(elm) {
	var elmstr = elm.value + "";
	var bFoundDecimal = "false";
	var nAfterDecimal = 0;

	if (elmstr == "") {
		return false;
	}  for (var i = 0; i < elmstr.length; i++) {
		if (elmstr.charAt(i) < "0" ||
			elmstr.charAt(i) > "9")	{

			if (elmstr.charAt(i) != ".") {
				 return false;
			} else {
				 if (bFoundDecimal == "true") {
					return false;
				} else {
					bFoundDecimal = "true"
				}  }

		} else {

			if (bFoundDecimal == "true") {
				nAfterDecimal = nAfterDecimal + 1;

				if (nAfterDecimal > 2) {
					 return false;
				}

			}  } }  if (elmstr.length == 1 && elmstr.charAt(0) == ".") {
		return false;
	}  return true;
} 

function HexToR(h) {return parseInt((cutHex(h)).substring(0,2),16)}

function HexToG(h) {return parseInt((cutHex(h)).substring(2,4),16)}

function HexToB(h) {return parseInt((cutHex(h)).substring(4,6),16)}

function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}

function isRGB(elm) {
	if (HexToR(elm) >= 0 && HexToR(elm) < 256 && HexToG(elm) >= 0 && HexToG(elm) < 256 && HexToB(elm) >= 0 && HexToB(elm) < 256) {
		return true;
	}else{
		return false;
	}
}

function countlines(fldname) {
	//var area = document.getElementById(fldname)         // trim trailing return char if exists
	var text = fldname.value.replace(/\s+$/g,"")
	var split = text.split("\n")
	return split.length	
}

// validate form input
