// JavaScript Document
ajaxHandler= function(fid,lang,type){
    this.lang=lang;
    this.type=type;
    this.staticPage='/tmpl/ajax/'
    this.ajaxPage='/ajax';
    this.loginPage='/login';
    this.fitID=fid;
    this.reservID=0;
    this.unregUser="";
    this.regCancel=0;
    this.emailAdd=0;
  }
ajaxHandler.ajaxObjects=[];

//tato funkce smaze vsechny existujici XMLHttpRequest objekty kters jous nebi byly aktulani
  //je volana pred novou sadou ajax pozadavku aby se zabranovalo zbytecnemu zobrazovani a zpracovani vysledku ktere budou brzo prepsany	
ajaxHandler.clearAjaxRequests=function(){
      for(args in window.ajaxObjects){
          //alert(window.ajaxObjects[args]+"AJAX");
          window.ajaxObjects[args].abort();
        }
      $('#LoadingMessage').css('display','none');
      window.ajaxObjects=[];
    }

ajaxHandler.prototype.setRefLinkForLoging=function(){
    //alert('neco');
    $('#currSetting').attr("value",location);  
    //$('#currSetting').attr("value",location);  
  }
//Funkce ktera odebira krizove reference u dynamicky vytarenych elementu aby nedocahzelo k unikum pameti
  //volano pri zruseni techot elementu pred nactenim nove sady dynamicky generovanych elementu  
ajaxHandler.destructCrossRef=function(){
      //alert('destruct');
      $('#BigCalContainer').find('img').unbind('click');
      $('#BigCalContainer').find("input[type='checkbox']").unbind('click');
      $('#BigCalContainer').find('.fitness').unbind('mouseover');
      $('#BigCalContainer').find('.fitness').unbind('mouseout');
      $('#BigCalContainer').find('.fitness').unbind('click');
      
       $('.unreg').unbind('click');
      $('.reserv').unbind('click');
			$('#neregReservForm').unbind('click');
			$('.reservButtonNotReg').unbind('click');
      $('.stornoReserv').unbind("click");
      $('.closeIcon').unbind('click');
      $('.reservButton').unbind('click');
      $('.UnReservButton').unbind('click');
      $('.reservButtonNotReg').unbind('click');
    }  

ajaxHandler.prototype.destruktoPopWindowHandlers=function(){
     $('.reservButton').unbind("click");
     $('.stornoReserv').unbind("click");
      $('.UnReservButton').unbind("click");
  }
    
//validace e-maliove adresy  
ajaxHandler.prototype.checkEmail=function(str) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)){
    return (true)
    }
    else {return false};   
    } 
    
/*
		*funkce obsluhujici inicializaci udalosti ktere se maji navazat na dynamicky vytvarene elementy deniku
		*vstu - flag - urcuje jaky type nahledu na denik je aktualni (tyden mesic den)		
    */
