function validateEmail(address)
{
  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  if(reg.test(address) == false)
    return false;
  return true;
}

function validatePhone(phone)
{
  var reg = /^[2-9]\d{2}-\d{3}-\d{4}$/;
  if(reg.test(phone) == false)
    return false;
  return true;
}

function checkCompForm()
{
  if(document.getElementById('contact_first_name').value == '')
  {
    alert('Please enter your first name.');
    document.getElementById('contact_first_name').select();
    return false;
  }
  if(document.getElementById('contact_last_name').value == '')
  {
    alert('Please enter your last name.');
    document.getElementById('contact_last_name').select();
    return false;
  }
  if(document.getElementById('contact_address').value == '')
  {
    alert('Please enter your address.');
    document.getElementById('contact_address').select();
    return false;
  }
  if(document.getElementById('contact_city').value == '')
  {
    alert('Please enter your city.');
    document.getElementById('contact_city').select();
    return false;
  }
  if(document.getElementById('contact_state').value == '')
  {
    alert('Please choose your state.');
    return false;
  }
  if(document.getElementById('contact_zip').value == '')
  {
    alert('Please enter your zip.');
    document.getElementById('contact_zip').select();
    return false;
  }
  if(document.getElementById('email_address').value == '')
  {
    alert('Please enter your email address.  If you don\'t have an email address, type "N/A"');
    document.getElementById('email_address').select();
    return false;
  }
  if(document.getElementById('phone_number').value == '')
  {
    alert('Please enter your phone number.');
    document.getElementById('phone_number').select();
    return false;
  }
  if(document.getElementById('contact_date_of_birth').value == '')
  {
    alert('Please enter your date of birth (mm/dd/yyyy).');
    document.getElementById('contact_date_of_birth').select();
    return false;
  }
  return true;
}

function checkGasForm()
{
  if(document.getElementById('first_name').value == '')
  {
    alert('Please enter your first name.');
    document.getElementById('first_name').select();
    return false;
  }
  if(document.getElementById('last_name').value == '')
  {
    alert('Please enter your last name.');
    document.getElementById('last_name').select();
    return false;
  }
  if(document.getElementById('address').value == '')
  {
    alert('Please enter your address.');
    document.getElementById('address').select();
    return false;
  }
  if(document.getElementById('city').value == '')
  {
    alert('Please enter your city.');
    document.getElementById('city').select();
    return false;
  }
  if(document.getElementById('state').value == '')
  {
    alert('Please choose your state.');
    return false;
  }
  if(document.getElementById('zip_code').value == '')
  {
    alert('Please enter your zip code.');
    document.getElementById('zip_code').select();
    return false;
  }
  if(validateEmail(document.getElementById('email_address').value) == false)
  {
    alert('Please enter a valid Email Address (ex. address@domain.com).');
    document.getElementById('email_address').select();
    return false;
  }
  if(validatePhone(document.getElementById('phone_number').value) == false)
  {
    alert('Please enter a valid Phone Number (ex. 555-555-5555).');
    document.getElementById('phone_number').select();
    return false;
  }
  if(!(document.getElementById('terms-conditions').checked))
  {
    alert('Please agree to the Terms & Conditions before entering the contest.');
    return false;
  }
  return true;
}

function checkCourseStep1()
{
  if(document.getElementById('contact_school').value == '')
  {
    alert('Please choose a school.');
    return false;
  }
  if(validateEmail(document.getElementById('email_address').value) == false)
  {
    alert('Please enter a valid Email Address (ex. address@domain.com).');
    document.getElementById('email_address').select();
    return false;
  }
  if(!(document.getElementById('valid-age').checked))
  {
    alert('Please confirm that you own a New York State Learner\'s Permit.');
    return false;
  }
  return true;
}

function checkCourseSignUp()
{
  if(document.getElementById('contact_first_name').value == '')
  {
    alert('Please enter your first name.');
    document.getElementById('contact_first_name').select();
    return false;
  }
  if(document.getElementById('contact_last_name').value == '')
  {
    alert('Please enter your last name.');
    document.getElementById('contact_last_name').select();
    return false;
  }
  if(document.getElementById('contact_address').value == '')
  {
    alert('Please enter your address.');
    document.getElementById('contact_address').select();
    return false;
  }
  if(document.getElementById('contact_city').value == '')
  {
    alert('Please enter your city.');
    document.getElementById('contact_city').select();
    return false;
  }
  if(document.getElementById('contact_state').value == '')
  {
    alert('Please choose your state.');
    return false;
  }
  if(document.getElementById('contact_zip_code').value == '')
  {
    alert('Please enter your zip code.');
    document.getElementById('contact_zip_code').select();
    return false;
  }
  if(validateEmail(document.getElementById('email_address').value) == false)
  {
    alert('Please enter a valid Email Address (ex. address@domain.com).');
    document.getElementById('email_address').select();
    return false;
  }
  if(validatePhone(document.getElementById('phone_number').value) == false)
  {
    alert('Please enter a valid Phone Number (ex. 555-555-5555).');
    document.getElementById('phone_number').select();
    return false;
  }
  return true;
}

function checkCourseTest()
{
  if(document.getElementById('tq_1-1').checked == false)
  {
    alert('Question #1 is incorrect, please try again.');
    return false;
  }
  if(document.getElementById('tq_2-0').checked == false)
  {
    alert('Question #2 is incorrect, please try again.');
    return false;
  }
  if(document.getElementById('tq_3-1').checked == false)
  {
    alert('Question #3 is incorrect, please try again.');
    return false;
  }
  if(document.getElementById('tq_4-3').checked == false)
  {
    alert('Question #4 is incorrect, please try again.');
    return false;
  }
  if(document.getElementById('tq_5-0').checked == false)
  {
    alert('Question #5 is incorrect, please try again.');
    return false;
  }
  var confirm_text = "Congratulations, you have successfully answered all questions correctly.\n\nBy clicking \"OK\", your registration will be complete and you will receive an email reminder with all course details.\n\nThank you for signing up!";
  return confirm(confirm_text);
}

// To switch the thumbnail on the Google Checkout Page
function updateThumb(selected_option, img_div, item)
{
  var the_div = document.getElementById(img_div);
  the_div.innerHTML = '<img src="/images/' + item + 's/' + item + '_' + selected_option.className + '.jpg" alt="Martin, Harding, &amp; Mazzotti ' + item + '" />';
}
