// JavaScript Document

	//validate form entries
	function validateForm(form)
	{
		var chList   = 'companyName||contactPerson||address1||city||state||zip||phone||email||taxID||username||password||confirmPassword';
		var emList   = 'email';
		var numList  = '';
		var charList = '';
		
		if (chList !== "")
		{
			var theData = chList.split("||");
			for(var i=0;i<=theData.length;i++)
			{
				if ((theData[i] != undefined) && (document.getElementById(theData[i]).value == "" || document.getElementById(theData[i]).value == undefined))
				{
					alert('Please fill in all required fields!');
					return false;
				}
			}
		}

				if (emList !== "")
		{
			var theData = emList.split("||");
			for(var i=0;i<=theData.length;i++)
			{
				if ((theData[i] != undefined) && document.getElementById(theData[i]).value != "" && document.getElementById(theData[i]).value != undefined)
				{
					tmp = document.getElementById(theData[i]).value;
					if (notValidEmail(tmp))
					{
						alert('"'+tmp+'" is not a valid email!');
						return false;
					}
				}
			}
		}
		
		if (charList !== "")
		{
			var theData = charList.split("||");
			for(var i=0;i<=theData.length;i++)
			{
				if ((theData[i] != undefined) && document.getElementById(theData[i]).value != "" && document.getElementById(theData[i]).value != undefined)
				{
					tmp = document.getElementById(theData[i]).value;
					if (!validChars(tmp))
					{
						alert('"'+tmp+'" should be Alphabetic only!');
						return false;
					}
				}
			}
		}
		
		if (numList !== "")
		{
			var theData = numList.split("||");
			for(var i=0;i<=theData.length;i++)
			{
				if ((theData[i] != undefined) && document.getElementById(theData[i]).value != "" && document.getElementById(theData[i]).value != undefined)
				{
					tmp = document.getElementById(theData[i]).value;
					if (!validNums(tmp))
					{
						alert('"'+tmp+'" should be Numeric only!');
						return false;
					}
				}
			}
		}
		
		document.forms[0].submit();
		return true;
	}
	
	// this function validates email addresses
	// entered
	function notValidEmail( email )
	{
		if( email.length < 4 )
		{
			return true;
		}

		// regular expression to check address validity
		var filter = new RegExp('^([\\w-]+(\\.[\\w-]+)*)@(([\\w-]+\\.)*\\w[\\w-]{0,66})\\.([a-z]{2,6}(\\.[a-z]{2})?)$','i');

		// test the string
		if( filter.test(email) )
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	
	function validChars( str )
	{
		return /^ *[a-zA-Z_]+ *$/.test(str);
	}
	
	function validNums( str )
	{
		return /^ *[0-9]+ *$/.test(str);
	}

	//get value from URL
	function getParam( name )
	{
	  name = name.replace(/[[]/,"\[").replace(/[]]/,"\]");
	  var regexS = "[\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
	    return "";
	  else
	    return results[1];
	}

	function onStart()
	{
		var res = getParam("res");
		if (res == "true" && document.getElementById("form_thanktext").value != "")
			alert(document.getElementById("form_thanktext").value);
		if (res == "false")
			alert("Could not save form results, please try again later.");
	}

