$(function () { var $demoName = $("#demoName"), $demoSurname = $("#demoSurname"), $demoPhone = $("#demoPhone"), $demoEmail = $("#demoEmail"), $btnDemoRegister = $("#btnDemoRegister"), $demoFormContainer = $("#demoFormContainer"), $topMainAccount = $("#topMainAccount"), $body = $("body"), $loadingScreen = $(".loadingScreen"), demoFormError = false, $inlinePopup = $(".inlinePopup"), $inlinePopupTrg = $(".inlinePopupTrg.fancybox"); $demoPhone.mask("(999) 999 99 99"); function ClearDemoForm() { $demoName.val(""); $demoSurname.val(""); $demoPhone.val(""); $demoEmail.val(""); } var demoElements = [$demoName, $demoSurname, $demoPhone, $demoEmail]; $btnDemoRegister.click(function () { for (var i = 0; i < demoElements.length - 1; i++) deleteAfter(demoElements[i]); if ($demoName.val().trim() == "") insertAfter(false, $demoName); if ($demoSurname.val().trim() == "") insertAfter(false, $demoSurname); if ($demoPhone.val().trim() == "") insertAfter(false, $demoPhone); if ($demoEmail.val().trim() == "") insertAfter(false, $demoEmail); if (!(emailValidation($demoEmail.val().trim()))) insertAfter(false, $demoEmail); if ($demoFormContainer.find(".errorElement").size() > 0) return false; $body.addClass("oHidden"); $loadingScreen.fadeIn(); $btnDemoRegister.addClass("disabledBtn"); var dns = $demoName.val().trim() + " " + $demoSurname.val().trim(), dp = $demoPhone.val().trim(), de = $demoEmail.val().trim(), dmt = $topMainAccount.hasClass("blueAccount") ? "0" : "1"; var myData = "{'values':'" + (base64Encode(dns + "|" + dp + "|" + de + "|" + dmt)) + "'}"; $.ajax({ type: "POST", url: "/Connector.aspx/Registration", data: myData, contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { var result = msg.d; if (result.indexOf("error|") > -1) { result = result.replace("error|", ""); $body.removeClass("oHidden"); $loadingScreen.fadeOut("1000", function () { $inlinePopup.html(result); $inlinePopup.fancybox({ autoSize: true, openEffect: 'fade', closeEffect: 'fade' }); $inlinePopup.trigger("click"); $btnDemoRegister.removeClass("disabledBtn"); }); } else if (result.indexOf("update|") > -1) { result = result.replace("update|", ""); $body.removeClass("oHidden"); $loadingScreen.fadeOut("1000", function () { $inlinePopup.html(result); $inlinePopup.fancybox({ autoSize: true, openEffect: 'fade', closeEffect: 'fade' }); $inlinePopup.trigger("click"); $btnDemoRegister.removeClass("disabledBtn"); ClearDemoForm(); }); } else if (result.indexOf("success|") > -1) { result = result.replace("success|", ""); window.location = result; } }, error: function (xhr, status, error) { $loadingScreen.fadeOut("1000", function () { $inlinePopup.html(error); $inlinePopup.fancybox({ autoSize: true, openEffect: 'fade', closeEffect: 'fade' }); $inlinePopup.trigger("click"); $btnDemoRegister.removeClass("disabledBtn"); }); } }); }); $demoName.keyup(function () { if ($demoName.val().trim() == "" | $demoName.val().trim().length < 2) insertAfter(false, $demoName); else insertAfter(true, $demoName); }); $demoSurname.keyup(function () { if ($demoSurname.val().trim() == "" | $demoSurname.val().trim().length < 2) insertAfter(false, $demoSurname); else insertAfter(true, $demoSurname); }); $demoPhone.focus(function () { $(this).select(); }); $demoEmail.keyup(function () { if ($demoEmail.val().trim() == "") insertAfter(false, $demoEmail); else if (!(emailValidation($demoEmail.val().trim()))) insertAfter(false, $demoEmail); else insertAfter(true, $demoEmail); }); $demoName.focusout(function () { $demoName.val($demoName.val().trim()); }); $demoSurname.focusout(function () { $demoSurname.val($demoSurname.val().trim()); }); $demoEmail.focusout(function () { $demoEmail.val($demoEmail.val().trim()); }); });