function checkAll(ctrl) {
	form = ctrl.form
	for(i=0;i<form.elements.length;i++) {
		el = form.elements[i];
		if(el.type=="checkbox") el.checked=ctrl.checked;
	}
}

// ---------------------------------
  	function pos_o(elem) {
		
			var p,elem;
		
			p = {x: 0.0, y: 0.0};

			while(elem && elem != document.body) {
			
				p.x+=elem.offsetLeft;
			
				p.y+=elem.offsetTop;

			
				elem=elem.offsetParent;
		
			}

		
			return p;
	
	}

	function pos(elem) {
		var p, elem;
		p = {x: 0.0, y: 0.0};
		elem = document.getElementById(elem);
		while(elem && elem != document.body) {
			p.x+=elem.offsetLeft;
			p.y+=elem.offsetTop;

			elem=elem.offsetParent;
		}
		return p;
	}
// ---------------------------------



// funkcje obslugi edytora 
	function command(tbTresc,cmd) {
		if(tbTresc.advEditMode) {
			alert('Wyłącz podgląd źródła');
			return;
		}
		tbTresc.focus()
		document.selection.createRange()
		if(arguments[2]) 
			document.execCommand(cmd,true,arguments[2]) 
		else 
			document.execCommand(cmd) 
		tbTresc.focus()
	}

	function actCut(tbTresc) { command(tbTresc,'Cut') }
	function actCopy(tbTresc) { command(tbTresc,'Copy') }
	function actPaste(tbTresc) { command(tbTresc,'Paste') }

	function actUndo(tbTresc) { command(tbTresc,'Undo') }

	function actBold(tbTresc) { command(tbTresc,'Bold') }
	function actItalic(tbTresc) { command(tbTresc,'Italic') }
	function actUnderline(tbTresc) { command(tbTresc,'Underline') }
	
	function actAlignLeft(tbTresc) { command(tbTresc,'JustifyLeft') }
	function actAlignCenter(tbTresc) { command(tbTresc,'JustifyCenter') }
	function actAlignRight(tbTresc) { command(tbTresc,'JustifyRight') }

	function actOrderedList(tbTresc) { command(tbTresc,'InsertOrderedList') }
	function actUnorderedList(tbTresc) { command(tbTresc,'InsertUnorderedList') }

	function actUnindent(tbTresc) { command(tbTresc,'Outdent') }
	function actIndent(tbTresc) { command(tbTresc,'Indent') }
	function actLink(tbTresc) { command(tbTresc,'Undrline') }

	function actChangeFont(tbTresc,font) { command(tbTresc,'fontname',font) }
	function actChangeFontSize(tbTresc,size) { command(tbTresc,'fontsize',size) }
	function actChangeFontColor(tbTresc,color) { command(tbTresc,'forecolor',color) }
	function actChangeBackColor(tbTresc,color) { command(tbTresc,'backcolor',color) }

	function actCreateLink(tbTresc) { command(tbTresc,'CreateLink') }

	function actChangeMode(tbTresc) {
		tbTresc.advEditMode = ! tbTresc.advEditMode;
		
		if(tbTresc.advEditMode) {
			tbTresc.innerText = tbTresc.innerHTML;
		} else {
			tbTresc.innerHTML = tbTresc.innerText;
		}
		
	}


var toScroll=0;
var toScrollInterval = false;

function doScrollDown() 
{
	if (toScroll>0) 
	{
		toScroll-=1;
		document.body.scrollTop+=1;
		}
}

function scrollDownBy(toScrollDown) 
{
	toScroll += toScrollDown;
	if(!toScrollInterval) toScrollInterval = setInterval("doScrollDown()",10);
}


// funkcje Newslettera na zapleczu

function init() {
		j=0;
//		for(i=0;i<kategorie.length;i++) {
//			kategorie_do_wybrania[j++] = kategorie[i];
//		}
		chooseForSelector();
		fillSelector();
		fillWybrane();
	}
	function fillSelector() {
		var selector = document.getElementById("do_wybrania");
		while(selector.length>1) selector.removeChild(selector[1]);
		for(i=0;i<kategorie_do_wybrania.length;i++) {
				try {
					el = selector.firstChild.cloneNode(true);
					el.text  = nazwa[kategorie_do_wybrania[i]].replace(/&gt;/,">");
					el.value = kategorie_do_wybrania[i];
					selector.appendChild(el);
				} catch(e) {}
		}
	}
	function fillWybrane() {
		var wybr = document.getElementById("wybrane");
		wybr.style.visible = 'false';
		while(wybr.childNodes.length>1) wybr.removeChild(wybr.childNodes[1]);
		for(i=0;i<wybrane.length;i++) {
					el = wybr.firstChild.cloneNode(true);
					el.childNodes[2].innerHTML  = nazwa[wybrane[i]].replace(/&gt;/,">");
					el.firstChild.value = wybrane[i];
					el.style.display='block'
					wybr.appendChild(el);
		}
		wybr.style.visible = 'true';
	}


	function chooseForSelector() {
		var bad;
		kategorie_do_wybrania = new Array();
		j=0;
		for(i=0;i<kategorie.length;i++) {
			bad = false;
			for(k=0;k<wybrane.length;k++) {
				if(wybrane[k] == kategorie[i]) { bad = true; break; }
				if(podrzedne[wybrane[k]]) for(q=0;q<podrzedne[wybrane[k]].length;q++) {
					if(podrzedne[wybrane[k]][q] == kategorie[i]) {bad = true; break; }
				}
			}
			if(!bad) kategorie_do_wybrania[j++] = kategorie[i];
		}

	}
	function dodaj(id) {
		wybrane[wybrane.length] = id;

		var bad;
		var stare = wybrane;

		if(podrzedne[id]) {
			wybrane = new Array();

			var i,j = 0;
			for(i=0;i<stare.length;i++) {
				bad = false;
				for(k=0;k<podrzedne[id].length;k++) {
					if(podrzedne[id][k] == stare[i]) {bad = true; break;}
				}
				if(!bad) wybrane[j++] = stare[i];
			}
		}

		chooseForSelector();
		fillSelector();
		fillWybrane();
	}
	function usun(id) {
		var stare = wybrane;
		wybrane = new Array();
		var i,j = 0;
		for(i=0;i<stare.length;i++) {
			if(stare[i]!=id) wybrane[j++] = stare[i];
		}
		chooseForSelector();
		fillSelector();
	}