// Form validator for KingdomREA.com. 27 Jan 06. schiraoka@cybertorpedo.com.
// Modified from original source. Used according to JimWorld.com copyright permissions.
// Original Source from http://www.virtualpromote.com/tools/javascript-regex/index.html
// Original Source Copyright: Copyright © 1994-2006 JimWorld.com, a division of iWeb, inc. All rights reserved. 

var valid = new Object();
	valid.emailAddress = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,6}|[0-9]{1,3})(\]?)$/;
	valid.reqField = /\S/;
var reCF = /_verify/i;
function validateForm(theForm) {
		var elArr = theForm.elements;
		for(var i = 0; i < elArr.length; i++) {
			 with(elArr[i]) {
					elArr[i].parentNode.style.backgroundColor = "transparent";
					var v = elArr[i].validator;
					if(!v) continue;
					var thePat = valid[v];
					var gotIt = thePat.exec(value);
					var alertName = name.replace(/_/g," ");
					if(type == "radio") {
						var radState = checkRadio(theForm, name);
						if(!radState) {
						alert("Please correct the following required field: \n" + alertName); 
						elArr[i].parentNode.style.backgroundColor = "#fd0";
						elArr[i].focus();
						return false;}}
					else if(reCF.test(name)){
						var cfN = name.replace(/_verify/i, "");
						var cfV = theForm.elements[cfN].value;
						var alertCFN = cfN.replace(/_/g," ");
						if(cfV != value){
						  alert("Please be sure these fields match:\n" + alertCFN + " and " + alertName);
							cfN = name.replace(/_verify/i, "");
						 	elArr[i].parentNode.style.backgroundColor = "#fd0";
						 	theForm.elements[cfN].parentNode.style.backgroundColor = "#fd0";
							elArr[i].select();
							return false;}
						else {
						 	elArr[i].parentNode.style.backgroundColor = "transparent";
						 	theForm.elements[cfN].parentNode.style.backgroundColor = "transparent";}}
					else if(!gotIt){
						 alert("Please correct the following required field: \n" + alertName);  
						 elArr[i].parentNode.style.backgroundColor = "#fd0";
						 elArr[i].focus();
						 if(tagName != "SELECT") { elArr[i].select(); }
						 return false;}}}
		return true;}
						 
function checkRadio(theForm, name) {
		var radArr = theForm.elements[name];
		for (var iRad = 0; iRad < radArr.length; iRad++) {
			with(radArr[iRad]) {
				var c = radArr[iRad].checked;
				if(!c) continue;
				return true;}}
		return false;}