function XMLHTTPRequestQueue(nd,od){if(typeof nd=="undefined"||nd<1){nd=1;}
if(typeof od=="undefined"){od=false;}
this.requestFactory=new XMLHTTPRequestFactory();this.queue=new Array();this.pool=new Array();var i;for(i=0;i<nd;i++){var hb=this.requestFactory.XMLHTTPRequest();this.pool.push(hb);}
this.enqueue=function(nb){if(typeof nb.action=="undefined"||typeof nb.action.method=="undefined"||typeof nb.action.url=="undefined"||typeof nb.stateChangeHandler=="undefined"){throw"XMLHTTPRequestQueue.enqueue: context.action.url, context.action.method, or context.stateChangeHandler is missing";}
this.queue.push(nb);this.run();}
this.run=function(){if(this.queue.length>0&&this.pool.length>0){var hb;while(typeof(hb=this.pool.pop())!="undefined"){var nb;if(nb=this.queue.shift()){this.execute(hb,nb,this);}
else{this.pool.push(hb);break;}
}
}
}
this.execute=function(hb,nb,pd){hb.open(nb.action.method,nb.action.url,true);if(nb.isForm){hb.setRequestHeader("Content-Type","application/x-www-form-urlencoded");}
if(nb.header){if(nb.header.length){var i;for(i=0;i<nb.header.length;i++){hb.setRequestHeader(nb.header[i].name,nb.header[i].value);}
}
else{hb.setRequestHeader(nb.header.name,nb.header.value);}
}
var bb=nb.data;if(typeof bb=="undefined"){bb=null;}
if(nb.stateChangeHandler){hb.onreadystatechange=function(){nb.stateChangeHandler(hb,nb.event);if(hb.readyState==4){pd.recycle(hb);pd.runNext();}
}
;}
hb.send(bb);}
;this.recycle=function(hb){if(this.requestFactory.ie||!od){this.pool.push(this.requestFactory.XMLHTTPRequest());}
else{hb.onreadystatechange=undefined;this.pool.push(hb);}
}
this.runNext=function(){if(this.requestFactory.ie||!od){this.run();}
else{window.setTimeout(this.run,0);}
}
}
function XMLHTTPRequestFactory(qd){if(typeof qd=="undefined"){qd=10;}
var pd=this;this.pool=new Array();this.XMLHTTPRequest=function(){if(window.XMLHttpRequest){this.ie=false;return new XMLHttpRequest();}
else if(window.ActiveXObject){this.ie=true;return new ActiveXObject("Microsoft.XMLHTTP");}
}
this.acquire=function(rd,event){var hb;hb=this.pool.pop();if(typeof hb=="undefined"){hb=this.XMLHTTPRequest();}
if(hb&&rd){hb.onreadystatechange=function(){rd(hb,event);if(hb.readyState==4){pd.release(hb);}
}
;}
return hb;}
this.release=function(sd){if(!this.ie&&this.pool.length<=qd){sd.onreadystatechange=undefined;this.pool.push(sd);}
}
this.size=function(){return this.pool.length;}
}
