
function AddToFavor(Id)
{
	var today = new Date();
	var expires = new Date();
	expires.setTime(today.getTime() + 1000*60*60*24*365);
	var count = Id.length;
	if (Id.length==2) {Id = "0" + Id;}
	if (Id.length==1) {Id = "00" + Id;}
	var goodId = GetCookie("Favor");
	if (goodId != null)
		SetCookie("Favor", goodId + "_" + Id, expires);
	else
		SetCookie("Favor", Id, expires);
	UpdateFavor(Id);
}


function UpdateFavor(Id)
{
	var goods = GetCookie("Favor");
	var goodsID=0;
	var i = 0;
	if (goods != null)
	{
		var ss = goods.split("_");
		var count = ss.length;
		while (i < count) {
		  	if (Id == ss[i]) goodsID = 1;
			i++;
		  }
	}

		if (goodsID == 1) 
			document.getElementById('FavorFrm').innerHTML = "<a onfocus='blur()' href='javascript: DelFavor(" + Id + ")'>Удалить из избранных</a> (Всего <a style='color: red' onfocus='blur()' href='http://www.handspc.ru/auction/favorits'><b>" + count + "</b> лота(ов)</a>)";
		else 
			document.getElementById('FavorFrm').innerHTML = "<a href='javascript:AddToFavor(" + Id + ");'><font color='#FF0000'>Добавить в избранное</font></a>";
	
}


function EmptyFavor(Id)
{
	DeleteCookie('Favor');
	if (Id>0) UpdateFavor(Id);
}

function DelFavor(Id)
{
		var goods = GetCookie("Favor");
	if (goods != null)
	{
		goodsNew = new Array();
		var i = 0;
		var y = 0;
		var ss = goods.split("_");
		var count = ss.length;
		  while (i < count) {
		  	if (Id != ss[i]) {
				goodsNew[y] = ss[i];
				y++;
				}
			i++;
		  }
		goodId=goodsNew.join("_");
		var today = new Date();
		var expires = new Date();
		expires.setTime(today.getTime() + 1000*60*60*24*365);
		if (goodId != null)	SetCookie("Favor", goodId, expires);
	}
	document.getElementById('FavorFrm').innerHTML = "<a href='javascript:AddToFavor(" + Id + ");'><font color='#FF0000'>Добавить в избранное</font></a>";
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}
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 SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
     ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
function changeProducer()
{
	if (document.getElementById('ddlProducer').value != 0)
	{
		document.getElementById('ProducerId').value = document.getElementById('ddlProducer').value;
		submForm = Form1.submit;
		submForm();
	}
	else alert("Выберите значение в списке.");
}

function changeModel()
{
	if (document.getElementById('ddlModel').value != 0)
	{
		document.getElementById('UnitId').value = document.getElementById('ddlModel').value;
		document.getElementById('ProducerId').value = document.getElementById('ddlProducer').value;
		submForm = Form1.submit;
		submForm();
	}
	else alert("Выберите значение в списке.");
}

function OnSearchClick()
{
	if ((document.getElementById('ddlProducer').value != 0) && (document.getElementById('ddlModel').value != 0) && (document.getElementById('ddlType').value != 0))
	{
		Form1.action = "BS.php?UnitId=" + document.getElementById('ddlModel').value + "&ChapterId=" + document.getElementById('ddlType').value;
		submForm = Form1.submit;
		submForm();
	}
}
