function addToCart(id/*:Number*/, price/*:String*/, firm/*:String*/, model/*:String*/) {
	var product = {};
	product.price = price;
    product.firm = firm
	product.model = model;
  	if (product.model.length > 100)
  	{
  		product.model = model.substr(0, 100) + "...";
  	}
	product.id = id;
	if (!shoppingCart)
	{
		shoppingCart = new ShoppingCart();
	}
	shoppingCart.addProduct(product);
}

//function removeProduct(sender, sum) {
//	tr = sender.parentNode.parentNode;
//	tr.parentNode.removeChild(tr);
//	document.getElementById("totalSum").firstChild.nodeValue =
//	roundTo(document.getElementById("totalSum").firstChild.nodeValue - sum, -2);
//}

function roundTo(value, digits) {
	return parseFloat(Math.round(value * Math.pow(10, -digits)) / Math.pow(10, -digits));
    //return pad_with_zeros(result3, decimals);
}

/*****************************************************************************\
									Array
\*****************************************************************************/

if (Array.prototype.push && ([0].push(true) == true))
	Array.prototype.push = null;

if (Array.prototype.splice && typeof([0].splice(0)) == "number")
	Array.prototype.splice = null;

if (!Array.prototype.shift) {
Array.prototype.shift = function () {
	var firstElement = this[0];
	this.reverse();
	this.length = Math.max(this.length - 1, 0);
	this.reverse();
	return firstElement;
}
}

if (!Array.prototype.push) {
Array.prototype.push = function () {
	for (var i = 0; i < arguments.length; i++) {
		this[this.length] = arguments[i];
	}
	return this.length;
}
}

if (!Array.prototype.pop) {
Array.prototype.pop = function () {
	var lastElement = this[this.length - 1];
	this.length = Math.max(this.length - 1, 0);
	return lastElement;
}
}

if (!Array.prototype.splice) {
Array.prototype.splice = function (index, count) {
	if (arguments.length == 0) return index;
	if (typeof index != "number") index = 0;
	if (index < 0) index = Math.max(0, this.length + index);

	if (index > this.length) {
		if (arguments.length > 2) index = this.length;
		else return [];
	}

	if (arguments.length < 2) count = this.length - index;
	count = (typeof count == "number") ? Math.max(0, count) : 0;
	var removeArray = this.slice(index, index + count);
	var endArray = this.slice(index + count);
	this.length = index;

	for (var i = 2; i < arguments.length; i++) {
		this[this.length] = arguments[i];
	}

	for (var i = 0; i < endArray.length; i++) {
		this[this.length] = endArray[i];
	}

	return removeArray;
}
}

if (!Array.prototype.roll) {
Array.prototype.roll = function (direction) {
	direction = direction || false;
	if (!direction) {
		this.splice(this.length, 1, this[0]);
		this.splice(0, 1);
	} else {
		this.splice(0, 0, this[this.length - 1]);
		this.splice(this.length - 1, 1);
	}
}
}

function clearAllButtonClick() {
	shoppingCart.clear();
}

/*****************************************************************************\
									Template
\*****************************************************************************/

function Template(id) {
	var temp = document.getElementById(id);
	temp.removeAttribute("id");
	this.template = temp.cloneNode(true);
	//this.element = this.template.cloneNode(true);

	//temp.removeNode(true);
	temp.parentNode.removeChild(temp);
}

Template.prototype.parent = function (parent) {
	this.element = this.template.cloneNode(true);

	if (typeof parent == "string")
		document.getElementById(parent).appendChild(this.element);
	else if (parent.nodeType)
		parent.appendChild(this.element);
	else
		parent.element.appendChild(this.element);
}

Template.prototype.removeId = function (id) {
	this.getElementById(id).removeAttribute("id");
}


Template.prototype.getElementById = function (id) {
	function all(element, id) {
		var result = null;
		if (element.id == id) return element;

		for (var i = 0; i < element.childNodes.length; i++) {
			result = all(element.childNodes[i], id);
			if (result) return result;
		}

		return null;
	}


	return all(this.element, id);
}

function cancelButtonClick() {
	//products[event.srcElement.product.id].row.removeNode(true);
	products[event.srcElement.product.id].row.parentNode.removeChild(products[event.srcElement.product.id].row);
	productsCountLabel.nodeValue -= products[event.srcElement.product.id].countSpinEdit.value();
	delete products[event.srcElement.product.id];
}

