path = 'http://www.skrypty.serverwms.pl/';

var screenDiv = null;
var onMouseMoveFunctions = new Array();
var onMouseUpFunctions = new Array();
var myMenus = new Array();

if( typeof Array.prototype.concat==='undefined' ) {
 Array.prototype.concat = function( a ) {
  for( var i = 0, b = this.copy(); i<a.length; i++ ) {
   b[b.length] = a[i];
  }
  return b;
  };
}
Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};
Array.prototype.insert = function( i, v ) {
 if( i>=0 ) {
  var a = this.slice(), b = a.splice( i );
  a[i] = v;
  return a.concat( b );
 }
};


function isRightButtonPressed(e) {
	var rightclick;
	if (!e) var e = window.event;
	if (e.which) rightclick = (e.which == 3);
	else if (e.button) rightclick = (e.button == 2);
	return rightclick;
}
function getElementPosition(elem){
var offsetTrail = elem;
var offsetLeft = 0;
var offsetTop = 0;
while (offsetTrail){
offsetLeft += offsetTrail.offsetLeft;
offsetTop += offsetTrail.offsetTop;
offsetTrail = offsetTrail.offsetParent;
}
if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined'){
offsetLeft += document.body.leftMargin;
offsetTop += document.body.topMargin;
}
return {left:offsetLeft,top:offsetTop};
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
function clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

var IE = document.all?true:false;
//if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
document.onmouseup = upMouse;
var tempX = 0;
var tempY = 0;
var xMouseCoordinate=0;
var yMouseCoordinate=0;
function getMouseXY(e) {
	function isIE() {
		return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
	}
        if (document.body){
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		if (document.documentElement){
			posx = e.clientX + document.body.scrollLeft+ document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop+ document.documentElement.scrollTop;
		}
	}
	if (isIE()==true) {
		posx-=2;
		posy-=2;
	}

		
	xMouseCoordinate= posx;
	yMouseCoordinate= posy;

	for(i=0;i<onMouseMoveFunctions.length;i++)
	onMouseMoveFunctions[i](e);
	}
	return true;
}
function upMouse(e) {

	for(i=0;i<onMouseUpFunctions.length;i++)
	onMouseUpFunctions[i](e);
	
	if (isRightButtonPressed(e)==false){
		for(i=0;i<myMenus.length;i++){
			myMenus[i].mainDiv.style.display = 'none';
		}
	}
	return true;
}


function mouseDown(e){
  e = e || window.event;
  if (e.preventDefault)
  {
    e.preventDefault();
  }
}

function initMyWindows(){
	screenDiv=document.createElement('div');
	document.body.appendChild(screenDiv);
	screenDiv.style.position = 'absolute';
	screenDiv.style.left = '0px';
	screenDiv.style.top = '0px';
	screenDiv.style.right = '0px';
	screenDiv.style.bottom = '0px';
	screenDiv.style.overflow = 'hidden';
	screenDiv.myLeft = getElementPosition(screenDiv).left;
	screenDiv.myTop = getElementPosition(screenDiv).top;
	//alert(screenDiv.myLeft+"  "+screenDiv.myTop);
}

function createFramedDiv(x,y,width,height,border,center,left,top,right,bottom,left_top,right_top,left_bottom,right_bottom){
	var mainDiv = document.createElement('div');
	mainDiv.style.position = 'absolute';
	if (y>=0)
	mainDiv.style.top = y+'px';
	else
	mainDiv.style.bottom = -y+'px';
	
	if (x>=0)
	mainDiv.style.left = x+'px';
	else
	mainDiv.style.right = -x+'px';
	
	mainDiv.style.width = width+'px';
	mainDiv.style.height= height+'px';
	mainDiv.style.overflow = 'hidden';
	
	var centerDiv = document.createElement('div');
	mainDiv.appendChild(centerDiv);
	centerDiv.style.position = 'absolute';
	centerDiv.style.top = border+'px';
	centerDiv.style.left = border+'px';
	centerDiv.style.width = (width-border-border)+'px';
	centerDiv.style.height = (height-border-border)+'px';
	centerDiv.innerHTML = '<img style="position:relative;width:100%;height:100%" src="'+center+'"/>';

	var topDiv = document.createElement('div');
	mainDiv.appendChild(topDiv);
	topDiv.style.position = 'absolute';
	topDiv.style.top = '0px';
	topDiv.style.left = border+'px';
	topDiv.style.right = border+'px';
	topDiv.style.height = '16px';
	topDiv.innerHTML = '<img style="position:relative;width:100%;height:16px" src="'+top+'"/>';

	var bottomDiv = document.createElement('div');
	mainDiv.appendChild(bottomDiv);
	bottomDiv.style.position = 'absolute';
	bottomDiv.style.top = (height-border)+'px';
	bottomDiv.style.left = border+'px';
	bottomDiv.style.right = border+'px';
	bottomDiv.style.height = '16px';
	bottomDiv.innerHTML = '<img style="position:relative;width:100%;height:16px" src="'+bottom+'"/>';
	
	var leftDiv = document.createElement('div');
	mainDiv.appendChild(leftDiv);
	leftDiv.style.position = 'absolute';
	leftDiv.style.top = border+'px';
	leftDiv.style.left = '0px';
	leftDiv.style.height = (height-border-border)+'px';
	leftDiv.style.width = '16px';
	leftDiv.innerHTML = '<img style="position:relative;height:100%;width:16px" src="'+left+'"/>';
	
	var rightDiv = document.createElement('div');
	mainDiv.appendChild(rightDiv);
	rightDiv.style.position = 'absolute';
	rightDiv.style.top = border+'px';
	rightDiv.style.left = (width-border)+'px';
	rightDiv.style.height = (height-border-border)+'px';
	rightDiv.style.width = '16px';
	rightDiv.innerHTML = '<img style="position:relative;height:100%;width:16px" src="'+right+'"/>';
	
	var leftTopDiv = document.createElement('div');
	mainDiv.appendChild(leftTopDiv);
	leftTopDiv.style.position = 'absolute';
	leftTopDiv.style.top = '0px';
	leftTopDiv.style.left = '0px';
	leftTopDiv.style.height = '16px';
	leftTopDiv.style.width = '16px';
	leftTopDiv.innerHTML = '<img style="position:relative;width:16px;height:16px" src="'+left_top+'"/>';
	
	var rightTopDiv = document.createElement('div');
	mainDiv.appendChild(rightTopDiv);
	rightTopDiv.style.position = 'absolute';
	rightTopDiv.style.top = '0px';
	rightTopDiv.style.left = (width-border)+'px';
	rightTopDiv.style.height = '16px';
	rightTopDiv.style.width = '16px';
	rightTopDiv.innerHTML = '<img style="position:relative;width:16px;height:16px" src="'+right_top+'"/>';
	
	var leftBottomDiv = document.createElement('div');
	mainDiv.appendChild(leftBottomDiv);
	leftBottomDiv.style.position = 'absolute';
	leftBottomDiv.style.top = (height-border)+'px';
	leftBottomDiv.style.left = '0px';
	leftBottomDiv.style.height = '16px';
	leftBottomDiv.style.width = '16px';
	leftBottomDiv.innerHTML = '<img style="position:relative;width:16px;height:16px" src="'+left_bottom+'"/>';
	
	var rightBottomDiv = document.createElement('div');
	mainDiv.appendChild(rightBottomDiv);
	rightBottomDiv.style.position = 'absolute';
	rightBottomDiv.style.top = (height-border)+'px';
	rightBottomDiv.style.left = (width-border)+'px';
	rightBottomDiv.style.height = '16px';
	rightBottomDiv.style.width = '16px';
	rightBottomDiv.innerHTML = '<img style="position:relative;width:16px;height:16px" src="'+right_bottom+'"/>';
	
	return mainDiv;
}
function createTabDiv(x,y,width,height,border,center,left,top,right,left_top,right_top){
	var mainDiv = document.createElement('div');
	mainDiv.style.position = 'absolute';
	mainDiv.style.top = y+'px';
	mainDiv.style.left = x+'px';
	mainDiv.style.width = width+'px';
	mainDiv.style.height= height+'px';
	mainDiv.style.overflow = 'hidden';
	
	var centerDiv = document.createElement('div');
	mainDiv.appendChild(centerDiv);
	centerDiv.style.position = 'absolute';
	centerDiv.style.top = border+'px';
	centerDiv.style.left = border+'px';
	centerDiv.style.width = (width-border-border)+'px';
	centerDiv.style.height = (height-border)+'px';
	centerDiv.innerHTML = '<img style="position:relative;width:100%;height:100%" src="'+center+'"/>';

	var topDiv = document.createElement('div');
	mainDiv.appendChild(topDiv);
	topDiv.style.position = 'absolute';
	topDiv.style.top = '0px';
	topDiv.style.left = border+'px';
	topDiv.style.right = border+'px';
	topDiv.style.height = '16px';
	topDiv.innerHTML = '<img style="position:relative;width:100%;height:16px" src="'+top+'"/>';

	var leftDiv = document.createElement('div');
	mainDiv.appendChild(leftDiv);
	leftDiv.style.position = 'absolute';
	leftDiv.style.top = border+'px';
	leftDiv.style.left = '0px';
	leftDiv.style.height = (height-border)+'px';
	leftDiv.style.width = '16px';
	leftDiv.innerHTML = '<img style="position:relative;height:100%;width:16px" src="'+left+'"/>';
	
	var rightDiv = document.createElement('div');
	mainDiv.appendChild(rightDiv);
	rightDiv.style.position = 'absolute';
	rightDiv.style.top = border+'px';
	rightDiv.style.left = (width-border)+'px';
	rightDiv.style.height = (height-border)+'px';
	rightDiv.style.width = '16px';
	rightDiv.innerHTML = '<img style="position:relative;height:100%;width:16px" src="'+right+'"/>';
	
	var leftTopDiv = document.createElement('div');
	mainDiv.appendChild(leftTopDiv);
	leftTopDiv.style.position = 'absolute';
	leftTopDiv.style.top = '0px';
	leftTopDiv.style.left = '0px';
	leftTopDiv.style.height = '16px';
	leftTopDiv.style.width = '16px';
	leftTopDiv.innerHTML = '<img style="position:relative;width:16px;height:16px" src="'+left_top+'"/>';
	
	var rightTopDiv = document.createElement('div');
	mainDiv.appendChild(rightTopDiv);
	rightTopDiv.style.position = 'absolute';
	rightTopDiv.style.top = '0px';
	rightTopDiv.style.left = (width-border)+'px';
	rightTopDiv.style.height = '16px';
	rightTopDiv.style.width = '16px';
	rightTopDiv.innerHTML = '<img style="position:relative;width:16px;height:16px" src="'+right_top+'"/>';
		
		
	return mainDiv;
}

