//funkcja pobierania 
function asyncGetWartosc(id, unique, panel, succesHandler) 
{
	
	//pobierz położenie panelu nadżędnego aby wyśrodkować loader
	if (panel != null) 
	{
		var region = YAHOO.util.Dom.getRegion(panel.body);
		var x = region.x + parseInt(region.width / 2) - 120;
		var y = region.y + parseInt(region.height / 2) - 50;
	}
	else 
	{
		var region = YAHOO.util.Dom.getRegion(document.body);
		var x = region.x + parseInt(region.width / 2) - 120;
		var y = region.y + parseInt(region.height / 2) - 50;
	}

	//stwórz i wyświetl loader
	this.Loader = new YAHOO.widget.Panel("wait", {width : "240px", close : false, modal : true, draggable : true, xy : [ x, y ] });
	this.Loader.setBody('<img src="' + CMS_AdminHref + 'public/scripts/js/YUI/images/rel_interstitial_loading.gif" />');
	this.Loader.setHeader('Pobieram dane. Proszę czekać...');
	this.Loader.render(document.body);
	this.Loader.show();

	// uchwyt na dane odsyłane przez serwer
	var Handler = 
	{
		wsk : this,
		unique : unique,
		id : id,
		successHandler : succesHandler,
		success : function(response)
		{
			this.wsk.Loader.hide();
			if (response.responseText.substring(0, 3) != 'err') 
			{
				var param;
				if (response.responseText.substring(3).length != 0) 
				{
					param = unserialize(base64_decode(response.responseText.substring(3)));
					dekodujRekurencyjnie(param);
				} 
				else
					param = '';

				//odpal funkcę która upora się z obsługą
				succesHandler ( param, { unique:unique, posID: id } );

			} 
			else 
			{
				YUIerr(response.responseText.substring(4));
				return false;
			}
		},
		failure : function(response) 
		{
			this.wsk.Loader.hide();
			YUIerr(response.responseText);
			return false;
		}
	};

	var cObj = YAHOO.util.Connect.asyncRequest('POST', CMS_AdminHref + 'index/async', Handler, "fun=getWartosc&posID=" + id + "&unique=" + unique);
}

//funkcja asynchronicznego ustawiania danych
function asyncSetWartosc(id, unique, value, panel, succesHandler) 
{
	//pobierz położenie panelu nadżędnego aby wyśrodkować loader
	var region = YAHOO.util.Dom.getRegion(panel.body);
	var x = region.x + parseInt(region.width / 2) - 120;
	var y = region.y + parseInt(region.height / 2) - 50;

	// stwórz i wyświetl loader
	this.Loader = new YAHOO.widget.Panel("wait", {
		width : "240px",
		close : false,
		modal : true,
		draggable : true,
		xy : [ x, y ]
	});
	this.Loader
			.setBody('<img src="' + CMS_AdminHref + 'public/scripts/js/YUI/images/rel_interstitial_loading.gif" />');
	this.Loader.setHeader('Zmieniam dane. Proszę czekać...');
	this.Loader.render(document.body);
	this.Loader.show();

	// uchwyt na dane odsyłane przez serwer
	var Handler = {
		wsk : this,
		unique : unique,
		successHandler : succesHandler,
		success : function(response) {

			this.wsk.Loader.hide();
			if (response.responseText.substring(0, 3) != 'err') {
				//odpal funkcję która upora się z obsługą   
		succesHandler();

	} else {
		YUIerr(response.responseText.substring(4));
		return false;
	}
},
failure : function(response) {
	this.wsk.Loader.hide();
	YUIerr(response.responseText);
	return false;
}
	};

	var cObj = YAHOO.util.Connect.asyncRequest('POST',CMS_AdminHref + 'index/async', Handler, "fun=setWartosc&posID="
					+ id + "&unique=" + unique + '&value=' + value);
}

//funkcja asynchronicznego ustawiania wartości tabelaryczbej
function asyncSetArrayWartosc(id, unique, value, panel, succesHandler, klucz)
{
	//pobierz położenie panelu nadżędnego aby wyśrodkować loader
	var region = YAHOO.util.Dom.getRegion(panel.body);
	var x = region.x + parseInt(region.width / 2) - 120;
	var y = region.y + parseInt(region.height / 2) - 50;

	// stwórz i wyświetl loader
	this.Loader = new YAHOO.widget.Panel("wait", { width : "240px", close : false, modal : true, draggable : true, xy : [ x, y ] });
	this.Loader.setBody('<img src="' + CMS_AdminHref + 'public/scripts/js/YUI/images/rel_interstitial_loading.gif" />');
	this.Loader.setHeader('Zmieniam dane. Proszę czekać...');
	this.Loader.render(document.body);
	this.Loader.show();

	// uchwyt na dane odsyłane przez serwer
	var Handler = 
	{
		wsk : this,
		unique : unique,
		id : id,
		successHandler : succesHandler,
		success : function(response) 
		{

			this.wsk.Loader.hide();
			if (response.responseText.substring(0, 3) != 'err') 
			{
				var dane;
				if (response.responseText.substring(3).length != 0) 
				{
					dane = unserialize(base64_decode(response.responseText.substring(3)));
					dekodujRekurencyjnie(dane);
				} 
				else
					dane = '';
				
				//odpal funkcję która upora się z obsługą   
				succesHandler(id, unique, dane);

			} 
			else 
			{
				YUIerr(response.responseText.substring(4));
				return false;
			}
		},
		failure : function(response) 
		{
			this.wsk.Loader.hide();
			YUIerr(response.responseText);
			return false;
		}
	};

	klucz != -1 ? klcz = '&klucz=' + klucz : klcz = ''; 
	var cObj = YAHOO.util.Connect.asyncRequest('POST',CMS_AdminHref + 'index/async', Handler, 
			"fun=setArrayWartosc&posID=" + id + "&unique=" + unique + '&value=' +  base64_encode(serialize(value)) + klcz);
}

function asyncDelArrayWartosc(id, unique, panel, succesHandler, klucze)
{
	//pobierz położenie panelu nadżędnego aby wyśrodkować loader
	var region = YAHOO.util.Dom.getRegion(panel.body);
	var x = region.x + parseInt(region.width / 2) - 120;
	var y = region.y + parseInt(region.height / 2) - 50;

	// stwórz i wyświetl loader
	this.Loader = new YAHOO.widget.Panel("wait", { width : "240px", close : false, modal : true, draggable : true, xy : [ x, y ] });
	this.Loader.setBody('<img src="' + CMS_AdminHref + 'public/scripts/js/YUI/images/rel_interstitial_loading.gif" />');
	this.Loader.setHeader('Usuwam dane. Proszę czekać...');
	this.Loader.render(document.body);
	this.Loader.show();

	// uchwyt na dane odsyłane przez serwer
	var Handler = 
	{
		wsk : this,
		unique : unique,
		id : id,
		successHandler : succesHandler,
		success : function(response) 
		{

			this.wsk.Loader.hide();
			if (response.responseText.substring(0, 3) != 'err') 
			{
				var klucze = explode(';',response.responseText.substring(3))
				succesHandler(id, unique, klucze);
			} 
			else 
			{
				YUIerr(response.responseText.substring(4));
				return false;
			}
		},
		failure : function(response) 
		{
			this.wsk.Loader.hide();
			YUIerr(response.responseText);
			return false;
		}
	};

	var cObj = YAHOO.util.Connect.asyncRequest('POST',CMS_AdminHref + 'index/async', Handler, "fun=delArrayWartosc&posID=" + id + "&unique=" + unique + '&klucze=' + klucze);
}
 






function add_inerHTML(parent, dana)
{
	var newRow = parent.insertRow(parent.rows.length);
	var newCell = newRow.insertCell(0);
	newCell.innerHTML = '<table style="margin:0px; padding:0px; text-align:left;" border="0"  cellspacing="0" cellpadding="0" ><tbody>' + dana + '</table></tbody>';
}










function YUImoduly(classParam, panel) 
{
	//blokada wielokrotnego renderowania zakładki
	if (document.getElementById(classParam.unique) != null)
		return;

	var tab, unique;

	unique = classParam.unique;

	if (classParam.page != undefined && classParam.page != '')
		tab = document.getElementById('panelTab' + classParam.page);

	var region = YAHOO.util.Dom.getRegion(tab.parentNode);
	var polax = parseInt((region.width - 32) / 2);

	tab.border = "0";
	tab.style.width = region.width + 'px';
	tab.style.height = classParam.h + 'px';

	var innerHTML =

	'<tr><td style="height:3px;" colspan="4"><div id="' + classParam.unique
			+ '" style="display:none;"></div></td></tr>' +

			'<tr>' + '<td style="width:16px;">' + '<td style="width:' + polax
			+ 'px;">' + 'Wybrane moduły' + '</td>' + '<td style="width:16px;">'
			+ '</td>' + '<td style="width:' + polax
			+ 'px; vertical-align:top">' + 'Dostępne moduły' + '</td>'
			+ '</tr>' +

			'<tr><td style="height:3px;" colspan="4"></td></tr>' +

			'<tr>' + '<td style="width:16px; vertical-align:top;">'
			+ '<div id="gora' + unique + '"  ></div>' + '<div id="dol' + unique
			+ '"  ></div>' + '<td style="width:' + polax
			+ 'px; vertical-align:top">' + '<select id="wybrane' + unique
			+ '" style="width:' + (polax - 25) + 'px; height:' + classParam.h
			+ 'px;" multiple="multiple">' +

			'</select>' + '</td>' + '<td style="width:16px;">'
			+ '<div id="lewo' + unique + '" ></div>' + '<div id="prawo'
			+ unique + '"  ></div>' + '</td>' + '<td style="width:' + polax
			+ 'px; vertical-align:top">' + '<select id="dostepne' + unique
			+ '" style="width:' + (polax - 25) + 'px; height:' + classParam.h
			+ 'px;" multiple="multiple">';

	for ( var i = 0; i < classParam.available.length; i++)
		innerHTML += '<option>' + classParam.available[i] + '</option>';

	innerHTML += '</select>' + '</td>' + '</tr>';
	tab.innerHTML += innerHTML;

	// obsługa klikniecia przycisku góra
	function goraButtonClick(p_oEvent) {
		var sel = document.getElementById('wybrane' + unique);

		var ile = 0;
		for ( var i = 0; i < sel.length; i++)
			if (sel.options[i].selected == true)
				ile++;

		if (ile != 1) {
			alert('Zaznacz jedną pozycję');
			return;
		}

		var selectOptions = sel.getElementsByTagName('option');
		for ( var i = 1; i < selectOptions.length; i++) {
			var opt = selectOptions[i];
			if (opt.selected) {
				sel.removeChild(opt);
				sel.insertBefore(opt, selectOptions[i - 1]);
			}
		}
	}
	// obsługa klikniecia przycisku dół
	function dolButtonClick(p_oEvent) {
		var sel = document.getElementById('wybrane' + unique);

		var ile = 0;
		for ( var i = 0; i < sel.length; i++)
			if (sel.options[i].selected == true)
				ile++;

		if (ile != 1) {
			alert('Zaznacz jedną pozycję');
			return;
		}

		var selectOptions = sel.getElementsByTagName('option');
		for ( var i = selectOptions.length - 2; i >= 0; i--) {
			var opt = selectOptions[i];
			if (opt.selected) {
				var nextOpt = selectOptions[i + 1];
				opt = sel.removeChild(opt);
				nextOpt = sel.replaceChild(opt, nextOpt);
				sel.insertBefore(nextOpt, opt);
			}
		}
	}
	// obsługa klikniecia przycisku lewo
	function lewoButtonClick(p_oEvent) {
		var dostepne = document.getElementById('dostepne' + unique);
		var sel = document.getElementById('wybrane' + unique);

		for ( var i = 0; i < dostepne.length; i++)
			if (dostepne.options[i].selected == true) {
				var elOptNew = document.createElement('option');
				elOptNew.text = dostepne.options[i].text;
				elOptNew.value = dostepne.options[i].value;
				try {
					sel.add(elOptNew, null); // standards compliant; doesn't
					// work in IE
				} catch (ex) {
					sel.add(elOptNew); // IE only
				}
				dostepne.remove(i);

			}
	}
	// obsługa klikniecia przycisku prawo
	function prawoButtonClick(p_oEvent) {
		var dostepne = document.getElementById('dostepne' + unique);
		var sel = document.getElementById('wybrane' + unique);

		for ( var i = 0; i < sel.length; i++)
			if (sel.options[i].selected == true) {
				var elOptNew = document.createElement('option');
				elOptNew.text = sel.options[i].text;
				elOptNew.value = sel.options[i].value;
				try {
					dostepne.add(elOptNew, null); // standards compliant;
					// doesn't work in IE
				} catch (ex) {
					dostepne.add(elOptNew); // IE only
				}
				sel.remove(i);

			}
	}

	//twórz przyciski góra, dół, lewo, prawo
	var oPushButton1 = new YAHOO.widget.Button( {
		label : "",
		id : "YUImodulyGora",
		container : "gora" + unique
	});
	var oPushButton2 = new YAHOO.widget.Button( {
		label : "",
		id : "YUImodulyDol",
		container : "dol" + unique
	});
	var oPushButton3 = new YAHOO.widget.Button( {
		label : "",
		id : "YUImodulyLewo",
		container : "lewo" + unique
	});
	var oPushButton4 = new YAHOO.widget.Button( {
		label : "",
		id : "YUImodulyPrawo",
		container : "prawo" + unique
	});

	// przechwyć zdarzenia kliknięcia przycisków
	oPushButton1.on("click", goraButtonClick);
	oPushButton2.on("click", dolButtonClick);
	oPushButton3.on("click", lewoButtonClick);
	oPushButton4.on("click", prawoButtonClick);

	// throw({Lokalizacja:'Moduł YUImoduly',Opis: 'kapucha'});

}

