/* ******************************************************************************* Copyright (c) 2005, 2006 John Ha ******************************************************************************* This work is licensed under the Creative Commons Attribution License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/2.5/ ******************************************************************************* If this code has helped you in anyway, any acknowledgement would be appreciated ******************************************************************************* */ /* Attach event handler to object */ function addEvent(obj, evType, fn, cap) { if (obj.addEventListener) { obj.addEventListener(evType, fn, cap); return true; } else if (obj.attachEvent) { var r = obj.attachEvent('on' + evType, fn); return r; } else alert('Handler could not be attached'); } /* Remove event handler reference from object */ function removeEvent(obj, evType, fn, cap){ if (obj.removeEventListener){ obj.removeEventListener(evType, fn, cap); return true; } else if (obj.detachEvent){ var r = obj.detachEvent('on' + evType, fn); return r; } else alert("Handler could not be removed"); } /* Waits for object to become available before executing target function, or else times out. fn: function (string) objID: object ID (string) t: timeout (milliseconds) e: output error message (boolean) */ function wait4obj(fn, objID, t, e) { var n = 20; t > 0 ? document.getElementById(objID) ? eval(fn) : setTimeout("wait4obj('" + fn + "', '" + objID + "', " + (t - n) + ", " + e + ")", n) /* Output error message? */ : e ? alert(fn + ' timed out.\n[' + objID + '] not found!') : 0; } /* setTimeout is used to make sure target functions are executed completely independent from event handler, since certain code balks when placed within an event handler. fn: function (string) objID: object ID (string) t: timeout (milliseconds) e: output error message (boolean) */ function schedule(fn, objID, t, e) { // Attach onload... addEvent(window, 'load', function () { // Look for object to attach to? objID ? /* Yes, then make sure object exists... */ document.getElementById(objID) ? /* If object found... */ eval('setTimeout("' + fn + '", 0)') /* Else wait till object exists or timeout */ : wait4obj(fn, objID, (t ? t : 1000), e) /* Object not specified - just attach on load handler */ : eval('setTimeout("' + fn + '", 0)'); }, false); } function setCookie(cookieName,cookieValue,nDays) { var today = new Date(); var expire = new Date(); if (nDays==null || nDays==0) nDays = 1; expire.setTime(today.getTime() + 3600000*24*nDays); document.cookie = cookieName + '=' + escape(cookieValue) + ';expires=' + expire.toGMTString(); } function readCookie(cookieName) { var theCookie = '' + document.cookie; var ind = theCookie.indexOf(cookieName); if (ind == -1 || cookieName == '') return ''; var ind1 = theCookie.indexOf(';', ind); if (ind1 == -1) ind1 = theCookie.length; if (ind + cookieName.length == theCookie.indexOf(';', ind)) return ''; else return unescape(theCookie.substring(ind + cookieName.length + 1, ind1)); } // delay in milliseconds function delay(t) { date = new Date(); var curDate = null; do curDate = new Date(); while(curDate - date < t); }