var myButtonsContainer = new Array();
var myButtonsContainerIndex = 0;
var myTabsContainer = new Array();
var myTabsContainerIndex = 0;

function MyButton(x,y,width,height,image){

	this.index = myButtonsContainerIndex;

	this.type = 0;
	myButtonsContainer[myButtonsContainerIndex] = this;
	myButtonsContainerIndex++;
    this.mainDiv = createFramedDiv(x,y,width,height,3,path+'/windows/button/center.png',path+'/windows/button/left.png',path+'/windows/button/top.png',path+'/windows/button/right.png',path+'/windows/button/bottom.png',path+'/windows/button/left_top.png',path+'/windows/button/right_top.png',path+'/windows/button/left_bottom.png',path+'/windows/button/right_bottom.png');
	
	var img = new Image();
	img.src = path+'/windows/button/light.png';
	this.lightDiv = document.createElement('div');
	this.mainDiv.appendChild(this.lightDiv);
	this.lightDiv.style.position = 'absolute';
	this.lightDiv.style.top = '0px';
	this.lightDiv.style.left = '0px';
	this.lightDiv.style.display = 'none';
	this.lightDiv.style.width = (width)+'px';
	this.lightDiv.style.height = (height)+'px';
	this.lightDiv.innerHTML = '<img style="position:relative;width:100%;height:100%" src="'+path+'/windows/button/light.png"/>';

	this.imageDiv = document.createElement('div');
	this.mainDiv.appendChild(this.imageDiv);
	this.imageDiv.style.position = 'absolute';
	this.imageDiv.style.top = '3px';
	this.imageDiv.style.left = '3px';
	this.imageDiv.style.width = (width-6)+'px';
	this.imageDiv.style.height = (height-6)+'px';
	this.imageDiv.style.backgroundImage='url('+image+')';	
	
	this.coverDiv = document.createElement('div');
	this.mainDiv.appendChild(this.coverDiv);
	this.coverDiv.style.position = 'absolute';
	this.coverDiv.style.top = '0px';
	this.coverDiv.style.left = '0px';
	this.coverDiv.style.width = (width)+'px';
	this.coverDiv.style.height = (height)+'px';
	//this.coverDiv.style.cursor = 'pointer';
	this.coverDiv.style.backgroundImage='url('+path+'windows/blank.png)';
	

	this.functionOnClick = null;
	var lightDiv = this.lightDiv;
	var imageDiv = this.imageDiv;
	var div = this;
	this.coverDiv.onmouseover = function(){
		lightDiv.style.display = 'block';
	}
	this.coverDiv.onmouseout = function(){
		lightDiv.style.display = 'none';
		imageDiv.style.top = '3px';
	}
	this.coverDiv.onmousedown = function(){
		imageDiv.style.top = '4px';
	}
	this.coverDiv.onmouseup = function(){
		imageDiv.style.top = '3px';
		if (div.functionOnClick!=null)
		div.functionOnClick();
	}
	
	if(this.coverDiv.addEventListener){
		this.coverDiv.addEventListener('mousedown', mouseDown, true);
	}
	
	this.appendTo = function(div){
		div.appendChild(this.mainDiv);
	}
	this.show = function(){
		this.mainDiv.style.display = 'block';
	}
	this.hide = function(){
		this.mainDiv.style.display = 'none';
	}

}
function MyTextButton(x,y,width,height,text){

	this.index = myButtonsContainerIndex;

	this.type = 0;
	myButtonsContainer[myButtonsContainerIndex] = this;
	myButtonsContainerIndex++;
    this.mainDiv = createFramedDiv(x,y,width,height,3,path+'/windows/button/center.png',path+'/windows/button/left.png',path+'/windows/button/top.png',path+'/windows/button/right.png',path+'/windows/button/bottom.png',path+'/windows/button/left_top.png',path+'/windows/button/right_top.png',path+'/windows/button/left_bottom.png',path+'/windows/button/right_bottom.png');
	
	var img = new Image();
	img.src = path+'/windows/button/light.png';
	this.lightDiv = document.createElement('div');
	this.mainDiv.appendChild(this.lightDiv);
	this.lightDiv.style.position = 'absolute';
	this.lightDiv.style.top = '0px';
	this.lightDiv.style.left = '0px';
	this.lightDiv.style.display = 'none';
	this.lightDiv.style.width = (width)+'px';
	this.lightDiv.style.height = (height)+'px';
	this.lightDiv.innerHTML = '<img style="position:relative;width:100%;height:100%" src="'+path+'/windows/button/light.png"/>';

	this.imageDiv = document.createElement('div');
	this.mainDiv.appendChild(this.imageDiv);
	this.imageDiv.style.position = 'absolute';
	this.imageDiv.style.top = '3px';
	this.imageDiv.style.left = '3px';
	this.imageDiv.style.width = (width-7)+'px';
	this.imageDiv.style.height = (height-6)+'px';
	this.imageDiv.innerHTML ='<table style="width:100%;height:100%;font-family:tahoma;font-size:11px;color:#000"><tr><td align="center">'+text+'</td></tr></table>';	
	
	this.coverDiv = document.createElement('div');
	this.mainDiv.appendChild(this.coverDiv);
	this.coverDiv.style.position = 'absolute';
	this.coverDiv.style.top = '0px';
	this.coverDiv.style.left = '0px';
	this.coverDiv.style.width = (width)+'px';
	this.coverDiv.style.height = (height)+'px';
	//this.coverDiv.style.cursor = 'pointer';
	this.coverDiv.style.backgroundImage='url('+path+'windows/blank.png)';
	

	this.functionOnClick = null;
	var lightDiv = this.lightDiv;
	var imageDiv = this.imageDiv;
	var div = this;
	this.coverDiv.onmouseover = function(){
		lightDiv.style.display = 'block';
	}
	this.coverDiv.onmouseout = function(){
		lightDiv.style.display = 'none';
		imageDiv.style.top = '3px';
	}
	this.coverDiv.onmousedown = function(){
		imageDiv.style.top = '4px';
	}
	this.coverDiv.onmouseup = function(){
		imageDiv.style.top = '3px';
		if (div.functionOnClick!=null)
		div.functionOnClick();
	}
	
	if(this.coverDiv.addEventListener){
		this.coverDiv.addEventListener('mousedown', mouseDown, true);
	}
	
	this.appendTo = function(div){
		div.appendChild(this.mainDiv);
	}
	this.show = function(){
		this.mainDiv.style.display = 'block';
	}
	this.show = function(){
		this.mainDiv.style.display = 'block';
	}
	this.hide = function(){
		this.mainDiv.style.display = 'none';
	}	
}