function YUIedit(classParam, panel, wartosci) {

	var unique = preparePostParam('value', classParam.posID, classParam.unique,
			false);

	// blokada wielokrotnego renderowania zakładki
	if (document.getElementById(classParam.unique) != null)
		return;

	var parent;
	if (classParam.page != undefined && classParam.page != ''
			&& classParam.page != false)
		parent = document.getElementById('panelTab' + classParam.page);
	else
		parent = document.getElementById('panelTab0');

	var region = YAHOO.util.Dom.getRegion(parent.parentNode.parentNode);

	var init = '';
	if (wartosci[classParam.posID] != undefined	&& wartosci[classParam.posID][classParam.unique] != undefined)
		init = wartosci[classParam.posID][classParam.unique];

	classParam.w == 0 ? inputWidth = parseInt(region.width - 9) + 'px'
			: inputWidth = classParam.w + 'px';

	var innerHTML = '<tr>' + '<td style="text-align:left; line-height:15px; height:15px;">'
						+ classParam.desc + '</td>' + '</tr>'
						+ '<tr style="vertical-align:top;">' + '<td>' + '<input id="'
						+ unique + '" type="text" name="' + unique + '" value="' + init
						+ '" style="width:' + inputWidth + '">' + '</td>' + '</tr>';

	if (classParam.sep == true) {
		innerHTML += '<tr>'
				+ '<td style="text-align:left; height:10px;">'
				+ '<div style="width:100%; height:0px; border-top: solid #d4d4d3 1px; border-bottom:solid 1px white;"></div>'
				+ '</td>' + '</tr>';
	}

	
	if (isIE())
		add_inerHTML(parent, innerHTML);
	else
		parent.innerHTML += innerHTML;
	
	

}

function YUIfck(classParam, panel, wartosci) 
{
	var unique = preparePostParam('value', classParam.posID, classParam.unique,
			false);
	// blokada wielokrotnego renderowania zakładki
	if (document.getElementById(unique) != null)
		return;

	var parent;
	if (classParam.page != undefined && classParam.page != ''
			&& classParam.page != false)
		parent = document.getElementById('panelTab' + classParam.page);
	else
		parent = document.getElementById('panelTab0');

	var region = YAHOO.util.Dom.getRegion(parent.parentNode.parentNode);

	var init = '';
	if (wartosci[classParam.posID] != undefined)
		init = wartosci[classParam.posID][classParam.unique];

	classParam.w == 0 ? inputWidth = parseInt(region.width - 5) + 'px'
			: inputWidth = classParam.w + 'px';
	var fck = CreateFckInstance(unique, inputWidth, classParam.h, init);
	var innerHTML = '<tr>' + '<td id="' + classParam.unique
			+ '" style="text-align:left; line-height:15px; height:15px;">' + classParam.desc
			+ '</td>' + '</tr>' + '<tr style="vertical-align:top;">' + '<td>'
			+ fck.CreateHtml() + '</td>' + '</tr>';
	//parent.innerHTML += innerHTML;
	if (isIE())
		add_inerHTML(parent, innerHTML);
	else
		parent.innerHTML += innerHTML;

	var intervalID = 0;

	function Disable(unique) {
		if (DisableFCK(unique) == true)
			clearInterval(intervalID);
	}
	this.Disable = Disable;

	if (classParam.disable == 'true')
		intervalID = setInterval('this.Disable(\'' + unique + '\')', 500);

	this.DisableFCK = DisableFCK;
}

function selectImg(sender) {
	if (sender.style.opacity == '0.5') {
		sender.style.opacity = '1';
		sender.style.borderColor = 'transparent';
		sender.parentNode.setChecked = false;
	} else {
		sender.style.opacity = '0.5';
		sender.style.borderColor = 'red';
		sender.parentNode.setChecked = true;
	}
	//alert
}

function YUIgaleria(classParam, panel, wartosci) 
{
	//blokada wielokrotnego renderowania zakładki
	// if (document.getElementById(classParam.unique) != null)
	// return;

	var unique = preparePostParam('value', classParam.posID, classParam.unique,
			false);
	// blokada wielokrotnego renderowania zakładki
	if (document.getElementById(unique) != null)
		return;

	var parent;
	if (classParam.page != undefined && classParam.page != ''
			&& classParam.page != false)
		parent = document.getElementById('panelTab' + classParam.page);
	else
		parent = document.getElementById('panelTab0');

	var ileObrazkow = 0;
	var imgStl = 'style="width:118px; height:81px; border: solid 1px transparent"';

	function mamDane(dane, unique) 
	{
		//Print(dane);
		/* var ileObrazkow = 0 */
		if (dane[classParam.unique + 'Imgs'] != undefined
				&& dane[classParam.unique + 'Imgs'].count != undefined)
			ileObrazkow = dane[classParam.unique + 'Imgs'].count;

		if (classParam.page != undefined && classParam.page != '')
			tab = document.getElementById('panelTab' + classParam.page);

		var region = YAHOO.util.Dom.getRegion(parent.parentNode.parentNode);
		classParam.w == 0 ? inputWidth = parseInt(region.width - 25) + 'px'
				: inputWidth = classParam.w + 'px';

		var innerHTML = '<tr>'
				+ '<td id="'
				+ classParam.unique
				+ 'tb" style="text-align:left; vertical-align:top; height:18px;"></td>'
				+ '</tr>' + '<tr> ' + '<td id="' + classParam.unique
				+ '" style="text-align:left; vertical-align:top; ">'
				+ '<div style="height:' + parseInt(classParam.h - 35)
				+ 'px; overflow:auto;">';

		if (dane[classParam.unique + 'Imgs'] != undefined) {
			for ( var i = 0; i < dane[classParam.unique + 'Imgs'].count; i++) {
				innerHTML += ''
						+ '<div style="border:dotted transparent 2px; margin:2px; display:inline; float:left;" id="dt'
						+ i + '">' + '<img ' + imgStl + ' src="'
						+ dane[classParam.unique + 'Imgs'].imgs[i]['src']
						+ '" alt="" onclick="selectImg(this);" '
						+ '	ondblclick="editImg(this);">' + '</div>';
			}
		}

		innerHTML += '<!-- END --></div></td></tr>';
		//parent.innerHTML += innerHTML;
		if (isIE())
			add_inerHTML(parent, innerHTML);
		else
			parent.innerHTML += innerHTML;

		var dragElem = [], dragTarget = [];
		Event = YAHOO.util.Event;
		DDM = YAHOO.util.DDM
		DDM.mode = 1;
		function initDD() {
			Dom = YAHOO.util.Dom;

			for ( var i = 0; i < img.count; i++) {

				dragElem[i] = new YAHOO.util.DD("dt" + i);
				dragTarget[i] = new YAHOO.util.DDTarget("dt" + i);
				//alert(dragElem[i]);

				dragElem[i].onInvalidDrop = function(e) {
					// Animating the move is more intesting
					new YAHOO.util.Motion(this.id, {
						points : {
							to : this.startPos
						}
					}, 0.3, YAHOO.util.Easing.easeOut).animate();
					YAHOO.util.Dom.setStyle(document.getElementById(this.id),
							"opacity", 1);
					this.getEl().style.zIndex = this.origZ;
				}

				dragElem[i].startDrag = function(x, y) {
					YAHOO.util.Dom.setStyle(document.getElementById(this.id),
							"opacity", 0.50);
					this.startPos = Dom.getXY(this.id);
					// store the original z-index
					this.origZ = this.getEl().style.zIndex;
					// The z-index needs to be set very high so the element will
					// indeed be on top
					this.getEl().style.zIndex = 999;

				}

				dragElem[i].onDragDrop = function(e, id) {
					//usuń aktualnie przesuwany element z tablicy celów 
					for ( var i = 0; i < id.length; i++)
						if (this.id == id[i].id) {
							id = id.slice(0, i).concat(id.slice(i + 1));
							break;
						}

					other = YAHOO.util.DDM.getBestMatch(id);
					other != null ? other = other.id : other = this.id;

					if (this.id == other)
						new YAHOO.util.Motion(this.id, {
							points : {
								to : this.startPos
							}
						}, 0.3, YAHOO.util.Easing.easeOut).animate();
					else {
						var div = document.getElementById(other);
						var pomStartPos = Dom.getXY(div);
						new YAHOO.util.Motion(div.id, {
							points : {
								to : this.startPos
							}
						}, 0.3, YAHOO.util.Easing.easeOut).animate();
						new YAHOO.util.Motion(this.id, {
							points : {
								to : pomStartPos
							}
						}, 0.3, YAHOO.util.Easing.easeOut).animate();
					}

					YAHOO.util.Dom.setStyle(document.getElementById(this.id),
							"opacity", 1);
					this.getEl().style.zIndex = this.origZ;

					var div = document.getElementById(other);
					div.style.borderColor = 'transparent';
					// this.isTarget = true;
				}

				dragElem[i].onDragOver = function(e, id) {
					//usuń aktualnie przesuwany element z tablicy celów 
					for ( var i = 0; i < id.length; i++)
						if (this.id == id[i].id) {
							id = id.slice(0, i).concat(id.slice(i + 1));
							break;
						}

					other = YAHOO.util.DDM.getBestMatch(id);
					other != null ? other = other.id : other = this.id;

					if (this.id != other) {
						var div = document.getElementById(other);
						div.style.borderColor = 'red';
					}
					for ( var i = 0; i < id.length; i++)
						if (id[i].id != other)
							document.getElementById(id[i].id).style.borderColor = 'transparent';

				}

				dragElem[i].onDragOut = function(e, id) {
					//usuń aktualnie przesuwany element z tablicy celów 
					for ( var i = 0; i < id.length; i++)
						if (this.id == id[i].id) {
							id = id.slice(0, i).concat(id.slice(i + 1));
							break;
						}

					other = YAHOO.util.DDM.getBestMatch(id);
					other != null ? other = other.id : other = this.id;

					if (this.id != other) {
						var div = document.getElementById(other);
						div.style.borderColor = 'transparent';
					}

					for ( var i = 0; i < id.length; i++)
						if (id[i].id != other)
							document.getElementById(id[i].id).style.borderColor = 'transparent';
				}
			}
		}
		initDD();

	}
	var dane = asyncGetWartosc(classParam.posID, classParam.unique, panel, mamDane);

	function addImg(event) 
	{
		function uploadComplete(response, index) 
		{			
			var Handler = 
			{
				success : function(response) 
				{
					//alert(response.responseText);
					if (response.responseText.substring(0, 3) != 'err') 
					{
						if (response.responseText.substring(3).length != 0) 
						{
							wartosci = unserialize(base64_decode(response.responseText.substring(3)));
							dekodujRekurencyjnie(wartosci);
						} 
						else
							wartosci = '';
					} 
					else 
					{
						YUIerr(response.responseText.substring(4));
						return false;
					}
				},
				failure : function(response) 
				{
					alert(response.responseText);
					return false;
				}
			}

			 
			YAHOO.util.Connect.asyncRequest('POST', CMS_AdminHref + 'index/async', Handler,
					"fun=setGaleriaImg&posID=" + classParam.posID + "&path=" + response.ok[0] + "&unique=" + classParam.unique);
			
			
			var pomDiv = document.getElementById(classParam.unique);
			var pom = pomDiv.innerHTML;
			
			var nowy = '<div style="border: dotted transparent 2px; margin:2px; display:inline; float:left;" id="dt' + ileObrazkow + '">' + 
						 	'<img ' + imgStl + ' src="' + response.ok[0] + '" alt="" onclick="selectImg(this);" >' + 
					   '</div><!-- END -->';
			pom = pom.replace('<!-- END -->', nowy);
			pomDiv.innerHTML = pom;
			//alert(4);
			// initDD();
		}
		fileLoader( [ event.pageX, event.pageY ], uploadComplete, classParam.posID, classParam.unique);
	}
	this.addImg = addImg;

	function delImg(event) {
		//alert(ileObrazkow);
		var indexy = '';
		for ( var i = 0; i < ileObrazkow; i++)
			if (document.getElementById('dt' + i).setChecked)
				indexy += i + ';';

		if (indexy != '') {

			var Handler = {
				ileObrazkow : ileObrazkow,
				indexy : indexy,
				success : function(response) {
					if (response.responseText.substring(0, 3) != 'err') {
						var indexyTab = explode(';', indexy);
						for ( var i = 0; i < indexyTab.length; i++)
							if (indexyTab[i] != '') {
								var div = document
										.getElementById('dt' + indexyTab[i]);
								if (div != null)
									div.parentNode.removeChild(div);
							}

						//ponumeruj pozostałe divy z obrazkami na nowo
						var poprawka = 0;
						for ( var i = 0; i < ileObrazkow; i++) {
							var div = document.getElementById('dt' + i);
							div == null ? poprawka--
									: div.id = 'dt' + (parseInt(i) + parseInt(poprawka));
						}
						ileObrazkow += poprawka;
					} else {
						YUIerr(response.responseText.substring(4));
						return false;
					}
				},
				failure : function(response) {
					YUIerr(response.responseText);
					return false;
				}
			};
			var cObj = YAHOO.util.Connect.asyncRequest('POST',
					CMS_AdminHref + 'index/async', Handler,
					"fun=delGaleriaImg&unique=" + classParam.unique
							+ "&indexy=" + indexy + "&posID="
							+ classParam.posID);
		}
	}
	this.delImg = delImg;

	function editImg(sender) {
		//Print(sender);

	}
	this.editImg = editImg;

	function settImg(event) {
		var pom = document.createElement('div');
		pom.id = 'galeriaSettings';
		document.body.appendChild(pom);

		// stwórz panel edycji użytkownika
		this.imgPanelSett = new YAHOO.widget.Dialog(pom, {
			visible : true,
			modal : true,
			close : true,
			width : '500px',
			height : '230px',
			xy : [ event.pageX - 250, event.pageY ]
		});

		this.imgPanelSett.setHeader("Ustawienia galerii");
		this.imgPanelSett
				.setBody(''
						+ '<form id="galeriaSett" class="newsletter" action="index/async" method="POST">'
						+ '	<table border="0" class="newsletter" id="listyAddFormTab">'
						+ '		<tr>'
						+ '			<td style="color: #318be8; text-decoration:underline;">Tryb powiększania miniatur :</td>'
						+ '			<td style="color: #318be8; text-decoration:underline;">Ustawienia obrazków :</td>'
						+ '			<td style="color: #318be8; text-decoration:underline;">Ustawienia miniatur :</td>'
						+ '		</tr>'
						+ '		<tr><td colspan="3" style="height:3px;"></td></tr>'
						+ '		<tr>'
						+ '			<td style="padding:2px;">'
						+ '				<input type="radio" id="trybLightBox" name="tryb" value="Light Box">'
						+ '				<label for="trybLightBox" style="cursor:pointer;">Light Box</label><br/> '
						+ '				<div style="height:2px;"></div>'
						+ '				<input type="radio" id="trybGrayBox" name="tryb" value="Gray Box">'
						+ '				<label for="trybGrayBox" style="cursor:pointer;">Gray Box</label><br/>'
						+ '				<div style="height:2px;"></div>'
						+ '				<input type="radio" id="trybSelf" name="tryb" value="Self">'
						+ '				<label for="trybSelf" style="cursor:pointer;">okno przegladarki (to samo)</label><br/>'
						+ '				<div style="height:2px;"></div>'
						+ '				<input type="radio" id="trybNew" name="tryb" value="New">'
						+ '				<label for="trybNew" style="cursor:pointer;">okno przegladarki (nowe)</label><br/>'
						+ '				<div style="height:2px;"></div>'
						+ '				<input type="radio" id="trybLink" name="tryb" value="Link">'
						+ '				<label for="trybLink" style="cursor:pointer;">zewnętrzny link</label><br/>'
						+ '				<div style="height:2px;"></div>'
						+ '				<input type="radio" id="trybNone" name="tryb" value="None">'
						+ '				<label for="trybNone" style="cursor:pointer;">nie powiększaj</label><br/>'
						+ '			</td>'
						+ '			<td style="vertical-align:top;">'
						+ '				<input type="checkbox" id="orgScale" name="orgScale"> '
						+ '				<label for="orgScale" style="margin-left:2px; cursor:pointer;">skaluj rozmiar [szer x wys] </label><br/>'
						+ '				<div style="height:4px;"></div>'
						+ '				<input type="text" name="orgX" value="" style="width:40px;" > &nbsp;x&nbsp; '
						+ '				<input type="text" name="orgY" value="" style="width:40px;" > &nbsp;[px]'
						+ '				<div style="height:4px;"></div>'
						+ '				<input type="checkbox" id="orgRound" name="orgScale"> '
						+ '				<label for="orgRound" style="margin-left:2px; cursor:pointer;">zaokrąglaj rogi [promień] </label><br/>'
						+ '				<div style="height:4px;"></div>'
						+ '				<input type="text" name="orgX" value="" style="width:40px;" > &nbsp;promień&nbsp; '
						+ '			</td>'
						+ '			<td style="vertical-align:top;">'
						+ '				<input type="checkbox" id="orgScale" name="orgScale"> '
						+ '				<label for="orgScale" style="margin-left:2px; cursor:pointer;">skaluj rozmiar [szer x wys] </label><br/>'
						+ '				<div style="height:4px;"></div>'
						+ '				<input type="text" name="orgX" value="" style="width:40px;" > &nbsp;x&nbsp; '
						+ '				<input type="text" name="orgY" value="" style="width:40px;" > &nbsp;[px]'
						+ '				<div style="height:4px;"></div>'
						+ '				<input type="checkbox" id="orgRound" name="orgScale"> '
						+ '				<label for="orgRound" style="margin-left:2px; cursor:pointer;">zaokrąglaj rogi [promień] </label><br/>'
						+ '				<div style="height:4px;"></div>'
						+ '				<input type="text" name="orgX" value="" style="width:40px;" > &nbsp;promień&nbsp; '
						+ '			</td>'
						+ '		</tr>'
						+

						'		<tr><td id="statusField"></td><td colspan="2" style="text-align:right;"><input id="submitBtn" class="newsletterBtn" type="button" value="Ok">'
						+ '				<input id="cancelBtn" class="newsletterBtn" type="button" value="Anuluj">'
						+ '		</td></tr>'
						+ '		<tr><td colspan="3"><input type="hidden" name="fun" value="add_edt_NewsletterList" >'
						+ '							<input type="hidden" name="id" value="" ></td></tr>'
						+ '	</table>' + ' </form>');
		this.imgPanelSett.render();

	}
	this.settImg = settImg;

	// stworz przyciski toolbara galerii
	this.oButton1 = new YAHOO.widget.Button( {
		type : "push",
		label : "Dodaj",
		container : classParam.unique + 'tb'
	});
	this.oButton1.subscribe("click", this.addImg, this);
	this.oButton1.addClass('tbaddbutton');
	this.oButton2 = new YAHOO.widget.Button( {
		type : "push",
		label : "Usun",
		container : classParam.unique + 'tb'
	});
	this.oButton2.subscribe("click", this.delImg, this);
	this.oButton2.addClass('tbdelbutton');
	// this.oButton3 = new YAHOO.widget.Button ({type: "push", label: "Edytuj",
	// container: classParam.unique+'tb' });
	// this.oButton3.subscribe("click", this.editImg, this);
	// this.oButton3.addClass('tbedtbutton');
	// this.oButton4 = new YAHOO.widget.Button ({type: "push", label:
	// "Ustawienia", container: classParam.unique+'tb' });
	// this.oButton4.subscribe("click", this.settImg, this);
	// this.oButton4.addClass('tbsetbutton');

}

