/* - - - - - - - - - - - - - - - - - - - - - - -
 JavaScript
 Thursday, December 13, 2007 11:53:50 AM
 HAPedit 3.1.11.111
 - - - - - - - - - - - - - - - - - - - - - - - */

// Validate calculusonline admin forms

// alert ( "Testing" );

function validateForm( )
{

    // are we even getting in here?
    // alert( "We're getting in here" );

    // set the name pattern (use for last and first name)
    var namepat = /^[a-zA-Z][a-zA-Z\s,-]+$/;
    // set the middle initial patern
    var mipat = /[^a-zA-Z]+/;
    // set the street pattern
    var streetpat = /^[a-zA-Z0-9][a-zA-Z0-9\s]+\s*$/;
    // set up the city pattern
    var citypat = /^[a-zA-Z][a-zA-Z\s]+\s{0,3}$/;
    // set up the zip code pattern
    var zippat = /^[0-9]{5}(-[0-9]{4})?\s*$/;
    // set up the email pattern
    var emailpat = /^[a-zA-Z0-9][\.a-zA-Z0-9_-]*@[a-zA-Z0-9]+\.[a-zA-Z]+$/;

    // set up the url pattern
    var urlpat = /http/;

    // set up the phone number pattern
    var phonepat = /^[^a-zA-Z]{10,20}$/;

    // set the school name pattern
    var schoolnamepat = /^[a-zA-Z][a-zA-Z\s,-]+\s{0,3}$/;
    // set up the date pattern
    var datepat = /^(0|1)[0-9]{1}-[0-3][0-9]-20(0|1)[0-9]$/;
    // set up a gate keeper
    var gate = true;

    if  ((document.fotmform.Name.value == "") || (!namepat.test(document.fotmform.Name.value)))
    {
        alert ( "Please provide a valid name with no punctuation" );
        document.tutor_entry.fname.focus();
        fotmform.Name.focus();
        gate = false;
        return (false);
    }

    if (
           (urlpat.test(document.fotmform.DayTimeNumber.value)) ||
           (urlpat.test(document.fotmform.HomeNumber.value)) ||
           (urlpat.test(document.fotmform.FaxNumber.value)) ||
           (urlpat.test(document.fotmform.ZipCode.value)) ||
           (urlpat.test(document.fotmform.DateOfArrival.value)) ||
           (urlpat.test(document.fotmform.DateOfDeparture.value)) ||
           (urlpat.test(document.fotmform.HowDidYouFindUs.value))
       )
    {
        alert( "What do you think you're doing putting a URL in one of these fields" );
        gate = false;
        return (false);
    }


    else if (((document.fotmform.HomeNumber.value == "") || (!phonepat.test(document.fotmform.HomeNumber.value))) &&
            ((document.fotmform.DayTimeNumber.value == "") || (!phonepat.test(document.fotmform.DayTimeNumber.value))) &&
            ((document.fotmform.EmailAddress.value == "") || (!emailpat.test(document.fotmform.EmailAddress.value))))
    {
       alert ( "Please provide a phone number, or an email address.  The phone number must be a minimum of 10 digits and a maximum of 20 digits.  The email address must be a valid email address" );
       gate = false;
       return (false);
    }

    else if (document.fotmform.Agree.selectedIndex == 0)
    {
        alert("We no longer make reservations with black bears, not since the incident.  Please select 'I am a real person'.");
        fotmform.Agree.focus();
        gate = false;
        return (false);
    }

    else{
        fotmform.submit();
    }
    /*
    else if(gate == true)
    {
        // change the form action to the real submition page
        document.getElementById('fotmform').action = "_vti_bin/shtml.dll/fotmform.htm";
        // submit the form
        document.getElementById('fotmform').submit();
    } */
}