ajaxHandler.prototype.initial=function(flag){
			//alert(flag);
			var _this=this;
			//pro den a denik
			if(flag=='day'){
			//pridam mouseover a mouseout
				$('#mainDiary').find(".fitness").bind("mouseover",function(){$(this).css('cursor','pointer');});
				$('#mainDiary').find(".fitness").bind("mouseout",function(){$(this).css('cursor','auto');});
			//pokiud ma faze prilis malou vysku tak pridam tlacitko ktere umoznu dynamicke (animovane) rozbalnei faze
      	var faze=$('#mainDiary').find(".fitness").each(function(){
					if(parseInt($(this).css('height'))<70){
					//obrazek ktery obsluhuje udalot rozbaleni
						var rozbal='<img  style="position:absolute;top:2px;right:5px;" src="/obr/8.gif"/>';
						$(this).append(rozbal);
						//udalost rozbaleni
						$(this).find('img').bind('click',function(e){
							var fazeDIV=this.parentNode;
							var fazeHeight=$(fazeDIV).css('height');
							$(fazeDIV).css('z-index','20');
							$(fazeDIV).css('overflow','auto')
							//animace rozbaleni
              $(fazeDIV).animate({
								height:'100px'},600);
							$(this).css('display','none');
							//na mouse leave fazy zase zabalim do pocaenich romeru
							$(fazeDIV).bind('mouseleave',{Fh:fazeHeight},function(e){
								$(fazeDIV).css('overflow','hidden');
                $(this).animate({
									height:e.data.Fh
									},600)
									this.scrollTop=0;
									var _this=this;
									//po zabaleni zase pridam rozbalovai tlactiko
								setTimeout(function(){$(fazeDIV).css('z-index',10);
								  	$(_this).find('img').css('display','inline')
                    },600);
								//$(this).unbind('mouseleave');
								})
							if(e.stopPropagation)e.stopPropagation();
							else e.cancelBubble=true;						
							return true
							});
						}
					else $(this).css('overflow','auto');
					});
					//na kliknuti prejud na detail faze
				$('#mainDiary').find('.fitness').bind('click',function(){
					var pom=$(this).attr('id');
					$('#kalendarbut').get(0).calendarType='day';
					$('#calButtons').hide();
					$('#fazeButtons').show();
					_this.lekceID=pom;
					_this.ajaxRequest('detail',cal.CalConector.date);
					//cal.callHandler();
				})
			}
		 
      // inicializace udalosit pro mesic
			if(flag=='month'){
			//pri kliknuti na den se prepnu na tento den
				$('#mainDiary').find("td[class='ActualMonth']").bind("click",function(){
            var pom=$('#mainDiary').find('tbody').find('td').index(this);
            //nastavim spravny den v kalendari
				    cal.CalConector.getMonthDay(pom)
				    cal.callHandler()}
        );
        // pokud je dednik v rezimu plan tak se pri kliknuti na fazi prepnu primo na detail faze
       
      $('#mainDiary').find('.fitness').bind("click",function(e){
            	$('#LoadingMessage').show();
					    var fazeOvner=this.parentNode.parentNode;  
					    var ind=$('#mainDiary').find('tbody').find("td").index(fazeOvner)
					     $('#kalendarbut').get(0).calendarType='month';
					     cal.CalConector.getMonthDay(ind) 
					    var pom=$(this).attr('id');
					              //nacteni detailu faze
                        //inicializace pormenych calendarConectoru pro opakovane nacteni tehoz dne
					    cal.CalConector.BeforeMonth=null;
					    cal.CalConector.BeforeDay=null;
              cal.CalConector.BeforeWeekNum=null;
              cal.CalConector.BeforeWeekMonth=null;
              cal.CalConector.BeforeWeekYear=null;
              cal.CalConector.BeforeDayMonth=null;
              cal.CalConector.BeforeDayYear=null;
              $('#kalendarbut').get(0).calendarType='month';
					    $('#calButtons').hide();
					    $('#fazeButtons').show();
					     _this.lekceID=pom;
					     _this.ajaxRequest('detail',cal.CalConector.date);
              e.cancelBubble = true;
	            if (e.stopPropagation) e.stopPropagation();                
                      })               
				$('#mainDiary').find("td[class='ActualMonth']").bind("mouseover",function(){$(this).css('cursor','pointer');$(this).addClass('actualHighlight')});
				$('#mainDiary').find("td[class='ActualMonth']").bind("mouseout",function(){$(this).css('cursor','auto');$(this).removeClass('actualHighlight')});
			}
			 // inicializace udalosit pro tyden
			if(flag=='week'){
			  // alert( cal.CalConector.date)
				$('.weekFazeContainer').bind("click",function() {
					var pom=$('.weekFazeContainer').index(this);
					cal.CalConector.getWeekDay(pom);
					//alert(pom);
					cal.callHandler();					
				});
			  // pokud je dednik v rezimu plan tak se pri kliknuti na fazi prepnu primo na detail faze
       
				$('#mainDiary').find('.fitness').bind('click',function(e){
			         var fazeOvner=this.parentNode;
				        var ind=$('.weekFazeContainer').index(fazeOvner);
					     cal.CalConector.getWeekDay(ind);
               var pom=$(this).attr('id');
					      cal.CalConector.BeforeMonth=null;
					      cal.CalConector.BeforeDay=null;
                cal.CalConector.BeforeWeekNum=null;
                cal.CalConector.BeforeWeekMonth=null;
                cal.CalConector.BeforeWeekYear=null;
                cal.CalConector.BeforeDayMonth=null;
                cal.CalConector.BeforeDayYear=null;
                $('#kalendarbut').get(0).calendarType='week';
					     $('#calButtons').hide();
					     $('#fazeButtons').show();
					     _this.lekceID=pom;
					     _this.ajaxRequest('detail',cal.CalConector.date);
					       e.cancelBubble = true;
	             if (e.stopPropagation) e.stopPropagation();
				  })
         // pozor, tohle funguje, ALE - je třeba ještě ošetřit návrat na výchozí pohled (při stisku "zpět na...") a taky ošetřit situaci, kdy je zobrazen TRÉNIKOVÝ PLÁN
				
				$('.weekFazeContainer').bind("mouseover",function(){$(this).css('cursor','pointer');$(this).addClass('actualHighlight')})
				$('.weekFazeContainer').bind("mouseout",function(){$(this).css('cursor','auto');$(this).removeClass('actualHighlight')});
			}
			if(flag=='detail'){
			     //nastavim priznak ze chci rusit rezervaci na 0 - to je ze ho nepouzivam
			     this.regCancel=0;
			     //a jeste resetnu email
			     this.emailAdd=0;
			     //a taky reservID na 
			     this.reservID=0;
			     //reset unreg uziv
			     this.unregUser='';
			     //unbin section pro vsechni co dynamicky binduju
			    
			    
			    //a ted dynam navzu
          $('.reserv').bind('click',function(e){
                 scrollXY=getScrollXY();
                 var innerOffset=[140,e.clientY+scrollXY[1]-257];
                  $('#rezervDetailWindow').css("top",innerOffset[1]);
                   $('#rezervDetailWindow').css("left",innerOffset[0]);
                $('#rezervDetailWindow').css("display","block");
                _this.reservID=this.id; 
                _this.regCancel="none";
                //skryji info pro odhlaseni
                $('#unsubscribeUser').hide(); 
                //pokud je uzivatel prihlasen
                if(window.userLogged){
                  $('#loggedUserReserv').css("display","block"); 
                  $('#notLoggedReserv').css("display","none"); 
                  var ergoID=$(this).parent().prev().html();
                  var lekceName=$('#lekceNazev').html();
                  $('#ergoNum').html(ergoID);
                  $('#lekceName').html(lekceName);
                  //ted si tu navazu potrebne udalosti pro odeslani rezervace
                  $('.reservButton').bind("click",function(){
                        $(this).unbind('click');
                        $('.stornoReserv').unbind("click");
                        $('#rezervDetailWindow').hide();     
                         _this.ajaxRequest('detail',cal.CalConector.date);                 
                      });
                  //zruseni rezervace
                  $('.stornoReserv').bind("click",function(){
                         $('.reservButton').unbind("click");
                         $('#unsubscribeUser').hide();
                         $('#rezervDetailWindow').css("display","none");
                         $(this).unbind('click');
                        });                     
                }
                //jinak nabidka s presmerovanim naprihlaseni
                else{
                  $('#loggedUserReserv').css("display","none"); 
                  $('#notLoggedReserv').css("display","block"); 
                  //presmerovani na loggin page
                  $('#logginHref').bind('click',function(){
                      var res=location.href.split("/");
                      var add1=res[3];
                      var add2=res[4].split('#')[0]
                      add1=add1+'/'+add2;
                      var pom=_this.loginPage+'?currPage='+escape(add1)+'&currSetting='+escape(location.hash);
                      location=pom;
                    }) 
                  }
              })
              
            //obsluha azvirani vyskakovacich oken
            $('.closeIcon').bind('click',function(){
                   if($(this).parent().hasClass('RegMessage')){
                      $(this).parent().hide();
                      }
                    else{
                      $(this).parent().parent().hide();
                      }
                   $('#neregUserLogin').hide();
                   $('#unsubscribeUser').hide(); 
                   $('#notLoggedReserv').css("display","none");
                   $('#noName').hide();
                   $('#noemail').hide();
                   $('#wrongemail').hide();
                   $('#name').attr("value","");
                    $('#email').attr("value","");
                   $('.reservButton').unbind("click");
                   $('.stornoReserv').unbind('click');
                   //jeste nastavim sprave ikonku pro rozbaleni registrace nereg uyivatele
                   var pom1=$('#neregReservForm').attr('langattr');
                   var pom2=$('#neregReservForm').attr('title');
                  $('#neregReservForm').attr('title',pom1);
                  $('#neregReservForm').attr('alt',pom1);
                  $('#neregReservForm').attr('langattr',pom2);
                  $('#neregReservForm').attr("src",'../obr/knob_forward.png');
                  $('#neregReservForm').get(0).show=false;
                  _this.reservID=0;
              })
            //moznost zrusit registraci
            //je jen pro registrovane uzivatele
            $('.unreg').bind('click',function(e){
                if(window.userLogged){
                  scrollXY=getScrollXY();
                  var innerOffset=[140,e.clientY+scrollXY[1]-257];
                  $('#rezervDetailWindow').css("top",innerOffset[1]);
                   $('#rezervDetailWindow').css("left",innerOffset[0]);
                  $('#rezervDetailWindow').css("display","block");
                  $('#unsubscribeUser').show();
                  $('#loggedUserReserv').hide(); 
                  $('#notLoggedReserv').hide();
                  
                  //nastavim pro predani na server
                  _this.reservID=this.id; 
                  _this.regCancel="cancel";
                  //potvrzuji zruseni reg
                    $('.UnReservButton').bind('click',function(){
                        $(this).unbind('click');
                        $('.stornoReserv').unbind("click");
                        $('#rezervDetailWindow').hide();     
                        _this.ajaxRequest('detail',cal.CalConector.date);  
                        })
                        //storno
                    $('.stornoReserv').bind("click",function(){
                         $('.UnReservButton').unbind("click");
                         $('#unsubscribeUser').hide();
                         $('#rezervDetailWindow').css("display","none");
                         $(this).unbind('click');
                         _this.regCancel=0;
                        });                 
                  }
              })
           //neregistorvany uzivatel   
          //prihlaseni neregistrovaneho uzivatele    
          $('#neregReservForm').bind('click',function(){
              //prehazovani popisu u obr
              var pom1=$(this).attr('langattr');
              var pom2=$(this).attr('title');
              $(this).attr('title',pom1);
              $(this).attr('alt',pom1);
              $(this).attr('langattr',pom2);
              
              if(!this.show){
                this.show=true
                $(this).attr("src",'../obr/knob_download.png');
                $('#neregUserLogin').show();
                $('.reservButtonNotReg').bind('click',function(){
                    $('#noName').hide();
                    $('#noemail').hide();
                    $('#wrongemail').hide();
                    var chyba=false;
                    if($('#name').attr("value").trim()==''){
                      $('#noName').show();
                      chyba=true;
                    }
                    if($('#email').attr("value").trim()==''){
                      $('#noemail').show();
                      chyba=true;;
                    }
                    else if(!_this.checkEmail($('#email').attr("value").trim())){
                      $('#wrongemail').show();
                      chyba=true;
                      }
                    if(chyba) return;
                     _this.unregUser=$('#name').attr("value").trim();
                     _this.emailAdd=$('#email').attr("value").trim();
                     _this.ajaxRequest('detail',cal.CalConector.date); 
                       //vse skryt
                       $('#neregUserLogin').hide();
                      $('#unsubscribeUser').hide(); 
                      $('#notLoggedReserv').css("display","none");
                      $('#noName').hide();
                      $('#noemail').hide();
                      $('#wrongemail').hide();
                      $('.reservButton').unbind("click");
                      $('.stornoReserv').unbind('click');
                    
                    })
                  }
                else{
                  this.show=false
                  $(this).attr("src",'../obr/knob_forward.png');
                   $('#neregUserLogin').hide();
                  $('.reservButtonNotReg').unbind('click');
                  $('.neregErr').hide();
                  }
              })
        }
		}
		
		
		
		/*genericka funkce obsluhujici ajax dotazy
  * vstup type - typ deniku (mesic tyden den) 
  * date - datum   
   */
