g = function (name){
return document.getElementById(name);
}
window.getScrollXY = function () {
var self = window;
var x,y;
if (self.pageYOffset) // all except Explorer
{
x = self.pageXOffset;
y = self.pageYOffset;
}
else if (document.documentElement && document.documentElement.scrollTop)
// Explorer 6 Strict
{
x = document.documentElement.scrollLeft;
y = document.documentElement.scrollTop;
}
else if (document.body) // all other Explorers
{
x = document.body.scrollLeft;
y = document.body.scrollTop;
}
return {x:x,y:y};
};
window.getInnerSize = function () {
var self = window;
var x,y;
if (self.innerHeight) // all except Explorer
{
x = self.innerWidth;
y = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
x = document.documentElement.clientWidth;
y = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
x = document.body.clientWidth;
y = document.body.clientHeight;
}
return { w : x, h: y };
};
window.getPageSize = function () {
var x,y;
var test1 = document.body.scrollHeight;
var test2 = document.body.offsetHeight
if (test1 > test2) // all but Explorer Mac
{
x = document.body.scrollWidth;
y = document.body.scrollHeight;
}
else // Explorer Mac;
//would also work in Explorer 6 Strict, Mozilla and Safari
{
x = document.body.offsetWidth;
y = document.body.offsetHeight;
}
return { w : x, h: y };
}
/* Adopted from http://www.quirksmode.org/dom/getstyles.html, the license seems
to be *almost* public domain, all reasonably foreseeable uses of the following
code does not seem to infringe upon the license. See http://www.quirksmode.org/about/copyright.html: */
getStyle = function (el,styleProp)
{
var x = el;
if (x.currentStyle)
var y = x.currentStyle[styleProp];
else if (window.getComputedStyle)
var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
return y;
}
var ua = navigator.userAgent.toLowerCase(),
isOpera = (ua.indexOf('opera') > -1),
isSafari = (ua.indexOf('safari') > -1),
isGecko = (!isOpera && !isSafari && ua.indexOf('gecko') > -1),
isIE = (!isOpera && ua.indexOf('msie') > -1);
document.getElementSize = function (elem) {
/***
MochiKit.DOM 1.3.1
See for documentation, downloads, license, etc.
(c) 2005 Bob Ippolito. All rights Reserved.
***/
if (getStyle(elem, 'display') != 'none') {
return {w:(elem.offsetWidth || 0), h: (elem.offsetHeight || 0)};
}
var s = elem.style;
var originalVisibility = s.visibility;
var originalPosition = s.position;
s.visibility = 'hidden';
s.position = 'absolute';
s.display = '';
var originalWidth = elem.offsetWidth;
var originalHeight = elem.offsetHeight;
s.display = 'none';
s.position = originalPosition;
s.visibility = originalVisibility;
return {w:originalWidth,h:originalHeight};
};
document.getElementPosition = function (elem) {
/***
MochiKit.DOM 1.3.1
See for documentation, downloads, license, etc.
(c) 2005 Bob Ippolito. All rights Reserved.
***/
if (!elem) return undefined;
var c = {x:0,y:0};
var box = null;
var parent = null;
var d = document;
var de = d.documentElement;
var b = d.body;
if (elem.getBoundingClientRect) { // IE shortcut
/*
The IE shortcut is off by two:
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/getboundingclientrect.asp
*/
box = elem.getBoundingClientRect();
c.x += box.left +
(de.scrollLeft || b.scrollLeft) -
(de.clientLeft || b.clientLeft);
c.y += box.top +
(de.scrollTop || b.scrollTop) -
(de.clientTop || b.clientTop);
} else if (d.getBoxObjectFor) { // Gecko shortcut
box = d.getBoxObjectFor(elem);
c.x += box.x;
c.y += box.y;
} else if (elem.offsetParent) {
c.x += elem.offsetLeft;
c.y += elem.offsetTop;
parent = elem.offsetParent;
if (parent != elem) {
while (parent) {
c.x += parent.offsetLeft;
c.y += parent.offsetTop;
parent = parent.offsetParent;
}
}
/*
Opera < 9 and old Safari (absolute) incorrectly account for
body offsetTop and offsetLeft.
*/
var ua = navigator.userAgent.toLowerCase();
if ((typeof(opera) != "undefined" && parseFloat(opera.version()) < 9) ||
(ua.indexOf('chrome') != -1) ||
(ua.indexOf('safari') != -1 && self.computedStyle(elem, 'position') == 'absolute')) {
c.x -= b.offsetLeft;
c.y -= b.offsetTop;
}
}
while (parent && parent.tagName != 'BODY' &&
parent.tagName != 'HTML') {
c.x -= parent.scrollLeft;
c.y -= parent.scrollTop;
if (parent.parentNode) {
parent = parent.parentNode;
} else {
parent = null;
}
}
return c;
};
document.getMousePos = function(e) {
var posx = 0;
var posy = 0;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
} else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
// posx and posy contain the mouse position relative to the document
// Do something with this information
return {x:posx, y:posy};
}
hookevent = function(obj,ev,func){
obj.attachEvent?obj.attachEvent('on'+ev,func):obj.addEventListener(ev,func,false);
}
unhookevent = function (obj,ev,func){
obj.detachEvent?obj.detachEvent('on'+ev,func):obj.removeEventListener(ev,func,false);
}