var sciezka,search_akt=null,zindex=1;
//   p_arr -  popup
//   p_menu  lista otwartych menu
var  p_arr = new Array(), p_menu=new Array(),menu_akt;
var scrX,scrY,divX,divY,screenX,screenY


function initId(div){
 var i;
 for (i=0; i< p_arr.length; i++) 
  if (p_arr[i].aktdiv==div) return i;  
 return false;    
}

function initdiv(div,f,s,style){
 if (typeof(f)=='string') f=document.getElementById(f); 
 if (typeof(div)=='string') div=document.getElementById(div); 
 var i=initId(div);
 if (typeof(i)=='boolean'){
   p_arr[p_arr.length]=new c_div(div);
   i=p_arr.length-1;
 } 
 p_arr[i].init(f,s,style);
}

function divout(f){
 if (typeof(f)=='string') f=document.getElementById(f); 
 f=get_zdiv(f);
 var i=initId(f);
 if (typeof(i)=='number') p_arr[i].delate();
}

function divoutblick(f){
 if (typeof(f)=='string') f=document.getElementById(f); 
 f=get_zdiv(f);
 var i=initId(f);
 if (typeof(i)=='number') p_arr[i].delateblick();
}


function searchId(f,id,znak){
 var i,x, b=false;
 if (typeof(f)=='object')
  for (i=0;i<f.length;i++){
   x=f[i].split(znak);
    if (x[0]==id){
     search_akt=i; 
     return x[1].split(';');
    }    
  }  
 return b;
}


function getScroll(s,f,div,style){
  initdiv(div,f,s,style);  
}


function getScrollXY(s,f,div,dstyle){
 var el,el1;
 var x,c,i,j,style="delete=z_div1;z_div2;z_div3,delay.in=time:600,delay.out=time:200,div.style=border:dotted 3px #A50;padding:0px,efekt.in=9,efekt.out=10".split(',');
 var nStyle=new Array();
 if (typeof(dstyle)=='undefined') dstyle='';
 if (typeof(dstyle)=='string' && dstyle!='') dstyle=dstyle.split(',');
 if (typeof(dstyle)=='object')
 for (i=0; i<dstyle.length; i++){
  el= dstyle[i].split('=');
  c=searchId(style, el[0] ,'=');// c w stylu

  var s_akt=search_akt;   
  el1=el[1].split(';');
  if (c) {
   var a=new Array();   
   for (j=0; j<c.length; j++)
   if (searchId(el1,c[j].split(':')[0],':')){   
      a[a.length]=el1[search_akt]; 
      el1= el1.slice(0,search_akt).concat(el1.slice(search_akt+1)); 
   }  else a[a.length]=c[j]; 
   a= a.concat(el1);
   style=style.slice(0,s_akt).concat(style.slice(s_akt+1)); 
   nStyle[nStyle.length]= el[0] + '=' + a.join(';'); 
  } else  nStyle[nStyle.length]=dstyle[i];

 } 
 style=style.concat(nStyle);
 initdiv(div, f,s, style);
}


function popup(f,s,width){
 var z='textAlign:left;'
if (typeof(width) !='undefined') z += 'width:'+ width + 'px'
 width="div.style=" + z
 var style=("delay.in=time:700,efekt.in=mix," + width).split(',')

 initdiv('z_div2',f,s,style)
}

function z_echo(f,title,text){
 var s=getNagl('z_div', '80%',title);
 s+="<div style='text-align:left'>" + text +'</div>';
 getScroll(s,f,'z_div');
}

function z_oceny(f,title,text){
 var s=getNagl('z_div', '250px',title);
 s+="<div style='text-align:left'>" + text +'</div>';
 getScroll(s,f,'z_div');
}


function submit(id,opcja){
 var f=document.getElementById(id);
 if (opcja>0 || opcja!='')   f.elements['opcja'].value= opcja;
 f.submit();
}

function display(f,b){
if (typeof(f) == 'string') f=document.getElementById(f);

 if ( f.style.display=='block'){
  f.style.display='none'; 
  if (b)  menu_akt.setcurr(null);
 }
 else {
  f.style.display='block';
  if (b) menu_akt.setcurr(b);
 }
}

function doMenu(t){
 if (document.getElementById(t)){
   var f=document.getElementById(t);
   if (firstParent(f)) menu_akt.doMenu(f,false,false); 
 }
} 