ajaxHandler.prototype.ajaxRequest=function (type,date){
		  //alert(date+'AJXA')
		  //ziskam session ID pokud by nebyly k dispozici cookies
		  $('#rezervDetailWindow').hide(); 
		  window.ajaxLoaded=false
			var sid=$('#sid').html();
			if(sid){
				sid=sid.split('=');
				sid=sid[1]
			}
			//promazu probihajici ajax dotazy
			ajaxHandler.clearAjaxRequests();
			$('#LoadingMessage').show();
      var pom
      //pro den 	
      //odakz na ajaxHandler objekt pro pouziti ve vnitr scope jinych objektu - ajax requestu jQuery
      var _this=this;
     // console.log(type)
			if(type=="day"){
			 _this.reservID=0;
			//nastavim aktualni URL
				location.hash='#type='+type+'&fitID='+this.fitID+'&date='+this.codeDate(date,0);
				 _this.setRefLinkForLoging();
				$('#fazeButtons').css('display','none');
				$('#calButtons').css('display','block');
				//neco=$.get('dayTemp.php',{year:date.getFullYear(),month:date.getMonth()+1,date:date.getDate(),lang:lang},function(data){$('#BigCal').html(data);initial(type)},'HTML')
				//dotaz na data pro den
        pom=$.ajax({
					type:'GET',
					url:_this.ajaxPage,
					dataType:'HTML',
					data:{q:'ergoReserv',type:'day',fitID:_this.fitID,'PHPSESSID':sid,year:date.getFullYear(),month:date.getMonth()+1,date:date.getDate(),lang:_this.lang},
					success:function(data){
					  ajaxHandler.destructCrossRef($('#BigCal').get(0))
            $('#BigCal').html(data);
            _this.initial(type);
            //jestli nevyprselo prihlaseni
            //musim znovu navazat funkce pro obsluhu
            if($('#LogTimeout').length){               
                var pom=_this.staticPage+_this.lang+'/loginArea.html';
                $.ajax({
					           type:'GET',
					      url:pom,
					      dataType:'HTML',
					      success:function(data){
                    $('#loginAreaSmall').html(data);
                    //$('#loginButton').bind('click',handle);
                    _this.setRefLinkForLoging();
                    $('#loginShow').bind('click',handle);
                    $('#loginShow').bind('mouseover',function(){$(this).addClass('hover');});
			              $('#loginShow').bind('mouseout',function(){$(this).removeClass('hover');});
                  }
                })
                }
						window.scrollTo(0,380);
						if(window.ajaxLoaded){
              $('#LoadingMessage').hide();
            }
            window.ajaxLoaded=true;
						},
					error: Error			
				})
				ajaxHandler.ajaxObjects.push(pom);
			}
			//pro mesic
			else if(type=="month"){
			   _this.reservID=0;
				location.hash='#type='+type+'&fitID='+this.fitID+'&date='+this.codeDate(date,0);
				 _this.setRefLinkForLoging();
				//neco=$.get('monthTemp.php',{year:date.getFullYear(),month:date.getMonth()+1,lang:lang},function(data){$('#BigCal').html(data);initial(type)},'HTML')
				pom=$.ajax({
					type:'GET',
					url:_this.ajaxPage,
					dataType:'HTML',
					data:{q:'ergoReserv',type:'month',fitID:_this.fitID,'PHPSESSID':sid,year:date.getFullYear(),month:date.getMonth()+1,date:date.getDate(),lang:_this.lang},
					success:function(data){
              ajaxHandler.destructCrossRef($('#BigCal').get(0))
              $('#BigCal').html(data);
              _this.initial(type);
             //jestli nevyprselo prihlaseni
            //musim znovu navazat funkce pro obsluhu
              if($('#LogTimeout').length){            
                var pom=_this.staticPage+_this.lang+'/loginArea.html';
                $.ajax({
					           type:'GET',
					           url:pom,
					           cahce:false,  
					           dataType:'HTML',
					           success:function(data){
					           //pridam obsluhu udalosti az pote co je login are nactena
					              //alert(data);
                        $('#loginAreaSmall').html(data);
                        //$('#loginButton').bind('click',handle);
                        _this.setRefLinkForLoging();
                        $('#loginShow').bind('click',handle);
                        $('#loginShow').bind('mouseover',function(){$(this).addClass('hover');});
			                   $('#loginShow').bind('mouseout',function(){$(this).removeClass('hover');});
                  }
                })
                }
							if(window.ajaxLoaded){
              $('#LoadingMessage').hide();
            }
            window.ajaxLoaded=true;
						},
					error: Error
				})
				ajaxHandler.ajaxObjects.push(pom);
			}
			//pro tyden
			else if(type=="week"){
			 _this.reservID=0;
					location.hash='#type='+type+'&fitID='+this.fitID+'&date='+this.codeDate(date,0);
					 _this.setRefLinkForLoging();
				//neco=$.get('weekTemp.php',{year:date.getFullYear(),month:date.getMonth()+1,date:date.getDate(),lang:lang},function(data){$('#BigCal').html(data);initial(type)},'HTML')
				       
				pom=$.ajax({
					type:'GET',
					url:_this.ajaxPage,
					dataType:'text',
					data:{q:'ergoReserv',type:'week',fitID:_this.fitID,year:date.getFullYear(),month:date.getMonth()+1,date:date.getDate(),lang:_this.lang},
					success:function(data){   
              ajaxHandler.destructCrossRef($('#BigCal').get(0))
              $('#BigCal').html(data);
              _this.initial(type);
              //jestli nevyprselo prihlaseni
            //musim znovu navazat funkce pro obsluhu
              if($('#LogTimeout').length){               
                var pom=_this.staticPage+_this.lang+'/loginArea.html';
                $.ajax({
					           type:'GET',
					      url:pom,
					      dataType:'HTML',
					      success:function(data){
                    $('#loginAreaSmall').html(data);
                    //$('#loginButton').bind('click',handle);
                    _this.setRefLinkForLoging();
                     $('#loginShow').bind('click',handle);
                    $('#loginShow').bind('mouseover',function(){$(this).addClass('hover');});
			              $('#loginShow').bind('mouseout',function(){$(this).removeClass('hover');});
                  }
                })
                }
							if(window.ajaxLoaded){
              $('#LoadingMessage').hide();
            }
            window.ajaxLoaded=true;
						},
					error: Error
				})
				ajaxHandler.ajaxObjects.push(pom);
				}
			else if(type=='detail'){
			 //resetuju pamet onjektu calendarCOnector
		   //diky tomu se po kliknuti na jakykoliv prvek kalendare menici datum vzdy skoci do kalendare a nacte se odpovidajici typ zobrazeni
			      cal.CalConector.BeforeDay=null;
            cal.CalConector.BeforeWeekNum=null;
            cal.CalConector.BeforeWeekMonth=null;
            cal.CalConector.BeforeWeekYear=null;
            cal.CalConector.BeforeDayMonth=null;
            cal.CalConector.BeforeDayYear=null;
            cal.CalConector.BeforeMonth=null;
            //
            var kalendarbut=$('#kalendarbut').get(0);
			      kalendarbut.locastioHASH=pom;
			     //a take zakodovany aktualni datum aby ze prez nej bylo mozno odkazat zpet do deniku z detailu faze
			     kalendarbut.date=this.codeDate(date,0);
			    	location.hash='#type='+type+'&fitID='+this.fitID+'&date='+this.codeDate(date,0)+'&lekceID='+this.lekceID;
			     _this.setRefLinkForLoging();
          	pom=$.ajax({
      					type:'GET',
      					url:_this.ajaxPage,
      					dataType:'HTML',
      					data:{q:'ergoReserv',type:'detail',fitID:_this.fitID,'PHPSESSID':sid,year:date.getFullYear(),month:date.getMonth()+1,
                      date:date.getDate(),lekceID:_this.lekceID,lang:_this.lang,
                      reservID:_this.reservID,regUserID:window.loggedUserID,unregUser:_this.unregUser,
                      cancel:_this.regCancel,
                      emailAdd:_this.emailAdd},
      					success:function(data){
                    ajaxHandler.destructCrossRef($('#BigCal').get(0))
                    $('#BigCal').html(data);
                    _this.initial(type);
                    window.scrollTo(0,0)
                    //pokud vyprselo prihlaseni tak opet nabidnu moznost loginu
                      //jestli nevyprselo prihlaseni
                  //musim znovu navazat funkce pro obsluhu
                   //inicialiyuji pohyb pop up div window
		                window.setLoginMessage()
                    if($('#LogTimeout').length){               
                        var pom=_this.staticPage+_this.lang+'/loginArea.html';
                        $.ajax({
					               type:'GET',
					                url:pom,
					               dataType:'HTML',
					               success:function(data){
                             $('#loginAreaSmall').html(data);
                              //$('#loginButton').bind('click',handle);
                              _this.setRefLinkForLoging();
                               $('#loginShow').bind('click',handle);
                              $('#loginShow').bind('mouseover',function(){$(this).addClass('hover');});
			                         $('#loginShow').bind('mouseout',function(){$(this).removeClass('hover');});
                             }
                          })
                          }
      							if(window.ajaxLoaded){
                    $('#LoadingMessage').hide();
                  }
                  window.ajaxLoaded=true;
      						},
      					error: Error
      				})
      				ajaxHandler.ajaxObjects.push(pom);
        }
			}
