// (c) 2004-2006 Rob Rohan, Richard Applebaum, and Barney Boisvert

if(typeof COLLECTIONS_VERSION=="undefined"||typeof BROWSER_SNIFFER_VERSION=="undefined")
{alert("Fatal Error: Gateway Missing Required Libraries");throw new Error("gateway.js Missing Required Libraries");}
var GATEWAY_VERSION="0.1";function HTTPConnectFactory(){;}
HTTPConnectFactory.prototype.getInstance=function getInstance()
{var gw_http_request=null;if(window.ActiveXObject){try{gw_http_request=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{gw_http_request=new ActiveXObject("Microsoft.XMLHTTP");}catch(ex){throw new Error("IE browser, but xmlhttp create failed: "+ex);}}}else{try{gw_http_request=new XMLHttpRequest();if(gw_http_request.readyState==null){gw_http_request.readyState=1;gw_http_request.addEventListener("load",function(){gw_http_request.readyState=4;if(typeof gw_http_request.onreadystatechange=="function")
gw_http_request.onreadystatechange();},false);}}catch(e){throw new Error("Gecko browser, but xmlhttp create failed: "+ex);}}
if(gw_http_request==null)
{throw new Error("HTTPConnect::createInstance(): Unable to create HTTPConnect object");}
return gw_http_request;};function JSRemote(connection,asyn)
{this.connection=connection;this.loading=false;this.async=asyn;this.username=null;this.password=null;this.doRequest=function(params){log.info("doRequest to "+params.url);this.loading=true;var conn=this.connection;var load=this.loading;var finaljsr=this;var finaltimeout=setTimeout("alert")
if(params.username!=null&&params.username!=null)
conn.open(params.method,params.url,this.async,params.username,params.password);else
conn.open(params.method,params.url,this.async);if(this.async){conn.onreadystatechange=function(){if(conn.readyState==4){if(conn.status==200){log.info("response: ]"+conn.responseText+"[");params.handler(conn);}else{try{params.error_handler(conn);}catch(e){throw Error(e);}}
finaljsr.loading=false;load=false;}}}
if(!params.body)
params.body="nothing";else{conn.setRequestHeader("Content-Length",""+params.body.length);if(params.body.indexOf("<?")==0)
conn.setRequestHeader("Content-Type","text/xml; charset="+((params.encoding)?params.encoding:"utf-8"));}
conn.setRequestHeader("XLibrary","Neuromancer 1.5");if(typeof params.extra_headers=="object"){for(var i in params.extra_headers){conn.setRequestHeader(i,params.extraHeaders[i]);}}
conn.send(params.body+"");if(!this.async){params.handler(conn);load=false;}};this.doGetRequest=function(url,func_handler)
{log.info("doGetRequest to: "+url);this.loading=true;var conn=this.connection;var load=this.loading;var finaljsr=this;if(this.username!=null&&this.password!=null)
conn.open("GET",url,this.async,this.username,this.password);else
conn.open("GET",url,this.async);if(this.async)
{conn.onreadystatechange=function()
{if(conn.readyState==4)
{if(conn.status==200)
{func_handler(conn.responseText,conn);finaljsr.loading=false;}
else
{throw new Error("There was a problem retrieving the data from the server:\n"+conn.statusText);}
load=false;}}}
conn.send("nothing");if(!this.async){func_handler(conn.responseText,conn);load=false;}};this.doFormPostRequest=function(url,fields,handler){var body="";var headers=new Object();var boundary="neuro"+Math.random();for(var i in fields){body+="--"+boundary+"\nContent-Disposition: form-data;name=\""+i+"\"\n";body+="\n";body+=fields[i]+"\n";body+="\n";}
body+="--"+boundary+"--";headers["Content-Type"]="multipart/form-data; boundary="+boundary;this.doPostRequest(url,handler,body,headers);}
this.doPostRequest=function(url,func_handler,bodyinfo,extraHeaders)
{log.info("doPostRequest to "+url);log.info("using pipe: "+this.connectionid);this.loading=true;var conn=this.connection;var load=this.loading;var finaljsr=this;var finaltimeout=setTimeout("alert")
if(this.username!=null&&this.password!=null)
conn.open("POST",url,this.async,this.username,this.password);else
conn.open("POST",url,this.async);if(this.async)
{conn.onreadystatechange=function()
{if(conn.readyState==4)
{log.info("response on pipe: "+finaljsr.connectionid);log.info("response: ]"+conn.responseText+"[");func_handler(conn.responseText,conn);load=false;finaljsr.loading=false;}}}
if(bodyinfo=="")
bodyinfo="nothing";conn.setRequestHeader("Content-Length",""+bodyinfo.length);conn.setRequestHeader("XLibrary","Neuromancer 1.5");if(bodyinfo.indexOf("<?")==0)
conn.setRequestHeader("Content-Type","text/xml; charset=utf-8");if(typeof extraHeaders=="object"){for(var i in extraHeaders){conn.setRequestHeader(i,extraHeaders[i]);}}
conn.send(bodyinfo+"");if(!this.async)
{func_handler(conn.responseText,conn);load=false;}};this.doSoapPost=function(url,func,func_handler,xmlinfo)
{log.info("doSoapPost to: "+url+" function: "+func);this.loading=true;var conn=this.connection;var load=this.loading;if(conn==null)
throw new Error("Connection problem in SoapPost");try
{conn.open("POST",url,this.async);if(this.async)
{conn.onreadystatechange=function()
{if(conn.readyState==4)
{if(conn.status!="200")
{conn.abort();}
else
{func_handler(conn.responseText,conn);load=false;}}}}
if(conn.readyState!=2&&conn.readyState!=3)
{if(func!=null&&func!="")
conn.setRequestHeader("SOAPAction",func);conn.setRequestHeader("Content-Type","application/soap+xml; charset=utf-8");conn.setRequestHeader("Content-Length",""+xmlinfo.toString().length);conn.send(xmlinfo.toString());}
if(!this.async)
{func_handler(conn.responseText,conn);load=false;}}
catch(e)
{conn.send(null);}};}