
// ***************************************************************************************************************************
// Javascript Validation Form - The idea behind this is that if a form field is left blank and is suppose to be a required
// field then on submission of the form, a javascript pop up window will pop up and let the user know that they need to fill
// in a certain field. The window will also display multiple requirements in case they leave multple field blank.
// ***************************************************************************************************************************

// Text that will be displayed in the pop up window
var m2alerttext = "";

// Flag to see if their are any empty fields. 0 means their are none, 1 means their is
var m2error = 0;

// This function accepts the field and the text to be displayed should the field be empty. 
// should the field be empty then it will append the text to m2alerttext and return false. 
// It returns true if the field is empty
function validate_required(field,alerttxt)
{
	with (field)
	{
		//Check to see if field is Null or empty
		if (value==null||value=="")
		{
			//Append to the alert text and return false
			m2alerttext = m2alerttext + alerttxt;
			return false;
		}
		else 
		{
			//Field is not empty return true
			return true
		}
	}
}
	

// This function is called when a person submits the form. It will loop through the required fields
// and call the validaton function. If validation returns false then it will trigger the trigger
// variable and after the loop it will output the text and return false so the form is not submitted
// Page 1 Function
function validate_form(thisform)
	{
		// Loop through the fields and see if they are empty
		with (thisform)
		{
			if (validate_required(firstname,"FIRST NAME must be filled out!\n")==false) {m2error = 1;}
			if (validate_required(lastname,"LAST NAME must be filled out!\n")==false) {m2error = 1;}
			if (validate_required(city,"CITY must be filled out!\n")==false) {m2error = 1;}
			if (validate_required(email,"E-MAIL must be filled out!\n")==false) {m2error = 1;}
		}
		
		// If a field is empty then pop up window
		if(m2error == 1) 
		{ 
			alert(m2alerttext);
			
			//Set error and alert text to nothing for when they resubmit the page
			m2error=0;
			m2alerttext="";
			return false; 
		}
	}