window.onload = function () {
    var el_email   = document.getElementById('email');
    var el_signup  = document.getElementById('signup');
    var el_success = document.getElementById('success');

    var ws = new WebSocket('wss://blue.binaryws.com/websockets/v3?app_id=1&l=' + (getParamValue(window.top.location.href, 'lang') || 'en'));

    function sendVerifyEmail() {
        ws.send(JSON.stringify({
            verify_email: el_email.value,
            type        : 'account_opening'
        }));
    }

    document.getElementById('frm_verify_email').addEventListener('submit', function (evt) {
        evt.preventDefault();

        if (ws.readyState === 1) {
            sendVerifyEmail();
        } else {
            ws.onopen = function() {
                sendVerifyEmail()
            };
        }
    });

    ws.onmessage = function(msg) {
        var data = JSON.parse(msg.data);
        if (data.error) {
            el_email.classList.add('error-field');
        } else {
            el_email.classList.remove('error-field');
            el_signup.classList.add('invisible');
            el_success.classList.remove('invisible');
        }
    };

    // Store gclid
    var gclid = getParamValue(window.top.location.href, 'gclid');
    if (gclid) {
        localStorage.setItem('gclid', gclid);
    }
};

function getParamValue(url, key) {
    var regex   = new RegExp('[?&]' + key + '(=([^&#]*)|&|#|$)');
    var results = regex.exec(url);
    if (!results || !results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

@@ -1,12 +1,46 @@
+var error_class = 'error-field';%0A%0A
 window.onloa
@@ -540,16 +540,88 @@
 %0A    %7D%0A%0A
+    var validation_set = false; // To prevent validating before submit%0A%0A
     docu
@@ -731,24 +731,529 @@
 Default();%0A%0A
+        if (!validateEmail(el_email.value)) %7B%0A            if (!validation_set) %7B%0A                %5B'input', 'change'%5D.forEach(function (evt) %7B%0A                    el_email.addEventListener(evt, function () %7B%0A                        setValidationStyle(el_email, !validateEmail(el_email.value));%0A                    %7D);%0A                %7D);%0A                setValidationStyle(el_email, !validateEmail(el_email.value));%0A                validation_set = true;%0A            %7D%0A            return false;%0A        %7D%0A%0A
         if (
@@ -1565,29 +1565,27 @@
 ist.add(
-'
 error
--field'
+_class
 );%0A     
@@ -1634,29 +1634,27 @@
 .remove(
-'
 error
--field'
+_class
 );%0A     
@@ -1928,16 +1928,246 @@
   %7D%0A%7D;%0A%0A
+function validateEmail(email) %7B%0A    return /%5E%5Ba-zA-Z0-9_.+-%5D+@%5Ba-zA-Z0-9.-%5D+%5C.%5Ba-zA-Z%5D%7B2,63%7D$/.test(email);%0A%7D%0A%0Afunction setValidationStyle(element, has_error) %7B%0A    element.classList%5Bhas_error ? 'add' : 'remove'%5D(error_class);%0A%7D%0A%0A
 function

Validate the email address