function x_menu(t_parent,nohide){
 var parent = t_parent, current=null,f, t,pop_up, b_hide,b_submit;
 if (typeof(nohide) == 'boolean') b_hide=nohide; else b_hide=false; 
 if (parent.id)  pop_up=document.getElementById('div_' + parent.id.split('_')[1]);
 else pop_up=null; 
 this.id=parent.id;
 this.pop=pop_up;
 this.getcurr=function(){
  if (current)  return current;
   return null
 }
 this.setcurr=function(c){
 current=c;
 }

 this.doMenu= function(df,d_submit){ 
  if (typeof(d_submit)=='boolean') b_submit=d_submit ; else b_submit=true;
  f=df;
  var  x, b=true;
  getimg();
  if (current){
   if (f.nodeName=='NOBR' || f.nodeName=='IMG') t=f.parentNode; else t=f;
   if (t==pop_up){
    f=current; b=false;
   } 
   if (pop_up) pop_up.style.visibility='hidden';
  } 
  if (parent.className.indexOf('vmenu')==0){
   // menu pionowe
  if (f.nodeName=='IMG' ){
    if (imgName(f)=='help_open.png') f.src='themes/img/help_close.png';else f.src='themes/img/help_open.png';       
	display(nextObj(f.parentNode.nextSibling,true),false);
	x=f.parentNode;
	if (x.href && x.href.indexOf('javascript:')==0){ 
		f.onclick=function(){
			if (typeof(event)!='undefined'){
				if (typeof(event.returnValue)=='boolean') event.returnValue=true; else
			       if (typeof(event.cancelBubble)=='boolean') event.cancelBubble=true;
			}
			return false
		}
		f.click();
/*
		x.onclick=function(){
		if (event){
			if (typeof(event.returnValue)=='boolean') event.returnValue=false; else
			if (typeof(event.cancelBubble)=='boolean') event.cancelBubble=false;
		}
		return true
	}
*/
   }
   return ;
  }


   if (b_hide) hide(parent);
   x=nextObj(f.nextSibling,true);
   if (x!=false && x.tagName =='DIV' && b) display(x,false);     
   if (b){
     if (b_submit && f.href && f.href.indexOf('javascript:')==0)  eval(f.href.substr(11));
   }
   rozwin(); 
  }
  else if (f!=null){
   // menu poziome
   if (f.nodeName=='IMG'){
	if (typeof(closeclick)=='boolean')  closeclick=true; 
	return
   }
   if (typeof(closeclick)=='boolean')  closeclick=false; 
    if (f.onclick) f.click()
   if (f.tagName=='NOBR') f=f.parentNode; 
   var c='div_'+ f.id; 
   if (current && current.id && document.getElementById('div_' + current.id)){
     display(document.getElementById('div_' + current.id),false);
   } 
   if (document.getElementById(c)){
    c=document.getElementById(c);    
    current=null;     
    if (b) display(c,false);     
   }  
  }
  if (b) {
   current=f; 
   startMenu();
  }

  return f;
 }


 function getimg(){
 if (f.nodeName=='IMG' ){
  var p=f.parentNode;
  if (imgName(f)!='help_open.png' && imgName(f)!='help_close.png') f=p;
    else if (p == pop_up){
     f=nextObj(current.firstChild,true);
    }
 } else
   if ((f.href && f.href.indexOf('#')==0) || !f.onclick){
    if (f.firstChild) p=nextObj(f.firstChild,true); else return;
    if (p.nodeName=='IMG' && (imgName(p) =='help_open.png' || imgName(p) =='help_close.png')) f=p;     
  }
 }

 function getfontsize(){  
  if (f.className=='vmenuHelp') return '12px'; 
 }

 function startMenu(){  
 var width;
 if (pop_up){
    scrXY(f);
    pop_up.innerHTML=f.innerHTML;   
    if (f.style.pixelWidth>0) width=f.style.pixelWidth; else width=f.offsetWidth;
    width=width-15
    pop_up.style.width=width + 'px';
    pop_up.style.fontSize=getfontsize(); 
    pop_up.style.top = divY + 'px';
    pop_up.style.left = divX + 'px';
    pop_up.style.visibility='visible';
  }
 }

 function rozwin(){
  var p=f,x,b=false;
  while (p && p != parent){
   p.style.display='block';
   x=nextObj(p.parentNode.firstChild,true);
   if (x && b){
    x=nextObj(x.firstChild ,true)
    if (imgName(x)=='help_close.png') x.src='themes/img/help_open.png';
   }
   b=true;
   p=p.parentNode;
  }
 }

 function hide(p){
  var i, x;
  if (p != parent){
//   x=nextObj(p, false);
  }
  var child=p.childNodes;
  for (i=0; i<child.length; i++) {
   x=child[i];
   if (x.nodeName=='LI'){
    x=nextObj(nextObj(x.firstChild,true).nextSibling,true); 
    if (x.tagName){
     switch (x.tagName){   
       case 'UL':
        hide(x);
       break;  
      case 'DIV':
       x.style.display='none';
      break; 
     }
    }
   }
  }
 }
}

 function imgName(f){
  if (f && f.nodeName=='IMG'){  
   var a=f.src.split('/');
    return a[a.length-1];
  }
  return false;
 }


 function nextObj(x, b, next){
  if (x==null || typeof(x)=='undefined') return false;
  if (typeof(next)=='undefined') next=false;
  if (!next && x.nodeType==1) return x;
  if (b) while(x && x.nodeType != 1) x=x.nextSibling;   
   else  while(x  && x.nodeType != 1)  x=x.previousSibling;   
  if (x==null) x=false;
  return x;
 }


function start_div(id){
 menuAkt = document.getElementById(id);
 if (!menuAkt) return;
 zamknij()
 mouseout()
} 


// ul menu