function YUISelectPodstrona(classParam, panel, wartosci) 
{
	var unique = preparePostParam('value', classParam.posID, classParam.unique,	false);
	// alert(wartosci[classParam.posID][classParam.unique]);

	// blokada wielokrotnego renderowania zakładki
	if (document.getElementById(unique) != null)
		return;

	var parent;
	if (classParam.page != undefined && classParam.page != ''
			&& classParam.page != false)
		parent = document.getElementById('panelTab' + classParam.page);
	else
		parent = document.getElementById('panelTab0');

	var region = YAHOO.util.Dom.getRegion(parent.parentNode.parentNode);

	/*
	 * if (wartosci!= null && wartosci[classParam.posID] != undefined &&
	 * wartosci[classParam.posID] != null)
	 * alert(wartosci[classParam.posID][classParam.unique]);
	 */

	classParam.w == 0 ? inputWidth = parseInt(region.width - 6) + 'px'
			: inputWidth = classParam.w + 'px';

	var innerHTML = '<tr>' + '<td style="line-height:15px; height:15px;">'
			+ classParam.desc + '</td>' + '</tr>'
			+ '<tr style="vertical-align:top;">' + '<td>' + '<select id="'
			+ unique + '" name="' + unique + '" style="width:' + inputWidth
			+ '">' + '<option></option>' + '</select>' + '</td>' + '</tr>';

	//parent.innerHTML += innerHTML;
	if (isIE())
		add_inerHTML(parent, innerHTML);
	else
		parent.innerHTML += innerHTML;

	// pobierz pozycje dostepne w bazie danych
	// uchwyt na dane odsyłane przez serwer
	var pomTPID = wartosci[classParam.posID][classParam.unique];
	pomTPID == '' ? pomTPID = 2 : false;
	var Handler = {
		tpID : pomTPID,
		unique : unique,
		classParam : classParam,
		panel : panel,
		success : function(response) {

			//this.wsk.Loader.hide();
		if (response.responseText.substring(0, 3) != 'err') {
			var param;
			if (response.responseText.substring(3).length != 0) {
				param = unserialize(base64_decode(response.responseText
						.substring(3)));
				dekodujRekurencyjnie(param);
			} else
				param = '';

			var ile = count(param);
			var select = document.getElementById(this.unique);
			for ( var i = 0; i < ile; i++) {
				var elOptNew = document.createElement('option');
				elOptNew.text = param[i].nazwa;
				elOptNew.value = param[i].id;

				if (param[i].id == this.tpID)
					elOptNew.selected = true;
				select.appendChild(elOptNew);
			}

			if (select) {
				var obj = {
					classParam : this.classParam,
					panel : this.panel,
					tpID : this.tpID
				};
				YAHOO.util.Event.addListener(select, "change",
						selectTPonChange, obj);
				selectTPonChange(select, obj);

			}

		} else {
			YUIerr(response.responseText.substring(4));
			return false;
		}
	},
	failure : function(response) {
		YUIerr(response.responseText);
		return false;
	}
	};
	var cObj = YAHOO.util.Connect.asyncRequest('POST', CMS_AdminHref + 'index/async', Handler, "fun=getPodpozycje&parentsID=" + implode(';', classParam.parents));

}

