(function () { "use strict"; var Dostep = { initialized: false, initialize: function () { if (this.initialized) return; this.initialized = true; this.build(); this.events(); }, build: function () { var zglform = $("#dostepForm"); // Validations Form Type if (zglform.get(0)) { this.basicValidations(); } }, events: function () { $('video').on('play', function (e) { if (e.target.currentTime == 0){ var token = $(".restricted-area #restr_token").val(); var a_id = $(".restricted-area #restr_a_id").val(); var email = $(".restricted-area #restr_email").val(); var movie = $(this).find('source').attr("src"); $.get( "obejrzyj_film", { 'a_id': a_id, 'token': token, 'email': email, 'movie': movie } ); } }); $('#collapseObowiazek').on('shown.bs.collapse', function () { $('.obowiazekText a.btn').html('Zwiń tekst'); }).on('hidden.bs.collapse', function () { $('.obowiazekText a.btn').html('Czytaj więcej'); }); }, basicValidations: function () { var zglform = $("#dostepForm"), url = zglform.attr("action"); zglform.validate({ submitHandler: function (zglform) { // Loading State var submitButton = $(this.submitButton); submitButton.button("loading"); if ($("#dostepForm #zgoda_handlowa").is(':checked')){ var zgoda2 = 1; } else{ var zgoda2 = 0; } // Ajax Submit $.ajax({ type: "POST", url: url, data: { "id": $("#dostepForm #a_id").val(), "email": $("#dostepForm #email").val(), "name": $("#dostepForm #name").val(), "tel": $("#dostepForm #tel").val(), "firma": $("#dostepForm #firma").val(), "zgoda1": $("#dostepForm #zgoda").val(), "zgoda2": zgoda2 }, dataType: "json", success: function (data) { if (data.response == "success") { $("#FormSuccess").removeClass("hidden"); $("#FormError").addClass("hidden"); // Reset Form $("#dostepForm .form-control") .val("") .blur() .parent() .removeClass("has-success") .removeClass("has-error") .find("label.error") .remove(); if (($("#FormSuccess").position().top - 80) < $(window).scrollTop()) { $("html, body").animate({ scrollTop: $("#FormSuccess").offset().top - 80 }, 300); } } else { $("#FormError").removeClass("hidden"); $("#FormSuccess").addClass("hidden"); if (($("#FormError").position().top - 80) < $(window).scrollTop()) { $("html, body").animate({ scrollTop: $("#FormError").offset().top - 80 }, 300); } } }, complete: function () { submitButton.button("reset"); } }); }, highlight: function (element) { $(element) .parent() .removeClass("has-success") .addClass("has-error"); }, success: function (element) { $(element) .parent() .removeClass("has-error") .addClass("has-success") .find("label.error") .remove(); } }); } }; Dostep.initialize(); })();