You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
4.0 KiB
148 lines
4.0 KiB
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();
|
|
|
|
|
|
// Pr
|
|
|
|
});
|
|
|