function YUIdata(classParam, panel, wartosci) {

	var unique = preparePostParam('value', classParam.posID, classParam.unique,false);
	// blokada wielokrotnego renderowania zakładki
	if (document.getElementById(unique) != null)
		return;

	var parent;
	if (classParam.page != undefined && classParam.page != ''
			&& classParam.page != false)
		parent = document.getElementById('panelTab' + classParam.page);
	else
		parent = document.getElementById('panelTab0');

	var region = YAHOO.util.Dom.getRegion(parent.parentNode.parentNode);

	var init = '';
	if (wartosci[classParam.posID] != undefined
			&& wartosci[classParam.posID][classParam.unique] != undefined)
		init = wartosci[classParam.posID][classParam.unique];

	classParam.w == 0 ? inputWidth = parseInt(region.width - 5) + 'px'
			: inputWidth = classParam.w + 'px';

	var innerHTML = '<tr>' + '<td id="' + classParam.unique
			+ '" style="text-align:left; line-height:15px; height:15px;">' + classParam.desc
			+ '</td>' + '</tr>' + '<tr style="vertical-align:top;">' + '<td style="text-align:left;">'
			+ '<input id="' + unique + '" name="' + unique + '" value="' + init
			+ '" type="text" readonly="readonly" >' + '</td>' + '</tr>';
	//parent.innerHTML += innerHTML;
	if (isIE())
		add_inerHTML(parent, innerHTML);
	else
		parent.innerHTML += innerHTML;

	function handleDataList(e, panel) {
		this.panel = panel;
		// stwórz diva dla panelu dodawania użytkownika
		var pom = document.createElement('div');
		pom.id = 'nwsltrAddListData';
		pom.style.position = "absolute";
		panel.body.appendChild(pom);

		function CloseDialogAddListData(e, param) {
			//zniszcz cały panel kalendarza
			this.callendar.destroy();
			this.callendar = false;

			// zniszcz diva zawierającego panel kalendarza
			var panelDiv = document.getElementById('nwsltrAddListData')
			if (panelDiv != null)
				this.panel.body.removeChild(panelDiv);

		}
		function calSelect(type, args, cal) {
			YAHOO.util.Event.stopEvent(type);

			var dates = args[0];
			var date = dates[0];
			var year = date[0], month = date[1], day = date[2];

			var txtDate1 = document.getElementById(unique);
			if (txtDate1 != null) {
				month < 10 ? month = "0" + month : false;
				day < 10 ? day = "0" + day : false;
				txtDate1.value = year + "-" + month + "-" + day;
			}

			cal.hide();

		}

		//pobierz aktualnie wyświetloną datę aby ustawić ja jako domyślną na kalendarzu
		var txtDate1 = document.getElementById(unique);
		var selDate = '';
		if (txtDate1 != null) {
			if (txtDate1.value != '') {
				var pom = explode('-', txtDate1.value);
				selDate = pom[1] + '/' + pom[2] + '/' + pom[0];
			}
		}

		this.callendar = new YAHOO.widget.Calendar('call', "nwsltrAddListData",
				{
					title : "Wybierz datę:",
					close : true,
					visible : true,
					selected : selDate
				});
		YAHOO.util.Dom.setXY("nwsltrAddListData", [ e.pageX, e.pageY ]);
		this.callendar.hideEvent.subscribe(CloseDialogAddListData,
				this.callendar, this, true);
		this.callendar.selectEvent.subscribe(calSelect, this.callendar, this,
				true);
		this.callendar.render();
	}
	this.handleDataList = handleDataList;

	function ustawListenera(unique) {
		YAHOO.util.Event.addListener(unique, "click", handleDataList, panel);
	}
	this.ustawListenera = ustawListenera;
	this.unique = unique;

	setTimeout("ustawListenera('" + unique + "')", 1000);

}

function YUItextarea(classParam, panel, wartosci) {
	var unique = preparePostParam('value', classParam.posID, classParam.unique,
			false);

	// blokada wielokrotnego renderowania zakładki
	if (document.getElementById(classParam.unique) != null)
		return;

	var parent;
	if (classParam.page != undefined && classParam.page != ''
			&& classParam.page != false)
		parent = document.getElementById('panelTab' + classParam.page);
	else
		parent = document.getElementById('panelTab0');

	var region = YAHOO.util.Dom.getRegion(parent.parentNode.parentNode);

	var init = '';
	if (wartosci[classParam.posID] != undefined
			&& wartosci[classParam.posID][classParam.unique] != undefined)
		init = wartosci[classParam.posID][classParam.unique];

	classParam.w == 0 ? inputWidth = parseInt(region.width - 9) + 'px'
			: inputWidth = classParam.w + 'px';
	classParam.h == 0 ? inputHeight = '40px'
			: inputHeight = classParam.h + 'px';

	var innerHTML = '<tr>' + '<td style="line-height:15px; height:15px;">'
			+ classParam.desc + '</td>' + '</tr>'
			+ '<tr style="vertical-align:top;">' + '<td>' + '<textarea id="'
			+ unique + '" name="' + unique + '" ' + '	style="width:'
			+ inputWidth + '; height:' + inputHeight + '">' + init
			+ '</textarea>' + '</td>' + '</tr>';

	//parent.innerHTML += innerHTML;
	if (isIE())
		add_inerHTML(parent, innerHTML);
	else
		parent.innerHTML += innerHTML;
}

function YUIplayer(classParam, panel, wartosci) 
{
	var unique = preparePostParam('value', classParam.posID, classParam.unique, false);

	// blokada wielokrotnego renderowania zakładki
	if (document.getElementById(classParam.unique) != null)
		return;

	var parent;
	if (classParam.page != undefined && classParam.page != ''
			&& classParam.page != false)
		parent = document.getElementById('panelTab' + classParam.page);
	else
		parent = document.getElementById('panelTab0');

	var region = YAHOO.util.Dom.getRegion(parent.parentNode.parentNode);

	var init = 'Aktualnie wybrany plik: nic nie wybrano';
	if (wartosci[classParam.posID] != undefined
			&& wartosci[classParam.posID][classParam.unique] != undefined
			&& wartosci[classParam.posID][classParam.unique] != '') {
		var pom = explode('/', wartosci[classParam.posID][classParam.unique]);
		init = 'Aktualnie wybrany plik:&nbsp;<span style="font-weight:bold;">' + pom[pom.length - 1] + '</span>';
	}

	//pobierz początkowe wartosci parametrów
	var autoPlayInit = '';
	if (wartosci[classParam.posID] != undefined
			&& wartosci[classParam.posID][classParam.unique + 'AutoPlay'] != undefined
			&& wartosci[classParam.posID][classParam.unique + 'AutoPlay'] == 'on')
		autoPlayInit = 'checked="checked"';
	var rewindInit = '';
	if (wartosci[classParam.posID] != undefined
			&& wartosci[classParam.posID][classParam.unique + 'Rewind'] != undefined
			&& wartosci[classParam.posID][classParam.unique + 'Rewind'] == 'on')
		rewindInit = 'checked="checked"';

	var control = preparePostParam('control', classParam.posID,
			classParam.unique, false);

	classParam.w == 0 ? inputWidth = parseInt(region.width - 9) + 'px'
			: inputWidth = classParam.w + 'px';
	var innerHTML = '<tr style="vertical-align:top;">' + '<td id="'
			+ classParam.unique
			+ '" style="vertical-align:top; height:18px; ">' + '</td>'
			+ '</tr>' + '<tr style="vertical-align:top;">' + '<td id="'
			+ classParam.unique
			+ '_desc" style="padding-left:7px; height:18px; padding-top:6px;">'
			+ init + '</td>' + '</tr>' + '<tr style="vertical-align:top;">'
			+ '<td style="padding-left:2px; height:18px; ">'
			+ '<input type="checkbox" name="' + unique + 'AutoPlay" '
			+ autoPlayInit + ' />Automatycznie rozpocznij odtwarzanie<br>'
			+ '<input type="checkbox" name="' + unique + 'Rewind" '
			+ rewindInit + ' />Odtwarzanie ciągłe'
			+ '<input type="hidden" name="' + control + '" value="video" />'
			+ '</td>' + '</tr>';
	if (classParam.sep == true) {
		innerHTML += '<tr>'
				+ '<td style="height:10px;">'
				+ '<div style="width:100%; height:0px; border-top: solid #d4d4d3 1px; border-bottom:solid 1px white;"></div>'
				+ '</td>' + '</tr>';
	}

	//parent.innerHTML += innerHTML;
	if (isIE())
		add_inerHTML(parent, innerHTML);
	else
		parent.innerHTML += innerHTML;

	function addImg(event) 
	{
		function uploadComplete(response, index) 
		{
			var pom = explode('/', response.ok[0]);
			var desc = document.getElementById(classParam.unique + '_desc');
			if (desc)
				desc.innerHTML = 'Aktualnie wybrany plik:&nbsp;<span style="font-weight:bold;">' + pom[pom.length - 1] + '</span>';
		}
		fileLoader( [ event.pageX, event.pageY ], uploadComplete, classParam.posID, classParam.unique);
	}
	this.addImg = addImg;

	this.oButton1 = new YAHOO.widget.Button( {
		type : "push",
		label : classParam.desc,
		container : classParam.unique
	});
	this.oButton1.subscribe("click", this.addImg, this);
	this.oButton1.addClass('tbaddbutton');

	function delImg(event) {
		function succesHandler() {
			var desc = document.getElementById(classParam.unique + '_desc');
			if (desc)
				desc.innerHTML = 'Aktualnie wybrany plik: nic nie wybrano';
		}
		asyncSetWartosc(classParam.posID, classParam.unique, '', panel, succesHandler);

	}
	this.delImg = delImg;

	this.oButton1 = new YAHOO.widget.Button( {type : "push", label : 'Usuń plik', container : classParam.unique });
	this.oButton1.subscribe("click", this.delImg, this);
	this.oButton1.addClass('tbdelbutton');
}

function YUIimage(classParam, panel, wartosci) {

	//flagi informujące o właczeniu bądĹş wyłączeniu paneli skolowanie i zaokrąglanie 
	var roundEnable = true, scaleEnable = true;
	// pobierz informacje o wyłączonych modułach
	if (classParam.disable != false)
		for ( var i = 0; i < classParam.disable.length; i++) {
			classParam.disable[i] == 'Round' ? roundEnable = false : false;
			classParam.disable[i] == 'Scale' ? scaleEnable = false : false;
		}

	var unique = preparePostParam('value', classParam.posID, classParam.unique,	false);

	// blokada wielokrotnego renderowania zakładki
	if (document.getElementById(classParam.unique) != null)
		return;

	var parent;
	if (classParam.page != undefined && classParam.page != ''
			&& classParam.page != false)
		parent = document.getElementById('panelTab' + classParam.page);
	else
		parent = document.getElementById('panelTab0');

	var region = YAHOO.util.Dom.getRegion(parent.parentNode.parentNode);

	var init = 'Admin/public/images/brakobrazka.gif';
	if (wartosci[classParam.posID] != undefined
			&& wartosci[classParam.posID][classParam.unique] != undefined
			&& wartosci[classParam.posID][classParam.unique] != '')
		init = wartosci[classParam.posID][classParam.unique];

	classParam.w == 0 ? inputWidth = parseInt(region.width - 9) + 'px'
			: inputWidth = classParam.w + 'px';

	var sizeX = sizeY = '';
	if (wartosci[classParam.posID] != undefined
			&& wartosci[classParam.posID][classParam.unique + 'sizeX'] != undefined)
		sizeX = wartosci[classParam.posID][classParam.unique + 'sizeX'];
	if (wartosci[classParam.posID] != undefined
			&& wartosci[classParam.posID][classParam.unique + 'sizeY'] != undefined)
		sizeY = wartosci[classParam.posID][classParam.unique + 'sizeY'];

	var innerHTML = '<tr style="text-align:left; vertical-align:top;1px; ">'
			+ '<td style="text-align:left; width:'+inputWidth+'" id="'
			+ classParam.unique
			+ '">'
			+ '</td>'
			+ '</tr>'
			+ '<tr style="text-align:left;">'
			+ '<td style="text-align:left; ">'
			+ '<table border="0" style="text-align:left;">'
			+ '<tr style="text-align:left;">'
			+ '<td style="text-align:left; width:100px; height:70px;  border: solid 1px black;">'
			+ '<img id="'
			+ unique
			+ '_img" src="'
			+ init
			+ '" style="width:100px; height:70px;">'
			+ '</td>'
			+ '<td style="text-align:left; width:10px; height:70px;">'
			+ '</td>'
			+ '<td style="text-align:left; width:120px; height:70px; vertical-align:top; ">'
			+ '<input id="'
			+ unique
			+ 'Scale" type="checkbox" name="'
			+ unique
			+ 'Scale" value="tr" />Skaluj obraz<br>'
			+ '<div style="padding-left:4px; padding-top:5px; line-height:22px;">'
			+ '<input type="text" name="'
			+ unique
			+ 'sizeX" id="'
			+ unique
			+ 'sizeX" value="'
			+ sizeX
			+ '" style="width:35px;"/> x '
			+ '<input type="text" name="'
			+ unique
			+ 'sizeY" id="'
			+ unique
			+ 'sizeY" value="'
			+ sizeY
			+ '" style="width:35px;"/> [px]'
			+ '</div>'
			+ '</td>'
			+ '<td style="text-align:left; width:120px; height:70px; vertical-align:top;">'
			+ '<input type="checkbox" id="'
			+ unique
			+ 'Round" name="'
			+ unique
			+ 'Round" value="tr" />Zaokrąglaj rogi<br>'
			+ '<div style="padding-left:4px; padding-top:5px; line-height:22px;">'
			+ '<input type="text" id="' + unique + 'R" name="' + unique
			+ 'R" value="" style="width:35px;"/> [px]' + '</div>' + '</td>'
			+ '</tr>' + '</table>' + '</td>' + '</tr>';
	
	

	if (classParam.sep == true) {
		innerHTML += '<tr>'
				+ '<td style="text-align:left; height:10px;">'
				+ '<div style="width:100%; height:0px; border-top: solid #d4d4d3 1px; border-bottom:solid 1px white;"></div>'
				+ '</td>' + '</tr>';
	}
	
	if (isIE())
		add_inerHTML(parent, innerHTML);
	else
		parent.innerHTML += innerHTML;

	function addImg(event) 
	{
		
		function uploadComplete(response, index) {
			var img = document.getElementById(unique + '_img');
			img.src = response.ok[0];
			// alert(img.src);
		}

		try {
			fileLoader( [ event.pageX, event.pageY ], uploadComplete,
					classParam.posID, classParam.unique);
		} catch (err) {
			YUIerr(err);
		}
	}
	this.addImg = addImg;

	function delImg(event) {
		function succesHandler() {
			var pomDiv = document.getElementById(unique + '_img');
			if (pomDiv)
				pomDiv.src = 'Admin/public/images/brakobrazka.gif';
		}
		asyncSetWartosc(classParam.posID, classParam.unique, '', panel,
				succesHandler);

	}
	this.delImg = delImg;

	this.oButton1 = new YAHOO.widget.Button( { type : "push", label : classParam.desc,	container : classParam.unique});
	this.oButton1.subscribe("click", this.addImg, this);
	this.oButton1.addClass('tbaddbutton');

	this.oButton2 = new YAHOO.widget.Button( {
		type : "push",
		label : 'Usuń plik',
		container : classParam.unique
	});
	this.oButton2.subscribe("click", this.delImg, this);
	this.oButton2.addClass('tbdelbutton');

	function handleImgClick() {

	}

	/*function ustawListenery()
	{		
		YAHOO.util.Event.addListener(unique+'_img', "click", handleImgClick, panel);		
	}
	this.ustawListenery = ustawListenery;*/
	
	//setTimeout("ustawListenery()",1000);
	
	//wyłącz wszystkie pola które są zablokowane 
	if (!scaleEnable)
	{
		var pom = document.getElementById(unique+'Scale');
		pom.disabled = true; 
		var pom = document.getElementById(unique+'sizeX');
		pom.disabled = true;
		var pom = document.getElementById(unique+'sizeY');
		pom.disabled = true;
	}
	if (!roundEnable)
	{
		var pom = document.getElementById(unique+'Round');
		pom.disabled = true; 
		var pom = document.getElementById(unique+'R');
		pom.disabled = true;		
	}
}