function MyButtonRadio(x,y,width,height,image,group){
	this.index = myButtonsContainerIndex;
	this.type = 1;
	this.group = group;

	myButtonsContainer[myButtonsContainerIndex] = this;
	myButtonsContainerIndex++;
    this.mainDiv = createFramedDiv(x,y,width,height,3,path+'/windows/button/center.png',path+'/windows/button/left.png',path+'/windows/button/top.png',path+'/windows/button/right.png',path+'/windows/button/bottom.png',path+'/windows/button/left_top.png',path+'/windows/button/right_top.png',path+'/windows/button/left_bottom.png',path+'/windows/button/right_bottom.png');
	
	var img = new Image();
	img.src = path+'/windows/button/light.png';
	var img1 = new Image();
	img1.src = path+'/windows/button/light.png';
	
	this.lightDiv = document.createElement('div');
	this.mainDiv.appendChild(this.lightDiv);
	this.lightDiv.style.position = 'absolute';
	this.lightDiv.style.top = '0px';
	this.lightDiv.style.left = '0px';
	this.lightDiv.style.display = 'none';
	this.lightDiv.style.width = (width)+'px';
	this.lightDiv.style.height = (height)+'px';
	this.lightDiv.innerHTML = '<img style="position:relative;width:100%;height:100%" src="'+path+'/windows/button/light_check2.png"/>';

	this.lightDiv2 = document.createElement('div');
	this.mainDiv.appendChild(this.lightDiv2);
	this.lightDiv2.style.position = 'absolute';
	this.lightDiv2.style.top = '0px';
	this.lightDiv2.style.left = '0px';
	this.lightDiv2.style.display = 'none';
	this.lightDiv2.style.width = (width)+'px';
	this.lightDiv2.style.height = (height)+'px';
	this.lightDiv2.innerHTML = '<img style="position:relative;width:100%;height:100%" src="'+path+'/windows/button/light.png"/>';	
	
	this.imageDiv = document.createElement('div');
	this.mainDiv.appendChild(this.imageDiv);
	this.imageDiv.style.position = 'absolute';
	this.imageDiv.style.top = '3px';
	this.imageDiv.style.left = '3px';
	this.imageDiv.style.width = (width-6)+'px';
	this.imageDiv.style.height = (height-6)+'px';
	this.imageDiv.style.backgroundImage='url('+image+')';	
	
	this.coverDiv = document.createElement('div');
	this.mainDiv.appendChild(this.coverDiv);
	this.coverDiv.style.position = 'absolute';
	this.coverDiv.style.top = '0px';
	this.coverDiv.style.left = '0px';
	this.coverDiv.style.width = (width)+'px';
	this.coverDiv.style.height = (height)+'px';
	//this.coverDiv.style.cursor = 'pointer';
	this.coverDiv.style.backgroundImage='url('+path+'windows/blank.png)';
	

	this.functionOnClick = null;
	var lightDiv = this.lightDiv;
	var lightDiv2 = this.lightDiv2;
	var imageDiv = this.imageDiv;
	var div = this;
	this.coverDiv.onmouseover = function(){
		lightDiv2.style.display = 'block';
	}
	this.coverDiv.onmouseout = function(){
		imageDiv.style.top = '3px';
		lightDiv2.style.display = 'none';
	}
	this.coverDiv.onmousedown = function(){
		imageDiv.style.top = '4px';
	}
	this.coverDiv.onmouseup = function(){
		imageDiv.style.top = '3px';
		for (i=0;i<myButtonsContainer.length;i++)
		{
			if  (myButtonsContainer[i].group == div.group)
			myButtonsContainer[i].lightDiv.style.display = 'none';
		}
		
		if (div.functionOnClick!=null)
		div.functionOnClick();
		lightDiv.style.display = 'block';
	}
	if(this.coverDiv.addEventListener){
		this.coverDiv.addEventListener('mousedown', mouseDown, true);
	}
	this.appendTo = function(div){
		div.appendChild(this.mainDiv);
	}
	this.check = function(){
		for (i=0;i<myButtonsContainer.length;i++)
		{
			if  (myButtonsContainer[i].group == div.group)
			myButtonsContainer[i].lightDiv.style.display = 'none';
		}
		lightDiv.style.display = 'block';
	}
	this.uncheck = function(){
		lightDiv.style.display = 'none';
	}
	this.show = function(){
		this.mainDiv.style.display = 'block';
	}
	this.hide = function(){
		this.mainDiv.style.display = 'none';
	}
}
function MyLabel(x,y,width,height,text,size,color,bold){
	this.mainDiv = document.createElement('div');
	this.mainDiv.style.position = 'absolute';
	this.mainDiv.style.top = y+'px';
	this.mainDiv.style.left = x+'px';
	this.mainDiv.style.width = (width)+'px';
	this.mainDiv.style.height = (height)+'px';
	this.mainDiv.style.overflow = 'hidden';
	this.mainDiv.innerHTML='<table style="width:100%;height:100%;font-family:tahoma;font-size:'+size+'px;color:'+color+';font-weight:'+bold+'"><tr><td><div style="width:100%;height:100%;overflow:hidden">'+text+'</div></td></tr></table>';
	this.appendTo = function(div){
		div.appendChild(this.mainDiv);
	}
	this.coverDiv = document.createElement('div');
	this.mainDiv.appendChild(this.coverDiv);
	this.coverDiv.style.position = 'absolute';
	this.coverDiv.style.top = '0px';
	this.coverDiv.style.left = '0px';
	this.coverDiv.style.width = (width)+'px';
	this.coverDiv.style.height = (height)+'px';
	this.coverDiv.style.backgroundImage='url('+path+'windows/blank.png)';
	if(this.coverDiv.addEventListener){
		this.coverDiv.addEventListener('mousedown', mouseDown, true);
	}
}
function MyTab(x,width,height,text,group){
	myTabsContainer[myTabsContainerIndex] = this;
	myTabsContainerIndex++;
	
	this.height = height;
	this.mainDiv = document.createElement('div');
	this.mainDiv.style.position = 'absolute';
	this.mainDiv.style.top = '0px';
	this.mainDiv.style.left = x+'px';
	this.mainDiv.style.overflow = 'hidden';
	this.mainDiv.style.width = (width)+'px';
	this.mainDiv.style.height = (height)+'px';
		
	this.activeDiv = createTabDiv(0,0,width,height,7,path+'windows/tab/center.png',path+'windows/tab/left.png',path+'windows/tab/top.png',path+'windows/tab/right.png',path+'windows/tab/left_top.png',path+'windows/tab/right_top.png');
	this.mainDiv.appendChild(this.activeDiv);
	
	this.unactiveDiv = createTabDiv(0,0,width,height,7,path+'windows/tab/center2.png',path+'windows/tab/left2.png',path+'windows/tab/top2.png',path+'windows/tab/right2.png',path+'windows/tab/left_top2.png',path+'windows/tab/right_top2.png');
	this.mainDiv.appendChild(this.unactiveDiv);
	this.unactiveDiv.style.display = 'none'; 
	
	this.group = group;
	
	this.textDiv = document.createElement('div');
	this.textDiv.innerHTML='<table style="width:100%;height:100%;font-family:tahoma;font-size:11px;color:#225;"><tr><td align="center">'+text+'</td></tr></table>'
	this.mainDiv.appendChild(this.textDiv);
	this.textDiv.style.position = 'absolute';
	this.textDiv.style.top = '0px';
	this.textDiv.style.left = '0px';
	this.textDiv.style.overflow = 'hidden';
	this.textDiv.style.width = (width)+'px';
	this.textDiv.style.height = (height)+'px';
	
	
	this.coverDiv = document.createElement('div');
	this.mainDiv.appendChild(this.coverDiv);
	this.coverDiv.style.position = 'absolute';
	this.coverDiv.style.top = '0px';
	this.coverDiv.style.left = '0px';
	this.coverDiv.style.width = (width)+'px';
	this.coverDiv.style.height = (height)+'px';
	//this.coverDiv.style.cursor = 'pointer'; 
	this.coverDiv.style.backgroundImage='url('+path+'windows/blank.png)';

	this.contentDiv = document.createElement('div');
	this.contentDiv.style.position = 'absolute';
	this.contentDiv.style.top = '0px';
	this.contentDiv.style.left = '0px';
	this.contentDiv.style.right = '0px';
	this.contentDiv.style.bottom = '0px';
	this.contentDiv.style.display = 'none';
	this.contentDiv.style.backgroundColor = '#eee';
	
	if(this.coverDiv.addEventListener){
		this.coverDiv.addEventListener('mousedown', mouseDown, true);
	}
	
	var obj = this;

	this.coverDiv.onmousedown = function()
	{
		obj.textDiv.style.top = '1px';
	}
	this.coverDiv.onmouseup = function()
	{
		obj.textDiv.style.top = '0px';
		obj.set();
	}
	
	this.appendTo = function(div){
		div.appendChild(this.mainDiv);
	}
	this.set = function(){
		for (i=0;i<myTabsContainer.length;i++)
		if (myTabsContainer[i].group == this.group)
		{
			myTabsContainer[i].unactivate();
		}
		this.activate();
	}
	this.activate = function(){
		this.activeDiv.style.display = 'block'; 
		this.unactiveDiv.style.display = 'none'; 
		this.contentDiv.style.display = 'block';
		//alert(this.contentDiv.innerHTML);
	}
	this.unactivate = function(){
		this.unactiveDiv.style.display = 'block'; 
		this.activeDiv.style.display = 'none'; 
		this.unactiveDiv.style.height = (height-1)+'px';
		this.contentDiv.style.display = 'none';
	}
	this.addButton = function(button)
	{
		button.appendTo(this.contentDiv);
	}
	this.addTreeView = function(tree)
	{
		tree.appendTo(this.contentDiv);
	}

}

