var error_msg_600 = ""; function validate_email_600(mail) { if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)) { return (true); } error_msg_600 = "Имэйл хаягаа зөв оруулна уу"; return (false); } function getCookie_600(cname) { var name_600 = cname + "="; var decodedCookie_600 = decodeURIComponent(document.cookie); var ca_600 = decodedCookie_600.split(';'); for(var i = 0; i < ca_600.length; i++) { var c_600 = ca_600[i]; while (c_600.charAt(0) == ' ') { c_600 = c_600.substring(1); } if (c_600.indexOf(name_600) == 0) { return c_600.substring(name_600.length, c_600.length); } } return ""; } function subscribe_submit_600(){ var form_600 = document.querySelector('#subscribe-form-600'); var data_600 = new FormData(form_600); var url_600 = "/api.php/subscription/save?site_id=546&id=600" + '&cookie_id=' + getCookie_600("cookie_id") + '&short_cookie_id=' + getCookie_600("short_cookie_id"); var xhr_600 = new XMLHttpRequest(); if (window.XMLHttpRequest) { // Mozilla, Safari, ... var xhr_600 = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE var xhr_600 = new ActiveXObject("Microsoft.XMLHTTP"); } xhr_600.open('POST', url_600, true); xhr_600.onload = function () { /* do something to response */ console.log(this.responseText); document.getElementById("subscription-form-container-600").innerHTML = this.responseText; }; var valid_600 = 1; if(form_600.querySelector('input[name="subscriber[name]"]')){ if(form_600.querySelector('input[name="subscriber[name]"]').value.trim().length > 0){ }else{ valid_600 = 0; form_600.querySelector('input[name="subscriber[name]"]').setAttribute("style", "border-color: red;"); } } if(form_600.querySelector('input[name="subscriber[email]"]')){ if(form_600.querySelector('input[name="subscriber[email]"]').value.trim().length > 0){ }else{ valid_600 = 0; form_600.querySelector('input[name="subscriber[email]"]').setAttribute("style", "border-color: red;"); } } if(form_600.querySelector('input[name="subscriber[phone]"]')){ if(form_600.querySelector('input[name="subscriber[phone]"]').value.trim().length > 0){ }else{ valid_600 = 0; form_600.querySelector('input[name="subscriber[phone]"]').setAttribute("style", "border-color: red;"); } } if(form_600.querySelector('input[name="subscription[company_name]"]')){ if(form_600.querySelector('input[name="subscription[company_name]"]').value.trim().length > 0){ }else{ valid_600 = 0; form_600.querySelector('input[name="subscription[company_name]"]').setAttribute("style", "border-color: red;"); } } if(form_600.querySelector('input[name="subscription[company_position]"]')){ if(form_600.querySelector('input[name="subscription[company_position]"]').value.trim().length > 0){ }else{ valid_600 = 0; form_600.querySelector('input[name="subscription[company_position]"]').setAttribute("style", "border-color: red;"); } } if(form_600.querySelector('input[name="subscription[title]"]')){ if(form_600.querySelector('input[name="subscription[title]"]').value.trim().length > 0){ }else{ valid_600 = 0; form_600.querySelector('input[name="subscription[title]"]').setAttribute("style", "border-color: red;"); } } if(form_600.querySelector('textarea[name="subscription[body]"]')){ if(form_600.querySelector('textarea[name="subscription[body]"]').value.trim().length > 0){ }else{ valid_600 = 0; form_600.querySelector('textarea[name="subscription[body]"]').setAttribute("style", "border-color: red;"); } } if(valid_600 == 0){ error_msg_600 = "Талбаруудыг бүрэн бөглөнө үү!"; } if(!validate_email_600(form_600.querySelector('input[name="subscriber[email]"]').value)){ form_600.querySelector('input[name="subscriber[email]"]').style="border-color: red;"; valid_600 = 0; }else{ } if(valid_600){ document.querySelector('#subscribe-form-600').style.display = "none"; document.querySelector('#subscription-form-loading-600').style.display = "inline"; xhr_600.send(data_600); }else{ alert(error_msg_600); } } // function postRequest_600(strURL) { var xmlHttp_600; if (window.XMLHttpRequest) { // Mozilla, Safari, ... var xmlHttp_600 = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE var xmlHttp_600 = new ActiveXObject("Microsoft.XMLHTTP"); } xmlHttp_600.open('POST', strURL, true); xmlHttp_600.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttp_600.onreadystatechange = function() { if (xmlHttp_600.readyState == 4) { updatepage_600(xmlHttp_600.responseText); } } xmlHttp_600.send(strURL); } // function updatepage_600(str){ document.getElementById("subscription-form-container-600").innerHTML = str; } //'//jp.micamongolia.com' + var get_url_600 = '/api.php/subscription/renderform?site_id=546' + '&id=600' + '' ; postRequest_600(get_url_600);