function slownikUstaw(slownik,wartosc)
	{

		document.all["nazwa\_"+slownik].innerHTML=document.all["slownik_"+wartosc].innerHTML;
		document.all["focus\_"+slownik].style.backgroundColor='#FFFFFF';		
		document.all[slownik].value=wartosc;
		document.all["menu"].style.visibility = "hidden";
		if (wartosc==8)
			{
				document.all['cykl'].innerHTML='<input type="radio" name="cyklicznoscu" value="3" checked="checked" onclick="ustawCykl(3)" />co 3 miesiace <input type="radio" name="cyklicznoscu" onclick="ustawCykl(4)" value="4" />co 4 miesiace <input type="radio" name="cyklicznoscu" onclick="ustawCykl(5)" value="5" /> co 5 miesiacy';
				document.all['cyklicznosc'].value=3;
			}	
		else
			{
				if (document.getElementById('cykl'))
					{
						document.getElementById('cykl').innerHTML='';
						document.all['cyklicznosc'].value=-1;
					}
			}
	}

function slownikiPokaz(slownik,kolorTlo)
	{

		dokumentOnClick=4;
		dokumentSlownik=slownik;
		szerokosc=196;
		eval('on_menu = document.getElementById("'+slownik+'_b")');
		document.all["focus\_"+slownik].style.backgroundColor=kolorTlo;
		document.all["menu"].style.left = get_real_left(on_menu)-180;
		document.all["menu"].style.top = get_real_top(on_menu)+15;
		document.all["menu"].style.visibility = "visible";
 		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		if (slownik=='sprzet')
			{
				xmlDoc.load('slowniki.php?slownik='+slownik+'&id='+document.all['kontrahent'].value);
				document.all["menu"].style.left = get_real_left(on_menu)-600;
				szerokosc=616;				
			}
		else if (slownik=='nadrzedna_strona')
			{
				xmlDoc.load('slowniki.php?slownik='+slownik+'&id='+document.all['glowna_strona'].value);
				//alert('oki');
			}			
		else if (slownik=='kontakt')
			{
				xmlDoc.load('slowniki.php?slownik='+slownik+'&id='+document.all['kontrahent'].value);
			}
		else
			{
				xmlDoc.load('slowniki.php?slownik='+slownik);
			}
		outHTML='<table width="'+szerokosc+'" border="0" cellspacing="1" cellpadding="0" bgcolor="#7F9DB9">'
				 +'<tr>'
				 +'<td valign="top" bgcolor="#FAFAFA">'
				 +'<table width="100%" border="0" cellspacing="1" cellpadding="0">';
		i=0;
		while(i<xmlDoc.getElementsByTagName("slownik").length)
			{
				outHTML+='<tr><td class="pointer" id="slownik_'+xmlDoc.getElementsByTagName("slownik").item(i).text+'" onClick="slownikUstaw(\''+slownik+'\','+xmlDoc.getElementsByTagName("slownik").item(i).text+')">'+xmlDoc.getElementsByTagName("nazwa_slownik").item(i).text+'</td><tr>';
				i++;				
			}
	outHTML+='</table>'
				 +'</td>'
				 +'</tr>'
				+'</table>';

		document.all["menu"].innerHTML=outHTML;
	}





function slownikiUsun(pole)
	{
		document.all["pola"].value--;
		outHTML	='<table width="100%" border="0" cellspacing="1" cellpadding="1">';
		i=0;
		while(i<pole)
			{
				wartoscCookie=dokumentCookie("pole_"+i);
				if (wartoscCookie==';')
					{
						wartoscCookie='';
					}				
				outHTML+='<tr>'
						+'<td width="20%"></td>'
						+'<td width="60%"><textarea name="pole_'+i+'" type="text" rows="1" cols="120" onKeyUp="vChange('+i+')">'+wartoscCookie+'</textarea></td>'
						+'<td width="20%" class="vtekst" onClick="slownikiUsun('+i+')"><img src="images/delete.gif" width="16" height="16" alt="usuń" class="pointer"></td>'
						+'</tr>'
				i++;
			}
		i=pole;

		while(i<document.all['pola'].value)
			{
				j=i+1;
				wartoscCookie=dokumentCookie("pole_"+j);
				if (wartoscCookie==';')
					{
						wartoscCookie='';
					}			
				outHTML+='<tr>'
						+'<td width="20%"></td>'
						+'<td width="60%"><textarea name="pole_'+i+'" type="text" rows="1" cols="120" onKeyUp="vChange('+i+')">'+wartoscCookie+'</textarea></td>'
						+'<td width="20%" class="vtekst" onClick="slownikiUsun('+i+')"><img src="images/delete.gif" width="16" height="16" alt="usuń" class="pointer"></td>'
						+'</tr>'			
				document.cookie='pole_'+i+'='+wartoscCookie;		
				i++;				
			}
		document.cookie='pole_'+i+'=; expires=-1';
		outHTML+='</table>'

		document.all['wartosci'].innerHTML=outHTML;		
	}

