/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}




/*
XHConn is a data object with a single method. In order to use the object, you must first instantiate a copy of it.
var myConn = new XHConn();
After instantiating the object, it is good practice to check for success and act accordingly.
if (!myConn) // XMLHTTP not available. exit method/handle error.
After you know you have a valid connection to work with, you need to define a function that will fire after your connection is complete. Your function should take a single argument which will be the XMLHttpRequest object with its members intact. [see: XMLHTTPRequest members]
 var fnWhenDone = function (oXML) { alert(oXML.responseText); };
Then the final step is to make your actual connection using the connect member function of the XHConn object. The method takes the following arguments: 
sURL - String - The string that specifies the path to the resource to connect to. (Note: Cross-domain scripting is explicitly denied with XMLHTTP for security reasons. You may only access files within the same domain as the host file.)
sMethod - String - One of either "GET" or "POST", which specify the type of HTTP request to make.
sVars - String - A string of arguments, encoded in the form var1=val1&var2=val2&.... These are the variables that will be submitted along with the request.
fnDone - Function - A reference to a function that will be called upon completion of the HTTP request. A single argument, the XMLHTTPRequest object, will be passed to the function.
So a typical function call would look something like this:
myConn.connect("mypage.php", "POST", "foo=bar&baz=qux", fnWhenDone);
At this point your connection will be made and the results will be sent to your function. The two major members of the XMLHTTPRequest object that you will deal with are responseText and responseXML.
*/

var hxconn_obj = {
  myConn:      false,
  target:      false,
  id:      false
}

var fnWhenDone = function (oXML) {
    hxconn_obj.target  = document.getElementById( 'zmena'+hxconn_obj.id );
    hxconn_obj.target.innerHTML = oXML.responseText;
}

function expand (id) {
	hxconn_obj.id = id;
    hxconn_obj.MyConn = new XHConn();
    if( !hxconn_obj.MyConn ) return;
    hxconn_obj.MyConn.connect("./class/ajax_treemenu.php?ajax=1", "POST", "close=0&id_menu="+hxconn_obj.id, fnWhenDone);
}

function close2 (id) {
	hxconn_obj.id = id;
    hxconn_obj.MyConn = new XHConn();
    if( !hxconn_obj.MyConn ) return;
    hxconn_obj.MyConn.connect("./class/ajax_treemenu.php?ajax=1", "POST", "close=1&id_menu="+hxconn_obj.id, fnWhenDone);
}

