
if(typeof XMLHttpRequest=="undefined")XMLHttpRequest=function(){try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(e){}
try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(e){}
try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(e){}
try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}
throw new Error("This browser does not support XMLHttpRequest.")};tunnel={seq:0,tunnel_url:"/mp/ajaxgbproxy.cgi",id:0,inbuf:"",inbuf_start:0,outbuf:"",port:0,server:"",tunnel_port:0,intAt:function(s,i)
{retval=(s.charCodeAt(i)<<24)+(s.charCodeAt(i+1)<<16)+(s.charCodeAt(i+2)<<8)+s.charCodeAt(i+3);if(retval>2147483647)
{retval-=4294967296;}
return(retval);},uintAt:function(s,i)
{return((s.charCodeAt(i)<<24)+(s.charCodeAt(i+1)<<16)+(s.charCodeAt(i+2)<<8)+s.charCodeAt(i+3));},shortAt:function(s,i)
{var retval=(s.charCodeAt(i)<<8)+s.charCodeAt(i+1);if(retval>32767)
{retval-=65536}
return(retval);},ushortAt:function(s,i)
{return((s.charCodeAt(i)<<8)+s.charCodeAt(i+1));},open:function(s,tp,p)
{var d=new Date();var t=tunnel;t.seq=d.getMilliseconds();t.port=p;t.tunnel_port=tp;t.server=s;var url="http://"+t.server;if(t.tunnel_port!=80)
{url+=":"+t.tunnel_port;}
url+=t.tunnel_url+"?cmd=open?id=0?port="+t.port+"?seq="+t.seq;var req=new XMLHttpRequest();req.open('POST',url,false);req.send(null);if((req.readyState==4)&&(req.status==200))
{var rt=decodeBase64(req.responseText);t.id=t.intAt(rt,0);}
else
{alert("error connecting to server");return false;}},close:function()
{var t=tunnel;if(t.id<=0)
{return;}
var url="http://"+t.server;if(t.tunnel_port!=80)
{url+=":"+t.tunnel_port;}
url+=t.tunnel_url+"?cmd=close?id="+t.id+"?port="+t.port+"?seq="+t.seq;var req=new XMLHttpRequest();req.open('POST',url,false);req.send(null);t.id=0;t.inbuf="";t.outbuf="";},get:function(minbytes,dontwait)
{var t=tunnel;if(t.id<=0)
{return;}
if(t.inbuf_start>0&&t.inbuf_start>=t.inbuf.length)
{t.inbuf="";t.inbuf_start=0;}
while(t.inbuf.length-t.inbuf_start<minbytes)
{var url="http://"+t.server;if(t.tunnel_port!=80)
{url+=":"+t.tunnel_port;}
url+=t.tunnel_url+"?cmd=get?id="+t.id+"?port="+t.port+"?seq="+t.seq;++t.seq;var req=new XMLHttpRequest();req.open('POST',url,dontwait!=null);req.setRequestHeader("Content-Length",0);if(dontwait)
{req.onreadystatechange=function()
{if(req.readyState==4)
{if(req.status==200)
{t.inbuf+=decodeBase64(req.responseText);}
else if(req.status==0||req.status==12031)
{t.id=0;return;}}}}
req.send(null);if(dontwait)
{break;}
if((req.readyState==4)&&(req.status==200))
{t.inbuf+=decodeBase64(req.responseText);}
else
{}}},post:function()
{var t=tunnel;if(t.outbuf.length<=0)
{return;}
var url="http://"+t.server;if(t.tunnel_port!=80)
{url+=":"+t.tunnel_port;}
url+=t.tunnel_url+"?cmd=post?id="+t.id+"?port="+t.port+"?seq="+t.seq;++t.seq;var req=new XMLHttpRequest();req.open('POST',url,false);var data=encodeBase64(t.outbuf);req.setRequestHeader("Content-Length",data.length);req.send(data);t.outbuf="";if((req.readyState==4)&&(req.status==200))
{t.inbuf=t.inbuf+decodeBase64(req.responseText);}},readInt:function()
{var t=tunnel;t.get(4);var retval=t.intAt(t.inbuf,t.inbuf_start);t.inbuf_start+=4;return(retval);},readUint:function()
{var t=tunnel;t.get(4);var retval=t.uintAt(t.inbuf,t.inbuf_start);t.inbuf_start+=4;return(retval);},readShort:function()
{var t=tunnel;t.get(2);var retval=t.shortAt(t.inbuf,t.inbuf_start);t.inbuf_start+=2;return(retval);},readUshort:function()
{var t=tunnel;t.get(2);var retval=t.ushortAt(t.inbuf,t.inbuf_start);t.inbuf_start+=2;return(retval);},readByte:function()
{var t=tunnel;t.get(1);var retval=t.inbuf.charCodeAt(t.inbuf_start);++t.inbuf_start;if(retval>127)
{retval-=256;}
return(retval);},readUbyte:function()
{var t=tunnel;t.get(1);var retval=t.inbuf.charCodeAt(t.inbuf_start);++t.inbuf_start;return(retval);},readString:function()
{var t=tunnel;var len=t.readUshort();var s="";if(len>0)
{t.get(len);s=t.inbuf.substr(t.inbuf_start,len);t.inbuf_start+=len;}
return(s);},readStringSize:function(len)
{var t=tunnel;t.get(len);var s=t.inbuf.substr(t.inbuf_start,len);t.inbuf_start+=len;return(s);},writeInt:function(i)
{var s=String.fromCharCode((i>>24)&0xff);s=s.concat(String.fromCharCode((i>>16)&0xff));s=s.concat(String.fromCharCode((i>>8)&0xff));s=s.concat(String.fromCharCode(i&0xff));tunnel.outbuf=tunnel.outbuf.concat(s);},writeShort:function(i)
{var s=String.fromCharCode((i>>8)&0xff);s=s.concat(String.fromCharCode(i&0xff));tunnel.outbuf=tunnel.outbuf.concat(s);},writeByte:function(i)
{var s=String.fromCharCode(i&0xff);tunnel.outbuf=tunnel.outbuf.concat(s);},writeString:function(s)
{tunnel.writeShort(s.length);tunnel.outbuf=tunnel.outbuf.concat(s);},writeStringOnly:function(s)
{tunnel.outbuf=tunnel.outbuf.concat(s);},connected:function()
{return(tunnel.id!=0);}};
