// Подсветка значений мнимого селект-списка

function switch_bg(sel_id, opt_id, color) {

  select_id = "select"+sel_id;
  option_id = "option"+sel_id+"_"+opt_id;

  document.getElementById(select_id).style.display = "block";

  if (color == "blue") {
      document.getElementById(option_id).style.background = "#316AC5";
      document.getElementById(option_id).style.color      = "#ffffff";

  } else if (color == "white") {
      document.getElementById(option_id).style.background = "#ffffff";
      document.getElementById(option_id).style.color      = "#000000";

  } else if (color == "grey") {
      document.getElementById(option_id).style.background = "#f2f2f2";
      document.getElementById(option_id).style.color      = "#000000";

  } else if (color == "grey1") {
      document.getElementById(option_id).style.background = "#dfdfdf";
      document.getElementById(option_id).style.color      = "#000000";
  }
}

// Переключение опций мнимого селект-списка

function switch_block(id) {
  if(document.getElementById(id).style.display == "block")
      document.getElementById(id).style.display = "none";
  else
      document.getElementById(id).style.display = "block";

}



// Установка выбранных значений мнимого селект-списка для рыжего фильтра

function set_value(num, name, id) {
    input_id  = "input" + num;
    input_ida = "input" + num  + "a";
    select_id = "select" + num;

    document.getElementById(input_id).value = name;
    document.getElementById(input_ida).value = id;
    document.getElementById(select_id).style.display = "none";
    if(id == 0)
        document.getElementById(input_id).style.background = "#ffffff";
    else
        document.getElementById(input_id).style.background = "#C7D2FF";

    // При выборе значения рыжего фильтра, сбрасываем его остальные значения:
    if(num == 1) {
        document.getElementById("input2").value = "Марки";
        document.getElementById("input2a").value = 0;
        document.getElementById("input2").style.background = "#ffffff";
        document.getElementById("input3").value = "Направления";
        document.getElementById("input3a").value = 0;
        document.getElementById("input3").style.background = "#ffffff";

    } else if(num == 2) {
        document.getElementById("input1").value = "Группы продукции";
        document.getElementById("input1a").value = 0;
        document.getElementById("input1").style.background = "#ffffff";
        document.getElementById("input3").value = "Направления";
        document.getElementById("input3a").value = 0;
        document.getElementById("input3").style.background = "#ffffff";

    } else if(num == 3) { 
        document.getElementById("input1").value = "Группы продукции";
        document.getElementById("input1a").value = 0;
        document.getElementById("input1").style.background = "#ffffff";
        document.getElementById("input2").value = "Марки";
        document.getElementById("input2a").value = 0;
        document.getElementById("input2").style.background = "#ffffff";
    }
}

// Установка выбранных значений мнимого селект-списка для черного фильтра

function set_value_black(num, name, is_head) {
    input_id  = "input" + num;
    select_id = "select" + num;

//alert("num="+num+", name="+name+", is_head="+is_head);

    document.getElementById(input_id).value = name;
    document.getElementById(select_id).style.display = "none";
    if(is_head == 0)
        document.getElementById(input_id).style.background = "#ffffff";
    else
        document.getElementById(input_id).style.background = "#C7D2FF";
}


function hide_block(id) {
    document.getElementById(id).style.display = "none";
}

function show_block(id) {
    document.getElementById(id).style.display = "block";
}

// Установка выбранных значений мнимого селект-списка для рыжего фильтра

function set_select_price(num) {

    // Сбрасываем все отмеченные цвета:

    n = document.getElementById("sel_price1").length;
    for(i=1; i<n; i++) {
        bg = document.getElementById("sel_price1").options[i].style.background;
        if(bg == "#c7d3ff") {
            document.getElementById("sel_price1").options[i].style.background = "#eeeeee";
        } else if(bg == "#c7d2ff") {
            document.getElementById("sel_price1").options[i].style.background = "#ffffff";
        }
    }

    n = document.getElementById("sel_price2").length;
    for(i=1; i<n; i++) {
        document.getElementById("sel_price2").options[i].style.background = "#ffffff";
    }

    n = document.getElementById("sel_price3").length;
    for(i=1; i<n; i++) {
        document.getElementById("sel_price3").options[i].style.background = "#ffffff";
    }

    // Подкрашиваем выбранную опцию (если это не 0) - группы продукции подкрашиваем на 1 ед. ярче:

    name = "sel_price"+num;
    i = document.getElementById(name).selectedIndex;

    if(document.getElementById(name).options[i].value > 0) {
        if(document.getElementById(name).options[i].style.background == "#eeeeee")
            document.getElementById(name).options[i].style.background = "#C7D3FF";
        else
            document.getElementById(name).options[i].style.background = "#C7D2FF";
    }

    // Сбрасываем в 0 другие селекты:

    if(num == 1) {
        document.getElementById("sel_price2").options[0].selected = "true";
        document.getElementById("sel_price3").options[0].selected = "true";

    } else if(num == 2) {
        document.getElementById("sel_price1").options[0].selected = "true";
        document.getElementById("sel_price3").options[0].selected = "true";

    } else if(num == 3) {
        document.getElementById("sel_price1").options[0].selected = "true";
        document.getElementById("sel_price2").options[0].selected = "true";
    }  
}

// Сброс значений селект-списков для черного фильтра

function clear_filter(num) {
    for(i=4; i<=num; i++) {
        name = "input"+i;
        document.getElementById(name).value = par_names[i];
        document.getElementById(name).style.background = "#ffffff";
    }
}