$(document).ready(function () {

  $(".saveProperty").live('click', function() {
    if (!is_logged_in()) { return false; }
    var property_id = $(this).attr('rel');
    
    $.post("/process/save_property/",
    {
      op: 'save',
      property_id : property_id
    },
    function(data){
      $('#not_saved_' + property_id).hide();
      $('#saved_' + property_id).show();
      return;
    },
      "text"
    );
    return false;
  });

  $(".unSaveProperty").live('click', function() {
    if (!is_logged_in()) { return false; }
    var property_id = $(this).attr('rel');

    $.post("/process/save_property/",
    {
      op: 'delete',
      property_id : property_id
    },
    function(data){
      $('#not_saved_' + property_id).show();
      $('#saved_' + property_id).hide();
      return;
    },
      "text"
    );
    return false;
  });
});

function is_logged_in() {
  if(!state_machine.get_is_authenticated()) {
    msg_box.set_width(300);
    msg_box.set_title("You must register.");
    msg_box.set_content("You must <a class='dialogLink' href='/accounts/register/'>Register</a> to save searches or apartments!");
    msg_box.open_message_box();
    return false;
  }
  return true;
}
