//**********************************************************

function Prawy(e)
{
if((document.all && event.button==2) || (document.layers && e.which==3))
	alert('(C) 2002-2003 Tomasz Nowak tomn@poczta.fm')
}

//**********************************************************

function send()
{
 if(send.arguments.length>0)
 {
  var forma=send.arguments[0];
  if(typeof(document.forms[forma])=='object')
  {
   //document.forms[forma].reset();
   for(var i=1;i<send.arguments.length;i=i+2)
   {
    obj=(document.forms[forma].elements[send.arguments[i]]);
     if((typeof(obj)=='object')&&(obj.type=='hidden'))
      obj.value=send.arguments[i+1];
     else
      return;
   }
   document.forms[forma].submit();
  }
  else if(typeof(forma)=='object')
  {
   for(var i=1;i<send.arguments.length;i=i+2)
   {
    obj=(forma.elements[send.arguments[i]]);
     if((typeof(obj)=='object')&&(obj.type=='hidden'))
      obj.value=send.arguments[i+1];
     else
      return;
   }
   forma.submit();
  }
  else
   alert('Wysyłany obiekt nie jest formularzem');
 }	
}

//**********************************************************

function zobacz(url,x,y)
{
var okno=window.open(url,'new_window','toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=yes,status=no,directories=no,resizable=yes,top=0,left=0,height='+y+',width='+x);
if(okno)
	okno.focus();
}

//**********************************************************

function zobacz2(url,x,y)
{
var okno=window.open(url,'new_window2','toolbar=no,menubar=yes,location=no,personalbar=no,scrollbars=yes,status=no,directories=no,resizable=yes,top=0,left=0,height='+y+',width='+x);
if(okno)
	okno.focus();
}

//**********************************************************

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//**********************************************************

function check_all(forma)
{
if(typeof(document.forms[forma])=='object')
{
for(i = 0; i < document.forms[forma].elements.length; i++)
{
	if(document.forms[forma].elements[i].type == 'checkbox')document.forms[forma].elements[i].click();
}
}
}
//**********************************************************

function msg(id,nazwa,id_parent,status)
{
var doc=parent.gora;
doc.opis.nazwa.value=nazwa;
doc.main.cmd.value='pokaz_tree';
doc.main.elements['class'].value='class_main';
doc.main.id.value=id;
doc.main.id_parent.value=id_parent;
doc.main.val.value=nazwa;
doc.main.status.value=status;

if(nazwa=='Główna')
	return;

	doc.main.submit();
};

//**********************************************************
function refresh_tree()
{
parent.lewa.window.location='tree.php';
}
//**********************************************************


var marked_row = new Array; 

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function 

//*****************************************************************

function setCell()
{
cell=document.getElementById("id_wyloguj");

if( (typeof(cell)=='object') && (typeof(cell.bgColor)!='undefined'))
{
	cell.bgColor="";
	red(cell);
}
}//end function setCell()

function red(cell)
{
cell.bgColor="#E3F8E0";
setTimeout('transparent(cell)',200);
}//end function red(cell)

function transparent(cell)
{
cell.bgColor="";
setTimeout('red(cell)', 3000);
}//end function transparent(cell)

//*****************************************************************

function trim(lancuch)
{
	while (lancuch.charAt(0) == " ")
		lancuch = lancuch.substring(1,lancuch.length);
	while (lancuch.charAt(lancuch.length-1) == " ")
		lancuch = lancuch.substring(0,lancuch.length-2);
	return lancuch;
};

//*****************************************************************

function show_picture(val, img, path, delimiter)
{
	var temp=val.split(delimiter);
	document.images[img].src=path+temp[1];
}

//*****************************************************************

function show_hide(div, val)
{

	if(val!=0)
		document.getElementById(div).style.display="block";
	else
		document.getElementById(div).style.display="none";

}

//*****************************************************************

function show_hide2(div)
{
	var element=document.getElementById(div);

	if(element.style.display=="none")
		element.style.display="block";
	else
		element.style.display="none";

}

