function set_count ()
{
	// Для начала установим счетчик выбранных работ
	var count_select = eval (GetCookie('count_select'));
	if (count_select == null){var count_select = 0;}	
	document.all.unitSelected.innerHTML = count_select;
}


function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0)
break;
}
return null;
}

function saveUnitID(unit_id)
{
	var count_select = eval (GetCookie('count_select'));
	if (count_select == null)
	{
		var count_select = 0;
	}	
	//alert ('Получили count_select из куки - ' + count_select);

	var chbxName = eval('document.reflist.unitselect' + unit_id);
	if (chbxName.checked==true)
	{
		document.cookie = 'cook' + "_" + count_select + "=" + unit_id;
	//	var b = 'cook' + "_" + count_select + "=" + unit_id;
	//	alert ('записали ' + b);
		count_select++;
	}
	else
	{
		if (count_select != 0)
		{
			var i = 0;
			while (i < count_select)
			{
				var unit_id_select = eval (GetCookie('cook' + "_" + i));
	//			var fn = 'document.reflist.unitselect' + unit_id_select;

				if (chbxName.value == unit_id_select)
				{
//					alert ('удаляем cook_' + i);
					var j = i+1;
					while (j < count_select)
					{
						var unit_id_select_shift = eval (GetCookie('cook' + "_" + j));
						document.cookie = 'cook' + "_" + (j-1) + "=" + unit_id_select_shift;
						j++;
					}
				}
				i++;
			}

			//	document.cookie = 'cook' + "_" + count_select + "=" + unit_id;
			//	var b = 'cook' + "_" + count_select + "=" + unit_id;
			//	alert ('записали ' + b);
			
				count_select--;
				}
			//	alert (count_select);
	}

	document.cookie = 'count_select' + "=" + count_select;
	document.all.unitSelected.innerHTML = count_select;
}


function cleanCount ()
{
var count_select = eval (GetCookie('count_select'));
if (count_select == null){var count_select = 0;}	
var i = 0;
while (i < count_select)
{
	var unit_id_select = eval (GetCookie('cook' + "_" + i));
	document.cookie = 'cook' + "_" + i + "=" + 0 + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
//	var chbxName = eval('document.reflist.unitselect' + unit_id_select);
//	chbxName.checked=false;
	i++;
}


var count_select = 0;
document.cookie = 'count_select' + "=" + count_select + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
document.all.unitSelected.innerHTML = count_select;


}


// Добавление в избранное

function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}
 
function bookmark(a){
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE' && 8 >= b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
 return false;
}


