// JavaScript Document for
//*confirming two fields of e-mail addresses are the same
//*ensuring proper e-mail address format in both
//*requiring certain fields

function ValidateForm() {

	//ensures that certain fields are required
	var popuptxt = new String();

	//Create regular expressions to find unwanted chars
	var bad_chars=/@|!|\?|%|&|\\|\/|<|>|\$|#|\[|\]|\{|\}|\(|\)|\^|~|=|\+|`|,|;|:|\*|'|"|\|/; 
	var bad_chars2=/!|\?|%|&|\\|\/|<|>|\$|#|\[|\]|\{|\}|\(|\)|\^|~|=|\+|`|,|;|:|\*|'|"|\|/; 
  var no_numbers=/\d/i;

	//error messages are generated if the following if statements are true
	if(document.askaqform.name.value.match(bad_chars))
		{ popuptxt += "\n\nPlease only use letters, numbers, underscores ( _ ), periods, or hyphens in the name field."; }
	if(document.askaqform.from.value.match(bad_chars2))
		{ popuptxt += "\n\nYour email address has one or more odd characters in it."; }
	if(document.askaqform.Location.value.match(no_numbers))
		{ popuptxt += "\n\nDo not use numbers in the city, state/country field. We do not need your street address or zip code."; }

	if(document.askaqform.Location.value.length > 30)
		{ popuptxt += "\n\nWe only allow 30 characters in the city, state/country field."; }
	if(document.askaqform.name.value < 1)
		{ popuptxt += "\n\nPlease enter your name in the \"Name\" text box."; }
	if(document.askaqform.from.value < 1)
		{ popuptxt += "\n\nPlease enter your email in the \"E-mail\" text box."; }
	if(document.askaqform.confirm.value < 1)
		{ popuptxt += "\n\nPlease enter your email again in the \"Confirm e-mail\" text box."; }

	if(document.askaqform.Area.value == "(None Selected)")
		{ popuptxt += "\n\nPlease choose a subject from the \"Subject\" drop down menu."; }

	if(document.askaqform.Reason.value < 1)
		{ popuptxt += "\n\nPlease fill in the \"How will you use this information?\" text box."; }

	if(document.askaqform.Question.value < 1)
		{ popuptxt += "\n\nPlease type your question in the \"Your question\" text box."; }

  //comparing the two e-mail addresses
	em1 = document.askaqform.from.value;
	em2 = document.askaqform.confirm.value;

	if (em1 != em2)
		{ popuptxt += "\n\nThe e-mail addresses you entered do not match. Please check them."; }

	//making sure that the e-mail address submitted has a proper format.
	FindAt = em1.indexOf("@") // check for ampersand (@)
	FindPeriod = em1.lastIndexOf(".") // check for dot (.)

	if (
			FindAt <= 0 || // need an @ sign and it cannot come first
			FindPeriod < 0 || // period cannot come first
			FindPeriod - FindAt < 2 || //period comes before @ sign and need 2 or more spaces between
			FindPeriod - em1.length == -1 // period is at end of email
		)
		{	popuptxt += "\n\nPlease check your email address."; }

	//making sure that the e-mail address does not have two at signs
	FindAt2 = em1.indexOf("@",FindAt+1) // check for at signs(@) after first at sign
	if (FindAt2 != -1)
		{	popuptxt += "\n\nYour e-mail address has more than one at sign (@) in it."; }

	//Disallow form to be submited if popuptxt has a value
	if(popuptxt == "")
	{
		//if no problems, return true and let form be submitted
		return true;
	}
	else
	{
		alert('Please look at the following fields on this form.' + popuptxt);
		return false;
	}

} // end of function ValidateForm()

function CheckRadioButtons(rb_name) {
	//checks if radio buttons are checked or not

	var rb_is_checked; //toggle to see if radio button is checked

	for(var i = 0; i < rb_name.length; i++)
	{
		if(rb_name[i].checked)
		{
			rb_is_checked = rb_name[i].value; } //no value if argument is checked
		}

		return rb_is_checked;
	}

