/**
 * This javascript file handles the AJAX signup functionality.
 */

$(document).ready(function() {
    $("#djschedule_signup_form").submit(function() {
        $.post("/schedule/signup/", 
               { date: $(".djschedule_slot:checked").val(), 
                 name: $("#djschedule_name").val(),
                 email: $("#djschedule_email").val(),
                 phone: $("#djschedule_phone").val(),
                 carrier: $(".djschedule_carrier_option:selected").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");
                       });
                       $(".djschedule_slot:checked").attr("checked", false);
                   } 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;
    });
});