/*****************************************************************************\
									System
\*****************************************************************************/
var NBSP                        = " "; // 160

// Languages
var EN                          = 0;
var RU                          = 1;
var FULL_MONTH_NAMES_RU         = 2;

// Inheritance
Object.prototype.inherits = function (superClass) {
	function F() {}
	F.prototype = superClass.prototype;
	this.prototype = new F;
	this.prototype.__super__ = superClass;
	this.prototype.__prototype__ = superClass.prototype;
}

Object.prototype.inherited = function() {
    this.__base = this.__super__;
    this.__super__ = this.__super__.prototype.__super__;
    this.__base(arguments[0], arguments[1], arguments[2], arguments[3],
        arguments[4], arguments[5], arguments[6], arguments[7]);
    delete this.__super__;
}

function call (/*function*/ method, /*object*/ obj /*arguments*/) {
	obj.__base = method;
	obj.__base(arguments[2], arguments[3], arguments[4], arguments[5],
		arguments[6], arguments[7], arguments[8], arguments[9]);
}

pageX = function () {
	return window.event.clientX + document.body.scrollLeft;
}

pageY = function () {
	return window.event.clientY + document.body.scrollTop;
}


/*****************************************************************************\
									Controls
\*****************************************************************************/

var eventTypes = ["blur", "click", "dblclick", "focus", "keydown", "keypress",
	"keyup", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup",
	"resize", "change"];

Element = function (type, id) {
	if (id) this.element = document.getElementById(id);

	if (!this.element && type) {
		this.element = document.createElement(type);
		if (id) this.element.setAttribute("id", id);
	}
	this.style = this.element.style;
}

Element.prototype.pagePos = function () {
	var element = this.element;
	var position = {left: element.offsetLeft, top: element.offsetTop};

	while (element.offsetParent != null) {
		element = element.offsetParent;
		position.left += element.offsetLeft;
		position.top += element.offsetTop;
		if (element.tagName == "BODY") break;
	}

	return position;
}

function pagePos(element) {
	var position = {left: element.offsetLeft, top: element.offsetTop};

	while (element.offsetParent != null) {
		element = element.offsetParent;
		position.left += element.offsetLeft;
		position.top += element.offsetTop;
		if (element.tagName == "BODY") break;
	}

	return position;
}

Element.prototype.show = function () {
	this.element.style.visibility = "visible";
}

Element.prototype.hide = function () {
	this.element.style.visibility = "hidden";
}

Element.prototype.left = function (value) {
	if (value == null)
	  return parseInt(this.style.left);
	else
	  this.style.left = value + "px";
}

Element.prototype.top = function (value) {
	if (value == null)
		return parseInt(this.style.top);
	else
		this.style.top = value + "px";
}

Element.prototype.width = function (value) {
	if (value == null) return parseInt(this.style.width);
	if (value != this.style.width) this.style.width = value + "px";
}

Element.prototype.height = function (value) {
	if (value == null) return parseInt(this.style.height);
	if (value != this.style.width) this.style.height = value + "px";
}

Element.prototype.parent = function (parent) {
	if (typeof parent == "string")
		document.getElementById(parent).appendChild(this.element);
	else if (parent.nodeType)
		parent.appendChild(this.element);
	else
		parent.element.appendChild(this.element);
}

/*****************************************************************************\
									Control
\*****************************************************************************/

Control = function (type, id, owner) {
	this.inherited(type, id);
	this.owner = owner || this;
	if (this.element) this.element.control = this;
}
Control.inherits(Element);

Control.prototype.addEventListener = function (type, listener, target) {
	if (this.element["on" + type] || type == "change") {
		this["_on" + type] = listener;
	} else {
		this.element["on" + type] = Control[type + "Listener"];
		this.element[type + "Listener"] = listener;
		if (target)
			this.element[type + "Target"] = target;
		else
			this.element[type + "Target"] = this;
	}
}

for (var i = 0; i < eventTypes.length; i++) {
	eval("Control." + eventTypes[i] + "Listener = function () {" +
		"call(this." + eventTypes[i] + "Listener, this." + eventTypes[i] + "Target, this.control);" +
	"}");

	eval("Control.prototype.on" + eventTypes[i] + " = function (listener, target) {" +
		"this.addEventListener('" + eventTypes[i] + "', listener, target || this.owner);" +
	"}");
}