function YUIpodpozycjeSett(classParam, panel, wartosci) {
	var unique = preparePostParam('value', classParam.posID, classParam.unique,
			false);
	// alert(wartosci[classParam.posID][classParam.unique]);

	// blokada wielokrotnego renderowania zakładki
	if (document.getElementById(unique) != null)
		return;

	var parent;
	if (classParam.page != undefined && classParam.page != ''
			&& classParam.page != false)
		parent = document.getElementById('panelTab' + classParam.page);
	else
		parent = document.getElementById('panelTab0');

	var region = YAHOO.util.Dom.getRegion(parent.parentNode.parentNode);
	classParam.w == 0 ? inputWidth = parseInt(region.width - 6) + 'px'
			: inputWidth = classParam.w + 'px';

	// pobierz wartości dla poszczegolnych pól
	var initIle = 'wszystkie';
	if (wartosci[classParam.posID] != undefined
			&& wartosci[classParam.posID][classParam.unique + 'Ile'] != undefined)
		initIle = wartosci[classParam.posID][classParam.unique + 'Ile'];
	var initIleNaStronie = 'wszystkie';
	if (wartosci[classParam.posID] != undefined
			&& wartosci[classParam.posID][classParam.unique + 'IleNaStronie'] != undefined)
		initIleNaStronie = wartosci[classParam.posID][classParam.unique + 'IleNaStronie'];
	// dla pola sortuj wg
	var initSort1 = '', initSort2 = '', initSort3 = '';
	if (wartosci[classParam.posID] != undefined
			&& wartosci[classParam.posID][classParam.unique + 'IleNaStronie'] != undefined) {
		wartosci[classParam.posID][classParam.unique + 'Sort'] == 'Daty dodania' ? initSort1 = 'selected="selected"'
				: false;
		wartosci[classParam.posID][classParam.unique + 'Sort'] == 'Nazwy' ? initSort2 = 'selected="selected"'
				: false;
		wartosci[classParam.posID][classParam.unique + 'Sort'] == 'Definicji użytkownika' ? initSort3 = 'selected="selected"'
				: false;
	}
	var initOrder1 = '', initOrder2 = '', initOrder3 = '';
	if (wartosci[classParam.posID] != undefined
			&& wartosci[classParam.posID][classParam.unique + 'IleNaStronie'] != undefined) {
		wartosci[classParam.posID][classParam.unique + 'Order'] == 'Rosnąco' ? initOrder1 = 'selected="selected"'
				: false;
		wartosci[classParam.posID][classParam.unique + 'Order'] == 'Malejąco' ? initOrder2 = 'selected="selected"'
				: false;
		wartosci[classParam.posID][classParam.unique + 'Order'] == 'Losowo' ? initOrder3 = 'selected="selected"'
				: false;
	}
	var initUserOrder = ''
	if (wartosci[classParam.posID] != undefined
			&& wartosci[classParam.posID][classParam.unique + 'UserOrder'] != undefined)
		initUserOrder = wartosci[classParam.posID][classParam.unique + 'UserOrder'];

	function SortChange(elem) {
		var wybrane = elem.options[elem.selectedIndex].value;
		if (wybrane == 'Definicji użytkownika') {
			oPozycje.oDT.undisable();
			document.getElementById(unique + 'Ile').disabled = true;
			document.getElementById(unique + 'Order').disabled = true;
		} else {
			oPozycje.oDT.disable();
			document.getElementById(unique + 'Ile').disabled = false;
			document.getElementById(unique + 'Order').disabled = false;
		}
	}
	this.SortChange = SortChange;

	var innerHTML = '<tr style="vertical-align:top;">'
			+ '<table border="0"'
			+ '<tr>'
			+ '<td style="text-align:left;">Sortowanie według<br>'
			+ '<select onchange="SortChange(this);" id="'+ unique+ 'Sort" name="'+ unique+ 'Sort" style="margin-top:3px; width:170px;">'
			+ '<option '+ initSort1+ '>Daty dodania</option>'
			+ '<option '+ initSort2+ '>Nazwy</option>'
			+ '<option '+ initSort3+ '>Definicji użytkownika</option>'
			+ '</select>'
			+ '</td>'
			+ '<td style="text-align:left; padding-left:25px;">Kierunek sortowania<br>'
			+ '<select id="'+ unique+ 'Order" name="'+ unique+ 'Order" style="margin-top:3px; width:170px">'
			+ '<option '+ initOrder1+ '>Rosnąco</option>'
			+ '<option '+ initOrder2+ '>Malejąco</option>'
			+ '<option '
			+ initOrder3
			+ '>Losowo</option>'
			+ '</select>'
			+ '</td>'
			+ '</tr>'
			+ '<tr>'
			+ '<td style="text-align:left;">Ile pozycji wyświetlić:<br> '
			+ '<input type="text" id="'
			+ unique
			+ 'Ile" name="'
			+ unique
			+ 'Ile" style="width:166px; margin-top:3px;" value="'
			+ initIle
			+ '"'
			+ '		  onFocus="this.value==\'wszystkie\' ? this.value=\'\' : false;"'
			+ '		  onBlur="this.value==\'\' || this.value==\'Wszystkie\' ? this.value=\'wszystkie\' : false;" >'
			+ '</td>'
			+ '<td style="text-align:left; padding-left:25px;">Ile pozycji na jednej stronie<br>'
			+ '<input type="text" id="'
			+ unique
			+ 'IleNaStronie" name="'
			+ unique
			+ 'IleNaStronie" style="width:166px; margin-top:3px;" value="'
			+ initIleNaStronie
			+ '"'
			+ '		  onFocus="this.value==\'wszystkie\' ? this.value=\'\' : false;"'
			+ '		  onBlur="this.value==\'\' || this.value==\'Wszystkie\' ? this.value=\'wszystkie\' : false;" >'
			+ '</td>'
			+ '</tr>'
			+ '<tr>'
			+ '<td colspan="2" style="text-align:left; vertical-align:top; padding-top:5px; height:150px;">Dostępne pozycje:'
			+ '<div id="'
			+ unique
			+ 'Container" style="margin:3px 0px;"></div>'
			+ '<span style="color:gray; font-size:10px;">Złap i przeciągnij wiersz aby zmienić jego kolejność</span></td>'
			+ '<input type="hidden" id="' + unique + 'UserOrder" name="'
			+ unique + 'UserOrder" value="' + initUserOrder + '">' + '</tr>'
			+ '</table>' + '</tr>';

	
	
	if (isIE())
		add_inerHTML(parent, innerHTML);
	else
		parent.innerHTML += innerHTML;

	function DTchanged(table) {
		var value = '';
		var records = table.getRecordSet().getRecords();
		for ( var i = 0; i < records.length; i++) {
			var data = records[i].getData();
			data.checked ? value += '-' + data.id + ';'
					: value += data.id + ';'
		}
		var elem = document.getElementById(unique + 'UserOrder');
		if (elem)
			elem.value = value;
	}

	function createTable(initIle) {
		var dataArr = new Array();
		var myColumnDefs = [ {
			key : "checked",
			label : "Wyświetl",
			width : 40,
			sortable : false,
			formatter : YAHOO.widget.DataTable.formatCheckbox
		}, {
			key : "id",
			label : "id",
			hidden : true,
			sortable : false
		}, {
			key : "name",
			label : "Nazwa ",
			sortable : true,
			width : 172
		}, {
			key : "data",
			label : "Data dodania",
			sortable : true,
			width : 70
		} ];

		this.myDataSource = new YAHOO.util.DataSource(dataArr);
		this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
		this.myDataSource.responseSchema = {
			fields : [ "checked", "id", "name", "data" ]
		};

		this.myDataTable = new YAHOO.widget.ScrollingDataTable(
				unique + 'Container', myColumnDefs, this.myDataSource, {
					height : "110px"
				});

		if (initIle != 'Definicji użytkownika')
			this.myDataTable.disable();

		function clickCheckBox(oArgs) {
			var row = this.getTrEl(oArgs.target);
			var records = this.getRecordSet().getRecords();
			if (oArgs.target.checked == true)
				this.getRecordSet().updateKey(records[row.sectionRowIndex],
						"checked", true);
			else
				this.getRecordSet().updateKey(records[row.sectionRowIndex],
						"checked", false);
			DTchanged(this);
		}
		this.myDataTable.subscribe("checkboxClickEvent", clickCheckBox);

		function clickSortColumn() {
			DTchanged(this);
		}
		this.myDataTable.subscribe("columnSortEvent", clickSortColumn);

		function makeDragable() {
			var Dom = YAHOO.util.Dom;
			Event = YAHOO.util.Event;
			DDM = YAHOO.util.DragDropMgr;

			myDTDrags = {};

			// ////////////////////////////////////////////////////////////////////////////
			// Custom drag and drop class
			// ////////////////////////////////////////////////////////////////////////////
			YAHOO.example.DDRows = function(id, sGroup, config) {
				YAHOO.example.DDRows.superclass.constructor.call(this, id,
						sGroup, config);
				Dom.addClass(this.getDragEl(), "custom-class");
				this.goingUp = false;
				this.lastY = 0;
			};

			// ////////////////////////////////////////////////////////////////////////////
			// DDRows extends DDProxy
			// ////////////////////////////////////////////////////////////////////////////
			YAHOO
					.extend(
							YAHOO.example.DDRows,
							YAHOO.util.DDProxy,
							{
								proxyEl : null,
								srcEl : null,
								srcData : null,
								srcIndex : null,
								tmpIndex : null,

								startDrag : function(x, y) {
									var proxyEl = this.proxyEl = this
											.getDragEl(), srcEl = this.srcEl = this
											.getEl();

									this.srcData = myDataTable.getRecord(
											this.srcEl).getData();
									this.srcIndex = srcEl.sectionRowIndex;
									// Make the proxy look like the source
									// element
									Dom.setStyle(srcEl, "visibility", "hidden");
									var inner = srcEl.innerHTML;
									if (this.srcData.checked == true)
										inner = str_replace(
												' type="checkbox',
												' type="checkbox" checked="checked"',
												srcEl.innerHTML);
									else
										inner = str_replace(
												'checked="checked"', '',
												srcEl.innerHTML);

									proxyEl.innerHTML = "<table><tbody>"
											+ inner + "</tbody></table>";
								},

								endDrag : function(x, y) {
									var position, srcEl = this.srcEl;

									Dom.setStyle(this.proxyEl, "visibility",
											"hidden");
									Dom.setStyle(srcEl, "visibility", "");
									DTchanged(myDataTable);
								},

								onDrag : function(e) {
									// Keep track of the direction of the drag for use during onDragOver
								var y = Event.getPageY(e);

								if (y < this.lastY)
									this.goingUp = true;
								else if (y > this.lastY)
									this.goingUp = false;

								this.lastY = y;
							},

							onDragOver : function(e, id) {
								// Reorder rows as user drags
								var srcIndex = this.srcIndex, destEl = Dom
										.get(id), destIndex = destEl.sectionRowIndex, tmpIndex = this.tmpIndex;

								if (destEl.nodeName.toLowerCase() === "tr") {
									if (tmpIndex !== null)
										myDataTable.deleteRow(tmpIndex);
									else
										myDataTable.deleteRow(this.srcIndex);

									myDataTable.addRow(this.srcData, destIndex);
									this.tmpIndex = destIndex;

									DDM.refreshCache();
								}
							}
							});

			// ////////////////////////////////////////////////////////////////////////////
			// Create DDRows instances when DataTable is initialized
			// ////////////////////////////////////////////////////////////////////////////
			myDataTable.subscribe("initEvent", function() {
				var i, id, allRows = this.getTbodyEl().rows;

				for (i = 0; i < allRows.length; i++) {
					id = allRows[i].id;
					// Clean up any existing Drag instances
					if (myDTDrags[id]) {
						myDTDrags[id].unreg();
						delete myDTDrags[id];
					}
					// Create a Drag instance for each row
					myDTDrags[id] = new YAHOO.example.DDRows(id);
				}
			});

			// ////////////////////////////////////////////////////////////////////////////
			// Create DDRows instances when new row is added
			// ////////////////////////////////////////////////////////////////////////////
			myDataTable.subscribe("rowAddEvent", function(e) {
				var id = e.record.getId();
				myDTDrags[id] = new YAHOO.example.DDRows(id);
			})
		}
		;
		makeDragable();

		return {
			oDS : this.myDataSource,
			oDT : this.myDataTable
		};
	}
	var oPozycje = createTable(wartosci[classParam.posID][classParam.unique + 'Sort']);

	// wyłacz niepotrzebne pozycje jeśli sortowanie wg. ustawień użytkownika
	if (wartosci[classParam.posID][classParam.unique + 'Sort'] == 'Definicji użytkownika') {
		document.getElementById(unique + 'Ile').disabled = true;
		document.getElementById(unique + 'Order').disabled = true;
	}

	//pobierz pozycje dostepne w bazie danych
	// uchwyt na dane odsyłane przez serwer
	var Handler = {
		tpID : wartosci[classParam.posID][classParam.unique],
		unique : unique,
		classParam : classParam,
		panel : panel,
		oDT : oPozycje.oDT,
		oDS : oPozycje.oDS,
		success : function(response) {

			//this.wsk.Loader.hide();
		if (response.responseText.substring(0, 3) != 'err') {
			var param;
			if (response.responseText.substring(3).length != 0) {
				param = unserialize(base64_decode(response.responseText
						.substring(3)));
				dekodujRekurencyjnie(param);
			} else
				param = '';

			var userSett = explode(';', document
					.getElementById(unique + 'UserOrder').value);
			var ile = count(param), posCount = 0;
			for ( var i = 0; i < userSett.length; i++)
				for ( var j = 0; j < ile; j++)
					if (Math.abs(userSett[i]) == param[j].id) {
						this.oDT.addRow( {
							checked : userSett[i] < 0,
							id : param[j].id,
							name : param[j].nazwa,
							data : param[j].data
						}, posCount++);
						break;
					}

			for ( var i = 0; i < ile; i++) {
				var dodano = false;
				for ( var j = 0; j < userSett.length; j++)
					if (Math.abs(userSett[j]) == param[i].id) {
						dodano = true;
						break;
					}

				if (!dodano) {
					this.oDT.addRow( {
						checked : false,
						id : param[i].id,
						name : param[i].nazwa,
						data : param[i].id
					}, posCount++);
				}
			}

		} else {
			YUIerr(response.responseText.substring(4));
			return false;
		}
	},
	failure : function(response) {
		YUIerr(response.responseText);
		return false;
	}
	};
	var cObj = YAHOO.util.Connect.asyncRequest('POST',
			CMS_AdminHref + 'index/async', Handler,
			"fun=getPodpozycje&parentsID=" + implode(';', classParam.parents));

}



