/**
* this derivative version of submodal can be downloaded from http://gabrito.com/files/submodal/
* original by seth banks (webmaster at subimage dot com) http://www.subimage.com/
* contributions by eric angel (tab index code), scott (hiding/showing selects for ie users), todd huss (submodal class on hrefs, moving div containers into javascript, phark method for putting close.gif into css), thomas risberg (safari fixes for scroll amount), dave campbell (improved parsing of submodal-width-height class)
*/
// popup code
var gpopupmask = null;
var gpopupcontainer = null;
var gpopframe = null;
var greturnfunc;
var gpopupisshown = false;
var ghideselects = false;
var gloading = "/js/loading.html";
var gtabindexes = new array();
// pre-defined list of tags we want to disable/enable tabbing into
var gtabbabletags = new array("a","button","textarea","input","iframe");
// if using mozilla or firefox, use tab-key trap.
if (!document.all) {
document.onkeypress = keydownhandler;
}
/**
* override the loading page from loading.html to something else
*/
function setpopuploadingpage(loading) {
gloading = loading;
}
/**
* initializes popup code on load.
*/
function initpopup() {
// add the html to the body
var body = document.getelementsbytagname('body')[0];
var popmask = document.createelement('div');
popmask.id = 'popupmask';
var popcont = document.createelement('div');
popcont.id = 'popupcontainer';
popcont.innerhtml = '' +
'
';
body.appendchild(popmask);
body.appendchild(popcont);
gpopupmask = document.getelementbyid("popupmask");
gpopupcontainer = document.getelementbyid("popupcontainer");
gpopframe = document.getelementbyid("popupframe");
// check to see if this is ie version 6 or lower. hide select boxes if so
// maybe they'll fix this in version 7?
var brsversion = parseint(window.navigator.appversion.charat(0), 10);
if (brsversion <= 6 && window.navigator.useragent.indexof("msie") > -1) {
ghideselects = true;
}
// add onclick handlers to 'a' elements of class submodal or submodal-width-height
var elms = document.getelementsbytagname('a');
for (i = 0; i < elms.length; i++) {
if (elms[i].classname.indexof("submodal") >= 0) {
elms[i].onclick = function(){
// default width and height
var width = 400;
var height = 200;
// parse out optional width and height from classname
var startindex = this.classname.indexof("submodal");
var endindex = this.classname.indexof(" ", startindex);
if (endindex < 0) {
endindex = this.classname.length;
}
var clazz = this.classname.substring(startindex, endindex);
params = clazz.split('-');
if (params.length == 3) {
width = parseint(params[1]);
height = parseint(params[2]);
}
showpopwin(this.href,width,height,null); return false;
}
}
}
}
addevent(window, "load", initpopup);
/**
* @argument width - int in pixels
* @argument height - int in pixels
* @argument url - url to display
* @argument returnfunc - function to call when returning true from the window.
*/
function showpopwin(url, width, height, returnfunc) {
gpopupisshown = true;
disabletabindexes();
gpopupmask.style.display = "block";
gpopupcontainer.style.display = "block";
centerpopwin(width, height);
var titlebarheight = parseint(document.getelementbyid("popuptitlebar").offsetheight, 10);
gpopupcontainer.style.width = width + "px";
gpopupcontainer.style.height = (height+titlebarheight) + "px";
gpopframe.style.width = parseint(document.getelementbyid("popuptitlebar").offsetwidth, 10) + "px";
gpopframe.style.height = (height) + "px";
gpopframe.src = url;
greturnfunc = returnfunc;
// for ie
if (ghideselects == true) {
hideselectboxes();
}
window.settimeout("setpoptitleandrewritetargets();", 100);
}
//
var gi = 0;
function centerpopwin(width, height) {
if (gpopupisshown == true) {
if (width == null || isnan(width)) {
width = gpopupcontainer.offsetwidth;
}
if (height == null) {
height = gpopupcontainer.offsetheight;
}
var fullheight = getviewportheight();
var fullwidth = getviewportwidth();
// scleft and sctop changes by thomas risberg
var scleft,sctop;
if (self.pageyoffset) {
scleft = self.pagexoffset;
sctop = self.pageyoffset;
} else if (document.documentelement && document.documentelement.scrolltop) {
scleft = document.documentelement.scrollleft;
sctop = document.documentelement.scrolltop;
} else if (document.body) {
scleft = document.body.scrollleft;
sctop = document.body.scrolltop;
}
gpopupmask.style.height = fullheight + "px";
gpopupmask.style.width = fullwidth + "px";
gpopupmask.style.top = sctop + "px";
gpopupmask.style.left = scleft + "px";
window.status = gpopupmask.style.top + " " + gpopupmask.style.left + " " + gi++;
var titlebarheight = parseint(document.getelementbyid("popuptitlebar").offsetheight, 10);
var topmargin = sctop + ((fullheight - (height+titlebarheight)) / 2);
if (topmargin < 0) { topmargin = 0; }
gpopupcontainer.style.top = topmargin + "px";
gpopupcontainer.style.left = (scleft + ((fullwidth - width) / 2)) + "px";
}
}
addevent(window, "resize", centerpopwin);
//addevent(window, "scroll", centerpopwin);
window.onscroll = centerpopwin;
/**
* @argument callreturnfunc - bool - determines if we call the return function specified
* @argument returnval - anything - return value
*/
function hidepopwin(callreturnfunc) {
gpopupisshown = false;
restoretabindexes();
if (gpopupmask == null) {
return;
}
gpopupmask.style.display = "none";
gpopupcontainer.style.display = "none";
if (callreturnfunc == true && greturnfunc != null) {
greturnfunc(window.frames["popupframe"].returnval);
}
gpopframe.src = gloading;
// display all select boxes
if (ghideselects == true) {
displayselectboxes();
}
}
/**
* sets the popup title based on the title of the html document it contains.
* also adds a base attribute so links and forms will jump out out of the iframe
* unless a base or target is already explicitly set.
* uses a timeout to keep checking until the title is valid.
*/
function setpoptitleandrewritetargets() {
if (window.frames["popupframe"].document.title == null) {
window.settimeout("setpoptitleandrewritetargets();", 10);
} else {
var popupdocument = window.frames["popupframe"].document;
document.getelementbyid("popuptitle").innerhtml = popupdocument.title;
if (popupdocument.getelementsbytagname('base').length < 1) {
var alist = window.frames["popupframe"].document.getelementsbytagname('a');
for (var i = 0; i < alist.length; i++) {
if (alist.target == null) alist[i].target='_parent';
}
var flist = window.frames["popupframe"].document.getelementsbytagname('form');
for (i = 0; i < flist.length; i++) {
if (flist.target == null) flist[i].target='_parent';
}
}
}
}
// tab key trap. iff popup is shown and key was [tab], suppress it.
// @argument e - event - keyboard event that caused this function to be called.
function keydownhandler(e) {
if (gpopupisshown && e.keycode == 9) return false;
}
// for ie. go through predefined tags and disable tabbing into them.
function disabletabindexes() {
if (document.all) {
var i = 0;
for (var j = 0; j < gtabbabletags.length; j++) {
var tagelements = document.getelementsbytagname(gtabbabletags[j]);
for (var k = 0 ; k < tagelements.length; k++) {
gtabindexes[i] = tagelements[k].tabindex;
tagelements[k].tabindex="-1";
i++;
}
}
}
}
// for ie. restore tab-indexes.
function restoretabindexes() {
if (document.all) {
var i = 0;
for (var j = 0; j < gtabbabletags.length; j++) {
var tagelements = document.getelementsbytagname(gtabbabletags[j]);
for (var k = 0 ; k < tagelements.length; k++) {
tagelements[k].tabindex = gtabindexes[i];
tagelements[k].tabenabled = true;
i++;
}
}
}
}
/**
* hides all drop down form select boxes on the screen so they do not appear above the mask layer.
* ie has a problem with wanted select form tags to always be the topmost z-index or layer
* thanks for the code scott!
*/
function hideselectboxes() {
for(var i = 0; i < document.forms.length; i++) {
for(var e = 0; e < document.forms[i].length; e++){
if(document.forms[i].elements[e].tagname == "select") {
document.forms[i].elements[e].style.visibility="hidden";
}
}
}
}
/**
* makes all drop down form select boxes on the screen visible so they do not reappear after the dialog is closed.
* ie has a problem with wanted select form tags to always be the topmost z-index or layer
*/
function displayselectboxes() {
for(var i = 0; i < document.forms.length; i++) {
for(var e = 0; e < document.forms[i].length; e++){
if(document.forms[i].elements[e].tagname == "select") {
document.forms[i].elements[e].style.visibility="visible";
}
}
}
}
/**
* x-browser event handler attachment and detachment
* @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;
}
}
/**
* 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() {
if (window.innerwidth!=window.undefined) return window.innerwidth;
if (document.compatmode=='css1compat') return document.documentelement.clientwidth;
if (document.body) return document.body.clientwidth;
return window.undefined;
}