function MyWindow(left,top,width,height,right,bottom,zIndex,minWidth,minHeight,toolbar,movingEnable,sizingEnable,position,isClose){
	this.left = left;
	this.top = top;
	
	if ((position=='center')&&(width!=null)&&(height!=null))
	{
		this.left = Math.round((clientWidth()-width)*0.5);
		this.top = Math.round((clientHeight()-height)*0.5);
	}
	
	this.tabs = new Array();
	
	this.width = width;
	this.height = height;
	this.right = right;
	this.bottom = bottom;
	
	this.zIndex = zIndex;
	this.minWidth = minWidth;
	this.minHeight = minHeight;
	if (toolbar>50) toolbar=50; 
	this.toolbar = toolbar;
	this.movingEnable = movingEnable;
	this.sizingEnable = sizingEnable;
	this.isClose = isClose;
	this.onclose = null;
	this.move = false;
	this.size = false;
	//main div
	this.mainDiv = document.createElement('div');
	screenDiv.appendChild(this.mainDiv);
	this.mainDiv.style.position = 'absolute';

	if (this.height!=null){
		this.mainDiv.style.height = this.height+'px';
		if (this.top!=null)
		this.mainDiv.style.top = this.top+'px';		
		if (this.bottom!=null)
		this.mainDiv.style.bottom = this.bottom+'px';			
	}
	else
	{	
		this.mainDiv.style.top = this.top+'px';	
		this.mainDiv.style.bottom = this.bottom+'px';	
	}

	if (this.width!=null)
	{
		this.mainDiv.style.width = this.width+'px';
		if (this.left!=null)
		this.mainDiv.style.left = this.left+'px';		
		if (this.right!=null)
		this.mainDiv.style.right = this.right+'px';			
	}
	else
	{	
		this.mainDiv.style.left = this.left+'px';
		this.mainDiv.style.right = this.right+'px';
	}
	

	this.mainDiv.style.display = 'none';
	
	//this.mainDiv.style.overflow = 'hidden';
	this.mainDiv.style.zIndex = this.zIndex;
	//
	this.contentDiv = document.createElement('div');
	this.mainDiv.appendChild(this.contentDiv);
	this.contentDiv.style.position = 'absolute';
	this.contentDiv.style.top = (10+this.toolbar)+'px';
	this.contentDiv.style.left = '16px';
	this.contentDiv.style.right = '16px';
	this.contentDiv.style.bottom = '16px';
	this.contentDiv.style.overflow = 'hidden';
	this.contentDiv.style.backgroundColor='#eee';
	this.contentDiv.style.zIndex = this.zIndex+1;

	/*
	this.infoDiv = document.createElement('div');
	this.mainDiv.appendChild(this.infoDiv);
	this.infoDiv.style.position = 'absolute';
	this.infoDiv.style.top = '16px';
	this.infoDiv.style.left = '16px';
	this.infoDiv.style.width = '66px';
	this.infoDiv.style.height = '16px';
	this.infoDiv.style.zIndex = this.zIndex+20;	
	*/
	
	this.mouseX = 0;
	this.mouseY = 0;
	var obj = this;
	this.calculatePosition = function(){	
		var pos = getElementPosition(obj.contentDiv);
		var poscr = getElementPosition(screenDiv);
		
		obj.mouseX = xMouseCoordinate-pos.left-poscr.left;
		obj.mouseY = yMouseCoordinate-pos.top-poscr.top;
		var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
		if (navigator.appVersion.indexOf("MSIE 7.")!=-1)	
		{
			obj.mouseX -= 2;
			obj.mouseY -= 3;		
		}
		if (is_chrome==true)	
		{
			obj.mouseX -= 0;
			obj.mouseY -= 1;		
		}
		if (navigator.userAgent.indexOf("Firefox")!=-1)
		{
			obj.mouseX -= 1;
			obj.mouseY -= 0;		
		}
	}
	this.contentDiv.onmousemove = function(e){	
		obj.calculatePosition();
	}
	
	this.contentDiv.onclick = function(e){
		obj.calculatePosition();
	}	
	
	this.bottomFrame = document.createElement('div');
	this.mainDiv.appendChild(this.bottomFrame);
	this.bottomFrame.style.position = 'absolute';
	this.bottomFrame.style.height = '16px';
	this.bottomFrame.style.left = '16px';
	this.bottomFrame.style.right = '16px';
	this.bottomFrame.style.bottom = '0px';
	this.bottomFrame.style.backgroundImage='url('+path+'/windows/bottom.png)';
	this.bottomFrame.style.zIndex = this.zIndex+1;
	
	this.leftFrame = document.createElement('div');
	this.mainDiv.appendChild(this.leftFrame);
	this.leftFrame.style.position = 'absolute';
	this.leftFrame.style.width = '16px';
	this.leftFrame.style.left = '0px';
	this.leftFrame.style.top = '16px';
	this.leftFrame.style.bottom = '16px';
	this.leftFrame.style.backgroundImage='url('+path+'/windows/left.png)';
	this.leftFrame.style.zIndex = this.zIndex+1;	

	this.rightFrame = document.createElement('div');
	this.mainDiv.appendChild(this.rightFrame);
	this.rightFrame.style.position = 'absolute';
	this.rightFrame.style.width = '16px';
	this.rightFrame.style.right = '0px';
	this.rightFrame.style.top = '16px';
	this.rightFrame.style.bottom = '16px';
	this.rightFrame.style.backgroundImage='url('+path+'/windows/right.png)';
	this.rightFrame.style.zIndex = this.zIndex+1;	

	this.rightBottomFrame = document.createElement('div');
	this.mainDiv.appendChild(this.rightBottomFrame);
	this.rightBottomFrame.style.position = 'absolute';
	this.rightBottomFrame.style.width = '16px';
	this.rightBottomFrame.style.right = '0px';
	this.rightBottomFrame.style.height = '16px';
	this.rightBottomFrame.style.bottom = '0px';
	this.rightBottomFrame.style.backgroundImage='url('+path+'/windows/right_bottom.png)';
	this.rightBottomFrame.style.zIndex = this.zIndex+1;
	if(this.rightBottomFrame.addEventListener){
		this.rightBottomFrame.addEventListener('mousedown', mouseDown, true);
	}
		
	if (this.sizingEnable == true){
		var obj = this;
		this.rightBottomFrame.style.cursor = 'nw-resize';
		this.rightBottomFrame.onmousedown = function(e){
			obj.xTmp = xMouseCoordinate;
			obj.yTmp = yMouseCoordinate;	
			obj.size = true;				
		}
			
		onMouseMoveFunctions[onMouseMoveFunctions.length] = function(e){
			
			if (obj.size==true)
			{
				var dx = obj.xTmp - xMouseCoordinate;
				var dy = obj.yTmp - yMouseCoordinate;
				
				//obj.contentDiv.innerHTML = obj.mainDiv.clientWidth+" "+obj.mainDiv.clientHeight;
				if (obj.width-dx>obj.minWidth)
				obj.mainDiv.style.width = (obj.width-dx)+'px';
				
				if (obj.height-dy>obj.minHeight)
				obj.mainDiv.style.height = (obj.height-dy)+'px';
			}

		}
			
		onMouseUpFunctions[onMouseUpFunctions.length] = function(e){
			if (obj.size==true)
			{
				var dx = obj.xTmp - xMouseCoordinate;
				var dy = obj.yTmp - yMouseCoordinate;
				//alert(dx+' '+dy);
				obj.width-=dx;
				obj.height-=dy;
				if (obj.width<obj.minWidth) obj.width = obj.minWidth;
				if (obj.height<obj.minHeight) obj.height = obj.minHeight;
				
				obj.mainDiv.style.width = obj.width+'px';
				obj.mainDiv.style.height = obj.height+'px';
				obj.size = false;
			}
		}

	}
	
	this.leftBottomFrame = document.createElement('div');
	this.mainDiv.appendChild(this.leftBottomFrame);
	this.leftBottomFrame.style.position = 'absolute';
	this.leftBottomFrame.style.width = '16px';
	this.leftBottomFrame.style.left = '0px';
	this.leftBottomFrame.style.height = '16px';
	this.leftBottomFrame.style.bottom = '0px';
	this.leftBottomFrame.style.backgroundImage='url('+path+'/windows/left_bottom.png)';
	this.leftBottomFrame.style.zIndex = this.zIndex+1;	
	
	this.topFrame = document.createElement('div');
	this.mainDiv.appendChild(this.topFrame);
	this.topFrame.style.position = 'absolute';
	this.topFrame.style.height = '16px';
	this.topFrame.style.left = '16px';
	this.topFrame.style.right = '16px';
	this.topFrame.style.top = '0px';
	this.topFrame.style.backgroundImage='url('+path+'/windows/top.png)';
	this.topFrame.style.zIndex = this.zIndex+1;
	
	this.leftTopFrame = document.createElement('div');
	this.mainDiv.appendChild(this.leftTopFrame);
	this.leftTopFrame.style.position = 'absolute';
	this.leftTopFrame.style.width = '16px';
	this.leftTopFrame.style.left = '0px';
	this.leftTopFrame.style.height = '16px';
	this.leftTopFrame.style.top = '0px';
	this.leftTopFrame.style.backgroundImage='url('+path+'/windows/left_top.png)';
	this.leftTopFrame.style.zIndex = this.zIndex+1;	
	
	this.rightTopFrame = document.createElement('div');
	this.mainDiv.appendChild(this.rightTopFrame);
	this.rightTopFrame.style.position = 'absolute';
	this.rightTopFrame.style.width = '16px';
	this.rightTopFrame.style.right = '0px';
	this.rightTopFrame.style.height = '16px';
	this.rightTopFrame.style.top = '0px';
	this.rightTopFrame.style.backgroundImage='url('+path+'/windows/right_top.png)';
	this.rightTopFrame.style.zIndex = this.zIndex+1;	

	if (this.toolbar>0){
		this.toolbarDiv = document.createElement('div');
		this.mainDiv.appendChild(this.toolbarDiv);
		this.toolbarDiv.style.position = 'absolute';
		this.toolbarDiv.style.left = '16px';
		this.toolbarDiv.style.right = '16px';
		this.toolbarDiv.style.height = this.toolbar+'px';
		this.toolbarDiv.style.top = '10px';
		if (this.movingEnable==true)
		this.toolbarDiv.style.cursor = 'pointer';
		this.toolbarDiv.style.backgroundImage='url('+path+'/windows/tlo1.jpg)';
		this.toolbarDiv.style.zIndex = this.zIndex+2;	
		

		
		this.toolbarRightDiv = document.createElement('div');
		this.mainDiv.appendChild(this.toolbarRightDiv);
		this.toolbarRightDiv.style.position = 'absolute';
		this.toolbarRightDiv.style.width = '16px';
		this.toolbarRightDiv.style.right = '15px';
		this.toolbarRightDiv.style.height = (this.toolbar)+'px';
		this.toolbarRightDiv.style.top = '9px';
		this.toolbarRightDiv.style.backgroundImage='url('+path+'/windows/right_przejscie.png)';
		this.toolbarRightDiv.style.zIndex = this.zIndex+4;	
		
		this.toolbarLeftDiv = document.createElement('div');
		this.mainDiv.appendChild(this.toolbarLeftDiv);
		this.toolbarLeftDiv.style.position = 'absolute';
		this.toolbarLeftDiv.style.width = '16px';
		this.toolbarLeftDiv.style.left = '15px';
		this.toolbarLeftDiv.style.height = (this.toolbar)+'px';
		this.toolbarLeftDiv.style.top = '9px';
		this.toolbarLeftDiv.style.backgroundImage='url('+path+'/windows/left_przejscie.png)';
		this.toolbarLeftDiv.style.zIndex = this.zIndex+4;
		
		this.toolbarDolDiv = document.createElement('div');
		this.mainDiv.appendChild(this.toolbarDolDiv);
		this.toolbarDolDiv.style.position = 'absolute';
		this.toolbarDolDiv.style.left = '15px';
		this.toolbarDolDiv.style.right = '15px';
		this.toolbarDolDiv.style.height = '2px';
		this.toolbarDolDiv.style.top = (this.toolbar+8)+'px';
		this.toolbarDolDiv.style.backgroundImage='url('+path+'/windows/toolbar_dol.png)';
		this.toolbarDolDiv.style.zIndex = this.zIndex+3;

		this.toolbarContainer = document.createElement('div');
		this.mainDiv.appendChild(this.toolbarContainer);
		this.toolbarContainer.style.position = 'absolute';
		this.toolbarContainer.style.overflow='hidden';
		this.toolbarContainer.style.left = '15px';
		this.toolbarContainer.style.right = '15px';
		this.toolbarContainer.style.height = this.toolbar+'px';
		this.toolbarContainer.style.top = '10px';
		
		//if (this.movingEnable==true)
		//this.toolbarContainer.style.cursor = 'pointer';
		this.toolbarContainer.style.zIndex = this.zIndex+5;		
		if(this.toolbarContainer.addEventListener){
			this.toolbarContainer.addEventListener('mousedown', mouseDown, true);
		}
		
		var obj = this;
		
		if (this.movingEnable==true){
			this.toolbarContainer.onmousedown = function(e)
			{
				obj.xTmp = xMouseCoordinate;
				obj.yTmp = yMouseCoordinate;	
				obj.move = true;				
			}
			
			onMouseMoveFunctions[onMouseMoveFunctions.length] = function(e){
			
				if (obj.move==true)
				{
					var dx = obj.xTmp - xMouseCoordinate;
					var dy = obj.yTmp - yMouseCoordinate;

					if (obj.left!=null)
					obj.mainDiv.style.left = (obj.left-dx)+'px';
					else
					obj.mainDiv.style.right = (obj.right+dx)+'px';
					
					if (obj.top!=null)
					obj.mainDiv.style.top = (obj.top-dy)+'px';
					else
					obj.mainDiv.style.bottom = (obj.bottom+dy)+'px';
				}

			}
			this.toolbarContainer.onmouseup = function(e){
				if (obj.move==true)
				{
					var dx = obj.xTmp - xMouseCoordinate;
					var dy = obj.yTmp - yMouseCoordinate;

					if (obj.left!=null)
					obj.left-=dx;
					else
					obj.right+=dx;
					
					if (obj.top!=null)
					obj.top-=dy;
					else
					obj.bottom+=dy;
					
					if (obj.left!=null)
					obj.mainDiv.style.left = (obj.left)+'px';
					else
					obj.mainDiv.style.right = (obj.right)+'px';
					
					if (obj.top!=null)
					obj.mainDiv.style.top = (obj.top)+'px';
					else
					obj.mainDiv.style.bottom = (obj.bottom)+'px';
					
					obj.move = false;
				}
			}
		}		
		if (this.isClose == true){
			this.closeDiv = document.createElement('div');
			this.mainDiv.appendChild(this.closeDiv);
			this.closeDiv.style.position = 'absolute';
			this.closeDiv.style.right = '16px';
			this.closeDiv.style.width = '28px';
			this.closeDiv.style.height = '15px';
			this.closeDiv.style.top = (10+Math.round((this.toolbar-15)*0.5))+'px';
			this.closeDiv.myTop = (10+Math.round((this.toolbar-15)*0.5));
			this.closeDiv.style.zIndex = this.zIndex+6;
			this.closeDiv.style.backgroundImage='url('+path+'/windows/close.png)';			
			if(this.closeDiv.addEventListener){
			this.closeDiv.addEventListener('mousedown', mouseDown, true);
			}
			var obj = this;
			var img = new Image();
			img.src = path+'/windows/closep.png';
			this.closeDiv.onmouseover = function()
			{
				obj.closeDiv.style.backgroundImage='url('+path+'/windows/closep.png)';		
			}
			this.closeDiv.onmouseout = function()
			{
				obj.closeDiv.style.backgroundImage='url('+path+'/windows/close.png)';	
				obj.closeDiv.style.top = (obj.closeDiv.myTop)+'px';					
			}			
			this.closeDiv.onmousedown = function()
			{
				obj.closeDiv.style.top = (obj.closeDiv.myTop+1)+'px';		
			}	
			this.closeDiv.onmouseup = function()
			{
				obj.closeDiv.style.top = (obj.closeDiv.myTop)+'px';	
				obj.mainDiv.style.display = 'none';	
				if (obj.onclose!=null)
				obj.onclose();
				
			}			
		}
	
	
	}	
	this.show = function()
	{
		this.mainDiv.style.display = 'block';
	}
	this.hide = function()
	{
		this.mainDiv.style.display = 'none';
	}
	this.addButton = function(button)
	{
		button.appendTo(this.toolbarContainer);
	}
	this.addLabel = function(label){
		label.appendTo(this.toolbarContainer);
	}
	this.addTab = function(tab){
		this.tabs[this.tabs.length] = tab;
		tab.appendTo(this.toolbarContainer);
		//tab.zIndex = this.zIndex;
		tab.mainDiv.style.top=(this.toolbar-tab.height)+'px';
		this.contentDiv.appendChild(tab.contentDiv);
	}
	this.removeAllTabs = function(){
		for (i=0;i<this.tabs.length;i++)
		{
			this.tabs[i].mainDiv.parentNode.removeChild(this.tabs[i].mainDiv);
		}
		for (i=0;i<this.tabs.length;i++)
		{
			this.tabs.remove(0);
		}
		this.contentDiv.innerHTML = '';
		this.tabs = new Array();
	}
}

