var http_request = false;
function ajax(id, Path, t, site) {
  $.ajax({
    type: "GET",
    url: Path+"/content/xml/"+site+".php?id="+id+"&typ="+t,
    dataType: "xml",
    success: function(xml) {
      $(xml).find('content').each(function(){

        var selLength = $('#miasto').length;
        if (t!='m') {
          for (i=0;i<selLength;i++) {
            $('#miasto option').remove();
          }
          var ile_node = $(this).find('ile').text();
          if (ile_node=='1') {
            $('#miasto').slideUp();
          } else {
            $('#miasto').slideDown();
            $(this).find('option').each(function() {
              $('#miasto').append('<option value="'+ $(this).attr('value') +'">'+ $(this).text() +'</option>');
            });
          }
        }
        $('#content').html($(this).find('item').text());
      });
    }
  });
/*   http_request = false;
  if (window.XMLHttpRequest) {
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/xml');
    }
  } else if (window.ActiveXObject) {
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }
  if (!http_request) {
    alert('Nie mogę zainstalować obiektu XMLHTTP');
    return false;
  }
  http_request.onreadystatechange = function() {  getxml(http_request,t); };
  http_request.open('GET', Path+'/content/xml/'+site+'.php?id='+id+'&typ='+t, true);
  http_request.send(null); */
}

function getxml(http_request,t) {
  var selLength = document.getElementById('miasto').length;
  if (t!='m') {
    for (i=0;i<selLength;i++) {
      document.getElementById('miasto').options[0] = null;
    }
  }
  if (http_request.readyState == 4) {
    if (http_request.status == 200) {
      var xmldoc = http_request.responseXML;
      var root_node = xmldoc.getElementsByTagName('content').item(0);
      var html_node = root_node.getElementsByTagName('html').item(0);
      if (t!='m') {
      var ile_node = root_node.getElementsByTagName('ile').item(0);
        if (ile_node.firstChild.data=='1') {
          document.getElementById('miasto').style.display = 'none';
        } else {
          document.getElementById('miasto').style.display = 'block';
          for (i=0;i<ile_node.firstChild.data;i++) {
            var selLength = document.getElementById('miasto').length;
            var v = root_node.getElementsByTagName('option').item(i).attributes[0].value;
            var newOpt = new Option(root_node.getElementsByTagName('option').item(i).firstChild.data, v);
            document.getElementById('miasto').options[selLength] = newOpt;
          }
        }
      }
      html_node.getElementsByTagName('item')
      alert(html_node.getElementsByTagName('item').item(0).firstChild.data.length);
      $('#content').html(html_node.getElementsByTagName('item').item(0).firstChild.data);
        /* with(document.getElementById("content")) { innerHTML=html_node.getElementsByTagName('item').item(0).firstChild.data; } */
    } else {
      alert("Błąd");
    }
  }
}
