// JavaScript Document
$(document).ready(function() {
    $(".register-form").submit(function(e) {
         e.preventDefault();
        var name = $(".name");
        var email = $(".email");
        var ticket = $(".get_ticket");
        var flag = false;
        if (name.val() == "") {
            name.closest(".form-control").addClass("error");
            name.focus();
            flag = false;
            return false;
        } else {
            name.closest(".form-control").removeClass("error").addClass("success");
        } if (email.val() == "") {
            email.closest(".form-control").addClass("error");
            email.focus();
            flag = false;
            return false;
        } else {
            email.closest(".form-control").removeClass("error").addClass("success");
        } if (ticket.val() == "") {
            ticket.closest(".control-group").addClass("error");
            ticket.focus();
            flag = false;
            return false;
        } else {
            ticket.closest(".control-group").removeClass("error").addClass("success");
            flag = true;
        }
        var dataString = "name=" + name.val() + "&email=" + email.val() + "&ticket=" + ticket.val();
        $(".loading").fadeIn("slow").html("Loading...");
        $.ajax({
            type: "POST",
            data: dataString,
            url: "php/register.php",
            cache: false,
            success: function (d) {
                $(".form-control").removeClass("success");
             if(d == 'success') // Message Sent? Show the 'Thank You' message and hide the form
 $('.loading').fadeIn('slow').html('<font color="#28db5a">Mail sent Successfully.</font>').delay(3000).fadeOut('slow');

     else
     $('.loading').fadeIn('slow').html('<font color="#fe4918">Mail not sent.</font>').delay(3000).fadeOut('slow');

            }
        });
        return false;
    });
    $("#reset").click(function () {
        $(".form-control").removeClass("success").removeClass("error");
    });
})


