function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function urldecode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brettz9.blogspot.com)
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    // *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
    // *     returns 2: 'http://kevin.vanzonneveld.net/'
    // *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
    
    var histogram = {};
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urlencode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
 
    for (replace in histogram) {
        search = histogram[replace]; // Switch order when decoding
        ret = replacer(search, replace, ret) // Custom replace. No regexing   
    }
    
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);
 
    return ret;
}



//----------------------------------------------------------------------------------
//
//	Operacje na liscie wyboru SELECT
//
//----------------------------------------------------------------------------------

 //funkcja sprawdza czy na liscie SELECT przekazanej jako pierwszy argument wystepuje wartosc przekazana jako
 //drugi parametr wywolania funkcji. Zwraca true lub false 
 function SelectList_isOptionInsideList(Lista, dana)
 { 	 	
 	for (var i=0; i<Lista.length; i++)
 	{ 		 		
 		if (Lista.options[i].text == dana)
 			return true;
 	} 		 
 	return false;
 }
 
 //funkcja dodaje do listy SELECT przekazanej jako pierwszy argument wartosc przekazana jako
 //drugi parametr wywolania funkcji. Zwraca nowo utworzona pozycje OPTION 
 function SelectList_AddOption(Lista, dana)
 { 	 	
 	var option=document.createElement("OPTION");
	option.appendChild(document.createTextNode(dana));				
	Lista.appendChild(option);
	return option;
 }
 
 //funkcja usuwa z listy SELECT wszystkie pozycje ktore sa zaznaczone jako wnik zwraca ilosc usunietych pozycji
 function SelectList_DelSelectedOptions(Lista)
 {
 	var ile = 0;
 	for (var i = Lista.length - 1; i >= 0; i--) 
		if (Lista.options[i].selected) 
		{
			Lista.remove(i);
			ile++;
		}		    	
    return ile;
 } 
 
  //funkcja zaznacza na liscie SELECT pozycje o nazwie przekazanej w zmiennej dana 
 function SelectList_SelectOption(Lista, dana)
 { 	 	 		 	
	for (var i = 0; i < Lista.length; i++) 
		if (Lista.options[i].text == dana) 
		   Lista.options[i].selected = true;					 	 
 }
 
 //funkcja zaznacza wszystkie pozycje na liscie
 function SelectList_SelectAll(Lista)
 {
	alert('zaznaczam'); 
 	for (var i=0; i<Lista.length; i++)
 		Lista.options[i].selected = true;
 }
 
 //funkcja usuwa wszystkie pozycje z listy List
 function SelectList_DelAll(List)
 {
 	for (var i = Lista.length - 1; i >= 0; i--)  	     	
    	Lista.remove(i);    		
 }
 



//----------------------------------------------------------------------------------
//
//	Funkcje Towrzące inputy dla dialogów
//
//----------------------------------------------------------------------------------
/** funkcja tworzy diva zawierającego w sobie opis pola input oraz samo pole input. 
 * 
 * @param {DOMNode} hParent - węzeł będący rodzice tworzonego panelu  
 * @param {int} left - odległość w pixelach od lewej krawędzi hParent
 * @param {int} top - odległość w pixelach od górnej krawędzi hParent
 * @param {int} width - długość panelu w pixelach
 * @param {int} height - wysokość panelu w pixelach
 * @param {string} nazwa - nazwa tworzonego pola input
 * @param {string} textowyOpis - tekstowy opis pola input wyświetlany nad nim
 * @return {DOMNode} nowo stworzony div
 */ 
function CreateInputField(hParent, left, top, width, height, nazwa, textowyOpis, value )
{
	value == undefined ? value = '' : false;
	//odległość w pixelach pomiędzy opisem a polem input
	var sep = 3;
	 	
	//stwórz opis pola
	var opis = document.createElement('div');
	opis.type='div';
	opis.name = 'InputText_Opis';
	opis.value='';	
	opis.innerHTML = textowyOpis;
    SetElemStyle(opis, "position:absolute; left:2px; top:0px;");
	//oblicz rozmiar jaki zajmie opis pola na dialogu
    hParent.appendChild(opis);
	var opisHeight = getElemHeight(opis);			
	hParent.removeChild(opis); 
	
	//stwórz element input
	var input = document.createElement('input');
	input.type  = 'text';
	input.name = nazwa;	
	input.value = value;	
    SetElemStyle(input,"position:absolute; background-color: white; " + 
						GetCSSSize(0, opisHeight + sep, width, height)); 
	//oblicz rozmiar jaki zajmie element input na dialogu             		
	hParent.appendChild(input);	
	var inputHeight = getElemHeight(input);
	hParent.removeChild(input); 
	
	var html = '<input type="text" name="' + nazwa + '" value="' + value + '" ' + 
	           'style="position:absolute; background-color: white; ' + GetCSSSize(0, opisHeight + sep, width, height) + '" />';
	
	//utwórrz kontener magazynujący opis i input	
	var pudlo = document.createElement('div');
	pudlo.type='div';	
	pudlo.name = 'InputText_Kontener';
	pudlo.value='';		 
    SetElemStyle(pudlo, "position:absolute; " + 
						GetCSSSize(left, top, width, opisHeight + sep + inputHeight) );
    hParent.appendChild(pudlo);	
	  
    //przypisz stworzone elemnty do pudla
    pudlo.innerHTML = html;
	pudlo.appendChild(opis);
	//pudlo.appendChild(input);
	
		                       	
	return pudlo;
}

function CreatPassField(hParent, left, top, width, height, nazwa, textowyOpis )
{
	//odległość w pixelach pomiędzy opisem a polem input
	var sep = 3;
	 	
	//stwórz opis pola
	var opis = document.createElement('div');	
	opis.innerHTML = textowyOpis;
    SetElemStyle(opis, "position:absolute; left:2px; top:0px;");
	//oblicz rozmiar jaki zajmie opis pola na dialogu
    hParent.appendChild(opis);
	var opisHeight = getElemHeight(opis);			
	hParent.removeChild(opis); 
	
	//stwórz element input
	var input = document.createElement('input');
	input.type  = 'password';
	input.name = nazwa;	  
    SetElemStyle(input,"position:absolute; background-color: white; " + 
						GetCSSSize(0, opisHeight + sep, width, height)); 
	//oblicz rozmiar ajki zajmie element input na dialogu             		
	hParent.appendChild(input);	
	var inputHeight = getElemHeight(input);
	hParent.removeChild(input); 
	
	//utwórrz kontener magazynujący opis i input	
	var pudlo = document.createElement('div');			 
    SetElemStyle(pudlo, "position:absolute; " + 
						GetCSSSize(left, top, width, opisHeight + sep + inputHeight) );
    hParent.appendChild(pudlo);	
	  
    //przypisz stworzone elemnty do pudla
	pudlo.appendChild(opis);
	pudlo.appendChild(input);
		                       	
	return pudlo;
	
}

/** funkcja tworzy przycisk button
 * 
 * @param {DOMNode} hParent - węzeł będący rodzice tworzonego panelu  
 * @param {int} left - odległość w pixelach od lewej krawędzi hParent
 * @param {int} top - odległość w pixelach od górnej krawędzi hParent
 * @param {int} width - długość panelu w pixelach
 * @param {int} height - wysokość panelu w pixelach
 * @param {string} id - identyfikator przycisku
 * @param {string} value - wartosc napisana na przycisku
 * @return {DOMNode} nowo stworzony button 
 */
