var error_msg_1574 = ""; function validate_email_1574(mail) { if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)) { return (true); } error_msg_1574 = "Имэйл хаягаа зөв оруулна уу"; return (false); } function getCookie_1574(cname) { var name_1574 = cname + "="; var decodedCookie_1574 = decodeURIComponent(document.cookie); var ca_1574 = decodedCookie_1574.split(';'); for(var i = 0; i < ca_1574.length; i++) { var c_1574 = ca_1574[i]; while (c_1574.charAt(0) == ' ') { c_1574 = c_1574.substring(1); } if (c_1574.indexOf(name_1574) == 0) { return c_1574.substring(name_1574.length, c_1574.length); } } return ""; } function subscribe_submit_1574(){ var form_1574 = document.querySelector('#subscribe-form-1574'); var data_1574 = new FormData(form_1574); var url_1574 = "/api.php/subscription/save?site_id=1062&id=1574" + '&cookie_id=' + getCookie_1574("cookie_id") + '&short_cookie_id=' + getCookie_1574("short_cookie_id"); var xhr_1574 = new XMLHttpRequest(); if (window.XMLHttpRequest) { // Mozilla, Safari, ... var xhr_1574 = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE var xhr_1574 = new ActiveXObject("Microsoft.XMLHTTP"); } xhr_1574.open('POST', url_1574, true); xhr_1574.onload = function () { /* do something to response */ console.log(this.responseText); document.getElementById("subscription-form-container-1574").innerHTML = this.responseText; }; var valid_1574 = 1; if(form_1574.querySelector('input[name="subscriber[name]"]')){ if(form_1574.querySelector('input[name="subscriber[name]"]').value.trim().length > 0){ }else{ valid_1574 = 0; form_1574.querySelector('input[name="subscriber[name]"]').setAttribute("style", "border-color: red;"); } } if(form_1574.querySelector('input[name="subscriber[email]"]')){ if(form_1574.querySelector('input[name="subscriber[email]"]').value.trim().length > 0){ }else{ valid_1574 = 0; form_1574.querySelector('input[name="subscriber[email]"]').setAttribute("style", "border-color: red;"); } } if(form_1574.querySelector('input[name="subscriber[phone]"]')){ if(form_1574.querySelector('input[name="subscriber[phone]"]').value.trim().length > 0){ }else{ valid_1574 = 0; form_1574.querySelector('input[name="subscriber[phone]"]').setAttribute("style", "border-color: red;"); } } if(form_1574.querySelector('input[name="subscription[company_name]"]')){ if(form_1574.querySelector('input[name="subscription[company_name]"]').value.trim().length > 0){ }else{ valid_1574 = 0; form_1574.querySelector('input[name="subscription[company_name]"]').setAttribute("style", "border-color: red;"); } } if(form_1574.querySelector('input[name="subscription[company_position]"]')){ if(form_1574.querySelector('input[name="subscription[company_position]"]').value.trim().length > 0){ }else{ valid_1574 = 0; form_1574.querySelector('input[name="subscription[company_position]"]').setAttribute("style", "border-color: red;"); } } if(form_1574.querySelector('input[name="subscription[title]"]')){ if(form_1574.querySelector('input[name="subscription[title]"]').value.trim().length > 0){ }else{ valid_1574 = 0; form_1574.querySelector('input[name="subscription[title]"]').setAttribute("style", "border-color: red;"); } } if(form_1574.querySelector('textarea[name="subscription[body]"]')){ if(form_1574.querySelector('textarea[name="subscription[body]"]').value.trim().length > 0){ }else{ valid_1574 = 0; form_1574.querySelector('textarea[name="subscription[body]"]').setAttribute("style", "border-color: red;"); } } if(valid_1574 == 0){ error_msg_1574 = "Талбаруудыг бүрэн бөглөнө үү!"; } if(!validate_email_1574(form_1574.querySelector('input[name="subscriber[email]"]').value)){ form_1574.querySelector('input[name="subscriber[email]"]').style="border-color: red;"; valid_1574 = 0; }else{ } if(valid_1574){ document.querySelector('#subscribe-form-1574').style.display = "none"; document.querySelector('#subscription-form-loading-1574').style.display = "inline"; xhr_1574.send(data_1574); }else{ alert(error_msg_1574); } } // function postRequest_1574(strURL) { var xmlHttp_1574; if (window.XMLHttpRequest) { // Mozilla, Safari, ... var xmlHttp_1574 = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE var xmlHttp_1574 = new ActiveXObject("Microsoft.XMLHTTP"); } xmlHttp_1574.open('POST', strURL, true); xmlHttp_1574.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttp_1574.onreadystatechange = function() { if (xmlHttp_1574.readyState == 4) { updatepage_1574(xmlHttp_1574.responseText); } } xmlHttp_1574.send(strURL); } // function updatepage_1574(str){ document.getElementById("subscription-form-container-1574").innerHTML = str; } //'//naadbrand.com' + var get_url_1574 = '/api.php/subscription/renderform?site_id=1062' + '&id=1574' + '' ; postRequest_1574(get_url_1574);