$(document).ready(function() {
  $(".button").tooltip({tipClass: "popup_tooltip"});
    $(".button").click(function(e) {
	    if ($(e.target).hasClass("button")) {
	      window.location = $(e.target).find("a").attr("href");
	    }
    });

  try {
    $("#school_school_code").change(function(event) {
      get_details($(this).val(), replace_and_clear);
      });

    if ($("#school_school_code").val()) {
      get_details($("#school_school_code").val(), replace_school);
    }
    } catch (e) {}
});


function replace_school(data){
  $(".school_details").html(data);
};

function replace_and_clear(data){
    replace_school(data)
    $("#teacher_school_confirmation").val(["0"]);
    forceRedraw($("#confirmation"));
};

function get_details(school_code, callback){
  $.get("/school/" + school_code + "/details/", callback);
};

function forceRedraw(e) {
    // IE sometimes doesn't update the position of elements when more content
    // is added above them. This function(HACK) fixes that.
    e.hide();
    e.show();
}