function CreateButton(hParent, left,top, width, height, id, value)
{
  var btn = document.createElement("button");
  btn.id = id;
  btn.type='button';
  btn.name=value;
  btn.innerHTML = value;  
  SetElemStyle(btn, "position: absolute;" + GetCSSSize (left, top, width, height) );  
  hParent.appendChild(btn);  
  return btn;
}

/** funkcja tworzy panel grupujacy kilka pól wraz z jego opisem
 * 
 * @param {DOMNode} hParent - węzeł będący rodzice tworzonego panelu  
 * @param {int} left - odległość w pixelach od lewej krawędzi hParent
 * @param {int} top - odległość w pixelach od górnej krawędzi hParent
 * @param {int} width - długość panelu w pixelach
 * @param {int} height - wysokość panelu w pixelach
 * @param {Object} text - tekstowy opis panelu
 * @return {DOMNode} - nowo stworzony div
 */
function CreateGroupPanel(hParent, left, top, width, height, text )
{
	//stwórz pudło zawierajace w sobie zarówno obramowanie jak i opis
	var pudlo = document.createElement("div"); 
	pudlo.name = 'GroupPanel_Kontener'; 	  
    SetElemStyle(pudlo,"position:absolute;" + GetCSSSize(left, top, width, height) );					   
	hParent.appendChild(pudlo);
	
	//stworz opis panelu
	var opis = document.createElement("div");
	opis.name = 'GroupPanel_Opis';
    opis.innerHTML = text;	
    SetElemStyle(opis,"position:absolute; left:7px; top:0px; padding: 0px 3px;" + 
					  " background-color: "+hParent.style.backgroundColor+";");       
    hParent.appendChild(opis);
	var opisHeight = getElemHeight(opis);
	hParent.removeChild(opis);	
	
	//stwórz obramowanie
	var elem = document.createElement("div");  
	elem.name = 'GroupPanel_Panel';	  
    SetElemStyle(elem,"position:absolute; border:solid black 1px; " + 
					   GetCSSSize(0, (opisHeight/2), width, height - (opisHeight/2)) );					   
	pudlo.appendChild(elem);
	pudlo.appendChild(opis);	 
    hParent.appendChild(pudlo);  	
	return pudlo;
	
}

/** funkcja zwraca całą sekcję head strony
 * 
 * @param {DOMNode} parent - uchyt rodzica na ktorym wyswietlona będzie pozycja
 * @param {int} sep - separator pozycji wyrażony w px
 * @param {Object} top - odstęp w pikselach sekcji head od górnegop marginesu pozycji hParent
 * @param {Object} elemWidth - długość elementów wyrażona w pikselacha
 * @param {Object} elemHeight - szerokość elementów wyrażona w pikselacha
 * @return {DOMNode} - funkcja zwraca ostatni stworzony element w obrebie sekcji head
 */ 
function CreateHeadSection(parent, sep, top, elemWidth, elemHeight)
{
	var elem;	
	elem = CreateInputField(parent, sep, top, elemWidth, elemHeight, "title", "[Meta] Tytuł Strony :");
	elem = CreateInputField(parent, sep, getElemBottom(elem) + sep, elemWidth, elemHeight, "description", "[Meta] Opis Strony :");
	elem = CreateInputField(parent, sep, getElemBottom(elem) + sep, elemWidth, elemHeight, "klucze", "[Meta] Słowa kluczowe :");
	elem = CreateInputField(parent, sep, getElemBottom(elem) + sep, elemWidth, elemHeight, "adminMail", "[Meta] Adres e-mail administratora :");
	return elem;		
}

/** funkcja tworzy pole input zawierające opis oraz właściwep ole
 * 
 * @param {DOMNode} hParent - węzeł będący rodzice tworzonego panelu  
 * @param {int} left - odległość w pixelach od lewej krawędzi hParent
 * @param {int} top - odległość w pixelach od górnej krawędzi hParent
 * @param {int} width - długość panelu w pixelach
 * @param {int} height - wysokość panelu w pixelach
 * @param {String} id - identyfikator pola Select
 * @param {String} opis - tekstowy opis panelu
 * @param {bool} multiselect - flag określająca czy pole typu multiselect czy nie
 * @return {Object} - obiekt klasy SelectList Składający się z dwóch pól Kontener oraz Lista. Pierwszy jest uchwytem do DIVA
 * 					
 */
function CreateSelectList(hDlg, left, top, width, height, id, opis, multiselect)
{
	var sep = 3;
	var opisDiv = document.createElement('div');	
	opisDiv.innerHTML = opis;  
    SetElemStyle(opisDiv, "position:absolute; left:0px; top:0px;");
    hDlg.appendChild(opisDiv);       
    
	var myselect = null;	
	if ( isIE() )
	{
		if (multiselect == true)
			myselect = document.createElement('<select name="' + id + '[]" multiple><\/select>');
		else
			myselect = document.createElement('<select name="' + id + '"><\/select>');
			
		myselect.id = id;
		SetElemStyle(myselect,"position: absolute; left:0px; top:" + (opisDiv.clientHeight + sep) + 
							  "px; width:" + width + "px; height:" + height + "px;");
		myselect.multiple = multiselect;	
	}
	else
	{		
		myselect = document.createElement("select");
		if (multiselect == true)
			myselect.setAttribute("name",id+"[]");
		else
			myselect.setAttribute("name",id);			
		myselect.setAttribute("id",id);
		myselect.setAttribute("style","position: absolute; left:0px; top:" + (opisDiv.clientHeight + sep) +  
							  "px; width:" + width + "px; height:" + height + "px;");							  
		if (multiselect == true)		
			myselect.setAttribute("multiple","multiple");
	}
	hDlg.appendChild(myselect);
	
	var pudlo = document.createElement('div');	
    SetElemStyle(pudlo, "position:absolute;" + 
						 GetCSSSize(left,top,width,getElemHeight(opisDiv) + sep + getElemHeight(myselect)));
    hDlg.removeChild(opisDiv);
	hDlg.removeChild(myselect);
	pudlo.appendChild(opisDiv);
	pudlo.appendChild(myselect);
	hDlg.appendChild(pudlo);  
	
		
	var Lista = new SelectList();
	Lista.Kontener = pudlo;
	Lista.Lista = myselect;
	return Lista;
}

function CreateImg(hParent, left, top, width, height, id,  path)
{
	var img = document.createElement("img");
  	img.id = id;
	img.type='image';
	img.value=path;
	img.src= path;  	  
  	SetElemStyle(img, "position: absolute; cursor:pointer; " + GetCSSSize (left, top, width, height) );  
  	hParent.appendChild(img);  
  	return img;
}

function CreateDiv(hParent, left, top, width, height, id)
{
	var img = document.createElement("div");
  	img.id = id;
		  	 
	SetElemStyle(img, "position: absolute; " + GetCSSSize (left, top, width, height) );
  	hParent.appendChild(img);  
  	return img;
}







/**
 * funkcja sprawdza czy przekazny parametr jest unikalny w obrębie dokumentu
 * 
 * @param id - string - identyfikator do sprawdzenia lub null jesli nie chcemy sprawdzać
 * @param typ_elem - opis jakiego typu element był tworzony
 * @return - true jesli id jest unikalne w obrębie dokumentu false w przeciwnym wypadku
 */
function checkID(id, typ_elem)
{
	if (id == null)
		return true;
	
	var elem = document.getElementById(id);
	if (elem != undefined)
	{
		alert('Zduplikowany unkalny identyfikator - "'+id+'". Tworzenie ' + typ_elem + ' nie będzie kontynuowane. Skontaktuj się z autorem oprogramowania.');
		return false;
	} 
	
	return true;
}

