/**
 *  Zbior funkcji javascript dla MultiOpac'a - WebSearch - lista kategorii
 *
 *  Author: michalsz
 *
 */    

var liczbaElementow = 0;

/**
 *  highlightThis - wlacza podswietlenie elementu
 */ 
function highlightThis(elem, id_val) {
  var isChecked = 0;
  if (id_val == 0) {
    elem.style.backgroundColor = '#FCDBBA';
  }  
  else {
    isChecked = document.getElementById("check" + id_val).value;
    if (isChecked == 0) {
      elem.style.backgroundColor = '#FCDBBA';
    }
    else {
      elem.style.backgroundColor = '#0F359B';
    }
  }
}

/**
 *  offThis - wylacza efekt na elemencie
 */ 
function offThis(elem, id_val) {
  var isChecked = 0;
  if (id_val == 0) {
    elem.style.backgroundColor = '#fff';
  }  
  else {
    isChecked = document.getElementById("check" + id_val).value;
    if (isChecked == 0) {
      elem.style.backgroundColor = '#fff';
    }
    else {
      elem.style.backgroundColor = '#0A246A';
    }
  }  
}

/**
 *  clearAllCat - czysci zaznaczone kategorie
 */ 
function clearAllCat(elem) {
  if (elem != '') { 
    elem.style.backgroundColor = '#FABE83';
    if (document.getElementById('chboxall').checked == false) {
      for (i=1; i<=liczbaElementow; i++) {
        document.getElementById("check" + i).value = 0;
        document.getElementById("elem" + i).style.backgroundColor = '#fff';  
        document.getElementById("elem" + i).style.color = "#000";    
      }
      odznaczKategorie();
      document.getElementById('searchform').KategoriePamiec.value = '';
    } 
  }
  else {
    for (i=1; i<=liczbaElementow; i++) {
      document.getElementById("check" + i).value = 0;
      document.getElementById("elem" + i).style.backgroundColor = '#fff';  
      document.getElementById("elem" + i).style.color = "#000";    
    }  
  }
}

/**
 *  setGoodColour - ustawia kolor 
 */ 
function setGoodColour(elem) {
  elem.style.backgroundColor = '#FCDBBA';
}

/**
 *  chooseCat - zaznaczenie/odznaczenie kategorii
 */ 
function chooseCat(elem, id_val) {
  var isChecked = document.getElementById("check" + id_val).value;
  if (isChecked == 0) {
    elem.style.backgroundColor = '#FABE83';
    document.getElementById("check" + id_val).value = 1;    
  }
  else {
    elem.style.backgroundColor = '#154DDF';
    document.getElementById("check" + id_val).value = 0;
  }
}

/**
 *  chooseUpCat - gdy zaznaczono/odznaczono kategorie
 */ 
function chooseUpCat(elem, id_val) {
  var isChecked = document.getElementById("check" + id_val).value;
  if (isChecked == 0) {    
    elem.style.backgroundColor = '#FCDBBA';  
    elem.style.color = "#000";
  }
  else {
    elem.style.backgroundColor = '#0A246A';
    elem.style.color = "#fff";
  }  
  updateAll();
  FillListValues(id_val);
}

/**
 *  updateAll - sprawdza, ktor pozycje sa faktycznie zaznaczone
 */ 
function updateAll() {
  var isChecked = 0;
  for (i=1; i<=liczbaElementow; i++) {
    isChecked = document.getElementById("check" + i).value;
      if (isChecked == 0) {    
        document.getElementById("elem" + i).style.backgroundColor = '#fff';  
        document.getElementById("elem" + i).style.color = "#000";
      }
      else {
        document.getElementById("elem" + i).style.backgroundColor = '#0A246A';
        document.getElementById("elem" + i).style.color = "#fff";
      }   
  }
}

/**
 *  setCounter - ustawia liczbe elementow na liscie
 */ 
function setCounter(val) {
  liczbaElementow = val;
}

/**
 *  checkRadioButtons - sprawdza, czy radiobutton wskazuje na indeks, ktory ma wypelniony warunek
 */
function checkRadioButtons() {
  var radioBtn = document.forms['searchform'].elements['oneidx'];
  var radioValue = 1;
  var radioLength = radioBtn.length;
  for (var j=0; j<radioLength; j++) {
    if (radioBtn[j].checked) {
      radioValue = j + 1;
    }
  }
  var radioBtnText = document.getElementById("warunek" + radioValue).value;
  if (radioBtnText == '') {
    for (var i=1; i<5; i++) {
      radioBtnText = document.getElementById("warunek" + i).value;
      if (radioBtnText != '') {
        radioBtn[i - 1].checked = true;
        break;
      }
    }
  }
} 
