document.observe("dom:loaded", function(event){

    load_comments();
    sort_comments();
    loadProfileList();
    searchCheckbox();

	  $$('.catAjax').each(function(n){
		  n.onclick = function(){
	 	   loadCategories(n);
	 	   return false;
	  }});

	  profileAction = new profileActionClass();
	  if($$('.ViewCountElement').first()){
	     imgCount = $$('.ViewCountElement').first();
	     imgCountId = imgCount.id.split('_');

	     switch(imgCountId[0]){
	       case 'ViewCountProfile':
	         typeObject = 'profile';
	         cookieName = imgCountId[0];
	       break;
	       case 'ViewCountComment':

	         if(getCookie('userLogId')) {
	           var userLog = getCookie('userLogId').split('##');
	           var ownerCommentId = imgCountId[2];
	           if(userLog[0]==ownerCommentId) {
	              Element.show($('delquestion'));
	              Element.show($('editquestion'));
	           }
	         }
	         typeObject = 'comment';
	         cookieName = imgCountId[0];
	       break;
	       case 'ViewCountPicture':
	         typeObject = 'picture';
	         cookieName = imgCountId[0];
	       break;
	     }
	     var cookieView = getCookie(cookieName) ? getCookie(cookieName) : "";

	     countFlag = true;
	     cookieViewTmp = cookieView.split('_');
	     for(var i=0; i<cookieViewTmp.size(); i++){
	         if(cookieViewTmp[i] == imgCountId[1]){
	            countFlag = false;
	            break;
	         }
	     }

	     if(countFlag){
	         var actionCountElement = "/stats/increment/format/noviews/typeobject/" + typeObject + "/item/" + imgCountId[1];
		     new Ajax.Request(actionCountElement, {
		         method: 'POST'
		     });
	         setCookie(cookieName,cookieView + ((cookieView!="")? '_': '') + imgCountId[1]);
	     }
      }


	  $$('#editemailpass .text').each(function(n){
	       Event.observe(n , 'change' , function(event) {

	    	  fillInputFlagPass = false;
	    	  fillInputFlagMail = false;
	    	  $$('#editemailpass .mail').each(function(n){
	    	     if(n.value.length>0) {
	    	        fillInputFlagMail = true;
	    	     }
	    	  });
	    	  $$('#editemailpass .pass').each(function(n){
	    	     if(n.value.length>0) {
	    	        fillInputFlagPass = true;
	    	     }
	    	  });

	    	  if(fillInputFlagMail) {
		    	  $$('#editemailpass .mail').each(function(n){n.addClassName('required')});
	    	  } else {
		    	  $$('#editemailpass .mail').each(function(n){
		    	     n.removeClassName('required');
		    	     if($('advice-required-'+n.id)) $('advice-required-'+n.id).hide();
		    	  });
	    	  }
	    	  if(fillInputFlagPass) {
	 	    	  $$('#editemailpass .pass').each(function(n){n.addClassName('required')});
	    	  } else {
		    	  $$('#editemailpass .pass').each(function(n){
		    	     n.removeClassName('required');
		    	     if($('advice-required-'+n.id)) $('advice-required-'+n.id).hide();
		    	  });
	    	  }

	       });
	  });

});