function MyNode(caption,image,value,checked){
	var obj = this;
	this.value = value;
	this.mainDiv = document.createElement('div');
	this.mainDiv.style.position = 'relative';
	this.mainDiv.style.fontFamily = 'tahoma';
	this.mainDiv.oncontextmenu = function(e){
		return false; 
	}
	this.image = image;
	var img = new Image();
	img.src = image;

	this.captionDiv = document.createElement('div');
	this.mainDiv.appendChild(this.captionDiv);
	this.captionDiv.style.position = 'relative';
	this.captionDiv.style.overflow = 'hidden';
	this.captionDiv.style.fontSize = '12px';
	this.strzalka =null;
	this.captionDiv.oncontextmenu = function(e){
			return false; 
	}
	this.checkDiv = null;
	//this.captionDiv.style.backgroundColor = '#eee';
	//this.captionDiv.style.padding = '2px 2px 2px 2px';
	this.expanded = true;
	if (checked!=undefined)
	this.checked = 	checked;
	else	
	this.checked = false;
	
	this.contentDiv = document.createElement('div');
	this.mainDiv.appendChild(this.contentDiv);
	this.contentDiv.style.position = 'relative';
	this.contentDiv.style.fontSize = '12px';
	this.contentDiv.style.padding = '0px 0px 0px 16px';	
	this.nodes = new Array();
	
	this.loaded = false;
	this.onclickcheck = null;
	this.onorderchange = null;
	this.onchildorderchange = null;
	this.onrightclick = null;
	
	this.setCheckImages = function(){
		if (this.checkDiv!=null)
		{
			if (this.checked==true)
			this.checkDiv.src=path+'/windows/checkz.png';	
			else
			this.checkDiv.src=path+'/windows/check.png';			
		}
	}
	this.setPluses = function(){
		if (this.nodes.length>0)
		{
			if(this.expanded==false) 
			this.strzalka.src=path+'/windows/plusik1.png';	
			else
			this.strzalka.src=path+'/windows/plusikr1.png';	
		}
		else
		{
			this.strzalka.src=path+'/windows/plusikn1.png';	
		}
	}
	this.init = function(){
		var img = new Image();
		img.src=path+'/windows/plusik1pod.png';	
		var img1 = new Image();
		img1.src=path+'/windows/plusikr1pod.png';	
		var img2 = new Image();
		img2.src=path+'/windows/checkz.png';	
		
		
		this.textDiv = document.createElement('div');
		this.captionDiv.appendChild(this.textDiv);
		this.textDiv.style.position = 'relative';
		this.textDiv.style.padding = '0px 0px 0px 0px ';
		
		this.tableCaption = document.createElement('table');
		this.textDiv.appendChild(this.tableCaption);
		this.tableCaption.style.cellPadding='0px';
		this.tableCaption.style.cellSpacing='0px';
		this.tableCaption.style.borderWidth='0px';
		
		this.tbody = document.createElement('tbody');
		this.tableCaption.appendChild(this.tbody);
		
		//this.tableCaption.style.backgroundColor='#eee';
		this.tableCaption.style.padding = '0px';
		var tr = document.createElement('tr');
		this.tbody.appendChild(tr);
		
		this.strzalka = new Image();
		this.strzalka.src=path+'/windows/plusik1.png';	


		this.checkDiv = new Image();
		this.checkDiv.src=path+'/windows/check.png';
		
		var obj = this;
		this.checkDiv.onclick = function()
		{
			if (obj.checked==true) 
			obj.checked=false;
			else
			obj.checked=true;

			obj.setCheckImages();
			if (obj.onclickcheck!=null)
			obj.onclickcheck(obj.checked,obj.data);
		}
		
		this.tdStrzalka = document.createElement('td');
		this.tdStrzalka.appendChild(this.strzalka);
		this.tdStrzalka.style.width = '10px';
		//this.tdStrzalka.style.backgroundColor='#ddd';
		tr.appendChild(this.tdStrzalka);
		
		var tdCheck = document.createElement('td');
		tdCheck.appendChild(this.checkDiv);
		//tdCheck.style.backgroundColor='#bbd';
		//this.tdStrzalka.style.width = '10px';
		if (checked!=null)
		tr.appendChild(tdCheck);
		
		if (this.image!='')
		{
			this.tdImage = document.createElement('td');
			this.tdImage.innerHTML = '<img src="'+this.image+'"/>';
			tr.appendChild(this.tdImage);
		}

		this.tdText = document.createElement('td');
		tr.appendChild(this.tdText);
		this.tdText.style.padding='1px 3px 1px 3px';
		this.tdText.innerHTML = caption;

		this.loadingDiv = document.createElement('div');
		this.loadingDiv.innerHTML = '<img src="'+path+'/windows/loading2.gif"/>'
		this.loadingDiv.style.display = 'none';
		
		this.tdLoad = document.createElement('td');
		tr.appendChild(this.tdLoad);
		this.tdLoad.style.padding='1px 3px 1px 3px';
		this.tdLoad.appendChild(this.loadingDiv);
		
		
		
		this.coverDiv = document.createElement('div');
		this.captionDiv.appendChild(this.coverDiv);
		this.coverDiv.style.position = 'absolute';
		this.coverDiv.style.top = '0px';
		this.coverDiv.style.left = '31px';
		this.coverDiv.style.right = '0px';
		this.coverDiv.style.bottom = '0px';
		//this.coverDiv.style.backgroundColor='#bbd';
		//this.coverDiv.style.cursor = 'pointer'; 
		this.coverDiv.style.backgroundImage='url('+path+'windows/blank.png)';
		if(this.coverDiv.addEventListener){
			this.coverDiv.addEventListener('mousedown', mouseDown, true);
		}
		
		var img1 = new Image();
		img1.src = path+'/windows/upp.png';
		var img2 = new Image();
		img2.src = path+'/windows/downp.png';
		
		this.upLayer = document.createElement('div');
		this.coverDiv.appendChild(this.upLayer);
		this.upLayer.style.position = 'absolute';
		this.upLayer.style.top = Math.round(2)+'px';
		this.upLayer.style.right = '3px';
		this.upLayer.style.width = '11px';
		this.upLayer.style.height = '7px';
		this.upLayer.style.display = 'none';
		this.upLayer.style.backgroundImage='url('+path+'/windows/up.png)';

		this.downLayer = document.createElement('div');
		this.coverDiv.appendChild(this.downLayer);
		this.downLayer.style.position = 'absolute';
		this.downLayer.style.bottom = Math.round(2)+'px';
		this.downLayer.style.right = '3px';
		this.downLayer.style.width = '11px';
		this.downLayer.style.height = '7px';
		this.downLayer.style.display = 'none';
		this.downLayer.style.backgroundImage='url('+path+'/windows/down.png)';
		
		var obj = this;
		
		this.upLayer.onmouseover = function(){
			obj.upLayer.style.backgroundImage='url('+path+'/windows/upp.png)';
		}
		this.upLayer.onmouseout = function(){
			obj.upLayer.style.backgroundImage='url('+path+'/windows/up.png)';
		}		
		this.downLayer.onmouseover = function(){
			obj.downLayer.style.backgroundImage='url('+path+'/windows/downp.png)';
		}
		this.downLayer.onmouseout = function(){
			obj.downLayer.style.backgroundImage='url('+path+'/windows/down.png)';
		}
		this.upLayer.onmouseup = function(e){
			if (isRightButtonPressed(e)==false)
			{
				var parent = obj.mainDiv.parentNode;
				var index = -1;
				for (i=0;i<parent.childNodes.length;i++)
				{
					if (parent.childNodes[i] == obj.mainDiv)
					index = i;
				}
				if (index>0)
				{
					parent.removeChild(obj.mainDiv);
					parent.insertBefore(obj.mainDiv,parent.childNodes[index-1]);
					
					if (obj.onorderchange!=null)
					{
						obj.onorderchange();		
					}
					if (obj.parentNode!=null)
					{
						obj.parentNode.pushNodeUp(obj);
						if (obj.parentNode.onchildorderchange!=null)
						{
							obj.parentNode.onchildorderchange();
						}			
					}
					if (obj.parentGroup!=null)
					{
						obj.parentGroup.pushNodeUp(obj);
						if (obj.parentGroup.onchildorderchange!=null)
						{
							obj.parentGroup.onchildorderchange();
						}			
					}
					obj.coverDiv.onmouseout(e);
				}				
			}
		}
		this.downLayer.onmouseup = function(e){
			if (isRightButtonPressed(e)==false)
			{
				var parent = obj.mainDiv.parentNode;
				var index = -1;
				for (i=0;i<parent.childNodes.length;i++)
				{
					if (parent.childNodes[i] == obj.mainDiv)
					index = i;
				}
				if (index<parent.childNodes.length-1)
				{
					var next = parent.childNodes[index+2];
					if (next!=null)
					{
						parent.removeChild(obj.mainDiv);
						parent.insertBefore(obj.mainDiv,next);
					}
					else
					{
						parent.removeChild(obj.mainDiv);
						parent.appendChild(obj.mainDiv);
					}
					if (obj.onorderchange!=null)
					{
						obj.onorderchange();
					}

					if (obj.parentNode!=null)
					{
						obj.parentNode.pushNodeDown(obj);
						if (obj.parentNode.onchildorderchange!=null)
						{
								obj.parentNode.onchildorderchange();
						}			
					}
					if (obj.parentGroup!=null)
					{
						obj.parentGroup.pushNodeDown(obj);
						if (obj.parentGroup.onchildorderchange!=null)
						{
							obj.parentGroup.onchildorderchange();
						}			
					}
					obj.coverDiv.onmouseout(e);
					
				}				
			}
		}
		this.coverDiv.onclick = function(){

		}
		this.coverDiv.onmouseover = function(){
			obj.captionDiv.style.backgroundColor='#dde7ef';
			obj.downLayer.style.display = 'block';
			obj.upLayer.style.display = 'block';
		}
		this.coverDiv.onmouseout = function(){
			obj.captionDiv.style.backgroundColor='#fff';
			obj.downLayer.style.display = 'none';
			obj.upLayer.style.display = 'none';			
			obj.downLayer.style.backgroundImage='url('+path+'/windows/down.png)';
			obj.upLayer.style.backgroundImage='url('+path+'/windows/up.png)';
		}		
		this.coverDiv.onmouseup = function(e){
			if (isRightButtonPressed(e)==true){  
				if (obj.onrightclick !=null) obj.onrightclick(obj.data);
			}
		}			
		
		this.coverDiv.oncontextmenu = function(e){
			return false; 
		}
		
		this.strzalka.onmouseup = function(e){
			if (isRightButtonPressed(e)==false)
			{
				if (obj.expanded == true)
				obj.collpase();
				else
				obj.expand();
			}
		}
		this.strzalka.onmouseover = function(e){
			if (obj.nodes.length>0)
			{
			if(obj.expanded==false) 
			obj.strzalka.src=path+'/windows/plusik1pod.png';	
			else
			obj.strzalka.src=path+'/windows/plusikr1pod.png';	
			}
			else
			{
				obj.strzalka.src=path+'/windows/plusikn1.png';	
			}
		}
		this.strzalka.onmouseout = function(e){
			if (obj.nodes.length>0)
			{
			if(obj.expanded==false) 
			obj.strzalka.src=path+'/windows/plusik1.png';	
			else
			obj.strzalka.src=path+'/windows/plusikr1.png';	
			}
			else
			{
				obj.strzalka.src=path+'/windows/plusikn1.png';	
			}
		}		
		this.setPluses();
		this.setCheckImages();
		this.loaded = true;
	}	
	
	obj.imageWidth = 0;
	if (this.image!=''){
		var img = new Image();
		img.onload = function()
		{
			obj.imageWidth = img.width;
			obj.imageHeight = img.height;
			obj.init();
		}
		img.src = this.image;
	}
	else
	this.init();
	
	

	this.showPluses = function(){
		if (this.loaded==true)
		{
		/*
			if (this.strzalka!=null)
			{
				this.setPluses();
				
				this.strzalka.style.display = 'block';
			}
			//alert(this.nodes.length);
			if (this.nodes.length>0)
			for(i=0;i<this.nodes.length;i++)
			this.nodes[i].showPluses();
		*/	
		}
	}
	this.setPluses = function(){
		if (this.strzalka!=null){
			if (this.nodes.length>0)
			{	
				if(this.expanded==false) 
				this.strzalka.src=path+'/windows/plusik1.png';	
				else
				this.strzalka.src=path+'/windows/plusikr1.png';	
			}
			else
			{
				this.strzalka.src=path+'/windows/plusikn1.png';	
			}
		}
	}
	this.hidePluses = function(){
		if (this.loaded==true)
		{	
		/*
			if (this.strzalka!=null)
			this.strzalka.style.display = 'none';
			if (this.nodes.length>0)
			for(i=0;i<this.nodes.length;i++)
			this.nodes[i].hidePluses();
		*/	
		}
	}	
	this.addNode = function(node){
		this.nodes[this.nodes.length] = node;
		this.contentDiv.appendChild(node.mainDiv);
		node.parentNode = this;
		node.parentGroup = null;	
	}
	this.expand = function(){
		
		this.contentDiv.style.display = 'block';
		this.expanded = true;
		this.setPluses();
	}
	this.collpase = function(){
		
		this.contentDiv.style.display = 'none';
		this.expanded = false;
		this.setPluses();
	}	
	this.getChildValuesString = function(){
		s = '';
		for(i=0;i<this.nodes.length;i++)
		{
			s+=','+this.nodes[i].value;
		}
		if (s.length>0)
		{
			return s.substring(1);
		}
		else
		return s;
	}
	this.showLoading = function(){
		if (this.loadingDiv!=undefined)
		this.loadingDiv.style.display = 'block';
	}
	this.hideLoading = function(){
		if (this.loadingDiv!=undefined)
		this.loadingDiv.style.display = 'none';
	}	
	this.pushNodeUp = function(node){
		var index=-1;
		for (i=0;i<this.nodes.length;i++)
		{
			if (this.nodes[i] == node) index = i;
		}
		if (index>0)
		{
			var stary = this.nodes[index-1];
			this.nodes.splice(index-1,1,node);
			this.nodes.splice(index,1,stary);
		}
	}
	this.pushNodeDown = function(node){
		var index=-1;
		for (i=0;i<this.nodes.length;i++)
		{
			if (this.nodes[i] == node) index = i;
		}
		if ((index<(this.nodes.length-1))&&(index!=-1))
		{
			var stary = this.nodes[index+1];
			this.nodes.splice(index+1,1,node);
			this.nodes.splice(index,1,stary);
		}
	}	
	this.setCaption = function(text){
		this.tdText.innerHTML = text;
	}
	this.removeNodes = function(){
		this.nodes = new Array();
		this.contentDiv.innerHTML = null;
	}
	this.setCheck = function(checked){
		this.checked = checked;
		this.setCheckImages();
		if (this.onclickcheck!=null)
		this.onclickcheck(this.checked,this.data);
	}
	this.setChildCheck = function(checked,value){
		value = value.toLowerCase();
		var i=0;
		if (value==null){
			this.setCheck(checked);
			
			for (i=0;i<this.nodes.length;i++){
				this.nodes[i].setChildCheck(checked,value);
			}
		} else {
			if (this.value == value) this.setCheck(checked);
			
			for (i=0;i<this.nodes.length;i++){
				if (this.nodes[i].value.toLowerCase()==value)
				this.nodes[i].setChildCheck(checked,value);
			}	
		}
	}
}

