function validateInput() {
  var email_pattern = /^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/i;

  if($('input[name=full_name]').val() == '') {
    $('input[name=full_name]').focus();
    alert(error_name);
    return false;
  } else if($('input[name=email]').val() == '') {
    $('input[name=email]').focus();
    alert(error_email);
    return false;
  } else if(!$('input[name=email]').val().match(email_pattern)) {
    $('input[name=email]').focus();
    alert(error_email_pattern);
    return false;
  } else if($('input[name=phone]').val() == '') {
    $('input[name=phone]').focus();
    alert(error_phone);
    return false;
  } else if($('textarea[name=question]').val() == '') {
    $('textarea[name=question]').focus();
    alert(error_question);
    return false;
  } else if($('input[name=captcha_code]').val() == '') {
    $('input[name=captcha_code]').focus();
    alert(error_captcha);
    return false;
  }

  $('#inquiry_form').submit();
  return true;
}

$(function() {

  // promotions carousel
  $("#carousel").featureCarousel();

  // centers list
  /*var active_center = 0;
  $('div.list-content').children('h2').click(function() {
    var parent = $(this).parent('div');
    var id = parent.attr('id').replace('center_', '');
    if(active_center == id) {
      parent.children('div.content').hide();
      parent.children('div.arrow').removeClass('active');
      
      active_center = 0;
      return false;
    }

    var active_div = $('div#center_' + active_center);
    active_div.children('div.content').hide();
    active_div.children('div.arrow').removeClass('active');

    parent.children('div.content').show();
    parent.children('div.arrow').addClass('active');

    active_center = id;
    return false;
  });
  */

  // news and events tabs
  $('div[id$=_tab]').click(function() {
    var id = $(this).attr('id');

    $('div[id$=_tab]').each(function() {
      if($(this).attr('id') == id) {
        $(this).attr('class', 'tpic-active');
        $('div#' + $(this).attr('id').replace('tab', 'box')).show();
      } else {
        $(this).attr('class', 'tpic');
        $('div#' + $(this).attr('id').replace('tab', 'box')).hide();
      }
    });
  });
  
  // reload CAPTCHA
  $('#captcha_reload').click(function() {
    $('#captcha').attr('src', live_site + '/includes/captcha/securimage_show.php?' + Math.random());
    return false;
  });

  $('#submit_button').click(function() {
    validateInput();
  });

  $('#reset_button').click(function() {
    $(':input','#inquiry_form')
     .not(':button, :submit, :reset, :hidden')
     .val('')
     .removeAttr('checked')
     .removeAttr('selected');
  });

  if($('div.success').length) {
    setTimeout("$('div.success').remove();", 5000);
  }

})