/**
 * Funkcja tworzenia  formularza
 * 
 * @param hParent
 * @param id - identyfikator formularza
 * @param action - akcja wywoływana przy wysyłaniu formularza
 * @param method - wybóir metody wysyłania danych POST lub GET
 * @param enctype - typ kodownaia danych
 * @return nowo-stworzony formularz lub false w przypadku niepowodzenia
 */
function CreateForm(hParent, id, action, method, enctype )
{
	if (checkID(id,'formularza') == false)
		return false;
	
	elem = document.createElement("form");
	if (elem == undefined)
	{
		alert('Nie udalo się stworzyć formularza - "'+id+'". Skontaktuj się z autorem oprogramowania.');
		return false;
	}
	
	elem.action= action;
	elem.method = method;
	id != null ? elem.id = id : false;
	elem.enctype = enctype;
	
	hParent.appendChild(elem);	
	return elem;		
}

/**
 * funkcja tworząca element typu TABLE
 
 * @param hParent - DOMObject - rodzic Tworzonej tabeli
 * @param id - string - identyfikator tabeli jesli null tabela nie będzie miała identyfikatora
 * @param style - string -  style wyświetlania tablei
 * @param showBorder - bool - znacznik ustalający czy wyświetlić granice tabeli
 * @return nowo-stworzona tabela lub false w przypadku niepowodzenia
 */
function CreateTable(hParent, id, style, showBorder)
{	
	if (checkID(id,'tabeli') == false)
		return false;
	
	elem = document.createElement("table");
	if (elem == undefined)
	{		
		alert('Nie udalo się stworzyć tabeli - "'+id+'". Skontaktuj się z autorem oprogramowania.');
		return false;
	}
	
	SetElemStyle(elem,style);
	id != null ? elem.id = id : false;
	showBorder == true ? elem.border = "1" : elem.border = "0";
	
	hParent.appendChild(elem);	
	return elem;		
}

/**
 * funkcja tworzenia komórki tabeli <td> </td> 
 * @param hParent - DOMObject table - rodzicdla którego tworzona jest komórka  
 * @param id - string - identyfikator komórki
 * @param createRow - znacznik określający czy obudowac tworzoną komórke wierszem <tr></tr>
 * @return - stworzona komórka lub false w przypadku niepowodzenia
 */
function CreateTableCol(hParent,id,createRow)
{
	var td, tr = null;
	//sprawdź czy rodzic ma odpowiedni typ do utworzenia tabali	
	if (createRow == true && hParent.localName != 'TABLE')
	{
		alert('Próba utworzenia komórki tabeli w obrębie rodzica nie będącego tabelą. Tworzenie komórki nie będzie kontynuowane. Skontaktuj się z autorem oprogramowania');
		return false;
	}	
	if (createRow == false && hParent.localName != 'TR')
	{
		alert('Próba utworzenia komórki tabeli w obrębie rodzica nie będącego wierszem tabeli. Tworzenie komórki nie będzie kontynuowane. Skontaktuj się z autorem oprogramowania');
		return false;
	}
	
	//sprawdź unikalność identyfikatora komórki
	if (checkID(id,'komórki tabeli') == false)
		return false;
	
	
	if (createRow == true)	
		tr = document.createElement('TR');		 
	
	td = document.createElement('TD');
	id != null ? td.id = id : false;
	
	if (createRow == true)
	{
		tr.appendChild(td);
		hParent.appendChild(tr);
	}
	else
	{
		hParent.appendChild(td);
	}
	
	return td;	
}

function CreateTableRow(hParent, id, style)
{
	var tr = null;
	//sprawdź czy rodzic ma odpowiedni typ do utworzenia tabali	
	if (hParent.localName != 'TABLE')
	{
		alert('Próba utworzenia komórki tabeli w obrębie rodzica nie będącego tabelą. Tworzenie komórki nie będzie kontynuowane. Skontaktuj się z autorem oprogramowania');
		return false;
	}
	
	
	//sprawdź unikalność identyfikatora komórki
	if (checkID(id,'wiersza tabeli') == false)
		return false;
	
	tr = document.createElement('TR');		 
	id != null ? tr.id = id : false;
		
	hParent.appendChild(tr);	
	return tr;	
} 

/**
 * funkcja tworzy pole wyboru pliku do uploadu
 * 
 * @param hParent - DOMObject - rodzic dla tworzonego elementu
 * @param id - string - identyfikator tworzonego elemntu
 * @param size - int - rozmiar pola w znakach
 * @param style - styl przypisany do elementu
 * @return
 */ 
function CreateInputFileField(hParent, id, size, style)
{
	//sprawdź unikalność identyfikatora komórki
	if (checkID(id,'pola wyboru pliku') == false)
		return false;
	
	var elem  = document.createElement('input');
	if (elem == undefined)
	{
		alert('Nie udalo się stworzyć pola wyboru pliku - "'+id+'". Skontaktuj się z autorem oprogramowania.');
		return false;
	}
	
	style != '' ? SetElemStyle(elem,style) : false;
	id != null ? elem.id = id : false;
	elem.size = size;
	elem.type = "file";
	
	hParent.appendChild(elem);
	return elem;
}
 
function CreatePlainText(hParent,text,style)
{
	var elem = document.createElement('div');
	elem.appendChild(document.createTextNode(text));
	
	style != "" ? SetElemStyle(elem,style) : false;
	
	hParent.appendChild(elem);
	return elem;
	
}

function CreateSelList(hParent,id,name,multiselect,style)
{
	//sprawdź unikalność identyfikatora komórki
	if (checkID(id,'listy wyboru') == false)
		return false;
	
	var elem  = document.createElement('select');
	if (elem == undefined)
	{
		alert('Nie udalo się stworzyć listy wyboru - "'+id+'". Skontaktuj się z autorem oprogramowania.');
		return false;
	}
	
	elem.name = name;
	style != "" ? SetElemStyle(elem,style) : false;
	id != null ? elem.id = id : false;
	
	hParent.appendChild(elem);
	return elem;
}

function CreateSelListOption(hParent, opis, select)
{
	var elem = document.createElement('option');
	if (elem == undefined)
	{
		alert('Nie udalo się stworzyć opcji dla listy wyboru - "'+id+'". Skontaktuj się z autorem oprogramowania.');
		return false;
	}
		
	var pom = document.createTextNode(opis);
	elem.appendChild(pom);
	elem.value = opis;
	if (isIE())
		elem.selected = select;
	else if (select == true)
		elem.setAttribute('selected',true);
	
	hParent.appendChild(elem);		
	return elem;
}

function CreateEditField(hParent, id, name, value, style)
{
	//sprawdź unikalność identyfikatora komórki
	if (checkID(id,'pola edycyjnego') == false)
		return false;
	
	var elem  = document.createElement('input');
	if (elem == undefined)
	{
		alert('Nie udalo się stworzyć listy wyboru - "'+id+'". Skontaktuj się z autorem oprogramowania.');
		return false;
	}
	
	
	elem.type='text';
	elem.value = value;
	elem.name = name;
	style != "" ? SetElemStyle(elem,style) : false;
	id != null ? elem.id = id : false;
	
	hParent.appendChild(elem);
	return elem;	
}

function CreateDivField(hParent, id, style)
{
	//sprawdź unikalność identyfikatora komórki
	if (checkID(id,'elementu div') == false)
		return false;
	
	var elem  = document.createElement('div');
	if (elem == undefined)
	{
		alert('Nie udalo się stworzyć elemntu div - "'+id+'". Skontaktuj się z autorem oprogramowania.');
		return false;
	}
	
	style != "" ? SetElemStyle(elem,style) : null;
	id != null ? elem.id = id : null;
	
	hParent.appendChild(elem);
	return elem;
}












