function activateButton(index)
{
  getElement('menu_left_' + index).style.backgroundPosition = "";
  getElement('menu_middle_' + index).style.backgroundPosition = "";
  getElement('menu_right_' + index).style.backgroundPosition = "";
  getElement('menu_middle_' + index).style.paddingTop = "7px";
}

function deactivateButton(index)
{
  getElement('menu_left_' + index).style.backgroundPosition = "0px 10px";
  getElement('menu_middle_' + index).style.backgroundPosition = "0px 10px";
  getElement('menu_right_' + index).style.backgroundPosition = "0px 10px";
  getElement('menu_middle_' + index).style.paddingTop = "";
}

function catalogSwitchSearchPanel()
{
  button = getElement('button_switch_search_panel');
  if (button.className == "button_search_panel button_search_panel_closed")
  {
    button.className = "button_search_panel button_search_panel_open";
    getElement('panel_search_form').style.display = "block";
    getElement('panel_search_form_footer').style.display = "block";
    setCookie('catalog_search_form', 0);
  }
  else
  {
    button.className = "button_search_panel button_search_panel_closed";
    getElement('panel_search_form').style.display = "none";
    getElement('panel_search_form_footer').style.display = "none";
    setCookie('catalog_search_form', 1);
  }
}

function fillSearchParams()
{
  deleteCookie("search_string");
  deleteCookie("price_from");
  deleteCookie("price_to");
  deleteCookie("class");
  deleteCookie("trademark");
  deleteCookie("purpose");

  var formControls = getElement("search_form").elements;
  for (var i = 0; i < formControls.length; i++)
  if (formControls[i].type == "checkbox")
  {
    if (formControls[i].checked)
    {
      if (getCookie(formControls[i].name) == "")
        setCookie(formControls[i].name, formControls[i].value, 30);
      else
        setCookie(formControls[i].name, getCookie(formControls[i].name) + "," + formControls[i].value, 30);
    }
  }
  else
    if (formControls[i].value != "")
      setCookie(formControls[i].name, formControls[i].value, 30);
    else
      deleteCookie(formControls[i].name);
}

function catalogShowTab(event)
{
  index = getFirstEventParent(event, "TD").cellIndex;
  panels = getElementsByClassName("catalog_body", null);
  for (var i = 0; i < panels.length; i++)
    panels[i].style.display = (index == i) ? 'block' : 'none';
  setCookie('catalog_tab_index', index);
}

function catalogSelectRecord(name)
{
  getElement(name).style.backgroundColor = '#FFFF85';
}

function catalogUnselectRecord(name)
{
  row = getElement(name);
  if (row.rowIndex % 2 == 1)
    row.style.backgroundColor = '#F3F3F3';
  else
    row.style.backgroundColor = '#FFFFFF';
}

function colorRecords()
{
  table = getElement('product_table');
  for (i in table.rows)
    if ((table.rows[i].id != null) && (table.rows[i].id != ''))
      catalogUnselectRecord(table.rows[i].id);
}

function showProductHint(code)
{
  hintWindow = getElement('hint_product' + code);
  hintWindow.style.visibility = 'visible';
}

function hideProductHint(code)
{
  hintWindow = getElement('hint_product' + code);
  hintWindow.style.visibility = 'hidden';
}

function positionProductHint(code, event)
{
  hintWindow = getElement('hint_product' + code);
  hintWindow.style.left = event.clientX + 5 + 'px';
  positionY = event.clientY - hintWindow.offsetHeight - 5 + document.documentElement.scrollTop;
  if (positionY < document.documentElement.scrollTop)
    positionY = document.documentElement.scrollTop + 5;
  hintWindow.style.top = positionY + 'px';
}

function cart_add_product(code, price)
{
  if (getElement('product_quantity' + code) != null)
    getElement('product_quantity' + code).innerHTML++;
  getElement('cart_product_quantity').innerHTML++;
  getElement('cart_product_sum').innerHTML = parseInt(getElement('cart_product_sum').innerHTML) + price;
  getElement('cart_product_total').innerHTML = Math.ceil(getElement('cart_product_sum').innerHTML);
  production = getCookie("production");
  quantity = getParamValue(production, code)
  if (quantity == null)
    quantityInt = 0;
  else
    quantityInt = parseInt(quantity);
  production = setParamValue(production, code, quantityInt + 1);
  setCookie("production", production, 30);
}

function cart_remove_product(code, price)
{
  quantity = parseInt(getElement('product_quantity' + code).innerHTML);
  if (quantity > 0)
  {
    if (getElement('product_quantity' + code) != null)
      getElement('product_quantity' + code).innerHTML--;
    getElement('cart_product_quantity').innerHTML--;
    getElement('cart_product_sum').innerHTML = parseInt(getElement('cart_product_sum').innerHTML) - price;
    getElement('cart_product_total').innerHTML = Math.ceil(getElement('cart_product_sum').innerHTML);
    production = getCookie("production");
    quantity = getParamValue(production, code)
    if (quantity == null)
      quantityInt = 0;
    else
      quantityInt = parseInt(quantity);
    if (quantityInt > 1)
      production = setParamValue(production, code, quantityInt - 1);
    else
      production = deleteParam(production, code);
    setCookie("production", production, 30);
  }
}

function cart_open_product(event, code)
{
  if ((getEventElement(event).tagName != 'IMG') || (getEventElement(event).className == 'bordered_image1'))
    window.open('product.php?id=' + code);
}