function createXMLHttpRequest() {
  var xmlReq = false;
  // branch for native XMLHttpRequest object
  if(window.XMLHttpRequest) {
    try {
      xmlReq = new XMLHttpRequest();
    } catch(e) {
      xmlReq = false;
    }
  // branch for IE/Windows ActiveX version
  } else if(window.ActiveXObject) {
    try {
      xmlReq = new  ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        xmlReq = new  ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        xmlReq = false;
      }
    }
  }
  return xmlReq;
}

var userAgent = { };
userAgent.isAJAX  = (createXMLHttpRequest()?true:false);
userAgent.isMozilla  = (navigator.userAgent.match(/\bGecko\b/));
userAgent.isOpera  = (navigator.userAgent.match(/\bOpera\b/));
userAgent.isInternetExplorer  =
  (navigator.userAgent.match(/\bMSIE\b/) && !userAgent.isOpera);

function callServer(method, url, data, dataType, func, arg, arg2) {
  if (!method) method='GET';
  if (data && !dataType)  dataType='application/xml;';
  var xmlReq = createXMLHttpRequest();
  if(xmlReq) {
    xmlReq.onreadystatechange = function() {
      // only if xmlReq shows "loaded"
      if (xmlReq.readyState == 4) {
        func(arg, arg2, xmlReq.responseText,  xmlReq.responseXML,
             xmlReq.status, xmlReq.statusText);
      }
    };
    xmlReq.open(method, url, true);
    if (userAgent.isMozilla) dataType=dataType+'charset=utf-8;';
    if (userAgent.isInternetExplorer) dataType = 'application/xml';
    xmlReq.setRequestHeader('Content-Type',  dataType);
    xmlReq.send(data);
    return false;
  }
  return true;
}

function show_gal(element, user_id, responseText, responseXML, statusCode, statusText)
{
  if ((statusCode==200) || (statusCode==201))
  {
    document.getElementById('gallery').innerHTML = responseText;
    $("div#gallery").gallery();
  }
  else
  {
    alert("Загрузить информацию не  удалось: "+statusText.toString());
  }
}

function load_gal(gal_name)
{
  gal_name = gal_name.toString();
  callServer(null,"main_gallery.php?gn=" + gal_name, null, null, show_gal, null);
  return false;
}