function checkThisContactForm(form)
{
    // Variables to hold the controls
    var Name;
    var Phone;
    var Course;
    
    Name = form["1) Name"];
    Phone = form["2) Phone"];
    Course = form["4) Subject"];
    
    if(Name.value == "")
    {
        alert("Please enter your name");
        Name.focus();
        return false;
    }
    else if(!checkPhone(Phone.value))
    {
        alert("Please enter a valid phone number");
        Phone.focus();
        return false;
    }
    else if(!checkCourse(Course))
    {
        alert("Please select a course/degree");
        return false;
    }
    return true;
}


function checkThisForm(form)
{
    // Variables to hold the controls
    var FirstName;
    var LastName;
    var Email;
    var Zip;
    var Phone;
    var Course;
	
        // Get the control a1firstname
    FirstName = form["a1firstname"];
        // If this is a control on that page, continue gathering controls
        // using this naming convention
    if(FirstName != null)
    {
        LastName = form["a2lastname"];
        Email = form["a9email"];
        Zip = form["a6zip"];
        Course = form["a10course"];
        Phone = form["a8phone"];
    }
        // Otherwise use the other naming convention
    else
    {
        FirstName = form["firstname"];
        LastName = form["lastname"];
        Email = form["email"];
        Zip = form["zip"];
        Course = form["Course Interested In"];
        Phone = form["phone"];
    }
    
    // Validate each control
    if(FirstName.value == "")
    {
        alert("Please enter your first name");
        FirstName.focus();
        return false;
    }
    else if(LastName.value == "")
    {
        alert("Please enter your last name");
        LastName.focus();
        return false;
    }
    else if(!checkEmail(Email.value) && !checkPhone(Phone.value))
    {
         alert("Please enter a valid 10 digit phone or email");
         return false;
    }
    else if(!checkZip(Zip.value))
    {
        alert("Please enter a valid zip code");
        return false;
    }
    else if(!checkCourse(Course))
    {
        alert("Please select a course/degree");
        return false;
    }
    return true;
}

function checkAllForm(form)
{
    // Variables to hold the controls
    var FirstName;
    var LastName;
    var Email;
    var Zip;
    var Phone;
    var Phone2;
    var Course;
    var Active;
    var Address;
    var City;
    var State;
	
        // Get the control a1firstname
    FirstName = form["a1firstname"];
        // If this is a control on that page, continue gathering controls
        // using this naming convention
    if(FirstName != null)
    {
        LastName = form["a2lastname"];
        Address = form["a3address"];
        City = form["a4city"];
        State = form["a5state"];
        Email = form["a9email"];
        Zip = form["a6zip"];
        Course = form["a10course"];
        Phone = form["a8phone"];
        //Phone2 = form["a8phone2"];
        Active = form["activeMilitaryPersonnel"];
    }
        // Otherwise use the other naming convention
    else
    {
        FirstName = form["firstname"];
        LastName = form["lastname"];
        Address = form["Address"];
        City = form["City"];
        State = form["state"];
        Email = form["email"];
        Zip = form["zip"];
        Course = form["Course Interested In"];
        Phone = form["phone"];
        //Phone2 = form["a8phone2"];
        Active = form["activeMilitaryPersonnel"];
    }
    
    
    // Validate each control
    if(FirstName.value == "")
    {
        alert("Please enter your first name");
        FirstName.focus();
        return false;
    }
    else if(LastName.value == "")
    {
        alert("Please enter your last name");
        LastName.focus();
        return false;
    }
    else if(Address.value == "")
    {
        alert("Please enter your address");
        Address.focus();
        return false;
    }
    else if(City.value == "")
    {
        alert("Please enter your city");
        City.focus();
        return false;
    }
    else if(State.value == "-1" || State.value == "undefined")
    {
        alert("Please select a state");
        return false;
    }
    else if(!checkZip(Zip.value))
    {
        alert("Please enter a valid zip code");
        Zip.focus();
        return false;
    }
    else if(!checkEmail(Email.value))
    {
         alert("Please enter a valid email");
         Email.focus();
         return false;
    }
    else if(!checkPhone(Phone.value))
    {
        alert("Please enter a valid 10 digit phone number");
        Phone.focus();
        return false;
    }
    /*else if(!checkPhone(Phone2.value))
    {
        alert("Please enter a valid 10 digit other/cell phone number");
        Phone2.focus();
        return false;
    }*/
    else if(!checkActiveBoth(Active))
    {
        alert("Please choose your status");
        return false;
    }
    else if(!checkCourse(Course))
    {
        alert("Please select a degree");
        return false;
    }
    return true;
}

