/* /////////////////////////////////////////////////////////////////////// 
	addEvent(window, "load", alert('hello world'));
	Add an eventListener to browsers that can do it somehow.

	NOTE: be careful when placing window.onload events in this .js-file,
	since they will then be called from both the main page and the iframe pages...

	Originally by the amazing Scott Andrew.
///////////////////////////////////////////////////////////////////////  */	
function addEvent(obj, evType, fn){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
  } else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
	return false;
  }
}
	
/* /////////////////////////////////////////////////////////////////////// 

Fixes IE/MAC disappearing scrollbar bug
call onload or inside the body tag
///////////////////////////////////////////////////////////////////////  */	

function fixScrollbars(){
	var agent = navigator.userAgent.toLowerCase(); 
	var mac = agent.indexOf('mac') != -1;
	if(mac && document.all){
		document.body.scroll = 'yes';
		var iframes = document.getElementsByTagName("iframe");
		for(i=0; i < iframes.length; i++){
			//if(!iframes[i].style.width) continue;
			//href = anchors[i].href;
			alert(iframes[i].id +', ', iframes[i].style.width );
		}
	}
}

//Popup, no Scrollbar
//usage: spawn('/the/url/here.htm','windowName',500,200);
function spawn(URL,windowName,width,height) {
    popRef = window.open(URL, windowName, "toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,width=" + width + ",height=" + height + ",resizable=no");
	setTimeout('popRef.focus()',250);
}

//Popup, no Scrollbar
//usage: spawn('/the/url/here.htm','windowName',500,200);
//Google maps needs special handling since it does noget work in a http context.
function spawnGoogleMap(URL, windowName, width, height) {
    popRef = window.open("http://" + location.host + "/" + URL, windowName, "toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,width=" + width + ",height=" + height + ",resizable=no");
    setTimeout('popRef.focus()', 250);
}

function HandleKey(button) {
    if (window.navigator.userAgent.indexOf('MSIE') > -1) {
        if (typeof (event) != 'undefined' && event.keyCode == 13) {
            document.getElementById(button).click();
            return false;
        }
    }

    else {
        var theEvent = arguments.callee.caller.arguments[0];

        var code;
        if (theEvent.keyCode)
            code = theEvent.keyCode;
        else if (theEvent.which)
            code = theEvent.which;

        if (typeof (code) != 'undefined' && code == 13) {
            document.getElementById(button).click();
        }
    }
}