var profileActionClass = Class.create({
  initialize: function(){
     this.formName = '';
     this.sendFriendObserve = true;
     this.sendMessageObserve = true;
     this.addQuestionObserve = true;
     this.addCommentObserve = true;
     this.sendMailObserve = true;
     this.delPictureObserve = true;
     this.editQuestionObserve = true;
  },

  sendFriend : function(profileId){
     if(!issLogged) return false;
     this.formName = 'send-friend';
     this.setPositionBox($(this.formName+'-box'));

     Element.show($('overlayer'));
     Element.show($(this.formName+'-box'));

     this.action='/profile/recommend/';
     if(this.sendFriendObserve){
        Event.observe($(this.formName+'-form'), 'submit', this.ajaxAction.bindAsEventListener(this));
        Event.observe($$('#'+this.formName+'-form input.button-cancel').first(), 'click', function(event){
          Event.stop(event);
          Element.hide($('overlayer'));
          Element.hide($('send-friend-box'));
        });
        this.sendFriendObserve = false;
     }
  },

  sendMessage : function(profileId){
     if(!issLogged) return false;
     this.formName = 'profile-message';
     this.setPositionBox($(this.formName+'-box'));

     Element.show($('overlayer'));
     Element.show($(this.formName+'-box'));

     this.action='/profile/sendingmessages/';
     this.paramsList = '&message_to_person='+profileId;
     if(this.sendMessageObserve){
	     Event.observe($(this.formName+'-form'), 'submit', this.ajaxAction.bindAsEventListener(this));
	     Event.observe($$('#'+this.formName+'-form input.button-cancel').first(), 'click', function(event){
	       Event.stop(event);
	       Element.hide($('overlayer'));
	       Element.hide($('profile-message-box'));
	     });
	     this.sendMessageObserve = false;
     }
  },

  addQuestion : function(param1,param2){
     if(!issLogged) return false;
     if(param1 && param2){
       this.formName = 'userAnswer';
     } else {
       this.formName = 'userQuestion';
     }
     this.setPositionBox($(this.formName+'-box'));
     Element.show($('overlayer'));
     Element.show($(this.formName+'-box'));

     this.action='/comments/new/';
     this.paramsList = ((param1) ? '&parentThread='+param1 : '') +
                       ((param2) ? '&profileId='+param2 : '') +
                       '&form_type=question';

     //if(this.addQuestionObserve){
     //this.redirectAction = document.location.href;
     if(this.addQuestionObserve){
     this.redirectAction = '/forum';
	     Event.observe($(this.formName+'-form'), 'submit', this.ajaxAction.bindAsEventListener(this));
	     Event.observe($$('#'+this.formName+'-form input.button-cancel').first(), 'click', this.hideForm.bindAsEventListener(this));
	     this.addQuestionObserve = false;
     }
  },
  editQuestion : function(param1){
     if(!issLogged) return false;
     this.formName = 'userEditQuestion';
     this.setPositionBox($(this.formName+'-box'));

     Element.show($('overlayer'));
     Element.show($(this.formName+'-box'));

     this.action='/profile/editquestion/';
     this.paramsList = '&commentId='+param1;

     if(this.editQuestionObserve){
	     Event.observe($(this.formName+'-form'), 'submit', this.ajaxAction.bindAsEventListener(this));
	     Event.observe($$('#'+this.formName+'-form input.button-cancel').first(), 'click', this.hideForm.bindAsEventListener(this));
	     this.editQuestionObserve = false;
     }

     Element.show('userEditQuestion-inprogress');
     new Ajax.Request('/profile/questiondata', {
         parameters: {commentId : param1},
         method: 'POST',
         onSuccess: function(transport){
            dataResponse = transport.responseJSON;
            if(dataResponse.status=='true'){
              $('editcomment').value=dataResponse.comment;
              $('describeedit').update(dataResponse.description);
              Element.hide('userEditQuestion-inprogress');
            }
         }
     });

  },

  hideForm : function(event){
	  Event.stop(event);
	  Element.hide($('overlayer'));
	  Element.hide($(this.formName+'-box'));
  },

  addComment : function(type,param1,param2,param3){
     this.formName = 'userComment';
     this.setPositionBox($(this.formName+'-box'));

     Element.show($('overlayer'));
     Element.show($(this.formName+'-box'));

     this.action='/comments/new/';
     switch(type){
       case 'pictures':
          this.paramsList = ((param1) ? '&picturesId='+param1 : '')+
                            ((param2) ? '&profileId='+param2 : '')+
                            ((param3) ? '&parentThread='+param3 : '')+
                            '&form_type=commentpictures';
       break;
       case 'profile':
          this.paramsList = ((param1) ? '&profileId='+param1 : '')+
                            ((param2) ? '&parentThread='+param2 : '')+
                            '&form_type=commentprofile';
       break;
     }
     if(this.addCommentObserve){
     this.redirectAction = document.location.href;
	    // Event.observe($(this.formName+'-form'), 'submit', this.ajaxAction.bindAsEventListener(this));
	       Event.observe($(this.formName+'-form'), 'submit', this.checkEmptyField.bindAsEventListener(this));
	       Event.observe($$('#'+this.formName+'-form .button-cancel').first(), 'click', function(event){
	       Event.stop(event);
	       Element.hide($('overlayer'));
	       Element.hide($('userComment-box'));
	     });
	     this.addCommentObserve = false;
     }
  },
  checkEmptyField: function(event){
  	if($('commentlogin')){
  		if($('commentlogin').value != ''){
  			this.ajaxAction();
  			Event.stop(event);
  		}
  	}
  },
  sendMail : function(){
     this.formName = 'mailSend';
     this.setPositionBox($(this.formName+'-box'));
     Element.hide($('login-form'));
     Element.show($('overlayer'));
     Element.show($(this.formName+'-box'));
     Element.show($('mailSend-buttons1'));
     Element.hide($('mailSend-buttons2'));
     Element.show($('mailSend-input1'));
     Element.hide($('mailSend-input2'));
     $('mailSend-description').update('Nie pamiętasz hasła? Podaj swój adres e-mail, a prześlemy Ci je. ');

     this.action='/profile/sendingmail/';
     this.paramsList = '&type=lostpassword';
     if(this.sendMailObserve){
	     Event.observe($(this.formName+'-form'), 'submit', this.ajaxMailAction.bindAsEventListener(this));
	     Event.observe($$('#'+this.formName+'-form input.button-cancel').first(), 'click', function(event){
	       Event.stop(event);
	       Element.hide($('overlayer'));
	       Element.hide($('mailSend-box'));
	     });
	     this.sendMailObserve = false;
     }
  },
  sendOveruse : function(){
     if(!issLogged) return false;
     this.formName = 'mailSend';
     this.setPositionBox($(this.formName+'-box'));

     Element.hide($('login-form'));
     Element.show($('overlayer'));
     Element.show($(this.formName+'-box'));

     Element.show($('mailSend-buttons1'));
     Element.hide($('mailSend-buttons2'));
     Element.hide($('mailSend-input1'));
     Element.show($('mailSend-input2'));
     $('mailSend-textinfo').update('');

     $('mailSend-title').update('Zgłoś nadużycie <img id="mailSend-inprogress" style="display: none" src="'+staticDomain+'/img/ajax-loader4.gif">');
     $('mailSend-description').update('Uważasz, że to zdjęcie albo komentarz narusza dobre zwyczaje panujące w serwisie Streetmoda.pl? Opisz dokładnie, co według Ciebie jest nie tak, a my się tym zajmiemy. Dziękujemy za pomoc!');
     $('input2').value = '';

     var photoId = $$('.main_image').first().identify();
     this.action='/profile/sendingmail/overuseurl/'+photoId;
     this.paramsList = '&type=overuse';
     if(this.sendMailObserve){
	     Event.observe($(this.formName+'-form'), 'submit', this.ajaxMailAction.bindAsEventListener(this));
	     Event.observe($$('#'+this.formName+'-form input.button-cancel').first(), 'click', function(event){
	       Event.stop(event);
	       Element.hide($('overlayer'));
	       Element.hide($('mailSend-box'));
	     });
	     this.sendMailObserve = false;
     }
  },
  sendAdvice : function(){
     if(!issLogged) return false;
     this.formName = 'mailSend';
     this.setPositionBox($(this.formName+'-box'));

     Element.hide($('login-form'));
     Element.show($('overlayer'));
     Element.show($(this.formName+'-box'));

     Element.show($('mailSend-buttons1'));
     Element.hide($('mailSend-buttons2'));
     Element.show($('mailSend-input1'));
     Element.show($('mailSend-input2'));
     $('mailSend-textinfo').update('');

     $('mailSend-title').update('Poleć serwis <img id="mailSend-inprogress" style="display: none" src="'+staticDomain+'/img/ajax-loader4.gif">');
     $('mailSend-description').update('Poleć swojemu znajomemu serwis Streetmoda.pl. Wyślij swoim znajomym e-mail i zaproś ich do odwiedzenia serwisu Streetmoda.pl');
     $('input2').value = 'Polecam Ci serwis Streetmoda.pl. To świetne miejsce dla ludzi, którzy chcą pokazać, jak się ubierają. Można tam dodać swoje fotki i zobaczyć, jak innym podoba się Twój styl. Można też poznać super ludzi, którzy Ci doradzą, co się teraz nosi.';

     this.action='/profile/sendingmail/';
     this.paramsList = '&type=advice';
     if(this.sendMailObserve){
	     Event.observe($(this.formName+'-form'), 'submit', this.ajaxMailAction.bindAsEventListener(this));
	     Event.observe($$('#'+this.formName+'-form input.button-cancel').first(), 'click', function(event){
	       Event.stop(event);
	       Element.hide($('overlayer'));
	       Element.hide($('mailSend-box'));
	     });
	     this.sendMailObserve = false;
     }
  },
  blocked : function(profileId, is_friend, is_observeByUser){
     if(!issLogged && myId!=0) return false;
     this.setPositionBox();
     this.formName = '';
     this.action='/profile/profileevent/';
     this.paramsList = {profileId : profileId, event : 'blocked'};
     this.hideelement = 'profileblocked';
     this.showelement = 'profiledelblocked';

     var inProgressAsk = 'Czy na pewno chcesz zablokować tego użtykownika?<br /> (Spowoduje to również ewentualne usunięcie z listy znajomych)<br /><br />';
        inProgressAsk += '<form id="in-progress-blockedform"><div class="buttons">';
     	inProgressAsk += '<input type="submit" value="zablokuj" class="submit button-accept" />';
	    inProgressAsk += '<input type="button" value="anuluj" class="button button-cancel" />';
        inProgressAsk += '</div></form>';
     $('in-progress-allert-box').update(inProgressAsk);

     Element.show($('overlayer'));
     Element.show($('in-progress-box'));

     Event.observe($('in-progress-blockedform'), 'submit', function(event){
     		Event.stop(event);
     		this.ajaxAction();
     		if(is_friend != 0)
       		this.delinvite(profileId);
       		if(is_observeByUser != 0)
			this.delobserveprofile(profileId);
     	}.bindAsEventListener(this)
     );
     Event.observe($$('#in-progress-allert-box input.button-cancel').first(), 'click', function(event){
       Event.stop(event);
       Element.hide($('overlayer'));
       Element.hide($('in-progress-box'));
     });

     return false;
  },

  youblocked : function(){
     if(!issLogged) return false;
     this.setPositionBox();
     this.formName = '';
     var inProgressAsk = 'Jesteś zablokowany przez tego użytkownika.<br /><br />';
        inProgressAsk += '<form id="info-blocked"><div class="buttons">';
	    inProgressAsk += '<input type="button" value="ok" class="button button-cancel" />';
        inProgressAsk += '</div></form>';
     $('in-progress-allert-box').update(inProgressAsk);

     Element.show($('overlayer'));
     Element.show($('in-progress-box'));
     Event.observe($$('#info-blocked input.button-cancel').first(), 'click', function(event){
       Event.stop(event);
       Element.hide($('overlayer'));
       Element.hide($('in-progress-box'));
     });
     return false;
  },

  delblocked : function(profileId){
     if(!issLogged) return false;
     this.setPositionBox();
     this.formName = '';
     this.action='/profile/profileevent/';
     this.paramsList = {profileId : profileId, event : 'delblocked'};
     this.hideelement = 'profiledelblocked';
     this.showelement = 'profileblocked';
     this.ajaxAction();
  },


  invite : function(profileId){
     if(!issLogged) return false;
     this.setPositionBox();
     this.formName = '';
     this.action='/profile/profileevent/';
     this.paramsList = {profileId : profileId, event : 'invite'};
     this.ajaxAction();
  },

  delinvite : function(profileId){
     if(!issLogged) return false;
     this.setPositionBox();
     this.formName = '';
     this.action='/profile/profileevent/';
     this.paramsList = {profileId : profileId, event : 'delinvite'};
     this.ajaxAction();
  },


  observe : function(profileId){
     if(!issLogged) return false;
     this.setPositionBox();
     this.formName = '';
     this.action='/profile/profileevent/';
     this.paramsList = {profileId : profileId, event : 'observe'};
     this.hideelement = 'profileobserve';
     this.showelement = 'profiledelobserve';
     this.ajaxAction();
  },

  delobserve : function(profileId){
     if(!issLogged) return false;
     this.setPositionBox();
     this.formName = '';
     this.action='/profile/profileevent/';
     this.paramsList = {profileId : profileId, event : 'delobserve'};
     this.hideelement = 'profiledelobserve';
     this.showelement = 'profileobserve';
     this.ajaxAction();
  },

  delobserveprofile : function(profileId){
     if(!issLogged) return false;
     this.setPositionBox();
     this.formName = '';
     this.action='/profile/profileevent/';
     this.paramsList = {profileId : profileId, event : 'delobserveprofile'};
     this.hideelement = 'profiledelobserve';
     this.showelement = 'profileobserve';
     this.ajaxAction();
  },
  delPicture : function(){
     if(!issLogged) return false;
     this.setPositionBox();
     this.formName = '';
     var photoId = $$('.main_image').first().identify();
     this.action='/profile/delpicture/';
     this.paramsList = {photoId : photoId};
     this.redirectAction = '/index';

     var inProgressAsk = 'Czy na pewno chcesz usunąć zdjęcie?<br /><br />';
        inProgressAsk += '<form id="in-progress-form"><div class="buttons">';
     	inProgressAsk += '<input type="submit" value="usuń" class="submit button-accept" />';
	    inProgressAsk += '<input type="button" value="anuluj" class="button button-cancel" />';
        inProgressAsk += '</div></form>';
     $('in-progress-allert-box').update(inProgressAsk);

     Element.show($('overlayer'));
     Element.show($('in-progress-box'));

     Event.observe($('in-progress-form'), 'submit', this.ajaxAction.bindAsEventListener(this));
     Event.observe($$('#in-progress-allert-box input.button-cancel').first(), 'click', function(event){
       Event.stop(event);
       Element.hide($('overlayer'));
       Element.hide($('in-progress-box'));
     });
     this.delPictureObserve = false;
  },
  delQuestion : function(param1){
     if(!issLogged) return false;
     this.setPositionBox();
     this.formName = '';
     this.action='/profile/delquestion/';
     this.paramsList = {commentId : param1};
     this.redirectAction = '/forum';

     var inProgressAsk = 'Czy na pewno chcesz usunąć pytanie?<br /><br />';
        inProgressAsk += '<form id="in-progress-form"><div class="buttons">';
     	inProgressAsk += '<input type="submit" value="usuń" class="submit button-accept" />';
	    inProgressAsk += '<input type="button" value="anuluj" class="button button-cancel" />';
        inProgressAsk += '</div></form>';
     $('in-progress-allert-box').update(inProgressAsk);

     Element.show($('overlayer'));
     Element.show($('in-progress-box'));

     Event.observe($('in-progress-form'), 'submit', this.ajaxAction.bindAsEventListener(this));
     Event.observe($$('#in-progress-allert-box input.button-cancel').first(), 'click', function(event){
       Event.stop(event);
       Element.hide($('overlayer'));
       Element.hide($('in-progress-box'));
     });
     this.delPictureObserve = false;
  },

  submitEditMail : function(){
     this.formName = '';
     fillInputFlag = true;
     $$('#editemailpass input').each(function(n){
    	  if(n.value.length>0) {
    	      fillInputFlag = false;
    	  }
     });

     if(fillInputFlag){
	     this.setPositionBox();
	     var inProgressAsk = 'Wprowadź dane<br /><br />';
	        inProgressAsk += '<form id="in-progress-form"><div class="buttons">';
		    inProgressAsk += '<input type="button" value="ok" class="submit button-ok" />';
	        inProgressAsk += '</div></form>';
	     $('in-progress-allert-box').update(inProgressAsk);

	     Element.show($('overlayer'));
	     Element.show($('in-progress-box'));
		 Event.observe($$('#in-progress-allert-box input.button-ok').first(), 'click', function(event){
		       Event.stop(event);
		       Element.hide($('overlayer'));
		       Element.hide($('in-progress-box'));
		 });
         return false;
     } else {
        return true;
     }
  },
  submitSearch : function(){
    this.formName = '';
    fillInputFlag = true;
    fillInputInfo = 'Okreść rodzj danych';
    $$('#search .checkimage').each(function(n){
	      if(n.hasClassName('selected')){
	         fillInputFlag = false;
	      }
    });

    var inputtext = $('inputsearch').value;
    if($('inputsearch').value=='') {
       fillInputFlag = true;
       fillInputInfo = 'Wprowadź kryteria wyszukiwania';
    } else if(inputtext.length<5) {
       fillInputFlag = true;
       fillInputInfo = 'Fraza wyszukiwania musi mieć powyżej 4 znaków';
    }


     if(fillInputFlag){
	     this.setPositionBox();
	     var inProgressAsk = fillInputInfo+'<br /><br />';
	        inProgressAsk += '<form id="in-progress-form"><div class="buttons">';
		    inProgressAsk += '<input type="button" value="ok" class="submit button-ok" />';
	        inProgressAsk += '</div></form>';
	     $('in-progress-allert-box').update(inProgressAsk);

	     Element.show($('overlayer'));
	     Element.show($('in-progress-box'));
		 Event.observe($$('#in-progress-allert-box input.button-ok').first(), 'click', function(event){
		       Event.stop(event);
		       Element.hide($('overlayer'));
		       Element.hide($('in-progress-box'));
		 });
         return false;
     } else {
        return true;
     }
  },


  ajaxAction : function(event){
     if(event) Event.stop(event);
     Element.show($('overlayer'));
     Element.show($('in-progress-box'));

     if(this.formName!=""){
        Element.hide($(this.formName+'-box'));
        this.paramsList=$(this.formName+'-form').serialize()+this.paramsList;
     }

     var show, hide, redirect;
     if(this.hideelement) show = $(this.showelement);
     if(this.hideelement) hide = $(this.hideelement);
     if(this.redirectAction) redirect = this.redirectAction;

     new Ajax.Request(this.action, {
         parameters: this.paramsList,
         method: 'POST',
         onSuccess: function(transport){
            dataResponse = transport.responseJSON;

            if(redirect) {
               $('in-progress-allert-box').update('<spn class="font-size:10px;">' + dataResponse.text + '</span><br /><br /><input type="button" value="ok" class="loaderclass" onclick=document.location="'+redirect+'" />');
            } else {
               $('in-progress-allert-box').update('<spn class="font-size:10px;">' + dataResponse.text + '</span><br /><br /><input type="button" value="ok" class="loaderclass" onclick="Element.hide($(\'overlayer\')); Element.hide($(\'in-progress-box\'));" />');
            }

            if(dataResponse.status=='true'){
               if(hide) Element.hide(hide);
               if(show) Element.show(show);
            }
         },
         onLoading: function(transport){
            $('in-progress-allert-box').update('<spn class="font-size:10px;">Proszę czekać....&nbsp;&nbsp;<span><img src="'+staticDomain+'/img/ajax-loader4.gif">');
         }
     });
     this.formName = '';
  },

  ajaxMailAction: function(event){
        Event.stop(event);
        Element.hide($('mailSend-textinfo'));
        Element.hide($('mailSend-inprogress'));

        form = $('mailSend-form');
        new Ajax.Request(this.action, {
            parameters: form.serialize()+this.paramsList,
            method: 'POST',
            onSuccess: function(transport){
                Element.hide($('mailSend-inprogress'));

                if (transport.responseJSON == false) {
                    Element.show($('mailSend-error'));
                } else {
                   dataResponse = transport.responseJSON;
                   if(dataResponse.result=='true'){
                      Element.hide($('mailSend-buttons1'));
                      Element.show($('mailSend-buttons2'));
                      Element.show($('mailSend-textinfo'));
                      $('mailSend-textinfo').update(dataResponse.text);
                      $('mailSend-buttons2').update('<input type="button" value="ok" class="submit button-cancel" onclick="Element.hide($(\'overlayer\')); Element.hide($(\'mailSend-box\'));" />');
                   } else {
                      Element.show($('mailSend-textinfo'));
                      $('mailSend-textinfo').update(dataResponse.text);
                   }
                }

            }.bind(this),
            onLoading: Element.show($('mailSend-inprogress'))
        });
  },

  setPositionBox: function(element){
        this.viewport();
        var scroollTopbody = document.documentElement.scrollTop;
        if(element) {
           Element.setStyle(element, {top: (scroollTopbody + 110) + 'px' });
        }
        Element.setStyle($('in-progress-box'), {top: (scroollTopbody + 110 + 100) + 'px' });


        var overlay = $('overlayer');
        Element.setStyle(overlay , {
            height: this.pageY + 'px'
        });
  },
  viewport: function(){
        this.pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth;
        this.pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
  },
  setActionParams: function(action){
     sringAction = action;
     eval(sringAction);
     return false;
  }

});