/*****************************************************************************\
									Button
\*****************************************************************************/


Button = function (id, owner) {
	this.inherited("input", id, owner);
	this.element.type =	"button";
}
Button.inherits(Control);

Button.prototype.type = function (type) {
	if (type == null) return this.element.type;
	this.element.type =	type;
}

Button.prototype.text = function (value) {
	if (value == null) return this.element.value;
	this.element.value = value;
}

/*****************************************************************************\
									Label
\*****************************************************************************/

Label = function (id, owner) {
	this.inherited("span", id, owner);
	if (!this.element.firstChild)
		this.element.appendChild(document.createTextNode(""));
}
Label.inherits(Control);

Label.prototype.eventclick = function () {
	this._onclick(event);
}

Label.prototype.caption = function (value) {
	if (value == null) return this.element.firstChild.nodeValue;
	this.element.firstChild.nodeValue = value;
}

/*****************************************************************************\
									Edit
\*****************************************************************************/

Edit = function (id, owner) {
	this.inherited("input", id, owner);
	this.onfocus(this.eventfocus, this);
	this.onblur(this.eventblur, this);
	this.onkeydown(this.eventkeydown, this);
}
Edit.inherits(Control);

Edit.prototype.text = function (value) {
	if (this._blocked) return;
	if (value == null) return (this.element.value);
	if (this.element.value != value) {
		if (this._onchange) {
			this._blocked = true;
			this.element.value = value;

			call(this._onchange, this.owner, this);

		} else {
			this.element.value = value;
		}
		this._blocked = false;
	}
}

Edit.prototype.eventfocus = function () {
	this._onFocusValue = this.element.value;
	//this.element.className = "spineditfocus";
	if (this._onfocus) call(this._onfocus, this.owner, this);
}

Edit.prototype.eventblur = function () {
	if (this._onFocusValue != this.element.value) {
		if (this._onchange)
			var newValue = call(this._onchange, this.owner, this, this.element.value);
		if (newValue != null) this.element.value = newValue;
	}

	//this.element.className = "spinedit";
	if (this._onblur) call(this._onblur, this.owner, this);
}

Edit.prototype.eventkeydown = function (sender) {
	if (event.keyCode == 13 /*DOM_VK_RETURN*/) sender.element.blur();
}

Edit.prototype.clear = function (value) {
	this.text("");
}

SpinEdit = function (editId, upButtonId, downButtonId, owner) {
	this.inherited(editId, owner);
	this._increment = 1;
	this._max = Infinity;
	this._min = -Infinity;

	this.upButton = new Button(upButtonId, this);
	this.upButton.onclick(this.upButtonClick);

	this.downButton = new Button(downButtonId, this);
	this.downButton.onclick(this.downButtonClick);
}
SpinEdit.inherits(Edit);

SpinEdit.prototype.eventblur = function (sender) {
	if (isNaN(this.value())) exception(IS_NAN, this.value());
	call(this.__prototype__.eventblur, this, sender);
}

SpinEdit.prototype.upButtonClick = function (sender) {
	var newValue = this.value() + this._increment;

	if (newValue > this._max) {
		if (this._wrap) this.value(this._min);
	} else {
		this.value(newValue);
	}
}

SpinEdit.prototype.downButtonClick = function (sender) {
	var newValue = this.value() - this._increment;

	if (newValue < this._min) {
		if (this._wrap) this.value(this._max);
	} else {
		this.value(newValue);
	}
}

SpinEdit.prototype.increment = function (value) {
	if (value == null) return parseInt(this._increment);
	this._increment = value;
}

SpinEdit.prototype.value = function (value) {
	if (value == null) return parseInt(this.element.value);
	if (isNaN(parseInt(value))) return exception(IS_NAN, value);
	this.text(parseInt(value));
}

SpinEdit.prototype.max = function (value) {
	if (value == null) return this._max;
	this._max = value;
}

SpinEdit.prototype.min = function (value) {
	if (value == null) return this._min;
	this._min = value;
}

SpinEdit.prototype.wrap = function (value) {
	if (value == null) return this._wrap;
	this._wrap = value;
}

/*****************************************************************************\
									Table
\*****************************************************************************/

Table = function (id, owner, colCount, rowCount, parent) {
	this.inherited("table", id, owner);

	if (!this.element.parentNode) { // Новая таблица.
		this.element.appendChild(document.createElement("tbody"));
	}

	this.rowCount(rowCount);
	this.colCount(colCount);
}
Table.inherits(Control);


