var a1='close';
var a2='close';
var a3='close';
var a4='close';
var a5='close';
var time;
function openMenu(id,num){
if(num==1 && a1=='close'){
a1='open';
$(id).style.width='117px';
$(id).appear({duration: 0.3});
return false;
}
if(num==2 && a2=='close'){
a2='open';
$(id).style.width='155px';
$(id).appear({duration: 0.3});
return false;
}
if(num==3 && a3=='close'){
a3='open';
$(id).appear({duration: 0.3});
return false;
}
if(num==4 && a4=='close'){
a4='open';
$(id).appear({duration: 0.3});
return false;
}
if(num==5 && a5=='close'){
a5='open';
$(id).appear({duration: 0.3});
return false;
}
}

function closeMenu(id,num){
if(num==1)
a1='close';
if(num==2)
a2='close';
if(num==3)
a3='close';
if(num==4)
a4='close';
if(num==5)
a5='close';
time=setTimeout('checkMenu("'+id+'","'+num+'")', 300);
}

function checkMenu(divId,num){
if(num==1){
if(a1=='close'){
$(divId).style.display='none';
$('img1').src='images/home1.png';
return false;
}
}
if(num==2){
if(a2=='close'){
$(divId).style.display='none';
$('img2').src='images/games1.png';
return false;
}
}
if(num==3){
if(a3=='close'){
$(divId).style.display='none';
$('img3').src='images/profile1.png';
return false;
}
}
if(num==4){
if(a4=='close'){
$(divId).style.display='none';
$('img4').src='images/galery1.png';
return false;
}
}
if(num==5){
if(a5=='close'){
$(divId).style.display='none';
$('img5').src='images/other1.png';
return false;
}
}
}

function openMenu2(id,num){
if(num==1)
a1='open';
if(num==2)
a2='open';
if(num==3)
a3='open';
if(num==4)
a4='open';
if(num==5)
a5='open';
}

var Imgi = new Array();                         
var Bledy = 0;                                     
var preloadTimer;                            
var preloadOK = ''       
var preloadBlad = ''            
                                                                                                       
function preload(url) {                                               
   if (document.images) {                                             
      var i = Imgi.length;                                            
      Imgi[i] = new Image();                                          
      Imgi[i].onerror = preloadOnError;                               
      Imgi[i].src = url;                                              
   }                                                                  
}                                                                     
                                                                      
   
function preloadOnError() {                                           
   Bledy++;                                                           
}                                                                     
                                                                      
function preloadStart(ok, blad) {                                     
   preloadOK = ok;                                                    
   preloadBlad = blad;                                                
   preloadCheck();                                                    
}                                                                     
                                                                      
                         
function preloadCheck() {                                             
   var i=0;                                                           
   var l=Imgi.length;                                                 
   var b = Bledy;                                                     
                                        
   while (i<l && Imgi[i].complete || b-->0) i++;                      
   if (i>=l)     
      if (Bledy==0)                                                   
         eval(preloadOK)                                              
      else                                                            
         eval(preloadBlad)                                            
   else                                 
      preloadTimer = setTimeout('preloadCheck()',100);                
}

preload('images/home1.png');
preload('images/home2.png');
preload('images/games1.png');
preload('images/games2.png');
preload('images/profile1.png');
preload('images/profile2.png');
preload('images/galery1.png');
preload('images/galery2.png');
preload('images/other1.png');
preload('images/other2.png');
preload('images/homeSub.png');

function checkValue(id,text,type){
if(type==1){
if($(id).value==text)
$(id).value='';
}
if(type==2){
if($(id).value=='')
$(id).value=text;
}
}

function calendar(month,year,dir){
  var ajaxRequest;
	var postBody = 'action=calendar&month='+month+'&year='+year+'&dir='+dir;
	new Ajax.Request('ajax/action.php', {method:'post', postBody:postBody, onSuccess: 
			function(t){
			
			$('cal').innerHTML=t.responseText;
     }
		});

}

function clearAll(){
$('pool').innerHTML='<option value="">Basen</option><option value="SCM">25m</option><option value="LCM">50m</option>';
$('style').innerHTML='<option value="">Styl</option>';
$('points').value='';
$('time').value='';
$('point').innerHTML='';
$('time').innerHTML='';
}

function getSex(){

if($('sex1').checked)
return 'M';
else 
return 'F';
}

