
//  Checks Empty Fields

function validate_required(nameValue,alertBox)  {
        with (nameValue)
            {
                if (value==null || value=="")
                    {
                        alert(alertBox);
                        return false;
                    }
                else
                    {
                        return true;
                    }
            }
}

//  Validates Email

function validate_email(nameValue,alertBox) {
        with (nameValue)
            {
                apos    = value.indexOf("@");
                dotpos  = value.lastIndexOf(".");

                if (apos < 1 || dotpos-apos < 2)
                    {
                        alert(alertBox);
                        return false;
                    }
                else
                    {
                      return true;
                    }
        }
}

//  Checks number of characters in comment field

function length_restriction(elem, min, max){
	    var uInput = elem.value;
	        if  (uInput.length >= min && uInput.length <= max)
                    {
		                return false;
	                }
            else
                    {
		                alert("Please enter your comments, but enter no more than 1000 characters");
		                elem.focus();
		                return true;
	                }
}

//  Performs form validation

function validate_form(thisform)    {
        with (thisform)
            {

                if (validate_required(FirstName,"Please enter your First Name")==false)
                {FirstName.focus();return false;}

                if (validate_required(LastName,"Please enter your Last Name")==false)
                {LastName.focus();return false;}

                if (validate_email(EmailAddress,"Please enter a valid e-mail address!")==false)
                {EmailAddress.focus();return false;}

                if (length_restriction(document.getElementById('Comments'), 1, 1000))
                {Comments.focus();return false;}

            }
    }