Table.prototype.deleteRow = function (index) {
	this.element.deleteRow(index);
}

Table.prototype.rowCount = function (rowCount) {
	if (rowCount == null) return this.element.rows.length;

	if (this.element.rows.length > rowCount) { // Удаляем ряды.
		for (var i = this.element.rows.length - 1; i >= rowCount; i--)
			this.deleteRow(i);
	} else if (this.element.rows.length < rowCount) { // Вставляем ряды.
		for (var i = this.element.rows.length; i < rowCount; i++)
			this.insertRow();
	}
}

Table.prototype.colCount = function (newColCount) {
	if (this.element.rows[0])
		var colCount = this.element.rows[0].childNodes.length;
	else
		var colCount = 0;

	if (newColCount == null) return colCount;

	var rowCount = this.element.rows.length;

	if (newColCount < colCount) {
		for (var i = 0; i < rowCount; i++) {
			var cells = this.element.rows[i].childNodes;
			for (var j = newColCount; j < colCount; j++)
				this.element.rows[i].removeChild(cells[j]);
		}
	} else {
		for (var i = 0; i < rowCount; i++)
			for (var j = colCount; j < newColCount; j++)
				this.element.rows[i].appendChild(document.createElement("td"));
	}
}

Table.prototype.cells = function (col, row) {
	this._rowCount = this.rowCount();
	this._colCount = this.colCount();

	if (row == null) {
		return this.element.rows[Math.floor(col / this._colCount)].childNodes(col % this._colCount);
	} else {
		return this.element.rows[row].childNodes(col);
	}
}

Table.prototype.rows = function (index) {
	return this.element.rows[index].childNodes;
}

Table.prototype.cols = function (index) {
	var result = new Array(this.element.rows.length);
	for (var i = 0; i < result.length; i++)
		result[i] = this.element.rows[i].childNodes(index);
	return result;
}

Table.prototype.insertRow = function (index) {
	var newRow = this.element.insertRow(index);
	var colCount = this.colCount();
	for (var i = 0; i < colCount; i++)
		newRow.appendChild(document.createElement("td"));

	return newRow;
}

Table.prototype.addRow = function () {
	return this.insertRow(this.rowCount());
}

Table.prototype.eventselectcell = function () {
	if (this.table._onselectcell)
		call(this.table._onselectcell, this.table.owner, this.table, this.col, this.row);
}

ProductView = function (product, owner) {
	this.owner = owner;
	this.product = product;

	this.row = owner.table.addRow();
	owner.table.colCount(1);
	owner.productTemplate.parent(this.row.firstChild);

	this.model = document.getElementById("productincartimage");
	this.model.innerHTML = product.model;
	owner.productTemplate.removeId("productincartimage");

	this.countSpinEdit = new SpinEdit("countedit",
		"countupbutton", "countdownbutton", this);
	this.countSpinEdit.onchange(this.countSpinEditChange, this);
	this.countSpinEdit.max(9999);
	this.countSpinEdit.min(1);

	if (!product.count) product.count = 1; //??????????
	this.countSpinEdit.element.value = product.count;

	owner.productTemplate.removeId("countedit");
	owner.productTemplate.removeId("countupbutton");
	owner.productTemplate.removeId("countdownbutton");

	this.cancelButton = new Button("cancelbutton", this);
	this.cancelButton.onclick(this.cancelButtonClick);
	owner.productTemplate.removeId("cancelbutton");
}

ProductView.prototype.cancelButtonClick = function (sender) {
	this.owner.deleteProduct(this.product.id);

	this.row.parentNode.removeChild(this.row);
}

ProductView.prototype.countSpinEditChange = function (sender, newValue) {
	this.owner.updateProductCount(this.product.id, sender.value());
}

ProductView.prototype.updateCount = function (value) {
	this.countSpinEdit.element.value = this.product.count;
}

ShoppingCart = function () {
	this.productsCountLabel = new Label("productsincartcountlabel", this);
	this.sumLabel = new Label("sumlabel", this);
	this.table = new Table("shoppingcartproducts", this, 0, 0);
	this.productTemplate = new Template("productincart");
	this.products = new DataCookie("ShoppingCart",
		["id", "price", "model", "count"]);
	var products = this.products.select();
	var sum = 0, count = 0;
	for (var i = 0; i < products.length; i++) {
		products[i].view = new ProductView(products[i], this);
		count += parseInt(products[i].count);
		sum += parseFloat(products[i].count * products[i].price);
	}
	this.productsCountLabel.caption(count);
	this.sumLabel.caption(roundTo(sum, -2));
	this.updateCheckoutButton();
}

