/* 
	kello light js library
	update: 07.05.2007
*/
	function findPosX(obj){
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	}
	function findPosY(obj){
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	}

	function pokazUkryj (co,takczynie) {
		if (takczynie == 1) {
			$(co).style.visibility = 'visible';
			$(co).style.display = 'block';
		}
		else {
			$(co).style.visibility = 'hidden';
			$(co).style.display = 'none';
		}
	}
	
	function ustawDiv (edest,esrc,xx,yy) {
		var obj = document.getElementById(edest);
		var obj2 = document.getElementById(esrc);
		var posnX = findPosX(obj2);
		var posnY = findPosY(obj2);
		obj.style.left = (posnX+xx)+'px';
		obj.style.top = (posnY+yy)+'px';
	}

	// zwraca id tagow TAG o atrybucie rel=REL
	// return el1|el2|el3
	function getTagsWith (TAG, REL) {
		var elementy = '';
	   for (i=0; (ab=document.getElementsByTagName(TAG)[i]); i++) {
	   	if (rel=ab.getAttribute('rel')) {
				if (rel.indexOf(REL) != -1) elementy += ab.getAttribute('id')+'|';				
	   	}
	   }
		return elementy.substr(0,elementy.length-1);
	}

	// zwraca referencje do TAG o rel=REL
	function getTagsByRef (TAG, REL) {
		var elementy = Array ();
		var j = 0;
	   for (i=0; (ab=document.getElementsByTagName(TAG)[i]); i++) {
	   	if (rel=ab.getAttribute('rel')) {
				if (rel.indexOf(REL) != -1) elementy[j++] = ab;
	   	}
	   }
		return elementy;		
	}

	function getTagsById (TAG, REL) {
		var elementy = Array ();
		var j = 0;
	   for (i=0; (ab=document.getElementsByTagName(TAG)[i]); i++) {
	   	if (rel=ab.getAttribute('id')) {
				if (rel.indexOf(REL) != -1) elementy[j++] = ab;
	   	}
	   }
		return elementy;		
	}

	// rozdzielczosc ekranu (prawie)
	function winSizeW () {
		winW = document.body.offsetWidth;
		return winW;
	}
	
	function winSizeH () {
  		winH = document.body.offsetHeight;
		return winH;
	}
	
// ciastka
	function createCookie (name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}	

	function readCookie (name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}

	function eraseCookie (name) {
		createCookie(name,"",-1);
	}	

	function ustawStyl (obiekt, styl, wartosc) {
		$(obiekt).style.styl = wartosc;
	}

	function showHint (obj,hint) {
		var gdzie = document.getElementById(obj);		
		if ((parseInt(document.getElementById(obj).style.left)+150) > winSizeW()) {
			ustawDiv ('hints',obj,-150,12);
		} else {
			ustawDiv ('hints',obj,12,12);		
		}
		$('hints').innerHTML = hint;
		$('hints').style.zIndex = '900';
		pokazUkryj ('hints',1);
	}

	// przypisuje wartosc do pola input poprzez podanie id
	function assignValueById (pole, wartosc) {
		$(pole).value=wartosc;
	}
	
	function $(id) {
		return document.getElementById(id);
	}
	
	// centruje ale nie uwzglednia przewiniecia okna w dol	
	function wycentruj (obj,ww,hh) {
		winW = document.body.offsetWidth;
  		winH = document.body.offsetHeight;
		with (document.getElementById(obj).style) {
			left = Math.round(winW/2)-Math.round(ww/2)+'px';
			top = Math.round(winH/2)-Math.round(hh/2)+'px';
			zIndex = '999';
		}
	}

	// centruje i uwzglednia przewiniecie okna w dol
	function wycentrujPrzesun (obj, ww, hh) {
		var przesuniecie = document.documentElement.scrollTop | document.body.scrollTop;
		oszer =  ww;
		owys = hh;
		if (document.all) bwys = document.body.clientHeight;
		else bwys = document.documentElement.clientHeight;
		wspY = Math.round(bwys/2) - Math.round(owys/2);
		wspX = Math.round(document.body.clientWidth/2) - Math.round(oszer/2);
		with (document.getElementById(obj).style) {
			left = wspX + 'px';
			top = wspY + przesuniecie + 'px';
			zIndex = '999';
		} 	
	}

	// rozszerza obiekt na caly ekran
	function pelnyEkran (obj) {
		if (document.all) bwys = document.body.clientHeight;
		else bwys = document.documentElement.clientHeight;
		pagesize = getPageSizeWithScroll();
		bwys = pagesize[1];
		bszer = document.body.clientWidth;		
		with (document.getElementById(obj).style) {
			width = bszer + 'px';
			height = bwys + 'px';
			top = '0px';
			left = '0px';
			zIndex = '998';
		}
		pokazUkryj (obj, 1);
	}

	function getPageSizeWithScroll () {
		if (window.innerHeight && window.scrollMaxY) {// Firefox
			yWithScroll = window.innerHeight + window.scrollMaxY;
			xWithScroll = window.innerWidth + window.scrollMaxX;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			yWithScroll = document.body.scrollHeight;
			xWithScroll = document.body.scrollWidth;
		} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
			yWithScroll = document.body.offsetHeight;
			xWithScroll = document.body.offsetWidth;
	  	}
		arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
		//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
		return arrayPageSizeWithScroll;
	}