//*****************************************************************

function odmiana( num, text1, text2, text3 )
{
	if(num==0)
		return "";

	if ( num < 20 )
	{
		if ( num == 1 )
			return num + " " +text1;
		else if ( num >= 2 && num <= 4 )
			return num + " " +text2;
		else
			return num + " " +text3;
	}
	else
	{
		tmp=Math.floor(num/10)*10;
		tmp=num-tmp;
		if(tmp>1 && tmp<5)
			return num + " " +text2;
		else
			return num + " " +text3;
	}
}

//*****************************************************************

// clock begin
/*
dCol='000000';//date colour.
fCol='000000';//face colour.
sCol='000000';//seconds colour.
mCol='000000';//minutes colour.
hCol='000000';//hours colour.
ClockHeight=40;
ClockWidth=40;
ClockFromMouseY=0;
ClockFromMouseX=100;

//Alter nothing below! Alignments will be lost!

d=new Array("Niedziela","Poniedzialek","Wtorek","Sroda","Czwartek","Piatek","Sobota");
m=new Array("STYCZEN","LUTY","MARZEC","KWIECIEN","MAJ","CZERWIEC","LIPIEC","SIERPIEN","WRZESIEN","PAZDZIERNIK","LISTOPAD","GRUDZIEN");
date=new Date();
day=date.getDate();
year=date.getYear();
if (year < 2000) year=year+1900; 
TodaysDate=" "+d[date.getDay()]+" "+day+" "+m[date.getMonth()]+" "+year;
D=TodaysDate.split('');
H='...';
H=H.split('');
M='....';
M=M.split('');
S='.....';
S=S.split('');
Face='1 2 3 4 5 6 7 8 9 10 11 12';
font='Arial';
size=1;
speed=0.6;
ns=(document.layers);
ie=(document.all);
Face=Face.split(' ');
n=Face.length; 
a=size*10;
ymouse=0;
xmouse=0;
scrll=0;
props="<font face="+font+" size="+size+" color="+fCol+"><B>";
props2="<font face="+font+" size="+size+" color="+dCol+"><B>";
Split=360/n;
Dsplit=360/D.length;
HandHeight=ClockHeight/4.5
HandWidth=ClockWidth/4.5
HandY=-7;
HandX=-2.5;
scrll=0;
step=0.06;
currStep=0;
y=new Array();x=new Array();Y=new Array();X=new Array();
for (i=0; i < n; i++){y[i]=0;x[i]=0;Y[i]=0;X[i]=0}
Dy=new Array();Dx=new Array();DY=new Array();DX=new Array();
for (i=0; i < D.length; i++){Dy[i]=0;Dx[i]=0;DY[i]=0;DX[i]=0}
if (ns){
for (i=0; i < D.length; i++)
document.write('<layer name="nsDate'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props2+D[i]+'</font></center></layer>');
for (i=0; i < n; i++)
document.write('<layer name="nsFace'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props+Face[i]+'</font></center></layer>');
for (i=0; i < S.length; i++)
document.write('<layer name=nsSeconds'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+sCol+'><center><b>'+S[i]+'</b></center></font></layer>');
for (i=0; i < M.length; i++)
document.write('<layer name=nsMinutes'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+mCol+'><center><b>'+M[i]+'</b></center></font></layer>');
for (i=0; i < H.length; i++)
document.write('<layer name=nsHours'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+hCol+'><center><b>'+H[i]+'</b></center></font></layer>');
}
if (ie){
document.write('<div id="Od" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < D.length; i++)
document.write('<div id="ieDate" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props2+D[i]+'</B></font></div>');
document.write('</div></div>');
document.write('<div id="Of" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < n; i++)
document.write('<div id="ieFace" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props+Face[i]+'</B></font></div>');
document.write('</div></div>');
document.write('<div id="Oh" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < H.length; i++)
document.write('<div id="ieHours" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+hCol+';text-align:center;font-weight:bold">'+H[i]+'</div>');
document.write('</div></div>');
document.write('<div id="Om" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < M.length; i++)
document.write('<div id="ieMinutes" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+mCol+';text-align:center;font-weight:bold">'+M[i]+'</div>');
document.write('</div></div>')
document.write('<div id="Os" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < S.length; i++)
document.write('<div id="ieSeconds" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+sCol+';text-align:center;font-weight:bold">'+S[i]+'</div>');
document.write('</div></div>')
}
(ns)?window.captureEvents(Event.MOUSEMOVE):0;
function Mouse(evnt){
ymouse = (ns)?evnt.pageY+ClockFromMouseY-(window.pageYOffset):event.y+ClockFromMouseY;
xmouse = (ns)?evnt.pageX+ClockFromMouseX:event.x+ClockFromMouseX;
}
(ns)?window.onMouseMove=Mouse:document.onmousemove=Mouse;
function ClockAndAssign(){
time = new Date ();
secs = time.getSeconds();
sec = -1.57 + Math.PI * secs/30;
mins = time.getMinutes();
min = -1.57 + Math.PI * mins/30;
hr = time.getHours();
hrs = -1.575 + Math.PI * hr/6+Math.PI*parseInt(time.getMinutes())/360;
if (ie){
Od.style.top=window.document.body.scrollTop;
Of.style.top=window.document.body.scrollTop;
Oh.style.top=window.document.body.scrollTop;
Om.style.top=window.document.body.scrollTop;
Os.style.top=window.document.body.scrollTop;
}
for (i=0; i < n; i++){
 var F=(ns)?document.layers['nsFace'+i]:ieFace[i].style; 
 F.top=y[i] + ClockHeight*Math.sin(-1.0471 + i*Split*Math.PI/180)+scrll;
 F.left=x[i] + ClockWidth*Math.cos(-1.0471 + i*Split*Math.PI/180);
 }
for (i=0; i < H.length; i++){
 var HL=(ns)?document.layers['nsHours'+i]:ieHours[i].style;
 HL.top=y[i]+HandY+(i*HandHeight)*Math.sin(hrs)+scrll;
 HL.left=x[i]+HandX+(i*HandWidth)*Math.cos(hrs);
 }
for (i=0; i < M.length; i++){
 var ML=(ns)?document.layers['nsMinutes'+i]:ieMinutes[i].style;
 ML.top=y[i]+HandY+(i*HandHeight)*Math.sin(min)+scrll;
 ML.left=x[i]+HandX+(i*HandWidth)*Math.cos(min);
 }
for (i=0; i < S.length; i++){
 var SL=(ns)?document.layers['nsSeconds'+i]:ieSeconds[i].style;
 SL.top=y[i]+HandY+(i*HandHeight)*Math.sin(sec)+scrll;
 SL.left=x[i]+HandX+(i*HandWidth)*Math.cos(sec);
 }
for (i=0; i < D.length; i++){
 var DL=(ns)?document.layers['nsDate'+i]:ieDate[i].style; 
 DL.top=Dy[i] + ClockHeight*1.5*Math.sin(currStep+i*Dsplit*Math.PI/180)+scrll;
 DL.left=Dx[i] + ClockWidth*1.5*Math.cos(currStep+i*Dsplit*Math.PI/180);
 }
currStep-=step;
}
function Delay(){
scrll=(ns)?window.pageYOffset:0;
Dy[0]=Math.round(DY[0]+=((ymouse)-DY[0])*speed);
Dx[0]=Math.round(DX[0]+=((xmouse)-DX[0])*speed);
for (i=1; i < D.length; i++){
Dy[i]=Math.round(DY[i]+=(Dy[i-1]-DY[i])*speed);
Dx[i]=Math.round(DX[i]+=(Dx[i-1]-DX[i])*speed);
}
y[0]=Math.round(Y[0]+=((ymouse)-Y[0])*speed);
x[0]=Math.round(X[0]+=((xmouse)-X[0])*speed);
for (i=1; i < n; i++){
y[i]=Math.round(Y[i]+=(y[i-1]-Y[i])*speed);
x[i]=Math.round(X[i]+=(x[i-1]-X[i])*speed);
}
ClockAndAssign();
setTimeout('Delay()',20);
}
if (ns||ie)window.onload=Delay;
*/
// clock end