// AAU forms require more information.  
// This function is used strictly for AAU LP's
function checkAAUForm(form)
{
    // Variables to hold the controls
    var FirstName;
    var LastName;
    var Email;
    var Zip;
    var Phone;
    var Course;
    var Active;
    var Address;
    var City;
    var State;
	
        // Get the control a1firstname
    FirstName = form["a1firstname"];
        // If this is a control on that page, continue gathering controls
        // using this naming convention
    if(FirstName != null)
    {
        LastName = form["a2lastname"];
        Address = form["a3address"];
        City = form["a4city"];
        State = form["a5state"];
        Email = form["a9email"];
        Zip = form["a6zip"];
        Course = form["a10course"];
        Phone = form["a8phone"];
        Active = form["activeMilitaryPersonnel"];
    }
        // Otherwise use the other naming convention
    else
    {
        FirstName = form["firstname"];
        LastName = form["lastname"];
        Address = form["Address"];
        City = form["City"];
        State = form["state"];
        Email = form["email"];
        Zip = form["zip"];
        Course = form["Course Interested In"];
        Phone = form["phone"];
        Active = form["activeMilitaryPersonnel"];
    }
    
    
    // Validate each control
    if(FirstName.value == "")
    {
        alert("Please enter your first name");
        FirstName.focus();
        return false;
    }
    else if(LastName.value == "")
    {
        alert("Please enter your last name");
        LastName.focus();
        return false;
    }
    else if(Address.value == "")
    {
        alert("Please enter your address");
        Address.focus();
        return false;
    }
    else if(City.value == "")
    {
        alert("Please enter your city");
        City.focus();
        return false;
    }
    else if(State.value == "-1" || State.value == "undefined")
    {
        alert("Please select a state");
        return false;
    }
    else if(!checkZip(Zip.value))
    {
        alert("Please enter a valid zip code");
        Zip.focus();
        return false;
    }
    else if(!checkEmail(Email.value))
    {
         alert("Please enter a valid email");
         Email.focus();
         return false;
    }
    else if(!checkPhone(Phone.value))
    {
        alert("Please enter a valid 10 digit phone number");
        Phone.focus();
        return false;
    }
    else if(!checkActive(Active))
    {
        alert("Please choose your status");
        return false;
    }
    else if(!checkCourse(Course))
    {
        alert("Please select a degree");
        return false;
    }
    return true;
}

function checkThisFormFooter(form)
{
    // Variables to hold the controls
    var FirstName;
    var LastName;
    var Email;
    var Phone;
    var Course;
    
        // Get the control a1firstname
    FirstName = form["a1firstname"];
        // If this is a control on that page, continue gathering controls
        // using this naming convention
    if(FirstName != null)
    {
        LastName = form["a2lastname"];
        Email = form["a9email"];
        Course = form["a10course"];
        Phone = form["a8phone"];
    }
        // Otherwise use the other naming convention
    else
    {
        FirstName = form["firstname"];
        LastName = form["lastname"];
        Email = form["email"];
        Course = form["Course Interested In"];
        Phone = form["phone"];
    }
    
    // Validate each control
    if(FirstName.value == "")
    {
        alert("Please enter your first name");
        FirstName.focus();
        return false;
    }
    else if(LastName.value == "")
    {
        alert("Please enter your last name");
        LastName.focus();
        return false;
    }
    else if(!checkEmail(Email.value) && !checkPhone(Phone.value))
    {
         alert("Please enter a valid phone or email");
         return false;
    }
    else if(!checkCourse(Course))
    {
        alert("Please select a course");
        return false;
    }
    return true;
}

function checkCourse(course)
{
    switch(course.type)
    {
        case "text":
        case "hidden":
            if(course.value == "")
            {
                return false;
            }
        break;
        case "select-multiple":
        case "select-one":
            if(course.value == "-1" || course.value == "")
            {
                return false;
            }
        break;
    }
    return true;
}

function checkZip(zip)
{
    if(zip.length != 5)
    {
        return false;
    }
    if(!IsNumeric(zip))
    {
        return false;
    }
    return true;
}

function checkActiveBoth(Active)
{
    if(Active.type == "select-one")
    {
        if(Active.value == "-1" || Active.value == "")
        {
            return false;
        }
        return true;
    }
    else
    {
        alert("here");
        for(var i=0; i<Active.length; i++)
        {
            if(Active[i].checked == true)
            {
                return true;
            }
        }
        return false;
    }
}

function checkActiveCombo(Active)
{
    if(Active.value == "-1" || Active.value == "")
    {
        return false;
    }
    return true;
}

function checkActive(Active)
{
    for(var i=0; i<Active.length; i++)
    {
        if(Active[i].checked == true)
        {
            return true;
        }
    }
    return false;
}

function IsNumeric(Num)
{
    // Nums is the list of possible numbers
    var Nums = "0123456789";
    var i=0;
    for(i=0;i<Num.length;i++)
    {
        // If the character at position i is not in the Nums string, return false
        if(Nums.indexOf(Num.charAt(i)) == -1)
        {
            return false;
        }
    }
    return true;
}

function checkPhone(phone)
{
    // Replace anything that is non-numeric
    phone = phone.replace(/\D/g,"");
    
    // Phone number must be 10 characters long
    if(phone.length != 10 && phone.length != 14)
    {
        return false;
    }
    return true;
}

function checkEmail(email)
{
     var at = "@";
     var dot = ".";
     // Get the first occurrence of @
     var AtLoc = email.indexOf(at);
     // Get the first occurrence of .
     var DotLoc = email.indexOf(dot);
     // Get the length of the email
     var len = email.length;
     // Make sure it is at least 5 characters long
     if(len < 5)
     {
        return false;
     }
     // Make sure it has an @ sign
     else if(AtLoc == -1)
     {
        return false;
     }
     // Make sure it has atleast one .
     else if(DotLoc == -1)
     {
        return false;
     }
     // Make sure there is a period after the @ sign
     else if(DotLoc < AtLoc)
     {
        DotLoc = email.indexOf(dot, AtLoc);
        if(DotLoc == -1)
        {
            return false;
        }
     }
     return true;
}