function submitMenu(which) {
	document.getElementById('menuform').action = "index.php";
	document.getElementById('menuform').page.value = which;
	document.getElementById('menuform').submit();
}

function ContactUs(form) {
	document.getElementById("firstlabel").style.color = "#000000";
	document.getElementById("lastlabel").style.color = "#000000";
	document.getElementById("emaillabel").style.color = "#000000";
	document.getElementById("phonelabel").style.color = "#000000";
	document.getElementById("invalid").style.color = "RED";
	document.getElementById("invalid").style.display = "none";
	var first = form.first_name.value;
	var last = form.last_name.value;
	var email = form.email_addr.value;
	var areacode = form.phone_area_code.value;
	var prefix = form.phone_prefix.value;
	var suffix = form.phone_suffix.value;
	var comment = form.comments.value;
	var spam = form.my_url.value;
	var temp = null;

	if (spam == "") {
		if (first.length > 0) {
			for (i = 0; i < first.length; i++) {
				temp = first.charAt(i);
				if (/[0-9]/.test(temp)) {
					document.getElementById("firstlabel").style.color = "RED";
					document.getElementById("invalid").innerHTML = "INVALID FIRST NAME";
					document.getElementById("invalid").style.display = "";
					form.first_name.focus();
					return false;
				}
			}
		} else {
			document.getElementById("firstlabel").style.color = "RED";
			document.getElementById("invalid").innerHTML = "INVALID FIRST NAME";
			document.getElementById("invalid").style.display = "";
			form.first_name.focus();
			return false;
		}
	
		if (last.length > 0) {
			for (i = 0; i < last.length; i++) {
				temp = last.charAt(i);
				if (/[0-9]/.test(temp)) {
					document.getElementById("lastlabel").style.color = "RED";
					document.getElementById("invalid").innerHTML = "INVALID LAST NAME";
					document.getElementById("invalid").style.display = "";
					form.last_name.focus();
					return false;
				}
			}
		} else {
			document.getElementById("lastlabel").style.color = "RED";
			document.getElementById("invalid").innerHTML = "INVALID LAST NAME";
			document.getElementById("invalid").style.display = "";
			form.last_name.focus();
			return false;
		}
	
		if (email.length > 0) {
			var at = email.lastIndexOf("@");
			var emailtest = true;

			// Make sure the at (@) sybmol exists and  
			// it is not the first or last character
			if (at < 1 || (at + 1) === email.length) emailtest = false;

			// Make sure there aren't multiple periods together
			if (/(\.{2,})/.test(email)) emailtest = false;

			// Break up the local and domain portions
			var local = email.substring(0, at);
			var domain = email.substring(at + 1);

			// Check lengths
			if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255) emailtest = false;

			// Make sure local and domain don't start with or end with a period
			if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain)) emailtest = false;

			// Check for quoted-string addresses
			// Since almost anything is allowed in a quoted-string address,
			// we're just going to let them go through
			if (!/^"(.+)"$/.test(local)) {
				// It's a dot-string address...check for valid characters
				if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local)) emailtest = false;
			}

			// Make sure domain contains only valid characters and at least one period
			if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1) emailtest = false;	

			if (emailtest == false) {
				document.getElementById("emaillabel").style.color = "RED";
				document.getElementById("invalid").innerHTML = "INVALID EMAIL";
				document.getElementById("invalid").style.display = "";
				form.email_addr.focus();
				return false;
			}
		} else {
			document.getElementById("emaillabel").style.color = "RED";
			document.getElementById("invalid").innerHTML = "INVALID EMAIL";
			document.getElementById("invalid").style.display = "";
			form.email_addr.focus();
			return false;
		}

		if (areacode != "" && prefix != "" && suffix != "") {
			if (!IsNumeric(areacode) || areacode.length < 3) {
				document.getElementById("phonelabel").style.color = "RED";
				document.getElementById("invalid").innerHTML = "INVALID AREA CODE";
				document.getElementById("invalid").style.display = "";
				form.phone_area_code.focus();
				return false;
			} else if (!IsNumeric(prefix) || prefix.length < 3) {
				document.getElementById("phonelabel").style.color = "RED";
				document.getElementById("invalid").innerHTML = "INVALID PREFIX";
				document.getElementById("invalid").style.display = "";
				form.phone_prefix.focus();
				return false;
			} else if (!IsNumeric(suffix) || suffix.length < 4) {
				document.getElementById("phonelabel").style.color = "RED";
				document.getElementById("invalid").innerHTML = "INVALID LINE NUMBER";
				document.getElementById("invalid").style.display = "";
				form.phone_suffix.focus();
				return false;
			}
		} else {
			document.getElementById("phonelabel").style.color = "RED";
			document.getElementById("invalid").innerHTML = "INVALID PHONE NUMBER";
			document.getElementById("invalid").style.display = "";
			form.phone_area_code.focus();
			return false;
		}
	
		if (comment == "") {
			answer = confirm("Are you sure you dont want to add a comment?\n\nOK=Submit Form  Cancel=Add Comment");
			if (!answer) {
				form.comments.focus();
				return false;
			}
		} else {
			var patt = /http/g;
			if (patt.test(comment)) {
				document.getElementById("invalid").innerHTML = "INVALID COMMENT";
				document.getElementById("invalid").style.display = "";
				form.comments.focus();
				return false;
			}	
		}
		form.action = "http://www.precision-gfx.com/index.php";
		form.submit();
	}
	else return false;
}

function ResetForm(form) {
	document.getElementById("firstlabel").style.color = "#000000";
	document.getElementById("lastlabel").style.color = "#000000";
	document.getElementById("emaillabel").style.color = "#000000";
	document.getElementById("phonelabel").style.color = "#000000";
	document.getElementById("invalid").style.display = "none";
	form.first_name.value = "";
	form.last_name.value = "";
	form.email_addr.value = "";
	form.phone_area_code.value = "";
	form.phone_prefix.value = "";
	form.phone_suffix.value = "";
	form.comments.value = "";
}

function IsNumeric(val) {
	for (i = 0; i < val.length; i++) {
		if (!(/[0-9]/.test(val.charAt(i)))) return false;
	}
	return true;
}

function Redirect(popwin) {
	popwin.close();
	window.location = "http://www.precision-gfx.com/";
}