function vChange(pole)
	{
		document.cookie='pole_'+pole+'='+document.all['pole_'+pole].value;
	}

function slownikiDodaj()
	{
		document.all["pola"].value++;
		outHTML	='<table width="100%" border="0" cellspacing="1" cellpadding="1">';
		for(i=0;i<document.all["pola"].value-1;i++)
			{
				wartoscCookie=dokumentCookie("pole_"+i);
				if (wartoscCookie==';')
					{
						wartoscCookie='';
					}
				outHTML+='<tr>'
						+'<td width="20%"></td>'
						+'<td width="60%"><textarea name="pole_'+i+'" type="text" rows="1" cols="120" onKeyUp="vChange('+i+')">'+wartoscCookie+'</textarea></td>'
						+'<td width="20%" class="vtekst" onClick="slownikiUsun('+i+')"><img src="images/delete.gif" width="16" height="16" alt="usuń" class="pointer"></td>'
						+'</tr>'
			}
				outHTML+='<tr>'
						+'<td width="20%"></td>'
						+'<td width="60%"><textarea name="pole_'+i+'" type="text" rows="1" cols="120" onKeyUp="vChange('+i+')"></textarea></td>'
						+'<td width="20%" class="vtekst" onClick="slownikiUsun('+i+')"><img src="images/delete.gif" width="16" height="16" alt="usuń" class="pointer"></td>'
						+'</tr>'			
		outHTML+='</table>'
		document.all['wartosci'].innerHTML=outHTML;
	}

function slownikiZapisz()
	{
		pole=document.all['slownik'].value+'|';
		for(i=0;i<document.all["pola"].value;i++)
			{
				pole+=document.all["pole_"+i].value+'|';
			}
		oHttp = new ActiveXObject("Microsoft.XMLHTTP");
		oHttp.open('POST','slowniki/edit.php',false);
		oHttp.setRequestHeader("Content-Type", "text/xml");
		oHttp.send(pole);
		alert('      Zapisano!!!');		
	}

