//funkcja zamykajaca okno komunikatu
function MsgBox_close(){
	if (document.getElementById("tlokomunikat")) document.getElementsByTagName("body")[0].removeChild(document.getElementById("tlokomunikat"));
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("komunikat"));
}

// klasa pobiera dane ekrany, wysokosc, szerokosc, scroll x i y
function Ekran () {
	this.imgpath="../";
	this.render="html";
	this.scrollX=0;
	this.scrollY=0;
	this.sizeX=0;
	this.sizeY=0;
	document.write('<div id="tooltip"></div>');
	this.tooltip=0;
}
Ekran.prototype.showTip = function (obj) {
	
	if (this.tooltip==1) return;
	this.tooltip=1;
	tip = document.getElementById("tooltip");
	tip.style.visibility="visible"
	tip.innerHTML = obj.getAttribute("tooltip")
	
	h = obj.height;
	w = obj.offsetWidth;
	
	var curLeft=0
	var curTop=1

  	if(obj.offsetParent) {
    	do {
      		curLeft += obj.offsetLeft;
      		curTop += obj.offsetTop;
    	} 	while(obj = obj.offsetParent)
    }
	oleft = curLeft;
	otop = curTop+h;
	
	if (oleft<0) oleft=0;
	if (otop<0) otop=0;	
	this.centerXY(0,0);
	if (oleft>this.sizeX-100) {	oleft -=100;}	
	if (otop+tip.offsetHeight>this.sizeY+this.scrollY) {
		otop-=((otop+tip.offsetHeight)-(this.sizeY+this.scrollY))//(otop+tip.offsetHeight-this.sizeY+this.scrollY)
		oleft+=w;
	}
		
	tip.style.top=otop+"px";
	tip.style.left=oleft+"px"; 
}
Ekran.prototype.hideTip = function () {
	tip = document.getElementById("tooltip");
	tip.style.visibility="hidden"
	tip.innerHTML="";
	this.tooltip=0; 
}

Ekran.prototype.centerXY = function (w,h) {
	if (this.render=="html") {
		var myWidth = 0, myHeight = 0;
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		
		if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
	} 
	if (this.render=="xhtml") {
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	
	this.sizeX = myWidth;
	this.sizeY = myHeight;
	this.size = [myWidth,myHeight];
	this.scrollX = scrOfX;
	this.scrollY = scrOfY;
	this.scroll= [ scrOfX, scrOfY ];
	
	this.centerX = this.scrollX+this.sizeX/2-(w ? w/2:w);
	this.centerY = this.scrollY+this.sizeY/2-(h ? h/2:h);
	if (this.centerX<0) this.centerX=0;
	if (this.centerY<0) this.centerY=0;
	return [this.centerX,this.centerY]; 
};

Ekran.prototype.pokaz_komunikat = function (tresc, lista1, lista2, tytul) {
	body ='<div class="komunikat_header">%tytul%</div><br><img src="%icon%" ><div class="komunikat_tresc">%tresc%</div><bR>';
	if (!tytul) {
		tytul = "Uwaga !!!";
	} 
	icon = "../img/icon/box_info.png";	
	if (!lista1) {
		lista1 = new Array("ok");
		lista2 = new Array(";");	
		
	}
	
	this.centerXY(300,130);
	msg = document.getElementsByTagName("body")[0].appendChild(document.createElement("div"));
	msg.id = "komunikat";

	msg.style.width = "300px";
	msg.style.height = "130px";
	msg.style.left = this.centerX+"px";
	msg.style.top = this.centerY+"px";

	body = body.replace('%tytul%',tytul);
	body = body.replace('%tresc%',tresc);
	body = body.replace('%icon%',icon);
	msg.innerHTML=body;
	
	for(i=0; i < lista1.length; i++) {
		b = document.createElement("INPUT");
		b.type = "button";
		b.value = lista1[i];
		msg.appendChild(b);
		eventAdder(b,"onclick",lista2[i]+";MsgBox_close();");;
	}
	
	
}

//prompt czy usunac. pobiera funkcje ktora wywoalc jezeli tak
function czy_usunac(w) {
	tmp = new Array("OK","Anuluj");
	tmp1 = new Array("wczytaj('"+w+"')","pusta()");
	e.pokaz_komunikat("Czy napewno usunąć ?",tmp,tmp1);
}


