<!--

/*
	klasa javascript
	autor: Marcin ukasiewicz, m-l.pl

	aktualizacja 2010-09-27
*/


var page = {
	
	XmousePosition : 0,
	YmousePosition : 0,
	newWin : false,
	
	LOADER_IMAGE : "_img/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 = this.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}, wait===true? 50 : wait);
		else
			obj.className = cName;
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	addLoader : function(dvName, txt)
	{
		if(dvName)
			this.$d(dvName).innerHTML = this.getLoader(txt);
		else
			return this.getLoader(txt);
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	getLoader : function(txt)
	{
		return '<img src="'+this.LOADER_IMAGE+'" style="vertical-align:middle;" alt=""> '+(txt || 'zaczekaj...');
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	clearLoader : function(dvName, txt)
	{
		this.$d(dvName).innerHTML = txt || '';
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	msg : function(str)
	{
		if(this.$d("msgDV"))
		{
			this.$d("msgDV").innerHTML = str;
			setTimeout('page.$d("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 pageWidth = $(document).width();
		var pageHeight = $(document).height();
		var windowWidth = $(window).width();
		var windowHeight = $(window).height();		
		
		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 f = document.forms[fname];
		var that = this;
		
		if(f.onsubmit && f.onsubmit.length > 0)
		{
			var ret = eval(f.onsubmit).apply();
			
			if(!ret)
				return false;
		}

		$.ajax({
			type : "POST",
			url : f.action,
			data : $(f).serializeArray(),
			error : function()
			{
				that.msg("Błąd wysłania formularza.");
			},
			success: function(str)
			{
				if(funct)
				{
					param? that.exuteFunction(funct, [param, str]) : that.exuteFunction(funct, str) ;
				}
				else if(param)
				{
					if(typeof param == "string")
						page.$d(param).innerHTML = str;
					else if(param.href)
						location.href = param.href;
				}
				else if(funct === false)
				{}
				else
					location.reload();
			}
		});		
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	sendQuery : function(query, funct, param)
	{
		var that = this;
		
		$.ajax({
			type : "GET",
			url : query,
			error : function()
			{
				that.msg("Błąd wysłania zapytania.");
			},
			success: function(returnStr)
			{
				if(funct)
				{
					param? that.exuteFunction(funct, [param, returnStr]) : that.exuteFunction(funct, returnStr) ;
				}
				else if(param)
				{
					if(typeof param == "string")
						page.$d(param).innerHTML = returnStr;
					else if(param.href)
						location.href = param.href;
				}
				else if(funct == undefined)
					location.reload();
			}
		});	
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	exuteFunction : function(funct, fnParam)
	{
		var obj = null;
		
		if(typeof funct == 'function')
		{
			if(fnParam != undefined)
				funct.apply(obj, typeof fnParam == 'object'? fnParam : [fnParam]);
			else
				funct.apply(obj);
		}
		else
		{
			if(funct.indexOf(".") != -1)
			{
				obj = eval(funct.substr(0, funct.indexOf(".")));
				funct.substr(funct.indexOf(".")+1);
			}

			if(fnParam != undefined)
				eval(funct).apply(obj, typeof fnParam == 'object'? fnParam : [fnParam]);
		//	else
			//	eval(funct).apply(obj);
		}
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	setCookie : function(name, value, days)
	{
		if(days)
		{
			var d = new Date();
			d.setTime(d.getTime() + (days * 86400000));
			var expires = "; expires="+date.toGMTString();
		}
		else
			var expires = "";

		document.cookie = name + "=" + escape(value) + expires ;
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	getCookie : function(name)
	{
		if(document.cookie.length > 0)
		{
			var start = document.cookie.indexOf(name+"=");
		
			if(start != -1)
			{
				start = start+name.length+1;
				var end = document.cookie.indexOf(";", start);
				
				if(end == -1)
					end = document.cookie.length;

				return unescape(document.cookie.substring(start, end));
			}
		}
		return "";
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	delCookie : function(name)
	{
		this.setCookie(name, "", -1);
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	chtextcode : function(str, a)
	{
	    var rc="", ch, i, regxp;
		
		var rpl = new Array(
	
			["%C4%99", "ę"],
			["%C3%B3", "ó"],
			["%C4%85", "ą"],
			["%C5%9B", "ś"],
			["%C5%82", "ł"],
			["%C5%BC", "ż"],
			["%C5%BA", "ź"],
			["%C4%87", "ć"],
			["%C5%84", "ń"],
			["%C4%98", "Ę"],
			["%C3%93", "Ó"],
			["%C4%84", "Ą"],
			["%C5%9A", "Ś"],
			["%C5%81", "Ł"],
			["%C5%BB", "Ż"],
			["%C5%B9", "Ź"],
			["%C4%86", "Ć"],
			["%C5%83", "Ń"]
		);
		
		if(a == undefined)
		{
			for(i=0; i<rpl.length; i++)
			{
				regxp = eval("/" + rpl[i][0] + "/gi");
			
				while(str.search(regxp) != -1)
					str = str.replace(regxp, rpl[i][1]);
			}
		
		    for (i=0;i<str.length;i++)
	    	{
	        	ch=str.charAt(i);
	
				switch(ch)
				{
				    case '+': ch=" ";
					break;			
				}
	    	    rc=rc+ch;
		    }
			
			return  rc;
		}
		else
		{
			for(i=0; i<rpl.length; i++)
			{
				regxp = eval("/" + rpl[i][1] + "/gi");
			
				while(str.search(regxp) != -1)
					str = str.replace(regxp, rpl[i][0]);
			}
			return  str;
		}
	},	

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	//private function
	
	setMousePosition : function(event)	{
		page.XmousePosition = event.pageX;
		page.YmousePosition = event.pageY;
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	$d : function(x)	{
		return (typeof x == "object")? x : document.getElementById(x);
	}
	
}

$(document).ready(function(){
	$(this).mousemove(page.setMousePosition);
})

//-->