function getDistance(pool,sex){
  if(pool!=''){
  var ajaxRequest;
	var postBody = 'action=getDistance&pool='+pool+'&sex='+sex;
	new Ajax.Request('ajax/action.php', {method:'post', postBody:postBody, onSuccess: 
			function(t){
			$('points').value='';
      $('time').value='';
      $('point').innerHTML='';
      $('time').innerHTML='';
			$('style').innerHTML=t.responseText;
     }
		});
}
else{
$('style').innerHTML='<option value="">Styl</option>';
$('points').value='';
$('time').value='';
$('point').innerHTML='';
$('time').innerHTML='';
}
}

function clearData(){
$('points').value='';
$('time').value='';
$('point').innerHTML='';
$('time').innerHTML='';
}

function getCount(){
  if($('points').value){
  var kind='points';
  var x=$('points').value;
  }
  if($('time').value){
  var kind='time';
  var x=$('time').value;
  }
  var id=$('style').value;
  var ajaxRequest;
	var postBody = 'action=getCount&id='+id+'&kind='+kind+'&x='+x;
	new Ajax.Request('ajax/action.php', {method:'post', postBody:postBody, onSuccess: 
			function(t){
			if(kind=='points')
			$('tim').innerHTML=t.responseText;
			else
			$('point').innerHTML=t.responseText;
     }
		});
}

function sendSelect(){
if($('pool').value!='' && $('sex').value!='' && $('age').value!='' && $('type').value!='')
location='rekordy.html?pool='+$('pool').value+'&sex='+$('sex').value+'&age='+$('age').value+'&type='+$('type').value;

}

function showPhoto(photo,where,show){
if(show=='1'){
$(photo).style.display='';
}
else{
$(photo).style.display='none';
}
}

function select2(item,order,sort){
 if(item==''){
 location='index.php?id=2&order='+order+'&sort='+sort;
 }
 else{
 var ajaxRequest;
 var postBody = 'action=select2&item='+item;
 new Ajax.Request('../ajax/action.php', {method:'post', postBody:postBody, onSuccess: 
  function(t){
  $('filtr').innerHTML=t.responseText;
  }
 });
 }
}

function select3(item,order,sort){
 if(item==''){
 location='index.php?id=3&order='+order+'&sort='+sort;
 }
 else{
 var ajaxRequest;
 var postBody = 'action=select3&item='+item;
 new Ajax.Request('../ajax/action.php', {method:'post', postBody:postBody, onSuccess: 
  function(t){
  $('filtr').innerHTML=t.responseText;
  }
 });
 }
}

function select4(item,order,sort){
 if(item==''){
 location='index.php?id=7&order='+order+'&sort='+sort;
 }
 else{
 var ajaxRequest;
 var postBody = 'action=select4&item='+item;
 new Ajax.Request('../ajax/action.php', {method:'post', postBody:postBody, onSuccess: 
  function(t){
  $('filtr').innerHTML=t.responseText;
  }
 });
 }
}

function select5(item,order,sort){
 if(item==''){
 location='index.php?id=5&order='+order+'&sort='+sort;
 }
 else{
 var ajaxRequest;
 var postBody = 'action=select5&item='+item;
 new Ajax.Request('../ajax/action.php', {method:'post', postBody:postBody, onSuccess: 
  function(t){
  $('filtr').innerHTML=t.responseText;
  }
 });
 }
}

function selectDate(date){
if(date){
var ajaxRequest;
 var postBody = 'action=selectDate&date='+date;
 new Ajax.Request('../ajax/action.php', {method:'post', postBody:postBody, onSuccess: 
  function(t){
  $('date2').innerHTML=t.responseText;
  }
 });

}
}

function envelope(){
$('info').style.display='none';
if($('message').style.display=='none')
Effect.SlideDown('message',{duration: 1,afterFinish: function() { $('mess').style.display=''; }});
else
Effect.SlideUp('message',{duration: 1,afterFinish: function() { $('mess').style.display='none'; }});
}

function sendMessage(id){
if($('from').value!='' && $('from').value!='Od...' && $('content').value!='' && $('content').value!='Treść wiadomości'){
  var ajaxRequest;
 var postBody = 'action=sendMessage&from='+$('from').value+'&content='+$('content').value+'&id='+id;
 new Ajax.Request('ajax/action.php', {method:'post', postBody:postBody, onSuccess: 
  function(t){
  if(t.responseText=='ok'){
  Effect.DropOut('message',{duration: 1,afterFinish: function() { Effect.BlindDown('info',{duration: 1, afterFinish: function() { clearMess(); }}); }});
  setTimeout(function() { $('info').style.display="none"; },5000)
  }
  }
 });
}
}

function clearMess(){
$('from').value='Od...';
$('content').value='Treść wiadomości';
}
