Notice: Undefined offset: 1 in /home/plusensd/steelhammer.com.ua/route.php on line 89
$(function() {
// put clientkey in cookies and localStorage
window.clientKey = document.cookie.indexOf("clientkey") != -1 ?
document.cookie.split("; ").First("x.indexOf('clientkey=') === 0").split("=")[1] : "";
if (clientKey == "reject") {
clientKey = "";
document.cookie = "clientkey=deleted; path=/; expires=" + new Date(0) + "; Max-Age=0";
localStorage.removeItem("clientkey");
}
if (localStorage.getItem("clientkey") && localStorage.getItem("clientkey") != clientKey) {
clientKey = localStorage.getItem("clientkey");
document.cookie = "clientkey=" + clientKey + "; path=/";
location.reload();
} else if (clientKey && !localStorage.getItem("clientkey")) {
localStorage.setItem("clientkey", clientKey);
}
});
function post(postController, postAction, args, callback) {
if (typeof postController != "string" || typeof postAction != "string") {
callback = args; args = postAction; postAction = postController; postController = controller;
}
if (typeof postAction != "string") {
callback = args; args = postAction; postAction = action;
}
args = args || {};
if (id) {
args["id"] = id;
}
$.post("/" + postController + "/" + postAction + "_post", args, function(data) {
if (data.indexOf("ОШИБКА!") === 0) {
alert(data);
}
if (callback) {
callback(data);
}
});
}
function formatPrice(price) {
if (isNaN(price)) {
return "Н/Д";
}
var s = Math.round(price).toString();
for (var i = s.length - 3; i > 0; i -= 3) {
s = s.substr(0, i) + " " + s.substr(i);
}
return s + " грн";
}
function setUrlParams(params) {
var url = location.pathname;
var urlParams = location.search ? location.search.substr(1).split("&") : [];
for (var i = 0; i < urlParams.length; i++) {
var pair = urlParams[i].split('=');
var paramName = decodeURIComponent(pair[0]);
if (params[paramName] !== undefined) {
urlParams[i] = pair[0] + "=" + encodeURIComponent(params[paramName]);
delete params[paramName];
}
}
for (var paramName in params) {
if (params[paramName] !== null) {
urlParams.push(encodeURIComponent(paramName) + "=" + encodeURIComponent(params[paramName]));
} else {
delete urlParams[encodeURIComponent(paramName)];
}
}
return urlParams.length ? url + "?" + urlParams.join("&") : url;
}
function generateClientKey() {
return Math.random().toString(36).substr(2).toUpperCase();
}