
				
function truebody() {
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function moveWindowTo(name) {
	var t = window.location.href; //find url parameter
	if(t.indexOf("#") == -1 || t.indexOf("#"+name) > -1){
		window.location.hash=name; 
	}
}

// Funkcja powstrzymuje wysyłanie formularza po naciśnięciu entera w wybranych polach
function stopEnter(event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) return false;
	else return true;
}

function login_alert(header) {
	var txt = '<a href=\"logowanie\" target=\"_self\" class=\"infoBoxLink\">Zaloguj się</a> na swoje konto, aby móc wykonać tą operację. Jeśli nie masz konta, kliknij na poniższy link:<br><br><a href=\"dodaj_konto\" target=\"_self\" class=\"infoBoxLink\"><b>Formularz zakładania konta</b></a><br>';
	alert2(header,txt);
	return false;
};

function $(v,o) {
	return((typeof(o)=='object'?o:document).getElementById(v));
}

function $S(o) {
	o=$(o);
	if(o) return(o.style);
}

function open_win(wwwlink,w,h) {
	window.open(wwwlink,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width="+w+", height="+h);
	return false;
}

function onoff(div,action) {
	var temp = $(div);
	if(action === 'on' && temp !== null ) temp.style.display = 'block';
	else if(action === 'off' && temp !== null ) temp.style.display = 'none';
	else if(action === undefined && temp !== null ) temp.style.display = ( temp.style.display === 'block' ) ? 'none' : 'block';
}



function onoffSmoothStep(o,d,m) {
	onoffSmoothOpac(o,d);
	$(d).style.height = ((o * m) / 100) + 'px';
}
function onoffSmoothOpac(op,id) {
	var o = $(id).style;
	o.opacity = (op / 100);
	o.MozOpacity = (op / 100);
	o.KhtmlOpacity = (op / 100);
	o.filter = 'alpha(opacity=' + op + ')';
	if (op == 0) {
		o.display = 'none';
	}
}
function onoffSmooth(div,maxheight,action) {
	
	var temp = $(div);
	temp.style.overflow = 'hidden';
	
	function expand(t,d) {
		t.style.height = 0 + 'px';
		onoffSmoothOpac(1,d);
		t.style.display = 'block';
		// powiększam diva do max rozmiaru		
		var timer = 0;
		var i;
		for(var i = 1; i <= 100; i++) { // jest od 1 aby onoffSmoothOpac nie ustawił display=none
			setTimeout("onoffSmoothStep(" + i + ",'" + d + "'," + maxheight + ")",(timer++ * 5));						
		}
	}
	
	function collapse(t,d) {
		onoffSmoothOpac(100,d);		
		// pomniejszam diva
		var timer = 0;
		var i;
		for(i = 100; i >= 0; i--) {
			setTimeout("onoffSmoothStep(" + i + ",'" + d + "'," + maxheight + ")",(timer++ * 5));			
		}
	}
	
	if(action === 'on' && temp !== null ) {		
		expand(temp,div);
	}
	else if(action === 'off' && temp !== null ) {		
		collapse(temp,div);
	}
	else if(action === undefined && temp !== null ) {
		if (temp.style.display === 'block') {
			collapse(temp,div);
		} else {
			expand(temp,div);
		}		
	}
}



function isEmail(who) {
	var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
	return (email.test(who));
}

function winSize() {
	var w = 0;
	var h = 0;
	if(!window.innerWidth) //IE
	{
		if(!(document.documentElement.clientWidth == 0)) { w = document.documentElement.clientWidth; h = document.documentElement.clientHeight; } //strict mode
		else { w = document.body.clientWidth; h = document.body.clientHeight; } //quirks mode
	}
	else { w = window.innerWidth; h = window.innerHeight; } //w3c
	return {width:w,height:h};
}


function trim(str) {
	var whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u200B\u2028\u2029\u3000';
	for (var i = 0; i < str.length; i++) {
		if (whitespace.indexOf(str.charAt(i)) === -1) {
			str = str.substring(i);
			break;
		}
	}
	for (i = str.length - 1; i >= 0; i--) {
		if (whitespace.indexOf(str.charAt(i)) === -1) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}

function potwierdzenie(t) {
	if (typeof(window.opera) != 'undefined') {return true;}
	var is_confirmed = confirm(t);
	return is_confirmed;
}

var alert_js; // zmienna globalna
function alert2(header,txt) {
	alert_js.wlot(header,txt);
}
function alert3(txt) {
	alert_js.wlot('Uwaga:',txt);
}
function alert4(txt) {
	alert_js.wlot('Informacja:',txt);
}

// klasa poruszająca alertem2
function alert2_obj(idDiv,idText,idHeader) {
	this.obiekt = $(idDiv);
	this.tekstarea = $(idText);
	this.headerarea = $(idHeader);
	this.docelY = 70;
	var ie = document.all && !window.opera;
	var docwidth = (ie) ? truebody().clientWidth : window.innerWidth; // szerokosc okna przegladarki
	this.obiekt.style.left = docwidth/2-215+'px';
	this.pozY = 0;
	this.ru;
	var self = this;
	var top;
	this.ruch = function() {
		top = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		this.pozY += (top + this.docelY - this.obiekt.offsetTop)/5;
		this.obiekt.style.top = this.pozY+'px';
	}
	this.wlot = function(header,tresc) {
		this.stop();
		this.headerarea.innerHTML = header;
		this.tekstarea.innerHTML = tresc;
		this.obiekt.style.display = 'block';
		this.ru = setInterval(function(){ self.ruch() }, 10);
	}
	this.stop = function() {
		clearInterval(this.ru);
		this.obiekt.style.display = 'none';
		this.obiekt.style.top = 0+'px';
		this.pozY = 0;
	}
	return this;
}




// Funkcje testujace zawartość inputa
function poleRzeczywiste(inputObj){
	var i,j,ok,przecinek;
	var txt = inputObj.value;
	var tabSigns = new Array('0','1','2','3','4','5','6','7','8','9',',','.');
	newTxt = new String('');
	reg = new RegExp("^[0-9]{1,}[,]{0,1}[0-9]*$");

	if(!reg.test(txt)) {
		przecinek=0;
		for(i=0;i<txt.length;i++){
			for(j=0;j<tabSigns.length;j++) if(tabSigns[j] == txt.charAt(i)) ok=1;

			// moze byc tylko jeden przecinek, jesli znajde drugi to zmieniam flage na zero
			if(txt.charAt(i)==',' || txt.charAt(i)=='.') {
				przecinek++;
				if(przecinek > 1) ok=0;
			}

			if(ok){
				if(txt.charAt(i)=='.') newTxt += ','; // zamieniam kropke na przecinek
				else newTxt += txt.charAt(i);
			}

			flaga=0;
		}

		if(txt.charAt(0)==',' || txt.charAt(0)=='.') newTxt = '0'+newTxt;
		inputObj.value = newTxt;
	}
}

function poleCalosci(inputObj) {
	var i,j;
	var txt = inputObj.value;
	var tabSigns = new Array('0','1','2','3','4','5','6','7','8','9');
	newTxt = new String('');
	reg = new RegExp("^[0-9]*$");

	if(!reg.test(txt)){
		for(i=0; i < txt.length; i++)
			for(j=0; j < tabSigns.length; j++)
				if(tabSigns[j]==txt.charAt(i)) newTxt = newTxt + txt.charAt(i);

		inputObj.value = newTxt;
	}
}

function poleDaty(inputObj){
	var i,j,ok,myslnik;
	var txt = inputObj.value;
	var tabSigns = new Array('0','1','2','3','4','5','6','7','8','9','-');
	newTxt = new String('');
	reg = new RegExp("^[0-9]*-?[0-9]*-?[0-9]*$");
	if(!reg.test(txt)) {
		myslnik=0;
		for(i=0;i<txt.length;i++) {
			for(j=0; j < tabSigns.length; j++) if(tabSigns[j]==txt.charAt(i)) ok=1;
			if('-' == txt.charAt(i)){
				myslnik++;
				if(myslnik>2) ok=0;
			}

			if(ok) newTxt += txt.charAt(i);
			ok=0;
		}
		inputObj.value = newTxt;
	}
}

function poleTelefon(inputObj){
	var i,j,ok;
	var txt = inputObj.value;
	var tabSigns = new Array('0','1','2','3','4','5','6','7','8','9','-','(',')',' ');
	newTxt = new String('');
	reg = new RegExp("^[-,(,), ,0,1,2,3,4,5,6,7,8,9]*$");
	if(!reg.test(txt)) {
		myslnik=0;
		for(i=0; i < txt.length; i++) {
			for(j=0; j < tabSigns.length; j++) if(tabSigns[j]==txt.charAt(i)) ok=1;
			if(ok) newTxt += txt.charAt(i);
			ok=0;
		}
		inputObj.value = newTxt;
	}
}


function bind(fn) { 
	var args = [];
	for (var n = 1; n < arguments.length; n++) args.push(arguments[n]);
	return function () { return fn.apply(this, args); };
}


// Klasa wymaga podania NAME taga IMG w ktorym będą zmieniane zdjęcia
function SlideShow() {
	this.imageArray = new Array();
	this.shell;
	var loopRotate = 0;
	var endalpha = 95;
	var alpha = 0;
	var speed = 50;
	var timer;
	var timer2;
	
	this.addImage = function(pic,w,h,trail) {
		this.imageArray[this.imageArray.length] = new SlideShowImage(pic,w,h,trail);
	}
	
	this.rotateImage = function() {
		var self = this;
		this.shell.width = this.imageArray[loopRotate].imageItem.width;
		this.shell.height = this.imageArray[loopRotate].imageItem.height;
		this.shell.style.width = this.imageArray[loopRotate].imageItem.width + 'px';
		this.shell.style.height = this.imageArray[loopRotate].imageItem.height + 'px';
		this.shell.style.opacity = 0;
		this.shell.style.filter = 'alpha(opacity=0)';
		
		function tt(s,l) {
			s.pause(); 
			tooltip.show(s.imageArray[l].imageItem.trail); 
		}
		
		if (this.imageArray[loopRotate].imageItem.trail != null) {
			this.shell.onmouseover = bind(tt,self,loopRotate);
			this.shell.onmouseout = function() { self.unpause(); tooltip.hide(); }
			this.shell.onclick = function() { tooltip.hide(); }
		} else {
			this.shell.onmouseover = function() { self.pause(); }
			this.shell.onmouseout = function() { self.unpause(); }
		}
		this.shell.src = this.imageArray[loopRotate].imageItem.src;
		
		loopRotate = (loopRotate === (this.imageArray.length-1)) ? 0 : (loopRotate+1); 
	}
	
	this.start = function(imgid) {
		this.shell = $(imgid);
		this.rotateImage();
		this.show();
	}
	
	this.pause = function() {
		clearInterval(timer);
		clearTimeout(timer2);
		this.shell.style.opacity = 1;
		this.shell.style.filter = 'alpha(opacity=100)';
	}
	
	this.unpause = function() {
		var self = this;
		timer2 = setTimeout(function() { self.hide(); }, 2000);
	}
	
	this.fade = function(d){
		var a = alpha;
		if((a != endalpha && d == 1) || (a != 0 && d == -1)){
			var i = 10;
			if(endalpha - a < 10 && d == 1){ i = endalpha - a; }
			else if(alpha < 10 && d == -1){ i = a; }
			alpha = a + (i * d);
			this.shell.style.opacity = alpha * .01;
			this.shell.style.filter = 'alpha(opacity=' + alpha + ')';
		} else {
			clearInterval(timer);
			// Jeśli wygaszał to na koncu zmienia na kolejne
			if (d == -1) {
				this.rotateImage();
				this.show();
			}
			// Jeśli pojawiał to na koncu uruchamia po 3 sekundach od nowa ukrywa
			if (d == 1) {
				var self = this;
				timer2 = setTimeout(function() { self.hide(); }, 3000);
			}
		}
	}
	
	this.show = function() {
		var self = this;
		clearInterval(this.timer);
		timer = setInterval(function(){self.fade(1)},speed);
	}
	this.hide = function() {
		var self = this;
		clearInterval(this.timer);
		timer = setInterval(function(){self.fade(-1)},speed);
	}
}

function SlideShowImage(pic,w,h,trail) {
	this.imageItem = new Image(); 
	this.imageItem.src = pic; 
	this.imageItem.width = w; 
	this.imageItem.height = h;
	this.imageItem.trail = trail;
}