function CreateInput(typ, hParent, id, nazwa, wartosc, style)
{
	//sprawdź unikalność identyfikatora komórki
	if (checkID(id,'elementu div') == false)
		return false;
		
	var elem  = document.createElement('input');
	if (elem == undefined)
	{
		alert('Nie udalo się stworzyć elemntu input '+typ+' o identyfikatorze "'+id+'". Skontaktuj się z autorem oprogramowania.');
		return false;
	}
		
	elem.type = typ;
	style   != null ? SetElemStyle(elem,style) 	: null;
	nazwa   != null ? elem.name = nazwa 		: null;	
	id      != null ? elem.id = id 				: null;
	wartosc != null ? elem.value = wartosc 		: null; 	
	
	hParent.appendChild(elem);
	return elem;
	
}


function CreateElem(typ, hParent, id, nazwa, wartosc, style)
{
	//sprawdź unikalność identyfikatora komórki
	if (checkID(id,'elementu div') == false)
		return false;
		
	var elem  = document.createElement(typ);
	if (elem == undefined)
	{
		alert('Nie udalo się stworzyć elemntu '+typ+' o identyfikatorze "'+id+'". Skontaktuj się z autorem oprogramowania.');
		return false;
	}
		
	style   != null ? SetElemStyle(elem,style) 	: null;
	nazwa   != null ? elem.name = nazwa 		: null;	
	id      != null ? elem.id = id 				: null;
	wartosc != null ? elem.innerHTML = wartosc 	: null; 	
	
	hParent.appendChild(elem);
	return elem;
	
}









//deklaracja obiektu Select List zawierajace dwa pola: Kontener (uchwyt na diva obejmującego listę i opis)
//oraz Lista uchwyt na Liste Select 
function SelectList()
{	
  this.Kontener = null;
  this.Lista = null;    
}





function CreateTabCtrlPage(hParent, opis, size)
{
	//stwórz górny przycisk TabCtrl
	var button = document.createElement('div');		
	PageCount == 0 ? button.className += 'przycisk select' : button.className += 'przycisk normal';	
	button.name = 'page' + PageCount;	
	button.id = 'page_button' + PageCount; 		
	button.innerHTML = opis;
	
		
	
	
	var pomLeft = size['left'];
	if (PageCount > 0) 
	{		
		var prev = document.getElementById('page_button' + (PageCount-1));
		pomLeft += parseInt(prev.style.left) + prev.clientWidth;		
	}
		
	var style = 'z-index:2; position: absolute;' + 'left:' + pomLeft +'px; top:' + size['top'] + 'px;';
	SetElemStyle(button, style);
	
	
	hParent.appendChild(button);
	
	//stwórz panel strony
	var pomTop = size['top'] + button.clientHeight + 1;	
	var page = document.createElement('div');			
	var style = 'z-index:1; position: absolute; border: solid black 1px; background-color:#D4D0C8; ' + 'left:' + size['left'] + 
				'px; top:'+ pomTop +'px; width:' + size['width'] +'px; height:' + size['height'] +'px; ';
				 	
	page.className = 'page';
	page.id = page.name = 'page' + PageCount;	 
	SetElemStyle(page, style);
	hParent.appendChild(page);
	
	
	button.onclick = function() {return ShowPage(this.name); }
	 	
	//zwiększ licznik stron dla kolejnej 
	PageCount++;
    
    return page;
}





function getChildByName(parent, wzor)
{	
	if (parent.name == wzor) 		
		return parent;			
		 	
	for (var i = 0; i < parent.childNodes.length; i++) 
	{
		res = getChildByName(parent.childNodes[i], wzor);
		if (res != undefined)
			return res;			
	}		
	return undefined;	
}


//----------------------------------------------------------------------------------
//
//	Deklaracje Dialogów
//
//----------------------------------------------------------------------------------
function CreateMetaDataDialog(hDlg)
{
	var sep = 8;
	var height = 18;	//szerokość poszczególnych inputów
	//szerokość poszczególnych inputów - 4 dla odjęcia obramowań inputa
	var width = getElemWidth(hDlg) - (2*sep) - 4; 	
	var elem;
	
	var parent = document.getElementById("formID");
	if (parent == null)
		parent = hDlg;
			 			
	CreateHideField(parent,'headID');	
	CreateHeadSection(parent, sep, 35, width, height);		
}

