function phone_clear( text ){ var text = text.replace(/[^0-9]/g, ''); //удалить все кроме цифр return text.replace(/^[^9]/g, ''); //удалить все цифры с начала до первой девятки. } function phoneInputKeyHandle ( event ){ var inputed = $( this ).val(); var numbers = phone_clear( inputed ); $( this ).val( numbers ); } function check_mail(text){ var pattern = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/; return pattern.test(text); } function getCookie(name) { var cookie = " " + document.cookie; var search = " " + name + "="; var setStr = null; var offset = 0; var end = 0; if (cookie.length > 0) { offset = cookie.indexOf(search); if (offset != -1) { offset += search.length; end = cookie.indexOf(";", offset) if (end == -1) { end = cookie.length; } setStr = unescape(cookie.substring(offset, end)); } } return(setStr); } function deleteCookie(name) { var cookie_date = new Date(); cookie_date.setTime(cookie_date.getTime()-1); document.cookie = name += "=; expires=" + cookie_date.toGMTString(); } $(document).ready(function(){ $(".logout_link").click(function(){ $.post('/engine/postlogin.php', { deist: "0" }, function(){ document.location.href='/'; }); }); $(".registration_link").on( 'click', main.viewRegistrationsForms ); $(".login_link").on( 'click', main.viewLoginForms ); $(".city_name").on( 'click', main.changingCity ); $(".view_phone").on( 'click', main.viewPhone ); }); var main = { viewRegistrationsForms: function( ev ){ ev.preventDefault(); $.post('/controller', { module: 'login', no_html: 1, action: 'view-registration-form' }, function( data ){ $( '#vca-main__modal_login_content' ).html( data ); $( '#vca-main__modal_login' ).modal( 'show' ); }); }, viewLoginForms: function( ev, login ){ ev.preventDefault(); $.post('/controller', { module: 'login', no_html: 1, action: 'view-login-form', login: login }, function( data ){ $( '#vca-main__modal_login_content' ).html( data ); $( '#vca-main__modal_login' ).modal( 'show' ); }); }, newRegistrations: function( ev ){ ev.preventDefault(); var pass = $( "#passInput" ).val(), name = $( "#name_input" ).val(), type = $( "#main_registration__reg_type" ).val(), phone = $( "#phoneInput" ).val(), mail = $( "#mailInput" ).val(), pass_type = $( '#main_registration__myselfPass_type' ).val(), login = ''; if ( type == 'phone' ){ if ( phone.length < 10 ){ $( '.main_registration__error-text' ).html( "Укажите корректный мобильный телефон 9xxxxxxxxx" ); $( '.main_registration__error' ).removeClass( 'hidden' ); $( "#phoneInput" ).focus(); return; } login = phone; mail = ''; } else { if ( mail.length < 1 ){ $( '.main_registration__error-text' ).html( "Укажите ваш E-mail" ); $( '.main_registration__error' ).removeClass( 'hidden' ); $( "#mailInput" ).focus(); return; } if( !check_mail( mail ) ) { $( '.main_registration__error-text' ).html( "Некорректно введен адрес E-mail" ); $( '.main_registration__error' ).removeClass( 'hidden' ); $( "#mailInput" ).focus(); return; } login = mail; phone = ''; } if ( name.length < 1 ){ $( '.main_registration__error-text' ).html( "Вы не указали ваше имя" ); $( '.main_registration__error' ).removeClass( 'hidden' ); $( "#name_input" ).focus(); return; } if ( pass_type == 'auto' ){ pass = ''; } else if ( pass.length < 6 ){ $( '.main_registration__error-text' ).html( "Длина пароля должна быть не менее 6 символов" ); $( '.main_registration__error' ).removeClass( 'hidden' ); $( "#passInput" ).focus(); return; } $.post('/engine/postlogin.php', { deist: "2", type: type, pass: pass, name: name, phone: phone, mail: mail }, function( data ){ if ( data.indexOf('') >= 0 ){ $( '.main_registration__error-text' ).html( data ); $( '.main_registration__error' ).removeClass( 'hidden' ); } else if ( data.indexOf('') >= 0 ){ main.viewLoginForms( ev, login ); } else { location.reload(); } }); }, login: function( ev ){ ev.preventDefault(); var login = $( "#loginInput" ).val(), pass = $( "#passInput" ).val(), repairs = $( "#main_login__repairs" ).val(); if ( login.length < 1 ){ $( '.main_login__error-text' ).html( "Вы не указали логин" ); $( '.main_login__error' ).removeClass( 'hidden' ); $( "#loginInput" ).focus(); return; } if ( pass.length < 6 ){ $( '.main_login__error-text' ).html( "Длина пароля должна быть не менее 6 символов" ); $( '.main_login__error' ).removeClass( 'hidden' ); $( "#passInput" ).focus(); return; } $.post('/engine/postlogin.php', { login: login, pass: pass, deist: "1", repairs: repairs }, function( data ){ if ( data.indexOf('') >= 0 ){ $( '.main_login__error-text' ).html( data ); $( '.main_login__error' ).removeClass( 'hidden' ); } else { location.reload(); } }); }, changingCity: function( ev ){ ev.preventDefault(); $.post('/controller', { module: 'changing-city', no_html: 1 }, function( data ){ $( '#vca-main__modal_city_content' ).html( data ); $( '#vca-main__modal_city' ).modal( 'show' ); }); }, viewPhone: function(){ var it = this; $.post('/controller', { module: 'view-phone', no_html: 1, type: $(this).data('type') }, function( data ){ $( it ).replaceWith( data ); var site = $('#host_name').val(); try{ ga( 'send', 'event', 'viewphone', site ); } catch (exc) { } }); } };