function MyGroup(caption,showCaption){
	this.caption = caption;
	this.showCaption = showCaption;
	this.nodes = new Array();
	this.expanded = true;
	this.onchildorderchange = null;
	this.mainDiv = document.createElement('div');
	this.mainDiv.style.position = 'relative';
	
	if (this.showCaption==true){
		this.captionDiv = document.createElement('div');
		this.mainDiv.appendChild(this.captionDiv);
		this.captionDiv.style.position = 'relative';
		this.captionDiv.style.fontSize = '12px';
		this.captionDiv.style.borderBottom = '1px dotted #aaa';
		this.captionDiv.style.borderTop = '1px dotted #aaa';
		//this.captionDiv.style.backgroundImage = 'url()';
		this.captionDiv.style.padding = '3px 3px 3px 3px';
		this.captionDiv.style.margin = '1px 1px 1px 1px';
		this.captionDiv.style.fontFamily = 'tahoma';
		//this.captionDiv.style.cursor = 'pointer';
		
		this.textDiv = document.createElement('div');
		this.captionDiv.appendChild(this.textDiv);
		this.textDiv.style.position = 'relative';
		this.textDiv.style.padding = '0px 23px 0px 0px ';
		this.textDiv.innerHTML = caption;

		this.strzalka = document.createElement('div');
		this.captionDiv.appendChild(this.strzalka);
		this.strzalka.style.position = 'absolute';
		this.strzalka.style.right = '7px';
		this.strzalka.style.top = '3px';
		this.strzalka.style.width = '14px';
		this.strzalka.style.height = '14px';
		this.strzalka.style.backgroundImage='url('+path+'/windows/strzalka_down.png)';
		
		this.coverDiv = document.createElement('div');
		this.captionDiv.appendChild(this.coverDiv);
		this.coverDiv.style.position = 'absolute';
		this.coverDiv.style.right = '0px';
		this.coverDiv.style.top = '0px';
		this.coverDiv.style.left = '0px';
		this.coverDiv.style.bottom = '0px';
		this.coverDiv.style.backgroundImage='url('+path+'windows/blank.png)';		
		//this.coverDiv.style.cursor = 'pointer';
		if(this.coverDiv.addEventListener){
			this.coverDiv.addEventListener('mousedown', mouseDown, true);
		}
		
		var obj = this;
		this.coverDiv.onclick = function(){
			if (obj.expanded == true)
			{
				obj.contentDiv.style.display = 'none';
				obj.expanded = false;
				obj.strzalka.style.backgroundImage='url('+path+'/windows/strzalka_right.png)';
			}
			else
			{
				obj.contentDiv.style.display = 'block';
				obj.expanded = true;
				obj.strzalka.style.backgroundImage='url('+path+'/windows/strzalka_down.png)';
			}			
		}
		
		this.coverDiv.onmouseover = function(){
			obj.captionDiv.style.backgroundColor = '#dde7ef';
		}
		this.coverDiv.onmouseout = function()
		{
			obj.captionDiv.style.backgroundColor = '#fff';
		}
		
	}
	

	this.contentDiv = document.createElement('div');
	this.mainDiv.appendChild(this.contentDiv);
	this.contentDiv.position = 'relative';
	this.contentDiv.style.padding = '0px 0px 0px 0px';
	
	var obj = this;
	this.contentDiv.onmouseover = function(){
		obj.showPluses();
	}
	this.contentDiv.onmouseout = function(){
		obj.hidePluses();
	}	
	this.addNode = function(node){
		node.zIndex = this.zIndex;
		this.nodes[this.nodes.length] = node;
		this.contentDiv.appendChild(node.mainDiv);
		node.parentNode = null;
		node.parentGroup = this;	
	}
	this.addNodeFirst = function(node){
		node.zIndex = this.zIndex;
		this.nodes[this.nodes.length] = node;
		if (this.contentDiv.childNodes.length==0){
			this.contentDiv.appendChild(node.mainDiv);
			node.parentNode = null;
			node.parentGroup = this;	
		} else {
			this.contentDiv.insertBefore(node.mainDiv,this.contentDiv.childNodes[0]);
			node.parentNode = null;
			node.parentGroup = this;	
		}
	}	
	this.showPluses = function(){
		for(i=0;i<this.nodes.length;i++)
		this.nodes[i].showPluses();
	}
	this.hidePluses = function(){
		for(i=0;i<this.nodes.length;i++)
		this.nodes[i].hidePluses();
	}
	this.getChildValuesString = function(){
		s = '';
		for(i=0;i<this.nodes.length;i++)
		{
			s+=','+this.nodes[i].value;
		}
		if (s.length>0)
		{
			return s.substring(1);
		}
		else
		return s;
	}
	this.pushNodeUp = function(node){
		var index=-1;
		for (i=0;i<this.nodes.length;i++)
		{
			if (this.nodes[i] == node) index = i;
		}
		if (index>0)
		{
			var stary = this.nodes[index-1];
			this.nodes.splice(index-1,1,node);
			this.nodes.splice(index,1,stary);
		}
	}
	this.pushNodeDown = function(node){
		var index=-1;
		for (i=0;i<this.nodes.length;i++)
		{
			if (this.nodes[i] == node) index = i;
		}
		if ((index<(this.nodes.length-1))&&(index!=-1))
		{
			var stary = this.nodes[index+1];
			this.nodes.splice(index+1,1,node);
			this.nodes.splice(index,1,stary);
		}
	}	
	this.setChildCheck = function(checked,value){
		value = value.toLowerCase();
		var i=0;
		if (value==null){
			for (i=0;i<this.nodes.length;i++){
				this.nodes[i].setChildCheck(checked,null);
			}
		} else {
			for (i=0;i<this.nodes.length;i++){
				this.nodes[i].setChildCheck(checked,value);
			}
		}
	}
}