function CreateSettingsDialog(hDlg, typ)
{
	
	var parent = document.getElementById("formID");
	if (parent == null)
		parent = hDlg;
			 		
	CreateHideField(parent,"id");
	
	
	if (typ == 'artykul') 
	{
		var sep = 10;
		//długość groupBoxów dla panelu -2 na końcu dla pominięcia obramowania groupboxa		
		var pageWidth = getElemWidth(parent) - (2*sep) - 2;
		//dł elementów wyświetlanych w groupBox-ach -4 na końcu dla pominięcia obramowania inputów
		var elemWidth = pageWidth - (2*sep) - 4;
		//szerokosc elementów 
		var elemHeight = 20;
		//szerokosc strony TabCtrl
		var pageHeight = 335;
		//rozmiary pozycji tabCtrl
		var size = GetSize(sep, 35, pageWidth, pageHeight);
		
		page1 = CreateTabCtrlPage(parent,"Ogólne", size); 		
			elem = CreateInputField(page1, sep, sep, elemWidth, elemHeight, "nazwa", "Nazwa strony:");
			//elem = CreateSelectList(page1, sep, getElemBottom(elem) + sep, elemWidth, elemHeight, "Pozycja", "Wstaw za:", false);
			//SelectList_AddOption(elem.Lista, "Wstaw na początek");		
			elem = CreateCheckBox(page1, sep, getElemBottom(elem) + sep, elemWidth, elemHeight, "PrintMainMenu", "Drukuj pozycję w głównym menu serwisu", false);
			elem = CreateCheckBox(page1, sep, getElemBottom(elem) + sep, elemWidth, elemHeight, "PrintSubMenu",  "Drukuj pozycję w bocznym menu serwisu", false);
		  
		page2 = CreateTabCtrlPage(parent,"Sekcja head", size);
			CreateHeadSection(page2, sep, sep, elemWidth, elemHeight);
			
		ShowPage(page1.name);
	}
	
	if (typ == 'news') 
	{
		var page1, page2, page3, page4, elem, elemPom, grp1, grp2, grp3;
		
		var sep = 10;
		//długość groupBoxów dla panelu -2 na końcu dla pominięcia obramowania groupboxa		
		var pageWidth = getElemWidth(parent) - (2*sep) - 2;
		//dł elementów wyświetlanych w groupBox-ach -4 na końcu dla pominięcia obramowania inputów
		var elemWidth = pageWidth - (2*sep) - 4;
		//szerokosc elementów 
		var elemHeight = 20;
		//szerokosc strony TabCtrl
		var pageHeight = 335;
		//rozmiary pozycji tabCtrl
		var size = GetSize(sep, 35, pageWidth, pageHeight);
		
		page1 = CreateTabCtrlPage(parent,"Ogólne", size);
		  elem = CreateInputField(page1, sep, sep, elemWidth, elemHeight, "nazwa", "Nazwa :");
		  //elem = CreateSelectList(page1, sep, getElemBottom(elem) + sep, elemWidth, elemHeight, "Pozycja", "Wstaw za:", false);
		  //SelectList_AddOption(elem.Lista, "Wstaw na początek");
		  elem = CreateInputField(page1, sep, getElemBottom(elem) + sep, 130, elemHeight, "IleWyswietlic", "Ile pozycji wyświetlić :");
		  elemPom = CreateInputField(page1, getElemRight(elem) + sep + 4, getElemTop(elem), 130, elemHeight, "IleNaStronie", "Ile pozycji na stronie :");
		  elem = CreateSelectList(page1, getElemRight(elemPom) + sep + 4, getElemTop(elemPom), 130, elemHeight, "SortKlucz", "Sortuj wg:", false);
		  SelectList_AddOption(elem.Lista, "Daty dodania");
		  SelectList_AddOption(elem.Lista, "Hierarchi w panelu");
		  SelectList_AddOption(elem.Lista, "Nazwy");
		  elem = CreateSelectList(page1, getElemRight(elem.Kontener) + sep + 4, getElemTop(elem.Kontener), 130, elemHeight, "SortKierunek", "Sortuj:", false);
		  SelectList_AddOption(elem.Lista, "Rosnąco");
		  SelectList_AddOption(elem.Lista, "Malejąco");
		  SelectList_AddOption(elem.Lista, "Losowo");
		  //elem = CreateSelectList(page1, sep, getElemBottom(elemPom) + sep, elemWidth, elemHeight, "Skrot", "Tworzenie skrótów:", false);
		  //SelectList_AddOption(elem.Lista, "Ręcznie");
		  //SelectList_AddOption(elem.Lista, "Pierwsze zdanie tekstu długiego");
		  //SelectList_AddOption(elem.Lista, "Dwa pierwsze zdania tekstu długiego");	  
		  //SelectList_AddOption(elem.Lista, "Trzy pierwsze zdania tekstu długiego");		
		  elem = CreateCheckBox(page1, sep, getElemBottom(elem.Kontener) + sep, elemWidth, elemHeight, "LinkTyt",   "Tytuł newsa jako link do strony", false);		
 		  elem = CreateCheckBox(page1, sep, getElemBottom(elem) + sep, elemWidth, elemHeight, "LinkTresc", "Treść newsa jako link do strony", false);
		  elem = CreateCheckBox(page1, sep, getElemBottom(elem) + sep, elemWidth, elemHeight, "wiecej", "Drukuj na końcu frazę więcej", false);
		  elem = CreateCheckBox(page1, sep, getElemBottom(elem) + sep, elemWidth, elemHeight, "PrintMainMenu", "Drukuj pozycję w głównym menu serwisu", false);
		  elem = CreateCheckBox(page1, sep, getElemBottom(elem) + sep, elemWidth, elemHeight, "PrintSubMenu",   "Drukuj pozycję w bocznym menu serwisu", true);		  
		  
		/*var page2 = CreateTabCtrlPage(parent,"Wyświetlanie", size );
		  CreateTrybWyswietlaniaPanel (page2, 5, 5,    550, 100, "news_tryb1_1");
		  CreateTrybWyswietlaniaPanel (page2, 5, 110,  550, 100, "news_tryb1_2");
		  CreateTrybWyswietlaniaPanel (page2, 5, 215,  550, 100, "news_tryb1_3");
		  CreateTrybWyswietlaniaPanel (page2, 5, 320,  550, 100, "news_tryb1_4");		  
		  CreateTrybWyswietlaniaPanel (page2, 5, 425,  550, 100, "news_tryb1_5");
		  CreateTrybWyswietlaniaPanel (page2, 5, 530,  550, 100, "news_tryb2_1");
		  CreateTrybWyswietlaniaPanel (page2, 5, 635,  550, 100, "news_tryb2_2");
		  CreateTrybWyswietlaniaPanel (page2, 5, 740,  550, 100, "news_tryb2_3");		  
		  CreateTrybWyswietlaniaPanel (page2, 5, 845,  550, 100, "news_tryb2_4");
		  CreateTrybWyswietlaniaPanel (page2, 5, 950,  550, 100, "news_tryb3_1");
		  CreateTrybWyswietlaniaPanel (page2, 5, 1055, 550, 100, "news_tryb3_2");
		  CreateTrybWyswietlaniaPanel (page2, 5, 1160, 550, 100, "news_tryb4_1");		  
		  CreateTrybWyswietlaniaPanel (page2, 5, 1265, 550, 100, "news_tryb4_2");
		  CreateTrybWyswietlaniaPanel (page2, 5, 1370, 550, 100, "news_tryb4_3");*/
		
		page3 = CreateTabCtrlPage(parent,"Sekcja head", size );
		  CreateHeadSection(page3,sep,sep,elemWidth,elemHeight);
		  		  	  		 
		  
		  
		/*var page4 = CreateTabCtrlPage(parent,"Zaawansowane", size );		  
		  var panelHeight = 70;		  	  		
		  grp1 = CreateGroupPanel(page4, sep, sep, elemWidth, panelHeight, "Tytuł");
		  elem = CreateInputField(grp1, sep, 2*sep, 120, elemHeight, "news_tytul_fontsize", "Rozmiar czcionki [px] :");
		  elem = CreateInputField(grp1, getElemRight(elem) + sep + 4, getElemTop(elem), 120, elemHeight, "news_tytul_margin_top", "Margines górny [px] :");
		  elem = CreateInputField(grp1, getElemRight(elem) + sep + 4, getElemTop(elem), 120, elemHeight, "news_tytul_margin_bottom", "Margines dolny [px] :");
		  elem = CreateInputField(grp1, getElemRight(elem) + sep + 4, getElemTop(elem), 120, elemHeight, "news_tytul_color", "Kolor czcionki [hex] :");
		  grp2 = CreateGroupPanel(page4, sep, getElemBottom(grp1) + sep, elemWidth, panelHeight, "Data dodania");		 
		  elem = CreateInputField(grp2, sep, 2*sep, 120, elemHeight, "data_tytul_fontsize", "Rozmiar czcionki [px] :");
		  elem = CreateInputField(grp2, getElemRight(elem) + sep + 4, getElemTop(elem), 120, elemHeight, "data_tytul_margin_top", "Margines górny [px] :");
		  elem = CreateInputField(grp2, getElemRight(elem) + sep + 4, getElemTop(elem), 120, elemHeight, "data_tytul_margin_bottom", "Margines dolny [px] :");
		  elem = CreateInputField(grp2, getElemRight(elem) + sep + 4, getElemTop(elem), 120, elemHeight, "data_tytul_color", "Kolor czcionki [hex] :");
		  
		  
		  grp3 = CreateGroupPanel(page4, sep, getElemBottom(grp2) + sep, elemWidth, panelHeight, "Treść");		  
		  elem = CreateInputField(grp3, sep, 2*sep, 120, elemHeight, "tresc_tytul_fontsize", "Rozmiar czcionki [px] :");
		  elem = CreateInputField(grp3, getElemRight(elem) + sep + 4, getElemTop(elem), 120, elemHeight, "tresc_tytul_margin_top", "Margines górny [px] :");
		  elem = CreateInputField(grp3, getElemRight(elem) + sep + 4, getElemTop(elem), 120, elemHeight, "tresc_tytul_margin_bottom", "Margines dolny [px] :");
		  elem = CreateInputField(grp3, getElemRight(elem) + sep + 4, getElemTop(elem), 120, elemHeight, "tresc_tytul_color", "Kolor czcionki [hex] :");
		  */
		  
		  
		  ShowPage(page1.name);
		
		
			
	}
	
	
	if (typ == 'katalog')
	{
		var page1, page2,elem, elemPom, grp1, grp2, grp3;
		
		var sep = 10;
		//długość groupBoxów dla panelu -2 na końcu dla pominięcia obramowania groupboxa		
		var pageWidth = getElemWidth(parent) - (2*sep) - 2;
		//dł elementów wyświetlanych w groupBox-ach -4 na końcu dla pominięcia obramowania inputów
		var elemWidth = pageWidth - (2*sep) - 4;
		//szerokosc elementów 
		var elemHeight = 18;
		//szerokosc strony TabCtrl
		var pageHeight = 350;
		//rozmiary pozycji tabCtrl
		var size = GetSize(sep, 35, pageWidth, pageHeight);
		
		page1 = CreateTabCtrlPage(parent,"Ogólne", size);
		
		elem = CreateInputField(page1, sep, sep, elemWidth, elemHeight, "nazwa", "Nazwa :");		
		elem = CreateCheckBox(page1, sep, getElemBottom(elem) + sep, elemWidth, elemHeight, "PrintMainMenu", "Drukuj pozycję w głównym menu serwisu", false);
		elem = CreateCheckBox(page1, sep, getElemBottom(elem) + sep, elemWidth, elemHeight, "PrintSubMenu",   "Drukuj pozycję w bocznym menu serwisu", true);
		
		ShowPage(page1.name);  
	}
	
	
	if (typ == 'news_pozycja')
	{
		var page1, page2,elem, elemPom, grp1, grp2, grp3;
		
		var sep = 10;
		//długość groupBoxów dla panelu -2 na końcu dla pominięcia obramowania groupboxa		
		var pageWidth = getElemWidth(parent) - (2*sep) - 2;
		//dł elementów wyświetlanych w groupBox-ach -4 na końcu dla pominięcia obramowania inputów
		var elemWidth = pageWidth - (2*sep) - 4;
		//szerokosc elementów 
		var elemHeight = 18;
		//szerokosc strony TabCtrl
		var pageHeight = 350;
		//rozmiary pozycji tabCtrl
		var size = GetSize(sep, 35, pageWidth, pageHeight);
		
		page1 = CreateTabCtrlPage(parent,"Ogólne", size);
		  elem = CreateInputField(page1, sep, sep, elemWidth, elemHeight, "nazwa", "Nazwa :");		  
		  elem = CreateSelectList(page1, sep, getElemBottom(elem) + sep, elemWidth, elemHeight+2, "kategoria", "Kategoria :", false);
		  SelectList_AddOption(elem.Lista, "");
		  SelectList_AddOption(elem.Lista, "Kariera");
		  SelectList_AddOption(elem.Lista, "Firma");		 
		
		page2 = CreateTabCtrlPage(parent,"Sekcja head", size );
		  CreateHeadSection(page2,sep,sep,elemWidth,elemHeight);
		  		  	  		 
		
		ShowPage(page1.name);		  
	}
	
	
	var ok = document.getElementById('BTN_OK');
	ok.onclick = function()
	{
		document.getElementById('formID').submit();
	};
		
}



