//funkce umoznujici prihlaseni uzivatele
//pass je heslo user je prihlas jmeno
ajaxHandler.prototype.LoggUser=function(userName,passWord){
    var sid=$('#sid').html();
			if(sid){
				sid=sid.split('=');
				sid=sid[1]
			}
		 var _this=this;	
     $.ajax({
      					type:'POST',
      					url:_this.ajaxPage,
      					dataType:'HTML',
      					data:"q=Login&user="+userName+"&pass="+passWord+"&PHPSESSID="+sid,
      					success:function(data){
                    ajaxHandler.destructCrossRef($('#BigCal').get(0))
                    $('#loginAreaSmall').html(data);
                      if($('#LogTimeout').length){
                        var pom=_this.staticPage+_this.lang+'/loginArea.html';
                        $('#loginAreaSmall').load(pom);
                      }
      							if(window.ajaxLoaded){
                    $('#LoadingMessage').hide();
                  }
                  window.ajaxLoaded=true;
      						},
      					error: Error
      				})
  }
//zakoduje datum do fomratu den.mesic.rok 4.11.2008 
		//date -datum 
		//offset pokud by datumy na strane klienta bylz zero based a na serveru 1 based nebo obracen (zatim nepouzito)
ajaxHandler.prototype.codeDate=function(date,offset){
			var dayStr='';
			dayStr=dayStr+(date.getDate()+offset)+'.';
			dayStr=dayStr+(date.getMonth()+1)+'.';
			dayStr=dayStr+date.getFullYear()
			return dayStr;
		}

	//inverzni funkce ktera ze stringu den.mesi.rok setasim odpovidajici objekt date
		//vstup string 