function YUIpliki(classParam, panel, wartosc1)
{
	
	var unique = classParam.unique;
	var id = classParam.posID
	
	//zdefiniuj unikalny prefiks dla wszystkich elementów wchodzących w skład panelu
	var uniquePref = preparePostParam('value', id, unique, false);
	// blokada wielokrotnego renderowania zakładki
	if (document.getElementById(uniquePref) != null)
		return;
	
	var param = getParam(classParam['posID']);
	
	function zmienBtn(e, param)
	{
		var uniquePref = preparePostParam('value', param.posID, param.unique, false);		
		var sel = document.getElementById(uniquePref + 'Pozycje');	
		
		//pobierz i skontroluj nazwę dodawanego linka oraz jego opis
		var plik = document.getElementById(uniquePref+'_desc');
		var opis = document.getElementById(uniquePref+'Opis');
		if ((plik && plik.value=='')) 
		{
			alert('Wybierz plik ktory chcesz umieścić na serwerze');
			return false;
		}
		
		// uchwyt na dane odsyłane przez serwer
		function succesHandler(id, unique, response) 
		{
			//Print(response);
			var uniquePref = preparePostParam('value', id, unique, false);
			var sel = document.getElementById(uniquePref + 'Pozycje');
			
			sel.options[response.klucz].firstChild.data = response.obj.opis;			
			sel.options[response.klucz].ofObj = response;
			
			//wyczyść pola dodawania nowej wartości
			document.getElementById(uniquePref+'_desc').innerHTML = 'Aktualnie wybrany plik:&nbsp;<span style="font-weight:bold;"></span>';
			document.getElementById(uniquePref+'Opis').value = '';
			
			//wyłącz przycisk Zmień 
			var edtBtn = document.getElementById(uniquePref+'LinkiEditBtn');
			edtBtn.disabled = true;
			//odznacz zmienianą pozycję
			sel.selectedIndex=-1;
		}
		
		var obj = new Object();
		obj.plik = plik.value;
		obj.opis = opis.value;
		
		Print(obj);
		
		asyncSetArrayWartosc(param.posID, param.unique, obj, panel, succesHandler, sel.ofEditObj.klucz);
				
	}


	function addBtn(e, param)	
	{
		var uniquePref = preparePostParam('value', param.posID, param.unique, false); 
		
		//pobierz i skontroluj nazwę dodawanego linka oraz jego opis
		var plik = document.getElementById(uniquePref+'_desc');
		var opis = document.getElementById(uniquePref+'Opis');
		if ((plik && plik.value=='')) 
		{
			alert('Nie wybrano pliku docelowego');
			return false;
		}
		
		// uchwyt na dane odsyłane przez serwer
		function succesHandler(id, unique, response) 
		{	
			var uniquePref = preparePostParam('value', id, unique, false);
			var sel = document.getElementById(uniquePref + 'Pozycje');
			var elem = document.createElement('option');
			if (elem == undefined)
			{
				alert('Nie udalo się stworzyć opcji dla listy wyboru. Skontaktuj się z autorem oprogramowania.');
				return false;
			}
			var pom = document.createTextNode(response.obj.opis);
			elem.appendChild(pom);
			elem.value = response.obj.opis;
			elem.ofObj = response;
			sel.appendChild(elem);
			
			//wyczyść pola dodawania nowej wartości
			document.getElementById(uniquePref+'_desc').innerHTML = 'Aktualnie wybrany plik:&nbsp;<span style="font-weight:bold;"></span>';
			document.getElementById(uniquePref+'Opis').value = '';
		}
		
		var obj = new Object();
		obj.plik = plik.value;
		obj.opis = opis.value;
		
		asyncSetArrayWartosc(param.posID, param.unique, obj, panel, succesHandler, -1);
	}
	
	function delBtn(e, param)
	{
		var uniquePref = preparePostParam('value', param.posID, param.unique, false);		
		var sel = document.getElementById(uniquePref + 'Pozycje');	
		
		var klucze = '';
		for (var i=0; i<sel.options.length; i++)		
			if(sel.options[i].selected)
				klucze += i + ";"
				
		// uchwyt na dane odsyłane przez serwer
		function succesHandler(id, unique, response) 
		{	
				
			var uniquePref = preparePostParam('value', id, unique, false);
			var sel = document.getElementById(uniquePref + 'Pozycje');
			
			//przenumeruj klucze pozostałych pozycji
			var ileUsunieto = 0;
			Print(response);
			for (var i=0; i<response.length; i++)
			{
				if (response[i] != '')
				{
					ileUsunieto++;				
					sel.options[i].ofObj.klucz -= ileUsunieto;
				}
			}
			
			//usuń zaznaczone pozycje	
			var ileUsunieto = 0;
			for (var i=0; i<response.length; i++)			
				if (response[i] != '')
				{
					sel.remove ( parseInt(response[i]) - parseInt(ileUsunieto) );
					ileUsunieto++;	
				}
			
			
		
			//wyłącz przycisk Zmień 
			var edtBtn = document.getElementById(uniquePref+'LinkiEditBtn');
			edtBtn.disabled = true;
			
			//wyłącz przycisk Usuń 
			var delBtn = document.getElementById(uniquePref+'LinkiDelBtn');
			delBtn.disabled = true;
			
			document.getElementById(uniquePref+'_desc').innerHTML='Aktualnie wybrany plik:&nbsp;<span style="font-weight:bold;"></span>';
			document.getElementById(uniquePref+'Opis').value='';
			
			//odznacz wszystkie zaznaczone pozycje listy
			sel.selectedIndex=-1;
		}
		
		asyncDelArrayWartosc(param.posID, param.unique, panel, succesHandler, klucze);
	}
	
	
	//funkcja wywoływana w momenci 
	function pozycjeSelectChange(e, param)
	{
		var uniquePref = preparePostParam('value', param.posID, param.unique, false); 
		//znajdź i włacz przycisk zmień 
		var edtBtn = document.getElementById(uniquePref+'LinkiEditBtn');
		edtBtn.disabled = false;
		//znajdź i włacz przycisk usuń 
		var delBtn = document.getElementById(uniquePref+'LinkiDelBtn');
		delBtn.disabled = false;
		var sel = document.getElementById(uniquePref + 'Pozycje');
		sel.ofEditObj = sel.options[sel.selectedIndex].ofObj; 
		
		var pom = explode('/', sel.ofEditObj.obj.plik);
		document.getElementById(uniquePref+'_desc').innerHTML = 
				'Aktualnie wybrany plik:&nbsp;<span style="font-weight:bold;">' + pom[pom.length - 1] + '</span>';
		document.getElementById(uniquePref+'Opis').value = sel.ofEditObj.obj.opis;		
	}	

	
	//przygotuj wygląd formularza dodawania linków
	function prepareFormat (classParam, uniquePref)
	{
		var parent;
		if (classParam.page != undefined && classParam.page != '' && classParam.page != false)
			parent = document.getElementById('panelTab' + classParam.page);
		else
			parent = document.getElementById('panelTab0');
		
		var innerHTML = 			
			'<tr><td style="text-align:left;">'+
				'<div style="margin-top: 3px;">Zdefiniowane linki</div>'+
			'</td></tr>'+
			'<tr><td style="text-align:left;">'+
				'<select multiple="multiple" style="width: 470px; height: 180px;" id="'+uniquePref+'Pozycje" name="'+uniquePref+'Pozycje"></select>'+
			'</td></tr>'+
			'<tr ><td style="text-align:left;">'+
				'<input value="Usuń" id="'+uniquePref+'LinkiDelBtn" disabled="disabled" style="margin: 3px 0 7px 0; width: 60px;" type="button">'+
			'</td></tr>'+
			'<tr><td style="text-align:left;">'+
				'<div id="'+uniquePref+'Plik" style="margin-left:5px; display:inline; float:left;"></div>'+
				'<div id="'+uniquePref+'_desc" style="line-height:24px;">' +
					'Aktualnie wybrany plik:&nbsp;<span style="font-weight:bold;"></span>'+
				'</div>'+
			'</td></tr>'+
			'<tr ><td style="text-align:left;">'+
				'<div>Wyswietlany opis</div>'+
				'<input id="'+uniquePref+'Opis" name="'+uniquePref+'Opis" value="" style="width: 470px;" type="text">'+
			'</td></tr>'+
			'<tr ><td style="text-align:left;">'+
				'<input id="'+uniquePref+'LinkiAddBtn" value="Dodaj" style="margin-top: 3px; width: 60px;" type="button">'+
				'<input id="'+uniquePref+'LinkiEditBtn" value="Zmień" disabled="disabled" style="margin:3px 0 0 5px; width: 60px;" type="button">'+
			'</td></tr>';
		
		if (classParam.sep == true) 
		{
			innerHTML += 
				'<tr><td style="text-align:left; height:10px;">'+ 
					'<div style="width:100%; height:0px; border-top: solid #d4d4d3 1px; border-bottom:solid 1px white;"></div>'+ 
				'</td></tr>';
		}
		
		//parent.innerHTML += innerHTML;
		if (isIE())
			add_inerHTML(parent, innerHTML);
		else
			parent.innerHTML += innerHTML;
	}
	prepareFormat (classParam, uniquePref);
	
	function addFile(event) 
	{
		function uploadComplete(response, index) 
		{
			var pom = explode('/', response.ok[0]);
			var desc = document.getElementById(uniquePref + '_desc');			
			if (desc)
			{
				desc.value = response.ok[0];
				desc.innerHTML = 'Aktualnie wybrany plik:&nbsp;<span style="font-weight:bold;">' + pom[pom.length - 1] + '</span>';
			}
			
			var opis = document.getElementById(uniquePref + 'Opis');
			if (opis)
			{
				opis.value=pom[pom.length - 1];
			}
		}
		fileLoader( [ event.pageX, event.pageY ], uploadComplete, classParam.posID, classParam.unique);
	}
	this.addFile = addFile;
	this.oButton1 = new YAHOO.widget.Button( {type : "push", label : 'Wybierz plik', container : uniquePref+'Plik' });
	this.oButton1.subscribe("click", this.addFile, this);
	this.oButton1.addClass('tbaddbutton');
	
	//przechwyć kliknięcie przycisku dodaj
	var btnOK = document.getElementById(uniquePref+'LinkiAddBtn');
	YAHOO.util.Event.addListener(btnOK, "click", addBtn, {unique: unique, posID: id} , true );
	//przechwyć kliknięcie przycisku zmien
	var btnZmien = document.getElementById(uniquePref+'LinkiEditBtn');
	YAHOO.util.Event.addListener(btnZmien, "click", zmienBtn, {unique: unique, posID: id} , true );
	//przechwyć kliknięcie przycisku usuń
	var btnDel = document.getElementById(uniquePref+'LinkiDelBtn');
	YAHOO.util.Event.addListener(btnDel, "click", delBtn, {unique: unique, posID: id} , true );
	//przechwyć zaznaczenie pozycji do edycji
	var selectPozycje = document.getElementById(uniquePref+'Pozycje');	
	YAHOO.util.Event.addListener(selectPozycje, "change", pozycjeSelectChange, {unique: unique, posID: id} , true );
	
	function mamDane(dane, param) 
	{
		var uniquePref = preparePostParam('value', param.posID, param.unique, false); 
		var sel = document.getElementById(uniquePref + 'Pozycje');
		var index = param.unique + 'Dane';
		
		if (dane[index] != undefined && dane[index].count != undefined)
			for (var i=0; i<dane[index].count; i++ )
			{
				var elem = document.createElement('option');
				if (elem == undefined)
				{
					alert('Nie udalo się stworzyć opcji dla listy wyboru. Skontaktuj się z autorem oprogramowania.');
					return false;
				}
				
				var pom = document.createTextNode(dane[index]['Dane'][i].opis);
				elem.appendChild(pom);
				elem.value = dane[index]['Dane'][i].plik;
				
				//przygotuj dane dla edycji
				elem.ofObj = {klucz:i, obj:dane[index]['Dane'][i]};
				
				sel.appendChild(elem);	
			}
	}
	asyncGetWartosc(id, unique, panel, mamDane);
}

