function add_image(id)
{
	global_image_id++;
	
	div1 = document.getElementById(id);
	
	table1 = document.createElement('table');
	table1.setAttribute("border","0");
	table1.setAttribute("id","table1_" + global_image_id);
	table1.setAttribute("name","table1_" + global_image_id);
	
	tbody = document.createElement('tbody');
	
	tr1 = document.createElement('tr');
	td1 = document.createElement('td');

	plik = document.createElement('input');
	plik.setAttribute("type","file");
	plik.setAttribute("name","image_" + global_image_id);
	plik.setAttribute("id","image_" + global_image_id);
	plik.setAttribute("size","50");


	td1.appendChild(plik);
	
	td2 = document.createElement('td');
	
	ahref = document.createElement('a');
	ahref.setAttribute("class","link_inny");
	ahref.setAttribute("className","link_inny");
	ahref.setAttribute("href","javascript:del_image('"+id+"', 'table1_"+global_image_id+"')");
	ahref.setAttribute("id","link1_"+global_image_id);
	ahref.setAttribute("name","link1_"+global_image_id);

	link = document.createTextNode(' Usuń');
	ahref.appendChild(link);

	td2.appendChild(ahref);

	tr1.appendChild(td1);
	tr1.appendChild(td2);

	tbody.appendChild(tr1);
	
	table1.appendChild(tbody);
	div1.appendChild(table1);
}

function del_image(id, node_name1, node_name2, node_name3)
{
	image = document.getElementById(id);
	
	image.removeChild(document.getElementById(node_name1));
}

function add_file(id)
{
	global_file_id++;
	
	var div1 = document.getElementById(id);
	
	var table1 = document.createElement('table');

	table1.setAttribute("border","0");
	table1.setAttribute("id","table2_" + global_file_id);

	var tbody = document.createElement('tbody');
	
	var tr1 = document.createElement('tr');
	var td1 = document.createElement('td');

	var plik = document.createElement('input');

	plik.setAttribute("type","file");

	plik.setAttribute("name","file_" + global_file_id);

	plik.setAttribute("id","file_" + global_file_id);

	plik.setAttribute("size","50");


	td1.appendChild(plik);
	
	var td2 = document.createElement('td');
	
	var ahref = document.createElement('a');


	ahref.setAttribute("class","link_inny");
	ahref.setAttribute("className","link_inny");

	ahref.setAttribute("href","javascript:del_file('"+id+"', 'table2_"+global_file_id+"')");

	ahref.setAttribute("id","link2_"+global_file_id);

	ahref.setAttribute("name","link2_"+global_file_id);

	var link = document.createTextNode(' Usuń');
	ahref.appendChild(link);
	
	var nazwa = document.createTextNode('Nazwa: ');
	var nazwa_input = document.createElement('input');
	nazwa_input.setAttribute("type","text");
	nazwa_input.setAttribute("name","nazwa_input_" + global_file_id);
	nazwa_input.setAttribute("id","nazwa_input_" + global_file_id);
	nazwa_input.setAttribute("size","50");

	td2.appendChild(ahref);
	
	var tr2 = document.createElement('tr');
	
	td2_1 = document.createElement('td');
	td2_1.appendChild(nazwa);
	
	td2_1.appendChild(document.createElement('br'));
	
	td2_2 = document.createElement('td');
	td2_1.appendChild(nazwa_input);
	
	tr1.appendChild(td1);
	tr1.appendChild(td2);
	
	tr2.appendChild(td2_1);
	tr2.appendChild(td2_2);

	tbody.appendChild(tr2);
	tbody.appendChild(tr1);
	table1.appendChild(tbody);
	div1.appendChild(table1);
}

function del_file(id, node_name1)
{
	file = document.getElementById(id);
	file.removeChild(document.getElementById(node_name1));
}