function firstParent(a){
 var i,b
 if (a.nodeType=='undefined') return false;
 if (a.nodeName=='IMG' || a.nodeName=='NOBR') a=a.parentNode; 

 for (i=0; i<p_menu.length; i++)
   if (p_menu[i].pop==a){
    menu_akt=p_menu[i];
    return true; 
   }

 if (!a.tagName || a.nodeName=='DIV' || a.nodeType=='undefined') return false; 
 var x=thisParent(a);
 if (!x) return false;
 while (y=thisParent(x)) x=y
 for (i=0; i<p_menu.length; i++)
   if (p_menu[i].id==x.id){
    menu_akt=p_menu[i];
    return x;
 }
 if (x.id) b=true; else b=false;
// tworzy popup gdy jest id i zwija wszystkie inne okna
 p_menu[p_menu.length]= new x_menu(x,b);
 menu_akt=p_menu[p_menu.length-1];
 return true;
}

function thisParent(a){
 var i
 if (a.nodeType=='undefined') return false
 var  x=a.parentNode
 if (x.nodeName != 'LI') return false; 
  x=x.parentNode;
  if ( x && x.nodeName=='UL' && x.className && (x.className.indexOf('vmenu') == 0 || x.className.indexOf('hmenu')==0)){
   return x; 
  }
  return false;
}


function getMove(title){
 var curs;
 if (typeof(title)=='undefined') title='dziennik elektroniczny&nbsp;&gt;&nbsp;pop_up' ;
 if (IE()) curs='hand'; else curs='pointer';
 var c= "<table   cellpadding='0px' cellspacing='0px' style='width:100%;opacity:0.6; background-color:#00F; height:25px;filter:alpha(opacity=60)'>";
 c += "<tr><td id='pasek' style='color:#FF0;padding-left:20px;'>" + title + "</td>";
 c += "<td style='text-align:right; width:10px; color:#FFF; cursor :" + curs +"' onclick='divout(this);'>X</td></tr></table>";
 return c;
}


function getN(width){
 var d=document.getElementById('z_div').style;
  d.padding = '10px'
  if (width!='') d.width = width+'px';
  else d.width='auto';
  d. backgroundColor = '#FFFACD'
  d. border = '2px inset  blue'; 
  d.color = '#000FFF'
  
}

function getNagl(id, width,title){
var  text = getMove();
 var d =document.getElementById(id).style; 
 if (width) d.width=width;
 d.color="#000FFF";
 d.borderColor='#F0F'; 
 text += "<div style='width:100%;background-color:#FFFACD'>";
  if (title)
  text += "<font style='font-size:18px; color:#AAA'><b>" + title+ "</b></font><br><br>";
 return text;
}



function scrXY(d){
 scrX=0; scrY=0;divX=0;divY=0
 if( typeof( window.pageYOffset ) == 'number' ) {
  //Netscape compliant
  scrY = window.pageYOffset
  scrX = window.pageXOffset
 } else
 if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )  {
  //DOM compliant
  scrY = document.body.scrollTop
  scrX = document.body.scrollLeft
 } else
 if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
   //IE6 standards compliant mode
  scrY = document.documentElement.scrollTop
  scrX = document.documentElement.scrollLeft
 }
 while(d != null) {
  divX = divX+d.offsetLeft
  divY = divY+d.offsetTop
  d = d.offsetParent
 } 
}



var offsetX = 0 
var offsetY = 0 
var selectedObj 
var frontObj 
// set document-level event handlers 
 document.onmouseup = release;
 document.onmousedown = engage;  
// setting the z-order of an object 

function bringToFront ( obj ){
/*
 if (frontObj) frontObj.style.zIndex = 0    
 frontObj = obj 
 frontObj.style.zIndex = 10
*/
zindex++
obj.style.zIndex=zindex
}
 

// set global var to a reference to dragged element 

function get_zdiv(f){
if (f.id.indexOf('z_div')==0) return f; 
  while (f.parentNode != null || f.parentNode!='undefined'){
   f=f.parentNode;
   if (f.id.indexOf('z_div')==0) return f;
  }
  return null;
} 

function setSelectedObj(e){ 
  var divakt , ev,name;
  selectedObj=null;
  if (e) ev=e; else if (window.event) ev= window.event; else return;
  if (ev.srcElement) divakt=ev.srcElement; else if (ev.target) divakt=ev.target; else return;
  if (divakt){
   if (firstParent(divakt)){
    if (typeof(zmienwid)=='function') zmienwid(divakt); else  menu_akt.doMenu(divakt); 
     selectedObj = null; return
   }
   if (divakt.id && divakt.id.indexOf('pasek')==0) selectedObj = get_zdiv(divakt); else return;
   if (selectedObj !=null) bringToFront(selectedObj); 
  }  
}



 
// do the dragging (called repeatedly by onMouseMove) 


function dragIt (e) {
 if ( selectedObj ) { 
 var ev ;
   if (document.selection) document.selection.empty();
   else if (document.getSelection) {
      var currSelection = window.getSelection ();
        currSelection.removeAllRanges ();
 }
 
   if (e) ev=e; else if (window.event) ev=window.event;else return; 
   shiftTo ( selectedObj,  ev.clientX + offsetX  ,  ev.clientY + offsetY) 
   if (IE()) ev.returnValue=false;
   return false 
 } 
}

// positioning an object at a specific pixel coordinate 
function shiftTo ( obj, x, y ) {    
     obj.style.left = x+'px' 
     obj.style.top = y+'px'  
}


 
// set global vars and turn on mousemove trapping (called by onMouseDown) 