//----------------------------------------------------------------------------------
//
//	Funkcje obslugujace dialog
//
//----------------------------------------------------------------------------------
 
 var hDlg = false; 
 var CheckCount = 0;
 var RadioCount = 0;
 var PageCount = 0;  		
 //domyślny kolor tła dla dialogu
 var DlgBkColor = '#FBF6BD';  

//funkcja usuwa DIV-a przekazanego przez zmienna globlana hDlg
function CloseDialog()
{	
	hDlg.parentNode.removeChild(hDlg);
	hDlg = false;	
	//wyzeruj liczniki pozycji dialogu
	CheckCount = RadioCount = PageCount = 0;
	
	if (Shadow != false)
	{
		Shadow.parentNode.removeChild(Shadow);
		Shadow = null;
	}
	
		
}

//funkcja znajduje wśród wszystkich dzieci dialogu pierwszy element o nazwie name lub null jesli go nie ma
function GetFirstDlgItemByName(hDlg, name)
{
	var res = null;
	
	if (hDlg.name == name)
		return hDlg;
	else if (hDlg.childNodes.length != 0)
	{
		for (var i = 0; i<hDlg.childNodes.length; i++)
		{
			res = GetFirstDlgItemByName(hDlg.childNodes[i],name);
			if (res != null)
				break;			
		}						 
		return res;
	}
}


function SetDlgItemAction(id, akcja, funkcja )
{	
	var control = document.getElementById(id);
	if (control != false)
	{
		if (akcja == 'onclick')				
			control.onclick = funkcja;		
		else if (akcja == 'ondblclick')
			control.ondblclick = funkcja;
		else 
			alert("Akcja '" + akcja + "' nie jest zdefiniowana w programie. Skontaktuj się z autorem oprogramowania");
	}
}
























function getPos(obj)
{	
	var lft = obj.offsetLeft;
	var top = obj.offsetTop;
	while(obj.offsetParent!=null)
	{
		var par = obj.offsetParent;
		lft += par.offsetLeft;
		top += par.offsetTop;
		obj = par;
	}
	return [lft,top];
}




function PrintStructure ( obj, poziom )
{
	wynik = "";		
	if (obj.name != undefined || obj.type != undefined || obj.value != undefined) 
	{
		if (obj.name != 'InputText_Opis' && obj.name != 'InputText_Kontener')
			wynik = poziom + obj.name + "[" + obj.type + "]" + " -> " + obj.value + '\n';
	}
	if (obj.childNodes.length > 0) 
	{		
		for (var i = 0; i < obj.childNodes.length; i++) 
		{
			wynik += PrintStructure(obj.childNodes[i], poziom + "|    ");
		}
	}
	
	return wynik;			
}


function getFormatedData()
{
	var d=new Date();
	(d.getMonth() + 1) > 9 ? mies = (d.getMonth() + 1) : mies = "0" + (d.getMonth() + 1);
	(d.getDate() + 1) > 9 ? dzien = d.getDate() : dzien = "0" + d.getDate();
	
	d.getHours() > 9 ? godzina = d.getHours() : godzina = "0" + d.getHours();
	d.getMinutes() > 9 ? minuta = d.getMinutes() : minuta = "0" + d.getMinutes(); 
	d.getSeconds() > 9 ? sekunda = d.getSeconds() : sekunda = "0" + d.getSeconds();
	
	
	
	return  '' + d.getFullYear() + '-' + mies + '-' + dzien + ' ' + godzina + ':' + minuta + ':' + sekunda;
}



var Shadow = null;
function CreateDialogEx ( hParent, nazwa, size, inputParam, extraParam )
{
	//jeśli rodzic == null utwórz obiekt wyszarzenia 
	if (hParent == null)
		CreateShadow();
	
	
	
	if (inputParam != '') 		
		inputParam = unserialize(base64_decode(inputParam));	
	
	if (extraParam != '') 	
		extraParam = unserialize(base64_decode(extraParam));		
	
	
	
		
	//opcja dla dialogu loader	
	/*var load = document.getElementById('loader');
	load.style.display = 'block' ;
	load.style.position = "absolute";	
	load.style.left = (document.body.clientWidth / 2) - 50 + "px";		
	load.style.top = (document.documentElement||document.body).scrollTop +
	                 ((document.documentElement||document.body).clientHeight / 2)
	                  - load.clientHeight + "px";
	 return;*/
	
	var dlgOpis; 
	(extraParam != 0 && extraParam['opis'] != undefined) ? dlgOpis = extraParam['opis'] : dlgOpis = ""; 
		
	var formAction = null;
	if (extraParam != 0 && extraParam['formAction'] != undefined)
	 	formAction = extraParam['formAction'];
		
	
			
	hDlg = CreateDialog(null, 0, size, dlgOpis, formAction);
	 
	 
	 switch (nazwa)
	 {
	 	/*case "MetaDataDialog" :
	 		CreateMetaDataDialog(hDlg);									
	 		SetDlgItemValues(hDlg, inputParam);
	 		break;*/
			
		case "SettingsDlg" :			
			CreateSettingsDialog(hDlg,extraParam['typ']);			
			SetDlgItemValues(hDlg, inputParam);						
			break;
			
		case "Newsletter_v1" :
			var newsletter = new Newsletter(hDlg);
			newsletter.create(inputParam);
			break;
	 	
	 	default : 
	 		alert("niezdefiniowany Dialog '" + nazwa + "'"); 
	 		break;
	 } 	
}

