/**
 * This javascript file handles the AJAX link submit functionality.
 */

$(document).ready(function() {
    $("#links_submit_form").submit(function() {
        $.post("/links/submit/", 
               { title: $("#links_title").val(), 
                 description: $("#links_description").val(),
                 url: $("#links_url").val()
               },
               function(response) {
                   if (response.status == 0) {
                       show_message(response.data);
                       $("input.with-instructions").attr("value", function() {
                            $(this).css("color", instruction_color);
                            return $(this).attr("title");
                       });
                   } else {
                       show_error(response.data);
                       $("input.with-instructions").attr("value", function() {
                            if ($(this).val() == '') {
                                $(this).css("color", instruction_color);
                                return $(this).attr("title");
                            }
                       });
                   }
        }, "json");
        
        return false;
    });
});