function engage (e) { 
var event;
  setSelectedObj (e) 
  if (selectedObj) {
        document.onmousemove = dragIt; 
        if (e) event=e; else event=window.event;
        offsetX =- event.clientX  + parseInt(selectedObj.style.left)
        offsetY =- event.clientY + parseInt(selectedObj.style.top) 
   }  
} 


// restore everything as before (called by onMouseUp) 
function release () { 
     if ( selectedObj ) { 
         document.onmousemove = null 
         selectedObj = null 
     } 
} 

var opa
var menuAkt

document.onmouseover=mouseover



function IE(){
 var c=navigator.appName
 return( c != 'Netscape' )
}

function zamknij(){
 var t=menuAkt.id.split('_'),z,t1,z1,b,x,i,j,ci,s ,typ;
 typ=t[0].substr(0,1);
 t[0]= typ + '2';
 t1=t.join('_');
 var c=document.getElementsByTagName('div'); 
 if (c !=null)
 for (i=0;i<c.length; i++)
 if (c[i].id!=''){
  ci=c[i]; 
  z1=ci.id; z=z1.split('_');
  if (z[0]==typ + '2'){
   z[0] = typ + '1';
   s=z.join('_');
   m_back(document.getElementById(s));
   if (t1==z1){
    if (ci.style.display == 'none' || ci.style.display=='')
    ci.style.display='block'; else ci.style.display='none';
   }
    else {
    x=t[0]; b=true;
    for (j=1; j<Math.min(t.length,z.length); j++ ){
      x += '_'+ t[j];
     if (x ==z1){
      ci.style.display= 'block'; b=false; break; 
     } else
      if (t[j] != z[j]) break;
    }
    if (b) ci.style.display='none'; 
   }
  } 
 }

 var idSplit=menuAkt.id.split('_') , typ=idSplit[0].substr(0,1), display=true;
 if (typ < 'k'){  
  idSplit[0] = typ + '2';
  display=document.getElementById(idSplit.join('_')).style.display=='block';
 }
 m_down(display)
}

 var typeOfMenu=0,currentImage, thePointerColor='#CCCCFF', theMarkColor='#FFCC99',theColor, currentColor ;


function setPointer(){
 var c;
 if (menuAkt==null) return;
 var t=getMAkt().id.split('_');  
 var theRowNum='check' + t[1];
 var c=document.getElementById(theRowNum);
 var check=getMAkt().id==menuAkt.id && c!=null;
 var b,  s=makeHex(currentColor);  
 if (s==theMarkColor.toLowerCase()) b=false; else b=true;
  m_down(b);
 if (check) c.checked=b;
}

function m_back(menu){
 var altMenu=menuAkt;
 menuAkt=menu;
 m_down(false);
 menuAkt=altMenu;

}


function m_down(wid){
 var f=getMAkt();
 var b=false;
 if (IE())
  if (f.filters.alpha){
   if (wid) opa=100; else opa=40;
   f.filters.alpha.opacity=opa; 
  }
 else b=true;
 else
  if (f.style.opacity){
   if (wid) opa=1; else opa=0,4; 
   f.style.opacity=opa; 
  } else b=true;
  if (b)
  if (typeOfMenu == 0){
   if (wid) currentColor=theMarkColor; else  currentColor=getColor(f.id);
   f.style.backgroundColor=currentColor;
  } 
}



function mouseout(){
 var f=getMAkt();
 if (f==false) return; 
 var b=false;
 if (IE())
  if (f.filters.alpha) f.filters.alpha.opacity=opa; else b=true;
   else
  if (f.style.opacity)  f.style.opacity=opa; else b=true;
  if (b && typeOfMenu == 0) f.style.backgroundColor=currentColor;   

 menuAkt=null;
 document.onmousedown = engage;
 document.onmouseout=null
}



function m_over(){
 var f=getMAkt();
 var classn=f.className;
 if (classn.indexOf('menu')==0) typeOfMenu=classn.substr(4); else typeOfMenu=0;
 if (IE()){
  if (f.filters.alpha){
   opa=f.filters.alpha.opacity
   f.filters.alpha.opacity=60 
   return;
  }
 }
 else {
  if (f.style.opacity){
   opa=f.style.opacity
   f.style.opacity=0.6
   return
  } 
 }

 if (typeOfMenu == 0) {
  currentColor=f.style.backgroundColor; 
  setColor(f.id,currentColor); 
  f.style.backgroundColor=thePointerColor;    
 }

}


function mouseover(e){
 var divakt,ev,m,name ;
 if (e) ev=e; else if (window.event) ev= window.event; else return;

  if (ev.srcElement) divakt=ev.srcElement; else divakt=ev.target;

  if (typeof(divakt.name)=='string')  name=divakt.name; 
   else if (typeof(divakt.id)=='string') name=divakt.id; 
    else name='';
 if (name.indexOf('1_') == 1) {
  menuAkt = document.getElementById(name);   
  bringToFront(menuAkt);
  m_over()
  document.onmousedown=zamknij
  document.onmouseout=mouseout
  return 
 } 

 m=indof(divakt);
 if (!m || !findRect(divakt)){
   mouseout();
   return;
 }
 document.onmousedown=null;
 if ( menuAkt && getMAkt().id != m.id){
   mouseout(); 
   menuAkt=m;
   m_over();
 } else if (!menuAkt){   
  menuAkt=m
  m_over();
 }
}