function MyTreeView(left,top,right,bottom,zIndex){
	this.mainDiv = document.createElement('div');
	this.mainDiv.style.position = 'absolute';
	this.mainDiv.style.left = left+'px';
	this.mainDiv.style.top = top+'px';
	this.mainDiv.style.right = right+'px';
	this.mainDiv.style.bottom = bottom+'px';
	this.mainDiv.style.backgroundColor = '#aaa';
	
	this.mainDiv.oncontextmenu = function(e){
			return false; 
	}
	//this.mainDiv.innerHTML = '<img style="width:100%;height:100%" src="'+path+'/windows/tlo2.png"/>';
	this.zIndex = zIndex;
	this.contentDiv = document.createElement('div');
	this.mainDiv.appendChild(this.contentDiv);
	this.contentDiv.style.position = 'absolute';
	this.contentDiv.style.left = '1px';
	this.contentDiv.style.top = '1px';
	this.contentDiv.style.right = '1px';
	this.contentDiv.style.bottom = '1px';
	this.contentDiv.style.overflow = 'auto';
	this.contentDiv.style.backgroundColor = '#fff';	
		
	this.group = new Array();	
		
	this.appendTo = function(div)
	{
		div.appendChild(this.mainDiv);
	}
	
	this.addGroup = function(group)
	{
		group.zIndex = this.zIndex;
		this.contentDiv.appendChild(group.mainDiv);
		this.group[this.group.length] = group;	
	}
}

