/**
* common dhtml functions
* these are handy functions i use all the time.
*
* by seth banks (webmaster at subimage dot com)
* http://www.subimage.com/
*
* up to date code can be found at http://www.subimage.com/dhtml/
*
* this code is free for you to use anywhere, just keep this comment block.
*/
/**
* x-browser event handler attachment and detachment
* th: switched first true to false per http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html
*
* @argument obj - the object to attach event to
* @argument evtype - name of the event - dont add "on", pass only "mouseover", etc
* @argument fn - function to call
*/
function addevent(obj, evtype, fn){
if (obj.addeventlistener){
obj.addeventlistener(evtype, fn, false);
return true;
} else if (obj.attachevent){
var r = obj.attachevent("on"+evtype, fn);
return r;
} else {
return false;
}
}
function removeevent(obj, evtype, fn, usecapture){
if (obj.removeeventlistener){
obj.removeeventlistener(evtype, fn, usecapture);
return true;
} else if (obj.detachevent){
var r = obj.detachevent("on"+evtype, fn);
return r;
} else {
alert("handler could not be removed");
}
}
/**
* code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
*
* modified 4/22/04 to work with opera/moz (by webmaster at subimage dot com)
*
* gets the full width/height because it's different for most browsers.
*/
function getviewportheight() {
if (window.innerheight!=window.undefined) return window.innerheight;
if (document.compatmode=='css1compat') return document.documentelement.clientheight;
if (document.body) return document.body.clientheight;
return window.undefined;
}
function getviewportwidth() {
var offset = 17;
var width = null;
if (window.innerwidth!=window.undefined) return window.innerwidth;
if (document.compatmode=='css1compat') return document.documentelement.clientwidth;
if (document.body) return document.body.clientwidth;
}
/**
* gets the real scroll top
*/
function getscrolltop() {
if (self.pageyoffset) // all except explorer
{
return self.pageyoffset;
}
else if (document.documentelement && document.documentelement.scrolltop)
// explorer 6 strict
{
return document.documentelement.scrolltop;
}
else if (document.body) // all other explorers
{
return document.body.scrolltop;
}
}
function getscrollleft() {
if (self.pagexoffset) // all except explorer
{
return self.pagexoffset;
}
else if (document.documentelement && document.documentelement.scrollleft)
// explorer 6 strict
{
return document.documentelement.scrollleft;
}
else if (document.body) // all other explorers
{
return document.body.scrollleft;
}
}