function findRect(f){
  var a=f.tagName.toLowerCase();
 if (a=='a' || a=='img') return false;
 var t=f.innerHTML;
  if (t.indexOf("<a ")>0 || t.indexOf('<img ')>0) return false;
 else return true; 
}


function indof(divakt){
 if (typeof(divakt.id)=='string' && divakt.id.indexOf('check')==0)  return divakt;
 var d=divakt;
 while (d!=null) {
  if (typeof(d.id)=='string' && d.id.indexOf('row_')==0) return d;
  d=d.parentNode;
 }
  return false;
}



function getMAkt(){
 if (!menuAkt) return false;
 var i=menuAkt.id;
 if (menuAkt.id.indexOf('check')==0) i='row_' + menuAkt.id.substr(5);
 return document.getElementById(i); 
}

function zaznacz(id,b){
 var f=document.getElementById(id).elements,i,x;
 for (i=0;i<f.length;i++) 
 if (f[i].id.indexOf('check')==0 ) {
  f[i].checked=b;
  if (x=document.getElementById('row_' + f[i].id.substr(5))){
    setColor(x.id,x.style.backgroundColor)
    menuAkt=x;
    m_down(b)
  }
 }
 menuAkt=null
}

function iszaznacz(f){
 var i,licz=0;
 if (typeof(f)=='string') f=document.getElementById(f).elements; else f=f.elements;
 for (i=0;i<f.length;i++) 
 if (f[i].id.indexOf('check')==0 && f[i].checked) licz++;
 return (licz);
}


var bgColors = new Array(), menuColors = new Array();

function setColor(ind,color) {
// zapami?tuje kolor bgColor elementu
 var i;
 if (ind.indexOf('1_') ==1) {
  i=ind.split('_');
  if (typeof(menuColors[i[1]]) == 'undefined' ) menuColors[i[1]]=color;
 }
 else {
  i=ind.substr(4);
  if (typeof(bgColors[i]) == 'undefined') bgColors[i]=color
 }
}

function getColor(ind){
 var color='#FFFF00'; ///  color b??du
  if (ind.indexOf('1_') ==1){
   i=ind.split('_');
   if (typeof(menuColors[i[1]]) != 'undefined') color =  menuColors[i[1]];
  }
  else{
   i=ind.substr(4);
   if (typeof(bgColors[i]) !='undefined') color=bgColors[i]
  }
 return color;
}


function makeHex(color){
 var c= color.toLowerCase();
 if (c.indexOf('#')==0) return c;
 c=c.substr(4,13).split(',');

 return RGBtoHex(parseInt(c[0]), parseInt(c[1]), parseInt(c[2]) );

}


function RGBtoHex(R,G,B) {
  return '#'+ toHex(R)+toHex(G)+toHex(B)}

function toHex(N) {
  if (N==null) return "00";
  N=parseInt(N); if (N==0 || isNaN(N)) return "00";
  N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
  return "0123456789abcdef".charAt((N-N%16)/16)
      + "0123456789abcdef".charAt(N%16);
}




var dt;
var day;
var month;
var year;
var dateF,dateNull;
/**
 * Opens calendar window.
 *
 * @param   string      calendar.php parameters
 * @param   string      form name
 * @param   string      field name
 * @param   string      edit type - date/timestamp
 */




/**
 * Formats number to two digits.
 *
 * @param   int number to format.
 */
function formatNum2(i, valtype) {
    f = (i < 10 ? '0' : '') + i;
    if (valtype && valtype != '') {
        switch(valtype) {
            case 'month':
                f = (f > 12 ? 12 : f);
                break;

            case 'day':
                f = (f > 31 ? 31 : f);
                break;

            case 'hour':
                f = (f > 24 ? 24 : f);
                break;

            default:
            case 'second':
            case 'minute':
                f = (f > 59 ? 59 : f);
                break;
        }
    }

    return f;
}

/**
 * Formats number to four digits.
 *
 * @param   int number to format.
 */
function formatNum4(i) {
    return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
}

/**
 * Initializes calendar window.
 */


function Calendar(field){
 var f, fakt;
 day=0; 
 if (typeof(field)=='string') {
   f=field.split(';');
   fakt=document.getElementById(f[0]); 
 } else {
  fakt=field;
  f=new Array();
 }

 if (dateF==fakt && document.getElementById('z_div3').style.visibility != 'hidden'){
  divout('z_div3'); 
  return;
 }
 dateF = fakt; 

 if (dateF.value){ 
     dt          =dateF.value;  
     year        = parseInt(dt.substr(0,4),10);
     month       = parseInt(dt.substr(5,2),10) - 1;
     day         = parseInt(dt.substr(8,2),10);
  }    
  if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0){
     dt      = new Date();
     year    = dt.getFullYear();
     month   = dt.getMonth();
     day     = dt.getDate();
     dt      = formatNum4(year) + "-" + formatNum2(month+1, 'month') + "-" + formatNum2(day, 'day');
   }
 if (f[1])
  dateNull=document.getElementById(f[1]);
  else dateNull=null;
  getScroll('', dateF, 'z_div3'); 
  init_Calendar();
}


 var month_names=new Array('sty', 'lut', 'mar', 'kwie', 'maj','cze','lip','sie','wrz','paĽ', 'lis', 'gru');   
 var day_names= new Array('pon', 'wto', '¶ro', 'czw', 'pi±', 'sob', 'nie');



