<!--

/*
	klasa javascript
	autor: Marcin £ukasiewicz, m-l.pl

	aktualizacja 2010-02-18
*/


var page = {
	
	XmousePosition : 0,
	YmousePosition : 0,
	newWin : false,
	
	LOADER_IMAGE : "images/loader.gif",

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	go2link : function(url, target)
	{
		window.location.href = url;
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	openWindow : function(url, width, height, scrollb)
	{
		if(isNaN(parseInt(width)) && isNaN(parseInt(height)))
		{
			width = 700;
			height = 500;
		}
	
		var scrb = (scrollb == 1)? "yes" : "no" ;
	
		var c = "toolbar=no,menubar=no,location=no,personalbar=no,status=no,statusbar=no,directories=no,resizable=no,";
		c += "scrollbars="+scrb+",width="+width+",height="+height+"";
		
		this.newWin = window.open(url, "newWin", c);
		
		this.newWin.focus();
	
		return this.newWin;
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	windowImage : function(url, w, h)
	{
		var w = openWindow("", w, h);
		var u = '<a href="javascript:window.close()"><img src="'+url+'" alt="" border="0"></a>';
		var t = document.title;
		
		if(t.indexOf("#") != -1)
			t = t.substr(0, t.indexOf("#"));
		
		var str = '<html><head><title>'+t+'</title></head><body style="margin:0px;" bgcolor="#ffffff">'+u+'</body></html>';
		
		w.document.write(str);
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
		
	zmClassName : function (obj, cName, wait)
	{
		if(wait)
			setTimeout(function(){obj.className = cName}, 50);
		else
			obj.className = cName;
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	addLoader : function(dvName, txt)
	{
		this.$(dvName).innerHTML = '<img src="'+this.LOADER_IMAGE+'" style="vertical-align:middle;" alt=""> '+(txt || 'zaczekaj...');
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	clearLoader : function(dvName, txt)
	{
		this.$(dvName).innerHTML = txt || '';
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	msg : function(str)
	{
		this.$("msgDV").innerHTML = str;
		setTimeout('page.$("msgDV").innerHTML="&nbsp;";', 3000);
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	preloadImg : function(imgObj, imgSrc)
	{
		if(document.images)
		{
			eval(imgObj+' = new Image()');
			eval(imgObj+'.src = "'+imgSrc+'"');
		}
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	chImgSrc : function(n, a)
	{
		document.images[n].src = eval(n+"_"+a+".src");
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	add2favorites : function(title, url)
	{
		if (window.sidebar)// Mozilla Firefox
			window.sidebar.addPanel(title, url,"");
		else if( window.external)//IE
			window.external.AddFavorite(url, title);
		else if(window.opera)// Opera
		{
		     var e = document.createElement('a');
	    	 e.setAttribute('href', url);
		     e.setAttribute('title', title);
	    	 e.setAttribute('rel', 'sidebar');
		     e.click();
		}
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	getScroll : function()
	{
		var xScroll, yScroll;
	
		if (self.pageXOffset) {
			xScroll = self.pageXOffset;
			yScroll = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			xScroll = document.documentElement.scrollLeft;
			yScroll = document.documentElement.scrollTop;
		} else if (document.body) {// all other Explorers
			xScroll = document.body.scrollLeft;
			yScroll = document.body.scrollTop;
		}
		return {left:xScroll, top:yScroll};
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	getPageSize : function()	// Core code from - quirksmode.org
	{
		var xScroll, yScroll;
		var windowWidth, windowHeight, pageWidth, pageHeight;
	
		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;
		}
	
		if (self.innerHeight) {	// all except Explorer
			windowWidth = 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
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
	
		return {pageWidth:pageWidth, pageHeight:pageHeight, windowWidth:windowWidth, windowHeight:windowHeight};
	},	
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	tooltip : function(e, txt, cssClassName)
	{
		var t = document.createElement("div");
		t.className = cssClassName || "tooltip" ;
		t.style.position = "absolute";
		t.innerHTML = txt;
	
		e.move = function()
		{
			t.style.left = page.XmousePosition + 10;
			t.style.top = page.YmousePosition;
		}
		e.move();
		
		document.body.appendChild(t);
		
		e.onmousemove = function()
		{
			e.move();
		}
		
		e.onmouseout = function()
		{
			document.body.removeChild(t);
		}
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	sendForm : function(fname, funct, param)
	{
		var req = mint.Request();
		req.retryNum = 1;
		req.timeout = 30 * 1000;
		var that = this;

    	req.OnSuccess = function()
		{
			if(funct)
			{
				param? that.exuteFunction(funct, [param, this.responseText]) : that.exuteFunction(funct, this.responseText) ;
			}
			else if(param)
			{
				if(typeof param == "string")
					page.$(param).innerHTML = this.responseText;
				else if(param.href)
					location.href = param.href;
			}
			else if(funct === false)
			{}
			else
				location.reload();
    	}
		
		req.OnError = function()
		{
			alert("BÅ‚Ä…d wysÅ‚ania formularza !");
		}
		
		req.OnTimeout = function()
		{
			alert("BÅ‚Ä…d - minÄ…Å‚ czas oczekiwania serwera !");
		}		
		
		if(document.forms[fname].onsubmit && document.forms[fname].onsubmit.length > 0)
		{
			if(eval(document.forms[fname].onsubmit).apply())
				req.SendForm(fname);
		}
		else
			req.SendForm(fname);
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	sendQuery : function(query, funct, param)
	{
		var req = mint.Request();
		req.retryNum = 1;
		req.timeout = 30 * 1000;
		req.evalScripts = true;
		var that = this;

    	req.OnSuccess = function()
		{
			if(funct)
			{
				param? that.exuteFunction(funct, [param, this.responseText]) : that.exuteFunction(funct, this.responseText) ;
			}
			else if(param)
			{
				if(typeof param == "string")
					page.$(param).innerHTML = this.responseText;
				else if(param.href)
					location.href = param.href;
			}
			else if(funct == undefined)
				location.reload();
    	}
		
		req.OnError = function(s)
		{
			if(s != -1)
				alert("BÅ‚Ä…d wysÅ‚ania zapytania !");
		}
		
		req.OnTimeout = function()
		{
			alert("BÅ‚Ä…d - minÄ…Å‚ czas oczekiwania serwera !");
		}

	    req.Send(query);
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	exuteFunction : function(funct, param)
	{
		var obj = null;
		
		if(typeof funct == 'function')
		{
			if(param != undefined)
				funct.apply(obj, typeof param == 'object'? param : [param]);
			else
				funct.apply(obj);
		}
		else
		{
			if(funct.indexOf(".") != -1)
			{
				obj = eval(funct.substr(0, funct.indexOf(".")));
				funct.substr(funct.indexOf(".")+1);
			}

			if(param != undefined)
				eval(funct).apply(obj, typeof param == 'object'? param : [param]);
			else
				eval(funct).apply(obj);
		}
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	//private function
	
	setMousePosition : function(e)	{
		page.XmousePosition = (document.all)? event.clientX + document.body.scrollLeft : e.pageX ;
		page.YmousePosition = (document.all)? event.clientY + document.body.scrollTop : e.pageY ;
	},	
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	$ : function(x)	{
		return (typeof x == "object")? x : document.getElementById(x);
	}
	
}

document.onmousemove = page.setMousePosition;

//-->