/* $Id: discussions.main.js,v 1.403 2011/09/13 10:27:37 rkarthick Exp $ */
function initTabContClick()
{
    $('#homeTab,#allforumsTab,#myareaTab,#SettingsTab,#NewTopicTab,#Search').click(function()
    {
        var $this = $(this);
        var hashPurpose = $this.attr('hashPurpose');
        processHash(hashPurpose,"",$this);
        return false;
    });
    $('#searchComboDownArrow').parent().click(function()
    {
        displaySearchOption();
    });
    $('#searchTab input').focus(function()
    {
        $('#searchTab').addClass('searchBoxFocus');
    }).focusout(function()
    {
        $('#searchTab').removeClass('searchBoxFocus');
    });

}//function initTabContClick()
//method to show the count of posts awaiting approval in moderation tab
function updateAwaitingApprovalCount()
{
    var awaitingApproval = {};
    awaitingApproval.forumGroupId = forumGroupId;
    doAjaxAction('/getAwaitingApprovalCount.do',awaitingApproval,function(data)//No internationalization
    {
        var countHTML = (data != "0")?" ("+data+")":"";//No I18N
        $('#awaitingCountCont').html(countHTML).attr('totalCount',data);//No I18N
    });
}
function processHash(hash,isWithHash,$target)
{
    if(isTopicQuickView == "false" && isWithHash != "withHash")
    {
        if(hash.toLowerCase() == "home")
        {
            hash = "recent"; //No I18N
        }
        else if(hash.toLowerCase() == "search" || hash.toLowerCase() == "normalsearch")
        {
            var searchingPurpose = $('#searchSelectedImage').attr('purpose');
            var $searchTab = $('#searchInputBox');
            var hashPurposeForSearch = "";
            var searchFor = $searchTab.val();
            var $forumComboCont = $('#forumComboCont');
            var $categoryComboCont = $('#categoryComboCont');
            var forForumNiceUrl = $forumComboCont.attr('forNiceUrl');
            var forCategoryNiceUrl = $categoryComboCont.attr('forNiceUrl');
            if(typeof forCategoryNiceUrl != "undefined" && forCategoryNiceUrl !="")
            {
                hashPurposeForSearch = forCategoryNiceUrl;
            }
            else
            {
                 hashPurposeForSearch = forForumNiceUrl;
            }
            if(typeof hashPurposeForSearch == "undefined" ||  hashPurposeForSearch == "")
            {
               hashPurposeForSearch = "";
            }
            if(hash.toLowerCase() == "normalsearch")
            {
                searchFor = $('#normalSearchInputBox').val();
            }
            searchFor =$.trim(searchFor);
            searchFor = encodeURIComponent(searchFor);
            searchFor = searchFor.replace(/\*/g,'%2A').replace(/\~/g,'%7E').replace(/\!/g,'%21').replace(/\'/g,'%27').replace(/\(/g,'%28').replace(/\)/g,'%29');
            if(searchFor == "")
            {
                showMessage(i18n["zohodiscussions.searchList.noSearchString"],'failure');
                return;
            }
            var searchType = "";
            if(typeof searchingPurpose == "undefined")
            {
                searchType = "";
            }
            else if(searchingPurpose != "all")
            {
                searchType = searchingPurpose+"/";
            }
            /*
            var $selectedTab = $('#tabListCont').find('li.selected')
            var tabPurpose  = $selectedTab.attr('tabPurpose');
            if(tabPurpose != "" && $.trim(tabPurpose) != "" && typeof tabPurpose != "undefined")
            {
                if(tabPurpose == "ResourceTab")
                {
                    location.href = serverURL+'/resources/search/'+searchType+searchFor;
                }
                return false;
            }
            */
            location.href = serverURL+hashPurposeForSearch+'/search/'+searchType+searchFor;
            return false;
        }
        else if(typeof $target != "undefined" && $target.attr('id') == "NewTopicTab")
        {
            if(hash == '')
            {
                return false;
            }
            var hashList = hash.split("/");
            var givenKey = hashList[0];
            var hashKey = givenKey.toLowerCase();
            var forumId = hashList[1];
            var categoryId = hashList[2];
            discussionsFunctions["newtopic"](hashKey,forumId,categoryId);
            return false;
        }
        location.href = serverURL+'/'+hash.toLowerCase();
        return false;
    }
    if(shouldReload == true && hash != "Search")
    {
        window.location.href = serverURL+'#'+hash;
        return false;
    }
    showLoadingImage();
    if(hash == '')
    {
        if(isTopicQuickView == "false")
        {
            window.location.href = serverURL+'/recent';
            return false;
        }
        discussionsFunctions['home']("home",1);//No I18N
        return false;
    }
    var hashList = hash.split("/");
    var givenKey = hashList[0];
    var hashKey = givenKey.toLowerCase();
    selectTab(hashKey);
    switch(hashKey)
    {
        case 'home':
        case 'chome':
            var fetchPage = 1
            if(parseInt(hashList[1]) > 1)
            {
                fetchPage = hashList[1];
            }
            discussionsFunctions[hashKey](givenKey,fetchPage);
            break;
        case 'alltags':
            discussionsFunctions[hashKey](givenKey);
            break;
        case 'allforums':
            discussionsFunctions[hashKey](givenKey);
            break;
        case 'stats': //No I18N
            window.location.href = serverURL+'/stats'; //No I18N
            break;
        case 'search':
            searchFor = hashList[1];
            discussionsFunctions[hashKey](givenKey,searchFor);
            break;
        case 'normalsearch':   //No I18N
            searchFor = $('#normalSearchInputBox').val();
            discussionsFunctions['search'](givenKey,searchFor);
            break;
        case 'myarea':
            var myAreaKey = hashList[1];
            var subAction = "";
            if(myAreaKey)
            {
                myAreaKey = myAreaKey.toLowerCase();
            }
            if(myAreaKey == "watchlist")
            {
                subAction = hashList[2];
                if(subAction)
                {
                    subAction = subAction.toLowerCase();
                }
            }
            else if(myAreaKey == "friends")
            {
                subAction = hashList[2];
                if(subAction)
                {
                    subAction = subAction.toLowerCase();
                }
            }
            discussionsFunctions[hashKey](givenKey,myAreaKey,subAction);
            break;
        case 'moderation':
            window.location.href = serverURL+'/moderation'; //No I18N
            break;
        case 'settings':
            discussionsFunctions[hashKey](givenKey);
            break;
        case 'topic':
            var forumTopicId = hashList[1];
            var recentResponseId = hashList[2];
            discussionsFunctions[hashKey](givenKey,forumTopicId,recentResponseId);
            break;
        case 'forum':
            var forumURL = hashList[1];
            var fetchPage = 1;
            if(hashList[2])
            {
                var categoryURL = "";
                var count = parseInt(2);
                if(hashList[count] != "filter" && hashList[count].toLowerCase() != "all")
                {
                    var temp = parseInt(hashList[count]);
                    if(temp > 0)
                    {
                        fetchPage = temp;
                        count = count+1;
                    }
                    else
                    {
                        categoryURL = hashList[count];
                        count = count+1;
                    }
                }
                if(hashList[count])
                {
                    if(hashList[count] == "filter")
                    {
                        count = count+1;
                        var filterType = hashList[count];
                        var filterStatus = "";
                        filterType = filterType.toLowerCase();
                        if(filterType == "twitter")
                        {
                            var forumId = $('#searchTwitterTab').attr('forumId');
                            getTwitterSearchList(forumId,1);
                            return;
                        }
                        else if(filterType != "discussions" && filterType != "questions" && filterType != "ideas" && filterType != "problems" && filterType != "announcement" && filterType != "sticky" && filterType != "unrepliedposts" && filterType != "postssincelastvisit")
                        {
                            filterType = "all"; //No I18N
                            if(isOneTopicType != "true")
                            {
                                count = count+1;
                            }
                        }
                        else
                        {
                            count = count+1;
                            if(hashList[count])
                            {
                                filterStatus = hashList[count];
                            }
                        }
                        if(isOneTopicType == "true" && filterType == "all")
                        {
                            filterStatus = hashList[count];
                        }
                        if(hashList[count])
                        {
                            if(parseInt(hashList[count]) > 0)
                            {
                                fetchPage = hashList[count];
                            }
                        }
                        getMoreTopics(forumURL,categoryURL,fetchPage,filterType,'',filterStatus,"reload"); //No I18N
                    }
                    else
                    {
                        if(hashList[count])
                        {
                            if(parseInt(hashList[count]) > 0)
                            {
                                fetchPage = hashList[count];
                            }
                        }
                        discussionsFunctions[hashKey](givenKey,forumURL,categoryURL,fetchPage);
                    }
                }
                else
                {
                    discussionsFunctions[hashKey](givenKey,forumURL,categoryURL,fetchPage);
                }
            }
            else
            {
                discussionsFunctions[hashKey](givenKey,forumURL,"",fetchPage);
            }
            break;
        case 'filter':
            var filterType = hashList[1];
            filterType = filterType.toLowerCase();
            var filterStatus = "";
            var fetchPage = 1;
            if(filterType == "twitter")
            {
                getTwitterSearchList(-1,1);
                return;
            }
            if(filterType != "discussions" && filterType != "questions" && filterType != "ideas" && filterType != "problems" && filterType != "announcement" && filterType != "sticky" && filterType != "unrepliedposts" && filterType != "postssincelastvisit")
            {
                filterType = "all"; //No I18N
                if(parseInt(hashList[2]) > 0)
                {
                    fetchPage = hashList[2];
                }
            }
            else
            {
                if(hashList[3])
                {
                    filterStatus = hashList[2];
                    if(parseInt(hashList[3]) > 0)
                    {
                        fetchPage = hashList[3];
                    }
                }
                else if(parseInt(hashList[2]) > 0)
                {
                    fetchPage = hashList[2];
                }
                else
                {
                    filterStatus = hashList[2];
                }
            }
            if(isOneTopicType == "true" && filterType == "all")
            {
                filterStatus = hashList[1];
            }
            getMoreTopics("","",fetchPage,filterType,"",filterStatus,"reload"); //No I18N
            break;
        case 'user':
            var authorName = hashList[1];
            discussionsFunctions[hashKey](givenKey,authorName);
            break;
       case 'tag':
            var tagName = hashList[1];
            discussionsFunctions[hashKey](givenKey,tagName);
            break;
       case 'newtopic':
            var forumId = hashList[1];
            var categoryId = hashList[2];
            discussionsFunctions[hashKey](givenKey,forumId,categoryId);
            break;
       case 'newdiscussion' || 'newquestion' || 'newidea' || 'newproblem':
            var forumId = hashList[1];
            var categoryId = hashList[2];
            discussionsFunctions["newtopic"](givenKey,forumId,categoryId);
            break;
        case 'tpw' : //No I18N
            var forumId = hashList[1];
            var categoryId = hashList[2];
            var limit = hashList[3];
            var style = hashList[4];
            var ph = hashList[5];
            var tps = hashList[6];
            var widget = hashList[7];
            var aj = hashList[8];
            var stat = hashList[9];
            var qstr = hashList[10];
            var tgt = hashList[11];
            discussionsFunctions["tphome"](givenKey,forumId,categoryId,limit,style,ph,tps,widget,aj,stat,qstr,tgt);//No I18N
            break;
       default:
            hideLoadingImage();
    }//switch(tabPurpose)
    return false;
}//function processHash(hash)

var discussionsFunctions = {};

//to load topic list
discussionsFunctions['tphome'] = function(givenKey,forumId,categoryId,limit,style,ph,tps,widget,aj,stat,qstr,tgt) //No I18N
{
    var fetchPage =1;
    getForumTopics(forumId,categoryId,fetchPage,givenKey,limit,style,ph,tps,widget,aj,stat,qstr,tgt);
};
discussionsFunctions['home'] = function(givenKey,fetchPage)
{
    var forumId = -1;
    var categoryId = -1;
    var fetchPage = fetchPage;
    if(typeof givenKey == "undefined")
    {
        givenKey = "home"; //No I18N
        fetchPage = 1;
    }
    getForumTopics(forumId,categoryId,fetchPage,givenKey);
};
discussionsFunctions['chome'] = function(givenKey,fetchPage)
{
    var forumId = -1;
    var categoryId = -1;
    var fetchPage =fetchPage;
    if(typeof givenKey == "undefined")
    {
        givenKey = "chome"; //No I18N
        fetchPage = 1;
    }
    getForumTopics(forumId,categoryId,fetchPage,givenKey);
};

discussionsFunctions['stats'] = function(givenKey)
{
    var forumId = -1;
    var categoryId = -1;
    var fetchPage =1;
    getTopicsReport(forumId,categoryId,fetchPage,givenKey);
};
//to load single forum topic list/ with widgets container
//params : forumURL, categoryURL
discussionsFunctions['forum'] = function(givenKey,forumURL,categoryURL,fetchPage)
{
    document.title = forumGroupName;
    var $topicListMainContainer = $('#topicListMainContainer');
        var options = {};
        options.forumGroupId = forumGroupId;
        options.forumURL = forumURL;
        options.fetchPage = fetchPage;
        if(categoryURL)
        {
            options.categoryURL = categoryURL;
        }
        doAjaxAction(
            '/getSingleForumTopics.do',
            options,
            function (data)
            {
                hideLoadingImage();
                $('#mainContent').get(0).innerHTML = data;
                lightBox('#chartWidget');
                if(categoryURL)
                {
                    if(parseInt(fetchPage) > 1)
                    {
                        $.history.add(givenKey+'/'+forumURL+'/'+categoryURL+'/'+fetchPage);
                    }
                    else
                    {
                        $.history.add(givenKey+'/'+forumURL+'/'+categoryURL);
                    }
                }
                else
                {
                    if(parseInt(fetchPage) > 1)
                    {
                        $.history.add(givenKey+'/'+forumURL+'/'+fetchPage);
                    }
                    else
                    {
                        $.history.add(givenKey+'/'+forumURL);
                    }
                }
                goToTop();
                lightBox('#topicList');//No I18N
                bindTopicClicks($('#topicList'));
                bindTopicClicks($('#topicsList'));
                bindTopicListHeaderClicks($('#topicListHeader'));
                bindWidgetsContClick($('#topicListWidgetsCont'));
                var $topicListFilter = $('#forumComboCont');
                var forumId = $topicListFilter.attr('forumId');
                var categoryId = $topicListFilter.attr('categoryId');
                var hashPurpose = "NewTopic/"+forumId+"/"+categoryId;
                if($('#allForumWidget').length > 0)
                {
                   if($('#allForumWidget').find('li[purpose="forumList"]').length < 9)
                   {
                       $('#moreForumView').hide();
                   }
                }
                $('#NewTopicTab').attr('hashPurpose',hashPurpose);
                if(typeof WmsContacts != "undefined" && ch == "true")
                {
                    var dataOb = WmsContacts.getZohoContacts();
                    setPresence(dataOb,"moderatorsChatList_"+forumId);
                    setPresenceInTopicList(dataOb);
                }
                if(isMac == "false")
                {
                    setToHotkeys();
                }
                return false;
            },
            function (errordata)
            {
                $('#mainContent').get(0).innerHTML = errordata.responseText;
                hideLoadingImage();
            }
        );
};
//to load new topic page
discussionsFunctions['newtopic'] = function(givenKey,forumId,categoryId)
{
    var zuid = ZUID;
    if(zuid == -1 && canThisUserPostATopic == "false" && isCustomSSOPortal == "false")
    {
        initLoginFrame($('#NewTopicTab'));
    }
    else if((zuid != -1 || canThisUserPostATopic == "true") && isTopicQuickView == "false")
    {
        var topicUrl = $('#NewTopicTab').attr('topicURL');
        window.location.href=serverURL+"/"+topicUrl;
    }
    else if(zuid != -1 && typeof canThisUserPostATopic == "undefined")
    {
        window.location.href = serverURL;
    }
    else if(typeof forumId == "undefined" && typeof categoryId == "undefined")
    {
        getWritePost("-1","-1",givenKey);
    }
    else
    {
        forumId = (typeof forumId == "undefined")?-1:forumId;
        categoryId = (typeof categoryId == "undefined")?-1:categoryId;
        getWritePost(forumId,categoryId,givenKey);
    }
};
//to load new topic page
discussionsFunctions['search'] = function(givenKey,searchFor)
{

    var options = {};
    options.forumGroupId = forumGroupId;
    if(!searchFor)
    {
        searchFor = $('#searchInputBox').val();
        searchFor =$.trim(searchFor);
    }
    if(searchFor == "")
    {
        showMessage(i18n["zohodiscussions.searchList.noSearchString"],'failure');
        hideLoadingImage();
        return;
    }
    var $forumComboCont = $('#forumComboCont');
    var $categoryComboCont = $('#categoryComboCont');
    var forumId = $forumComboCont.attr('forumId');
    var categoryId = $forumComboCont.attr('categoryId');

    var hashPurposeForSearch = $categoryComboCont.attr('hashPurpose');
    options.searchFor = searchFor;
    options.forumId = forumId;
    options.categoryId = categoryId;
    var searchingPurpose = $('#searchSelectedImage').attr('purpose');
    options.normalSearchType = searchingPurpose;
    if(typeof searchingPurpose == "undefined")
    {
        searchingPurpose = "";
    }
    else if(searchingPurpose != "all")
    {
        searchingPurpose = "/"+searchingPurpose;
    }
    else
    {
        searchingPurpose = "";
    }
    if(typeof hashPurposeForSearch != "undefined" && hashPurposeForSearch != "")
    {
        givenKey = hashPurposeForSearch + "/" +givenKey;
    }
    else
    {
        hashPurposeForSearch = $forumComboCont.attr('hashPurpose');
        if(hashPurposeForSearch == "Home")
        {
            hashPurposeForSearch = ""
        }
        if(typeof hashPurposeForSearch != "undefined" && hashPurposeForSearch != "")
        {
            givenKey = hashPurposeForSearch + "/" +givenKey;
        }
    }
    /*
    var $selectedTab = $('#tabListCont').find('li.selected')
    var tabPurpose  = $selectedTab.attr('tabPurpose');
    if(tabPurpose != "" && $.trim(tabPurpose) != "" && typeof tabPurpose != "undefined")
    {
        if(tabPurpose == "ResourceTab")
        {
            location.href = serverURL+'/resources/search'+searchingPurpose+"/"+searchFor;
        }
        return false;
    }
    */
    $.history.add(givenKey+searchingPurpose+"/"+searchFor);
    if($('#currSearchSortBy').attr('currSortBy') == "date")
    {
        options.searchSortBy = "date"; //No I18N
    }
    doAjaxAction('/getSearchResult.do',options,function(data)//No internationalization
    {
        hideLoadingImage();
        var $data = $('<div></div>');
        $data.get(0).innerHTML = data;
        $('#mainContent').get(0).innerHTML = data;
        bindSearchContentClick($('#mainContent'));
        showAuthorPopout($data);
        $('#searchInputBox').val(searchFor);
    },
    function (err)
    {
        hideLoadingImage();
        var responseData = eval(err.responseText);
        var reason =  responseData.reason;
        if(responseData.errorcode == "REMOTE_IP_LOCKED")
        {
            showMessage(i18n["zohodiscussions.generalmessage.tryagainaftersometime"],'failure'); // No I18N
        }
    });
};
//to load single post
discussionsFunctions['topic'] = function(givenKey,forumTopicId,recentResponseId)
{
    if(recentResponseId != undefined)
    {

        openSinglePost(forumTopicId,givenKey,recentResponseId);
    }
    else
    {
        openSinglePost(forumTopicId,givenKey);
    }
};

//to load tag related post
discussionsFunctions['tag'] = function(givenKey,tagName)
{
      $.history.add(givenKey+'/'+tagName);
      $this = $(this);
      var options = {};
      options.forumGroupId = forumGroupId;
      options.tagName = tagName;
      options.fetchPage = 1;
      doAjaxAction('/getTagRelatedPosts.do',options,function (data)//No internationalization
      {
            hideLoadingImage();
            $('#mainContent').get(0).innerHTML = data;
            goToTop();
            bindTopicClicks($('#topicList'));
            bindTopicClicks($('#topicsList'));
            bindTopicListHeaderClicks($('#topicListHeader'));
            bindWidgetsContClick($('#topicListWidgetsCont'));
            return false;
          },
          function(errordata)
          {
            hideLoadingImage();
            var responseData = (errordata.responseText);
            $('#mainContent').get(0).innerHTML = responseData;
      });
}
//to load all tags
discussionsFunctions['alltags']=function(allTags)
{
    $.history.add(allTags);
    $this = $(this);
    var options = {};
    options.forumGroupId =  forumGroupId;
    doAjaxAction('/showAllTags.do',options,function (data)//No internationalization
    {
          hideLoadingImage();
          $('#mainContent').get(0).innerHTML = data;
          bindTagsContClick($('#allTagsContainer'));
          bindWidgetsContClick($('#topicListWidgetsCont'));
          return false;
        },
        function(errordata)
        {
            hideLoadingImage();
            var responseData = (errordata.responseText);
            $('#mainContent').get(0).innerHTML = responseData;
   });
}
//to load myarea
discussionsFunctions['allforums'] = function(givenKey)
{
    if($('#preloadedForumsCont').length > 0)
    {
        $('#preloadedForumsCont').show().siblings().remove();
        $.history.add(givenKey);
        hideLoadingImage();
        return false;
    }
    var options = {};
    options.purpose = "AllForums"
    options.forumGroupId = forumGroupId;
    options[csrfParamName] = csrfToken;
    doAjaxAction('/AllForums.do',options,function(data)//No internationalization
    {
        hideLoadingImage();
        document.title = i18n["zohodiscussions.general.allForums"];//No internationalization
        $.history.add('AllForums');
        $('#mainContent').get(0).innerHTML = data;
        var $iframeLogin = $('#iamLoginBox').find('iframe');
        var currSRC = $iframeLogin.attr('src');
        $iframeLogin.attr('src',currSRC);
        allForumsBindActions();
        return false;
        },
        function(errordata)
        {
            hideLoadingImage();
            var responseData = (errordata.responseText);
            $('#mainContent').get(0).innerHTML = responseData;
        });
}
function allForumsBindActions()
{
    lightBox('#chartWidget');
    bindAllForumsClick($('#allForums_MainContentCont'));
    bindWidgetsContClick($('#topicListWidgetsCont'));
    goToTop();
    var $listof_FC_Counts = $('#listof_FC_Counts');
    $('#countOfForum').html($listof_FC_Counts.attr('forumCount'));
    $('#countOfCategory').html($listof_FC_Counts.attr('categoryCount'));
    $('#countOfPosts').html($listof_FC_Counts.attr('postCount'));
    $('#countOfResponses').html($listof_FC_Counts.attr('responseCount'));
    if(typeof WmsContacts != "undefined" && ch == "true")
    {
        var dataOb = WmsContacts.getZohoContacts();
        setPresenceInTopicList(dataOb);
    }
}
//to load myarea
discussionsFunctions['myarea'] = function(givenKey,myAreaAction,subAction)
{
    document.title = i18n["zohodiscussions.general.myarea"];//No I18N
    var $myAreaParentContainer = $('#myAreaParentContainer');
    if($myAreaParentContainer.length > 0 && $myAreaParentContainer.is('[shouldReload="false"]'))
    {
        $myAreaParentContainer.show().attr('shouldReload','true').siblings().remove();
        hideLoadingImage();
    }
    else
    {
        var options = {};
        options.forumGroupId = forumGroupId;
        options[csrfParamName] = csrfToken;
        if(!myAreaAction)
        {
            myAreaAction = "dashboard";
        }
        if(myAreaAction != "dashboard" && myAreaAction != "myposts" && myAreaAction != "watchlist" && myAreaAction != "friends" && myAreaAction != "bookmark" && myAreaAction != "privatemsg" && myAreaAction != "preference")
        {
            hideLoadingImage();
            return;
        }
        options.myAreaAction = myAreaAction
        options.ch = ch;
        doAjaxAction('/getMyArea.do',options,function(data)//No internationalization
        {
            $('#authorPopout:visible').hide();
            hideLoadingImage();
            $('#mainContent').get(0).innerHTML = data;
            getMyAreaBindActions(myAreaAction,givenKey,'',subAction);
            return false;
            },
            function(errordata)
            {
                hideLoadingImage();
                var responseData = (errordata.responseText);
                $('#mainContent').get(0).innerHTML = responseData;
           }
        );
    }//else
};
discussionsFunctions['user'] = function(givenKey,authorName)
{
    getAuthorProfile(authorName);
};
//to load moderation panel
discussionsFunctions['moderation'] = function(givenKey)
{
    document.title = i18n["zohodiscussions.moderationAction.moderation"];//No I18N
    var options = {};
    options.forumGroupId = forumGroupId;
    if(portalPlanIndex > 4)
    {
        options.postFor = 'AllWaitingApproval';//No internationalization
    }
    else
    {
        options[csrfParamName] = csrfToken;
        options.postFor = 'AllReportedSpam';//No internationalization
    }
    ModerationLoadingPage(options);
};
function ModerationLoadingPage(options)
{
    var toLoad = "";
    if(portalPlanIndex > 4)
    {
        toLoad = "/getModerationPanel.do"; //No internationalization
    }
    else
    {
        toLoad = "/getReportedSpam.do"; //No internationalization
    }
    doAjaxAction(toLoad,options,function(data)
    {
        hideLoadingImage();
        $('#mainContent').get(0).innerHTML = data;
        $.history.add('Moderation');
        getModerationPanelBindAction();
        return false;
        },
        function(errordata)
        {
            hideLoadingImage();
            var responseData = (errordata.responseText);
            $('#mainContent').get(0).innerHTML = responseData;
   });
}
function getModerationPanelBindAction()
{
    goToTop();
    bindModerationTabClick();
    if(portalPlanIndex > 4)
    {
        bindModerationActionClick("AllAwaiting");
    }
    else
    {
     bindModerationActionClick("AllReportedSpam");//No internationalization
    }
    ModerationAction($('#moderationRightCont'));
    initModerationPanel($('#moderationPanel'));
}
function getMyAreaBindActions(myAreaAction,givenKey,niceUrl,subAction)
{
    bindMyAreaClicks($('#myAreaContent'));
    $('#authorPopout_'+ZUID).hide();
    showAuthorPopout($('#myAreaInnerMainContent'));
    if(myAreaAction != "dashboard")
    {
        if(myAreaAction == "myposts")
        {
            myAreaAction = "myjournals"; //No I18N
        }
        if(subAction != undefined)
        {
            if(subAction != "topic" && subAction != "user" && subAction != "forum" && subAction != "subforum" && subAction != "following" && subAction != "follower")
            {
                subAction = "topic"; //No I18N
            }
        }
        if(niceUrl != "niceurl")
        {
            if($('#'+myAreaAction+'View').length > 0)
            {
                getMyAreaAction($('#'+myAreaAction+'View'),subAction);
            }
            else
            {
                getMyAreaAction($('#dashboardView'));
            }
        }
        else
        {
            var purpose = $('#'+myAreaAction+'View').attr('purpose');
            bindMyareaTabsActions(purpose,subAction);
        }
    }
    else
    {
        if(niceUrl != "niceurl")
        {
            $.history.add(givenKey+"/"+myAreaAction);
        }
        if(typeof WmsContacts != "undefined" && ch == "true")
        {
            var dataOb = WmsContacts.getZohoContacts();
            setPresence(dataOb,"followingUserDetails"); //No I18N
            setPresence(dataOb,"followersUserDetails"); //No I18N
            setPresenceInMyArea(dataOb,"current_recentActivity_List"); //No I18N
        }
        if(myAreaAction == "dashboard")
        {
            //activate user activity chart
            initialiseUserActivityChart();
        }
    }
}
function ModerationAction($context)
{
    $context.unbind('click',bindModerationAction).click(bindModerationAction);
    showAuthorPopout($context);
}

function getTopicsReport(forumId,categoryId,fetchPage,givenkey)
{
    document.title = forumGroupNameDecode(forumGroupName);
    var options = {};
    options.forumGroupId = forumGroupId;
    options.forumId = forumId;
    options.categoryId = categoryId;
    options.fetchPage = fetchPage;
    options[csrfParamName] = csrfToken;
    doAjaxAction('/Reports.do',options,function(data) //No internationalization
    {
        hideLoadingImage();
        if(givenkey)
        {
            $.history.add(givenkey);
        }
        $("#mainContent").get(0).innerHTML = data;
        lightBox('#chartWidget');
        bindReportsClicks($('#reportsLeftPanel'));
    });
 }//get Topics Report

function getForumTopics(forumId,categoryId,fetchPage,givenkey,limit,style,ph,tps,widget,aj,stat,qstr,tgt)
{
    document.title = forumGroupNameDecode(forumGroupName);
    var $topicListMainContainer = $('#topicListMainContainer');
    if($topicListMainContainer.length > 0 && $topicListMainContainer.is('[shouldReload="false"]') && fetchPage < 2)
    {
        $.history.add(givenkey);
        setTimeout(function(){$topicListMainContainer.show().attr('shouldReload','true').siblings().remove();},200);
        hideLoadingImage();
        if(isMac == "false")
        {
            setToHotkeys();
        }
    }
    else
    {
        var options = {};
        options.forumGroupId = forumGroupId;
        options.forumId = forumId;
        options.categoryId = categoryId;
        options.fetchPage = fetchPage;
        options.givenkey = givenkey;
        if(givenkey == "tpw")
        {
            options.limit = limit;
            options.style = style;
            options.ph = ph;
            options.tps = tps;
            options.widget = widget;
            options.aj = aj;
            options.stat = stat;
            options.querystring = qstr;
            options.tgt = tgt;
        }
        doAjaxAction('/getSingleForumTopics.do',options,function(data)//No internationalization
        {
            hideLoadingImage();
            if(givenkey)
            {
                if(parseInt(fetchPage) > 1)
                {
                    $.history.add(givenkey+"/"+fetchPage);
                }
                else
                {
                    $.history.add(givenkey);
                }
            }
            $('#mainContent').get(0).innerHTML = data;
            var $iframeLogin = $('#iamLoginBox').find('iframe');
            var currSRC = $iframeLogin.attr('src');
            $iframeLogin.attr('src',currSRC);
            lightBox('#chartWidget');
            lightBox('#topicList');//No I18N
            bindTopicClicks($('#topicList'));
            bindTopicClicks($('#topicsList'));
            bindTopicListHeaderClicks($('#topicListHeader'));
            bindWidgetsContClick($('#topicListWidgetsCont'));
            var hashPurpose = "NewTopic/"+forumId+"/"+categoryId;
            $('#NewTopicTab').attr('hashPurpose',hashPurpose);
            if($('#allForumWidget').length > 0)
            {
               if($('#allForumWidget').find('li[purpose="forumList"]').length < 9)
               {
                   $('#moreForumView').hide();
               }
            }
            if(typeof WmsContacts != "undefined" && ch == "true")
            {
                var dataOb = WmsContacts.getZohoContacts();
                setPresenceInTopicList(dataOb);
            }
            if(isMac == "false")
            {
                setToHotkeys();
            }
            return false;
            },
            function(errordata)
            {
                hideLoadingImage();
                var responseData = (errordata.responseText);
                $('#mainContent').get(0).innerHTML = responseData;
       });
    }
}
function getWritePostCallBack(givenKey,isNewWritePost)
{
        var topicType = givenKey;
        var titleArr = {};
        if(isNewWritePost != "true")
        {
            $.history.add(givenKey);
        }
        $('#tabListCont li.selected').removeClass('selected');
        goToTop();
        var $selectForumContainer = $('#SelectForum > option');
        if(($selectForumContainer.length) == 1)
        {
            $selectForumContainer.attr('selected',true);
        }
        var $selectCategoryContainer = $('#SelectCategory > option');
        if(($selectCategoryContainer.length) == 1)
        {
            $selectCategoryContainer.attr('selected',true);
        }
        initWritePost();
        givenKey = givenKey.toLowerCase();
        if(givenKey != "newtopic")
        {
            if(givenKey == "newproblem")
            {
                givenKey = "error";
            }
            else if(givenKey =="newquestion")
            {
                givenKey ="question";
            }
            else if(givenKey == "newidea")
            {
                givenKey = "idea";
            }
            else if(givenKey == "newdiscussion")
            {
                givenKey = "discuss"; //No I18N
            }
            var $this = $('#writepostTabsCont').find('li[topiciconclass="'+givenKey+'"]');
            if($this.length > 0)
            {
                 selectTopicType($this);
            }
            else
            {
                selectTopicType($this,givenKey);
            }

        }
        hideLoadingImage();
        var findLastTitle = "";
        $('#topicTitle').keydown(function(e)
        {
            var $listOfTitleAutoSugg = $('#listOfTitleAutoSugg');
            var currSearchName = $(this).val();
            currSearchName = currSearchName.replace(/^\s+|\s+$/g,'').replace(/\s+/g,' ');
            if(currSearchName == "" || e.keyCode == 27)
            {
                $listOfTitleAutoSugg.hide();
                return;
            }
     // To check current title was searched or not. If there to show the result.
            storedTitle = titleArr[currSearchName];
            if(storedTitle != undefined)
            {
                if(storedTitle == "")
                {
                    $listOfTitleAutoSugg.hide();
                    return;
                }
                $listOfTitleAutoSugg.html(storedTitle).show();
                return;
            }
// To check the keycode. Space bar only to search result
            if(e.keyCode != 32)
            {
                 return;
            }
            //$listOfTitleAutoSugg.html('');
// To avoid search request
            if(findLastTitle != ""  && currSearchName.indexOf(findLastTitle) == 0)
            {
                return;
            }
            else
            {
                findLastTitle = "";
            }
// To search the result
            var options = {};
            options.searchFor = currSearchName;
            options.forumGroupId = forumGroupId;
            options[csrfParamName] = csrfToken;
            doAjaxAction('/getTopicTitleSearch.do',options,function (data)//No internationalization
            {
                $listOfTitleAutoSugg.get(0).innerHTML = data;
                var $data = $('<div></div>');
                $data.get(0).innerHTML = data;
                if($data.find('li').length < 1)
                {
                    titleArr[currSearchName] = "";
                    findLastTitle = currSearchName;
                    $listOfTitleAutoSugg.hide();
                    return;
                }
                var currTitleWidth = $('#topicTitle').width();
                $listOfTitleAutoSugg.width(currTitleWidth-5);

                $listOfTitleAutoSugg.show();
                titleArr[currSearchName] = $listOfTitleAutoSugg.html();
            },
            function(errordata)
            {
                //alert('failure');
            });
        });
        var $context = $('#writepostCont');
        $context.unbind('click', manageTopicTitle).click(manageTopicTitle); //No I18N
}

function manageTopicTitle(event)
{
    var $target = $(event.target);
    var $targetParent = $target.parent();
    if($('#listOfTitleAutoSugg').is(":visible"))
    {
        if($target.parents('li').attr('eachTopic') == "autosugg")
        {
             if(!$target.is('a'))
                {
                        var topicUrl = $target.parents('li').find('a').attr('href'); //No I18N
                        window.open(topicUrl);
                }
             return;
        }
        if($target.is('#moreSearchTopicList'))
        {
            $('#listOfTitleAutoSugg').find('ul li').show();
            $target.hide();
        }
        else
        {
            $('#listOfTitleAutoSugg').hide();
            return;
        }
    }
    return;
}

function getWritePost(forumId,categoryId,givenKey,isNewWritePost)
{
    var options = {};
    options.forumGroupId = forumGroupId;
    options.forumId = forumId;
    options.categoryId = categoryId;
    if(isTopicQuickView != "false")
    {
        showLoadingImage();
    }
    doAjaxAction('/writePost.do',options,function (data)//No internationalization
        {
            document.title = i18n["zohodiscussions.writePost.documentTitle"]+" - "+forumGroupNameDecode(forumGroupName);//No I18N
            $('#mainContent').get(0).innerHTML = data;
            getWritePostCallBack(givenKey,isNewWritePost)
            return false;
        },
        function(errordata)
        {
             hideLoadingImage();
             var responseData = (errordata.responseText);
             $('#mainContent').get(0).innerHTML = responseData;
        });

}

//method to set the given tab as selected
function selectTab(tabId)
{
    if(tabId == "user")
    {
        $('#newtopicCont').siblings('li.selected').removeClass('selected');
        return;
    }
    else if(tabId == "newtopic" || tabId =="search")
    {
        searchFor = $('#searchInputBox').val();
        searchFor =$.trim(searchFor);
        if(tabId =="search" && searchFor == "")
        {
            return;
        }
        $('#'+tabId+"Tab").siblings('li.selected').removeClass('selected');
        return;
    }
    else if(tabId == "forum" || tabId == "topic" || tabId == "chome")
    {
        tabId = "home"; //No I18N
    }
    $('#'+tabId+"Tab").addClass('selected').siblings('li.selected').removeClass('selected');

}//function initTabContainerClicks()

/*** TOPIC LIST HEADER CLICKS ***/
function bindTopicListHeaderClicks($context)
{
    $context.unbind('click', processTopicListHeaderClick).click(processTopicListHeaderClick);
}
/**** TOPIC LIST CLICKS ****/
function bindTopicClicks($context) /* context is mandatory */
{
    $context.unbind('click', processTopicListClick).click(processTopicListClick);
    var $content = $context.find("script").html();
    try
    {
        eval($content);
    }
    catch(e)
    {}
}//function bindTopicClicks()

//method show the author popout
function showAuthorPopout($context)
{
    var isSinglePostAuthor = $context.attr('authorPopout');
    if((typeof isTopicQuickView == "undefined" || isTopicQuickView == "false") && (typeof isSinglePostAuthor == "undefined" || isSinglePostAuthor != "true"))
    {
       return false;
    }
    $context.find('a[purpose="authorProfile"],img[purpose="authorProfile"]').hover(
    function()
    {
        var $this = $(this);
        if((typeof isTopicQuickView == "undefined" || isTopicQuickView == "false") && $this.is('img[purpose="authorProfile"]') && isSinglePostAuthor == "true" && $this.attr('authorPopout') != "true")
        {
            return;
        }
        var authorId = $this.attr('authorId');
        if(authorId == -1)
        {
            return;
        }
        var authorName = $this.attr('authorName');
        var forumId = $this.attr('forumId');
        var handleAuthPopout = setTimeout(function()
        {
        var currPos = $this.position();
        var maincont = $('#mainContent').position();
        var maincontLeft = maincont.left;
        currPos.left = currPos.left + parseInt(maincontLeft);
        if($('#SinglePostContainer').length > 0)
        {
            var maincontTop = maincont.top;
            currPos.top = currPos.top + parseInt(maincontTop) + 20;
        }
        if(currPos.left > 800)
        {
            currPos.left = currPos.left - 300;
        }
        $authorPopup = $('#authorPopout_'+authorId);
        if($authorPopup.length > 0)
        {
            $authorPopup.css(currPos).show();
            authorPopupHover($authorPopup)
        }
        else
        {
            $authorPopup = $('#authorPopoutTemplate').clone();
            $authorPopup.attr('popoutPurpose','authorDetailsPopout');
            $authorPopup.attr('id','authorPopout_'+authorId);
            var options = {};
            options.forumGroupId = forumGroupId;
            options.authorId = authorId;
            options.forumId = forumId;
            options.ch = ch;
            doAjaxAction('/getAuthorPopup.do',options,function (data)//No internationalization
            {
                $thisAuthPopup = $("<div>"+data+"</div>");
                authorPopUpAction($thisAuthPopup,authorId,authorName,$authorPopup);

            });
            $authorPopup.css(currPos).show();
            $authorPopup.appendTo('body');  //No internationalization
            authorPopupHover($authorPopup)
        }
    },700);
        $this.data('destroyHandleAuthPopout', handleAuthPopout);
    },
    function()
    {
        var $this = $(this);
        var authorId = $this.attr('authorId');
        var handleAuthPopout = $this.data('destroyHandleAuthPopout');
        if(handleAuthPopout){clearTimeout(handleAuthPopout);}
        var $authCont = $('#authorPopout_'+authorId);
        $authCont.attr('hideAuhPopout','true');
        setTimeout(function()
        {
            var hideAuthPopout = $authCont.attr('hideAuhPopout');
            if(hideAuthPopout == "true")
            {
                $authCont.hide();
            }
        },500);
    }
  );
}//function showAuthorPopout($context)

function mouseOutAuthor($target)
{
    var $this = $target;
    var authorId = $this.attr('authorId');
    var handleAuthPopout = $this.data('destroyHandleAuthPopout');//No internationalization
    if(handleAuthPopout){clearTimeout(handleAuthPopout);}
    var $authCont = $('#authorPopout_'+authorId);
    $authCont.attr('hideAuhPopout','true');
    setTimeout(function()
    {
        var hideAuthPopout = $authCont.attr('hideAuhPopout');
        if(hideAuthPopout == "true")
        {
            $authCont.hide();
        }
    },500);
}


/** SEARCH CONTENT CLICK **/

function mouseOverAuthor($target)
{
    if(isTopicQuickView == "false")
    {
        return false;
    }
    var $this = $target;
    var $authorPopup;
    var authorId = $this.attr('authorId');

    if(authorId == -1)
    {
        return;
    }
    var authorName = $this.attr('authorName');
    var forumId = $this.parents('li[parentCont="actualParent"]').attr('forumId');//No I18N
    if(typeof forumId == "undefined")
    {
        forumId = $this.attr('forumId');
    }
    var handleAuthPopout = setTimeout(function()
    {
        var currPos = $this.position();
        $authorPopup = $('#authorPopout_'+authorId);
        if($authorPopup.length > 0)
        {
            $authorPopup.css(currPos).show();
            authorPopupHover($authorPopup);
        }
        else
        {
            $authorPopup = $('#authorPopoutTemplate').clone();
            $authorPopup.attr('popoutPurpose','authorDetailsPopout');
            $authorPopup.attr('id','authorPopout_'+authorId);
            var options = {};
            options.forumGroupId = forumGroupId;
            options.authorId = authorId;
            options.forumId = forumId;
            options.ch = ch;
            doAjaxAction('/getAuthorPopup.do',options,function (data)//No internationalization
            {
                $thisAuthPopup = $("<div>"+data+"</div>");
                authorPopUpAction($thisAuthPopup,authorId,authorName,$authorPopup);

            });
            $authorPopup.css(currPos).show();
            $authorPopup.appendTo('body');  //No internationalization
            authorPopupHover($authorPopup)
        }
    },700);
    $this.data('destroyHandleAuthPopout', handleAuthPopout);//No internationalization
}
function authorPopUpAction($thisAuthPopup,authorId,authorName,$authorPopup)
{
    $thisAuthPopup.find('li[purpose="watchUser"]').click(function()
    {
        $thisWatchCont = $(this);
        var watchOptions = {};
        watchOptions.forumGroupId = forumGroupId;
        watchOptions.itemId = authorId;
        watchOptions.itemType = 3;
        watchOptions[csrfParamName] = csrfToken;
        var watchAction = $thisWatchCont.attr('watchAction');
        var watchActionURL = (watchAction == "watch")?'/watchUser.do':'/unwatchUser.do';
        doAjaxAction(watchActionURL,watchOptions,function(data)
        {
            if(data == "SUCCESS")
            {
                $thisWatchCont.attr('watchAction',(watchAction == "watch")?'unwatch':'watch');
                var displayText = ((watchAction == "watch")?i18n["zohodiscussions.general.Unwatch"]:i18n["zohodiscussions.general.watch"])+" "+authorName;//No I18N
                $thisWatchCont.find('a[purpose="watchuserNameCont"]').html(displayText);
                if(watchAction == "watch")
                {
                    showTipper(i18n["zohodiscussions.generalmessage.userAddedToWatchlist"],'success');
                }
                else
                {
                    showTipper(i18n["zohodiscussions.generalmessage.userRemovedFromWatchlist"]);
                }
            }
        });
    });
    $thisAuthPopup.find('li[purpose="addAsFriend"]').click(function()
    {
        $addFriendCont = $(this);
        var successMsg = $addFriendCont.attr('successMsg');
        var options = {};
        options.forumGroupId = forumGroupId;
        options.userId = authorId;
        options[csrfParamName] = csrfToken;
        doAjaxAction(
            '/addAsFriend.do',//No I18N
            options,
            function (data)
            {
                hideLoadingImage();
                if(data == "SUCCESS")
                {
                    $addFriendCont.attr("purpose","friendWaitingApproval");
                    $addFriendCont.find('a[linkpurpose="addAsFriend"]').attr('style','cursor:default;text-decoration:none;').html(i18n['zohodiscussions.friends.awaitingApproval']);//No I18N
                    $addFriendCont.find('div.imgAddFriend').removeClass('imgAddFriend').addClass('imgWaitingFriend')
                    showTipper(successMsg,"success");
                }
            }
        );
    });
    $thisAuthPopup.find('li[purpose="authorProfile"]').click(function()
    {
        if(authorName == screenName || authorName == encodedScreenName)
        {
          processHash('MyArea');
        }
        else
        {
          processHash('User/'+authorName);
        }
    });
    $authorPopup.html('').append($thisAuthPopup);
    if(typeof WmsContacts != "undefined" && ch == "true")
    {
        var authStatus = WmsContacts.status(authorId);
        if(authStatus === false)
        {
                authStatus = 9;
        }
        manageUserChatStatus("authorPopup_"+authorId,authStatus);//No internationalization
    }
}
function authorPopupHover($authorPopup)
{
    $authorPopup.hover
    (
        function()
        {
            $authorPopup.attr('hideAuhPopout','false');
            var handle = $authorPopup.data('destroyHandle');//No internationalization
            if(handle){clearTimeout(handle);}
        },
        function ()
        {
            var handle = setTimeout(function()
            {
                $authorPopup.hide();
                $authorPopup.unbind('mouseenter').unbind('mouseleave');
            }, 700);
            $authorPopup.data('destroyHandle', handle);//No internationalization
        }
    );
}
function displaySearchOption()
{
    var $listOfSearchOptions = $('#listOfSearchOptions');
    $listOfSearchOptions.show();
    $listOfSearchOptions.find('li').unbind('click').click(function()
    {
        var $this = $(this);
        var $currselectImg = $this.find('div');
        var selectImg = $currselectImg.attr('class');
        var currpurpose = $currselectImg.attr('purpose');
        if(!$currselectImg.is('.imgAdvanceSearch'))
        {
            if($currselectImg.is('.imgSearchBlack'))
            {
                selectImg = "imgSearchWhite flLeft";
            }
            $('#searchSelectedImage').attr('class',selectImg).attr('purpose',currpurpose);
            $('#searchInputBox').focus();
        }
        else
        {
            if($('#advanceSearchContainerForm').is(':visible'))
            {
                $('#listOfSearchOptions').hide();
                return;
            }
            if($('#searchMainContainer').is(':visible'))
            {
                $('#normalSearchInSearchList').hide();
                $('#advanceSearchContainerForm').show();
                $('#advanceSearchInpurBox').focus();
                return;
            }
            showLoadingImage();
            var options ={};
            options.forumGroupId = forumGroupId;
            doAjaxAction('/AdvanceSearchContainer.do',options,function (data)//No internationalization
            {
                hideLoadingImage();
                var $firstMainContainer = $('#mainContent > div:first');
                var $data = $('<div></div>');
                $data.get(0).innerHTML = data;
                $data.insertBefore($firstMainContainer);
                $data.find('#advanceSearchContainerForm').show();
                $data.find('#advanceSearchInpurBox').focus();
                if($('#normalSearchInSearchList').is(':visible'))
                {
                    $('#normalSearchContainer').hide();
                }
                bindSearchContentClick($data);
            },
            function(errordata)
            {
                hideLoadingImage();
                var responseData = (errordata.responseText);
                $('#mainContent').get(0).innerHTML = responseData;
            });
        }
        $listOfSearchOptions.hide();
    });
    var $searchOptionParent = $listOfSearchOptions.parent('div');
    $searchOptionParent.hover
    (
        function()
        {
           var handle = $searchOptionParent.data('destroyHandle');
           if(handle){clearTimeout(handle);}
        },
        function ()
        {
            var handle = setTimeout(function()
            {
                $listOfSearchOptions.hide();
                $searchOptionParent.unbind('mouseenter').unbind('mouseleave');
            }, 500);
            $searchOptionParent.data('destroyHandle', handle);
        }
    );
}//function displaySearchOption()

function bindSearchContentClick($context)
{
    $context.unbind('click', processSearchContClick).click(processSearchContClick);
    $('#SearchforumCategoryVice').change(function()
    {
        searchForumCatSelect($(this));
    });
}

function searchForumCatSelect($target)
{
        var forumId = $target.val();
        var categoriesForForum = $('#searchCategoryList').val().split('$$');
        $.each(categoriesForForum, function(index, item)
        {
            if(item.indexOf(forumId+':') > -1)
            {
                $('#SearchCategoryVice').html('<option selected value="-1">' + i18n["zohodiscussions.myArea.all"] + '</option>'+item.split(':')[1]).show();
                $('#SelectCategory option:first').attr('selected','true');
                return false;
            }//if(item.indexOf(forumId+':') > -1)
            else
            {
               if(forumId == -1)
               {
                   $('#SearchCategoryVice').html('<option selected value="-1">' + i18n["zohodiscussions.myArea.all"] + '</option>').show();//No I18N
               }
               else
               {
                   $('#SearchCategoryVice').html('<option selected value="-1">Uncategorised</option>').show();
               }
            }
        });
        $('#SearchCategoryVice option:first').attr('selected','true');
}
/*** WIDGETS CONTAINR CLICK ***/
function bindWidgetsContClick($context)
{
    $context.unbind('click', processWidgetsContClick).click(processWidgetsContClick);
    showAuthorPopout($context);
    bindSubscribeAction();
    var $target = $('#followAnnouncement a[purpose="watchAnnouncement"]');
    $target.click(function(event){
       watchThisItem($target,"announcement",event);//No I18N
    });
}
function bindAllForumsClick($context)
{
    $context.unbind('click', processAllForumsClick).click(processAllForumsClick);
    showAuthorPopout($context);
}
function processTopicListHeaderClick(event)
{
    var $target = $(event.target);
    var $targetParent = $target.parent();
    if($target.is('#forumsFilter span, #categoriesFilter span, #forumsFilter li, #categoriesFilter li,#currentCategoryContext,#currentForumContext'))
    {
        if($target.is('#forumsFilter span,#categoriesFilter span'))
        {
            $target = $targetParent
        }
        //this is forum filter
        hashPurpose = $target.attr('hashPurpose');
        processHash(hashPurpose);
        return false;
    }//if($target.is('#forumsFilter li'))
    else if($target.is('div[purpose="linkForDropDown"]'))
    {
        var $switchPortalLink = $target;
        var portalsDropDownLocation = $switchPortalLink.attr('dropDownContLocation');
        var $parentCont = $($switchPortalLink.attr('parentCont'));
        if($parentCont.is('.newCombo'))
        {
            $parentCont.addClass('newComboSelected').removeClass('newCombo');
        }
        else
        {
            $parentCont.addClass('newCombo').removeClass('newComboSelected');
        }
        var $portalsDropDown = $('#'+portalsDropDownLocation);
        $portalsDropDown.toggle();
    }
    if($target.is('#topicListFilter li[purpose="filterLink"]'))
    {
        //this is topic filter
        var topicFilter = $target.attr('topicFilter');
        $topicFilterParent = $('#topicListFilter');
        var forumURL = $topicFilterParent.attr('forumURL');
        var categoryURL = $topicFilterParent.attr('subForumURL');
        var labelStatus = "";
        //getMoreTopics(forumId,categoryId,fetchPage,topicFilter,postSinceLastVisitTime);
        if($topicFilterParent.attr('isTypeURL') == "yes")
        {
            getMoreTopics(forumURL,categoryURL,fetchPage,topicFilter,'',labelStatus);
            $('#currentFilterContext').html($target.text());
        }
        else
        {
            manageFilterHash(forumURL,categoryURL,topicFilter,labelStatus);
        }
        return false;
    }//
    if($target.is('#showAllTags') && $target.attr('isNiceURL') != "Yes")
    {
       processHash("AllTags");
    }
    else if($target.attr('purpose')=="filterTab" || ($target.is('#innerTabFilter span') && $targetParent.parent().attr('purpose')=="filterTab") )
    {
        if(!($target.attr('purpose')=="filterTab"))
        {
            $target=$targetParent;
        }
        manageFilterTabList($target);
    }
    else if($target.is('#innerTabFilter li[purpose="filterTabMenu"]') || $targetParent.attr('purpose') == "filterTabMenu")
    {
        if($targetParent.attr('purpose') == "filterTabMenu")
        {
            $target = $targetParent;
        }
        manageFilterMenuList($target.attr('filterParent'),$target);
    }
    else if($targetParent.attr('id') == "searchTwitterTab")
    {
        manageFilterTabList($targetParent);
    }
    var $dropDownConts = $('#typeFilterOptions');
}//function processTopicListHeaderClick(event)

function getTwitterSearchList(forumId,fetchPage,sinceId)
{
    if(isTwitterPortal != "true")
    {
        return;
    }
    var $tweetContainer = $('#tweetContainer');
    var currStatusId = $tweetContainer.attr('status_Id');
    var options = {};
    options.forumGroupId = forumGroupId;
    options.forumId = forumId;
    options[csrfParamName] = csrfToken;
    options.fetchPage = fetchPage;
    var nextPage = parseInt(fetchPage)+1;
    if(typeof sinceId != "undefined")
    {
        options.sinceId = sinceId;
    }
    else if(fetchPage > 1)
    {
        options.maxId = currStatusId;
    }
    else
    {
        showLoadingImage();
    }
    doAjaxAction("/getTwitterSearchList.do",options,function (data)//No I18N
    {
        var $topicList = $('#topicList');
        if(fetchPage > 1)
        {
            $('#searchMoreTweetsLoading').remove();
            var $showMoreTweets = $('<div class="tFootCount" id="searchMoreTweets" forumId="'+forumId+'" fetchPage="'+nextPage+'" loadCompleted="false">Older Tweets</div>');
            $('#searchMoreTweetsParents').html($showMoreTweets);//No I18N
            var $data = $('<div></div>');
            $data.html(data);
            var $currTopicCont = $data.find('#tweetContainer li');
            $currTopicCont.each(function()
            {
                $(this).hide();
                $tweetContainer.append($(this));
            });
            $data.unbind('click', bindTwittReplyContent).click(bindTwittReplyContent);//No I18N
        }
        else
        {
            if(typeof sinceId != "undefined")
            {
                var preTotal = $tweetContainer.find('li[isrecenttweets = "true"]').length;
                if(preTotal > 1)
                {
                    preTotal = parseInt(preTotal) - 1;
                }
                var $data = $('<div></div>');
                $data.html(data);
                var $latestTweets = $data.find('li');
                $latestTweets.hide();
                var recentTweetCount = $latestTweets.length;
                if( recentTweetCount > 0)
                {
                    var recentStatusId = $data.find('#tweetContainer').attr('status_Id');
                    $tweetContainer.attr('status_Id',recentStatusId);
                    $('#searchRecentTweet').remove();
                    $latestTweets.insertBefore($tweetContainer.find('li:first'));
                    recentTweetCount = parseInt(recentTweetCount) + preTotal;
                    var $recent = $('<li isrecenttweets="true" id="searchRecentTweet"><div id="searchRecentTweetsLink" class="tCount">You have '+recentTweetCount+' new tweets</div></li>');
                    $recent.insertBefore($tweetContainer.find('li:first'));
                    $('#searchRecentTweetsLink').unbind('click').click(function()
                    {
                        $tweetContainer.find('li[isrecenttweets = "true"]').attr('isrecenttweets','false').show();
                        $(this).parents('li').remove();
                    });
                }
                manageRecentTweets();
            }
            else
            {
                var $topicListMainContainer = $('#topicListMainContainer');
                if($topicListMainContainer.length > 0 && $topicListMainContainer.is('[shouldReload="false"]'))
                {
                    $topicListMainContainer.show().attr('shouldReload','true');
                }
                $topicList.get(0).innerHTML = data;
                hideLoadingImage();
                if(forumId == -1)
                {
                    var currForumId = -1;
                    if($('#forum_Twitter_Default').length > 0)
                    {
                        currForumId = $('#forum_Twitter_Default').attr('forumId');
                    }
                    else
                    {
                            currForumId = $('#forum_Twitter_SelectForum').val();
                    }
                    loadTweetCategories(currForumId,"twitter_SubForumList","forum_Twitter_SelectSubForum");//No I18N
                }
            }
            $topicList.unbind('click', bindTwittReplyContent).click(bindTwittReplyContent);//No I18N
        }
        if(fetchPage == 1 && typeof sinceId == "undefined")
        {
            manageRecentTweets();
            $.history.add("filter/twitter");//No I18N
            getTwitterSearchList(forumId,2);
        }

    },
    function (err)
    {
        var responseData = eval(err.responseText);
        var reason =  responseData.reason;
        if(responseData.errorcode == "REMOTE_IP_LOCKED")
        {
            showMessage(i18n["zohodiscussions.generalmessage.tryagainaftersometime"],'failure'); // No I18N
}
    }
);
}
function initTwitterPageActions(forumId)
{
    var $topicList = $('#topicList');//No I18N
    $topicList.unbind('click', bindTwittReplyContent).click(bindTwittReplyContent);//No I18N
    bindTopicListHeaderClicks($('#topicListHeader'));
    bindWidgetsContClick($('#topicListWidgetsCont'));
    if(typeof forumId == "undefined" || forumId == "null")
    {
        forumId = -1;
    }
    getTwitterSearchList(forumId,2);
    manageRecentTweets();
}
function manageRecentTweets()
{
    var $tweetCont = $('#tweetContainer');

    if($tweetCont.is(':visible'))
    {
        setTimeout(function()
        {
            if($tweetCont.is(':visible'))
            {
                var forumId= $tweetCont.attr('forumId');
                var statusId = $tweetCont.attr('status_Id');
                getTwitterSearchList(forumId,1,statusId);
            }
        }, 60000);
    }

}
function bindTwittReplyContent(event)
{
    var $target = $(event.target);
    var $targetParent = $target.parent();
    if($targetParent.is('.ndTwitterBtnCont') && $targetParent.attr('purpose') == "replyTweet")
    {
        addNewTweetPost($target);
    }
    else if($target.is('#searchMoreTweets'))
    {
        manageMoreTweets($target);
    }
}
function manageMoreTweets($this)
{
    var forumId = $this.attr('forumId');
    var fetchPage = $this.attr('fetchPage');
    $this.parents('li').remove();//No I18N
    var $tweetContent = $('#tweetContainer');
    $tweetContent.find('li[isrecenttweets = "false"]').show();
    fetchPage = parseInt(fetchPage)+1;
    getTwitterSearchList(forumId,fetchPage);
}

function addNewTweetPost($target)
{
    var $tweetContainer = $('#tweetContainer');
    if($tweetContainer.data('inEditMode') == true)
    {
        var currStatusId = $tweetContainer.data('currStatusId');//No I18N
        $('#tweetReply_'+currStatusId).focus();
        showMessage(i18n["zohodiscussions.singlepost.alertmessageforediting"],'info');
        return;
    }
    var statusId = $target.attr('statusId');
    var $eachTwitter = $('#eachTwittId_'+statusId);
    var $eachTwitterCont = $('#twitterCont_'+statusId);
    var $eachTwitterAuthImg = $('#twitterImg_'+statusId);
    var options = {};
    options.forumGroupId = forumGroupId;
    options.statusId = statusId;
    options.tweetBy = $eachTwitter.attr('tweetBy');
    options.tweetDate = $eachTwitter.attr('tweetDate');
    options.tweetAuthImg = $eachTwitterAuthImg.attr('src');
    options.tweetCont = $eachTwitterCont.html();
    options[csrfParamName] = csrfToken;
    newOpenEditor($('#tweetReplyContainer_'+statusId),"responseContent","postContentTA","tweetReply_"+statusId,"TweetPost","tweetContainer");//No I18N
    $tweetContainer.data('inEditMode',true);//No I18N
    $tweetContainer.data('currStatusId',statusId);//No I18N
}//function addNewTweetPost($target)
function loadTweetCategories(forumId,subFormCont,subForumLocation)
{
    var categoriesForForum = $('#'+subFormCont).val().split('$$');
    var $selectCategory = $('#'+subForumLocation);
    $selectCategory.hide();
    $selectCategory.html('');//No I18N
    $.each(categoriesForForum, function(index, item)
    {
        if(item.indexOf(forumId+':') > -1)
        {
            $selectCategory.html(item.split(':')[1]).show();//No I18N
        return false;
        }//if(item.indexOf(forumId+':') > -1)
        else if(forumId != -1)
        {
            $selectCategory.html('<option selected value="-1">Uncategorised</option>').show();//No I18N
        }
        else
        {
            $selectCategory.html('<option selected value="-1">choose Subforum</option>').show();//No I18N
        }
    });
}//function loadTweetCategories(forumCont,subFormCont,subForumLocation)
function manageFilterTabList($target)
{
    var $innerTabFilter = $('#innerTabFilter');
    $innerTabFilter.find('li.selectedTab').removeClass('selectedTab');
    if($target.attr('purpose')=="filterTab")
    {
        $target.addClass('selectedTab');
    }
    else
    {
        $target.parents('li').addClass('selectedTab');
    }
    var forumURL= $innerTabFilter.attr('forumURL');
    var categoryURL = $innerTabFilter.attr('subForumURL');
    var fetchPage = 1;
    var topicFilter = $target.attr('filterBy') || $target.find('a').attr('filterBy');
    var labelStatus = '';
    var topicFilterType = $innerTabFilter.attr('topicFilterType');
    var postsincelastvisit = $innerTabFilter.attr('postSinceLastVisitTime');
    if(topicFilterType != 'All')
    {
        labelStatus = $target.attr('filterLabelId') || $target.find('a').attr('filterLabelId');
        if(labelStatus)
        {
            labelStatus = topicFilter;
            topicFilter = topicFilterType;
        }
    }
    if($innerTabFilter.attr('isTypeURL') == "yes")
    {
        getMoreTopics(forumURL,categoryURL,fetchPage,topicFilter,postsincelastvisit,labelStatus);
    }
    else
    {
        manageFilterHash(forumURL,categoryURL,topicFilter,labelStatus);
    }
}//function manageFilterTabList()
function manageFilterHash(forumURL,categoryURL,topicFilter,labelStatus)
{
    var filterURL = "forum/"; //No I18N
    if(isTopicQuickView == "false" || forumURL == "")
    {
        filterURL = "";
    }
    if(forumURL != "" && typeof forumURL != "undefined")
    {
        filterURL = filterURL + forumURL+"/" ;
    }
    if(categoryURL != "" && typeof categoryURL != "undefined")
    {
        filterURL = filterURL +categoryURL+"/" ;
    }
    if(labelStatus != "")
    {
        labelStatus = "/"+labelStatus;
    }
    var filterType =  "filter/"+topicFilter+labelStatus+"/1"; //No I18N
    if(typeof topicFilter != "undefined" && topicFilter.toLowerCase() == "all")
    {
        if("" != forumURL)
        {
            filterType = "1";
        }
        else if(isTopicQuickView == "false")
        {
            filterType = "recent"; //No I18N
        }
        else
        {
            filterType = ""; //No I18N
        }
    }
    processHash(filterURL + filterType); //No I18N
}
function manageFilterMenuList(context,$target)
{
    var $this = $('#'+context);
    if($('#innerTabFilter div.forumOptions').is(':visible'))
    {
        $(this).hide();
    }

    if($target.attr('purpose') == "filterTabMenu")
    {
        var $innerTabFilter = $('#innerTabFilter');
        var forumURL= $innerTabFilter.attr('forumURL');
        var categoryURL = $innerTabFilter.attr('subForumURL');
        var labelStatus = $target.attr('labelName');
        var topicFilter = $target.parent().attr('filterType');
        var fetchPage = 1;
        $innerTabFilter.find('li.selectedTab').removeClass('selectedTab');
        $('#'+topicFilter+'FilterMenuList').addClass('selectedTab');
        var filterBy = $target.attr('filterBy');
        if(filterBy)
        {
            topicFilter = filterBy;
        }
        if($innerTabFilter.attr('isTypeURL') == "yes")
        {
            getMoreTopics(forumURL,categoryURL,fetchPage,topicFilter,'',labelStatus);
        }
        else
        {
            manageFilterHash(forumURL,categoryURL,topicFilter,labelStatus);
        }
        //getMoreTopics(forumURL,categoryURL,fetchPage,topicFilter,'',labelStatus);
    }
}//function manageFilterMenuList()

//this is used for click event while listing tags
function bindTagsContClick ($tagContext)
{
    $tagContext.find('li[purpose ="getTagPosts"]').click(function()
    {
        $this = $(this);
        var hashPurpose = $this.attr('hashPurpose');
        processHash(hashPurpose);
    });
}
function processTopicListClick(event)
{
    var $target = $(event.target);
    var $targetParent = $target.parent();
    var $topicUtilContainer = $('#topicList');
    var $location = "topicList"; //No I18N
    var forumTopicId = $target.parents('li[parentCont="actualParent"]').attr('forumTopicId');//No I18N
    if($target.is('span[defaultTopicView="true"]') || $target.is('a[purpose="postTitleQuickView"]'))
    {
        forumTopicId = forumTopicId || $targetParent.parents('li[parentCont="actualParent"]').attr('forumTopicId');//No I18N
        if($target.is('span.nddownArrow'))
        {
            var $lastUpArrow = $topicUtilContainer.data('currentUpArrow');//No I18N
            if(typeof $lastUpArrow != "undefined")
            {
                $lastUpArrow.removeClass("ndupArrow").addClass("nddownArrow");//No I18N
        }
            $target.removeClass("nddownArrow").addClass("ndupArrow");//No I18N
            $topicUtilContainer.data('currentUpArrow',$target);//No I18N
        }
        else if($target.is('span.ndupArrow'))
        {
            $target.removeClass("ndupArrow").addClass("nddownArrow");//No I18N
        }
        //to expand the response in topic list view
        handleTopicClick(event,forumTopicId,$location);
    }
    else if($target.is('a[purpose="postTitle"]') || $target.is('a.orangeLink') || $target.is('span[defaultTopicView="false"]'))
    {

        //to open a single post in full thread view
        showLoadingImage();
        if(isTopicQuickView == "false")
        {
            //do nothing
        }
        else
        {
            var recentResponseId = $target.parents('li[parentCont="actualParent"]').attr('recentResponseId');//No I18N
            var isResponse = $target.attr("isResponse");
            if(recentResponseId != undefined && isResponse=="true")
            {
                processHash('Topic/'+forumTopicId+'/'+recentResponseId);
            }
            else
            {
                processHash('Topic/'+forumTopicId);
            }
            return false;
        }

    }
    else if($targetParent.is('li[purpose="moreAction"]'))
    {
        manageMoreAction($targetParent);
    }
    else if($target.is('a[purpose="moreAction"]'))
    {
        var parentLi = $target.parents('li');
        manageMoreAction(parentLi);
    }
     else if($target.is('a[purpose="linkedTopicTitle"]'))
    {
        //to open a single post in full thread view
        showLoadingImage();
        if(isTopicQuickView == "false")
        {
            //do nothing
        }
        else
        {
            var linkToTopicId = $target.attr('linkToTopicId');
            processHash('Topic/'+linkToTopicId);
            return false;
        }
    }
    else if($target.is('li[linkPurpose="replyToTopic"]') || $targetParent.is('li[linkPurpose="replyToTopic"]'))
    {
        forumTopicId = forumTopicId || $targetParent.parents('li[parentCont="actualParent"]').attr('forumTopicId');//No I18N
        //check whether a editor was already opened // if so set the focus to that location
        if($topicUtilContainer.data('inEditMode') == true)
        {
            showMessage(i18n["zohodiscussions.singlepost.alertmessageforediting"],'info');
            var openedEditorLcation = $topicUtilContainer.data('editorContLocation');
            var openedEditorTopicLocation = $topicUtilContainer.data('eachTopicContainerId');
            var openForumTopic = $topicUtilContainer.data('forumTopicId');
            if(openForumTopic != forumTopicId)
            {
                //to expand the response in topic list view
                handleTopicClick(event,openForumTopic,"editTopicList");
            }
            setFocusToContainer($(openedEditorLcation));
            return false;
        }
        $('#eachTopicReplyCont_'+forumTopicId).show();
        newOpenEditor($('#eachTopicReply_'+forumTopicId),"responseContent","postContentTA","replyToTopic_"+forumTopicId,"Write","paginationContainer");//No I18N
        setFocusToContainer($('#eachTopicReplyCont_'+forumTopicId));
        $topicUtilContainer.data('inEditMode',true);
        $topicUtilContainer.data('editorContLocation',"#eachTopicReplyCont_"+forumTopicId);
        $topicUtilContainer.data('eachTopicContainerId','#eachTopic_'+forumTopicId);
        $topicUtilContainer.data('forumTopicId',forumTopicId);
        return false;
    }
    else if(($target.is('#olderPostsLink') || $target.is('#newerPostsLink'))&& $target.is('.navBtnEnabled'))
    {
        var forumURL =  $target.attr('forumURL');
        var categoryURL = $target.attr('categoryURL');
        var fetchPage = $target.attr('fetchPage');
        var topicFilter = $target.attr('topicFilter');
        var getPostFor = $target.attr('getPostFor');
        var topicStatus = $target.attr('topicStatus');
        var postSinceLastVisitTime = $target.attr('postSinceLastVisitTime');
        if(typeof getPostFor == "undefined")
        {
            getMoreTopics(forumURL,categoryURL,fetchPage,topicFilter,postSinceLastVisitTime,topicStatus,"true");
        }
        else
        {
            var tagName = $target.attr('tag_Name');
            getMoreTagRelatedPost(fetchPage,tagName,getPostFor)
        }
    }
    else if($target.is('a[purpose="forumPostsFilter"]'))
    {
        hashPurpose = $target.attr('hashPurpose');
        processHash(hashPurpose);
        return false;
    }
    else if(($target.is('a[purpose="authorProfile"]')) || $target.is('img[purpose="authorProfile"]'))
    {
        var authorName = $target.attr('authorName');
        if(authorName == screenName || authorName == encodedScreenName)
        {
            processHash('MyArea');
        }
        else
        {
            processHash('User/'+authorName);
        }
        return;
    }
    else if($target.is('div.imgSmallWatchSel') || $target.is('div.imgSmallWatch'))
    {
       watchThisItem($target,"singleTopicWatch",event);
       return;
    }
    else if(($target.is('li.ndtopicNavPrev') || $target.is('li.ndtopicNavNext'))&& !$targetParent.is('.navLoading'))
    {
        checkPrevNextResponse($target);
        return;
    }
    else if(($target.is('li.ndtopicNavFirst') || $target.is('li.ndtopicNavLast')) && !$targetParent.is('.navLoading'))
    {
        firstOrLastResponse($target);
        return;
    }
    else if($targetParent.is('li[purpose="watchAction"]'))
    {
        $location = ($targetParent.is('li[purpose="watchAction"]'))?$location:"";//No I18N
        watchThisItem($targetParent,$location,event);
        return;
    }
    else if($target.is('input[purpose="watchAction"]'))
    {
        var forumTopicId = $target.attr('forumTopicId');
        var $isFollowTopicCont = $('#eachTopicReplyCont_'+forumTopicId).find('input[name="isFollowTopic"]');
        if($target.attr('checked') == true)
        {
            $isFollowTopicCont.attr('value','true');
        }
        else
        {
            $isFollowTopicCont.attr('value','false');
        }
        return;
    }
    else if($targetParent.is('li[purpose="emailThisTopic"]'))
    {
        openEmailTopicDialog($targetParent);
        var parentLi = $targetParent.parents('li[purpose="moreAction"]');
        manageMoreAction(parentLi);
        return;
    }
    else if($targetParent.is('li[purpose="moderateThisTopic"]'))
    {
        moderateAction($targetParent,$location,event);
        return;
    }
    else if($targetParent.is('li[actionPurpose="delete"]'))
    {
        singlePostDeleteAction($targetParent,$location);
        return;
    }
    else if($targetParent.is('#removeTopicLink') || $targetParent.is('li[purpose="removeTopicLink"]'))
    {
      deletelinkedTopic($targetParent);
    }
    else if($targetParent.is('li[actionPurpose="edit"]'))
    {
      var thisResponseId = $targetParent.attr('responseId');
      var editingForumTopic = $targetParent.parents('li[parentCont="actualParent"]').attr('forumTopicId');//No I18N
      var editResponseLocation = "#eachTopic_"+editingForumTopic;
      if($topicUtilContainer.data('inEditMode'))
      {
          showMessage(i18n["zohodiscussions.singlepost.alertmessageforediting"],'info');
          openedEditorLcation = $topicUtilContainer.data('editorContLocation');
          var openForumTopic = $topicUtilContainer.data('forumTopicId');
          if(editingForumTopic!=openForumTopic)
          {
            //to expand the response in topic list view
            handleTopicClick(event,openForumTopic,$location);
          }
          setFocusToContainer($(openedEditorLcation));
          return false;
      }
      newOpenEditor($('#recentResponseContent_'+thisResponseId),"responseContent","postContentTA",('editPostContent_'+thisResponseId),"Edit",('eachTopic_'+thisResponseId)); //No I18N
      setFocusToContainer($(editResponseLocation));
      $topicUtilContainer.data('inEditMode',true);
      $topicUtilContainer.data('editorContLocation',editResponseLocation);
      $topicUtilContainer.data('forumTopicId',editingForumTopic);
      $('#postTextContent_'+thisResponseId).find('ul.singlePostActions').hide();
      $('#linkedTopic_'+thisResponseId).hide();
      $('#singlePostActions_'+thisResponseId).hide();
      $('#recent_ResPonse_'+thisResponseId).find('div.listOfResponseLink').hide();
      $('#previewResponse').attr('location','topicListEditResponse');
      $('#previewResponse').attr('responseId',thisResponseId);
      $('#previewResponse').attr('forumTopicId',editingForumTopic);
      return false;
    }
    else if($target.is('li[deletepurpose="deleteAttachment"]'))
    {
        deletePublishedAttachment($target,event);
        return;
    }
    else if($targetParent.is('li[bestResponse]'))
    {
        var $this = $targetParent;
        var thisResponseId = $this.attr('responseId');
        var forumTopicId = $this.parents('li[parentCont="actualParent"]').attr('forumTopicId');//No I18N

        var topicAuthorId = $this.attr('topicAuthorId');
        var bestResponseAction = $this.attr('bestResponse');
        var options = {};
        options.forumGroupId = forumGroupId;
        if(bestResponseAction == "choose")
        {
            options.responseId = thisResponseId;
        }
        options.forumTopicId = forumTopicId;
        if(topicAuthorId == ZUID)
        {
            options.topicowner = "true";
        }
        options[csrfParamName] = csrfToken;
        var bestResponseURL = (bestResponseAction == "choose")?'/bestResponse.do':'/removeBestResponse.do';
        showSmallLoadingImage(event);
        doAjaxAction(bestResponseURL,options,function (data)
        {
            if(data == "SUCCESS")
            {
                var bestResponseMsg = (bestResponseAction == "choose")?i18n["zohodiscussions.singlepost.bestResponseSuccessMsg"]:i18n["zohodiscussions.singlePost.removeBestResponseMsg"];//No I18N
                var msgStyle = (bestResponseAction == "choose")?'success':'info';
                showTipper(bestResponseMsg,msgStyle);
                refreshSingleTopic(forumTopicId);
            }
            else
            {
                hideLoadingImage();
                showMessage(i18n["zohodiscussions.generalmessage.noPermission"]);
            }
        });
    }
    else if($target.is('input[followItem]'))
    {
        var followItem = $target.attr('followItem');
        var responseId = $target.attr('responseId');
        if(followItem == "true")
        {
            watchItem($target);
        }
        $('#followTopicList_'+responseId).hide();
    }
}//function processTopicListClick(event)

function manageMoreAction($target)
{
    if($target.is('.newComboSelectedNm'))
    {
        $target.removeClass('newComboSelectedNm').addClass('newCombo');
        $target.find('div.forumOptins').hide();
        return;
    }
    $target.removeClass('newCombo').addClass('newComboSelectedNm');
    var $moreOptions = $target.find('div.forumOptins');
    $moreOptions.show();

    $target.hover
    (
        function()
        {
            $target.attr('hideAuhPopout','false');
            var handle = $target.data('destroyHandle');
            if(handle){clearTimeout(handle);}
        },
        function ()
        {
            var handle = setTimeout(function()
            {
                $target.removeClass('newComboSelectedNm').addClass('newCombo');
                $moreOptions.hide();
                $target.unbind('mouseenter').unbind('mouseleave');
            }, 500);
            $target.data('destroyHandle', handle);
        }
    );

}//function manageMoreAction(parentLi)
function refreshResponseVoteContainer(responseId)
{

    var options = {};
    options.forumGroupId = forumGroupId;
    options.responseId = responseId;
    doAjaxAction('/refreshSingleResponse.do',options,function (data)//No internationalization
    {
        var $voteCont = $(data).find('div[contPurpose="voteContainer"]');
        $('#postTextContent_'+responseId+' div[contPurpose="voteContainer"]').html($voteCont.html());
        hideLoadingImage();
    });
}
function backtoEditor()
{
  $('#addForumPostForm').show();
  $('#writeNewTopic').show();
  $('#publishPreviewedTopic').hide();
  $('#backToEditor').hide();
  $('#preview_Posts').hide();
  $('#writePostButtons').show();
  $('#writepostCont').show();
    $('#forumTagsPreview').html(' ');
  //$.history.add("NewTopic/Editor");
}
function publishPreviewedTopic()
{
  $('#publishTopic').trigger('click');
}
function writePostPreview(userName,location,flag,isDraft)
{
    var topicTitle = $('#topicTitle').val();
    var finalTopicTitle = topicTitle.replace(/^<+|<+$/g,'&lt;').replace(/<+/g,'&lt;').replace(/^>+|>+$/g,'&gt;').replace(/>+/g,'&gt;');

    finalTopicTitle = finalTopicTitle.replace(/^\s+|\s+$/g,'').replace(/\s+/g,' ');
    if (finalTopicTitle == '' )
    {
        hideLoadingImage();
        setFocusToContainer(($('#topicTitle')).focus());
        enablePostButtons();
        showMessage(i18n["zohodiscussions.writePost.TopicTitleCannotbeEmptymessage"],'failure');
        return;
    }
    if(finalTopicTitle.length > 200)
    {
        hideLoadingImage();
        showMessage(i18n["zohodiscussions.writePost.TopicTitleLengthMsg"],'failure');
        enablePostButtons();
        return;
    }
    var contentToPost = editor.getContent();
    contentToPost = contentToPost.replace(/^\s+/g, '').replace(/\s+$/g, ''); //replace(/<[^>]*>/ig, '')

    var $tempCont = $('<div></div>').html(contentToPost);
    contentToPost = $tempCont.text();
    if (contentToPost == '' )
    {
        hideLoadingImage();
        showMessage(i18n["zohodiscussions.writePost.noContentInPost"],'failure');
        enablePostButtons();
        return;
    }

    var selectedForumOption = $('#SelectForum').val();
    var selectedCategoryOption = $('#SelectCategory').val();
    if(selectedForumOption == null)
    {
       hideLoadingImage();
       $('#selectForumMessage').show();
       setFocusToContainer($('#SelectForum'));
       enablePostButtons();
       showMessage(i18n["zohodiscussions.writePost.selectAnyForum"],'failure');
       return;
    }
    else if(selectedCategoryOption == '0')
    {
       hideLoadingImage();
       $('#selectForumMessage').show();
       setFocusToContainer($('#SelectCategory'));
       enablePostButtons();
       showMessage(i18n["zohodiscussions.writePost.selectAnyCategory"],'failure');//No I18N
       return;
    }
    else
    {
      $('#selectForumMessage').hide();
    }
    var writepostTags = $('#forumTags').val();
    if(writepostTags != "")
    {
      writepostTags = writepostTags.replace(/^\s+|\s+$/g,' ').replace(/\s+/g,' ');
      if(writepostTags.match(/^[^\^\"'()~`!@#$%&:;\/\\?|<>{}[\]*-+=]+$/) == null)
      {
         hideLoadingImage();
         showMessage(i18n["zohodiscussions.singlepost.specialCharacterNotAllowedMsg"],'failure');
         enablePostButtons();
         return;
      }
    }

    if(isDraft)
    {
        $('#previewAttachment >li').html('');
        var attachmentDetails = $('#attachmentsListCont').find('div[attachmentDetails]');
        var attachmentContLength = $('#attachmentsListCont').find('div[attachmentDetails]').length;
        if(attachmentContLength > 0)
        {
            var $appendingAttachmentCont = $('#previewAttachment'); //$editorLocation.find('div[purpose ="attachmentListContForPreview"] > ul');
            attachmentListPreview($appendingAttachmentCont,attachmentDetails);
            $('#AttachmentPreviewCont').show();
        }
        else
        {
             $('#AttachmentPreviewCont').hide();
        }

    }

    $('#addForumPostForm').hide();
    $('#writeNewTopic').hide();
    $('#publishPreviewedTopic').show();
    $('#backToEditor').show();
    $('#writepostCont').hide();

    //this function will sync the preview contents with the editor and fields - so that live preview can be given
    var $previewSection = $('#preview_Posts').show();
    $('#writePostButtons').hide();

    var topicClass = $('#TopicContentHolder').attr('imgAttrClass');
    var topicTypeClass = $('#previewTopicTypeImg').attr('class');
    var topicType = topicTypeClass.split(" ");
    $('#previewTopicTypeImg').removeClass(topicType[1]).addClass(topicClass);


    if($previewSection.is(':visible'))
    {
        var $previewCont = $('#preview_breadCrumb,#preview_postHeader')
        $previewCont.find('a[purpose="authorProfile"]').html(userName);
        //process only if the preview section is visible.
        $('#previewDocumentTitle').html(finalTopicTitle);
        //get forumName
        $previewCont.find('a[purpose="forum_Topic"]').html($('#SelectForum option:selected').text());
        var categoryCont = $('#SelectCategory option:selected').text();
        var categroyId = $('#SelectCategory option:selected').val();
        if(categroyId > 0)
        {
            $previewCont.find('span[purpose="cateArrow"]').show();
            $previewCont.find('a[purpose="category_Topic"]').html(categoryCont);
        }
        else
        {
            $previewCont.find('span[purpose="cateArrow"]').hide();
            $previewCont.find('a[purpose="category_Topic"]').html("");
        }
        writepostTags = writepostTags.replace(/^\s+|\s+$/g,' ').replace(/\s+/g,' ');
        if(writepostTags == "")
        {
          $('#forumTagsPreview').html(i18n["zohodiscussions.singlepost.noTagsMsg"]);//append('No tags')//('i18n["zohodiscussions.singlepost.noTagsMsg"]');
        }
        var tagList = writepostTags.split(",");

        //var flag = "false";
        for(var index = 0; index<tagList.length ;index++)
        {
          if(jQuery.trim(tagList[index]) != "")
          {
            $('#forumTagsPreview').append('<li><a>'+tagList[index]+'</a></li>');
          }
        }
        var contentToPost = editor.getContent();
        contentToPost = contentToPost.replace(/^\s+/g, '').replace(/\s+$/g, ''); //replace(/<[^>]*>/ig, '')
        if (contentToPost == '' )
        {
            hideLoadingImage();
            showMessage(i18n["zohodiscussions.writePost.noContentInPost"],'failure');
            return;
        }
         //get post content
        $previewSection.find('#responsePreviewContentContainer').html(contentToPost);
    }//if($previewSection.is(':visible'))

}
function forHidingSmallLoadingImg()
{
    var $browserCont = "";
    var cont ="";
    if($('#newPostRightCont').length > 0)
    {
        $browserCont = $('#newPostRightCont');
    }
    else if($('#attachBrowseCont').length > 0)
    {
        $browserCont = $('#attachBrowseCont');
    }
    $browserCont.find("[purpose='attachLoadingCont']").hide();
}

function processSearchContClick(event)
{
    var $target = $(event.target);
    var $targetParent = $target.parent();
    if($('#loadingImg').is(":visible"))
    {
        return;
    }
    if($targetParent.is('div[purpose="advanceSearch"]'))
    {
        $('#advanceSearchContainerForm').show();
        $('#normalSearchInSearchList').hide();
    }
    else if($target.is('button[purpose="advanceSearchCancel"]') || $target.is('div[purpose="advanceSearchCancel"]'))
    {
        if($('#advancedSearchForm').is(':visible'))
        {
            $('#advancedSearchForm').remove();
        }
        else
        {
            $('#advanceSearchContainerForm').hide();
            $('#normalSearchContainer').show();
            $('#normalSearchInSearchList').show()
        }
    }
    else if($target.is('button[purpose="normalSearch"]'))
    {
        var searchFor = $('#normalSearchInputBox').val();
        processHash("normalsearch"); //No I18N
    }
    else if($target.is('button[purpose="getAdvanceSearch"]'))
    {
        getAdvanceSearchResult();
    }
    else if($target.is('a[purpose="postTitle"]'))
    {
        var forumTopicId = $target.attr('forumTopicId');
        var searchFor = $target.attr('searchFor');
        openSinglePost(forumTopicId,"topic",searchFor);
        return;
    }
    else if($targetParent.is('a[purpose="postTitle"]'))
    {
        var forumTopicId = $targetParent.attr('forumTopicId');
        var searchFor = $targetParent.attr('searchFor');
        openSinglePost(forumTopicId,"topic",searchFor);
        return;
    }
    else if($target.is('a[purpose="forumAction"]') || $target.is('a[purpose="categoryAction"]') )
    {
        var hashPurpose = $target.attr("hashPurpose");
        processHash(hashPurpose);
    }
    else if($target.is('a[purpose="authorProfile"]') || $targetParent.is('a[purpose="authorProfile"]'))
    {
        var authorName = $target.attr('authorName');
        if(!authorName)
        {
            authorName = $targetParent.attr('authorName');
        }
        var singleClickflag = $target.attr('singleClickflag');
        if(!singleClickflag)
        {
            singleClickflag = $targetParent.attr('singleClickflag');
        }
        if(singleClickflag == "0")
        {
          if(authorName == screenName || authorName == encodedScreenName)
          {
              processHash('MyArea');
              $target.attr('singleClickflag','1');
          }
          else
          {
              processHash('User/'+authorName);
              $target.attr('singleClickflag','1');
          }
        }
        return;
    }
    else if($target.is('li.navBtnEnabled') && $target.is('[navType="searchNav"]'))
    {
        var navTab = $target.attr('purpose');
        searchNavigation($targetParent,navTab);
        return;
    }
    else if($target.is('a[purpose="relativeLinkSearch"]'))
    {
        //categoryId = $target.attr('categId');
        searchNavigation($target,"relativeLinkSearch")

    }
    else if($target.is('a[purpose="sortbyrelevance"]') && !$target.is('.boldText'))
    {
        searchNavigation($('#breadCrumbForSearch span:last a'),"breadCrumbForSearch","relevance"); //No I18N
    }
    else if($target.is('a[purpose="sortbydate"]') && !$target.is('.boldText'))
    {
        searchNavigation($('#breadCrumbForSearch span:last a'),"breadCrumbForSearch","date"); //No I18N
    }
    else if($target.is('a[purpose="breadCrumbForSearch"]'))
    {
        searchNavigation($target,"breadCrumbForSearch");
    }
    else if($target.is('a[purpose="expandForumList"]'))
    {
        var currStatus = $target.attr('status');
        if(currStatus == "off")
        {
            $target.attr('status','on').html("&laquo; less");
            $target.parents('ul').find('li').show();
        }
        else
        {
            $target.attr('status','off').html("more &raquo;");
            var count = 0;
            $target.parents('ul').children('li').each(function()
            {
                if(count > 4)
                {
                    $(this).hide();
                }
                count++;
            });
        }

    }
}
function searchNavigation($target,navTab,sortby)
{
    showLoadingImage();
    var currFetchPage = parseInt($target.attr('fetchPage'));
    var fieldType = $target.attr('fieldType');
    var categ_Id = $target.attr('categId');
    var path_Traverse = $target.attr('pathTraverse');
    var $breadCrumbForSearch = $('#breadCrumbForSearch');
    var forumId = $target.attr('forumId');
    var searchLevel = $target.attr('searchLevel');
    if(navTab == "next")
    {
        currFetchPage = currFetchPage+1;
    }
    else if(navTab == "prev")
    {
        currFetchPage = currFetchPage-1;
    }
    else
    {
        currFetchPage = 1;
    }
    if(forumId == "undefined")
    {
        forumId = -1;
    }
    if(searchLevel == "forums" || searchLevel == "all")
    {
        categ_Id = "";
        path_Traverse = "";
        var $forumList = $('#SearchforumCategoryVice');
        var $categoryList = $('#SearchCategoryVice');
        $categoryList.find('option[value="-1"]').attr('selected','true');
        if(searchLevel == "all")
        {
            $forumList.find('option[value="-1"]').attr('selected','true');
        }
    }
    var searchSortBy = sortby;
    if(searchSortBy != "relevance" && searchSortBy != "date")
    {
        searchSortBy = $('#currSearchSortBy').attr('currSortBy');
    }
    if($('#searchListContainer').is(':visible'))
    {
        doAjaxAction('/getMoreSearchResult.do?fetchPage='+currFetchPage+'&searchSortBy='+searchSortBy+'&category_id='+categ_Id+'&category_pathTraverse='+path_Traverse+'',$('#advanceSearchForm').serialize(),function(data)//No internationalization
        {
            hideLoadingImage();
            reloadeSearchContainer(data,navTab,fieldType,forumId,categ_Id,path_Traverse,searchSortBy);
        });

    }
    else
    {
        var options = {};
        options.fetchPage = currFetchPage;
        options.searchSortBy = searchSortBy;
        if(navTab == "breadCrumbForSearch")
        {
            options.searchFor = $breadCrumbForSearch.attr('searchFor');
        }
        else
        {
            options.searchFor = $target.attr('searchFor');
        }
        options.category_pathTraverse = path_Traverse;
        options.category_id = categ_Id;
        options.forumGroupId = forumGroupId;
        options.forumId = forumId;
        options.normalSearchType = $('#searchSelectedImage').attr('purpose');
        doAjaxAction('/getMoreSearchResult.do',options,function(data)//No internationalization
        {
            hideLoadingImage();
            reloadeSearchContainer(data,navTab,fieldType,forumId,categ_Id,path_Traverse,searchSortBy);
        });
    }
}

function reloadeSearchContainer(data,navTab,fieldType,forumId,categ_Id,path_Traverse,sortby)
{
    var $breadCrumbForSearch = $('#breadCrumbForSearch');
    var $data = $('<div></div>');
    $data.get(0).innerHTML = data;
    var $container = $data.find('#searchListContainer').html();
    $('#searchListContainer').html($container);
    var $searchResultViewRange = $data.find('#searchResultViewRange').html();
    $('#searchResultViewRange').html($searchResultViewRange);
    var $filterContainer = $data.find('#searchFilterArea').html();
    $('#searchFilterArea').html($filterContainer);
    var $currSearchSortBy =  $data.find('#currSearchSortBy').html();
    $('#currSearchSortBy').html($currSearchSortBy).attr('currSortBy',sortby);
    if(navTab == "relativeLinkSearch")
    {
        var $newbreadCrumb = $("<span> &raquo; <a class=underline href=javaScript:; purpose=breadCrumbForSearch fieldType="+fieldType+" forumId="+forumId+" categId="+categ_Id+" pathTraverse="+path_Traverse+ ">"+fieldType+"</a></span>");
        $newbreadCrumb.insertAfter($('#breadCrumbForSearch').find('span:last'));

    }
    else if(navTab == "breadCrumbForSearch")
    {
        var afterRemove = 0;
        $breadCrumbForSearch.children().each(function()
        {
            var $this = $(this);
            var currType = $this.find('a').attr('fieldType');
            if(afterRemove == 1)
            {
                $this.remove();
            }
            if(currType == fieldType)
            {
                afterRemove = 1;
            }
        });
    }

}//function reloadeSearchContainer(data,navTab)
function getAdvanceSearchResult()
{
    showLoadingImage();
    var searchString = $('#advanceSearchInpurBox').val();
    searchString =$.trim(searchString);
    if(searchString == "")
    {
        showMessage(i18n["zohodiscussions.searchList.noSearchString"],'failure');
        hideLoadingImage();
        return;
    }
    var $searchForumCategoryVice  = $('#SearchforumCategoryVice');
    var searchType = "forumId";
    var options = {};

    doAjaxAction(
        "/getAdvanceSearchResult.do", //No I18N
        $("#advanceSearchForm").serialize(),
        function (data)
        {
            hideLoadingImage();
            var $data = $('<div></div>');
            $data.get(0).innerHTML = data;
            var $searchContainer = $('#searchContainer');
            //$.history.add("Search/"+searchFor);
            if($('#searchListContainer').is(':visible'))
            {
                 var $container = $data.find('#searchResultFullContainer').html();
                 $('#searchResultFullContainer').html($container);
            }
            else
            {
                $('#mainContent').get(0).innerHTML = data;
                bindSearchContentClick($('#mainContent'));
                $('#advanceSearchContainerForm').show();
                $('#normalSearchInSearchList').hide();
            }
        },
        function (err)
        {
            hideLoadingImage();
            var responseData = eval(err.responseText);
            var reason =  responseData.reason;
            if(responseData.errorcode == "REMOTE_IP_LOCKED")
            {
                showMessage(i18n["zohodiscussions.generalmessage.tryagainaftersometime"],'failure'); // No I18N
            }
        });
}//function getAdvanceSearchResult()

function processWidgetsContClick(event)
{
    var $target = $(event.target);
    var $targetParent = $target.parent();
    if($target.is('a[hashPurpose]') && $target.is('a[currpurpose="usingHash"]'))
    {
        var hash = $target.attr('hashPurpose');
        if(isTopicQuickView == "false" && hash.indexOf("Topic/") == 0)
        {
            //do nothing
        }
        else
        {
            processHash(hash);
            return false;
        }
    }
    else if($target.is('div.teeplus'))
    {
        var forumId = $target.attr('forumId');//No internationalization
        var $teecont = $('#allForumControl').find('div[purpose="subForumView_'+forumId+'"]');
        $teecont.removeClass('teeplus').addClass('teeminus');//No internationalization
        $('ul.eachCategoryContainer_'+forumId).show();
    }
    else if($target.is('div.teeminus'))
    {
        var forumId = $target.attr('forumId');//No internationalization
        var $teecont = $('#allForumControl').find('div[purpose="subForumView_'+forumId+'"]');
        $teecont.removeClass('teeminus').addClass('teeplus');//No internationalization
        $('ul.eachCategoryContainer_'+forumId).hide();
    }
    else if($targetParent.is('#forumPermalink'))
    {
        var thisForumPermalink = $targetParent.attr('thisForumPermalink');
        $('#PermalinkCont textarea').val(thisForumPermalink);
        $('#permalink_Text').select();
        $('#PermalinkCont').show().parent().show();
        return;
    }
    else if($targetParent.is('li.watchingForum'))
    {
        watchThisItem($targetParent,"singleForumActions",event);
    }
    else if($targetParent.is('li.watchingCategory'))
    {
        watchThisItem($targetParent,"singleCategoryActions",event);
    }
    else if($target.is('a[purpose="newWatchedUser"]'))
    {
        processHash("myarea/dashboard");
        return;
    }
    else if($target.is('a[purpose="newPrivateMsg"]'))
    {
        processHash("myarea/privateMsg");
        return;
    }
    else if($target.is('a[purpose="newRecentActivity"]'))
    {
        var currStatus = $target.attr("currStatus");
        if(currStatus == "dashboard")
        {
            processHash("myarea/"+currStatus);
            return;
        }
        processHash("myarea/watchList/"+currStatus);
        return;
    }
    else if($target.is('a[purpose="authorProfile"]'))
    {
        var authorName = $target.attr('authorName');
        var singleClickflag = $target.attr('singleClickflag');
        if(singleClickflag == "0")
        {
          if(authorName == screenName || authorName == encodedScreenName)
          {
              processHash('MyArea');
              $target.attr('singleClickflag','1');
          }
          else
          {
              processHash('User/'+authorName);
              $target.attr('singleClickflag','1');
          }
        }
        return;
    }
    else if($targetParent.is("#loginToParticipate"))
    {
        $('#signinwidgetBox').hide();
        $('#iamLoginBox').show();
    }
    else if($targetParent.is("#chartMenu"))
    {
        if($target.is('li'))
        {
            $target.siblings().removeClass('selected');
            $target.addClass('selected');
            var assocImage=$target.attr('assocImage');
            var $assocImage = $(assocImage);
            if(assocImage == "#weekTrendChart")
            {
                //if weekTrendChart is called,check if the image src is empty.If so,fill 'image src'.
                var $chartImage = $assocImage.find('img[chart="true"]');
                if(typeof $chartImage.attr('src') == "undefined")
                {
                    $chartImage.attr("src", $chartImage.attr("actualURL"));
                    $("#weekTrendChartLoading").show().siblings('a').hide();
                    //show the image if it is loaded completely.
                    $chartImage.one("load",function() //No I18N
                    {
                        $assocImage.show();
                        $assocImage.prev('div[purpose="chartLoading"]').hide(); //No I18N
                    }).each(function()
                    {
                        if(this.complete){$(this).trigger("load");}
                    });
                }
                else //image already loaded,show it and hide month chart.
                {$assocImage.show().siblings().hide();}
            }
            else
            {$assocImage.show().siblings().hide();}
        }
    }
    else if($target.is('li[assocDiv]'))
    {
        $target.siblings().removeClass('selected');
        $target.addClass('selected');
        var assocDiv=$target.attr('assocDiv');
        if(assocDiv == "#topPublishers_Month")
        {
            if($(assocDiv).find('li').length == 0)
            {
                var forumId=$target.attr('forumId');
                var categoryId=$target.attr('categoryId');
                var options = {};
                options.forumGroupId = forumGroupId;
                options.forumId = forumId;
                options.categoryId = categoryId;
                doAjaxAction('/getLeaderboardTopics.do',options,function (data)//No internationalization
                {
                    $(assocDiv).get(0).innerHTML = data;
                });
            }
            $(assocDiv).show();
            $('#topContributors_Month').hide();
        }
        else
        {
            $(assocDiv).show().siblings('ul').hide();
        }
    }
}//function processWidgetsContClick(event)
function processAllForumsClick(event)
{
    var $target = $(event.target);
    var $targetParent = $target.parent();
    if($target.is('a[hashPurpose]'))
    {
        var hashPurpose = $target.attr('hashPurpose');
        if((isTopicQuickView == "false" && hashPurpose.indexOf("Topic/") == 0) || $target.attr('isNiceUrl') == "Yes")
        {
            //do nothing
        }
        else
        {
            processHash(hashPurpose);
            return false;
        }
    }
   else if($targetParent.is('li[purpose="eachForumPermalink"]'))
    {
        var thisForumPermalink = $targetParent.attr('thisForumPermalink');
        $('#PermalinkCont textarea').val(thisForumPermalink);
        $('#permalink_Text').select();
        $('#PermalinkCont').show().parent().show();
        return;
    }
    else if($targetParent.is('li.watchingForum'))
    {
        watchThisItem($targetParent,"singleForumActions",event);
    }
    else if($targetParent.attr('itemType')==1)
    {
        watchThisItem($targetParent,"singleCategoryActions",event);//No I18N
    }

    else if ($targetParent.is('div[purpose="moderator"]'))
    {
        var forumId=$targetParent.attr('forumId');
        $forumCont = $('#forumId_'+forumId);
        if($forumCont.is('.singleForumSub'))
        {
           $forumCont.removeClass("singleForumSub");
        }
        $forumCont.toggleClass('singleForumMod');//No I18N
    }
    else if ($targetParent.is('div[purpose="subforums"]'))
    {
        var forumIdSub = $targetParent.attr('forumId');
        $forumCont = $('#forumId_'+forumIdSub);
        if($forumCont.is('.singleForumMod'))
        {
           $forumCont.removeClass("singleForumMod");
        }
        $forumCont.toggleClass('singleForumSub');//No I18N
    }
}

function handleTopicClick(event,forumTopicId,$location)
{
    var $topicContainer = $('#eachTopic_'+forumTopicId);
    var $recentResponseContainer = $('#lastResponse_'+forumTopicId);
    var responseId = $recentResponseContainer.parents('li[parentCont="actualParent"]').attr('recentResponseId');//No I18N
    var $topicList = $('#topicList');
    $topicList.data('currentSelectedPost',$topicContainer);
    var $currFocusPost = $topicList.data('currentFocusPost');
    if($currFocusPost != undefined)
    {
        $currFocusPost.removeClass('hotKeyTopicCont');
    }
    $topicList.data('currentFocusPost',$topicContainer);
    if($recentResponseContainer.is(':visible') == true)
    {
        $topicContainer.removeClass('ndquickList').addClass('');
    }
    else
    {

        $topicContainer.siblings('li.ndquickList').removeClass('ndquickList').addClass(' ');
        $topicContainer.addClass('ndquickList');
        if(topicContent[forumTopicId])
        {
            $('#recentResponseContent_'+responseId).html(topicContent[forumTopicId]);
            topicContent[forumTopicId] = undefined;
        }
        setFocusToContainer($('#eachTopic_'+forumTopicId),false,0);
    }

    if($recentResponseContainer.attr('navStatus') == "No" && $location == "topicList")
    {
        $recentResponseContainer.attr('navStatus',"Yes");
        getprevAndFirstPost($recentResponseContainer);
    }
}//function handleTopicClick(event,forumTopicId)

//method to fetch more topics in topic list
function getMoreTopics(forumId,categoryId,fetchPage,topicFilter,postSinceLastVisitTime,statusURL,isPagination)
{

    showLoadingImage();
    var options = {};
    var filterHash = "";
    var isTypeUrl = $('#topicListHeaderCont').attr('isTypeURL');
    var $currviewFilter = $('#innerTabFilter');
    if($('#topicListFilter').is(':visible'))
    {
        $currviewFilter = $('#topicListFilter');
    }
    if(forumId != "")
    {
        options.forumURL =  forumId;
        if(isTopicQuickView == "true")
        {
        filterHash = "forum/"+forumId; //No I18N
        }
        else
        {

            filterHash = forumId;
        }
    }
    if(categoryId != "")
    {
        options.categoryURL = categoryId;
        filterHash = filterHash+"/"+categoryId; //No I18N

    }

    options.forumGroupId = forumGroupId;
    options.fetchPage = fetchPage;
    var isFilterThere = 0;
    if(topicFilter && topicFilter.toLowerCase() != "all" && (isOneTopicType != "true" || topicFilter.toLowerCase() != "questions" && topicFilter.toLowerCase() != "ideas" && topicFilter.toLowerCase() != "problems"))
    {
        if(filterHash == "")
        {
            filterHash = "filter"; //No I18N
        }
        else
        {
            filterHash = filterHash+"/filter"; //No I18N
        }
        isFilterThere = 1;
        filterHash = filterHash+"/"+topicFilter;
    }
    if(topicFilter)
    {
        if($currviewFilter.attr('isTypeURL') == 'yes')
        {
            var currTopicFilter = $currviewFilter.attr('topicfiltertype');
            if(topicFilter.toLowerCase() == "all")
            {
                topicFilter = currTopicFilter;
            }
            else if(topicFilter.toLowerCase() == "unrepliedposts")
            {
                options.unReplyWithType = currTopicFilter;
            }
        }
        options.topicFilter = topicFilter;
    }
    if(topicFilter == "postssincelastvisit")
    {
        var lastVisit = $currviewFilter.attr('postSinceLastVisitTime');
        if(lastVisit != null && lastVisit != "undefined")
        {
            options.postSinceLastVisitTime = lastVisit;
        }
    }
    var action = "";
    if($('#topicList').length > 0 && isPagination != "reload")
    {
        action = "/getMoreTopics.do"; //No I18N
        $locadLocation = $('#topicList');
    }
    else if($('#topicsList').length > 0 && isPagination != "reload")
    {
        action = "/getMoreTopicsTP.do"; //No I18N
        $locadLocation = $('#topicsList');
    }
    else
    {
        action = "/getSingleForumTopics.do"; //No I18N
        $locadLocation = $('#mainContent');
    }
    if(statusURL)
    {
            statusURL = statusURL.toLowerCase();
            statusURL = statusURL.replace(/\s/ig,"").replace("-","");
            var currStatusURL = statusURL;
            if(topicFilter == "problems" && statusURL == "needmoreinfo")
            {
                statusURL = "moreinfo" //No I18N
                currStatusURL = "needmoreinfo"; //No I18N
            }
            if(topicFilter == "questions" && statusURL == "workingonit")
            {
                statusURL = "working" //No I18N
                currStatusURL = "workingonit"; //No I18N
            }
            if(statusURL == "we")
            {
                statusURL = "wewillthinkaboutit" //No I18N
                currStatusURL = statusURL //No I18N
            }
            if(i18n_Status_[statusURL])
            {
                var i18n_statusURL = i18n_Status_[statusURL];
                if(i18n_statusURL)
                {
                    if(isFilterThere == 0 && filterHash == "")
                    {
                        filterHash = "filter"; //No I18N
                    }
                    else if(isFilterThere == 0)
                    {
                        filterHash = filterHash+"/filter"; //No I18N
                    }
                    filterHash = filterHash+"/"+currStatusURL;
                    options.statusURL = i18n_statusURL;
                }
            }
    }

    doAjaxAction(
        action,
        options,
        function (data)
        {
            $locadLocation.get(0).innerHTML = data;
            bindTopicClicks($('#topicList'));
            bindTopicClicks($('#topicsList'));
            if(action == "/getSingleForumTopics.do")
            {
                lightBox('#chartWidget');
                lightBox('#topicList');//No I18N
                bindTopicListHeaderClicks($('#topicListHeader'));
                bindWidgetsContClick($('#topicListWidgetsCont'));
            }
            goToTop();
            hideLoadingImage();
            if(typeof WmsContacts != "undefined" && ch == "true")
            {
                var dataOb = WmsContacts.getZohoContacts();
                setPresenceInTopicList(dataOb);
            }
            if(topicFilter == "PostsSinceLastVisit")
            {
                var $postSinceLastVisit = $('#topicList').find('a.mediumUnderlineLink');
                $postSinceLastVisit.removeClass('mediumUnderlineLink').addClass('mediumUnderlineLinkNew');
            }
            if(isTypeUrl == "no")
            {
                if(isTopicQuickView == "true")
                {
                    if(filterHash != "")
                    {
                        if(parseInt(fetchPage) > 1)
                        {
                            $.history.add(filterHash+"/"+fetchPage);
                        }
                        else
                        {
                            $.history.add(filterHash);
                        }
                    }
                    else
                    {
                        if(parseInt(fetchPage) > 1)
                        {
                            $.history.add("home/"+fetchPage); //No I18N
                        }
                        else
                        {
                            $.history.add("home"); //No I18N
                        }
                    }
                }
            }
        },
        function (errordata)
        {
            //alert(errordata.responseText);
        }
        );
    return false;
}//function getMoreTopics(forumId,categoryId,fetchPage)

//method to fetch more topics in topic list
function getMoreTagRelatedPost(fetchPage,tagName,getPostFor)
{
    showLoadingImage();
    var options = {};
    options.fetchPage =  fetchPage;
    options.tagName = tagName;
    options.forumGroupId = forumGroupId;
    options.getPostFor = getPostFor;
    doAjaxAction(
        "/getMoreTagRelatedPosts.do", //No I18N
        options,
        function (data)
        {
            if($('#topicList').length > 0)
            {
                $('#topicList').get(0).innerHTML = data;
                bindTopicClicks($('#topicList'));
            }
            else
            {
                $('#topicsList').get(0).innerHTML = data;
                bindTopicClicks($('#topicsList'));
            }
            goToTop();
            hideLoadingImage();
        },
        function (errordata)
        {
            //alert(errordata.responseText);
        }
     );
    return false;
}//function getMoreTopics(forumId,categoryId,fetchPage)

//method to fetch single forum topics
function getSingleForumTopics($target)
{
    showLoadingImage();
    var $this = $target
    var options = {};
    options.forumId =  $this.attr('forumId');
    options.categoryId = $this.attr('categoryId');
    options.forumGroupId = forumGroupId;
    options.fetchPage = $this.attr('fetchPage');
    options.ch = ch;
    doAjaxAction(
        "/getSingleForumTopics.do", //No I18N
        options,
        function (data)
        {

            $('#mainContent').get(0).innerHTML = data;
            lightBox('#chartWidget');
            lightBox('#topicList');//No I18N
            bindTopicClicks($('#topicList'));
            bindTopicClicks($('#topicsList'));
            bindTopicListHeaderClicks($('#topicListHeader'));
            bindWidgetsContClick($('#topicListWidgetsCont'));
            goToTop();
            hideLoadingImage();
            if($('#allForumWidget').length > 0)
            {
               if($('#allForumWidget').find('li[purpose="forumList"]').length < 9)
               {
                   $('#moreForumView').hide();
               }
            }
        },
        function (errordata)
        {
            $('#mainContent').get(0).innerHTML = errordata.responseText;
            hideLoadingImage();
        }
    );
    return false;
}//
/**** END OF TOPIC LIST CLICKS ****/
function selectTopicType($this,givenKey)
{
        var topicType = "";
        if(typeof givenKey == "undefined" || givenKey == "")
        {
             $this.addClass('selected').siblings('li[purpose="topicTypeTab"]').removeClass('selected');
             topicType = $this.attr('topicType');
             var topicTypeIcon = $this.attr('topicIconClass');
        }
        else
        {
            /*Kannapiran:::: li[purpose="topicTypeTab"] is not present in singletopictype portal.
            //This Check is needed when directly call the singletopictype URL like /newidea, /newdiscussion etc.,*/
            topicTypeIcon = givenKey;
            topicType = $('#writepostCont').attr('topicType');
        }
        var imgAttrClass = "";
        if(topicType == 1)
        {
            imgAttrClass = "imgAnnouncement";
            $('#announcementExpiryCont').show();
        }
        else
        {
            $('#announcementExpiryCont').hide();
        }
        $('#currentTopicType').val(topicType);

        if(topicTypeIcon == 'discuss')
        {
            imgAttrClass = "imgDiscuss";
            $('#writeNewTopic').html(i18n["zohodiscussions.writePost.discussionTypeMessage"]);
        }
        else if(topicTypeIcon == 'question')
        {
            imgAttrClass = "imgQuestion";
            $('#writeNewTopic').html(i18n["zohodiscussions.writePost.questionTypeMessage"]);
        }
        else if(topicTypeIcon == 'idea')
        {
            imgAttrClass = "imgIdea";
            $('#writeNewTopic').html(i18n["zohodiscussions.writePost.ideaTypeMessage"]);
        }
        else if(topicTypeIcon == 'error')
        {
            imgAttrClass = "imgError";
            $('#writeNewTopic').html(i18n["zohodiscussions.writePost.problemTypeMessage"]);
        }
        else
        {
            $('#writeNewTopic').html(i18n["zohodiscussions.writePost.announcementTypeMessage"]);
        }
        $('#TopicContentHolder').attr('class',topicTypeIcon).attr('imgAttrClass',imgAttrClass);
        var selectedForumOption = $('#SelectForum').val();
        if(selectedForumOption == null)
        {
           $('#selectForumMessage').show();
        }
        else
        {
           $('#selectForumMessage').hide();
        }
}//function selectTopicType($this)
/****WRITE POST****/
var createEditor = function()
{
    try
    {
        editor = ZE.create(
            {
                id : "editorHolder", //No I18N
                content : $('#postContentTA').val()
            }
            );
    }catch(ex)
    {
        setTimeout("createEditor()",300);
    }
}
function initWritePost()
{
    newOpenEditor($('#editorLocation'),"responseContent","postContentTA"); //No I18N
    loadCategories();
    $('#writepostTabsCont li[purpose="topicTypeTab"]').click(function()
    {
        selectTopicType($(this));
    });
    $('#SelectForum').change(function()
    {
        loadCategories();
    });
    $('#publishTopic').click(function()
    {
          addForumPost(false);
    });
    $('#previewTopic').click(function()
    {
      var $this = $(this);
      var isDraft = $this.attr('isDraft');
      var userName = $this.attr('userName');
      writePostPreview(userName,"Preview","true",isDraft)
    });

    $('#attachmentsListCont').find('div.imgAshDelete').click(function(event)
    {
        $this = $(this);
        var attachmentName = $this.attr('attachmentName');
        var attachmentId = $this.attr('attachmentId');
        deleteUnpublishedAttachment(attachmentName,attachmentId,event);
        return;
    });

    $('#listOfMyDraftCont').click(function()
    {

        var draftSize = $(this).attr('draftsize');
        if(draftSize < 1)
        {
            return;
        }
        var $this = $(this);
        if($this.is('.moreOptionsTop'))
        {
            $this.removeClass('moreOptionsTop').addClass('moreOptionsTopSelected');
        }
        else
        {
            $this.removeClass('moreOptionsTopSelected').addClass('moreOptionsTop');
        }
        $this.hover
        (
            function()
            {
               var handle = $this.data('destroyHandle');
               if (handle) {clearTimeout(handle);}
            },
            function ()
            {
                var handle = setTimeout(function()
                {
                    $this.removeClass('moreOptionsTopSelected').addClass('moreOptionsTop');
                }, 500);
                $this.data('destroyHandle', handle);
            }
        );//$myDraftContainer.hover()
    });
    $('#saveDraft').click(function()
    {
        addForumPost(true);
    });
    $('#cancelAddTopic').click(function()
    {
        $('#mainContent div.mainFullWrite').html('');
        processHash('Home');
    });
    loadUploadAttachmentsCont();
}//function initWritePost()

function closeGDocsAttachTemplate(docType)
{
    if(docType == "zdocs")
    {
        $('#zDocsTemplate').hide();
    }
    else
    {
        $('#gDocsTemplate').hide();
    }
    hideLoadingImage();
}
function loadUploadAttachmentsCont(docs,attachType)
  {
  //before loading a attachment cont delete the existing attachements cont
      var forNewPost = ($('#attachTemplate').length == 1)?true:false;
      var contName = (forNewPost == true)?"attachTemplate":"responseAttachTemplate"
      var $attachmentsListCont = $('#attachmentsListCont');
      var attachementsUploaded = $attachmentsListCont.find('div.singleElementBox,li.tinyText').length;
      if(forNewPost == true)
      {
          $('#newPostRightCont  div[purpose="attachmentTemplate"]').remove();
      }
      else
      {
          $('#attachBrowseCont').html('');
      }
      //make (sure that uploaded attachments count is less than maxAttachmentsPerPost
      if(attachementsUploaded < maxAttachmentsPerPost)
      {
          var remAttachement = maxAttachmentsPerPost - attachementsUploaded;
          var currentAttachementNo = attachementsUploaded+1;
          //we have attachement container template
          var $attachTemplate = $('#'+contName);
          //take a clone of attachTemplate container and process the file uploading
          var $attacher = $attachTemplate.clone();
          if(forNewPost == true)
          {
              $attacher.insertBefore($attachmentsListCont).show();
          }
          else
          {
              $('#attachBrowseCont').append($attacher.show()).show();
          }
          $attacher.attr('id',contName+'_'+currentAttachementNo);
          $attacher.attr('purpose','attachmentTemplate');
          $attacher.find('div.dataEncloser').wrap('<form action = "/uploadFile.do" target = "fileUpdTgt" method="post" enctype="multipart/form-data"></form>');
          $attacher.find('div.iFrameContainer').html('<iframe name = "fileUpdTgt_'+currentAttachementNo+ '"> </iframe>');
          $attacher.find('form').attr('target', 'fileUpdTgt_'+currentAttachementNo);
          var $currDataEncloser = $attacher.find('form > div.dataEncloser');
     //zoho Docs attachments
          var $currZDocsAttach = $currDataEncloser.find('a#zDocsAttachments');
          $currZDocsAttach.click(function()
          {
              var $zDocsTemplate = $('#zDocsTemplate');
              var zDocSrc= scheme+"://"+ZDOCS_URL+"/index.do?service=discussions&share=true"; //No I18N
              $zDocsTemplate.html('<iframe height="500px;" width="600px;" style="margin-top:5%; margin-left:25%;" src="'+zDocSrc+'"></iframe>');
              $zDocsTemplate.show();
          });
  //GDocs attachments
          var $currGDocsAttach = $currDataEncloser.find('a#gDocsAttachments');
          $currGDocsAttach.click(function()
          {
              var $gDocsTemplate = $('#gDocsTemplate');
              var gDocSrc= scheme+"://"+GADGET_URL+"/gdocs?serURL="+scheme+"://"+domainNameURL+"/jsp/AddGDocs.jsp&maxDocs="+remAttachement+"&id=1"; //No I18N
              $gDocsTemplate.html('<iframe height="600px;" width="800px;" style="margin-top:5%; margin-left:17%" src="'+gDocSrc+'"></iframe>');
              $gDocsTemplate.show();
          });
          if(typeof docs == "undefined")
          {
              //write the file upload action
              $attacher.find(':file').change(function()
              {
                  $attacher.find('[purpose="attachLoadingCont"]').show();
                  $attacher.find(':input[name="attacher"]').val('');
                  $attacher.find('form').get(0).submit();
              });
          }
          else
          {
              //$attacher.find(':form').attr(docs);
              showLoadingImage(i18n["zohodiscussions.settings.creating"]);
              var eachGDocs = docs.split(':');
              var docsType = "attachZDocs" //No I18N
              if(attachType == "gdocs")
              {
                  docsType = "attachGDocs"; //No I18N
              }
              $.each(eachGDocs, function(index, item)
              {
                  $attacher.find('form div.dataEncloser').append('<input name="'+docsType+'"  type="hidden" value="'+item+'">');
              });
              $attacher.find('form').get(0).submit();
          }
      }//if(attachementsUploaded < maxAttachmentsPerPost)
}//function loadUploadAttachmentsCont()

function uploadGDocsFileSuccess(attachDetails,forumGroupId,docType)
{
    var attachedLength = attachDetails.length;
    var isFailed = 0;
    var listOfFailedAttach = "";
    var concat = "";
    for(var i=0; i<attachedLength; i++)
    {
        var $eachAttachArr = attachDetails[i];
        var result = $eachAttachArr.result;
        var attachmentName = $eachAttachArr.actualFileName;
        if(result == "success")
        {
            var actualAttachmentId = $eachAttachArr.actualAttachId;
            var formattedFileSize = $eachAttachArr.attachmentSize;
            var attachmentId = $eachAttachArr.attachmentId;
            uploadFileSuccess(attachmentId,attachmentName,forumGroupId,actualAttachmentId,formattedFileSize);
        }
        else
        {
            isFailed = 1;
            var reason = $eachAttachArr.reason;
            listOfFailedAttach = listOfFailedAttach + concat +"<b>"+attachmentName+"</b> : "+i18n[reason]; //No I18N
            concat = "<br><br>";
        }
    }
    if(isFailed == 1)
    {
       showMessage(i18n["zohodiscussions.popupContainers.failedattachmentMess"]+"<br>"+listOfFailedAttach,'failure',5000); //No I18N
    }
    closeGDocsAttachTemplate(docType);
}//uploadGDocsFileSuccess(attachDetails,forumGroupId)

function uploadFileSuccess(attachmentId,attachmentName,forumGroupId,actualAttachmentId,formattedFileSize)
{
    //hideLoadingImage();
    var $attachmentsListCont = $('#attachmentsListCont');
    var forNewPost = ($('#attachTemplate').length == 1)?true:false;
    var $currentAttachment;
    var attachmentDetails = attachmentId+','+attachmentName+','+formattedFileSize;
    if(forNewPost == true)
    {
        $currentAttachment = $('<div id="newAttachment_' + attachmentId + '" class="singleElementBox" attachmentDetails="'+ attachmentDetails +'"><div class="flLeft">'+attachmentName+'</div><div class="flRight imgAshDelete bgBox"></div></div>');
        var $attachmentContForPreview = $('#previewAttachment');
        //var $eachAttachment = $('<li class="singleList" id="eachAttachmentForPreview_'+ attachmentId +'"  attachmentDetails="'+ attachmentDetails +'"><div class="flLeft iconCont"><div class="attachIcon imgAttachmentTh"></div></div>  <ul class="ulNoStyle detailsListNew"> <li class="header"> <a>'+attachmentName+'</a> </li> <li class="forumDetailsList"> <span>Size:'+formattedFileSize+'</span></li></ul></li>')
        //$attachmentContForPreview.append($eachAttachment);
        $('#newAttachment_' + attachmentId).attr('attachmentDetails', attachmentDetails);
        $('#AttachmentPreviewCont').show();

    }
    else
    {
        $currentAttachment = $('#responseEachAttachmentTemplate').clone();
        $currentAttachment.attr('id','newAttachment_' + attachmentId).attr('attachmentDetails',attachmentDetails).show();
        $currentAttachment.find('[attachmentPurpose="attachmentName"]').html(attachmentName);
        $currentAttachment.find('[attachmentPurpose="attachmentSize"]').html(formattedFileSize);
    }
    $('#previewResponse').append('<input type = "hidden" name="attachmentId" value = "' + attachmentId + '"  attachmentDetails= "' + attachmentDetails + '">')
    if(actualAttachmentId != -1)
    {
        $currentAttachment.append('<input type = "hidden" name="attachmentId" value = "' + actualAttachmentId + '">');
    }
    $currentAttachment.find('div.imgAshDelete').click(function(event)
    {
        deleteUnpublishedAttachment(attachmentName,attachmentId,event);
    });
    $attachmentsListCont.append($currentAttachment);

    //generate the new file upload container
    loadUploadAttachmentsCont();
}

function deleteUnpublishedAttachment(attachmentName,attachmentId,event)
{
    if(confirm(i18n["zohodiscussions.generalmessage.deleteAttachmentConfirmMsg"]))
    {
        showSmallLoadingImage(event);
        var options = {};
        options.forumGroupId = forumGroupId;
        options.fileName = attachmentName;
        options.fileId = attachmentId;
        options[csrfParamName] = csrfToken;
        doAjaxAction('/deleteUnpublishedAttachment.do',options,function (data)//No internationalization
        {
            hideLoadingImage();
                if(data == "SUCCESS")
                {
                    $('#newAttachment_'+attachmentId).remove();
                    if($('#previewAttachment').find('li.singleList').length == 1)
                    {
                      $('#AttachmentPreviewCont').hide();
                    }
                    $('#previewResponse').find('input[value= "' + attachmentId + '"]').remove();
                    showTipper(i18n["zohodiscussions.general.Deleted"],'info');
                    loadUploadAttachmentsCont();
                }//if(data == "SUCCESS")
            });
        }//
}
function loadCategories()
{
    loadAdminActionsLinks();
    var $selectForumContainer = $('#SelectForum');
    var forumId = $selectForumContainer.val();
    var selectedCategoryName = $selectForumContainer.attr('selectedCategoryName');
    var selectedCategoryId = $selectForumContainer.attr('selectedCategoryId');
    //load categories for this forum
    var categoriesForForum = $('#categoryList').val();
    $('#SelectCategory').hide();
    $('#selectCategory').html('');
    if(typeof categoriesForForum != 'undefined')
    {
        $.each(categoriesForForum.split('$$'), function(index, item)
        {
            if(item.indexOf(forumId+':') > -1)
            {
                $('#SelectCategory').html(item.split(':')[1]).show();
                //$('#SelectCategory option:first').attr('selected','true');
                return false;
            }//if(item.indexOf(forumId+':') > -1)
            else
            {
               $('#SelectCategory').html('<option selected value="-1">Uncategorised</option>').show();
            }
        });
    }

    var $selectedCategoryCont = $('#SelectCategory').find('option[value="'+selectedCategoryId+'"]');
    if($selectedCategoryCont.length == 1)
    {
        $selectedCategoryCont.attr('selected','true');
    }
    else
    {
        $('#SelectCategory option:first').attr('selected','true');
    }

}//function loadCategories(postId)

function loadAdminActionsLinks()
{
    var isForumModerator = $('#SelectForum option:selected').attr('isForumModerator');
    if(isForumModerator == "true")
    {
        $('#isStickyLinkCont,#announcementLinkCont,#isNotifyEveryone').fadeIn();
    }
    else
    {
        //the author is not admin or moderator
        $('#isStickyLinkCont,#announcementLinkCont,#isNotifyEveryone').fadeOut();
        //if the currently selected topictype is announcement then select the discussions tab
        if($('#writepostTabsCont li.selected').attr('topicIconClass') == 'announcement')
        {
            $('#writepostTabsCont li:first').trigger('click');
        }
    }
}//function loadAdminActionsLinks()

function addForumPost(isDraft)
{
    if($('#fileUploadStatus').val() != 'uploading')
    {
        var loadingMessage = (isDraft == true)?i18n["zohodiscussions.general.saving"]:i18n["zohodiscussions.general.publishing"];
        disablePostButtons();
        var $writePostForm = $('#addForumPostForm');
        $topicTitle = $('#topicTitle');
        var postTitle = $topicTitle.val();
        postTitle = postTitle.replace(/^\s+|\s+$/g,' ').replace(/\s+/g,' ');
        postTitle = $.trim(postTitle);
        if (postTitle == '')
        {
            hideLoadingImage();
            setFocusToContainer($('#topicTitle'));
            enablePostButtons();
            showMessage(i18n["zohodiscussions.writePost.TopicTitleCannotbeEmptymessage"],'failure');
            $('#topicTitle').focus();
            return;
        }
        $('#topicTitle').val(postTitle);
        if(postTitle.length > 200)
        {
            hideLoadingImage();
            showMessage(i18n["zohodiscussions.writePost.TopicTitleLengthMsg"],'failure');
            enablePostButtons();
            return;
        }
        var postTags = $('#forumTags').val();
        postTags = postTags.replace(/^\s+|\s+$/g,' ').replace(/\s+/g,' ');
        if(postTags != "")
        {
          if(postTags.match(/^[^\^\"'()~`!@#$%&:;\/\\?|<>{}[\]*-+=]+$/)== null)
          {
             hideLoadingImage();
             showMessage(i18n["zohodiscussions.singlepost.specialCharacterNotAllowedMsg"],'failure');
             enablePostButtons();
             return;
          }
        }//if(postTags != "")
        var tag =postTags.split(",");
        for(var i=0;i<tag.length;i++)
        {
            if(tag[i].length > 50)
            {
                showTipper(i18n["zohodiscussions.singlepost.TagexceedMessage"],'failure');
                enablePostButtons();
                return;
            }
        }// for(var i=0;i<tag.length;i++)

        var contentToPost = editor.getContent();
        contentToPost = contentToPost.replace(/^\s+|\s+$/g,' ').replace(/\s+/g,' ');
        $('#postContentTA').val(contentToPost);
        var $tempCont = $('<div></div>').html(contentToPost);
        contentToPost = $tempCont.text();
        contentToPost = $.trim(contentToPost);
        if (contentToPost == '')
        {
            setFocusToContainer(($('#editorHolder')).focus());
            hideLoadingImage();
            enablePostButtons();
            showMessage(i18n["zohodiscussions.writePost.noContentInPost"],'failure');
            return;
        }
        if(isDraft == true)
        {
            //this is draft so topic status will be 1
            $('#topicStatus').val(1);
        }
        else
        {
            //this is a normal post so status will be 0
            $('#topicStatus').val(0);
        }
        var selectedForum = $('#SelectForum').val();
        var selectedCategory = $('#SelectCategory').val();
        if(selectedForum == null)
        {
           hideLoadingImage();
           showMessage(i18n["zohodiscussions.writePost.selectAnyForum"],'failure');
           enablePostButtons();
           return;
        }
        if(selectedCategory == '0')
        {
           hideLoadingImage();
           showMessage(i18n["zohodiscussions.writePost.selectAnyCategory"],'failure');//No I18N
           enablePostButtons();
           return;
        }
        var action = '/addForumPost.do';
        if(ZUID == -1)
        {
            action = '/addGuestForumPost.do';
        }
        showLoadingImage(loadingMessage);

        doAjaxAction(
            action,
            $('#addForumPostForm').serialize(),
            function (data)
            {
                hideLoadingImage();
                var responseData = eval(data);
                if(responseData.result=="success")
                {
                    var forumTopicId = responseData.value;
                    if(isDraft == true)
                    {
                        showTipper(i18n["zohodiscussions.writePost.saveDraftMsg"],'success',3000);
                        enablePostButtons();
                        $('#forumTopicId').val(forumTopicId);
                    }
                    else
                    {
                        if(responseData.isApproved == 0)
                        {
                            //this topic is waiing for moderation
                            $('#mainContent div.mainFullWrite').html('');
                            showMessage(i18n["zohodiscussions.writePost.topicAwaitingModeration"],'info');
                            if(isTopicQuickView == "false")
                            {
                                window.location.href = serverURL+'/topic/'+responseData.topicPermaLink;
                            }
                            else
                            {
                                showLoadingImage();
                                openSinglePost(forumTopicId);
                            }
                            return;
                        }
                        else
                        {
                            $('#mainContent div.mainFullWrite').html('');
                            showTipper(i18n["zohodiscussions.writePost.publishMsg"],'success',4000);
                            if(isTopicQuickView == "false")
                            {
                                window.location.href = serverURL+'/topic/'+responseData.topicPermaLink;
                            }
                            else
                            {
                                showLoadingImage();
                                openSinglePost(responseData.value);
                            }
                        }
                    }
                }//
                else
                {
                    showMessage(responseData.reason,'failure');
                    enablePostButtons();
                }
            },
            function(errordata)
            {
                hideLoadingImage();
                if(errordata.responseText.indexOf("'result':'failure'") > 0)
                {
                    var responseData = eval(errordata.responseText);
                    if(responseData.result == "failure")
                    {
                        if(responseData.errorcode == "HIP_REQUIRED")
                        {
                            var $writePostCaptcha = $('#writePostCaptcha');
                            if($writePostCaptcha.attr('currCaptcha') == "new")
                            {
                                 showMessage(i18n["zohodiscussions.writePost.captchaMsg"],'failure');
                            }
                            else
                            {
                                showMessage(i18n["zohodiscussions.writePost.captchaErrorMsg"],'failure');
                            }

                            $writePostCaptcha.find('img[purpose="captchaImage"]').replaceWith("<img purpose=captchaImage name=hipImg border=0 src=/showcaptcha?digest="+responseData.reason+" align=absmiddle alt=HIP image>");
                            $('#captchaCode').attr('name',responseData.reason);
                            $writePostCaptcha.attr('currCaptcha',"old");
                            $writePostCaptcha.show();
                        }
                        else
                        {
                            showMessage(responseData.reason,'failure'); //No I18N
                        }
                    }
                }
                else
                {
                    if(errordata.responseText != "")
                    {
                        $('#writepostCont').get(0).innerHTML = errordata.responseText;
                    }
                }
                enablePostButtons();
            });

        }
        else
        {
            $('#submitStat').show();
        }
}//function addForumPost(isDraft)

function singlePostDeleteAction($this,$location)
{
  var forumTopicId = $this.attr('forumTopicId');
  forumTopicId = forumTopicId || $this.parents('li[parentCont="actualParent"]').attr('forumTopicId');//No I18N
  var responseId = $this.attr('responseId');
  var categoryId = $this.attr('categoryId');
  categoryId = categoryId || $this.parents('li[parentCont="actualParent"]').attr('categoryId');//No I18N
  var responseAuthorId = $this.parents('li[parentCont="actualParent"]').attr('responseAuthorId');//No internationalization
  var forumId = $this.attr('forumId');
  forumId = forumId || $this.parents('li[parentCont="actualParent"]').attr('forumId');//No I18N
  var itemType = $this.attr('itemType');
  if(itemType != "post") //handle responses and threads
  {
      var deleteResponse = {};
      if(responseAuthorId == ZUID)
      {
        deleteResponse.responseowner = "true";
      }
      deleteResponse.forumGroupId = forumGroupId;
      deleteResponse.forumTopicId = forumTopicId;
      deleteResponse.categoryId = categoryId;
      deleteResponse.forumId = forumId;
      deleteResponse.responseId = responseId;
      deleteResponse[csrfParamName] = csrfToken;
      slideUpActionInModeration('/deleteForumResponse.do',deleteResponse,$this);//No I18N
  }//if(itemType != "post")
  else
  {
  //TODO: post delete. Prompt that all response will be deleted.
      var deleteOptions = {};
      if(responseAuthorId == ZUID)
      {
        deleteOptions.access = "author";//No internationalization
      }
      deleteOptions.forumGroupId = forumGroupId;
      deleteOptions.forumTopicId = forumTopicId;
      deleteOptions.categoryId = categoryId;
      deleteOptions.forumId = forumId;
      deleteOptions[csrfParamName] = csrfToken;
      slideUpActionInModeration('/deleteTopic.do',deleteOptions,$this);//No I18N
   }
}//function deletePost()

function refreshSingleTopic(forumTopicId)
{
        //refresh the content of a single topic in the forum list page.
        //this will be called whenever a forum topic is changed - by adding/deleting a response / thread
        //as well as topic level events like sticky and locking/unlocking.
        var $topicList = $('#topicList');
        if($topicList.length < 1)
        {
            $topicList = $('#topicsList');
        }
        var options = {};
        options.forumTopicId = forumTopicId;
        options.forumGroupId = forumGroupId;
        options.singleTopicRefresh='singleTopicRefresh'; //No internationalization
        var $divToRefresh = $('#eachTopic_'+forumTopicId);//$topicList.find('div[forumTopicId="' + forumTopicId + '"]');
        doAjaxAction('/refreshSingleTopic.do',options, function(data)//No internationalization
        {
            hideLoadingImage();
            $data = $("<div></div>").html(data);
            if($data.find('li.singleList').length < 1)
            {
                $divToRefresh.remove();
                return false;
            }

            var thisModifiedTime = $data.find('div.singleTopicCont').attr('modifiedtime');
            var endPostModifiedTime =$topicList.find('div.singleTopicCont:last').attr('modifiedtime');
            var $firstSinglePost = $topicList.find('div.singleTopicCont:first');
            var startPostModifiedTime = $firstSinglePost.attr('modifiedtime');
            var shouldScrollTop= false;

            if(thisModifiedTime < endPostModifiedTime)
            {
                $divToRefresh.remove();
            }
            else if(thisModifiedTime > startPostModifiedTime)
            {
               $data.insertBefore($firstSinglePost);
               $divToRefresh.remove();
               eval($data.find("script").html());
               shouldScrollTop = true;
            }
            else
            {
                $data.insertBefore($divToRefresh);
                $divToRefresh.remove();
                eval($data.find("script").html());
                shouldScrollTop = true;
            }
            if(shouldScrollTop == true)
            goToTop();

        });//$divToRefresh.load('/getForumTopicList.do?forumTopicId='+forumTopicId, function()
}//function refreshSingleTopic(forumTopicId)


function disablePostButtons()
{
    $('#publishTopic').attr('disabled',true);
    $('#saveDraft').attr('disabled',true);
}
function enablePostButtons()
{
    $('#publishTopic').attr('disabled',false);
    $('#saveDraft').attr('disabled',false);
}

//response pagination

function getprevAndFirstPost($content)
{
    var forumTopicId = $content.parents('li[parentCont="actualParent"]').attr('forumTopicId');//No I18N
    var options = {};
    options.forumGroupId = forumGroupId
    options.forumTopicId = forumTopicId;

    var responseId = $content.attr('recentResponseId');
    if(typeof responseId != "undefined")
    {
        options.responseId = responseId;
        options.modifiedTime = $content.attr('modifiedTime');
        options.currResponseCount = $content.attr('currResponseCount');
    }
    else
    {
        var targetParent = $content.parents('div.listOfResponseLink');
        options.responseId = targetParent.attr('responseId');
        options.modifiedTime = targetParent.attr('modifiedTime');
        options.currResponseCount = targetParent.attr('currResponseCount');
    }

    options.toProvide = "First";
    options.currStage = "1";
    doAjaxAction('/getResponse.do',options,function(data)
    {
        var $data = $(data);
        var $currResponseContent = $('#recent_ResPonse_'+responseId);
        if($('#lastResponse_'+forumTopicId).find('div.listOfResponseLink[prev="-1"]').length < 1)
        {
            $data.insertAfter($currResponseContent);
            lightBox("#"+$data.get(0).id);
            $currResponseContent.next('div.listOfResponseLink').attr("Prev","-1");
        }
        var $navLoading = $('#navigationLoading_'+responseId);
        if($navLoading.attr('currRequest') == "first")
        {
            $navLoading.remove();
            $currResponseContent.hide();
            $('#navCont_'+responseId+',#navCont_1_'+responseId).removeClass('navLoading');
            firstOrLastResponse($('#navCont_'+responseId).find('li.ndtopicNavFirst'));
        }
        else
        {
            provideResponse($content);
        }
        return;
    });
}//function getprevAndFirstPost($content)

function provideResponse($content)
{
    var forumTopicId = $content.parents('li[parentCont="actualParent"]').attr('forumTopicId'); //No I18N
    var responseId = $content.attr('recentResponseId');
    var toProvide = $content.attr('toProvide');
    var options = {};
    options.forumGroupId = forumGroupId;
    options.forumTopicId = forumTopicId;
    options.toProvide = toProvide;
    if(typeof responseId != "undefined")
    {
        options.modifiedTime = $content.attr('modifiedTime');
        options.currResponseCount = $content.attr('currResponseCount');
        options.currStage = $content.attr('currResponsestage');
    }
    else
    {
        var targetParent = $content.parents('div.listOfResponseLink');
        responseId = targetParent.attr('responseId');
        options.modifiedTime = targetParent.attr('modifiedTime');
        options.currResponseCount = targetParent.attr('currResponseCount');
        options.currStage = targetParent.attr('currResponsestage');
    }
    options.responseId = responseId;
    doAjaxAction('/getResponse.do',options,function(data)
    {
          var $currResponseContent = $('#recent_ResPonse_'+responseId);
          // now check it new input response data was already loaded or not..
          var $this = $("<div>"+data+"</div>");
          var inputResponseId = $this.find('div.listOfResponseLink').attr('responseId');
          var inputResponseContent = $('#lastResponse_'+forumTopicId).find('div.listOfResponseLink[responseId = "'+inputResponseId+'"]');
          if(inputResponseContent.length > 0)
          {
                if(toProvide == "Prev")
                {
                    $currResponseContent.attr("Prev",inputResponseId);
                    inputResponseContent.attr("Next",responseId);
                }
                else if(toProvide == "Next")
                {
                    $currResponseContent.attr("Next",inputResponseId);
                    inputResponseContent.attr("Prev",responseId);
                }
          }
          else
          {
              var $data = $($this.html());
              if(toProvide == "Prev")
              {
                  $data.insertAfter($currResponseContent);
                  lightBox("#"+$data.get(0).id);
                  var $newResponseContent = $currResponseContent.next('div.listOfResponseLink');
                  $newResponseContent.attr("Next",responseId);
                  $currResponseContent.attr("Prev",inputResponseId);
              }
              else if(toProvide == "Next")
              {
                  $data.insertBefore($currResponseContent);
                  var $newResponseContent = $currResponseContent.prev('div.listOfResponseLink');
                  $newResponseContent.attr("Prev",responseId);
                  $currResponseContent.attr("Next",inputResponseId);
              }
          }
         var $navLoading = $('#navigationLoading_'+responseId);
         if($navLoading.attr('currRequest') == "Prev")
         {
             $navLoading.remove();
             $currResponseContent.hide();
             checkPrevNextResponse($('#navCont_'+responseId).find('li.ndtopicNavPrev'));
             $('#navCont_'+responseId+',#navCont_1_'+responseId).removeClass('navLoading');
         }
         else if($navLoading.attr('currRequest') == "Next")
         {
             $navLoading.remove();
             $currResponseContent.hide();
             checkPrevNextResponse($('#navCont_'+responseId).find('li.ndtopicNavNext'));
             $('#navCont_'+responseId+',#navCont_1_'+responseId).removeClass('navLoading');
         }
      });
}//function provideRespones($conent)

function checkPrevNextResponse($content)
{
    var $contentParent = $content.parents('div.listOfResponseLink');
    var responseId = $contentParent.attr('responseId');
    var toProvide = $content.attr('toProvide');

    var currResponse = $contentParent.attr(toProvide);

    if(currResponse == "0")
    {
        var $loading = $('#navigationLoading').clone();
        $loading.attr('id','navigationLoading_'+responseId).attr('currRequest',toProvide);
        var $navCont = $('#navCont_'+responseId);
        $loading.insertAfter($navCont).show();
        $('#navCont_'+responseId+',#navCont_1_'+responseId).addClass('navLoading');
        provideResponse($content);
        return;
    }
    else
    {
        var $newResponseCont = $('#recent_ResPonse_'+currResponse);
        $contentParent.hide();
        $newResponseCont.show();
        setFocusToContainer($newResponseCont.parents('.ndquickList'),false,0);//No I18N
        if($('#navCont_'+currResponse).is('.navLoading'))
        {
            $('#navCont_'+responseId+',#navCont_1_'+responseId).removeClass('navLoading');
        }
        if($newResponseCont.attr(toProvide) == "0")
        {
           var $shouldProvideLink =  $('#navCont_'+currResponse).find('li[toProvide="'+toProvide+'"]');
           provideResponse($shouldProvideLink);
        }
        else
        {
            return;
        }
     }
}//fucntion checkPrevNextResponse($content)

//if click first or last img
// if click first img which one prev is -1 then that's will be display,
// click last img whick one next is -1 then that's will be display..
function firstOrLastResponse($content)
{
    var $targetParent = $content.parents('div.listOfResponseLink');
    var toProvide = $content.attr('toProvide');
    var responseId = $targetParent.attr('responseId');
    var forumTopicId = $content.parents('li[parentCont="actualParent"]').attr('forumTopicId');//No I18N

    var $responaseContainer = $('#lastResponse_'+forumTopicId);
    var $currentOpenedResponse = $('#recent_ResPonse_'+responseId);
    if(toProvide == "First")
    {
        var $firstResponse = $responaseContainer.find('div.listOfResponseLink[Prev="-1"]');
        if($firstResponse.length == 0)
        {
           var $loading = $('#navigationLoading').clone();
           $loading.attr('id','navigationLoading_'+responseId).attr('currRequest','first');
           var $navCont = $('#navCont_'+responseId);
           $loading.insertAfter($navCont).show();
           $('#navCont_'+responseId+', #navCont_1_'+responseId).addClass('navLoading');
           getprevAndFirstPost($content);
           return;
        }
        $currentOpenedResponse.hide();
        $firstResponse.show();
        setFocusToContainer($('#eachTopic_'+forumTopicId),false,0);
        if($('#navCont_'+responseId).is('.navLoading'))
        {
            $('#navCont_'+responseId+',#navCont_1_'+responseId).removeClass('navLoading');
        }
        var currResponse = $firstResponse.attr('responseId');
        if($firstResponse.attr('Next') == "0")
        {
           var $shouldProvideLink =  $('#navCont_'+currResponse).find('li[toProvide="Next"]')
           provideResponse($shouldProvideLink);
        }
    }
    else if(toProvide == "Last")
    {
        $currentOpenedResponse.hide();
        $responaseContainer.find('div.listOfResponseLink[Next="-1"]').show();
        setFocusToContainer($('#eachTopic_'+forumTopicId),false,0);
    }
}//function firstOrLastResponse($content)

function lightBox(containerId)
{
    $(containerId).find('a.lightbox').lightbox(
    {
           'navbarOnTop': true,
           'resizeSpeed' : 150,
           'overlayOpacity': 0.1
    });
    $(window.document).keydown(function (e)
    {
        if(e.keyCode == 27)
        {
            if($('#lightbox').is(':visible'))
            {
                $("#lightbox").hide();
                $("#overlay").hide();
            }
            return false;
        }
     });
}
function saveButtonClick(id)//No I18N
{
        var $this=$('#'+id);
        var options={};
        options.forumGroupId=forumGroupId;
        options.referrer = $this.attr('referrer');
        options.customFieldValue = $this.prev().val();
        $.ajax(
        {
            url: "/joinPortal.do",//No I18N
            type: "POST",//No I18N
            data: options,//No I18N
            error: function (err, desc, exceptionobj)
            {
                showTipper(err.responseText);
            },//error
            success : function (data)
            {
               if( "success" == data)
               {
                   showTipper(i18n["zohodiscussions.widgetscontainer.subscribedSuccessfully"],'success',1000);
                   $('#waitingforApproval,#portalWaitingforApproval').show();
                   $('#joinPortalContent,#portaljoinContent').hide();
                }
                else if("open" == data)
                {
                    window.location.reload();
                }
                else if("customSignUp" == data)
                {
                    location.href=action;
                }
            }//success : function (data)
        });
}
function bindSubscribeAction()
{
    $('#joinThisPortal,#portalJoin').unbind('click').click(function()
    {
            var options = {};
            options.forumGroupId = forumGroupId;
            options.referrer='ajax'; //No I18N
            var isCustomFieldStatus = $(this).attr('isCustomFieldStatus');
            var action ="";
            if(isCustomFieldStatus == '1')
            {
                 $('#customFieldDiv,#customFieldWidgetDiv').show();
                $('#portalJoin,#joinThisPortal').hide();
            }
            else
            {
                $.ajax(
                {
                    url: "/joinPortal.do", //No I18N
                    type: "POST", //No I18N
                    data: options,
                    error: function (err, desc, exceptionobj)
                    {
                        showTipper(err.responseText,'failure',1000);
                    },//error
                    success : function (data)
                    {
                        if( "success" == data)
                        {
                           showTipper(i18n["zohodiscussions.widgetscontainer.subscribedSuccessfully"],'success',1000);
                           $('#waitingforApproval,#portalWaitingforApproval').show();
                           $('#joinPortalContent,#portaljoinContent').hide();
                        }
                        else if("open" == data)
                        {
                            window.location.reload();
                        }
                        else
                        {
                            showTipper(i18n["zohodiscussions.widgetscontainer.failure"],'failure',1000);

                        }
                    }//success : function (data)
                });
            }
        });

    $('#joinButtonClick,#portalJoinButtonClick').click(function(){
        $('#signInorSignUp,#portalsignInorSignUp').toggle();
        $('#participateButtonClick,#portalparticipateButtonClick').toggle();
    });
    $('#signInClick,#participateButtonClick').click(function()
    {
        if("portalBut" == this.className)
        {
            $('#portalSignUpClick').attr('action',$(this).attr('action'));
        }
         $('#iamLoginBox').show();
         $('#joinPortalWidget,#portaljoinContent').hide();
         var currSrc = $(this).attr('src');
        $('#iamLoginBox iframe,#portaliamLoginBox iframe').attr('src',currSrc);
    });
    $('#signUpClick,#portalSignUpClick,#portalSignUpClickPopup').click(function()
    {
        var action=$(this).attr('action');
        location.href=action;
    });
}
function showall(cont,isCatg)
{
    var mode = $('#showAll').attr('currentmode');
    if(mode == "show")
    {
        $('#'+cont).removeAttr('style');
        $('#showAll').text(i18n["zohodiscussions.general.less"]);//No I18N
        $('#showAll').attr('currentmode','hide');
    }
    else
    {
        if(isCatg == "isCatg")
        {
            $('#'+cont).attr('style','min-height:40px;max-height:170px;overflow:hidden;');
        }
        else
        {
            $('#'+cont).attr('style','min-height:40px;max-height:230px;overflow:hidden;');
        }
        $('#showAll').text(i18n["zohodiscussions.general.more"]);//No I18N
        $('#showAll').attr('currentmode','show');
    }
    return false;
}
$(window.document).click(function(event)
{
    var $listOfOptins = $('#switchToProductOptions,#changePortalOptions');
    var $dropDownConts = $('#statusList,#typeFilterOptions');
    var $target = $(event.target);
    var $targetparent = $target.parent();
    if($target.is('[purpose="linkForDropDown"]') || $targetparent.is('[purpose="linkForDropDown"]') || $target.is('#statusInfo') || $targetparent.is('#statusContainer') || $target.is('#statusContainer'))
    {
        var dropDownPurpose = $target.attr('dropDownLinkPurpose');
        dropDownPurpose = dropDownPurpose || $targetparent.attr('dropDownLinkPurpose');
        $dropDownConts.each(function(index, item)
        {
            var $item = $(item);
            if(typeof dropDownPurpose == "undefined" && $item.is('#statusList'))
            {
                if(($('#statusInfo').find('div.statuschanges')).length > 0  || ($('#statusContainer').find('b.imgdownArrow')))
                {
                    if($('#statusList').is(':visible'))
                    {
                        $item.hide();
                    }
                    else
                    {
                       $item.show();
                    }
                }
            }
            else if($item.is('div[dropDownPurpose!="'+dropDownPurpose+'"]:visible'))
            {
                $item.hide();
                $item.parent('.newComboSelected').addClass('newCombo').removeClass('newComboSelected');//No I18N
            }

        });
        return false;
    }
    else
    {
        $dropDownConts.hide();
        $dropDownConts.parent('.newComboSelected').addClass('newCombo').removeClass('newComboSelected');//No I18N
    }
});
$(window.document).keypress(function (e)
{
    var $dropDownConts = $('#statusList,#typeFilterOptions,#privateConversation');
    var $conboCont = $('#portalComboCont');
    if(e.keyCode == 27)
    {
        $('#messageContainer').hide();
        $('#authorPopout:visible').hide();
        $('#PopupContainer div.dimDiv:visible button:visible[purpose="closePopout"]').trigger('click');
        if($('#PopupContainer div.dimDiv:visible div:visible[purpose="imgCancel"]'))
        {
            $('#imgCancel').trigger('click');
        }
        if($dropDownConts.is(':visible'))
        {
            $dropDownConts.hide();
        }
        if($conboCont.is('.newComboSelected'))
        {
            $conboCont.addClass('newCombo').removeClass('newComboSelected');
        }
        if($('#privateMsgPrompt').is(':visible'))
        {
            $('#privateMsgPrompt').parent().hide();
        }
        if($('#inappropriateReason').is(':visible'))
        {
            $('#inappropriateReason').hide(); //No I18N
        }
        return false;
    }
});
function initTopicsPageActions()
{
    lightBox('#chartWidget');//No I18N
    lightBox('#topicList');//No I18N
    bindTopicClicks($('#topicList'));
    bindTopicClicks($('#topicsList'));
    bindTopicListHeaderClicks($('#topicListHeader'));
    bindWidgetsContClick($('#topicListWidgetsCont'));
    if(isMac == "false")
    {
        setToHotkeys();
    }
}
function newTopicCall()
{
    initLoginFrame($('#NewTopicTab'));
}
function initLoginFrame($target)
{
    var $loginFrame = $('#loginFrame');
    hideLoadingImage();
    var iamLogin = $target.attr('iamURL');
    if($loginFrame.size() > 0)
    {
        $loginFrame.show().find('div.iFrameContainer').show().html('<iframe scrolling="no" frameborder="0" height="192px" src="'+iamLogin+'"></iframe>');
        $('#iamLoginBox').hide();
    }
    var $listof_FC_Counts = $('#listof_FC_Counts');
    $('#countOfForum').html($listof_FC_Counts.attr('forumCount'));
    $('#countOfCategory').html($listof_FC_Counts.attr('categoryCount'));
    $('#countOfPosts').html($listof_FC_Counts.attr('postCount'));
    $('#countOfResponses').html($listof_FC_Counts.attr('responseCount'));
    var $tploginforms = $('#tploginforms');
    var loginServiceUrl = $target.attr('loginURL');
    var loginIamUrl = $target.attr('iamURL');
    $tploginforms.find('input[name="serviceurl"]').val(loginServiceUrl);
    $tploginforms.find('input[name="domain"]').val(loginIamUrl);
    return false;
}
function loginBoxClose()
{
    $('#iamLoginBox').show();
    if($('#joinPortalWidget').size() > 0)
    {
        $('#joinPortalWidget').show();
         $('#iamLoginBox').hide();
    }
    $('#loginFrame').hide();
    initTopicsPageActions();
}
function signInViaGoogle()
{
    $('#tploginforms').find('form[name="googleform"]').submit();
    return false;
}
function signInViaYahoo()
{
    $('#tploginforms').find('form[name="yahooform"]').submit();
    return false;
}
function signInViaFacebook()
{
    $('#tploginforms').find('form[name="fbform"]').submit();
    return false;
}
function signInViaGoogleApps()
{
    $('#tploginforms').find('form[name="gappsform"]').submit();
    return false;
}
function forumGroupNameDecode(forumGroupName)
{
    var count = forumGroupName.split('&#39;').length-1;
    for(var incr = 0; incr < count; incr++ )
    {
        forumGroupName = forumGroupName.replace('&#39;','/\'');
    }
    return forumGroupName;
}
