
  /**
    * DYNAMIC+
    *
    */

  if ( !window.interactiveComments  )
  {
    function interactiveComments( strInstance, iObjectType, iObjectId, oObject, oOptions, oUser, oPager )
    {
      var oInstance = this;
      oInstance.strInstance = strInstance;

      oInstance.bIsInitialized = false;
      oInstance.bIsWorking = false;
      oInstance.bIsReplying = false;

      oInstance.iReplyCommentId = 0;
      oInstance.iLastCommentId = 0;

      oInstance.iObjectType = iObjectType;
      oInstance.iObjectId = iObjectId;
      oInstance.oObject = oObject;
      oInstance.oOptions = oOptions;
      oInstance.oUser = oUser;
      oInstance.oPager = oPager;

      oInstance.oErrors = null;
      oInstance.oWarnings = null;
      oInstance.oInformations = null;

      oInstance.captchaUrl = '/captcha';
      oInstance.asyncUrl = '/commenti/ajax';

      oInstance.init = function( )
      {
        if ( !oInstance.bIsInitialized )
        {
          oInstance.hComments = document.getElementById( 'interactiveComments_' + oInstance.strInstance );
          oInstance.hCommentsLoader = document.getElementById( 'interactiveCommentsLoader_' + oInstance.strInstance );
          oInstance.hCommentsInformation = document.getElementById( 'interactiveCommentsInformation_' + oInstance.strInstance );
          oInstance.hCommentsList = document.getElementById( 'interactiveCommentsListContainer_' + oInstance.strInstance );
          oInstance.hCommentsReply = document.getElementById( 'interactiveCommentsReplyContainer_' + oInstance.strInstance );
          oInstance.hCommentsReplyForm = document.getElementById( 'interactiveCommentsReplyFormContainer_' + oInstance.strInstance );
          oInstance.hCommentsNewReplyContainer = document.getElementById( 'interactiveCommentsNewReplyContainer_' + oInstance.strInstance );
          oInstance.hCommentsNewReply = document.getElementById( 'interactiveCommentsNewReply_' + oInstance.strInstance );

          oInstance.hAuthorContainer = document.getElementById( 'interactiveCommentsReplyAuthorContainer_' + oInstance.strInstance );
          oInstance.hHomePageContainer = document.getElementById( 'interactiveCommentsReplyHomePageContainer_' + oInstance.strInstance );
          oInstance.hEMailContainer = document.getElementById( 'interactiveCommentsReplyEMailContainer_' + oInstance.strInstance );
          oInstance.hEMailNotificationContainer = document.getElementById( 'interactiveCommentsReplyEMailNotificationContainer_' + oInstance.strInstance );
          oInstance.hVoteContainer = document.getElementById( 'interactiveCommentsReplyVoteContainer_' + oInstance.strInstance );
          oInstance.hCaptchaContainer = document.getElementById( 'interactiveCommentsReplyCaptchaContainer_' + oInstance.strInstance );
          oInstance.hTitleContainer = document.getElementById( 'interactiveCommentsReplyTitleContainer_' + oInstance.strInstance );
          oInstance.hContentContainer = document.getElementById( 'interactiveCommentsReplyContentContainer_' + oInstance.strInstance );

          oInstance.hAuthorError = document.getElementById( 'interactiveCommentsReplyAuthorError_' + oInstance.strInstance );
          oInstance.hHomePageError = document.getElementById( 'interactiveCommentsReplyHomePageError_' + oInstance.strInstance );
          oInstance.hEMailError = document.getElementById( 'interactiveCommentsReplyEMailError_' + oInstance.strInstance );
          oInstance.hEMailNotificationError = document.getElementById( 'interactiveCommentsReplyEMailNotificationError_' + oInstance.strInstance );
          oInstance.hVoteError = document.getElementById( 'interactiveCommentsReplyVoteError_' + oInstance.strInstance );
          oInstance.hCaptchaError = document.getElementById( 'interactiveCommentsReplyCaptchaError_' + oInstance.strInstance );
          oInstance.hTitleError = document.getElementById( 'interactiveCommentsReplyTitleError_' + oInstance.strInstance );
          oInstance.hContentError = document.getElementById( 'interactiveCommentsReplyContentError_' + oInstance.strInstance );

          oInstance.hAuthor = document.getElementById( 'interactiveCommentsReplyAuthor_' + oInstance.strInstance );
          oInstance.hHomePage = document.getElementById( 'interactiveCommentsReplyHomePage_' + oInstance.strInstance );
          oInstance.hEMail = document.getElementById( 'interactiveCommentsReplyEMail_' + oInstance.strInstance );
          oInstance.hEMailNotification = document.getElementById( 'interactiveCommentsReplyEMailNotification_' + oInstance.strInstance );
          oInstance.hTitle = document.getElementById( 'interactiveCommentsReplyTitle_' + oInstance.strInstance );
          oInstance.hCaptchaImage = document.getElementById( 'interactiveCommentsReplyCaptchaImage_' + oInstance.strInstance );
          oInstance.hCaptcha = document.getElementById( 'interactiveCommentsReplyCaptcha_' + oInstance.strInstance );
          oInstance.hCaptchaRefresh = document.getElementById( 'interactiveCommentsReplyCaptchaImageRefresh_' + oInstance.strInstance );
          oInstance.hContent = document.getElementById( 'interactiveCommentsReplyContent_' + oInstance.strInstance );
          oInstance.hReplyClose = document.getElementById( 'interactiveCommentsReplyClose_' + oInstance.strInstance );
          oInstance.hReplySubmit = document.getElementById( 'interactiveCommentsReplySubmit_' + oInstance.strInstance );

          oInstance.hVote0Container = document.getElementById( 'interactiveCommentsReplyVote0Container_' + oInstance.strInstance );
          oInstance.hVote0Image = document.getElementById( 'interactiveCommentsReplyVote0Image_' + oInstance.strInstance );

          oInstance.hVote0 = document.getElementById( 'interactiveCommentsReplyVote0_' + oInstance.strInstance );
          oInstance.hVote1 = document.getElementById( 'interactiveCommentsReplyVote1_' + oInstance.strInstance );
          oInstance.hVote2 = document.getElementById( 'interactiveCommentsReplyVote2_' + oInstance.strInstance );
          oInstance.hVote3 = document.getElementById( 'interactiveCommentsReplyVote3_' + oInstance.strInstance );
          oInstance.hVote4 = document.getElementById( 'interactiveCommentsReplyVote4_' + oInstance.strInstance );
          oInstance.hVote5 = document.getElementById( 'interactiveCommentsReplyVote5_' + oInstance.strInstance );
          oInstance.hVote6 = document.getElementById( 'interactiveCommentsReplyVote6_' + oInstance.strInstance );

          oInstance.hPager = document.getElementById( 'interactiveCommentsPagerContainer_' + oInstance.strInstance );
          oInstance.hPagerInfo = document.getElementById( 'interactiveCommentsPagerInfo_' + oInstance.strInstance );
          oInstance.hPagerList = document.getElementById( 'interactiveCommentsPagerList_' + oInstance.strInstance );

          oInstance.hOptionalCommentsCounter = document.getElementById( 'interactiveCommentsCounter_' + oInstance.strInstance );
          oInstance.hOptionalRefresh = document.getElementById( 'interactiveCommentsRefreshContainer_' + oInstance.strInstance );
          oInstance.hOptionalFeed = document.getElementById( 'interactiveCommentsFeedContainer_' + oInstance.strInstance );
          oInstance.hOptionalPagedList = document.getElementById( 'interactiveCommentsPagedListContainer_' + oInstance.strInstance );


          oInstance.hEditingKeyListener = typeof(YAHOO.util.KeyListener) != 'undefined' ? new YAHOO.util.KeyListener
          (
            document,
            { keys: 27 /* ESC */ },
            { fn: oInstance.replyCommentClose },
            'keyup'
          ) : null;


          oInstance.hReplyYuiPanel = typeof(YAHOO.widget.Panel) != 'undefined' ? new YAHOO.widget.Panel(oInstance.hCommentsReply,
            {
              width: '400px',
              visible: false,
              constraintoviewport: true,
              fixedcenter: true,
              close: false,
  	          modal: true,
  	          zindex: 9999,
  	          /* effect: { effect: YAHOO.widget.ContainerEffect.FADE, duration: 0.25 }, */
  	          keylisteners: oInstance.hEditingKeyListener
            }
          ) : null;


          oInstance.hInformationYuiPanel = typeof(YAHOO.widget.Panel) != 'undefined' ? new YAHOO.widget.Panel(oInstance.hCommentsInformation,
            {
              width: '400px',
              visible: false,
              constraintoviewport: true,
              fixedcenter: true,
              close: false,
  	          modal: true,
  	          zindex: 99999
            }
          ) : null;


          if ( oInstance.hComments && oInstance.hCommentsLoader && oInstance.hCommentsInformation && oInstance.hCommentsList && oInstance.hCommentsReply && oInstance.hCommentsNewReplyContainer && oInstance.hCommentsNewReply && oInstance.hCommentsReplyForm && oInstance.hAuthorContainer && oInstance.hHomePageContainer && oInstance.hEMailContainer && oInstance.hEMailNotificationContainer && oInstance.hVoteContainer && oInstance.hCaptchaContainer && oInstance.hContentContainer && oInstance.hTitleContainer && oInstance.hAuthorError && oInstance.hHomePageError && oInstance.hEMailError && oInstance.hEMailNotificationError && oInstance.hVoteError && oInstance.hCaptchaError && oInstance.hContentError && oInstance.hTitleError && oInstance.hAuthor && oInstance.hHomePage && oInstance.hEMail && oInstance.hEMailNotification && oInstance.hTitle && oInstance.hCaptchaImage && oInstance.hCaptcha && oInstance.hCaptchaRefresh && oInstance.hContent && oInstance.hReplyClose && oInstance.hReplySubmit && oInstance.hVote0Container && oInstance.hVote0Image && oInstance.hVote0 && oInstance.hVote1 && oInstance.hVote2 && oInstance.hVote3 && oInstance.hVote4 && oInstance.hVote5 && oInstance.hVote6 && oInstance.hPager && oInstance.hPagerInfo && oInstance.hPagerList && oInstance.hReplyYuiPanel && oInstance.hInformationYuiPanel && oInstance.hEditingKeyListener )
          {
            oInstance.hCommentsReply.style.display = 'none';
            oInstance.hReplyYuiPanel.render( );

            oInstance.hCommentsInformation.style.display = 'none';
            oInstance.hInformationYuiPanel.render( );

            oInstance.bIsInitialized = true;
            return true;
          }

          else
            alert( 'Alcuni componenti DHTML sono mancanti oppure le librerie Yahoo! YUI non sono state caricate.' );
        }

        return false;
      };


      oInstance.asyncCall = function( strUrl, strPostData, fCallBack )
      {
        var hHttpRequest = null;

        if( window.XMLHttpRequest )
        {
          try
          {
            hHttpRequest = new XMLHttpRequest( );
          }

          catch( oErr )
          {
            hHttpRequest = null;
          }
        }

        else if( window.ActiveXObject )
        {
          var aStrMsxhtml = new Array( 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP' );

          for ( var i = 0; i < aStrMsxhtml.length && !hHttpRequest; i++ )
          {
            try
            {
              hHttpRequest = new ActiveXObject( aStrMsxhtml[i] );
            }

            catch( oErr )
            {
              hHttpRequest = null;
            }
          }
        }

        if ( hHttpRequest != null )
        {
          hHttpRequest.onreadystatechange = function( )
          {
            if ( hHttpRequest.readyState == 4 )
              fCallBack(hHttpRequest.status == 200 && hHttpRequest.responseText ? hHttpRequest.responseText : null );
          }

          hHttpRequest.open( strPostData == null ? 'GET' : 'POST', strUrl, true );

          if ( strPostData != null )
          {
            hHttpRequest.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
            hHttpRequest.setRequestHeader( 'Content-Length', strPostData.length );
          }

          hHttpRequest.setRequestHeader( 'If-Modified-Since', 'Thu, 01 Jan 1970 00:00:00 GMT' );
          hHttpRequest.setRequestHeader( 'X-Requested-With', 'XMLHttpRequest' );

          hHttpRequest.send( strPostData );

          return true;
        }

        fCallBack( null );
        return false;
      };


      oInstance.fixFlash = function( )
      {
        try
        {
          var aObjects = document.getElementsByTagName( 'object' );
          for ( var i = 0; i < aObjects.length; i++ )
          {
            var oObject = aObjects[i];
            var bFoundWmodeParam = false;

            var aParams = oObject.getElementsByTagName( 'param' );
            for ( var j = 0; j < aParams.length; j++ )
            {
              var oParam = aParams[j];

              if ( (oParam.getAttribute && oParam.getAttribute('name').toLowerCase() == 'wmode') || oParam.name.toLowerCase() == 'wmode' )
              {
                if ( oParam.setAttribute )
                  oParam.setAttribute( 'value', 'opaque' );
                oParam.wmode = 'opaque';

                bFoundWmodeParam = true;
              }
            }

            if ( !bFoundWmodeParam )
            {
              var oParam = document.createElement( 'param' );
                if ( oParam.setAttribute )
                {
                  oParam.setAttribute( 'name', 'wmode' );
                  oParam.setAttribute( 'value', 'opaque' );
                }

                oParam.name = 'wmode';
                oParam.value = 'opaque';

              oObject.appendChild( oParam );
            }
          }


          var aEmbeds = document.getElementsByTagName( 'embed' );
          for ( var i = 0; i < aEmbeds.length; i++ )
          {
            var oEmbed = aEmbeds[i];

            if ( oEmbed.setAttribute )
              oEmbed.setAttribute( 'wmode', 'opaque' );

            oEmbed.wmode = 'opaque';
          }

          return true;
        }

        catch ( e )
        {
        }

        return false;
      };


      oInstance.trimString = function( strString )
      {
        return strString.replace( /^[\s]+|[\s]+$/gi, '' );
      };


      oInstance.escapeString = function( strString )
      {
        strString = strString.replace( /[&]/gi, '&amp;' );
        strString = strString.replace( /[\042]/gi, '&quot;' );
        strString = strString.replace( /[\047]/gi, '&#039;' );
        strString = strString.replace( /[<]/gi, '&lt;' );
        strString = strString.replace( /[>]/gi, '&gt;' );

        return strString;
      };


      oInstance.newLineToBreakLine = function( strString )
      {
        return strString.replace( /[\n]/gi, '<br />\n' );
      };


      oInstance.isVoteValid = function( iVote )
      {
        return iVote >= 1 && iVote <= 6;
      }


      oInstance.getPageLink = function( iPage )
      {
        iPage = parseInt( iPage );

        if ( !isNaN(iPage) && iPage >= 1 )
        {
          var strCurrentLocation =  location.pathname;
	        var strCurrentQueryString = location.search.substring( 1 );

          if ( /\/pag\/[^\/]+/.test(strCurrentLocation) )
            strCurrentLocation = strCurrentLocation.replace( /\/pag\/[^\/]+/g, iPage > 1 ? '/pag/' + iPage : '' );

          else if ( iPage > 1 )
            strCurrentLocation += '/pag/' + iPage;

  	      if ( strCurrentQueryString != '' )
  	      {
  	        var aQueryStringTokens = strCurrentQueryString.split( /[&]+/ );
              var aNewQueryStringTokens = new Array( );

              for ( var i = 0; i < aQueryStringTokens.length; i++ )
              {
                if ( !/^pag(=[\s\S]*)$/.test(aQueryStringTokens[i]) )
                  aNewQueryStringTokens[ aNewQueryStringTokens.length ] = aQueryStringTokens[i];
              }

              strCurrentQueryString = aNewQueryStringTokens.length ? ('?' + aNewQueryStringTokens.join('&')) : '';
  	      }

          return strCurrentLocation + strCurrentQueryString;
        }

        return null;
      };


      oInstance.isWorking = function( )
      {
        return oInstance.bIsWorking;
      };


      oInstance.setWorking = function( bWorking, bHideAnimation )
      {
        oInstance.bIsWorking = bWorking;

        if ( oInstance.bIsInitialized )
          oInstance.hCommentsLoader.style.display = bWorking && !bHideAnimation ? '' : 'none';

        return true;
      };


      oInstance.isReplying = function( )
      {
        return oInstance.bIsReplying;
      };


      oInstance.setReplying = function( bReplying )
      {
        oInstance.bIsReplying = bReplying;
        return true;
      };


      oInstance.list = function( iPage, bAutoUpdate )
      {
        iPage = parseInt( iPage );
        if ( isNaN(iPage) || iPage < 1 ) iPage = null;


        if ( oInstance.bIsInitialized && !oInstance.isWorking() && !oInstance.isReplying() )
        {
          var aParams = new Array( );
          aParams[ aParams.length ] = 'rand_' + Math.round(Math.random()*999999999) + '=' + Math.round(Math.random()*999999999);


          if ( oInstance.oPager.pager )
          {
            aParams[ aParams.length ] = 'mode=1';
            aParams[ aParams.length ] = 'page=' + encodeURIComponent( iPage ? iPage : oInstance.oPager.current );
          }

          else
            aParams[ aParams.length ] = 'mode=0';


          aParams[ aParams.length ] = 'object_type=' + encodeURIComponent( oInstance.iObjectType );
          aParams[ aParams.length ] = 'object_id=' + encodeURIComponent( oInstance.iObjectId );


          oInstance.setWorking( true, bAutoUpdate );
          oInstance.asyncCall( oInstance.asyncUrl, aParams.join('&'),
            function( strResponse )
            {
              oInstance.setWorking( false, false );

              if ( strResponse != null )
              {
                try
                {
                  var oResponse = eval( '(' + strResponse + ')' );
                }

                catch ( e )
                {
                  var oResponse = null;
                }

                if ( oResponse != null && typeof oResponse == 'object' )
                {
                  if ( oResponse.success )
                  {
                    oInstance.oObject = oResponse.response.object;
                    oInstance.oOptions = oResponse.response.options;
                    oInstance.oUser = oResponse.response.user;
                    oInstance.oPager = oResponse.response.pager;
                    oInstance.oErrors = oResponse.response.errors;
                    oInstance.oWarnings = oResponse.response.warnings;
                    oInstance.oInformations = oResponse.response.informations;

                    if ( oInstance.oOptions.comments_enabled )
                    {
                      oInstance.hCommentsList.style.display = 'none';
                      var bGloballyFoundLastComment = false;

                      var fRecursiveUnroll = function( hParentCommentContainer, aComment, iComment )
                      {
                        var bFoundLastComment = false;
                        var bHiddenChildren = oInstance.oOptions.loaded_level >= 0 && aComment.level >= oInstance.oOptions.loaded_level;

                        var hNewCommentContainer = document.createElement( 'div' );
                          hNewCommentContainer.className = 'bs_ic' + (' bs_ic' + (iComment % 2 == 0 ? '1' : '2')) + (' bs_icLevel_' + aComment.level);

                          if ( oInstance.iLastCommentId && oInstance.iLastCommentId == aComment.id )
                          {
                            hNewCommentContainer.className += ' bs_icLatest';

                            var hLastestCommentAnchor = document.createElement( 'a' );
                              hLastestCommentAnchor.name = 'interactiveCommentsLatestAnchor_' + oInstance.strInstance;
                            hNewCommentContainer.appendChild( hLastestCommentAnchor );

                            bGloballyFoundLastComment = true;
                          }


                          var hNewCommentsReply = document.createElement( 'div' );
                            hNewCommentsReply.className = 'bs_icCont';

                            if ( oInstance.oOptions.show_avatar )
                            {
                              var hNewCommentAvatar = document.createElement( 'div' );
                                hNewCommentAvatar.className = 'bs_icAvatar';

                                var hNewCommentProfile = document.createElement( 'a' );
                                  hNewCommentProfile.href = aComment.is_logged && aComment.logged_author_profile ? aComment.logged_author_profile : (aComment.home_page ? aComment.home_page : '#');
                                  hNewCommentProfile.target = '_blank';
                                  hNewCommentProfile.title = aComment.is_logged && aComment.logged_author_profile ? 'Profilo di ' + aComment.author : aComment.author;

                                  if ( !(aComment.is_logged && aComment.logged_author_profile) && !aComment.home_page )
                                    hNewCommentProfile.onclick = function() { oInstance.warnNoUserLink( ); return false; };

                                  else
                                    hNewCommentProfile.onclick = function() { return oInstance.confirmUserLink( this ); };


                                  var hNewCommentProfileImage = document.createElement( 'img' );
                                    hNewCommentProfileImage.alt = aComment.is_logged && aComment.logged_author_avatar ? 'Avatar di ' + aComment.author : aComment.author;
                                    hNewCommentProfileImage.src = aComment.is_logged ? (aComment.vote == 0 && aComment.logged_author_avatar ? aComment.logged_author_avatar : (oInstance.isVoteValid(aComment.vote) ? '/images/avatars/' +aComment.vote+ '.gif' : '/images/avatars/0.gif')) : (oInstance.isVoteValid(aComment.vote) ? '/images/avatars/' + aComment.vote + '.gif' : '/images/avatars/0.gif');
                                    hNewCommentProfileImage.onerror = function() { oInstance.checkUserAvatar( this, false ); }
                                    hNewCommentProfileImage.onload = function() { oInstance.checkUserAvatar( this, true ); }

                                  hNewCommentProfile.appendChild( hNewCommentProfileImage );

                                hNewCommentAvatar.appendChild( hNewCommentProfile );

                              hNewCommentsReply.appendChild( hNewCommentAvatar );
                            }


                            var hNewCommentsReplyHead = document.createElement( 'div' );
                              hNewCommentsReplyHead.className = 'bs_icHead';

                              var hNewCommentUserHomePage = document.createElement( 'a' );
                                hNewCommentUserHomePage.target = '_blank';
                                hNewCommentUserHomePage.rel = 'nofollow';

                                if ( aComment.home_page )
                                {
                                  hNewCommentUserHomePage.href = aComment.home_page;
                                  hNewCommentUserHomePage.onclick = function( ) { return oInstance.confirmUserLink( this ); }
                                }

                                else if ( aComment.is_logged && aComment.logged_author_profile )
                                {
                                  hNewCommentUserHomePage.href = aComment.logged_author_profile;
                                  hNewCommentUserHomePage.onclick = function( ) { return oInstance.confirmUserLink( this ); }
                                }

                                else
                                {
                                  hNewCommentUserHomePage.href = '#';
                                  hNewCommentUserHomePage.onclick = function() { oInstance.warnNoUserLink( ); return false; };
                                }

                                hNewCommentUserHomePage.appendChild( document.createTextNode(aComment.author) );
                              hNewCommentsReplyHead.appendChild( hNewCommentUserHomePage );

                              var hNewCommentUserPostDate = document.createElement( 'span' );
                                hNewCommentUserPostDate.title = aComment.created_at;
                                hNewCommentUserPostDate.appendChild( document.createTextNode(aComment.created_at_human) );
                              hNewCommentsReplyHead.appendChild( hNewCommentUserPostDate );

                            hNewCommentsReply.appendChild( hNewCommentsReplyHead );


                            var hNewCommentsReplyText = document.createElement( 'div' );
                              hNewCommentsReplyText.className = 'bs_icText';

                              var hNewCommentTitle = document.createElement( 'h4' );
                                hNewCommentTitle.appendChild( document.createTextNode(aComment.title) );
                              hNewCommentsReplyText.appendChild( hNewCommentTitle );

                              var hNewCommentContent = document.createElement( 'p' );
                                hNewCommentContent.id = 'interactiveCommentsCommentContent_' + oInstance.strInstance +'_' + aComment['id'];

                                if ( oInstance.oOptions.show_extended_gui )
                                  hNewCommentContent.innerHTML = aComment.content_html;
                                else
                                  hNewCommentContent.appendChild( document.createTextNode(aComment.content) );

                              hNewCommentContent.innerHTML = oInstance.newLineToBreakLine( hNewCommentContent.innerHTML );
                              hNewCommentsReplyText.appendChild( hNewCommentContent );


                              if ( !aComment['level'] )
                              {
                                var hNewCommentsReplyCount = document.createElement( 'div' );
                                  hNewCommentsReplyCount.className = 'bs_icCount';
                                  hNewCommentsReplyCount.appendChild( document.createTextNode( 'n° ' + ((oInstance.oPager.paged ? (oInstance.oPager.elements - (oInstance.oPager.current-1)*oInstance.oOptions.pager_elements ) : oInstance.oPager.elements) - iComment) ) );

                                  if ( oInstance.oOptions.show_threaded_comments )
                                  {
                                    hNewCommentsReplyCount.title = aComment.last_comment_available ? ('Ultima risposta di ' + aComment.last_comment.author + (aComment.last_comment.is_logged ? ' (loggato)' : '') + ' scritta ' + aComment.last_comment.created_at_human + ': "' + aComment.last_comment.title + '"') : 'Non ci sono risposte';
                                    hNewCommentsReplyCount.style.cursor = 'help';
                                  }

                                hNewCommentsReplyText.appendChild( hNewCommentsReplyCount );
                              }


                              if ( oInstance.oOptions.show_threaded_comments )
                              {
                                var hNewCommentReplyBox = document.createElement( 'div' );
                                  hNewCommentReplyBox.className = 'bs_icReplyLink';

                                  if ( aComment.descendants_count > 0 )
                                  {
                                    var hNewCommentReplyCount = document.createElement( 'u' );

                                      if ( aComment.descendants_count == 1 )
                                        hNewCommentReplyCount.appendChild( document.createTextNode('1 risposta') );

                                      else
                                        hNewCommentReplyCount.appendChild( document.createTextNode(aComment.descendants_count + ' risposte') );

                                    hNewCommentReplyBox.appendChild( hNewCommentReplyCount );


                                    var hNewCommentReplySeparator = document.createElement( 'font' );
                                      hNewCommentReplySeparator.appendChild( document.createTextNode('-') )
                                    hNewCommentReplyBox.appendChild( hNewCommentReplySeparator );

                                    var hNewCommentChildrenToggle = document.createElement( 'a' );
                                      hNewCommentChildrenToggle.href = '#';
                                      hNewCommentChildrenToggle.title = 'Vedi/Nascondi le risposte';
                                      hNewCommentChildrenToggle.onclick = function() { oInstance.toggleChildren( this, aComment.id ); return false; };
                                    hNewCommentReplyBox.appendChild( hNewCommentChildrenToggle );
                                  }

                                  if ( oInstance.oUser.can_comment && oInstance.oUser.can_comment_extended )
                                  {
                                    if ( aComment.descendants_count > 0 )
                                    {
                                      var hNewCommentReplySeparator = document.createElement( 'font' );
                                        hNewCommentReplySeparator.appendChild( document.createTextNode('|') )
                                      hNewCommentReplyBox.appendChild( hNewCommentReplySeparator );
                                    }


                                    var hNewCommentQuoteCreate = document.createElement( 'a' );
                                      hNewCommentQuoteCreate.href = '#';
                                      hNewCommentQuoteCreate.title = 'Rispondi a questo commento quotando';
                                      hNewCommentQuoteCreate.onclick = function() { oInstance.replyComment( aComment.id, aComment.title, true ); return false; };
                                      hNewCommentQuoteCreate.appendChild( document.createTextNode('quota') );
                                    hNewCommentReplyBox.appendChild( hNewCommentQuoteCreate );


                                    var hNewCommentReplySeparator = document.createElement( 'font' );
                                      hNewCommentReplySeparator.appendChild( document.createTextNode('-') )
                                    hNewCommentReplyBox.appendChild( hNewCommentReplySeparator );

                                    var hNewCommentReplyCreate = document.createElement( 'a' );
                                      hNewCommentReplyCreate.href = '#';
                                      hNewCommentReplyCreate.title = 'Rispondi a questo commento';
                                      hNewCommentReplyCreate.onclick = function() { oInstance.replyComment( aComment.id, aComment.title, false ); return false; };
                                      hNewCommentReplyCreate.appendChild( document.createTextNode('rispondi') );
                                    hNewCommentReplyBox.appendChild( hNewCommentReplyCreate );
                                  }

                                hNewCommentsReplyText.appendChild( hNewCommentReplyBox );
                              }

                            hNewCommentsReply.appendChild( hNewCommentsReplyText );

                          hNewCommentContainer.appendChild( hNewCommentsReply );


                        if ( oInstance.oOptions.show_threaded_comments && aComment.children_count > 0 )
                        {
                          var hNewCommentChildrenContainer = document.createElement( 'div' );
                            hNewCommentChildrenContainer.id = 'interactiveCommentsListContainerChildren_' + oInstance.strInstance + '_' + aComment.id;

                            for ( var iChildrenCommentId in aComment.children )
                            {
                              if ( arguments.callee(hNewCommentChildrenContainer, aComment.children[iChildrenCommentId], iComment) )
                                bFoundLastComment = true;
                            }

                            hNewCommentChildrenContainer.style.display = bHiddenChildren && !bFoundLastComment ? 'none' : '';

                            if ( hNewCommentChildrenToggle )
                              hNewCommentChildrenToggle.appendChild( document.createTextNode( bHiddenChildren && !bFoundLastComment ? 'vedi' : 'nascondi' ) );

                            hNewCommentContainer.appendChild( hNewCommentChildrenContainer );
                        }

                        hParentCommentContainer.appendChild( hNewCommentContainer );

                        return (oInstance.iLastCommentId && oInstance.iLastCommentId == aComment.id) || bFoundLastComment;
                      };


                      while ( oInstance.hCommentsList.firstChild )
                        oInstance.hCommentsList.removeChild( oInstance.hCommentsList.firstChild );


                      var iComment = 0;
                      for ( var iCommentId in oResponse.response.data )
                        fRecursiveUnroll( oInstance.hCommentsList, oResponse.response.data[iCommentId], iComment++ );


                      oInstance.hCommentsNewReplyContainer.style.display = oInstance.oUser.can_comment && oInstance.oUser.can_comment_extended ? '' : 'none';
                      oInstance.hCommentsList.style.display = '';

                      oInstance.buildPager( );

                      if ( !bAutoUpdate )
                        location.href = (bGloballyFoundLastComment ? '#interactiveCommentsLatestAnchor_' : '#interactiveCommentsListAnchor_') + oInstance.strInstance;

                      if ( oInstance.oPager.pager )
                      {
                        if ( oInstance.oPager.current == 1 )
                          document.title = 'Commenti a "' + (oInstance.oObject.title ? oInstance.oObject.title : '') + '"';

                        else
                          document.title = 'Commenti a "' + (oInstance.oObject.title ? oInstance.oObject.title : '') + '" - pagina ' + oInstance.oPager.current;
                      }


                      if ( oInstance.hOptionalCommentsCounter )
                      {
                        while ( oInstance.hOptionalCommentsCounter.firstChild )
                          oInstance.hOptionalCommentsCounter.removeChild( oInstance.hOptionalCommentsCounter.firstChild );

                        oInstance.hOptionalCommentsCounter.appendChild( document.createTextNode('(' + oInstance.oPager.elements + ')') );
                        oInstance.hOptionalCommentsCounter.title = oInstance.oPager.elements == 1 ? 'C\'è un solo argomento' : ('Ci sono ' + oInstance.oPager.elements + ' argomenti');
                        oInstance.hOptionalCommentsCounter.style.display = !oInstance.oPager.elements ? 'none' : '';
                      }

                      if ( oInstance.hOptionalRefresh )
                        oInstance.hOptionalRefresh.style.display = oInstance.oPager.elements ? '' : 'none';

                      if ( oInstance.hOptionalFeed )
                        oInstance.hOptionalFeed.style.display = oInstance.oPager.elements ? '' : 'none';

                      if ( oInstance.hOptionalPagedList )
                        oInstance.hOptionalPagedList.style.display = oInstance.oPager.elements ? '' : 'none';


                      oInstance.hComments.style.display = oInstance.oPager.elements || (oInstance.oUser.can_comment && oInstance.oUser.can_comment_extended) ? '' : 'none';
                    }

                    else
                      oInstance.hComments.style.display = 'none';
                  }

                  else if ( !bAutoUpdate )
                    alert( oResponse.description );
                }

                else if ( !bAutoUpdate )
                  alert( 'Il server ha risposto con dei dati corrotti: riprovare più tardi.' );
              }

              else if ( !bAutoUpdate )
                alert( 'Il server ha risposto in modo inatteso oppure la connessione è stata annullata: riprovare più tardi.' );
            }
          );
        }

        return false;
      };


      oInstance.toggleChildren = function( hHref, iCommentId )
      {
        if ( oInstance.bIsInitialized && !oInstance.isWorking() )
        {
          var hChildrenContainer = document.getElementById( 'interactiveCommentsListContainerChildren_' + oInstance.strInstance + '_' + iCommentId );

          if ( hChildrenContainer && hHref )
          {
            while ( hHref.firstChild )
              hHref.removeChild( hHref.firstChild );

            if ( hChildrenContainer.style.display.toLowerCase() == 'none' )
            {
              hChildrenContainer.style.display = '';
              hHref.appendChild( document.createTextNode('nascondi') );
            }

            else
            {
              hChildrenContainer.style.display = 'none';
              hHref.appendChild( document.createTextNode('vedi') );
            }

            return true;
          }

          else
            alert( 'Alcuni componenti DHTML sono mancanti.' );
        }

        return false;
      };


      oInstance.initReplyComment = function( bInitFields, strInitTitle, strInitContent )
      {
        if ( oInstance.bIsInitialized && !oInstance.isWorking() )
        {
          if ( oInstance.oOptions != null && oInstance.oUser != null )
          {
            if ( bInitFields )
            {
              if ( oInstance.trimString(oInstance.hEMail.value) == '' )
                oInstance.hEMail.value = oInstance.oUser.is_logged && oInstance.oUser.user_email ? oInstance.oUser.user_email : '';

              oInstance.hEMailNotification.checked = false;
              oInstance.hTitle.value = strInitTitle ? strInitTitle : '';
              oInstance.hContent.value = strInitContent ? strInitContent : '';

              oInstance.hVote0.checked = oInstance.oUser.is_logged ? true : false;
              oInstance.hVote1.checked = false;
              oInstance.hVote2.checked = false;
              oInstance.hVote3.checked = false;
              oInstance.hVote4.checked = false;
              oInstance.hVote5.checked = false;
              oInstance.hVote6.checked = false;

              oInstance.refreshCaptcha( true );
            }

            if ( /\bbs_icError\b/.test(oInstance.hAuthorContainer.className) )
              oInstance.hAuthorContainer.className = oInstance.hAuthorContainer.className.replace( /\bbs_icError\b/g, '' );

            if ( /\bbs_icError\b/.test(oInstance.hEMailContainer.className) )
              oInstance.hEMailContainer.className = oInstance.hEMailContainer.className.replace( /\bbs_icError\b/g, '' );

            if ( /\bbs_icError\b/.test(oInstance.hEMailNotificationContainer.className) )
              oInstance.hEMailNotificationContainer.className = oInstance.hAuthorContainer.className.replace( /\bbs_icError\b/g, '' );

            if ( /\bbs_icError\b/.test(oInstance.hVoteContainer.className) )
              oInstance.hVoteContainer.className = oInstance.hVoteContainer.className.replace( /\bbs_icError\b/g, '' );

            if ( /\bbs_icError\b/.test(oInstance.hCaptchaContainer.className) )
              oInstance.hCaptchaContainer.className = oInstance.hCaptchaContainer.className.replace( /\bbs_icError\b/g, '' );

            if ( /\bbs_icError\b/.test(oInstance.hTitleContainer.className) )
              oInstance.hTitleContainer.className = oInstance.hTitleContainer.className.replace( /\bbs_icError\b/g, '' );

            if ( /\bbs_icError\b/.test(oInstance.hContentContainer.className) )
              oInstance.hContentContainer.className = oInstance.hContentContainer.className.replace( /\bbs_icError\b/g, '' );


            oInstance.hAuthorError.style.display = 'none';
            while ( oInstance.hAuthorError.firstChild )
              oInstance.hAuthorError.removeChild( oInstance.hAuthorError.firstChild );

            oInstance.hEMailError.style.display = 'none';
            while ( oInstance.hEMailError.firstChild )
              oInstance.hEMailError.removeChild( oInstance.hEMailError.firstChild );

            oInstance.hEMailNotificationError.style.display = 'none';
            while ( oInstance.hEMailNotificationError.firstChild )
              oInstance.hEMailNotificationError.removeChild( oInstance.hEMailNotificationError.firstChild );

            oInstance.hHomePageError.style.display = 'none';
            while ( oInstance.hHomePageError.firstChild )
              oInstance.hHomePageError.removeChild( oInstance.hHomePageError.firstChild );

            oInstance.hVoteError.style.display = 'none';
            while ( oInstance.hVoteError.firstChild )
              oInstance.hVoteError.removeChild( oInstance.hVoteError.firstChild );

            oInstance.hCaptchaError.style.display = 'none';
            while ( oInstance.hCaptchaError.firstChild )
              oInstance.hCaptchaError.removeChild( oInstance.hCaptchaError.firstChild );

            oInstance.hTitleError.style.display = 'none';
            while ( oInstance.hTitleError.firstChild )
              oInstance.hTitleError.removeChild( oInstance.hTitleError.firstChild );

            oInstance.hContentError.style.display = 'none';
            while ( oInstance.hContentError.firstChild )
              oInstance.hContentError.removeChild( oInstance.hContentError.firstChild );


            if ( oInstance.oUser.is_logged )
              oInstance.hAuthor.value = oInstance.oUser.user_name ? oInstance.oUser.user_name : '';

            with ( oInstance.hAuthor )
            {
              readOnly = oInstance.oUser.is_logged ? true : false;
              disabled = oInstance.oUser.is_logged ? true : false;
            }


            oInstance.hVote0Container.style.display = oInstance.oUser.is_logged ? '' : 'none';

            oInstance.hVote0Image.userAvatarChecked = false;
            oInstance.hVote0Image.onerror = function() { oInstance.checkUserAvatar( this, false ); }
            oInstance.hVote0Image.onload = function() { oInstance.checkUserAvatar( this, true ); }
            oInstance.hVote0Image.src = oInstance.oUser.is_logged && oInstance.oUser.user_avatar ? oInstance.oUser.user_avatar : '/images/avatars/0.gif';


            oInstance.hEMailContainer.style.display = oInstance.oOptions.show_email ? '' : 'none';
            oInstance.hEMailNotificationContainer.style.display = oInstance.oOptions.show_email && oInstance.oOptions.email_notification ? '' : 'none';
            oInstance.hHomePageContainer.style.display = oInstance.oOptions.show_home_page ? '' : 'none';
            oInstance.hVoteContainer.style.display = oInstance.oOptions.show_vote ? '' : 'none';
            oInstance.hCaptchaContainer.style.display = oInstance.oOptions.show_captcha && !oInstance.oUser.is_logged ? '' : 'none';

            if ( window.tinyMCE && tinyMCE.init && !tinyMCE.__initialized )
            {
              tinyMCE.__initialized = true;
              
              if ( window.tinymce && tinymce.create && tinymce.PluginManager )
              {
                tinymce.create( 'tinymce.plugins.interactiveCommentsEmoticonsPlugin',
                {
                  createControl: function( n, cm )
                  {
                    switch ( n )
                    {
                      case 'interactiveCommentsEmoticonsButton':
                        var c = cm.createMenuButton('interactiveCommentsEmoticonsButton',
                        {
                          title: 'Emoticons',
                          image: '/images/be/smiles/sereno.gif',
                          icons: false
                        });

                        c.onRenderMenu.add( function(c, m)
                        {
                          m.add({title: ':)', onclick : function() {
                            tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, ' :)' );
                          }});
                        });

                        c.onRenderMenu.add( function(c, m)
                        {
                          m.add({title: ':(', onclick : function() {
                            tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, ' :(' );
                          }});
                        });

                        c.onRenderMenu.add( function(c, m)
                        {
                          m.add({title: ':D', onclick : function() {
                            tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, ' :D' );
                          }});
                        });

                        c.onRenderMenu.add( function(c, m)
                        {
                          m.add({title: ':|', onclick : function() {
                            tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, ' :|' );
                          }});
                        });

                        c.onRenderMenu.add( function(c, m)
                        {
                          m.add({title: ':/', onclick : function() {
                            tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, ' :/' );
                          }});
                        });

                        c.onRenderMenu.add( function(c, m)
                        {
                          m.add({title: 'xD', onclick : function() {
                            tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, ' xD' );
                          }});
                        });

                        c.onRenderMenu.add( function(c, m)
                        {
                          m.add({title: '8)', onclick : function() {
                            tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, ' 8)' );
                          }});
                        });

                        c.onRenderMenu.add( function(c, m)
                        {
                          m.add({title: '8|', onclick : function() {
                            tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, ' 8|' );
                          }});
                        });

                        c.onRenderMenu.add( function(c, m)
                        {
                          m.add({title: ':*', onclick : function() {
                            tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, ' :*' );
                          }});
                        });

                        c.onRenderMenu.add( function(c, m)
                        {
                          m.add({title: ':P', onclick : function() {
                            tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, ' :P' );
                          }});
                        });

                        c.onRenderMenu.add( function(c, m)
                        {
                          m.add({title: ':O', onclick : function() {
                            tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, ' :O' );
                          }});
                        });

                        c.onRenderMenu.add( function(c, m)
                        {
                          m.add({title: ':@', onclick : function() {
                            tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, ' :@' );
                          }});
                        });

                        c.onRenderMenu.add( function(c, m)
                        {
                          m.add({title: 'x|', onclick : function() {
                            tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, ' x|' );
                          }});
                        });

                        return c;
                    }

                    return null;
                  }
                });

                tinymce.PluginManager.add( 'interactiveCommentsEmoticonsPlugin', tinymce.plugins.interactiveCommentsEmoticonsPlugin );
              }

              tinyMCE.init
              ({
                language: 'it',

                mode: 'textareas',
                theme: 'advanced',
                plugins: 'safari,bbcode,fullscreen,-interactiveCommentsEmoticonsPlugin',

                force_p_newlines: true,
                force_br_newlines: true,
                remove_linebreaks: false,
                convert_newlines_to_brs: false,
                convert_fonts_to_spans: false,
                inline_styles: false,
                forced_root_block: '',
                theme_advanced_more_colors: false,
                theme_advanced_default_foreground_color: '#FF0000',
                force_hex_style_colors: true,

                valid_elements: '-b/-strong,-i/-em,-u,-font[color],br',

                theme_advanced_buttons1: 'interactiveCommentsEmoticonsButton,|,bold,italic,underline,forecolor,|,undo,redo,|,removeformat,cleanup,|,fullscreen',
                theme_advanced_buttons2: '',
                theme_advanced_buttons3: '',
                theme_advanced_buttons4: '',
                theme_advanced_toolbar_location: 'bottom',
                theme_advanced_toolbar_align: 'center',
                theme_advanced_resizing: false,

                entity_encoding: 'raw',
                add_unload_trigger: false,

                editor_selector: 'interactiveCommentsTinyMce'
              });
            }
            

            if ( window.tinyMCE && tinyMCE.activeEditor && tinyMCE.activeEditor.load )
              tinyMCE.activeEditor.load( );
          }
        }

        return false;
      };


      oInstance.lockReplyComment = function( bLock )
      {
        if ( oInstance.bIsInitialized && !oInstance.isWorking() && oInstance.isReplying() )
        {
          if ( oInstance.oOptions != null && oInstance.oUser != null )
          {
            oInstance.hAuthor.disabled = oInstance.oUser.is_logged ? true : bLock;
            oInstance.hVote0.disabled = !oInstance.oUser.is_logged ? true : bLock;

            oInstance.hTitle.disabled = bLock;
            oInstance.hContent.disabled = bLock;
            oInstance.hHomePage.disabled = bLock;
            oInstance.hEMail.disabled = bLock;
            oInstance.hEMailNotification.disabled = bLock;
            oInstance.hCaptcha.disabled = bLock;
            oInstance.hReplySubmit.disabled = bLock;

            oInstance.hVote1.disabled = bLock;
            oInstance.hVote2.disabled = bLock;
            oInstance.hVote3.disabled = bLock;
            oInstance.hVote4.disabled = bLock;
            oInstance.hVote5.disabled = bLock;
            oInstance.hVote6.disabled = bLock;
            
            if ( window.tinyMCE && tinyMCE.activeEditor && tinyMCE.activeEditor.setProgressState )
              tinyMCE.activeEditor.setProgressState( bLock );

            return true;
          }
        }

        return false;
      };



      oInstance.replyComment = function( iReplyCommentId, strReplyCommentTitle, bQuote )
      {
        if ( oInstance.bIsInitialized && !oInstance.isWorking() && !oInstance.isReplying() )
        {
          if ( oInstance.oOptions != null && oInstance.oUser != null )
          {
            iReplyCommentId = parseInt( iReplyCommentId );
            if ( isNaN(iReplyCommentId) || iReplyCommentId < 0 ) iReplyCommentId = 0;

            if ( oInstance.oOptions.comments_enabled )
            {
              if ( oInstance.oUser.can_comment && oInstance.oUser.can_comment_extended )
              {
                if ( iReplyCommentId > 0 ? oInstance.oOptions.show_threaded_comments : true )
                {
                  var strReplyCommentContent = null;

                  if ( bQuote )
                  {
                    var oCommentContent = document.getElementById( 'interactiveCommentsCommentContent_' + oInstance.strInstance + '_' + iReplyCommentId );

                    if ( oCommentContent )
                    {
                      if ( typeof oCommentContent.innerText != typeof void(0) )
                        strReplyCommentContent = oInstance.trimString( oCommentContent.innerText );

                      else if ( typeof oCommentContent.textContent != typeof void(0) )
                        strReplyCommentContent = oInstance.trimString( oCommentContent.textContent );

                      if ( strReplyCommentContent != null )
                        strReplyCommentContent = strReplyCommentContent.replace( /(^)/mgi, '> $1' );
                    }
                  }

                  oInstance.iReplyCommentId = iReplyCommentId;
                  oInstance.initReplyComment( true, strReplyCommentTitle ? ('R: ' + strReplyCommentTitle).substring(0, 65535) : null, strReplyCommentContent );
                  oInstance.setReplying( true );

                  oInstance.fixFlash( );

                  if ( iReplyCommentId > 0 )
                    oInstance.hReplyYuiPanel.setHeader( 'Aggiungi una risposta a <i>' + oInstance.escapeString(strReplyCommentTitle)  + '</i> per <i>' + oInstance.escapeString(oInstance.oObject.title) + '</i>...' );
                  else
                    oInstance.hReplyYuiPanel.setHeader( 'Aggiungi un commento a <i>' + oInstance.escapeString(oInstance.oObject.title) + '</i>...' );

                  oInstance.hCommentsReply.style.display = '';
                  oInstance.hReplyYuiPanel.show( );

                  return true;
                }

                else
                  alert( 'Non è possibile rispondere in modo gerarchico ai commenti.' );
              }

              else
                alert( 'Non puoi scrivere nuovi commenti o aggiungere risposte.' );
            }

            else
              alert( 'I commenti sono disabilitati.' );
          }

          else
            alert( 'Inizializzazione non eseguita.' );
        }

        return false;
      };


      oInstance.replyCommentSubmit = function( )
      {
        if ( oInstance.bIsInitialized && !oInstance.isWorking() && oInstance.isReplying() )
        {
          if ( oInstance.oOptions != null && oInstance.oUser != null )
          {
            if ( oInstance.oOptions.comments_enabled )
            {
              if ( oInstance.oUser.can_comment && oInstance.oUser.can_comment_extended )
              {
                if ( oInstance.iReplyCommentId > 0 ? oInstance.oOptions.show_threaded_comments : true )
                {
                  if ( window.tinyMCE && tinyMCE.triggerSave )
                    tinyMCE.triggerSave( );

                  oInstance.initReplyComment( false, null, null );
                  oInstance.lockReplyComment( true );


                  var aParams = new Array( );
                  aParams[ aParams.length ] = 'rand_' + Math.round(Math.random()*999999999) + '=' + Math.round(Math.random()*999999999);

                  aParams[ aParams.length ] = 'mode=10';
                  aParams[ aParams.length ] = 'object_type=' + encodeURIComponent( oInstance.iObjectType );
                  aParams[ aParams.length ] = 'object_id=' + encodeURIComponent( oInstance.iObjectId );

                  aParams[ aParams.length ] = 'parent_id=' + encodeURIComponent( oInstance.iReplyCommentId );


                  if ( !oInstance.oUser.is_logged )
                    aParams[ aParams.length ] = 'author=' + encodeURIComponent( oInstance.trimString(oInstance.hAuthor.value) );


                  if ( oInstance.oOptions.show_email )
                    aParams[ aParams.length ] = 'e_mail=' + encodeURIComponent( oInstance.trimString(oInstance.hEMail.value) );

                  if ( oInstance.oOptions.show_home_page )
                    aParams[ aParams.length ] = 'home_page=' + encodeURIComponent( oInstance.trimString(oInstance.hHomePage.value) );

                  if ( oInstance.oOptions.show_email && oInstance.oOptions.email_notification )
                    aParams[ aParams.length ] = 'e_mail_notification=' + encodeURIComponent( oInstance.hEMailNotification.checked ? '1' : '0' );

                  if ( oInstance.oOptions.show_vote )
                  {
                    var iVote = '';

                    if ( oInstance.hVote0.checked )
                      iVote = oInstance.oUser.is_logged ? 0 : '';
                    else if ( oInstance.hVote1.checked )
                      iVote = 1;
                    else if ( oInstance.hVote2.checked )
                      iVote = 2;
                    else if ( oInstance.hVote3.checked )
                      iVote = 3;
                    else if ( oInstance.hVote4.checked )
                      iVote = 4;
                    else if ( oInstance.hVote5.checked )
                      iVote = 5;
                    else if ( oInstance.hVote6.checked )
                      iVote = 6;
                    else
                      iVote = '';

                    aParams[ aParams.length ] = 'vote=' + encodeURIComponent( iVote );
                  }

                  if ( oInstance.oOptions.show_captcha && !oInstance.oUser.is_logged )
                    aParams[ aParams.length ] = 'captcha=' + encodeURIComponent( oInstance.trimString(oInstance.hCaptcha.value) );

                  aParams[ aParams.length ] = 'title=' + encodeURIComponent( oInstance.trimString(oInstance.hTitle.value) );
                  aParams[ aParams.length ] = 'content=' + encodeURIComponent( oInstance.trimString(oInstance.hContent.value) );



                  oInstance.setWorking( true, false );
                  oInstance.hCaptchaImage.src = '/images/loading.gif';

                  oInstance.asyncCall( oInstance.asyncUrl, aParams.join('&'),
                    function( strResponse )
                    {
                      oInstance.setWorking( false, false );
                      oInstance.lockReplyComment( false );

                      oInstance.refreshCaptcha( true );

                      if ( strResponse != null )
                      {
                        try
                        {
                          var oResponse = eval( '(' + strResponse + ')' );
                        }

                        catch ( e )
                        {
                          var oResponse = null;
                        }

                        if ( oResponse != null && typeof oResponse == 'object' )
                        {
                          if ( oResponse.success )
                          {
                            oInstance.oObject = oResponse.response.object;
                            oInstance.oOptions = oResponse.response.options;
                            oInstance.oUser = oResponse.response.user;

                            oInstance.oErrors = oResponse.response.errors;
                            oInstance.oWarnings = oResponse.response.warnings;
                            oInstance.oInformations = oResponse.response.informations;


                            var aErrors = new Array( );
                            var aWarnings = new Array( );
                            

                            for ( var strErrorType in oInstance.oErrors )
                            {
                              aErrors[ aErrors.length ] = oInstance.oErrors[ strErrorType ];

                              switch ( strErrorType )
                              {
                                case 'author':
                                  if ( /\bbs_icError\b/.test(oInstance.hAuthorContainer.className) )
                                    oInstance.hAuthorContainer.className += ' bs_icError';

                                  oInstance.hAuthorError.appendChild( document.createTextNode(oInstance.oErrors[strErrorType]) );
                                  oInstance.hAuthorError.style.display = '';
                                  break;

                                case 'e_mail':
                                  if ( /\bbs_icError\b/.test(oInstance.hEMailContainer.className) )
                                    oInstance.hEMailContainer.className += ' bs_icError';

                                  oInstance.hEMailError.appendChild( document.createTextNode(oInstance.oErrors[strErrorType]) );
                                  oInstance.hEMailError.style.display = '';
                                  break;

                                case 'e_mail_banned':
                                  if ( /\bbs_icError\b/.test(oInstance.hEMailNotificationContainer.className) )
                                    oInstance.hEMailNotificationContainer.className += ' bs_icError';

                                  oInstance.hEMailNotificationError.appendChild( document.createTextNode(oInstance.oErrors[strErrorType]) );
                                  oInstance.hEMailNotificationError.style.display = '';
                                  break;

                                case 'email_notification':
                                  if ( /\bbs_icError\b/.test(oInstance.hEMailContainer.className) )
                                    oInstance.hEMailContainer.className += ' bs_icError';

                                  if ( /\bbs_icError\b/.test(oInstance.hEMailNotificationContainer.className) )
                                    oInstance.hEMailNotificationContainer.className += ' bs_icError';


                                  oInstance.hEMailError.appendChild( document.createTextNode(oInstance.oErrors[strErrorType]) );
                                  oInstance.hEMailNotificationError.appendChild( document.createTextNode(oInstance.oErrors[strErrorType]) );

                                  oInstance.hEMailError.style.display = '';
                                  oInstance.hEMailNotificationError.style.display = '';
                                  break;

                                case 'home_page':
                                  if ( /\bbs_icError\b/.test(oInstance.hHomePageContainer.className) )
                                    oInstance.hHomePageContainer.className += ' bs_icError';

                                  oInstance.hHomePageError.appendChild( document.createTextNode(oInstance.oErrors[strErrorType]) );
                                  oInstance.hHomePageError.style.display = '';
                                  break;

                                case 'vote':
                                  if ( /\bbs_icError\b/.test(oInstance.hVoteContainer.className) )
                                    oInstance.hVoteContainer.className += ' bs_icError';

                                  oInstance.hVoteError.appendChild( document.createTextNode(oInstance.oErrors[strErrorType]) );
                                  oInstance.hVoteError.style.display = '';
                                  break;

                                case 'title':
                                  if ( /\bbs_icError\b/.test(oInstance.hTitleContainer.className) )
                                    oInstance.hTitleContainer.className += ' bs_icError';

                                  oInstance.hTitleError.appendChild( document.createTextNode(oInstance.oErrors[strErrorType]) );
                                  oInstance.hTitleError.style.display = '';
                                  break;

                                case 'content':
                                  if ( /\bbs_icError\b/.test(oInstance.hContentContainer.className) )
                                    oInstance.hContentContainer.className += ' bs_icError';

                                  oInstance.hContentError.appendChild( document.createTextNode(oInstance.oErrors[strErrorType]) );
                                  oInstance.hContentError.style.display = '';
                                  break;

                                case 'captcha':
                                  if ( /\bbs_icError\b/.test(oInstance.hCaptchaContainer.className) )
                                    oInstance.hCaptchaContainer.className += ' bs_icError';

                                  oInstance.hCaptchaError.appendChild( document.createTextNode(oInstance.oErrors[strErrorType]) );
                                  oInstance.hCaptchaError.style.display = '';
                                  break;
                              }
                            }
                            
                            
                            for ( var strWarningType in oInstance.oWarnings )
                              aWarnings[ aWarnings.length ] = oInstance.oWarnings[ strWarningType ];
                            

                            if ( !aErrors.length )
                            {
                              oInstance.iLastCommentId = oResponse.response.data.id;

                              oInstance.hCommentsReply.style.display = 'none';
                              oInstance.hReplyYuiPanel.hide( );

                              oInstance.hCommentsInformation.style.display = '';

                              if ( aWarnings.length > 0 )
                              {
                                oInstance.hInformationYuiPanel.setHeader( 'Grazie per aver risposto a <i>' + oInstance.escapeString(oInstance.oObject.title) + '</i>...' );
                                oInstance.hInformationYuiPanel.setBody( oInstance.escapeString(oResponse.description) );
                                oInstance.hInformationYuiPanel.setFooter( '<img src="/images/be/progress.gif" alt="Caricamento in corso..." title="Caricamento in corso..." />' );
  
                                oInstance.hInformationYuiPanel.render();
                                oInstance.hInformationYuiPanel.show( );
  
                                window.setTimeout( function()
                                {
                                  oInstance.setReplying( false );
  
                                  oInstance.hInformationYuiPanel.hide( );
                                  oInstance.hCommentsInformation.style.display = 'none';
                                  oInstance.hCaptchaImage.src = '/images/loading.gif';
  
                                  if ( oInstance.oPager.pager )
                                  {
                                    if ( oResponse.response.data.parent_id )
                                      oInstance.list( null, false );
  
                                    else
                                      oInstance.list( 1, false );
                                  }
  
                                  else
                                    oInstance.list( null, false );
  
                                }, 2500 );
                              }
                              
                              else
                              {
                                oInstance.setReplying( false );
                                
                                oInstance.hInformationYuiPanel.hide( );
                                oInstance.hCommentsInformation.style.display = 'none';
                                oInstance.hCaptchaImage.src = '/images/loading.gif';

                                if ( oInstance.oPager.pager )
                                {
                                  if ( oResponse.response.data.parent_id )
                                    oInstance.list( null, false );

                                  else
                                    oInstance.list( 1, false );
                                }

                                else
                                  oInstance.list( null, false );
                              }
                            }
                          }

                          else
                            alert( oResponse.description );
                        }

                        else
                          alert( 'Il server ha risposto con dei dati corrotti: riprovare più tardi.' );
                      }

                      else
                        alert( 'Il server ha risposto in modo inatteso oppure la connessione è stata annullata: riprovare più tardi.' );
                    }
                  );

                  return true;
                }

                else
                  alert( 'Non è possibile rispondere in modo gerarchico ai commenti.' );
              }

              else
                alert( 'Non puoi scrivere nuovi commenti o aggiungere risposte.' );
            }

            else
              alert( 'I commenti sono disabilitati.' );
          }

          else
            alert( 'Inizializzazione non eseguita.' );
        }

        return false;
      };


      oInstance.replyCommentClose = function( )
      {
        if ( oInstance.bIsInitialized && !oInstance.isWorking() && oInstance.isReplying() )
        {
          if ( confirm('Desideri annullare l\'inserimento del nuovo commento?') )
          {
            oInstance.hCommentsReply.style.display = 'none';
            oInstance.hReplyYuiPanel.hide( );
            oInstance.hCaptchaImage.src = '/images/loading.gif';

            oInstance.setReplying( false );
            return true;
          }
        }

        return false;
      };


      oInstance.warnNoUserLink = function(  )
      {
        if ( oInstance.bIsInitialized &&!oInstance.isWorking() )
        {
          alert( 'Non è disponibile alcun sito personale o pagina di profilo per questo utente.' );
          return true;
        }

        return false;
      };


      oInstance.confirmUserLink = function( hHref )
      {
        if ( oInstance.bIsInitialized &&!oInstance.isWorking() && hHref )
          return confirm( 'Desideri visitare il sito internet "' + hHref.href + '"?' );

        return false;
      };


      oInstance.refreshCaptcha = function( bForce )
      {
        if ( oInstance.bIsInitialized && !oInstance.isWorking() && (bForce ? true : oInstance.isReplying()) )
        {
          if ( bForce || confirm('Sei sicuro di voler aggiornare il codice di controllo?') )
          {
            oInstance.hCaptcha.value = '';
            oInstance.hCaptchaImage.src = oInstance.captchaUrl + (oInstance.captchaUrl.indexOf('?') >= 0 ? '&' : '?') + 'rand_' + Math.round(Math.random()*999999999) + '=' + Math.round(Math.random()*999999999);

            return true;
          }
        }

        return false;
      };


      oInstance.checkUserAvatar = function( hImage, bLoaded )
      {
        if ( oInstance.bIsInitialized && hImage && !hImage.userAvatarChecked )
        {
          hImage.userAvatarChecked = true;

          if ( bLoaded ? (hImage.width <= 16 || hImage.height <= 16) : true )
            hImage.src = '/images/avatars/0.gif';

          return true;
        }

        return false;
      };


      oInstance.buildPager = function( )
      {
        if ( oInstance.bIsInitialized && !oInstance.isWorking() && !oInstance.isReplying() )
        {
          if ( oInstance.oOptions != null && oInstance.oUser != null && oInstance.oPager != null )
          {
            if ( oInstance.oPager['pager'] && oInstance.oPager['paged'] )
            {
              oInstance.hPager.style.display = 'none';

              while ( oInstance.hPagerInfo.firstChild ) oInstance.hPagerInfo.removeChild( oInstance.hPagerInfo.firstChild );
              oInstance.hPagerInfo.appendChild( document.createTextNode('Pagina ' + oInstance.oPager['current'] + ' di ' + oInstance.oPager['all'] + ':') );

              while ( oInstance.hPagerList.firstChild ) oInstance.hPagerList.removeChild( oInstance.hPagerList.firstChild );


              if ( oInstance.oPager['current'] > 1 )
              {
                var hFirstPageLink = document.createElement( 'a' );
                  hFirstPageLink.href = oInstance.getPageLink( 1 );
                  hFirstPageLink.title = 'Vai alla prima pagina';
                  hFirstPageLink.appendChild( document.createTextNode('«') );
                  hFirstPageLink.onclick = function() { oInstance.list( 1, false ); return false; };
                oInstance.hPagerList.appendChild( hFirstPageLink );

                var hPrevPageLink = document.createElement( 'a' );
                  hPrevPageLink.href = oInstance.getPageLink( oInstance.oPager['current']-1 );
                  hPrevPageLink.title = 'Vai alla pagina precedente';
                  hPrevPageLink.appendChild( document.createTextNode('<') );
                  hPrevPageLink.onclick = function() { oInstance.list( oInstance.oPager['current']-1, false ); return false; };
                oInstance.hPagerList.appendChild( hPrevPageLink );
              }



              for ( var i = Math.max(1, oInstance.oPager['current']-5); i <= Math.min(oInstance.oPager['current']+5, oInstance.oPager['all']); i++ )
              {
                if ( oInstance.oPager['current'] != i )
                {
                  var hPageLink = document.createElement( 'a' );
                    hPageLink.href = oInstance.getPageLink( i );
                    hPageLink.title = 'Vai alla pagina ' + i;
                    hPageLink.appendChild( document.createTextNode(i) );
                    hPageLink.onclick = new Function( '', 'interactiveComments_' + oInstance.strInstance + '.list( ' +i+ ', false ); return false;' );
                  oInstance.hPagerList.appendChild( hPageLink );
                }

                else
                {
                  var hCurrentPage = document.createElement( 'b' );
                    hCurrentPage.title = 'Sei sulla pagina ' + i;
                    hCurrentPage.appendChild( document.createTextNode(i) );
                  oInstance.hPagerList.appendChild( hCurrentPage );
                }
              }



              if ( oInstance.oPager['current'] < oInstance.oPager['all'] )
              {
                var hNextPageLink = document.createElement( 'a' );
                  hNextPageLink.href = oInstance.getPageLink( oInstance.oPager['current']+1 );
                  hNextPageLink.title = 'Vai alla pagina successiva';
                  hNextPageLink.appendChild( document.createTextNode('>') );
                  hNextPageLink.onclick = function() { oInstance.list( oInstance.oPager['current']+1, false ); return false; };
                oInstance.hPagerList.appendChild( hNextPageLink );

                var hLastPageLink = document.createElement( 'a' );
                  hLastPageLink.href = oInstance.getPageLink( oInstance.oPager['all'] );
                  hLastPageLink.title = 'Vai all\'ultima pagina';
                  hLastPageLink.appendChild( document.createTextNode('»') );
                  hLastPageLink.onclick = function() { oInstance.list( oInstance.oPager['all'], false ); return false; };
                oInstance.hPagerList.appendChild( hLastPageLink );
              }


              oInstance.hPager.style.display = '';
              return true;
            }

            else
              oInstance.hPager.style.display = 'none';
          }
        }

        return false;
      };
    };
  }