function YUIlinki (classParam, panel, wartosc1)
{
	var unique = classParam.unique;
	var id = classParam.posID
	
	//zdefiniuj unikalny prefiks dla wszystkich elementów wchodzących w skład panelu
	var uniquePref = preparePostParam('value', id, unique, false);
	// blokada wielokrotnego renderowania zakładki
	if (document.getElementById(uniquePref) != null)
		return;
	
	var param = getParam(classParam['posID']);
	
	function zmienBtn(e, param)
	{
		var uniquePref = preparePostParam('value', param.posID, param.unique, false);		
		var sel = document.getElementById(uniquePref + 'Pozycje');	
		
		//pobierz i skontroluj nazwę dodawanego linka oraz jego opis
		var nazwa = document.getElementById(uniquePref+'Nazwa');
		var cel = document.getElementById(uniquePref+'Cel');
		if ((nazwa && nazwa.value=='') || (cel && cel.value=='')) 
		{
			alert('Podaj opis i adres zmienianego linka');
			return false;
		}
		
		// uchwyt na dane odsyłane przez serwer
		function succesHandler(id, unique, response) 
		{	
			var uniquePref = preparePostParam('value', id, unique, false);
			var sel = document.getElementById(uniquePref + 'Pozycje');
			
			sel.options[response.klucz].firstChild.data = response.obj.nazwa;			
			sel.options[response.klucz].ofObj = response;
			
			//wyczyść pola dodawania nowej wartości
			document.getElementById(uniquePref+'Nazwa').value = '';
			document.getElementById(uniquePref+'Cel').value = '';
			
			//wyłącz przycisk Zmień 
			var edtBtn = document.getElementById(uniquePref+'LinkiEditBtn');
			edtBtn.disabled = true;
			//odznacz zmienianą pozycję
			sel.selectedIndex=-1;
		}
		
		var obj = new Object();
		obj.nazwa = nazwa.value;
		obj.cel = cel.value;				
		
		asyncSetArrayWartosc(param.posID, param.unique, obj, panel, succesHandler, sel.ofEditObj.klucz);
				
	}


	function addBtn(e, param)	
	{
		var uniquePref = preparePostParam('value', param.posID, param.unique, false); 
		
		//pobierz i skontroluj nazwę dodawanego linka oraz jego opis
		var nazwa = document.getElementById(uniquePref+'Nazwa');
		var cel = document.getElementById(uniquePref+'Cel');
		if ((nazwa && nazwa.value=='') || (cel && cel.value=='')) 
		{
			alert('Podaj opis i adres dodawanego linka');
			return false;
		}
		
		// uchwyt na dane odsyłane przez serwer
		function succesHandler(id, unique, response) 
		{	
			var uniquePref = preparePostParam('value', id, unique, false);
			var sel = document.getElementById(uniquePref + 'Pozycje');
			var elem = document.createElement('option');
			if (elem == undefined)
			{
				alert('Nie udalo się stworzyć opcji dla listy wyboru. Skontaktuj się z autorem oprogramowania.');
				return false;
			}
			var pom = document.createTextNode(response.obj.nazwa);
			elem.appendChild(pom);
			elem.value = response.obj.nazwa;
			elem.ofObj = response;
			sel.appendChild(elem);
			
			//wyczyść pola dodawania nowej wartości
			document.getElementById(uniquePref+'Nazwa').value = '';
			document.getElementById(uniquePref+'Cel').value = '';
		}
		
		var obj = new Object();
		obj.nazwa = nazwa.value;
		obj.cel = cel.value;
				
		asyncSetArrayWartosc(param.posID, param.unique, obj, panel, succesHandler, -1);
	
	}
	
	function delBtn(e, param)
	{
		var uniquePref = preparePostParam('value', param.posID, param.unique, false);		
		var sel = document.getElementById(uniquePref + 'Pozycje');	
		
		var klucze = '';
		for (var i=0; i<sel.options.length; i++)		
			if(sel.options[i].selected)
				klucze += i + ";"
				
		// uchwyt na dane odsyłane przez serwer
		function succesHandler(id, unique, response) 
		{	
				
			var uniquePref = preparePostParam('value', id, unique, false);
			var sel = document.getElementById(uniquePref + 'Pozycje');
			
			//przenumeruj klucze pozostałych pozycji
			var ileUsunieto = 0;
			for (var i=0; i<response.length; i++)
			{
				if (response[i] != '')
					ileUsunieto++;				
				sel.options[i].ofObj.klucz -= ileUsunieto;
			}
			
			//usuń zaznaczone pozycje	
			var ileUsunieto = 0;
			for (var i=0; i<response.length; i++)			
				if (response[i] != '')
				{
					sel.remove ( parseInt(response[i]) - parseInt(ileUsunieto) );
					ileUsunieto++;	
				}
			
			
		
			//wyłącz przycisk Zmień 
			var edtBtn = document.getElementById(uniquePref+'LinkiEditBtn');
			edtBtn.disabled = true;
			
			//wyłącz przycisk Usuń 
			var delBtn = document.getElementById(uniquePref+'LinkiDelBtn');
			delBtn.disabled = true;
			
			document.getElementById(uniquePref+'Nazwa').value='';
			document.getElementById(uniquePref+'Cel').value='';
			
			//odznacz wszystkie zaznaczone pozycje listy
			sel.selectedIndex=-1;
		}
		
		asyncDelArrayWartosc(param.posID, param.unique, panel, succesHandler, klucze);
	}
	
	
	//funkcja wywoływana w momenci 
	function pozycjeSelectChange(e, param)
	{
		var uniquePref = preparePostParam('value', param.posID, param.unique, false); 
		//znajdź i włacz przycisk zmień 
		var edtBtn = document.getElementById(uniquePref+'LinkiEditBtn');
		edtBtn.disabled = false;
		//znajdź i włacz przycisk usuń 
		var delBtn = document.getElementById(uniquePref+'LinkiDelBtn');
		delBtn.disabled = false;
		var sel = document.getElementById(uniquePref + 'Pozycje');
		sel.ofEditObj = sel.options[sel.selectedIndex].ofObj; 
		document.getElementById(uniquePref+'Nazwa').value = sel.ofEditObj.obj.nazwa;
		document.getElementById(uniquePref+'Cel').value = sel.ofEditObj.obj.cel;		
	}	

	
	//przygotuj wygląd formularza dodawania linków
	function prepareFormat (classParam, uniquePref)
	{
		var parent;
		if (classParam.page != undefined && classParam.page != '' && classParam.page != false)
			parent = document.getElementById('panelTab' + classParam.page);
		else
			parent = document.getElementById('panelTab0');
		
		var innerHTML = 			
			'<tr><td style="text-align:left;">'+
				'<div style="margin-top: 3px;">Zdefiniowane linki</div>'+
			'</td></tr>'+
			'<tr><td style="text-align:left;">'+
				'<select multiple="multiple" style="width: 470px; height: 180px;" id="'+uniquePref+'Pozycje" name="'+uniquePref+'Pozycje"></select>'+
			'</td></tr>'+
			'<tr ><td style="text-align:left;">'+
				'<input value="Usuń" id="'+uniquePref+'LinkiDelBtn" disabled="disabled" style="margin: 3px 0 7px 0; width: 60px;" type="button">'+
			'</td></tr>'+
			'<tr><td style="text-align:left;">'+
				'<div>Opis linka</div>'+
				'<input id="'+uniquePref+'Nazwa" name="'+uniquePref+'Nazwa" value="" style="width: 470px;" type="text">'+
			'</td></tr>'+
			'<tr ><td style="text-align:left;">'+
				'<div>Adres docelowy</div>'+
				'<input id="'+uniquePref+'Cel" name="'+uniquePref+'Cel" value="" style="width: 470px;" type="text">'+
			'</td></tr>'+
			'<tr ><td style="text-align:left;">'+
				'<input id="'+uniquePref+'LinkiAddBtn" value="Dodaj" style="margin-top: 3px; width: 60px;" type="button">'+
				'<input id="'+uniquePref+'LinkiEditBtn" value="Zmień" disabled="disabled" style="margin:3px 0 0 5px; width: 60px;" type="button">'+
			'</td></tr>';
		
		if (classParam.sep == true) 
		{
			innerHTML += 
				'<tr><td style="text-align:left; height:10px;">'+ 
					'<div style="width:100%; height:0px; border-top: solid #d4d4d3 1px; border-bottom:solid 1px white;"></div>'+ 
				'</td></tr>';
		}
		
		//parent.innerHTML += innerHTML;
		if (isIE())
			add_inerHTML(parent, innerHTML);
		else
			parent.innerHTML += innerHTML;
	}
	prepareFormat (classParam, uniquePref);
	
	//przechwyć kliknięcie przycisku dodaj
	var btnOK = document.getElementById(uniquePref+'LinkiAddBtn');
	YAHOO.util.Event.addListener(btnOK, "click", addBtn, {unique: unique, posID: id} , true );
	//przechwyć kliknięcie przycisku zmien
	var btnZmien = document.getElementById(uniquePref+'LinkiEditBtn');
	YAHOO.util.Event.addListener(btnZmien, "click", zmienBtn, {unique: unique, posID: id} , true );
	//przechwyć kliknięcie przycisku usuń
	var btnDel = document.getElementById(uniquePref+'LinkiDelBtn');
	YAHOO.util.Event.addListener(btnDel, "click", delBtn, {unique: unique, posID: id} , true );
	//przechwyć zaznaczenie pozycji do edycji
	var selectPozycje = document.getElementById(uniquePref+'Pozycje');	
	YAHOO.util.Event.addListener(selectPozycje, "change", pozycjeSelectChange, {unique: unique, posID: id} , true );
	
	function mamDane(dane, param) 
	{
		
		
		var uniquePref = preparePostParam('value', param.posID, param.unique, false); 
		var sel = document.getElementById(uniquePref + 'Pozycje');
		var index = param.unique + 'Dane';
		
		//Print(dane[index]);
		
		if (dane[index] != undefined && dane[index].count != undefined)
			for (var i=0; i<dane[index].count; i++ )
			{
				
				
				
				
				var elem = document.createElement('option');
				if (elem == undefined)
				{
					alert('Nie udalo się stworzyć opcji dla listy wyboru. Skontaktuj się z autorem oprogramowania.');
					return false;
				}
				
				var pom = document.createTextNode(dane[index]['Dane'][i].nazwa);
				elem.appendChild(pom);
				elem.value = dane[index]['Dane'][i].nazwa;
				
				//przygotuj dane dla edycji
				elem.ofObj = {klucz:i, obj:dane[index]['Dane'][i]};
				
				sel.appendChild(elem);	
			}
	}
	asyncGetWartosc(id, unique, panel, mamDane);
	
}