function load_comments(){
	$$('#forum_form input').each(function(n){
		n.onchange = function(){
	      if ($('cat_selected')) {
	         location_href = $('cat_selected').href+'show/'+n.value;
	      }else {
	         location_href = $('forum_form').action+n.value;
	      }

		  document.location = location_href;
  	}
  	})
};


function sort_comments(){
	$$('.sort_comment').each(function(n){
		n.onclick = function(){
            if (n.hasClassName('up')) {
               directionSort = 'desc';
               n.removeClassName('up').addClassName('down');
            } else {
               directionSort = 'asc';
               n.removeClassName('down').addClassName('up');
            }

            new Ajax.Request('/forum/answer', {
            parameters: {format: 'ajax', idParent: n.id, sort: directionSort},
            method: 'POST',
            onSuccess: function(transport){
                 var response = transport.responseText;
                 $('answerblock_' + n.id).update(response);
             },
            onLoading: $('answerblock_' + n.id).update('<div style="text-align: center; padding: 20px;"><img src="'+staticDomain+'/img/ajax-loader.gif"></div>')
        });
  	}
  	});
};


function loadCategories(n){
   $$('#rightmenu .selected').each(function(n){
       n.removeClassName('selected');
       //n.down('div').removeClassName('showblock');
  	})

   categoryId = n.id.split('_');
   $('cat_' + categoryId[1]).addClassName('selected');
   if(!$('cat_' + categoryId[1]).hasClassName('loaded')){
	   new Ajax.Request('/photos/categoriespreview/', {
		     parameters: {format: 'ajax', idCat : categoryId[1]},
		     method: 'POST',
		     onSuccess: function(transport){
		        var response = transport.responseText;
		        Element.show($('catList_' + categoryId[1]));
		        $('catList_' + categoryId[1]).update(response);
		     },
		     onLoading: function(){
		        $('catList_' + categoryId[1]).addClassName('showblock');
		        $('catList_' + categoryId[1]).update('<div class="loaderclass1"><img src="'+staticDomain+'/img/ajax-loader1.gif"></div>');
		        $('cat_' + categoryId[1]).addClassName('loaded');
		     }
	    });
    }
}


function loadProfileList(){
	$$('#displaytype_form input').each(function(n){
		n.onchange = function(){
	      location_href = $('displaytype_form').action+'/displaytype/'+n.value;
		  document.location = location_href;
  	    }
  	})
};


function searchCheckbox(){
	$$('#search .checkimage').each(function(n){
	   n.onclick = function(){
	      if(n.hasClassName('searchpeople')){
	         var name = 'searchpeople';
	      } else if(n.hasClassName('searchphotos')){
	         var name = 'searchphotos';
	      } else if(n.hasClassName('searchcomments')){
	         var name = 'searchcomments';
	      }

          var checkboxImg = $(name + 'img');
          var checkboxInput = $(name + 'value');
          if (checkboxImg.hasClassName('selected')) {
               checkboxInput.value = "false";
               checkboxImg.removeClassName('selected');
          } else {
              checkboxInput.value = "true";
              checkboxImg.addClassName('selected');
          }
  	   }
  	})
};