function init_Calendar(){    
 var style, astyle;
        /* Moving in calendar */
 if (month > 11) {
   month = 0;
   year++;
 }
 if (month < 0) {
   month = 11;
   year--;
 }
    str = ""
    //heading table
    str += getMove('kalendarz podręczny');
    str += "<table style='width:100%;' border='1px'  bordercolor='#AAAAAA' cellspacing='0px' cellpadding='0px'><tr><th width='50%'>";
    str += '<a href="javascript:month--; init_Calendar();">&laquo;</a> ';
    str += month_names[month];
    str += ' <a href="javascript:month++; init_Calendar();">&raquo;</a>';
    str += '</th><th width="50%">';
    str +='<SELECT onchange="javascript:year=parseInt(this.value);init_Calendar();">';           
          for (i=year-20;i<year+20;i++){
            if (i==year)  sel='SELECTED'; else sel=''; 
            str +='<OPTION value='+i+' '+sel+'>'+i+'</OPTION>' ;
           }        
    str +='</SELECT>';   
    str += '</th></tr></table>';
    str += "<table style='width:100%;font-size:smaller; text-align:center' align='center' border='1px'  bordercolor='#AAAAAA' cellspacing='0px' cellpadding='0px'>";
    str += "<tr style='background-color:#EAEAEA'>";
    for (i = 0; i < 7; i++) {
         
        str += "<th>" + day_names[i] + "</th>";
    }
    str += "</tr>";
    var firstDay = new Date(year, month, 1).getDay()-1;
    firstDay = firstDay<0 ? 6 : firstDay 
    var lastDay = new Date(year, month + 1, 0).getDate();
    str += "<tr>";
    dayInWeek = 0;
    for (i = 0; i < firstDay; i++) {
        str += "<td>&nbsp;</td>";
        dayInWeek++;
    }
    for (i = 1; i <= lastDay; i++) {
        if (dayInWeek == 7) {
            str += "</tr><tr>";
            dayInWeek = 0;
        }

        dispmonth = 1 + month;        
        actVal = formatNum4(year) + "-" + formatNum2(dispmonth, 'month') + "-" + formatNum2(i, 'day');
        style='';astyle='';  

        if (dayInWeek==6)  astyle += "style='color:red'"; 

        if (actVal == dt) style += "border-color:#F00;border-width:2px; ";
        if (style!='') style= "style='" + style + "'";      

        style += "onmouseover=this.style.backgroundColor='#AAA' onmouseout=this.style.backgroundColor=''";

        str += "<td " + style + "><a href=\"javascript:returnDate('" + actVal + "');\"" + astyle + ">" + i + "</a></td>"
        dayInWeek++;
    }
    for (i = dayInWeek; i < 7; i++) {
        str += "<td>&nbsp;</td>";
    }
    str += "</tr></table>";
    var f=document.getElementById('z_div3');
    f.innerHTML=  str ;
}

/**
 * Returns date from calendar.
 *
 * @param   string     date text
 */

function returnDate(d) {
  dateF.value=d;
  if (dateNull) dateNull.checked=false;
  divout('z_div3'); 
  if (dateF.onchange) dateF.onchange();    
}

function checknull(fnull,f){
  if ( fnull.checked){
   var inp= document.getElementsByName(f);
   if (inp[0].tagName=='INPUT'){
     switch (inp[0].type){
      case 'radio':
      for (var i=0; i<inp.length; i++)
       inp[i].checked=false;
      break;
      case 'text':
       inp[0].value='';
       break;
      case 'select-one':
      case 'select':
      for (var i=0; i<inp.length; i++)
       inp[i].selected=false;   
      break;
     }
    } else
    if (inp[0].tagName=='TEXTAREA')
    inp[0].value=''; else {
      var opt= inp[0].options;
      for (var i=0; i<opt.length; i++)
       opt[i].selected=false;
     }
    fnull.checked =true;
 }
}



/*
  Zdjęcia uczniów

*/
function fotoon(f, id){
 var z='';
 var s="<div style='background-color:#CCC'><img src='" + id + "' style=\"width:100px; height:120px;" + z + "\"></div>"; 
 document.getElementById('z_div').style.width='100px'; 
 getScroll(s,f,'z_div');
}

var f_rob;
var rob;


function submit_arkusz(f,arkusz,id,ofset){
 if (typeof(f)=='string') f=document.getElementById(f)
 f.elements['arkusz'].value=arkusz
 switch (arkusz){
	case 1:
	 if (!iszaznacz(f)) {
		alert("Brak zaznaczonych elementów")
		return
	 }
	break

	case 11://filtry
	 f.action='filtry.php';

	break;
	case 13: //drukowanie
	 f.target='_blank'
	break
	case 100://edycja rekordu
	 f.elements['id'].value=id
	break;
	case 10:
	 if (!iszaznacz(f)) {
		alert("Brak zaznaczonych elementów")
		return
	 }
 	case 101: //del
	 if (window.confirm("Czy na pewno usun±ć?")){
	 f.elements['id'].value=id
	 } else return
	break;
	case 125: // insert_rows
	 f.elements['ins_rows'].value=document.getElementById(id).value 

	break;
	case 126://newoffset
	 f.elements['arkusz'].value=3
	 f.elements['limit'].value=id
	 f.elements['offset'].value=ofset
	break;
	case 127: //page
	 f.elements['arkusz'].value=3
	 f.elements['offset'].value=id;
	break;
	case 128: //sort
	 f.elements['arkusz'].value=3
	 f.elements['order'].value=id;
	break;
 }
 f.submit()	
}


