/**
 * Interface functions (c) Marek Lisiecki <m.lisiecki@ibp.net.pl>
 * $Id$
 */

/**
 * Set basic variables
 */
var screenX=0;screenY=0;mouseX=0;mouseY=0;
var mojeokno,mojatresc;

function initInterface() {
	/**
	* Get visible screen area coords
	*/
	screenX=document.body.clientWidth;
	screenY=document.body.clientHeight;
}

document.onmousemove = function(e) {
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		mouseX = e.pageX;
		mouseY = e.pageY;
	} else if (e.clientX || e.clientY) {
		mouseX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		mouseY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
}

function dWindowCreate(pos,w,h,l,name) {
	try {
		var dWindowName = 'dWindow'+l;
		if (!document.getElementById(dWindowName)) {
			var dWindow = document.createElement('div');
			var dWindowMask = document.createElement('iframe');
			var dws = dWindow.style;
			var dwms = dWindowMask.style;
			dWindow.setAttribute('id',dWindowName);
			dWindowMask.setAttribute('id',dWindowName+'M');
			dWindow.innerHTML =  '<div style="width:100%;height:100%;border:solid 1px #999;background:#ddd;"><table cellspacing="0" cellpadding="2" width="100%" style="height:20px;background:#333;color:#fff;font:bold 11px verdana;border-bottom:solid 1px #000;text-transform:uppercase;"><tr><td>'+name+'</td><td onclick="dWindowDestroy(document.getElementById(\''+dWindowName+'M\'));dWindowDestroy(document.getElementById(\''+dWindowName+'\'));" style="width:16px;cursor:pointer;"><img src="img/close.gif" border="0"></td></tr></table></div>';
			dws.position = 'absolute';
			dwms.position = 'absolute';
			//dws.position = 'fixed';
			//dwms.position = 'fixed';
			dws.zIndex=l;
			dwms.zIndex=l-1;
			dws.width = w+'px';
			dwms.width = w+1+'px';
			dws.height = h+'px';
			dwms.height = h+1+'px';
			dwms.border=0+'px';
			if(pos=='mouse') {
				dws.left = mouseX;
				dws.top = mouseY;
				dwms.left = mouseX;
				dwms.top = mouseY;
			} else {
				scy = (document.all)?document.body.scrollTop:window.pageYOffset;
				dws.left = Math.round((screenX-w)/2);
				dws.top = Math.round((screenY-h)/2+scy);
				dwms.left = Math.round((screenX-w)/2);
				dwms.top = Math.round((screenY-h)/2+scy);
			}
			document.body.appendChild(dWindow);
			document.body.appendChild(dWindowMask);
			return dWindow;
		}
	} catch(e) {
		alert('Can\'t create dWindow object');
	}
}

function dWindowContentCreate(dWindowHandle,w,h,content) {
	var dWindowContent = document.createElement('div');
	var dwcs = dWindowContent.style;
	var dWindowName = dWindowHandle.id + 'ihtml';
	dWindowContent.setAttribute('id',dWindowName);
	dWindowContent.innerHTML = content;
	dwcs.width = (w-2)+'px';
	dwcs.height = (h-22)+'px';
	dwcs.padding = 5 +'px';
	dwcs.fontFamily = 'verdana';
	dwcs.fontSize = 11 + 'px';
	dWindowHandle.firstChild.appendChild(dWindowContent);
	return dWindowContent;
}

function dWindowDestroy(what) { document.body.removeChild(what); document.body.removeChild.what+'M'; }

