var error_msg_439 = ""; function validate_email_439(mail) { if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)) { return (true); } error_msg_439 = "Имэйл хаягаа зөв оруулна уу"; return (false); } function getCookie_439(cname) { var name_439 = cname + "="; var decodedCookie_439 = decodeURIComponent(document.cookie); var ca_439 = decodedCookie_439.split(';'); for(var i = 0; i < ca_439.length; i++) { var c_439 = ca_439[i]; while (c_439.charAt(0) == ' ') { c_439 = c_439.substring(1); } if (c_439.indexOf(name_439) == 0) { return c_439.substring(name_439.length, c_439.length); } } return ""; } function subscribe_submit_439(){ var form_439 = document.querySelector('#subscribe-form-439'); var data_439 = new FormData(form_439); var url_439 = "/api.php/subscription/save?site_id=512&id=439" + '&cookie_id=' + getCookie_439("cookie_id") + '&short_cookie_id=' + getCookie_439("short_cookie_id"); var xhr_439 = new XMLHttpRequest(); if (window.XMLHttpRequest) { // Mozilla, Safari, ... var xhr_439 = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE var xhr_439 = new ActiveXObject("Microsoft.XMLHTTP"); } xhr_439.open('POST', url_439, true); xhr_439.onload = function () { /* do something to response */ console.log(this.responseText); document.getElementById("subscription-form-container-439").innerHTML = this.responseText; }; var valid_439 = 1; if(form_439.querySelector('input[name="subscriber[name]"]')){ if(form_439.querySelector('input[name="subscriber[name]"]').value.trim().length > 0){ }else{ valid_439 = 0; form_439.querySelector('input[name="subscriber[name]"]').setAttribute("style", "border-color: red;"); } } if(form_439.querySelector('input[name="subscriber[email]"]')){ if(form_439.querySelector('input[name="subscriber[email]"]').value.trim().length > 0){ }else{ valid_439 = 0; form_439.querySelector('input[name="subscriber[email]"]').setAttribute("style", "border-color: red;"); } } if(form_439.querySelector('input[name="subscriber[phone]"]')){ if(form_439.querySelector('input[name="subscriber[phone]"]').value.trim().length > 0){ }else{ valid_439 = 0; form_439.querySelector('input[name="subscriber[phone]"]').setAttribute("style", "border-color: red;"); } } if(form_439.querySelector('input[name="subscription[company_name]"]')){ if(form_439.querySelector('input[name="subscription[company_name]"]').value.trim().length > 0){ }else{ valid_439 = 0; form_439.querySelector('input[name="subscription[company_name]"]').setAttribute("style", "border-color: red;"); } } if(form_439.querySelector('input[name="subscription[company_position]"]')){ if(form_439.querySelector('input[name="subscription[company_position]"]').value.trim().length > 0){ }else{ valid_439 = 0; form_439.querySelector('input[name="subscription[company_position]"]').setAttribute("style", "border-color: red;"); } } if(form_439.querySelector('input[name="subscription[title]"]')){ if(form_439.querySelector('input[name="subscription[title]"]').value.trim().length > 0){ }else{ valid_439 = 0; form_439.querySelector('input[name="subscription[title]"]').setAttribute("style", "border-color: red;"); } } if(form_439.querySelector('textarea[name="subscription[body]"]')){ if(form_439.querySelector('textarea[name="subscription[body]"]').value.trim().length > 0){ }else{ valid_439 = 0; form_439.querySelector('textarea[name="subscription[body]"]').setAttribute("style", "border-color: red;"); } } if(valid_439 == 0){ error_msg_439 = "Талбаруудыг бүрэн бөглөнө үү!"; } if(!validate_email_439(form_439.querySelector('input[name="subscriber[email]"]').value)){ form_439.querySelector('input[name="subscriber[email]"]').style="border-color: red;"; valid_439 = 0; }else{ } if(valid_439){ document.querySelector('#subscribe-form-439').style.display = "none"; document.querySelector('#subscription-form-loading-439').style.display = "inline"; xhr_439.send(data_439); }else{ alert(error_msg_439); } } // function postRequest_439(strURL) { var xmlHttp_439; if (window.XMLHttpRequest) { // Mozilla, Safari, ... var xmlHttp_439 = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE var xmlHttp_439 = new ActiveXObject("Microsoft.XMLHTTP"); } xmlHttp_439.open('POST', strURL, true); xmlHttp_439.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttp_439.onreadystatechange = function() { if (xmlHttp_439.readyState == 4) { updatepage_439(xmlHttp_439.responseText); } } xmlHttp_439.send(strURL); } // function updatepage_439(str){ document.getElementById("subscription-form-container-439").innerHTML = str; } //'//moncon.mn' + var get_url_439 = '/api.php/subscription/renderform?site_id=512' + '&id=439' + '' ; postRequest_439(get_url_439);