$(document).ready(function() {
  $("a.lightbox").colorbox();
  $('input.rememberValue').each(function() {
    $(this).data('oldVal', $(this).val());
    $(this).focus(function(){
      if($(this).val()==$(this).data('oldVal')) {
        $(this).val('');
      }
    });
    $(this).blur(function(){
      if($(this).val()=='') {
        $(this).val($(this).data('oldVal'));
      }
    });
  });

  $('#frmSearch').submit(function() {
    if($('#searchKeywords').val()==$('#searchKeywords').data('oldVal') || $('#searchKeywords').val()=='') {
      alert('Please enter something to search.');
      $('#searchKeywords').focus();
    } else {
      window.location = '/search/' + escape($('#searchKeywords').val());
    }
    return false;
  });

  $('#frmNewsletter').submit(function() {
    if($('#newsletterEmail').val()==$('#newsletterEmail').data('oldVal') || $('#newsletterEmail').val()=='') {
      alert('Please enter your email address');
      $('#newsletterEmail').focus();
    } else {
      $('#btnEmail').attr('disabled', 'disabled');
      $.post($(this).attr('action'),
        {'email': $('#newsletterEmail').val()},
        function(response) {
          alert(response.msg);
          $('#newsletterEmail').val('');
          $('#newsletterEmail').focus();
          $('#btnEmail').attr('disabled', '');
        },
        'json'
      );
    }
    return false;
  });

});