function checkContactForm(form1)
{
	error_text = '';
	error = 0;
	
	if(form1.imie.value=='')
	{
		error_text += 'Proszę podać imię i nazwisko.\n';
		error = 1;

	}
	
	if(form1.kontakt.value=='')
	{
		error_text += 'Proszę podać telefon kontaktowy lub adres e-mail.\n';
		error = 1;

	}
	
	if(form1.temat.value=='')
	{
		error_text += 'Proszę podać temat wiadomości.\n';
		error = 1;

	}
	
	if(form1.tresc.value=='')
	{
		error_text += 'Proszę podać treść wiadomości.';
		error = 1;

	}
	
	if (error>0)
		alert(error_text);

	for(i=0;i<form1.elements.length;i++)
	{
		if(form1.elements[i].value =='')
		{
			form1.elements[i].focus();
			break;
		}
	}
		
	return !error;
}

	function remove(tab, s)
	{
		//alert(tab);
		//alert(s);
		var temp1 = new Array();
		for(var i=0;i<tab.length;i++)
		{
			if(s==tab[i])
			{
				temp1 = tab.splice(i, 1);
				//tab.length--;
				//alert(tab.length);
				return tab;
				//alert(tab[i]);
			}
		}
		return tab;
	}

function edit_file(file_id, tablica)
{
	div = document.getElementById('nazwa_pliku_' + file_id);
	
	ahref = div.getElementsByTagName('a').item(0);
	myinput = div.getElementsByTagName('input').item(0);

	if(ahref != null)
	{

		nazwa_input = document.createElement('input');
		nazwa_input.type = "text";
		nazwa_input.id = 'file_name_'+ file_id;
		nazwa_input.name = 'file_name_'+ file_id;
		nazwa_input.value = ahref.innerHTML;
		nazwa_input.size = "50";

		div.removeChild(ahref);
		div.appendChild(nazwa_input);
		nazwa_input.focus();
		nazwa_input.select();
		tablica.push(file_id);
	}
	else
	{
		ahref = document.createElement('a');
		ahref.href = '../getFile.php?id=' + file_id;
		ahref.appendChild(document.createTextNode(div.getAttribute('name')));
		ahref.setAttribute('class', 'link_inny');
		ahref.setAttribute('className', 'link_inny');
		ahref.setAttribute('target', '_blank');

		div.removeChild(myinput);
		div.appendChild(ahref);
		tablica = remove(tablica, file_id)
	}
	return tablica;	
}

function changeState(nazwa, pole)
{
	if(pole.checked)
	{
		document.forms[0].elements[nazwa+'_add'].disabled =  false;
		document.forms[0].elements[nazwa+'_edit'].disabled =  false;
		document.forms[0].elements[nazwa+'_del'].disabled =  false;
		document.forms[0].elements[nazwa+'_sort'].disabled =  false;
	}
	else
	{
		document.forms[0].elements[nazwa+'_add'].checked =  false;
		document.forms[0].elements[nazwa+'_edit'].checked =  false;
		document.forms[0].elements[nazwa+'_del'].checked =  false;
		document.forms[0].elements[nazwa+'_sort'].checked =  false;
	
		document.forms[0].elements[nazwa+'_add'].disabled =  true;
		document.forms[0].elements[nazwa+'_edit'].disabled =  true;
		document.forms[0].elements[nazwa+'_del'].disabled =  true;
		document.forms[0].elements[nazwa+'_sort'].disabled =  true;
	}
}

function changeStatePanel(panel, pola)
{
	if(panel.checked)
	{
		for( i = 0 ; i < pola.length ; i++ )
		{
			document.forms[0].elements[pola[i]+'_access'].disabled =  false;
			/*document.forms[0].elements[pola[i]+'_add'].disabled =  false;
			document.forms[0].elements[pola[i]+'_edit'].disabled =  false;
			document.forms[0].elements[pola[i]+'_del'].disabled =  false;
			document.forms[0].elements[pola[i]+'_sort'].disabled =  false;*/
		}
		document.forms[0].elements['settings_access'].disabled =  false;
	}
	else
	{
		for( i = 0 ; i < pola.length ; i++ )
		{
			document.forms[0].elements[pola[i]+'_access'].disabled =  true;
			document.forms[0].elements[pola[i]+'_add'].disabled =  true;
			document.forms[0].elements[pola[i]+'_edit'].disabled =  true;
			document.forms[0].elements[pola[i]+'_del'].disabled =  true;
			document.forms[0].elements[pola[i]+'_sort'].disabled =  true;
			
			document.forms[0].elements[pola[i]+'_access'].checked =  false;
			document.forms[0].elements[pola[i]+'_add'].checked =  false;
			document.forms[0].elements[pola[i]+'_edit'].checked =  false;
			document.forms[0].elements[pola[i]+'_del'].checked =  false;
			document.forms[0].elements[pola[i]+'_sort'].checked =  false;
		}
		document.forms[0].elements['settings_access'].disabled =  true;
		document.forms[0].elements['settings_access'].checked =  false;
	}
}