function get_elm(elm_id) {
    if(document.getElementById && document.getElementById(elm_id)) {
		return document.getElementById(elm_id);
    } else if(document.all && document.all(elm_id)) {
		return document.all(elm_id);
    } else if(document.layers && document.layers[elm_id]) {
		return document.layers[elm_id];
    } else {
		return false;
    }
}

function go_to(url) {
	document.location = url;
}

function insert_at_cursor(elm_id, text) {
	var elm = get_elm(elm_id);
	if(elm) {
		if(document.selection) { //IE support
			elm.focus();
			sel = document.selection.createRange();
			sel.text = text;
		} else if (elm.selectionStart || elm.selectionStart == '0') { //MOZILLA/NETSCAPE support
			var start_pos = elm.selectionStart;
			var end_pos = elm.selectionEnd;
			elm.value = elm.value.substring(0, start_pos) + text + elm.value.substring(end_pos, elm.value.length);
		} else {
			elm.value += text;
		}
	} else {
		return false;
	}
}


function popup(img_src, img_title, width, height) {
	
	page = "about:blank";
	target = "";
	params = "scrollbars=auto,width=" + width + ",height=" + height + ",left=" + 150 + ",top=" + 150;
	img_win = window.open(page, target, params);
	
	with(img_win.document) {
		writeln("<html>\
                 <head>\
                 <title>" + img_title + "</title>\
                 </head>\
                 <body scroll=\"no\" style=\"margin: 0px 0px 0px 0px;\" onload=\"self.focus();\" onblur=\"self.close();\">\
                 <img src=\"" + img_src + "\" alt=\"" + img_title + "\" title=\"Klik om af te sluiten\" style=\"cursor: pointer;\" onclick=\"self.close();\" />\
                 </body>\
                 </html>");
		close();
	}
}

function disable_button(elm_id) {
	var button = get_elm(elm_id);
	if(button) {
		button.disabled = "disabled";
	}
}
/*
function hide(elm_id) {
	var elm = get_elm(elm_id);
	if(elm) {
		elm.style.display = "none";
	}
}

function show(elm_id) {
	var elm = get_elm(elm_id);
	if(elm) {
		elm.style.display = "block";
	}
}

function toggle(elm_id) {
	var elm = get_elm(elm_id);
	if(elm) {
		if(elm.style.display == "block")
			hide(elm_id);
		else
			show(elm_id);
	}
}
*/
function add_event(obj, ev_type, fn) {
	if(obj.addEventListener) {
		obj.addEventListener(ev_type, fn, false);
		return true;
	} else if(obj.attachEvent) {
		obj.attachEvent("on" + ev_type, fn);
		return true;
	} else {
		return false;
	}
}

function get_event_src(e) {
	var e_src = "undefined";
	
	var e = (e) ? e : (window.event) ? window.event : false;
	if(e) {
		e_src = (e.target) ? e.target : (e.srcElement) ? e.srcElement : "undefined";
	}
	
	return e_src;
}

function get_highest_zindex() {
	var all_elems = document.getElementsByTagName ? document.getElementsByTagName("*") : document.all;
	var max_zindex = 0;
	
	for(var i = 0; i < all_elems.length; i++) {
		var elem = all_elems[i];
		var style = null;
		if(elem.currentStyle) {
			style = elem.currentStyle;
		} else if(document.defaultView && document.defaultView.getComputedStyle) {
			style = document.defaultView.getComputedStyle(elem, "");
		}
		
		var zindex;
		if(style) {
			zindex = Number(style.zIndex);
		} else {
			zindex = Number(elem.style.zIndex);
		}
		
		if(!isNaN(zindex)) {
			max_zindex = Math.max(max_zindex, zindex);
		}
	}
	
	return max_zindex;
}

document.getSize = function() { 
    var xScroll = 0; 
    var yScroll = 0; 
	
    if (window.innerHeight && window.scrollMaxY) { 
        xScroll = window.innerWidth + window.scrollMaxX; 
        yScroll = window.innerHeight + window.scrollMaxY; 

    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac 
        xScroll = document.body.scrollWidth; 
        yScroll = document.body.scrollHeight; 

    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari 
        xScroll = document.body.offsetWidth; 
        yScroll = document.body.offsetHeight; 
    } 
	
    var windowWidth, windowHeight; 

    if (self.innerHeight) { // all except Explorer 
        windowWidth = (document.documentElement.clientWidth) ? document.documentElement.clientWidth : self.innerWidth; 
        windowHeight = self.innerHeight; 

    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode 
        windowWidth = document.documentElement.clientWidth; 
        windowHeight = document.documentElement.clientHeight; 

    } else if (document.body) { // other Explorers 
        windowWidth = document.body.clientWidth; 
        windowHeight = document.body.clientHeight; 
    } 
	
    // for small pages with total height less then height of the viewport 
    var docHeight = (yScroll < windowHeight) ? windowHeight : yScroll; 

    // for small pages with total width less then width of the viewport 
    var docWidth = (xScroll < windowWidth) ? xScroll : windowWidth; 

    // return arrayPageSize; 
    return {"width": docWidth, "height": docHeight}; 
}