﻿// JScript File

function validatePostalCode(inputValue)
{
        var pattern=/^[A-Za-z][0-9][A-Za-z] [0-9][A-Za-z][0-9]$/;
        var status = true;
        
        if(!pattern.test(inputValue))
        {         
            alert("Not a valid postal code!");
            status = false;
        }
        
        return status;
}  
function checkEmail(field1,field2,alertText)
  {
            with(field1,field2)
      { 
            if( field1.value != field2.value)
         {
            alert("Email address must be same");
            return false;
         } 
   else
         {
               return true;
         }
       }
   }



        
function radio_button_checker(field)
{
// set var radio_choice to false
var radio_choice = false;

// Loop from zero to the one minus the number of radio button selections
for (counter = 0; counter < field.length; counter++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (field[counter].checked)
radio_choice = true; 
}

if (!radio_choice)
{
// If there were no selections made display an alert box 
alert("You must select a size of T-Shirt.")
return (false);
}
return (true);
}

function radio_button_checker1(field) {
    // set var radio_choice to false
    var radio_choice = false;

    // Loop from zero to the one minus the number of radio button selections
    for (counter = 0; counter < field.length; counter++) {
        // If a radio button has been selected it will return true
        // (If not it will return false)
        if (field[counter].checked)
            radio_choice = true;
    }

    if (!radio_choice) {
        // If there were no selections made display an alert box 
        alert("You must select How did you hear about this event.")
        return (false);
    }
    return (true);
}
function validateEmail(inputvalue)
{	
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    var status = true;
    
    if(!pattern.test(inputvalue))
    {         
        alert("Not a valid e-mail address!");
        status = false;
    }
    
    return status;
    
}

function isNumeric(input)
{
    return (input - 0) == input && input.length > 0;
}

function validateCheckBox(field,alertText)
{
    with(field)
    {
        if(!checked)
        {
            alert(alertText);
            return false;
        }
        else
        {
            return true;
        }
    }
}

function validateDropDown(field,alertText)
{
    with(field)
    {
        if (selectedIndex == 0)
        {
            alert(alertText);
            return false;
        }
        else
        {
            return true;
        }
    }
}

function validateRequired(field,alertText)
{
    with (field)
    {
        if (value == null || value == "")
        {
            alert(alertText);
            return false;
        }
        else
        {
            return true;
        }
    }
}



function validateForm(thisform) {
    with (thisform) {
        if (!validateCheckBox(rules, "You must read and accept the Event Rules and Regulations")) {
            rules.focus();
            return false;
        }

        if (!validateCheckBox(waiver, "You must read and accept the Event Waiver and Liability Form")) {
            waiver.focus();
            return false;
        }

        if (!validateRequired(FirstName, "First Name must be filled out!")) {
            FirstName.focus();
            return false;
        }

        if (!validateRequired(LastName, "Last name must be filled out!")) {
            LastName.focus();
            return false;
        }
        if (!validateRequired(PostalCode, "Postal code must be filled out!")) {
            PostalCode.focus();
            return false;
        }


        if (!validateDropDown(Gender, "You must select gender!")) {
            Gender.focus();
            return false;
        }


        if (!validatePostalCode(PostalCode.value)) {
            PostalCode.focus();
            return false;
        }

        if (!validateRequired(MainPhone, "Main phone must be filled out!")) {
            MainPhone.focus();
            return false;
        }

        if (!validateRequired(Email1, "Email must be filled out!")) {
            Email1.focus();
            return false;
        }

        if (!validateEmail(Email1.value)) {
            Email1.focus();
            return false;
        }
     
        if (!checkEmail(Email1, Email2)) {
        Email2.focus();
        return false;
    }
    
   if (!radio_button_checker(TShirt)) {
   return false;
   }
if (!radio_button_checker1(How)) {
    return false;
}
    if (!validateDropDown(ShoeDiva, "You must select which of the following is most important to you!")) {
        ShoeDiva.focus();
        return false;
    }
    }
}

       
       
        /*
        if (!validateDropDown(RunningExperience,"You must select Runing Experience!"))
        {
        RunningExperience.focus();
        return false;
        }
        
        if (!validateDropDown(HowOften,"You must select How often do you shop at STYLESENSE!"))
        {
        HowOften.focus();
        return false;
        }
        
        */
  
   
        

/*
if (!validateRequired(Age,"Age must be filled out!"))
{
Age.focus();
return false;
}
        
if(!isNumeric(Age.value))
{
alert("Please enter only numbers in the Age field")
Age.focus();
return false;
}
*/
/*
if (!validateRequired(Email2, "Email must be filled out!")) {
Email2.focus();
return false;
}

if (!validateEmail(Email2.value)) {
Email2.focus();
return false;
}
*/