gwwa.ns("gwwa.polling");gwwa.ns("gwwa.polling.xmlhttp");gwwa.polling.xmlhttp.handlers=[];gwwa.polling.xmlhttp.CONNECTION_TIMEOUT=60*1000;gwwa.polling.xmlhttp.grassCatcherTimer=-1;gwwa.polling.xmlhttp.register=function(handlerInfo){gwwa.polling.xmlhttp.handlers[gwwa.polling.xmlhttp.handlers.length]=handlerInfo};gwwa.polling.xmlhttp.reset=function(){gwwa.polling.xmlhttp.handlers=[]};var idx=1;gwwa.polling.xmlhttp.getPollURL=function(){var sURL=homeURL+"/poll?User.context="+userContext+"&Url.idx="+idx+++"&merge=jpoll&JSON.User.interface=&action=Poll.Check";sURL+=util.getForceUpdateURL();return sURL};gwwa.polling.xmlhttp.handleSlap=function(slap){var key=slap.key;for(var i=0;i<gwwa.polling.xmlhttp.handlers.length;i++){handler=gwwa.polling.xmlhttp.handlers[i];for(var j=0;j<handler.keys.length;j++){if(handler.keys[j]===key&&handler.handler){try{var ret=handler.handler(slap)}catch(err){}}}}};gwwa.polling.xmlhttp.handleSlapPollInfo=function(pollInfoList){for(var i=0;i<gwwa.polling.xmlhttp.handlers.length;i++){handler=gwwa.polling.xmlhttp.handlers[i];try{var ret=handler.handler(pollInfoList)}catch(err){console.log(err)}}};var request=undefined;gwwa.polling.xmlhttp.poll=function(){if(request){request.abort()}var url=gwwa.polling.xmlhttp.getPollURL();request=new XMLHttpRequest();request.open("GET",url,true);request.timeout=gwwa.polling.xmlhttp.CONNECTION_TIMEOUT;request.ontimeout=gwwa.polling.xmlhttp.timeoutFired;request.setRequestHeader("Content-Type","application/x-javascript;");request.onreadystatechange=function(){try{if(request.readyState==4){if(request.status==200){var resp=null;if(request.responseText){if(request.responseText.indexOf("WEBACC_LOGIN_PAGE")>0){request.responseText="TIMED_OUT"}else{resp=gwwa.parseJSON(request.responseText,true);if(resp&&resp.slap){console.log("resp.slap.slapIndex: "+resp.slap.slapIndex);if(resp.slap.key==="TIMED_OUT"||resp.slap.key==="END"){request=null}else{gwwa.polling.xmlhttp.handleSlap(resp.slap)}}else{if(resp&&resp.length>0){gwwa.polling.xmlhttp.handleSlapPollInfo(resp)}}}}if(resp!==null&&request&&request.responseText!=="TIMED_OUT"){window.setTimeout(gwwa.polling.xmlhttp.poll,1000)}request=null}else{if(request!=null){request.abort();request=null}}}}catch(e2){request=null;console.log(e2.stack)}};try{request.send(null)}catch(e){console.log(e.stack)}};gwwa.polling.xmlhttp.timeoutFired=function(){gwwa.polling.xmlhttp.poll()};gwwa.polling.xmlhttp.master=function(){var ca=readCookie("SA");if((ca===null||ca==="1")&&!request){try{gwwa.polling.xmlhttp.poll()}catch(e){util.log(e.stack)}}else{if(ca==="0"){var mainWindow=getMainWindow();if(mainWindow){mainWindow.location.href=homeURL}}}};gwwa.polling.xmlhttp.abortLastTransaction=function(){if(request){request.abort()}};gwwa.websocket={};gwwa.websocket.socket=null;gwwa.websocket.connect=function(host){if("WebSocket" in window){gwwa.websocket.socket=new WebSocket(host)}else{if("MozWebSocket" in window){gwwa.websocket.socket=new MozWebSocket(host)}else{console.log("Error: WebSocket is not supported by this browser.");gwwa.polling.xmlhttp.connect()}}gwwa.websocket.socket.onopen=function(){console.log("Info: WebSocket connection opened.")};gwwa.websocket.socket.onclose=function(){console.log("Info: WebSocket closed.")};gwwa.websocket.socket.onmessage=function(message){slap=gwwa.parseJSON(message.data);gwwa.polling.xmlhttp.handleSlap(slap.slap)}};gwwa.websocket.initialize=function(){var protocol=window.location.protocol=="http:"?"ws://":"wss://";var url=protocol+window.location.host+":8080/gw/pollws?User.context="+userContext;gwwa.websocket.connect(url)};