//----------------------------------

function wypelnij_liste(list, id_selected, dane)
{

	var i=0;
	var sel=0;
	var wektor;

	//czyszcze liste
	while(list.options[0])
		list.options[0]=null;

	list.options[0]=new Option("wybierz",0, false, false);

	var i_sel=0;

	for( i=0; i<dane.length; i++ )
	{
		if(dane[i]['id']==id_selected)
		{
			list.options[i+1]=new Option(dane[i]['nazwa'], dane[i]['id'], true, true);
			i_sel=i+1;
		}
		else
			list.options[i+1]=new Option(dane[i]['nazwa'], dane[i]['id'], false, false);
	}

// dla IE
	if(i_sel)
	{
//		list.options[i_sel].selected=true;
		list.selectedIndex=i_sel;
	}

}

//----------------------------------

function in_array(arr, val)
{
	for(var i in arr)
	{
		if(arr[i]==val)
			return true;
	}
	return false;
}

//----------------------------------

function show_hide_menu_ezwww(id)
{

	var element=document.getElementById('menu_'+id);
	var img=document.images['img_'+id];



	if(element.style.display=="none")
	{
		element.style.display="block";
		img.src=imgMinus.src;
	}
	else
	{
		element.style.display="none";
		img.src=imgPlus.src;
	}
}

