var open_requests = 0;



function AJAXRequest(method, url, data, process, processData) {

  //increment the number of open requests so we can track

  open_requests++;

  //alert(AJAXRequest.caller);

  var self = this;



  if (window.XMLHttpRequest)	// Moz et all

    self.AJAX = new XMLHttpRequest();

  else if (window.ActiveXObject)	// IE

    self.AJAX = new ActiveXObject("Microsoft.XMLHTTP");

  else

  {

    //js won't work like this, but we downgrade gracefully

//     if((navigator.appName.indexOf("Microsoft")!=-1))

  }

  self.AJAX.url = url;

  // default callback

  if (typeof process == 'undefined' || process == null)

    process = executeReturn;

  

  self.process = process;

  

  self.processData = processData;

  

  if (!method)

    method = "POST";

  

  method = method.toUpperCase();



  //alert(url);

  

  //top.main.asdf.document.write('numAJAXRequests: ' + top.main.numAJAXRequests + '\ncaller: ' + AJAXRequest.caller + '\n\n\n');

  self.AJAX.open(method, url, true);

  self.AJAX.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

  if(typeof self.processData == 'undefined' || self.processData == null)

    self.AJAX.onreadystatechange = function( ) {

      self.process(self.AJAX);

  }

  else

    self.AJAX.onreadystatechange = function () {

      self.process(self.AJAX, self.processData);

  }

  

  if (!data) 

  	data = ""; 

// alert(data);

  self.AJAX.send(data);



  return self.AJAX;

}


function swapImage(hid, iid, pe){

//     alert(hid);

    query = 'id=' + iid + '&pe=' + pe;

    new AJAXRequest('POST', 'ajax_picture_enlarge.php', query, parseSwapImage, hid);

}



function parseSwapImage(AJAX, processData){

  if (AJAX.readyState == 4){

    if (AJAX.status!=200){

//       alert(AJAX.status);

    }else{
    
//       alert(AJAX.responseText);

      document.getElementById(processData).innerHTML = AJAX.responseText;

    }

  }

}
