//
// This is the javascript validation for the Getting Started form. If all of the validation
// passes then the form is posted using AJAX (not the normal form POST). The response is then
// processed and we either show a <DIV> that has the confirmation message or we display a
// javascript alert popup with the error message returned from the PHP script.
//
function validate_getting_started_form() {
  //Form validation
  var bError = false;
  if ($j('#start_name').val() == '') { addError('start_name'); bError = true; } else { removeErrorClass('start_name'); }
  if ($j('#start_town_state').val() == '') { addError('start_town_state'); bError = true; } else { removeErrorClass('start_town_state'); }
  var sEmail = $j('#start_email').val();
  if (sEmail == '' || !sEmail.match(/^\b[A-Z0-9._%+-]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,4}\b$/i)) { addError('start_email'); bError = true; } else { removeErrorClass('start_email'); }
  if ($j('#start_phone').val() == '') { addError('start_phone'); bError = true; } else { removeErrorClass('start_phone'); }
  if ($j('#start_age').val() == '') { addError('start_age'); bError = true; } else { removeErrorClass('start_age'); }
  if ($j('#start_life_stage').val() == '') { addError('start_life_stage'); bError = true; } else { removeErrorClass('start_life_stage'); }
  if ($j('#start_occupation').val() == '') { addError('start_occupation'); bError = true; } else { removeErrorClass('start_occupation'); }
//  if ($j('#start_transition').val() == '') { addError('start_transition'); bError = true; } else { removeErrorClass('start_transition'); }
  if ($j('#start_contact_time').val() == '') { addError('start_contact_time'); bError = true; } else { removeErrorClass('start_contact_time'); }
  if ($j('#start_info').val() == '') { addError('start_info'); bError = true; } else { removeErrorClass('start_info'); }

  if ($j('#start_security_code').val() == '') { addError('start_security_code'); bError = true; } else { removeErrorClass('start_security_code'); }

  if (bError == true) {
    alert ("Please correct the highlighted fields.");
    return false;
  }
  else {
    return true;
  }
}

function removeErrorClass(control_id) {
  $j('#'+control_id).parent().removeClass('error');
  return true;
}

function addError(control_id) {
  $j('#'+control_id).select().focus();
  $j('#'+control_id).parent().addClass('error');
  return true;
}