return the top level doc for this browser return gBrowser.browsers[j].contentDocument; } } } return doc;};searchshield.getTopLevelWindow = function (){ // TODO: determine a method of doing this for IE, if necessary return mediator.getMostRecentWindow("navigator:browser");};//Event functionssearchshield.addListener = function (object, evtType, listener, useCapture){ useCapture = !!useCapture; if (object.addEventListener) { object.addEventListener(evtType, listener, useCapture); return true; } else if (object.attachEvent) { object.attachEvent("on"+evtType, listener); return true; } return false;};searchshield.cancelEvent = function (event){ event.cancelBubble = true; event.returnValue = false;};searchshield.doEvent = function (evtObj, evtTarget, evtName, evtType, bubbles, cancelable){ bubbles = !!bubbles; cancelable = !!cancelable; if (document.createEvent) { var evt = document.createEvent("Events"); evt.initEvent(evtName, bubbles, cancelable); evtTarget.dispatchEvent(evt); return true; } else if (document.createEventObject) { var evt = document.createEventObject(evtObj); evtTarget.fireEvent("on" + evtType, evt); return true; } return false;};searchshield.removeListener = function (object, evtType, listener, useCapture){ useCapture = !!useCapture; if (object.removeEventListener) { object.removeEventListener(evtType, listener, useCapture); return true; } else if (object.detachEvent) { object.detachEvent(evtType, listener); return true; } return false;};// HTML functionssearchshield.CleanupHTML = function (data){ if (data == null) return data; // cleanup html data, replace any new lines data = data.replace(/\r/g, ""); data = data.replace(/\n/g, ""); // escape any single quotes data = data.replace(/'/g, "\\'"); return data;};searchshield.removeHtmlTags = function (str){ var re = new RegExp('(<[^>]+>)','g'); var strStr = new String(str); if (!!strStr) return strStr.replace(re, ''); else return str; };// Browser functionssearchshield.elementSize = function (element){ //returns an array [sizeX, sizeY] var elemX; var elemY; elemX = parseInt(element.offsetWidth); elemY = parseInt(element.offsetHeight) return [elemX, elemY];};searchshield.GetFullBoundingRect = function (element){ if (!element) return; // get bounding rect for incoming element var elementRect = element.getBoundingClientRect(); var nextImg = null; var nextImgRect = null; // first check for another non-TextNode element after this one var siblingElement = searchshield.NextSiblingNode(element); if ( siblingElement && siblingElement.firstChild && siblingElement.id && siblingElement.id.indexOf("XPLSS_") != -1) { nextImg = siblingElement.firstChild; nextImgRect = nextImg.getBoundingClientRect(); } else { return elementRect; } if ((nextImgRect.top >= elementRect.bottom) && (nextImgRect.left <= elementRect.left)) { // images appear to be on seperate lines return elementRect; } // else merge the rects together into a new one var newRect = new function() { this.top=0; this.left=0; this.right=0; this.bottom=0; this.mid=0;}; newRect.top = Math.min(elementRect.top, nextImgRect.top); newRect.left= Math.min(elementRect.left, nextImgRect.left); newRect.right=Math.max(elementRect.right, nextImgRect.right); newRect.bottom=Math.max(elementRect.bottom, nextImgRect.bottom); newRect.mid = Math.min(elementRect.right, nextImgRect.left); return newRect;};searchshield.offsetLeft = function (element){ var offset = 0; while (element) { offset += element.offsetLeft; element = element.offsetParent; } return offset;};searchshield.offsetTop = function (element){ var offset = 0; while (element) { offset += element.offsetTop; element = element.offsetParent; } return offset;};searchshield.scrollSize = function (imageElem){ // returns an array [scrollX, scrollY, hasParentFrame] var scrollX; var scrollY; var hasParentFrame; // firefox if (window.pageXOffset && window.pageYOffset) { scrollX = window.pageXOffset; scrollY = window.pageYOffset; } else if (document.documentElement || document.body) { scrollX = document.documentElement.scrollLeft || document.body.scrollLeft; scrollY = document.documentElement.scrollTop || document.body.scrollTop; if (imageElem) { var frames = document.frames; if (frames) { for (var i=0; i < frames.length; i++) { var img; try { img = frames[i].document.getElementById(imageElem.id); } catch(domErr){} if (img != null) { scrollX = frames[i].document.documentElement.scrollLeft; scrollY = frames[i].document.documentElement.scrollTop; hasParentFrame = true; break; } } } } } else { scrollX = 0; scrollY = 0; } return [parseInt(scrollX,10), parseInt(scrollY,10), hasParentFrame];};searchshield.viewPortSize = function (){ // returns an array [width, height, scrollYWidth], where scrollYWidth is always 0 for IE var scrollXWidth