jQuery(document).ready(function ($) {
    "use strict";
    
    
    if ($('.xs-faq').length > 0) {
        var container = $('.xs-faq').parent('.sec-content');
        var html = container.html();
        container.html('<div class="section clearfix xs-section bottom-margin"><article class="row"><div class="clearfix" >' + html + '</div></article></div>');
    }
    
    
    $('#commentform input#submit').addClass('btn btn-default');
    if ($('#register').length > 0) {
        /*
         var selectHTML = '';
         var data;
         if($('.price-data-json').length > 0){
         $( ".price-data-json" ).each(function( ) {
         data = jQuery.parseJSON($(this).attr('data-xsjson'));
         selectHTML += '<option value="'+data.price+'">'+data.name+'</option>';
         });
         
         $('.dynamic-price-select').html('<div class="form-row"><select name="package" class="form-control xsss"><option value="none">Select Package</option>'+selectHTML+'</select></div>');
         
         }
         */
//        $('.priceBox .btn').click(function (e) {
//            e.preventDefault();
//
//            var jsonDiv = $(this).parent().find('.price-data-json').attr('data-xsjson');
//            var data = jQuery.parseJSON(jsonDiv);
//            if (!$('#register').is(':visible')) {
//                $(".register-trigger").trigger("click");
//            }
//            /*
//             $('.xsss option').prop('selected', false)
//             .filter('[value="'+data.price+'"]')
//             .prop('selected', true);
//             */
//            $("html, body").scrollTop(0);
//        });

    }


// Register Form
    $("#register input, #register textarea").focus(function () {
        $(this).prev("label").hide();
        $(this).prev().prev("label").hide();
    });

    $("#register").submit(function () {
        $("#register").children().removeClass('has-error');
        var url = $(this).attr('data-ajaxURL');
        var postdata = $(this).serialize();
        // validate and process form here
        var name = $("#name").val();
        if (name == "") {
            $('#name').addClass('reqfld').parent().addClass('has-error');
            $('<span class="error" style="display:none; margin-top:0px; color:#cc0000"><i class="fa fa-exclamation-circle"></i></span>').insertBefore('#name').fadeIn(400);
            $("#name").focus(function () {
                $('#name').removeClass('reqfld');
                $(this).prev().fadeOut(400);
            });
            return false;
        }

        var phone = $("#phone").val();
        if (phone == "") {
            $('#phone').addClass('reqfld').parent().addClass('has-error');
            $('<span class="error" style="display:none; color:#cc0000"><i class="fa fa-exclamation-circle"></i></span>').insertBefore('#phone').fadeIn(400);
            $("#phone").focus(function () {
                $('#phone').removeClass('reqfld');
                $(this).prev().fadeOut(400);
            });
            return false;
        }

        var email = $("#email").val();
        if (email == "") {
            $('#email').addClass('reqfld');
            $('<span class="error" style="display:none; color:#cc0000"><i class="fa fa-exclamation-circle"></i></span>').insertBefore('#email').fadeIn(400);
            $("#email").focus(function () {
                $('#email').removeClass('reqfld');
                $(this).prev().fadeOut(400);
            });
            return false;
        } else if (email.indexOf('@') == -1 || email.indexOf('.') == -1) {
            $('#email').addClass('reqfld').parent().addClass('has-error');
            $('<span class="error" style="display:none;  color:#cc0000">Invalid!</span>').insertBefore('#email').fadeIn(400);
            $("#email").focus(function () {
                $('#email').removeClass('reqfld');
                $(this).prev().fadeOut(400);
            });
            return false;
        }

        var comment = $("#comment").val();
        /*
         var pkg = $(".xsss").val();
         if (pkg == "none") {
         $('.xsss').parent().addClass('has-error');
         }
         */
        $.post(url, postdata, function (json) {
            json = jQuery.parseJSON(json);
            if (json.result == 'success') {
                $("#register").animate({opacity: '1'}, 500);
                $('.loader').hide();
                $("<div id='success' class='alert alert-success' style='border:#" + successBox_Border_Color + " 1px " + successBoxBorderStyle + "; background:#" + successBoxColor + ";' ></div>").insertAfter('.field-wrapper');
                $('.field-wrapper').slideUp(300);
                $('#success').html("<h5 style='color:#" + textColor + ";'>" + submitMessage + "</h5><p style='color:#" + textColor + ";'>" + successParagraph + "</p>")
                        .hide().delay(300)
                        .fadeIn(1500);

                $('#register').delay(6000).slideUp('fast');
            }
        });
        return false;
    });

});