    function getPageSize() {	        
	     var xScroll, yScroll;		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}
  
  var initWidth=0
  var initHeight=0
  var initX=0
  var initY=0
  var openBox=''
  var openId=''
  var open=0
  
    function makeBoxPrev(source,updateId){
       
       var arrayPageSize = getPageSize()                      
       $('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' })
       new Effect.Appear($('overlay'), { 
        duration: 0.2,
        from: 0.0, to: 0.8,        
        })                 
       var rozmiary = source.getDimensions(source)
       initWidth = rozmiary.width
       initHeight = rozmiary.height  
       if(openBox!=''){
            revertPosition($(openBox))          
          }
        openBox = source.readAttribute('id')
        openId = updateId
                                                
       source.makePositioned(source)                           
       source.setStyle('z-index:99')
       $('bodybox'+updateId).empty()
       source.morph('width:703px;left:-430px;')        
       new Ajax.Updater(source,'/menu/readbox/'+updateId,{        
              asynchronous:true,
              evalScripts:true,              
              onComplete:new Effect.Appear(source, { 
                  duration: 1.0,
                  from: 0.0, 
                  to: 1.0,
                  afterUpdate:function(){ open=1 }        
                  })                            
       })
//       Event.observe(document, 'keypress', function(event){ if(event.keyCode == Event.KEY_ESC && open==1 ){alert(open); revertPosition(source);}});                                  
    }
    
    

    
  
  function revertPosition(source){  
    //$('overlay').hide().observe('click', (function() { this.end(); }).bind(this));
    $('overlay').fade();
    //$('bodybox'+openId).empty();
    source.empty();
    source.undoPositioned()
    //source.setStyle('width:'+initWidth+'px;height:'+initHeight+'px;left:720px;')    
    source.setStyle('width:'+initWidth+'px;height:'+initHeight+'px')
    new Ajax.Updater(source,'/menu/readlitlebox/'+openId,{
    asynchronous:true,
    evalScripts:true,
    onComplete: new Effect.Appear(source, { 
                  duration: 1.0,
                  from: 0.0, 
                  to: 1.0        
                  })
     })                   
    
    //source.down().setStyle('margin-top:20px;');
    openBox=''
    openId=''
    open=0
  }


function a_blur() {
	
	var arr = document.getElementsByTagName( 'a' );
	for( i=0; i<arr.length; i++ ) {

	arr[i].setAttribute('onFocus', 'blur()');
	
	}
}


function validate(f){
var v,i,e
for(i=0;e=f[i++];)
  if(v=window[e.getAttribute('valid')]){   
   if(!v(e.value))
    {    
    alert(e.getAttribute('alert'));e.focus();return 1}
    }
}

function niepuste(x){return x>''}
function ismail(e){return (/^[\w\.-]{2,}@[\w\.-]+\.[a-z]{2,5}$/i.test(e))||(e=='')}
function noempymail(e){return (/^[\w\.-]{2,}@[\w\.-]+\.[a-z]{2,5}$/i.test(e))>''}
function isnumopt(x){return x==~~x}
function isnum(x){return x==parseInt(x)}
function iscnum(x){return (/[\d]/.test(x))>''}
function istel(e){return (/\+[0-9]{11,18}/.test(e))>''}

function submitForm(){
  if(!validate($('contact').elements)) window.document.contact.submit();
}

function clearfield(element,wartosc){
  if(element.value==wartosc){
      element.value = ""
      element.style.textAlign='left';      
      element.style.color="#0d386f";
    }
}

function submfield(element,wartosc){
  if($('fraza').value!=wartosc && $('fraza').value!=''){
  $(element).submit();
  }
}

function submfield2(element){
  if($('fraza2').value!=''){
  $(element).submit();
  }
}


function subscribe(element,co){
 if($('newsletterId').value!=''){
 $('newsletterAction').value=co
  $(element).submit()
  }
}

function checkForm(element){
ns = wymagane.split(",")
for(a=0;a<ns.length;a++){
tm = ns[a]
  $(element).elements[tm].style.border = "1px solid #CCC"
}
}
// onsubmit="return(!validate(this.elements))"
function submitform(element){
  ns = wymagane.split(",")
    dalej = false;
    for(a=0;a<ns.length;a++){
      tm = ns[a]
      //alert(tm)
      dalej = niepuste($(element).elements[tm].value)        
   }
  
  if(dalej) $(element).submit();
  else alert(subalert)
}


/* zmiana zdjec na stronie glownej */

var l = 0
var max=0
var avg=0
var stotalSecs = 5
var si = stotalSecs
var simgarr = new Array()
var nextImage = new Image;

function slidercount() {	
	if(stotalSecs != null) timerId = setTimeout("slidercount()", 1000)
	if(si>0) {		
  		si -= 1
 	} else {
   		imageslider()
   		si=stotalSecs
    }    
}

function imageslider(){
  $('imageholder').src = nextImage.src       
  l++
  if(l==simgarr.length) l=0
  nextImage.src = simgarr[l];	
}

var logonw=false

function switchLogon(){
 if(logonw!=true){
  $('logonramka').show()
    logonw = true
  }else{
  $('logonramka').hide()
    logonw = false
  }

}


function init() {
	var lis = $('slide-images').getElementsByTagName('li');
	for( i=0; i < lis.length; i++){
		if(i!=0){
			lis[i].style.display = 'none';
		}
	}
	end_frame = lis.length -1;
	start_slideshow(start_frame, end_frame, delay, lis);
  		
}

function start_slideshow(start_frame, end_frame, delay, lis) {
	setTimeout(fadeInOut(start_frame,start_frame,end_frame, delay, lis), delay);
}


function fadeInOut(frame, start_frame, end_frame, delay, lis) {
	return (function() {
		lis = $('slide-images').getElementsByTagName('li');
		Effect.Fade(lis[frame]);
		if (frame == end_frame) { frame = start_frame; } else { frame++; }
		lisAppear = lis[frame];
		setTimeout("Effect.Appear(lisAppear);", 0);
		setTimeout(fadeInOut(frame, start_frame, end_frame, delay), delay + 1850);
	})
	
}
