jQuery.ajaxSetup( { 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript"); } } );

function searchField() {
	$('#clear_search_phrase').click( function() {
	  $('#search_phrase').val("");
	});
	$('#commit_search').click( function() {
	  $('#search_form').submit();
	});
}

function hideNotice() {
  $('#hide_notice').click( function () {
    $.cookie("hide_notice", "true");
    $('#student_notice').hide(500);
    return false;
  });
}

function showCurrencies() {
  $('a.show_currencies').mouseover( function () {
    $(this).parent().find('ul.currency_info').slideDown();
    $(this).hide();
  });
}

function showCCV() {
  $('a#ccv-link').click( function () {
    $('#ccv-balloon').fadeIn();
    return false;
  });
}

// $(function(){
//   $('input#code').blur(function(){
//     if($(this).val()){
//       $('#spinner').show();
//       $.get('/promotions/' + $(this).val(), function(data){
//         eval(data);
//         $('#spinner').hide();
//       });
//     } else {
//       $('#main_plans input[type=radio]').attr('disabled','');
//       $('#promo_plan').html('');
//     }
//   })
// });



$(function(){
  $('input#code').change(function(){
    $('input#verify-btn').val("Verify");
    $('#main_plans input[type=radio]').attr('disabled','');
    $('#promo_plan').html('');
  });
  
  $('input#verify-btn').click(function(){
    if($('input#verify-btn').val()=="Verify" && $('input#code').val()){
      $('#spinner').show();
      $.get('/promotions/' + $('input#code').val(), function(data){
        eval(data);
        $('#spinner').hide();
      });
    }
    else {
      $('input#verify-btn').val("Verify");
      $('input#code').val(null);
      $('#main_plans input[type=radio]').attr('disabled','');
      $('#promo_plan').html('');
    }
    return false;
  })
});


$(document).ready( function() {
	searchField();
	hideNotice();
	showCurrencies();
	showCCV();
});

