// All functions in this procedure are protected by Logic rules of programmers.
// You can use all or part of this document

function isValidPhoneNumber(s) {
	var temp = s.replace(/\D/g, "");
	return temp.length > 9 && temp.length < 26;
}

function isValidZipCode(s) {
	var temp = s.replace(/\D/g, "");
	return temp.match(/^\d{5}$|^\d{9}$/) != null;
}

function isValidSelectBox(o) {
	return (o.options[o.selectedIndex].value != "_none_" && o.options[o.selectedIndex].value.trim() != "");
}

function isValidEmailAddress(s) {
	var temp = s.replace(/\s/g, "");
	return temp.match(/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) && temp.charAt(0) != "." && !(temp.match(/\.\./));
}
	
function textFieldBlurHandler() {
	this.value = this.value.trim();
}

function phoneFieldBlurHandler() {
	var temp = this.value.replace(/\D/g, "");

	if (temp.length > 9 && temp.length < 26)
		if (temp.length == 10) {
			this.value = "(" + temp.substring(0,3) + ") ";
			this.value += temp.substring(3,6) + "-" + temp.substring(6,10);
		}
	}

function zipcodeFieldBlurHandler() {
	var temp = this.value.replace(/\D/g, "");

	if (temp.length == 5 || temp.length == 9) { 
		if (temp.length == 5) this.value = temp
		else this.value = temp.substring(0,5) + "-" + temp.substring(5,9);
	}
}

function attachAllTextHandlers(f) {
	var el;
	for (var i = 0; (el = f.elements[i]); i++) {
		if (el.type == "text" || el.type == "textarea") 
			el.onblur = textFieldBlurHandler;
	}
}

Array.prototype.push = function(v) {
	this[this.length] = v;
	return v;
}
