function highlight(id,focusClass,blurClass)
{
	id.value='';
	id.onfocus = function () {this.className = focusClass;}
	id.onblur = function () {this.className = blurClass;}
	id.focus();
}

function jump(elmnt,content)
{
	if (content.length==elmnt.maxLength)
	{
	next=elmnt.tabIndex;
		if (next<document.body.forms[0].elements.length)
		{
			document.body.forms[0].elements[next].focus();
		}
	}
}

function lenCheck(value, field, category) 
{
	// Requires at least 2 characters to be entered.
	if (value < 2)
		{
			alert('Please enter at least 2 characters in the ' + category + ' field.');
			field.value='';
			field.focus();
			return false;
		}
		// Requires at most 29 characters to be entered.
	if (value > 29)
		{
			alert('Please enter no more than 29 characters in the ' + category + ' field.');
			field.value='';
			field.focus();
			return false;
		}
	return true;
}

function concatPhone()
{
	var f = document.forms["theForm"].elements;				// Grab your form.
	var s = "";												// Initialize variable s.
	for (var i = 0; i < f.length; i++) 						// While 'i' is less than the length of all form elements...
	{
		if (f[i].getAttribute("class") == "form4 required") // If the current 'i' form element has the class name equal to "xxx"
		{
			s += "".concat(f[i].value);						// Add and set equal to the value with "" to 's'.
		}					
	}						
	document.getElementById("phone").value = s; 			// Set concatentated string to the hidden phone input field.
	//alert(s);
}

function vladTheValidator(theForm)
{
	
	var fnameID = theForm.fname;
	var lnameID = theForm.lname; 
	var zipID = theForm.zip;
	var emailID = theForm.email;
	var phoneID = theForm.phone;
	
	
	var alphaRegxp = /^([a-zA-Z\s\-]+)$/;			// Letters, whitespace, and hyphen.
	var alphaNumRegxp = /^([0-9A-Za-z\s\-]+)$/;		// Letters, numbers, whitespace, and hyphen.
	var NumRegxp = /^([0-9]+)$/;					// Numbers only -- Any Length.
	var emailRegxp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	
	
	
	
	// First Name Check	
	
		if (!fnameID.value)
			{
				alert('You must enter your First Name.');
				fnameID.value='';
				fnameID.focus();
				return false;
			}
		
		if (alphaRegxp.test(fnameID.value) != true)
			{
				alert('First name contains illegal characters.');
				fnameID.value='';
				fnameID.focus();
				return false;
			}
		
		if (lenCheck(fnameID.value.length, fnameID, 'First Name') == false)
				return false;
		
	// Last Name Check		
	
			if (!lnameID.value)
			{
				alert('You must enter your Last Name.');
				lnameID.value='';
				lnameID.focus();
				return false;
			}								
		
		if (alphaRegxp.test(lnameID.value) != true)
			{
				alert('Last name contains illegal characters.');
				lnameID.value='';
				lnameID.focus();
				return false;
			}

		// Require at least 2 characters and no more than 29 characters to be entered.
		
		if (lenCheck(lnameID.value.length, lnameID, 'Last Name') == false)
				return false; 
	
	// Zip Code Check
		var zip_len = zipID.value.length;
		var zip_1st = zipID.value.charAt(0);
		if (!zipID.value)
			{
				alert('You must fill in the Zip Code Field.');
				highlight(zipID,'highlightActiveField','form_fields');
				return false;
			}
		if (NumRegxp.test(zip_1st) != true)
			{
				if(zip_len != 6)
				{
					alert('Please enter six (6) characters for your Canadian Zip Code.');
					highlight(zipID,'highlightActiveField','form_fields');
					return false;
				}
			}
			if (NumRegxp.test(zip_1st) != false)
			{	
				if(zip_len != 5)
				{
					alert('Please enter five (5) characters for your Zip Code.');
					highlight(zipID,'highlightActiveField','form_fields');
					return false;
				}
				
			}
			/* Commented out for Canada */
			/*if (NumRegxp.test(zipID.value) != true)
					{
						alert('Please enter only numbers for your Zip Code.');
						zipID.value='';
						zipID.focus();
						return false;
					} */
	// Email Check
		if (!emailID.value)
			{
				alert('Please Enter your Email Address');
				highlight(emailID,'highlightActiveField','form_fields');
				return false;
			}
		if (emailRegxp.test(emailID.value) != true)
			{
				alert('Please enter a valid Email Address.');
				highlight(emailID,'highlightActiveField','form_fields');
				return false;
			}	
	// Phone Area Code Check
		var pac_len = phoneID.value.length;
		if (!phoneID.value)
		{
				alert('You must fill in the Phone Field.');
				highlight(phoneID,'highlightActiveField','form_fields');
				return false;
		}
		
		if (pac_len != 10)
		{
				alert('Please enter exactly ten (10) digits for your Phone Number.');
				highlight(phoneID,'highlightActiveField','form_fields');
				return false;
		}
		
		if (NumRegxp.test(phoneID.value) != true)
		{
				alert('Please enter only numbers for your Phone Number.');
				highlight(phoneID,'highlightActiveField','form_fields');
				return false;
		}


	else	// All good, son!
	{
		return true;
	}
} // End of Script