//*********************************
// Form Validation functions
//*********************************

function ValidateEmailTextBox (strTextBoxID, fIsRequired)
{
	var cTextBox = document.getElementById(strTextBoxID);
	var cEmailRegExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))\s*$/;
	var fIsValid = true;

	if ((fIsRequired) && (!ValidateTextBox(strTextBoxID)))
	{
		cTextBox.value = cTextBox.value.replace(/\s/g, "")

		fIsValid = false;
	}
	else if ((cTextBox.value.replace(/\s/g, "") != "") && (!cEmailRegExp.test(cTextBox.value)))
	{

		fIsValid = false;
	}

	return (fIsValid);
}

function ValidateTextBox (strTextBoxID)
{
	var cTextBox = document.getElementById(strTextBoxID);
	var fIsValid = true;

	if (cTextBox.value.replace(/\s/g, "") == "")
	{
		cTextBox.value = cTextBox.value.replace(/\s/g, "")

		fIsValid = false;
	}

	return (fIsValid);
}


function removeWhiteSpace( email )
{
	var orgString = document.getElementById(email).value
	var newString = "";
	var counter = 0

	for (counter; counter < orgString.length; counter ++)
	{
		newString += orgString.substring(counter, counter+1).replace(" ", "");
	}
	document.getElementById(email).value = newString;

	//document.getElementById(email).value = (document.getElementById(email).value).replace("e",'');
	///^\s*|\s*$/g
}

function checkPhone3( phone )
{
  	// phoneRegex = /^\D*\d{3}\D*\d{3}\D*\d{4}$/;
  	phoneRegex = /^\D*\d{3}$/;

 	if( !phone.match( phoneRegex ) )
 	{
 		 return false;
 	}

 	return true;
}

function checkPhone4( phone )
{
   	phoneRegex = /^\D*\d{4}$/;

 	if( !phone.match( phoneRegex ) )
 	{
 		 return false;
 	}

 	return true;
}

// reset 'invalid entry' style back to normal text style
function setStyle(x)
{
	document.getElementById(x).className = 'text';
}

function fastPhone(original,destination){
if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
destination.focus()
}