//ShoppingCart.prototype.getProductCount = function () {
//	this._records;
//	var result = 0;
//	if (this.products) {
//		for (var key in this.products) {
//			result++;
//		}
//	}
//	alert(result);
//	return result;
//}


ShoppingCart.checkout = function ()
{
	document.location = "/order/";
}

ShoppingCart.denyCheckout = function ()
{
	alert("Нельзя закзать товар: ваша корзина пуста.");
}

ShoppingCart.prototype.updateCheckoutButton = function () {
	var button = document.getElementById("CheckoutButton");
		if (button) {
		if (this.products._records.length  > 0) {
			button.src = "/shopping-cart/checkout-green-button.png";
			button.onclick = ShoppingCart.checkout;
			document.getElementById("ShoppinCartContainer").style.display = "";
		} else {
			
			button.onclick = ShoppingCart.denyCheckout;
			button.src = "/shopping-cart/checkout-black-button.png";
			document.getElementById("ShoppinCartContainer").style.display = "none";
		}
	}
}

ShoppingCart.prototype.save = function () {
	this.products.save();
}

ShoppingCart.prototype.countSpinEditChange = function (sender) {
	var oldValue = sender.product.count;
	sender.product.count = sender.value();
	var count = sender.product.count - oldValue;
	this.productsCountLabel.caption(
		parseInt(this.productsCountLabel.caption()) + count);
	this.sumLabel.caption(
		roundTo(parseFloat(this.sumLabel.caption()) + count * sender.product.price), -2);
	this.save();
}

ShoppingCart.prototype.getProduct = function (id) {
	return this.products.select(id);
}

ShoppingCart.prototype.deleteProduct = function (id) {
	var product = this.products.select(id);
	this.productsCountLabel.caption(
		parseInt(this.productsCountLabel.caption()) - product.count);
	this.sumLabel.caption(
		roundTo(parseFloat(this.sumLabel.caption()) - product.count * product.price, -2));
	this.products.remove(id);
	if (document.getElementById(id)) {

		document.getElementById(id).parentNode.removeChild(document.getElementById(id));
	}
	this.save();
	this.updateCheckoutButton();
}

ShoppingCart.prototype.addProduct = function (product) {
	var id = product.id;
	var price = product.price;

	var oldProduct = this.products.select(id);

	if (oldProduct) {
			this.updateProductCount(
				oldProduct.id,
				parseInt(oldProduct.count) + 1
			);

		oldProduct.view.updateCount();
	} else {

		var newProduct = this.products.insert(
			id, price, product.model, 1 // ???
		);
		newProduct.view = new ProductView(newProduct, this);
		newProduct.count = 0;
		this.updateProductCount(newProduct.id, 1);
	}
	this.save();
	this.updateCheckoutButton();
}

ShoppingCart.prototype.updateProductCount = function (/*number*/ id, /*number*/ value) {
	var product = this.products.select(id);
	var delta = value - product.count;
	product.count = value;

	this.productsCountLabel.caption(parseInt(this.productsCountLabel.caption()) + delta);
	this.sumLabel.caption(roundTo(
		parseFloat(this.sumLabel.caption()) + delta * product.price
		, -2));
	this.save();
}

ShoppingCart.prototype.clear = function () {
	this.products.remove();
	this.table.rowCount(0);
	this.productsCountLabel.caption(0);
	this.sumLabel.caption(0);
	this.save();
}

Cookie = function (/*string*/ name) {
	if (!name) return;

	this._name = name;
	var re = new RegExp(name + "=([^;]*)");
	this._value = document.cookie.match(re);
	if (this._value)
		this._value = this._value[1];
	else
		this._value = "";
}

Cookie.prototype.getName = function () {
	return this._name;
}

Cookie.prototype.setName = function (value) {
	this._name = value;
}

Cookie.prototype.getValue = function () {
	return this._value;
}

Cookie.prototype.setValue = function (value) {
	this._value = value;
}

Cookie.prototype.getExpires = function () {
	return this._expires;
}

Cookie.prototype.setExpires = function (value) {
	this._expires = value;
}