//funkcja tworzy diva wyszarzxającego zcałą stronę uniemożliwiając kliknięcie 
//niczego co jest pod divem 
function CreateShadow()
{
	
	if (Shadow != null)
		document.body.appendChild(Shadow);	
			
	Shadow = document.createElement('div');
	Shadow.style.top = "0px";  		   		       		 
	Shadow.style.left = "0px";
	Shadow.style.opacity= '0.7';
	Shadow.style.filter="Alpha(Opacity=70)";
	Shadow.style.display = 'block';
	Shadow.style.position = "absolute";
	Shadow.style.backgroundColor= "black";
	
	
	
	Shadow.style.height = getElemHeight(document.getElementById('top')) + 'px';
	Shadow.style.width = document.body.clientWidth + 'px';		 		 	
	
	document.body.appendChild(Shadow);		
	return Shadow;
}

function CreateDialog(parent, id, size, opis, formAction) 
{
  if (hDlg != false)
  	 return hDlg;
	 
   
  
    
  //jeśli przeglądarka IE omiń problem pozycjinowania SELECTÓW ponad wszystkim innym
  if ( isIE() )
  {
  	var ie = document.createElement('iframe');
  	ie.id = "poprawka";
  	ie.frameborder = "none";	
  	SetElemStyle(ie,"display:block; position:absolute; z-index:-1; background-color:"+DlgBkColor+ 
					"width:"+size['width'] + "px; height: "+ size['height'] + "px; border:none;");
  	ie.style.backgroundColor = DlgBkColor;
  }
 
  var div = document.createElement('div');
  div.id = id;      
  if ( size['left'] == 'center')
  	 size['left'] = (document.body.clientWidth / 2) - (size['width'] / 2);
  if ( size['top'] == 'center')
  	 size['top'] = ((document.documentElement||document.body).clientHeight / 2) - size['height']/2;
					 
  if (size['width'] == 'max') 
  {
  	size['width'] = parseInt(document.body.clientWidth) - 6;
	size['left'] = 3;
	
  }
  if (size['height'] == 'max')   
  {
  	size['height'] = (document.documentElement || document.body).scrollTop +
  					 ((document.documentElement || document.body).clientHeight) - 2;
	size['top'] = 1;
  }
  size['left'] = parseInt(size['left']);  
  size['top'] = parseInt(size['top']);
  size['width'] = parseInt(size['width']);
  size['height'] = parseInt(size['height']);
  					
  
  SetElemStyle(div,"font-size:12px; position:fixed; top:" + size['top'] + "px; left:" + size['left'] + "px; width:"+
               size['width'] + "px; height: "+ size['height'] + "px; border: solid black 1px;" + 
			   " border-left: solid #0054e3 1px; border-right:  solid #0054e3 1px; border-bottom:  solid #0054e3 1px; "+
			   " border-top: none;");
  div.style.backgroundColor = DlgBkColor;
  
  if ( isIE() )
  	div.appendChild(ie);    
	
  if (formAction != null)
  {
  	 var form = document.createElement('form');
	 form.id = "formID";
	 form.name = "formID";
	 form.type = 'form';
	 form.method = "POST";
	 form.enctype = "multipart/form-data";
	 form.action = formAction;
	 form.style.backgroundColor = DlgBkColor;	 
	 div.appendChild(form); 
  } 
  
  //stworz belke panelu
  var belka = document.createElement('div');
  belka.className = 'belka';    
  SetElemStyle(belka,'position:absolute; width:' + size['width'] + 'px; height:25px; top:0px; margin-top:0px;');
  
  var divpom = document.createElement('div');
  SetElemStyle(divpom,"color:white; display:inline; float:left; text-align:left; height:23px; line-height: 23px; margin-left:3px; font-weight:bold; font-size:14px;");
  divpom.appendChild(document.createTextNode(opis));
  belka.appendChild(divpom);    
  div.appendChild(belka);	//dodaj belke do panelu
  
  
  
  
  if ( !isIE() && !isOpera() )
  {
  	//uczyn ja przesuwalna
  	//dragContainerInit(belka);
  }
  
  //stworz przycisk zamykajacy panel
  var item = document.createElement("img");
  item.src= "public/images/cms/exit.gif";  
  SetElemStyle(item,"width:20px; height:23px; display:inline; float:right; cursor:pointer;"); 
  item.onclick = CloseDialog; 
  
  belka.appendChild(item);	//dodaj belke do panelu
  
  //stworz, spozycjonuj i dodaj przycisk OK 
  var btn_ok = document.createElement("button");  
  SetElemStyle(btn_ok,"position: absolute; top: " + (size['height'] - 29) + "px; left: " + (size['width'] - 135) +"px; width:60px; height:22px;");
  btn_ok.setAttribute("id","BTN_OK");
  btn_ok.appendChild(document.createTextNode("OK"));
  div.appendChild(btn_ok);
   
  //stwórz, spozycjonuj i dodaj przycisk Cancel
  var btn_anuluj = document.createElement("button");
  SetElemStyle(btn_anuluj,"position: absolute; top: " + (size['height'] - 29) + "px; left: " + (size['width'] - 67) +"px; width:60px; height:22px;");
  btn_anuluj.setAttribute("id","BTN_CANCEL");
  btn_anuluj.appendChild(document.createTextNode("Anuluj"));
  btn_anuluj.onclick = CloseDialog;
  div.appendChild(btn_anuluj);
  
  if (parent != null)  
  	parent.appendChild( div );
  else
  	document.body.appendChild( div );  
  return div;
}



//----------------------------------------------------------------------------------
//
//	Pomocnicze funkcje ułatwiające operacje na dialogach
//
//----------------------------------------------------------------------------------
/** funkcja tworzy na podstawie czterech intów tablicę asocjacyjną postaci tab['left'] = left itd.
 * 
 * @param {int} left - wspołrzędna x lewego górnego rogu
 * @param {int} top - wspołrzędna y lewego górnego rogu
 * @param {int} width - długość pola
 * @param {int} height - szerokosc polo
 * @return {Object} - tablica asocjacyjna 
 */
function GetSize(left, top, width, height)
{
	var tab = { 'left' : left, 'top' : top, 'width' : width, 'height' : height };	
	return tab; 
}

/** funkcja zwraca długość elementu wyrażoną w pixelach
 * 
 * @param {DOMElem} elem  - elent którego długość chcemy poznać
 * @return {int} - długość elementu
 */
function getElemWidth(elem)
{
	return elem.offsetWidth || elem.style.pixelWidth;	
}

