// must-have functions. function isIPhone( ) { // test for iPhone and iPod Touch var iPhoneCheck = /iPhone|iPod/; var b_version=navigator.appVersion; return iPhoneCheck.test(b_version); } // general data container. data = { scrollFudgeFactor: isIPhone( ) ? 11 : -5 }; listener = new Listen(); serverProxy = new ServerProxy( "http://scramboni.com/Byteclub/component.op" ); function $(element) { if (arguments.length > 1) { for (var i = 0, elements = [], length = arguments.length; i < length; i++) elements.push($(arguments[i])); return elements; } if (typeof element == 'string') element = document.getElementById(element); return element; }; /* * */ AjaxUtils = new Object( ); AjaxUtils.toJSON = function(req) { try { var json = AjaxUtils.getHeader(req, 'X-JSON'); return json ? eval('(' + json + ')') : null; } catch (e) { return null } } AjaxUtils.getHeader = function(req, name) { try { return req.getResponseHeader(name); } catch (e) { return null } } /* * */ function Listen( ) { var url = "http://scramboni.com/Byteclub/listen.op"; var watchdogTimerId = null; var shutdown = false; /* * */ function execute_listen( ) { if ( shutdown ) { return; } if ( watchdogTimerId != null ) { clearTimeout( watchdogTimerId ); } watchdogTimerId = setTimeout( execute_listen, 35000 ); AjaxRequest.post( { url: url, //timeout: 10000, parameters: { qid: "$qid" }, onSuccess: function( transport ) { if ( transport.responseText != null ) { messages = eval( transport.responseText ); if ( typeof messages == 'object' ) { for( var len = 0; len < messages.length; ++len ) { var hash = messages[len]; try { //var script = hash['operation'] + "(" + JSON.stringify( hash ) + ")"; var script = hash; eval( script ); } catch( ex ) { //alert( "Exception while eval'ing [" + script + "]\n" + ex ); } } } } // reschedule call again. setTimeout( execute_listen, 1000 ); }, onError: function( transport ) { // reschedule call again. setTimeout( execute_listen, 1000 ); }, onTimeout: function( transport ) { // reschedule call again. setTimeout( execute_listen, 1000 ); } }); } /* * */ this.start = function( ) { execute_listen( ); } this.stop = function( ) { if ( watchdogTimerId != null ) { clearTimeout( watchdogTimerId ); watchdogTimerId = null; } shutdown = true; } } /* * Server rpc proxy object. */ function ServerProxy( url ) { var url = url; var timerId = null; this.send = function( args, onResultCallback ) { internal_send( args, onResultCallback ); } function internal_send( args, onResultCallback ) { // cancel pending call if scheduled. if ( timerId !== null ) { clearTimeout( timerId ); timerId = null; } AjaxRequest.post( { url: url, parameters: {json: JSON.stringify( args )}, onSuccess: function( transport ) { if ( typeof(onResultCallback) == "function") { onResultCallback( "ok", transport.responseText ); } }, onError: function( transport ) { if ( typeof(onResultCallback) == "function") { onResultCallback( "error", transport.responseText ); return; } timerId = setTimeout( function( ) { internal_send( args, onResultCallback ); }, 500 ); } }); } } function forced_logout( args ) { if ( args.reason == "LOGGEDIN_ELSEWHERE" ) { listener.stop( ); alert( "You logged in from a different location." ); window.document.location = "http://scramboni.com/Byteclub/"; } } function getCookie( cookieName ) { var results = document.cookie.match('(^|;) ?'+cookieName+'=([^;]*)(;|$)'); return ( results ? unescape ( results[2] ) : null ); } function setCookie( cookieName, cookieValue, expires, path ) { var cookieString = cookieName + "=" + cookieValue + ";"; if ( expires ) { cookieString += " expires=" + expires.toGMTString() + ";"; } if ( path ) { cookieString += " path=" + path; } document.cookie = cookieString; }