/* NEEDED TO MAKE FORM RETURN FALSE WITH FIREFOX */
addEvent(window, "load", init);

function init()
{
	registrationForm = document.getElementById("registrationForm"); // initialize registration form and paste the line below into return false area of checkForm area
	//addEvent(registrationForm, "submit", correctSubmitHandler);
}

function correctSubmitHandler(e)
{
	if (e && e.preventDefault)
		e.preventDefault();
	return false;
}

function addEvent(obj, evType, fn)
{
	if (obj.addEventListener)
	{
   		obj.addEventListener(evType, fn, false);
   		return true;
	}
	else if (obj.attachEvent)
	{
   		var r = obj.attachEvent("on"+evType, fn);
   		return r;
 	}
 	else
 	{
   		return false;
 	}
}
/* NEEDED TO MAKE FORM RETURN FALSE WITH FIREFOX */


function checkForm_onmouseup()
{
	var myForm = document.registrationForm;
	if(myForm.firstName.value == "" || myForm.lastName.value == "" || myForm.address.value == "" || myForm.city.value == "" || myForm.phone.value == "" || myForm.email.value == "")
	{
		alert("Please fill in all the required sections");
		if(myForm.firstName.value == "")
		{
			myForm.firstName.focus();
		}
		else if(myForm.lastName.value == "")
		{
			myForm.lastName.focus();
		}
		else if(myForm.address.value == "")
		{
			myForm.address.focus();
		}
		else if(myForm.city.value == "")
		{
			myForm.city.focus();
		}
		else if(myForm.phone.value == "")
		{
			document.getElementById("phoneWarning").style.display = "inline";
			myForm.phone.focus();
		}
		else if(myForm.email.value == "")
		{
			document.getElementById("emailWarning").style.display = "inline";
			myForm.email.focus();
		}
		//addEvent(registrationForm, "submit", correctSubmitHandler);
		return false;
	}
	else
	{
		return true;
	}
}

function checkZip_onchange()
{
	var zipValue = document.registrationForm.zip;
	if(isNaN(zipValue.value) == true || zipValue.value.match(/\d{1}/) || zipValue.value.match(/\d{2}/) || zipValue.value.match(/\d{3}/) || zipValue.value.match(/\d{4}/))
	{
		document.getElementById("zipWarning").style.display = "inline";
		zipValue.focus();
	}
	if(zipValue.value.match(/\d{5}/))
	{
		document.getElementById("zipWarning").style.display = "none";
	}
}

function checkPhone_onchange()
{
  var rePhone = new RegExp(/\d{3}-\d{3}-\d{4}/);
	var phoneValue = document.registrationForm.phone.value;
  if(!phoneValue.match(rePhone))
	{
		document.getElementById("phoneWarning").style.display = "inline";
		document.registrationForm.phone.focus();
  }
	if(phoneValue.match(rePhone))
	{
		document.getElementById("phoneWarning").style.display = "none";
	}
}

function checkFax_onchange()
{
  var reFax = new RegExp(/\d{3}-\d{3}-\d{4}/);
	var faxValue = document.registrationForm.fax.value;
  if(!faxValue.match(reFax))
	{
		document.getElementById("faxWarning").style.display = "inline";
		document.registrationForm.fax.focus();
  }
	if(faxValue.match(reFax))
	{
		document.getElementById("faxWarning").style.display = "none";
	}
}

function checkEmail_onchange()
{
  var reEmail = new RegExp(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/);
	var emailValue = document.registrationForm.email.value;
  if (!emailValue.match(reEmail))
	{
    document.getElementById("emailWarning").style.display = "inline";
		document.registrationForm.email.focus();
  }
	if (emailValue.match(reEmail))
	{
    document.getElementById("emailWarning").style.display = "none";
  }
}

function writeOptions()
{
	var stateOption = new Array("Select a state","Alaska, AK","Alabama, AL","Arkansas, AR","Arizona, AZ","California, CA","Colorado, CO","Connecticut, CT","District of Columbia, DC","Delaware, DE","Florida, FL","Georgia, GA","Hawaii, HI","Iowa, IA","Idaho, ID","Illinois, IL","Indiana, IN","Kansas, KS","Kentucky, KY","Louisiana, LA","Massachusetts, MA","Maryland, MD","Maine, ME","Michigan, MI","Minnesota, MN","Missouri, MO","Mississippi, MS","Montana, MT","North Carolina, NC","North Dakota, ND","Nebraska, NE","New Hampshire, NH","New Jersey, NJ","New Mexico, NM","Nevada, NV","New York, NY","Ohio, OH","Oklahoma, OK","Oregon, OR","Pennsylvania, PA","Rhode Island, RI","South Carolina, SC","South Dakota, SD","Tennessee, TN","Texas, TX","Utah, UT","Virginia, VA","Virgin Islands, VI","Vermont, VT","Washington, WA","Wisconsin, WI","West Virginia, WV","Wyoming, WY");
	var optionCounter;
	
	for (optionCounter=0; optionCounter<stateOption.length; optionCounter++)
	{
		document.write('<option value="' + stateOption[optionCounter] + '">' + stateOption[optionCounter] + '</option>');
	}
}