/* Common Beertraq functions */

function none() {}

function do_login() {
  // If the user isn't using HTTPS, have them login the old way
  var url = window.location.toString()
  if (url.indexOf("https://") == -1) {
    window.location = "https://{{server_name}}/accounts/login/";
  } else {
    $('#loginDialog').dialog('open');
  }
}
    
function add_beer() {
  $.post("/api/beer/drank/", {
    beer: $("#beer_id").val(), 
    comments: $("#comments").val()}, 
    function(data) {
      if (data == "success") {
        // Do we really want to redirect the user, or just congratulate them?
        //location = "/beer/";
          
        $("#addDrankBeerDialog").dialog('close');
        alert("We've added that beer to your list of drank beers.");
      } else {
        $("#errormsg").text(data).show();
      }        
  });
}
    
function open_drank_beer_dialog(beer_id) {
  $("#comments").val("");
  $("#beer_id").val(beer_id);
  $("#addDrankBeerDialog").dialog('open');
}