//-------------------------------------------------------------------------

function setWidth(width)
{
	var ico_wide=document.getElementById('ico_wide');
	var ico_narrow=document.getElementById('ico_narrow');;

	var container=document.getElementById('container');
	container.style.width=width;

	createCookie('page_width', width, 30) ;


	if((!ico_wide) || (!ico_narrow))
		return;

	if(width=='700px')
	{
		ico_wide.style.display		= 'block';
		ico_narrow.style.display	= 'none';	
	}
	else
	{
		ico_wide.style.display		= 'none';
		ico_narrow.style.display	= 'block';
	}

}

//-------------------------------------------------------------------------

function createCookie(name,value,days) 
{
if (days) 
{
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
}
else 
	expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

//-------------------------------------------------------------------------

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 setStartWidth()
{
	var width=readCookie('page_width');
	if(width)
		setWidth(width);
	else
		setWidth('700px');
}

//-------------------------------------------------------------------------


function TimeLeft(sekund, div_before, div_counter, div_after)
{	
	sekund--;

	if(sekund<1)
	{
		show_hide(div_before, 0);
		show_hide(div_after, 1);
		return;
	}

	d = Math.floor( sekund/(24*3600) );

	str_d = odmiana(d, 'dzień', 'dni', 'dni');


	h = Math.floor( (sekund/(3600) )-(d*24) );
	str_h = odmiana( h, 'godzina', 'godziny', 'godzin');

	m =	Math.floor((sekund/(60) )-(h*60+d*24*60) );
	str_m = odmiana( m, 'minuta', 'minuty', 'minut');

	s = Math.floor( sekund-(m*60+h*3600+d*24*3600) );
	str_s =	odmiana( s, 'sekunda', 'sekundy', 'sekund');

	document.getElementById(div_counter).innerHTML = str_d + " " + str_h + " " + str_m + " " + str_s;

	setTimeout("TimeLeft("+sekund+", '"+div_before+"', '"+div_counter+"', '"+div_after+"')", 1000);
}	


//-------------------------------------------------------------------------

function Odliczaj(Data1, Data2, div_before, div_counter, div_after)
{
	show_hide(div_after, 0);
	var sekund = ( Date.parse(Data2)-Date.parse(Data1) )/1000;	
	TimeLeft(sekund, div_before, div_counter, div_after);
}

//-------------------------------------------------------------------------