// pobieranie podkategorii do selectow, s1 - ten w ktorym zmienilo sie zaznaczenie,
// s2 - ten w ktorym maja byc wypisane podkategorie

function wpiszNazweNumerKategorii(select)
{
  var s = document.getElementById(select);
  var numer = s.options[s.selectedIndex].value;
  //alert(numer);
  var nazwa = s.options[s.selectedIndex].text;
  //alert(nazwa);
  document.getElementById('nazwa_kategoria').value = nazwa;
  document.getElementById('kategoria').value = numer;
}

function wyczyscNazweNumerKategorii()
{
  document.getElementById('nazwa_kategoria').value = 
  document.getElementById('kategoria').value = "";
}

function pobierzKategorie(s1,s2)
{
  var xmlHttp;
  try
  {
    if (window.ActiveXObject) xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    else xmlHttp = new XMLHttpRequest();
  }
  catch (e)
  {
    alert("Twoja przeglądarka nie obsługuje AJAX!");
    return false;
  }
 
  xmlHttp.onreadystatechange=function()
  {
    if(xmlHttp.readyState==4)
    {
      // podzielenie pobranych danych
      var select = document.getElementById(s2);
      options = xmlHttp.responseText.split(";");
      optionsCount = options.length;
      if (optionsCount < 2)
      {
        wpiszNazweNumerKategorii(s1);
      } else {
        wyczyscNazweNumerKategorii();
      } 
      
      
      // wyczyszczenie selectow podkategorii 
      if (s1 == 'select2') {
        document.getElementById('select3').options.length = 0;
      } else {
        document.getElementById('select2').options.length = 0;
        document.getElementById('select3').options.length = 0;
      }
      
      //wpisanie pobranych kategorii
      for (var i=0;i<optionsCount-1;i=i+2)
      {
        option = document.createElement("OPTION");
    		option.value = options[i];
    		option.text = options[i + 1];
    		try 
        {
          // IE :-[
           select.add(option)
        }
        catch(e) { }
        
        try 
        {
          // reszta
           select.add(option, null)
        }
        catch(e) { }
      } 
      return true;
    }
  }
  // pobranie zaznaczonego id 
  var select = document.getElementById(s1);
  var sI = select.selectedIndex;
  var sId = select.options[sI].value;
  // wyslanie zapytania
  xmlHttp.open("GET", "http://ogloszenia.24polska.pl/ajax/kategorie.php?id=" + sId, true);
  xmlHttp.send(null);  
}

function ukryjPoleZCena(opcja)
{
  var element = document.getElementById('input_cena');
  if (opcja == 1) {
    element.style.visibility = "visible";
    element.value = "";
  } else {
    if (opcja == 2) {
      element.style.visibility = "hidden";
      element.value = "-1.00";
    } else {
      element.style.visibility = "hidden";
      element.value = "-2.00";
    } 
  }
}

function ukryjPoleZCena2()
{
  alert();
  var spanElement = document.getElementById('span_cena');
  var element = document.getElementById('cena');
  if (element.value == '-1.00' || element.value == '-2.00') {
    spanElement.style.visibility = "hidden";
  } else {
    spanElement.style.visibility = "visible";
  }
}