function podswietl(div){
	
}

function MyMenu(items,width){
	var obj = this;
	this.createPosition = function(index,text,onclickfun){
			var itemDiv = document.createElement('div');
			itemDiv.style.position = 'absolute';
			itemDiv.style.right = '1px';
			itemDiv.style.height = '20px';
			itemDiv.style.left = '1px';
			itemDiv.style.paddingTop = '2px';
			itemDiv.style.paddingLeft = '6px';
			itemDiv.style.backgroundColor = '#fff';
			itemDiv.innerHTML = text;
			itemDiv.style.top = (1+(index*22))+'px';
			this.mainDiv.appendChild(itemDiv);
			itemDiv.oncontextmenu = function(e){
				return false; 
			}
			
			var coverDiv = document.createElement('div');
			coverDiv.style.position = 'absolute';
			coverDiv.style.width = '100%';
			coverDiv.style.height = '100%';
			coverDiv.style.left = '0px';
			coverDiv.style.top = '0px';
			coverDiv.style.backgroundImage = 'url('+path+'windows/blank.png)';
			coverDiv.oncontextmenu = function(e){
				return false; 
			}
			itemDiv.appendChild(coverDiv);			

			coverDiv.onmouseover = function(e){		
				itemDiv.style.backgroundColor = '#dde7ef';		
			}
			coverDiv.onmouseout = function(e){				
				itemDiv.style.backgroundColor = '#fff';
			}
			
			if (onclickfun!=null){ 
				coverDiv.onclick = function(e){					
					onclickfun(obj.data);
				}	
			}
	
	}
	if (items!=null){
		var ile = items.length;
		this.mainDiv = document.createElement('div');
		this.mainDiv.style.position = 'absolute';		
		this.mainDiv.style.backgroundColor = '#999';
		this.mainDiv.oncontextmenu = function(e){
			return false; 
		}
		//this.mainDiv.style.border = '1px solid #999';
		if (width==null) width = '200'
		this.mainDiv.style.width = width+'px';
		this.mainDiv.style.height = (2+(ile*22))+'px';
		this.mainDiv.style.display = 'none';
		this.mainDiv.style.zIndex = '900000';
		var i;
		for (i=0;i<ile;i++){
			this.createPosition(i,items[i].text,items[i].onclick);
			
		}
		myMenus.push(this);
	}	
	this.show = function(data){
		for(i=0;i<myMenus.length;i++){
			myMenus[i].mainDiv.style.display = 'none';
		}
		var x = xMouseCoordinate;
		var y = yMouseCoordinate;
		obj.data = data;
		obj.mainDiv.style.left = x+'px';
		obj.mainDiv.style.top = y+'px';
		obj.mainDiv.style.display = 'block';
		document.body.appendChild(obj.mainDiv);
	}
}
