/**
 * Created by Tejas on 12/03/2017.
 */

$(function () {
    var hab = hab || {};
    hab = function(){
        return {
            sendEnq:function(form){
                var url = "frm_subscribe.php";
                var form_data = $(form).serializeArray();
                console.log(form_data);
                form_data.push({name:"submit",value:"submit"});
                $.ajax({
                    type: "POST",
                    url: url,
                    data: form_data,
                    dataType: "text",
                    success: function(data)
                    {
                        //console.log("ajax reply" + data);
                        if(data=='success') {
                            $(".msg_box").html('<i class="fa fa-check color-green"></i> <strong>Thank you!! <br> We have added you to our mailing list. </strong>').css("display", "block").attr('class', 'animated fadeInDown');
                            $(form).css("display","none");
                        }else if(data=='used') {
                            $(".msg_box").html('<i class="fa fa-exclamation-triangle color-yellow"></i> <strong>This email id is already used.</strong>').css("display", "block").attr('class', 'animated fadeInDown');
                        }else{
                            $(".msg_box").html('<i class="fa fa-exclamation-triangle color-yellow"></i> <strong>Please try again.</strong>').css("display", "block").attr('class', 'animated fadeInDown');
                        }

                    }
                });
            }
        }
    }
    var b = new hab;
//Be sure to check the verification e-mail we have sent you.
    $("#reg_form").submit(function(e){
        var disp = $(".msg_box").css('display');
        if(disp ==="block"){
            $("#success_msg").attr('class', 'animated fadeOutDown');
        }
        b.sendEnq('#reg_form');
        e.preventDefault();
    });

    $("#pop_form").submit(function(e){
        var disp = $(".msg_box").css('display');
        if(disp ==="block"){
            $("#success_msg_pop").attr('class', 'animated fadeOutDown');
        }
        b.sendEnq('#pop_form');
        e.preventDefault();
    });
});