/** funkcja zwraca wyskość elementu wyrażoną w pixelach
 * 
 * @param {DOMElem} elem  - elent którego wysokość chcemy poznać
 * @return {int} - długość elementu
 */
function getElemHeight(elem)
{
	return elem.offsetHeight || elem.style.pixelHeight;	
}

function getElemLeft(elem)
{
	if (elem.style.left != undefined)
		return parseInt(elem.style.left);	
	return  elem.offsetLeft
}
function getElemRight(elem)
{			
	return getElemLeft(elem) + getElemWidth(elem)	
}

function getElemTop(elem)
{
	return  elem.offsetTop || elem.style.top;
}
function getElemBottom(elem)
{
	return  parseInt(elem.offsetTop || elem.style.top) + 
			parseInt(elem.offsetHeight || elem.style.pixelHeight);
}



//funckja na podstawie tablicy asocjacyjnej param, wyszukuje w dialogu hDlg elementy 
//o nazwach odpowiadających indeksom tablicy a następnie przypisuje im wartość będącą 
//wartością tablicy o danym indekcie.
function SetDlgItemValues(hDlg, param)
{	
	//jeśli nie przekazano wartosci żadnych pól formularza nic nie rób 
	if (param == 0)
		return true;
		
	var brak = "Nie znalazłem następujących pól formularza\n";
	
	for (klucz in param)             
    {
		
   		//znajdz element o nazwie klucz i wpisz dla niego wartosc dane[klucz]
   		//var elem = GetFirstDlgItemByName(hDlg, klucz);
   		//if (elem == null)	//jesli nie znalazłeś eleementu wprost poszukaj z [] w celu znlezienia pola selct
   			//elem = GetFirstDlgItemByName(hDlg, klucz+"[]");
		var elem = getChildByName(hDlg,klucz);
		if (elem == null)	//jesli nie znalazłeś eleementu wprost poszukaj z [] w celu znlezienia pola selct
			elem = getChildByName(hDlg, klucz+"[]");
   		
   		if (elem != undefined)
   		{ 
			
   			//zastosuj odpowiednią funkcę wpisująca w zależności od typu pola
   			if (elem.type == 'text' || elem.type == 'password' || elem.type == 'textarea' ||
			    elem.type == 'hidden') 
			{
				elem.value = param[klucz];
			}
			else if (elem.type == 'select-multiple') 
			{
				for (var i = 0; i < param[klucz].length; i++) 
					if (!SelectList_isOptionInsideList(elem, param[klucz][i])) 
						SelectList_AddOption(elem, param[klucz][i]);
			}
			else if (elem.type == 'select-one') 
			{				
				SelectList_SelectOption(elem, param[klucz]);
			}   
			else if (elem.type == 'checkbox')
			{
				elem.checked = true;
			}  			
   		}
   		else
   			brak += "\n" +klucz;   			  		   		     	
    }
    
    //jesli nie wszystkie elmeny zostały znalezione poinformuj o tym      
    //if (brak != "Nie znalazłem następujących pól formularza\n")    
    	//alert(brak);  
}




var OpisTrybu = 
{
	'news_tryb1_1' : 'Data dodania, tytuł, krótki opis.',
	'news_tryb1_2' : 'Tytuł, data dodania, krótki opis.',
	'news_tryb1_3' : 'Data dodania, tytuł',
	'news_tryb1_4' : 'Tytuł, data dodania.',
	'news_tryb1_5' : 'Tylko tytuł',
	'news_tryb2_1' : 'Data dodania, tytuł, obrazek.',
	'news_tryb2_2' : 'Tytuł, data dodania, obrazek.',
	'news_tryb2_3' : 'Tytuł, obrazek.',
	'news_tryb2_4' : 'Obrazek, tytuł.',
	'news_tryb3_1' : 'Obrazek, tytuł, krótki opis.',
	'news_tryb3_2' : 'Tytuł, obrazek, krótki opis.',
	'news_tryb4_1' : 'Obrazek, tytuł, krótki opis, pliki do pobrania.',
	'news_tryb4_2' : 'Tytuł, krótki opis, pliki do pobrania, obrazek.',
	'news_tryb4_3' : 'Tytuł, krótki opis, pliki do pobrania.'		
}

function CreateTrybWyswietlaniaPanel(hParent, left, top, width, height, value )
{
	var div = document.createElement("div");   
    SetElemStyle(div,"position:absolute; left:" + left + "px; top:" + top + "px; width:" + width + 
					 "px; height:" + height + "px; border-bottom:solid #c1c1c1 1px;");
	hParent.appendChild(div);
	
	CreateRadio(div, 2, 2, 15, 15, "tryb", value, "", false);
	
	var opis = document.createElement("div");
	opis.innerHTML = OpisTrybu[value];
	SetElemStyle(opis,"position:absolute; left:8px; top:20px; width:" + (width - 100) + 
					  "px; height:" + (height - 24) + "px;");
	div.appendChild(opis);
	
	//<img src="public/images/cms/news_tryb3_1.jpg" alt="" />
	var obrazek = document.createElement("img");
	obrazek.src = "public/images/cms/"+value+".jpg";
	SetElemStyle(obrazek,"position:absolute; left:" + (width - 99) +"px; top:10px; width:90px; height:60px;");
	div.appendChild(obrazek);
	
	
	
	return div;
}








function CreateHideField(hDlg, nazwa, wartosc)
{
	
	/*var elem = document.createElement('input');
	elem.type  = 'hidden';
	elem.name = nazwa;  	                 
	elem.value = wartosc;       	
    hDlg.appendChild(elem); 
	return elem;*/
	
	elem  = document.createElement('input');
	elem.name = nazwa;
	elem.type = 'hidden';
	elem.value = wartosc;
	elem.innerHTML = '<input type="hidden" name="' + name + '" value="'+wartosc+'" >';
	hDlg.appendChild(elem); 
	return elem;	
}


function GetCSSSize(left, top, width, height)
{
	return "left:" + left + "px; top:" + top + "px; " + 
		   "width:" + width + "px; height:" + height + "px; ";
}












function CreateRadio(hDlg, left, top, width, height, id, value, opis, checked )
{
  	var uniqID = "radio" + id + RadioCount;
	var Label = document.createElement("label");
	if (Label == null)
  		return;
 
  	var check;
  	checked == true ? check = 'checked="checked"' : check = '';
  	Label.innerHTML = "<input type='radio' name='"+id+"' id='" + uniqID + "' value='" + opis + "' " + check + " >";
  	Label.htmlFor = uniqID;
  	Label.appendChild(document.createTextNode(opis));  
  	SetElemStyle(Label,"position:absolute; left:" + left + "px; top:" + top + "px; width:" + width +
                       "px; height:" + height + "px;");  
  	hDlg.appendChild(Label);		
  	RadioCount++; 	  
	return Label;
 
}



function CreateCheckBox(hDlg, left, top, width, height, id, opis, checked)
{
	var uniqID = "check" + id + CheckCount;
	var Label = document.createElement("label");
	if (Label == null)
  		return;
   	
  	var check;
  	checked == true ? check = 'checked="checked"' : check = '';
  	Label.innerHTML = "<input type='checkbox' name='"+id+"' id='" + uniqID + "' value='" + opis + "' " + check + " >";
  	Label.htmlFor = uniqID;
  	Label.appendChild(document.createTextNode(opis));
  
  	SetElemStyle(Label,"position:absolute; left:" + left + "px; top:" + top + "px; width:" + width +
                       "px; height:" + height + "px;");  
  	hDlg.appendChild(Label);		
  	CheckCount++;   	  
	return Label;
}









 

 