Cookie.prototype.getPath = function () {
	return this._path;
}

Cookie.prototype.setPath = function (value) {
	this._path = value;
}

Cookie.prototype.getDomain = function () {
	return this._domain;
}

Cookie.prototype.setDomain = function (value) {
	this._domain = value;
}

Cookie.prototype.getSecure = function (value) {
	return this._secure;
}

Cookie.prototype.setSecure = function (value) {
	this._secure = value;
}

Cookie.prototype.remove = function () {
	document.cookie = this._name + "=" +
	((this._path) ? "; path=" + this._path : "") +
	((this._domain) ? "; domain=" + this._domain : "") +
	"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

Cookie.prototype.save = function () {
	this._path = "/";

//	alert(this._name + "=" + this._value +
//		((this._expires) ? "; expires=" + this._expires.toGMTString() : "") +
//		((this._path) ? "; path=" + this._path : "") +
//		((this._domain) ? "; domain=" + this._domain : "") +
//		((this._secure) ? "; secure" : ""));


	document.cookie = this._name + "=" + this._value +
		((this._expires) ? "; expires=" + this._expires.toGMTString() : "") +
		((this._path) ? "; path=" + this._path : "") +
		((this._domain) ? "; domain=" + this._domain : "") +
		((this._secure) ? "; secure" : "");
}

DataCookie = function (/*string*/ name, /*array*/ fields) {
	this.inherited(name);

	this._records = [];
	this._fields = fields;

	if (!this._value) return;

	var record, values = this._value.split("&");

	while (values.length > 0) {
		//alert (777);
		// Заполняем запись.
		record = {};
		for (var i = 0; i < this._fields.length; i++) {
			record[this._fields[i]] = unescape(values.shift());
		}
		// Вставляем запись.
		this._records.push(record);
	}
}
DataCookie.inherits(Cookie);


DataCookie.prototype._find = function (id) {
	for (var i = 0; i < this._records.length; i++) {
		if (this._records[i].id == id) return i;
	}
	return -1;
}


DataCookie.prototype.insert = function (/*any values*/) {
	if (this._find(arguments[0]/*id*/) >=0) return false;

	// Заполняем запись.
	record = {};
	for (var i = 0; i < this._fields.length; i++) {
		record[this._fields[i]] = arguments[i];
	}

	// Вставляем запись.
	this._records.push(record);

	return record;
}


DataCookie.prototype.replace = function (/*any values*/) {
	// Заполняем запись.
	record = {};
	for (var i = 0; i < this._fields.length; i++) {
		record[this._fields[i]] = arguments[i];
	}

	// Вставляем запись.
	this._records.push(record);

	return true;
}

DataCookie.prototype.update = function (/*callback*/ where) {
	if (!where) return;

	for (var i = 0; i < this._records.length; i++) {
		where(this._records[i]);
	}
}

DataCookie.prototype.length = function () {
	return this._records.length;
}

DataCookie.prototype.remove = function (/*callback*/ where) {
	var initLength = this._records.length;

	if (!where) {
		// Удаляем все.
		this._records = [];
	} else if (!isNaN(parseInt(where))) {
		// Удаляем запись с определенным id.
		var index = this._find(where);
		if (index >= 0) this._records.splice(index, 1);
	} else {
		// Удаляем все записи по функции.
		for (var i = this._records.length; i >= 0; i--) {
			if (where(this._records[i]))
				this._records.splice(where, 1);
		}
	}

	return /*nomber*/ initLength - this._records.length;
}

DataCookie.prototype.select = function (/*callback*/ where) {
	if (!where) {
		// Возвращаем все записи.
		return this._records;
	} else if (!isNaN(parseInt(where))) {
		var index = this._find(where);
		if (index >= 0)
			return this._records[index];
		else
			return null;
	} else {
		// Возвращаем массив записей или null.
		var result = [];
		for (var i = 0; i < this._records.length; i++) {
			if (where(this._records[i])) result.push(this._records[i]);
		}
		if (result.length > 0)
			return result;
		else
			return null;
	}
}

DataCookie.prototype.save = function (/*record members*/) {
	this._value = "";

	for (var i = 0; i < this._records.length; i++) {
		for (var f = 0; f < this._fields.length; f++) {
			this._value += "&" +
				escape(this._records[i][this._fields[f]]);
		}
	}

	this._value = this._value.substring(1);
	call(this.__prototype__.save, this);
}