/**
* @file ajax_call.js
*	@version v 1.0 2007/3/15 20:52:20
* @copyright (c) 2005 - 2007 eifr.com
* @license http://www.gnu.org/copyleft/gpl.html gnu/gpl
* eifr is free software
*/


var XMLHttp = new Object();
 
XMLHttp._objPool = [];
XMLHttp._getInstance = function() 
{ 
	/*
	for (var i = 0; i < this._objPool.length; i ++) 
	{ 
	    alert(this._objPool[i].readyState);
	    if (this._objPool[i].readyState == 4) 
	    { 
	        return this._objPool[i]; 
	    } 
	} 
	*/
	this._objPool[this._objPool.length] = this._createObj(); 
	
	return this._objPool[this._objPool.length - 1]; 
}
XMLHttp._createObj = function () 
{ 
  if (window.XMLHttpRequest) 
  { 
		var objXMLHttp = new XMLHttpRequest(); 

  } 
  else 
  { 
    var MSXML = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP']; 
    for(var n = 0; n < MSXML.length; n ++) 
    { 
      try 
      { 
        var objXMLHttp = new ActiveXObject(MSXML[n]); 
        break; 
      } 
      catch(e) 
      { 
      } 
    } 
   }           

  return objXMLHttp; 
}
XMLHttp.sendReq = function (sendmethod, url, senddata, callback) 
{ 
  var objXMLHttp = this._getInstance(); 
	try 
  { 
      
    if (url.indexOf("?") > 0) 
    { 
      url += "&randnum=" + Math.random(); 
    } 
    else 
    { 
    	url += "?randnum=" + Math.random(); 
    }    
     
    objXMLHttp.onreadystatechange = function () 
    { 
      if (objXMLHttp.readyState == 4 && (objXMLHttp.status == 200 || objXMLHttp.status == 304)) 
      { 
          callback(objXMLHttp); 
      } 
    } 

    objXMLHttp.open(sendmethod, url, true); 
    objXMLHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
    objXMLHttp.send(senddata);

  } 
  catch(e) 
  { 
      alert(e); 
  } 

} 
  