function changeProgram() {
	alert(this);
}

//funkcje pomocnicze
function fileLoader(pos, uploadComplete, posID, unique, uplaodCompleteParam) 
{
	//stwórz panel do wysyłania plików
	var uplaodPanelDiv = document.createElement('div');
	uplaodPanelDiv.id = 'uplaodPanelDiv';
	document.body.appendChild(uplaodPanelDiv);

	this.uploadPanel = new YAHOO.widget.Panel(uplaodPanelDiv, {width : '500px',xy : pos,visible : true,modal : true,
		effect : {effect : YAHOO.widget.ContainerEffect.FADE,duration : 0.6} });

	this.uploadPanel.setHeader('Wybierz pliki do wysłania na serwer');
	this.uploadPanel
			.setBody(''
					+ '<div id="uiElements" style="display:inline;">'
					+ '<div id="uploaderContainer">'
					+ '<div id="uploaderOverlay" style="position:absolute; z-index:2;  width:77px; height:24px;"></div>'
					+ '<div id="selectFilesLink" style="z-index:1">'
					+ '<div id="selectLink" style="display:inline; float:left;" ></div>'
					+ '<div id="uploadLink" style="display:inline; float:left;" ></div>'
					+ '</div>'
					+ '<div style="clear:both;" ></div>'
					+ '</div>'
					+ '</div>'
					+ '<div style="margin-top:7px;" id="dataTableContainer"></div>');
	this.uploadPanel.body.id = 'uploadPanelBody';

	this.uploadPanel.render();

	function CloseDialogUpload(e) {
		//zniszcz cały panel dodawania usera
		this.uploadPanel.destroy();
		this.uploadPanel = false;

		// zniszcz diva zawierającego panel
		var panelDiv = document.getElementById('uplaodPanelDiv')
		if (panelDiv != null)
			document.body.removeChild(panelDiv);

		return true;
	}
	;

	this.uploadPanel.hideEvent.subscribe(CloseDialogUpload, this.panelSend,
			this, true);
	YAHOO.widget.Uploader.SWFURL = CMS_AdminHref + 'public/scripts/js/YUI/Uploader/uploader.swf';

	// Instantiate the uploader and write it to its placeholder div.
	// var uploader = new YAHOO.widget.Uploader( "uploaderOverlay" );
	var uploader = new YAHOO.widget.Uploader("uploaderOverlay");

	createDataTable(null);
	// Add event listeners to various events on the uploader.
	// Methods on the uploader should only be called once the
	// contentReady event has fired.

	uploader.addListener('contentReady', handleContentReady);
	uploader.addListener('fileSelect', onFileSelect)
	uploader.addListener('uploadStart', onUploadStart);
	uploader.addListener('uploadProgress', onUploadProgress);
	uploader.addListener('uploadCancel', onUploadCancel);
	uploader.addListener('uploadComplete', onUploadComplete);
	uploader.addListener('uploadCompleteData', onUploadResponse);
	uploader.addListener('uploadError', onUploadError);
	uploader.addListener('rollOver', handleRollOver);
	uploader.addListener('rollOut', handleRollOut);
	uploader.addListener('click', handleClick);

	// Variable for holding the filelist.
	var fileList, uploadCount = 0;

	// When the mouse rolls over the uploader, this function
	// is called in response to the rollOver event.
	// It changes the appearance of the UI element below the Flash overlay.
	function handleRollOver(event, button) {
		var button = document.getElementById('usersbtn_add');
		button.className = 'yui-button yui-push-button yui-button-hover yui-push-button-hover';
	}

	// On rollOut event, this function is called, which changes the appearance of the
	// UI element below the Flash layer back to its original state.
	function handleRollOut() {
		var button = document.getElementById('usersbtn_add');
		button.className = 'yui-button yui-push-button';
	}

	// When the Flash layer is clicked, the "Browse" dialog is invoked.
	// The click event handler allows you to do something else if you need to.
	function handleClick() {
	}

	// When contentReady event is fired, you can call methods on the uploader.
	function handleContentReady() {
		// Allows the uploader to send log messages to trace, as well as to YAHOO.log
		uploader.setAllowLogging(true);

		// Allows multiple file selection in "Browse" dialog.
		uploader.setAllowMultipleFiles(true);

		// New set of file filters.
		var ff = new Array( {
			description : "zdjęcia",
			extensions : "*.jpeg;*.jpg;*.png;*.gif"
		}, {
			description : "video",
			extensions : "*.avi;*.mov;*.mpg;*.flv"
		}, {
			description : "wszystkie pliki",
			extensions : "*.*"
		});

		// Apply new set of file filters to the uploader.
		uploader.setFileFilters(ff);
	}

	// Actually uploads the files. In this case,
	// uploadAll() is used for automated queueing and upload 
	// of all files on the list.
	// You can manage the queue on your own and use "upload" instead,
	// if you need to modify the properties of the request for each
	// individual file.
	function upload() 
	{
		if (fileList != null) 
		{
			uploadCount = 0;
			uploader.setSimUploadLimit(1);			
			uploader.uploadAll(CMS_AdminHref + 'index/async', "post", { fun : "YUIuploadFile", id : posID, unique : unique }, "Filedata");			
		}
	}

	// Fired when the user selects files in the "Browse" dialog
	// and clicks "Ok".
	function onFileSelect(event) {
		if ('fileList' in event && event.fileList != null) {
			fileList = event.fileList;
			createDataTable(fileList);
		}
	}

	function createDataTable(entries) {
		rowCounter = 0;
		this.fileIdHash = {};
		this.dataArr = [];
		for ( var i in entries) {
			var entry = entries[i];
			entry["progress"] = "<div style='height:5px;width:140px;background-color:#CCC;'></div>";
			dataArr.unshift(entry);
		}

		for ( var j = 0; j < dataArr.length; j++) {
			this.fileIdHash[dataArr[j].id] = j;
		}

		var myColumnDefs = [ {
			key : "name",
			label : "Nazwa pliku",
			sortable : false,
			width : 200
		}, {
			key : "size",
			label : "Rozmiar [b]",
			sortable : false,
			width : 70
		}, {
			key : "progress",
			label : "Postęp wysyłania",
			sortable : false,
			width : 140
		} ];

		this.myDataSource = new YAHOO.util.DataSource(dataArr);
		this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
		this.myDataSource.responseSchema = {
			fields : [ "id", "name", "created", "modified", "type", "size",
					"progress" ]
		};

		this.singleSelectDataTable = new YAHOO.widget.DataTable(
				"dataTableContainer", myColumnDefs, this.myDataSource, {
					selectionMode : "single"
				});
	}

	// Do something on each file's upload start.
	function onUploadStart(event) {

	}

	// Do something on each file's upload progress event.
	function onUploadProgress(event) {
		rowNum = fileIdHash[event["id"]];
		prog = Math.round(140 * (event["bytesLoaded"] / event["bytesTotal"]));
		progbar = "<div style='height:5px;width:140px;background-color:#CCC;'><div style='height:5px;background-color:#F00;width:"
				+ prog + "px;'></div></div>";
		singleSelectDataTable.updateRow(rowNum, {
			name : dataArr[rowNum]["name"],
			size : dataArr[rowNum]["size"],
			progress : progbar
		});
	}

	// Do something when each file's upload is complete.
	function onUploadComplete(event) 
	{
		rowNum = fileIdHash[event["id"]];
		prog = Math.round(140 * (event["bytesLoaded"] / event["bytesTotal"]));
		progbar = "<div style='height:5px;width:140px;background-color:#CCC;'><div style='height:5px;background-color:#F00;width:140px;'></div></div>";
		singleSelectDataTable.updateRow(rowNum, {
			name : dataArr[rowNum]["name"],
			size : dataArr[rowNum]["size"],
			progress : progbar
		});
	}

	// Do something if a file upload throws an error.
	// (When uploadAll() is used, the Uploader will
	// attempt to continue uploading.
	function onUploadError(event) {
		alert('error' + event);
		//PrintObject(event, 1, 1, 70, true);
	}

	// Do something if an upload is cancelled.
	function onUploadCancel(event) {
	}

	// Do something when data is received back from the server.
	function onUploadResponse(event) 
	{

		if (event.data.substring(0,3) == 'ok:')
		{
			var param = unserialize(base64_decode(event.data.substring(3)));		
			dekodujRekurencyjnie(param);
			uploadComplete(param, uploadCount);
			uploadCount++;
			if (uploadCount == count(fileList))
				uploadPanel.hide();
		}
		else
			YUIerr(response.responseText.substring(4));
	}

	this.oButton1 = new YAHOO.widget.Button( {id : "usersbtn_add",type : "push",label : "Dodaj",container : "selectLink" });
	this.oButton2 = new YAHOO.widget.Button( {id : "usersbtn_snd",type : "push",label : "Wyślij",container : "uploadLink"});
	this.oButton2.subscribe("click", upload, this);

}

var buttonRefreshStateClone = false, specialComboRefreshStateClone = false;
function EnableFCK(unique) {
	if (typeof (FCKeditorAPI) != 'undefined') {
		var editorInstance = FCKeditorAPI.GetInstance(unique);
		if (editorInstance) {
			// enable the editArea
			if (document.all)
				editorInstance.EditorDocument.body.disabled = false;
			else
				editorInstance.EditorDocument.designMode = "on";

			// enable the toolbar
			editorInstance.EditorWindow.parent.FCK.ToolbarSet.Enable();
			if (buttonRefreshStateClone != false)
				editorInstance.EditorWindow.parent.FCKToolbarButton.prototype.RefreshState = buttonRefreshStateClone;
			if (specialComboRefreshStateClone != false)
				editorInstance.EditorWindow.parent.FCKToolbarSpecialCombo.prototype.RefreshState = specialComboRefreshStateClone;

			// set focus on editorArea
			editorInstance.EditorWindow.focus();
			// and update toolbarset
			editorInstance.EditorWindow.parent.FCK.ToolbarSet
					.RefreshModeState();
			return true;

		}
	}
	return false;
}

function DisableFCK(unique) {
	if (typeof (FCKeditorAPI) != 'undefined') {
		var editorInstance = FCKeditorAPI.GetInstance(unique);
		if (editorInstance) {
			if ((!document.all && editorInstance.EditorDocument.designMode
					.toLowerCase() != "off")
					|| (document.all && editorInstance.EditorDocument.body.disabled == false)) {
				// disable the editArea
				if (document.all)
					editorInstance.EditorDocument.body.disabled = true;
				else
					editorInstance.EditorDocument.designMode = "off";

				// disable the toolbar
				editorInstance.EditorWindow.parent.FCK.ToolbarSet.Disable();
				buttonRefreshStateClone = editorInstance.EditorWindow.parent.FCKToolbarButton.prototype.RefreshState;
				specialComboRefreshStateClone = editorInstance.EditorWindow.parent.FCKToolbarSpecialCombo.prototype.RefreshState;
				editorInstance.EditorWindow.parent.FCKToolbarButton.prototype.RefreshState = function() {
					return false;
				};
				editorInstance.EditorWindow.parent.FCKToolbarSpecialCombo.prototype.RefreshState = function() {
					return false;
				};
				return true;
			}
		}
	}
	return false;
}

function changeFCKid(unique, nowe) {
	if (typeof (FCKeditorAPI) != 'undefined') {
		var editorInstance = FCKeditorAPI.GetInstance(unique);
		if (editorInstance) {
			//przekopiuj starego fck do nowego
			var pom = FCKeditorAPI.__Instances[unique];
			delete FCKeditorAPI.__Instances[unique];
			FCKeditorAPI.__Instances[nowe] = pom;
			// zmien parametry wysyłane w metodzie POST na nowe
			var pom1 = document.getElementById(unique);
			pom.Name = nowe;

			pom1.id = nowe;
			pom1.name = nowe;
			// pobierz nowego edytora i przypisz do niego nową nazwę
			var fck = FCKeditorAPI.GetInstance(nowe);
		}

	}

}