ajaxHandler.prototype.decodeDate=function(str){
		//rozdelim podle .
			var pom=str.split('.');
			var datum=new Date();
			//kontroluji jednotile slozky a pripadne vyhazuji vyjimky
			if(pom.length==3){
			  if(parseInt(pom[0]) && parseInt(pom[1]) && parseInt(pom[2])){
			    if(parseInt(pom[0])>0 && parseInt(pom[0])<32 && parseInt(pom[1])>0 && parseInt(pom[1])<13 && parseInt(pom[2])>1970 && parseInt(pom[2])<2030){  
				   // datum.seDate();
            datum.setFullYear(parseInt(pom[2]));
            datum.setDate(1);
				    var t=pom[1]-1;
				    datum.setMonth(parseInt(t));
				    datum.setDate(parseInt(pom[0]));
				   // alert(datum.getMonth()+'  Datum');
				    }
				  else throw 'chyba';
				  }
				else throw 'chyba';
				return datum;
				}	
			else return null;
		}		
		
	//funkce ktera precte paramety z URL (parametry za #) - a na jejich zaklade sestai volani ajax dotazu pro ziskani pozadovaneho deniku
ajaxHandler.prototype.getURLparams=function(){
		  //alert(location.hash)
		  //paremtry z url
			var params=location.hash.substring(1);
			if(!params) return null;
			//rozdelim podle &
			params=params.split('&')
			var pom;
			//vytvorim si pomocny objektu URL
			var URLparams=new Object();
			for(var i=0;i<params.length;i++){
			  //kazdou cast dal splintu polde = a pridavam do objektu URL
				pom=params[i].split('=');
				if((pom[0]=='type' || pom[0]=='date' || pom[0]=='fitID' || pom[0]=='lekceID') && pom[1]){
					switch(pom[0]){
						case 'type': if(pom[1]=='day' || pom[1]=='week' || pom[1]=='month' || pom[1]=='detail'){
								URLparams[pom[0]]=pom[1];
								
								}
								break;
						case 'date': URLparams[pom[0]]=pom[1];
								break;
						case 'lekceID':
								URLparams[pom[0]]=pom[1];	
								break;
						case 'fitID':URLparams[pom[0]]=pom[1];		
                window.fitnessID=pom[1];;
                this.fitID=pom[1];
								break;
					}	
				}
			}
			var message='';
			if(!URLparams.type){message=message+ErrorMessage[this.lang].URLparError;}
			if(!URLparams.fitID){message=message+ErrorMessage[this.lang].URLparError;}
			if(URLparams.date){
				try{
					var datum=this.decodeDate(URLparams.date)
					if(datum){
					URLparams.date=datum;
					}
					else throw 'chyba'
				}
				catch(e){
					URLparams.date=null;
					message=message+ErrorMessage[lang].URLparError;
				}
			}
			else message=message+ErrorMessage[lang].URLparError;
		
			
			if(message)alert(message);
			if(URLparams.type && URLparams.fitID){
			//pokud jsou k dispozici mimimalni pozadovane parametyr vratim objekt URL obsahuji informace extrahovane z URL
			//jink vratim null
				if(URLparams.type=='detail' && URLparams.lekceID)return URLparams;
				else if(URLparams.type && URLparams.type!='detail' && URLparams.date)return URLparams;
				else return null;
			}
			else return null;
		}
		
		
		

