function validateZIP(whichfield) {
	var valid = "0123456789-";
	var hyphencount = 0;
	var str = whichfield.value;

	if (str.length!=5 && str.length!=10) {
		whichfield.style.backgroundColor="#FFAAAA";
		return false;
	}
	for (var i=0; i < str.length; i++) {
	temp = "" + str.substring(i, i+1);
	if (temp == "-") hyphencount++;
		if (valid.indexOf(temp) == "-1") {
			whichfield.style.backgroundColor="#FFAAAA";
			return false;
		}
		if ((hyphencount > 1) || ((str.length==10) && ""+str.charAt(5)!="-")) {
			whichfield.style.backgroundColor="#FFAAAA";
			return false;
		}
	}
	whichfield.style.backgroundColor="white";
	return true;
}

function checkEmail(whichfield){
	var str = whichfield.value
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var chars = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(i=0; i < str.length ;i++){
		if( chars.indexOf(str.charAt(i))<0) {
			whichfield.style.backgroundColor="#FFAAAA";
			return (false);
		}
	}
	if (filter.test(str)){
		whichfield.style.backgroundColor="white";
		return true;
	} else {
		whichfield.style.backgroundColor="#FFAAAA";
		return false;
	}
}

function checkPhone(whichfield) {
	r = "";
	s = whichfield.value;
	for (i=0; i < s.length; i++) {
		if (s.charAt(i) != '\n' && s.charAt(i) != '\r' && s.charAt(i) != '\t' && s.charAt(i) != '-' && s.charAt(i) != '\)' && s.charAt(i) != '(' && s.charAt(i) != ' ' && s.charAt(i) != '.') {
			r += s.charAt(i);
		}
	}
	t = "";
	for (j=0; j < 10; j++){
		t += r.charAt(j);
		if ((j==2) || (j==5)){
			t += "-";
		}
	}
	var useareacode=1;
	whichfield.value =  t;
	phoneRegex = /^\d\d\d-\d\d\d-\d\d\d\d$/;
	if( !t.match( phoneRegex ) ) {
		whichfield.style.backgroundColor="#FFAAAA";
		return false;
	} else {
		whichfield.style.backgroundColor="white";
		return true;
	}
}

function testNull(whichfield){
	str = whichfield.value;
	if(str==""){
		whichfield.style.backgroundColor="#FFAAAA";
		return false;
	} else {
		whichfield.style.backgroundColor="white";
		return true;
	}
}

function dateValidate(whichfield){
	xval=whichfield.value;
	if (xval==''){
		whichfield.style.backgroundColor="#FFAAAA";
		return false;
	} else {
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
		var matchArray = datePat.test(xval); // is the format ok?
		if (matchArray == false) {
			whichfield.style.backgroundColor="#FFAAAA";
			return false;
		}else {
			whichfield.style.backgroundColor="white";
			return true;
		}
	}
}

function dateValidateBlankOK(whichfield){
	xval=whichfield.value;
	if (xval==''){
		whichfield.style.backgroundColor="white";
		return true;
	} else {
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
		var matchArray = datePat.test(xval); // is the format ok?
		if (matchArray == false) {
			var datePat2 = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{2})$/;
			var matchArray2 = datePat2.test(xval); // is the format ok?
			if (matchArray2 == false) {
				whichfield.style.backgroundColor="#FFAAAA";
				return false;
			} else {
				whichfield.style.backgroundColor="white";
				return true;
			}
		}else {
			whichfield.style.backgroundColor="white";
			return true;
		}
	}
}

function isInt(whichfield) {
	if (isNaN (whichfield.value)){
		whichfield.style.backgroundColor="#FFAAAA";
		return false;
	}else {
		whichfield.style.backgroundColor="white";
		return true;
	}
}

function formatPhone( num ) {
  if(num.length != 10) {
	_return = num;
  } else {
	_return = "(" + num.substring(0,3) + ") " + num.substring(3,6) + "-" + num.substring(6,10);
  }
  return _return;
}

function lettersNumbersOnly( fld ){
	var valid = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
	var str = fld.value;
	var temp = '';
	var newstr = '';
	for (var i=0; i < str.length; i++) {
		temp = str.substring(i, i+1);
		if (valid.indexOf(temp) != "-1") {
			newstr += temp;
		}
	}
	fld.value = newstr;
	return true;
}