// Dynamicka cast stranek, vyuziti AJAXu

var xmlHTTP = createXmlHttpRequestObject();

// Ziska instanci objektu pro komunikaci se serverem
function createXmlHttpRequestObject()
{
  var xmlHTTP;
  try 
  { // standardni chovani
    xmlHTTP = new XMLHttpRequest();
  }
  catch(e)
  { // IE 6 a nizsi
    try
    {
      xmlHTTP = new ActiveXObject("Microsoft.XMLHttp");
    }
    catch (e) { }
  }
  
  if (!xmlHTTP)
    alert("Chyba při vytváření objektu pro AJAX");
  else 
    return xmlHTTP;     
}

function searchForCategories(str)
{ 
  if (xmlHTTP)
  {
    try
    {
      xmlHTTP.open("GET","/service_api.php?service=searchForCategories&str="+str, true);
      xmlHTTP.onreadystatechange = handleRequestSearchCategory;
      xmlHTTP.send(null);
    }
    catch (e)
    {
      alert("Server connection error.");
    }
  }
}

function handleRequestSearchCategory()
{
  if (xmlHTTP.readyState == 4)
  {
    if (xmlHTTP.status == 200)
    {
      document.getElementById('category_search_results').innerHTML = xmlHTTP.responseText;
    }
  }
}



function getCategoryPath()
{ 
  if (xmlHTTP)
  {
    try
    {
      xmlHTTP.open("GET","/service_api.php?service=getCategoryPath&id="+document.getElementById('categoryID').value, true);
      xmlHTTP.onreadystatechange = handleRequestGetCategoryPath;
      xmlHTTP.send(null);
    }
    catch (e)
    {
      alert("Server connection error.");
    }
  }
}

function handleRequestGetCategoryPath()
{
  if (xmlHTTP.readyState == 4)
  {
    if (xmlHTTP.status == 200)
    {
      document.getElementById('category_path').innerHTML = xmlHTTP.responseText;
    }
  }
}
