var reg_empty = /^\s+$/;
var reg_email = /^[^@ ]+@[^@ ]+\.[^@ \.]+$/;
function replaceValue(e, newValue, check) {
	if (e.value == check) {
		e.value = newValue;
	}
}

function validateForm(f, skip) {
	var e = f.elements;
	allowSubmit = true;
	var msg = "Please make sure that all fields are completed correctly.";
	for (var i=0; i<e.length; i++) {
		var n = e[i].name;
		var skipElement = false;
		if (skip != undefined) {
			for (var a=0; a<skip.length; a++) {
				if (skip[a] == n) {
					skipElement = true;
					break;
				}
			}
		}
		if (skipElement == false) {
			var t = e[i].type;
			if (t == "text" || t == "password" || t == "textarea") {
				var testValue = checkEmpty(e[i].value);
				if (testValue == true) {
					allowSubmit = false;
				} else if (n.indexOf('email')>-1) {
					var testEmail = checkEmail(e[i].value);
					if (testEmail == false) {
						allowSubmit = false;
						msg += "\nMake sure all email addresses are correct.";
					}
				}
			}
		}
	}
	if (allowSubmit == false) {
		alert(msg);
	}
	return allowSubmit;
}

function checkEmpty(v) {
	if (v == "") {
		var isEmpty = true;
	} else {
		isEmpty = reg_empty.test(v);
	}
	return isEmpty;
}

function checkEmail(v) {
	return reg_email.test(v);
}