function setCookie (name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}

function GetCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function showCountItems() {
	var cookie = "" + document.cookie;
	var cookieCount = 0;
	var itemsInNotepadCount = "";

	if(cookie.length > 0) {
		
		var cookieArray = cookie.split(";");
		for(i=0; i <= cookieArray.length - 1; i++) {
			offset = cookieArray[i].indexOf("paulsyardlot");
			if (offset != -1) {
				var cookieValues = cookieArray[i].split("=");
				cookieValue = cookieValues[1];
				if(cookieValue != 0) cookieCount++;
			}
		}
		
		strCookieCount = "" + cookieCount;
		if(strCookieCount.length > 1) lastSymbol = strCookieCount.substr(strCookieCount.length-1, 1);
		else lastSymbol = strCookieCount;

		if((lastSymbol >= 5 && lastSymbol <= 9) || lastSymbol == 0 || (cookieCount >= 11 && cookieCount <= 19)) {
			itemsInNotepadCount = '<b>' + strCookieCount + '</b>' + ' объектов';
			return itemsInNotepadCount;
		}

		if(lastSymbol == 1) {
			itemsInNotepadCount = '<b>' + strCookieCount + '</b>' + ' объект';
			return itemsInNotepadCount;
		}

		if(lastSymbol >= 2 && lastSymbol <= 4) {
			itemsInNotepadCount = '<b>' + strCookieCount + '</b>' + ' объекта';
			return itemsInNotepadCount;
		}
		
	} else return "<b>0</b> объектов";
}

function slots(el, date1, date2, domain)
{
	var className = el.className;
	var id = el.id;
	if (className == 'to-favourite')
	{
		setCookie("paulsyardlot["+id+"]", date1, date2, '/', domain, 0);
		el.className = 'from-favourite';
		el.firstChild.innerHTML = 'из избранного';
	}
	else
	{
		setCookie("paulsyardlot["+id+"]", 0, "Thu, 01-Jan-70 00:00:01 GMT", '/', domain, 0);
		el.className = 'to-favourite';
		el.firstChild.innerHTML = 'в избранное';
	}
	document.getElementById('itemsInNotepadCount').innerHTML = showCountItems();
	return false;
}