function formatData(s){
 while (s.length>0 && s[0]=='0' ) s=s.substr(1);
 return parseInt(s);
}


function dateAdd(date,n){
 var a=date.split('-');
  var dzien= new Date(a[0], formatData(a[1])-1, formatData(a[2])+n);
  d=dzien.getFullYear() + '-' + formatNum2(dzien.getMonth()+1) + '-' + formatNum2(dzien.getDate());
 return d;
}

function checkInteger(number){
var  re = /[0-9]*/i;
 if (number.match(re) != number)    return false; 
 return true ; 
}


function checkData(f){
var data=f.value;
var a, b=true , i ;
 if (data != ''){ 
  a=data.split('-');
  if (a.length == 3){
     for  (i=0; i<3; i++) 
      if (checkInteger(a[i])== false) b=false;
  }  else b=false;
 } else return true;


 if (!b) alert('Zły format daty');
  else {  
  i=formatData(a[0]);
  if (i<1910   ||  i>2050 || formatData(a[1])>12 || formatData(a[2]) >31){
   alert('Niewłaściwa data');
   b=false; 
  }
 }
 if (!b && f.id){
  var alt=f.id.split('_');
  if (alt.length==4){
    alt[3]='1';
    alt=alt.join('_');
    if (document.getElementsByName(alt))
    f.value=document.getElementsByName(alt)[0].value;
  }
 }
 return b; 
}