function slownikiUstaw(tabela,slownik)
	{
		if (dokumentSlowniki!='')
			{
			document.all['slownik_'+dokumentSlowniki].style.backgroundColor='';
			document.all['slownik_'+dokumentSlowniki].cells[0].style.backgroundColor='';
				
			}
		tabela.cells[0].style.backgroundColor='#FAFAFA';		
		tabela.style.backgroundColor='#2254b1';
		dokumentSlowniki=slownik;
		
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
       	xmlDoc.async="false";
		xmlDoc.load('slowniki/view.php?slownik='+slownik);
		outHTML	='<br>'
				+'<div align="center">'
				+'<table width="98%" border="0" cellspacing="1" cellpadding="1" bgcolor="#DCE3EB">'
				+' <tr>'
				+'  <td height="16" bgcolor="#FFFFFF" background="images/tlonaglowek.gif">'
				+'  <table border="0" cellspacing="0" cellpadding="0">'
				+'   <tr>'
				+'    <td>'
				+'    <table border="0" cellspacing="1" cellpadding="1" class="pointer" onClick="slownikiZapisz()" onMouseOver="ustawTlo(this,\'#FEE197\',\'#2254b1\')" onMouseOut="ustawTlo(this,\'\',\'\')">'
				+'     <tr>'
				+'      <td>'
				+'      <table border="0" cellspacing="0" cellpadding="0">'
				+'       <tr>'
				+'        <td width="5"></td>'						
				+'        <td width="20"><img src="images/save.gif" width="14" height="14"></td>'
				+'        <td>Zapisz</td>'
				+'        <td width="10"></td>'						
				+'       </tr>'
				+'      </table>'
				+'      </td>'
				+'     </tr>'
				+'    </table>'
				+'    </td>'
				+'    <td>|</td>'
				+'    <td>'
				+'    <table border="0" cellspacing="1" cellpadding="1" class="pointer" onClick="slownikiDodaj()" onMouseOver="ustawTlo(this,\'#FEE197\',\'#2254b1\')" onMouseOut="ustawTlo(this,\'\',\'\')">'
				+'     <tr>'
				+'      <td>'
				+'      <table border="0" cellspacing="0" cellpadding="0">'
				+'       <tr>'
				+'        <td width="5"></td>'
				+'        <td width="20"><img src="images/nowy.gif" width="14" height="14"></td>'
				+'        <td>Nowy element</td>'
				+'        <td width="10"></td>'						
				+'       </tr>'
				+'      </table>'
				+'      </td>'
				+'     </tr>'
				+'    </table>'
				+'    </td>'				
				+'   </tr>'
				+'  </table>'					
				+'  </td>'
				+' </tr>'
				+'</table>'
				+'<br>'
				+'<div id="wartosci">'		
				+'<table width="100%" border="0" cellspacing="1" cellpadding="1">';
				
		i=0;
		j=0;
		while(i<xmlDoc.getElementsByTagName("nazwa_slowniki_wartosc").length)
			{
				outHTML+='<tr>'
						+'<td width="20%"></td>'
						+'<td width="60%"><textarea name="pole_'+i+'" type="text" rows="1" cols="120" onKeyUp="vChange('+i+')">'+xmlDoc.getElementsByTagName("nazwa_slowniki_wartosc").item(i).text+'</textarea></td>'
						+'<td width="20%" class="vtekst" onClick="slownikiUsun('+i+')"><img src="images/delete.gif" width="16" height="16" alt="usuń" class="pointer"></td>'
						+'</tr>'
				document.cookie='pole_'+i+'='+xmlDoc.getElementsByTagName("nazwa_slowniki_wartosc").item(i).text;
				i++;
			}
		outHTML+='</table>'
				+'</div>'
				+'<input name="slownik" type="hidden" value="'+xmlDoc.getElementsByTagName("slownik").item(0).text+'">'
				+'<input name="pola" type="hidden" value="'+xmlDoc.getElementsByTagName("nazwa_slowniki_wartosc").length+'">';
		document.all['podstrona'].innerHTML=outHTML;
	}


function slowniki()
	{
	//	menuUstaw('slowniki');	
		document.all['naglowek'].innerHTML='<b>Słowniki</b>';
		document.all['logo'].innerHTML='<div align="center"><img src="images/slowniki.gif" width="41" height="41"></div>';
		document.all['panel'].innerHTML='';		
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
       	xmlDoc.async="false";
		xmlDoc.load('slowniki/view.php');
	
		outHTML =' <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">'
				+'  <tr>'
				+'   <td width="140" background="images/tlobok.gif" valign="top">'
				+' <table width="100%" border="0" cellspacing="1" cellpadding="0">'				
		i=0;
		while(i<xmlDoc.getElementsByTagName("slownik").length)
			{
				outHTML+='<tr>'
						+'<td width="5"></td>'
						+'<td>'
						+'   <table width="120" height="18" border="0" cellspacing="1" cellpadding="1" id="slownik_'+xmlDoc.getElementsByTagName("slownik").item(i).text+'" class="pointer" onClick="slownikiUstaw(this,'+xmlDoc.getElementsByTagName("slownik").item(i).text+')" onMouseOver="ustawTlo(this,\'#FEE197\',\'#2254b1\')" onMouseOut="ustawTlo(this,\'\',\'\')">'
						+'    <tr>'
						+'     <td>'
						+'      <table width="100%" border="0" cellspacing="0" cellpadding="0">'
						+'       <tr>'
						+'        <td width="10"></td>'
						+'        <td>'+xmlDoc.getElementsByTagName("nazwa_slownik").item(i).text+'</td>'
						+'        <td width="10"></td>'						
						+'       </tr>'
						+'      </table>'
						+'     </td>'
						+'    </tr>'
						+'   </table>'						
						+' </td>'
						+'</tr>';
						
				i++;				
			}				
		outHTML+=' </table>'				
				+'   </td>'
				+'   <td valign="top" id="podstrona">&nbsp;</td>'
				+'  </tr>'
				+' </table>';				
		
		document.all['strona'].innerHTML=outHTML;
	}



