GetNoun = function(number, one, two, five) { number = Math.abs(number); number %= 100; if (number >= 5 && number <= 20) { return five; } number %= 10; if (number == 1) { return one; } if (number >= 2 && number <= 4) { return two; } return five; }; GetAdj = function(number, one, two) { number %= 100; if (number == 11) return two; number %= 10; if (number == 1) return one; return two; }; setCookie = function(key, value) { var expires = new Date(); expires.setTime(expires.getTime() + (1 * 24 * 60 * 60 * 1000)); document.cookie = key + '=' + value + ';expires=' + expires.toUTCString() + ';path=/'; }; getCookie = function(name) { var matches = document.cookie.match(new RegExp( "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)" )); return matches ? decodeURIComponent(matches[1]) : undefined; } detectRegion = function() { function renderRegionData(region_name, country_code) { var regions = { 'Moscow': { 'city': 'В Москве', 'phone': '+7 495 775-16-37' }, 'St.-Petersburg': { 'city': 'В Санкт Петербурге', 'phone': '+7 812 449-03-54.' }, 'Rostov': { 'city': 'В Ростове-на-Дону', 'phone': '+7 863 209-85-65' }, 'Krasnodarskiy Kray': { 'city': 'В Ростове-на-Дону', 'phone': '+7 863 209-85-65' }, 'Stavropol\'skiy Kray': { 'city': 'В Ростове-на-Дону', 'phone': '+7 863 209-85-65' }, 'Voronezhskaya Oblast': { 'city': 'В Воронеже', 'phone': '8 800 700-16-37' }, 'Volgogradskaya Oblast': { 'city': 'В Волгограде', 'phone': '8 800 700-16-37' }, 'US': { 'city': 'В США', 'phone': '+7 495 775-16-37' }, 'UA': { 'city': 'В Украине', 'phone': '+7 495 775-16-37' }, 'KZ': { 'city': 'В Казахстане', 'phone': '+7 495 775-16-37' }, 'BY': { 'city': 'В Беларуси', 'phone': '+7 495 775-16-37' }, 'DE': { 'city': 'В Германии', 'phone': '+7 495 775-16-37' }, 'UZ': { 'city': 'В Узбекистане', 'phone': '+7 495 775-16-37' } }; var current_region = regions[region_name] || regions[country_code] if(typeof current_region !== "undefined") { $('.city').text(current_region['city']); $('.header-contacts .consultation h3').text(current_region['phone']); } } if(typeof getCookie('region') === "undefined" || getCookie('region') == "") { var request = $.get('http://ip-api.com/json') request.done(function(data) { setCookie('region', data.regionName); renderRegionData(data.regionName, data.countryCode); }); } else { renderRegionData(getCookie('region')); } }; $(function() { var csrftoken = getCookie('csrftoken'); $( "[href^='#service-form-submit']" ).click(function(e) { e.preventDefault(); $('.service-calculator form').submit(); }); function csrfSafeMethod(method) { // these HTTP methods do not require CSRF protection return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); } $.ajaxSetup({ beforeSend: function(xhr, settings) { if (!csrfSafeMethod(settings.type) && !this.crossDomain) { xhr.setRequestHeader("X-CSRFToken", csrftoken); } } }); detectRegion(); $.urlParamGet = function (name){ var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); if (results==null) { return null; } else{ return results[1] || 0; } }; $.urlParamUpdate = function (paramName, paramValue){ if(paramValue == null) { paramValue = '' } var pattern = new RegExp('\\b(' + paramName + '=).*?(&|$)'), url = window.location.href; if (url.search(pattern) >= 0){ window.location = url.replace(pattern, '$1' + paramValue + '$2'); return window.location; } window.location = url + '#' + (url.indexOf('?')>0 ? '&' : '?') + paramName + '=' + paramValue; return window.location; }; });