function c_div(ddiv){
 var div=ddiv,width;
 var f=null, text='',  style='',newF=null, newText='',newStyle='',name='', shadow,
 interval=false, timeOut=false, filter='', krok=0, start='', type=false,top,left;
 div.innerHTML='';
 okno()
 var xx = new Array()

 this.init= function initDiv(df,dtext,dstyle){
  newF=df;
  newText=dtext;
  newStyle=dstyle;
  if (type=='ready') this.delate(); else start_cykl();
 }
,
 


 this.setshadow =function initshadow(newshadow){
alert(newshadow)
 shadow=newshadow
}



this.aktdiv=div; 
function start_cykl(){
  var i,f_h,t,divH,divW;
  clearT();
  text=newText
  f=newF;style=newStyle;
  if (t=searchId(style,'name','=')) name=t[0] 
  if (t=searchId(style,'div.style','='))
   for (i=0;i<t.length;i++)
   if (t[i]){
    var x=t[i].split(':')
    x='div.style.'+x[0]+ "='" + x[1] +"'"
    eval(x)     
   }
  type='in';
  delay()
}
  
 this.delateblick=function(){
  type=false;
  donediv()
 }

 this.delate=function(){
  if (type==false) donediv()
  clearT();
  type='out';
  var b=searchId(style,'delete','=');
  if (b.length>0) for (var i=0;i<b.length;i++) 
  if (b[i]!=div.id) divout(b[i]); 
  delay();
 }

 function delay(){
  if (f && f.nodeName == 'IMG' ){
   switch (imgName(f)){
    case 'help_open.png':
	f.src='themes/img/help_close.png'
	break;
    case 'help_close.png':
	f.src='themes/img/help_open.png'
	break;
   }
  }
  var b,time; 
  if (type==false) return;

  if (b=searchId(style,'delay.' + type ,'=')){
   time=searchId(b,'time',':');
   clearT()
   timeOut=setTimeout(body,time)  
  } else  body();
 }


function body(){
 clearT()
 if (type=='in'){
	scrXY(f)
	okno()
	if (name=='pophelp') scrY=scrY+32
	div.style.left=scrX.toString() + 'px'
	div.style.top=scrY.toString() + 'px'
	div.innerHTML=text
	if (div.style.pixelHeight) divH=div.style.pixelHeight; else if (div.offsetHeight) divH=div.clientHeight; else divH=0;
	if (div.style.pixelWidth) divW=div.style.pixelWidth; else if (div.offsetWidth) divW=div.offsetWidth; else divH=0;
	if (f != null){
	   if (f.style.pixelHeight) f_h=f.style.pixelHeight; else f_h=f.offsetHeight;  
		if (f.tagName=='AREA'){
		  var z = f.coords.split(',')
		  divY += parseInt(z[1])
		  divX += parseInt(z[0])
		  f_h = parseInt(z[3]) - parseInt(z[1])
		}

	   if (divY - scrY > divH) top=divY - divH ; else top= divY + f_h 
	   if (divX + divW > scrX + screenX) divX=Math.max(scrX,scrX+screenX-divW-20);     
	   left=divX;

	} else if (screenY>1200 || screenX>1400){
	  left=10
	  top=32	
	} else {
	   left =Math.max(scrX,scrX + (screenX-divW)/2)  
	   top=Math.max(scrY, scrY + (screenY -divH)/2) 
	}
	bringToFront(div);
 }
 efekt()
}


 
function efekt(){   
  allowshadow=false
  clearT()
  var b=searchId(style ,'efekt.'+ type,'=') ,time;
   if (b=='mix') dopopup();
   else
    if (b) pMoveHorizontal()
      else{
	div.style.top=top + 'px' 
	div.style.left=left + 'px'   
	div.style.visibility='visible'
	donediv();
    }
 }

 function dopopup(){
  div.style.top=top + 'px' 
  div.style.left=left + 'px'  
  if (IE()){
   var r=searchId(style,'filter','=')
   if (!r) r = Math.random()
   if (r<0.3)  filter = " wave(strength=2, freq=3, lightstrength=15, phase=45)";
    else if (r<0.6) filter =  " blur(direction=45 , strength=4)";
    else filter = '';

  }
 krok=searchId(style,'startkrok','=')
 if (krok)krok=parseFloat(krok) ; else if (Math.random()>0.5)  krok=0.1;  else krok = 0.9;
 var timekrok=searchId(style,'timekrok','=') 
 if (timekrok) timekrok=parseInt(timekrok) ; else timekrok=50;
interval=setInterval(do_popup, timekrok) 
}

 function do_popup(){
  div.style.visibility='visible'
  if (IE()) div.style.filter = "alpha(opacity=" + Math.round(100 * krok) + ")"+ filter;
  else div.style.opacity= krok; 
  krok = krok + 0.05; 
  var maxkrok=searchId(style,'maxkrok','=') 
  if (maxkrok) maxkrok=parseFloat(maxkrok) ; else maxkrok=0.9;

  if (krok>maxkrok) donediv();
 }

var delta , p_out;

 /* p_out=
9 - najazd z góry
10 - odjazd w dół

2 odjazd poziomy w prawą stronę

*/
 function pMoveHorizontal(){
  p_out=searchId(style, 'efekt.' + type ,'=');
  scrXY(div);   
  if (div.style.pixelWidth>0) width = div.style.pixelWidth; else width = div.offsetWidth;
  if (p_out<8){
	start=left
       div.style.top=top + 'px'
	if (p_out==2){
             //odjazd poziomy od f w prawą stronę 
		krok=0;
		delta=(scrX + screenX-start)/200;
	} else if (p_out==1){
             //najazd poziomy od lewej do f
		krok=13;
		delta=(scrX-width-start)/200;
	} else if (p_out==3){
		//odjazd poziome od f do lewego
		krok=0;
		delta=(scrX-width-start)/200;
	}
  } else {
	div.style.left=left + 'px'
	if (p_out==9){
		start=top;
		delta = (scrY - div.offsetHeight-start)/200;
		krok=13;
	} if (p_out==10){//odjazd w dół
		krok=0;
		delta=(scrY + screenY-div.offsetTop)/200;
	}
  } 
  pMoveH();
  interval =setInterval(pMoveH,20);
}

function pMoveH(){
 var d= delta * krok * (krok + 1), z = start + parseFloat(d),b=false;
 if (p_out<8){
	div.style.left = z +'px';
	if (p_out == 2){
	 krok=krok+1;
	 if (krok > 13) b=true     
	} else if (p_out == 1){
	 krok = krok - 1;
	 if (krok < 0) b=true
	} else if (p_out == 3){
	 krok = krok + 1;
	 if (krok > 13) b=true      
	}
  } else {
	div.style.top= z + 'px';
	if (p_out == 9){
	krok = krok - 1;
	if (krok < 0)  b=true     
   } else 
   if (p_out==10){
	krok=krok+1;
	if (krok>13) b=true
   }
  }
  if (b) donediv(); else  div.style.visibility='visible'
 }

 function donediv(){

  clearT();
  document.body.style.overflow='auto'
  if (type=='out' || type==false){
   type=false;
   div.style.visibility='hidden'; 
   div.innerHTML=''
   if (text!=newText) start_cykl();    
   } else {
   type='ready'; 
  }
  allowshadow=true
 }

 function clearT(){
  if (timeOut) clearTimeout(timeOut);
  if (interval)clearInterval(interval); 
  interval=false;timeOut=false;
 }

} // koniec obiektu

function trim(s){
 var i
 while(s.length>0 && s[s.length-1]==' ') s=s.substr(0,s.length-1)
 while(s.length>0 && s[0]==' ') s=s.substr(1,s.length-1)
 return s
}

function okno(){
var w=window.parent
  if (w.parent.innerWidth){
   screenX = w.parent.innerWidth;
   screenY = w.parent.innerHeight;
   screenX = window.innerWidth;
   screenY = window.innerHeight;
  } else
    if (w.document.documentElement){
    var d= w.document.documentElement;
    if (d){
     screenX=d.clientWidth
     screenY=d.clientHeight
    }
  }
else
  if (document.body && document.body.offsetWidth){
   screenX=w.document.body.offsetWidth
   screenY=w.document.body.offsetHeight 
  } 
}


function appname(){
 if (document.getElementById('ie')) document.getElementById('ie').value=navigator.appName
}



