var mouseposX = 0;
var mouseposY = 0;

function setEvent(e) {
	if(!e) var e = window.event
	
	if(e.pageX || e.pageY) {
		mouseposX = e.pageX
		mouseposY = e.pageY
	}
	else if(e.clientX || e.clientY) {
		mouseposX = e.clientX + document.body.scrollLeft
		mouseposY = e.clientY + document.body.scrollTop
	}
		//alert(mouseposY)
}


function makeInput(id, styleClass, encrypt) {
	var field = document.createElement('input');
	field.setAttribute('type', 'input');
	field.setAttribute('id', id);
	field.style.position = 'absolute';
	if(styleClass) {field.className = styleClass;}
	
	if(encrypt) {
		field.removeAttribute('type');
		field.setAttribute('type', 'password');
	}
	return field;
}


function makeButton(val, styleClass) {
	var btn = document.createElement('div');
	btn.className = styleClass;
	btn.innerHTML = val;
	btn.style.textAlign = 'center';
	btn.style.cursor = 'pointer';
	btn.style.position = 'absolute';
	btn.style.border = '2px outset #dee3ff';
	btn.onselectstart = function() {return false;}
	btn.onmousedown = new Function("this.style.border = '#dee3ff 2px inset';");
	btn.onmouseup = new Function("this.style.border = '#dee3ff 2px outset';");
	return btn
}

/* ========================
	External links function
======================== */
function externalLinks() { 
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") 
			anchor.target = "_blank"; 
	} 
} 
window.onload = externalLinks;

/* =============================================
	Photo pop-up function (centered in page)
================================================ */
function popupPhoto(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=' + scroll + ',resizable=no'
	win = window.open(mypage, myname, winprops)
	if(parseInt(navigator.appVersion) >= 4) { 
		win.window.focus(); 
	}
	
	win.document.open();
	win.document.writeln('<html>');
	win.document.writeln('<head>');
	win.document.writeln('<title>'+myname+'</title>');
	win.document.writeln('</head>');
	win.document.writeln('<body background="'+mypage+'" margin="0" padding="0">');
	win.document.writeln('</body>');
	win.document.writeln('</html>');
	win.document.close();
}

/* GET OBJECT 
	@param obj: naam of id van het invoerveld
*/
function $(obj) {
	var getObject = null;
	getObject = document.getElementById(obj);

    if(typeof(getObject) == "object") {
		return getObject;
	} else {
		getObject = getElementsByName(obj);
		if(typeof(getObject) == "object") {
			return getObject;
		}
    }
	return null;
}


/* GET VALUE OF OBJECT 
	@param obj: naam of id van het invoerveld
*/
function $v(obj) {
	var ob = $(obj);
	if(typeof(ob) == "object") {
		try {
			return ob.value;
		} catch(e) {
			return null;
		}
	}
}


/* Number format function 
	How to use:
		- Dutch:	number_format(value, 2, ',', '.');
		- English:	number_format(value, 2, ',', '.');
		- French:	number_format(value, 2, ',', ' ');
*/
function number_format(number, decimals, comma, formatSeparator) {
	number = Math.round(number * Math.pow(10, decimals)) / Math.pow(10, decimals);
	e = number + '';
	f = e.split('.');

	if (!f[0]) {
		f[0] = '0';
	}
 
	if (!f[1]) {
		f[1] = '';
	}
 
	if (f[1].length < decimals) {
		g = f[1];
		for(i=f[1].length + 1; i <= decimals; i++) {
			g += '0';
		}
		f[1] = g;
	}
 
	if(formatSeparator != '' && f[0].length > 3) {
		h = f[0];
		f[0] = '';
		for(j = 3; j < h.length; j+=3) {
			i = h.slice(h.length - j, h.length - j + 3);
			f[0] = formatSeparator + i +  f[0] + '';
		}
		j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
		f[0] = j + f[0];
	}
 
	comma = (decimals <= 0) ? '' : comma;
 
	return f[0] + comma + f[1];
}

/* =====================
	PNG Transparacy
===================== */
// correctly handle PNG transparency in Win IE 5.5 or higher.
function correctPNG() { 
	for(var i=0; i<document.images.length; i++) {
		var img = document.images[i]
        var imgName = img.src.toUpperCase()
        if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle                        
            var strNewHTML = "<span " + imgID + imgClass + imgTitle 
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
                + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			img.outerHTML = strNewHTML
            i = i-1
		}
	}
}

function onLoadPage() {
	externalLinks();
	if(IE)	{
		correctPNG();
	}
	
}
if(window.attachEvent)
	window.attachEvent("onload", onLoadPage);
else if(window.attachEventListener)
	window.attachEventListener("onload", onLoadPage);