var good_word_forms = ['товаров','товар','товара','товаров'];
var ruble_word_forms = ['рублей','рубль','рубля','рублей'];
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
function number_format(number, decimals, dec_point, thousands_sep ) { // Format a number with grouped thousands
//
// + original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfix by: Michael White (http://crestidg.com)
var i, j, kw, kd, km;
// input sanitation & defaults
if( isNaN(decimals = Math.abs(decimals)) ){
decimals = 2;
}
if( dec_point == undefined ){
dec_point = ",";
}
if( thousands_sep == undefined ){
thousands_sep = ".";
}
i = parseInt(number = (+number || 0).toFixed(decimals)) + "";
if( (j = i.length) > 3 ){
j = j % 3;
} else{
j = 0;
}
km = (j ? i.substr(0, j) + thousands_sep : "");
kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep);
//kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).slice(2) : "");
kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : "");
return km + kw + kd;
}
function count_word(number, word_forms) { // return correct form of word
//
// by: Maxim Kovtun (emotionless@yandex.ru)
// word forms example: good_word_forms = ['товаров','товар','товара','товаров'];
number = number.toString();
if(number.length>1 && number.substr(number.length-2,2)>=11 && number.substr(number.length-2,2)<=14)
return word_forms[0];
else if(number.substr(number.length-1,1)==1)
return word_forms[1];
else if(number.substr(number.length-1,1)>=2 && number.substr(number.length-1,1)<=4)
return word_forms[2];
else
return word_forms[3];
}
function RecountOrder(href) {
var list = {};
$('#order_table tbody tr').each(function() {
id = $(this).attr('id');
list['g['+id+']'] = $(this).find('input.input-count').attr('value');
}
);
list['get_type'] = 'recount';
$.getJSON('/include/get_content.php', list, function(data) {
UpdateOrder(data);
if(href)
location.href = href;
}
);
}
function DeleteItems(objJQcheckbox) {
var list = {};
var rows_to_del = [];
i=0;
objJQcheckbox.each(function() {
list['g['+i+']'] = $(this).attr('name').replace('del_item_',''); // id товаров для удаления
rows_to_del.push($(this).parents('tr')); // объекты-строки для удаления
i++;
}
);
if(Object.size(list)) {
list['get_type'] = 'delitems';
$.getJSON('/include/get_content.php', list, function(data) {
// удаляем строки
if(rows_to_del.length) {
for(i=0; i