// -*- Mode:Javascript-Generic -*- // Copyright (C) 2005, Halloo Communciations, Inc. // All rights reserved. // var IPeriodicalExecuter = Class.create(); IPeriodicalExecuter.prototype = { initialize: function(callback, frequency) { this.callback = callback; this.frequency = frequency; this.currentlyExecuting = false; this.intervalId = 0; this.registerCallback(); }, registerCallback: function() { this.intervalId = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); }, onTimerEvent: function() { if (!this.currentlyExecuting) { try { this.currentlyExecuting = true; this.callback(); } finally { this.currentlyExecuting = false; } } }, clearCallback: function() { if (this.intervalId != 0) { window.clearInterval( this.intervalId); } } } /********* UTILITIES *********************************/ function URLEncode( plaintext) { // The Javascript escape and unescape functions do not correspond // with what browsers actually do... var SAFECHARS = "0123456789" + // Numeric "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic "abcdefghijklmnopqrstuvwxyz" + "-_.!~*'()"; // RFC2396 Mark characters var HEX = "0123456789ABCDEF"; var encoded = ""; for (var i = 0; i < plaintext.length; i++ ) { var ch = plaintext.charAt(i); if (ch == " ") { encoded += "+"; // x-www-urlencoded, rather than %20 } else if (SAFECHARS.indexOf(ch) != -1) { encoded += ch; } else { var charCode = ch.charCodeAt(0); if (charCode > 255) { alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" + "(URL encoding only supports 8-bit characters.)\n" + "A space (+) will be substituted." ); encoded += "+"; } else { encoded += "%"; encoded += HEX.charAt((charCode >> 4) & 0xF); encoded += HEX.charAt(charCode & 0xF); } } } // for return encoded; }; function getPageWidth() { if (typeof( window.innerWidth)=='number') return window.innerWidth; else if ( document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth; else return document.body.clientWidth; } function getPageHeight() { if (typeof( window.innerHeight)=='number') return window.innerHeight; else if ( document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight; else return document.body.clientHeight; } function getPosLeft() { return window.pageXOffset != null? window.pageXOffset: document.body.scrollLeft != null? document.body.scrollLeft:0;} function getPosTop() { return window.pageYOffset != null? window.pageYOffset: document.body.scrollTop != null? document.body.scrollTop:0;} function getPosRight() { return getPosLeft()+getPageWidth();} function getPosBottom() { return getPosTop()+getPageHeight();} function randomvalue(low, high) { return Math.floor(Math.random() * (1 + high - low) + low); }