if (!window.jqDCCAJAX)
    jqDCCAJAX = jQuery;

function handlepaging(ModuleId, thispageno, totalpages, hidePager, themeName) {
   
    idlbPrevText = jqDCCAJAX('div#dnn_ctr' + ModuleId + '_ModuleContent').find('a#PrevText');
    idlbPrevPrevPrevPrev = jqDCCAJAX('div#dnn_ctr' + ModuleId + '_ModuleContent').find('a#PrevPrevPrevPrev');
    idlbPrevPrevPrev = jqDCCAJAX('div#dnn_ctr' + ModuleId + '_ModuleContent').find('a#PrevPrevPrev');
    idlbPrevPrev = jqDCCAJAX('div#dnn_ctr' + ModuleId + '_ModuleContent').find('a#PrevPrev');
    idlbPrev = jqDCCAJAX('div#dnn_ctr' + ModuleId + '_ModuleContent').find('a#Prev');
    idlbCurrent = jqDCCAJAX('div#dnn_ctr' + ModuleId + '_ModuleContent').find('a#Current');
    idlbNext = jqDCCAJAX('div#dnn_ctr' + ModuleId + '_ModuleContent').find('a#Next');
    idlbNextNext = jqDCCAJAX('div#dnn_ctr' + ModuleId + '_ModuleContent').find('a#NextNext');
    idlbNextNextNext = jqDCCAJAX('div#dnn_ctr' + ModuleId + '_ModuleContent').find('a#NextNextNext');
    idlbNextNextNextNext = jqDCCAJAX('div#dnn_ctr' + ModuleId + '_ModuleContent').find('a#NextNextNextNext');
    idlbNextText = jqDCCAJAX('div#dnn_ctr' + ModuleId + '_ModuleContent').find('a#NextText');

    if (themeName != '_SkinDefault') {
    }
    else {
        //faq_jq_pager faq_pager<%=this.strThemeName%>
        idlbPrevText.removeClass('faq_pager_text' + themeName);
        idlbPrevPrevPrevPrev.removeClass('faq_pager' + themeName);
        idlbPrevPrevPrev.removeClass('faq_pager' + themeName);
        idlbPrevPrev.removeClass('faq_pager' + themeName);
        idlbPrev.removeClass('faq_pager' + themeName);
      //  idlbCurrent.removeClass('faq_pager_current' + themeName);
        idlbNext.removeClass('faq_pager' + themeName);
        idlbNextNext.removeClass('faq_pager' + themeName);
        idlbNextNextNext.removeClass('faq_pager' + themeName);
        idlbNextNextNextNext.removeClass('faq_pager' + themeName);
        idlbNextText.removeClass('faq_pager_text' + themeName);

        idlbPrevText.addClass('commandbutton');
        idlbPrevPrevPrevPrev.addClass('commandbutton');
        idlbPrevPrevPrev.addClass('commandbutton');
        idlbPrevPrev.addClass('commandbutton');
        idlbPrev.addClass('commandbutton');
        idlbCurrent.addClass('commandbutton');
        idlbNext.addClass('commandbutton');
        idlbNextNext.addClass('commandbutton');
        idlbNextNextNext.addClass('commandbutton');
        idlbNextNextNextNext.addClass('commandbutton');
        idlbNextText.addClass('commandbutton');
    }
    if (hidePager != 1) {
        idlbCurrent.parent('td').parent('tr').show();

        if (((thispageno - 4) <= 0) || ((thispageno - 4) > totalpages)) {
            idlbPrevPrevPrevPrev.hide();
        }
        else {
            idlbPrevPrevPrevPrev.show();
            idlbPrevPrevPrevPrev.html(thispageno - 4);
            idlbPrevPrevPrevPrev.data("PageNo", thispageno - 4);
        }
        if (((thispageno - 3) <= 0) || ((thispageno - 3) > totalpages)) {
            idlbPrevPrevPrev.hide();
        }
        else {
            idlbPrevPrevPrev.show();
            idlbPrevPrevPrev.html(thispageno - 3);
            idlbPrevPrevPrev.data("PageNo", thispageno - 3);
        }
        if (((thispageno - 2) <= 0) || ((thispageno - 2) > totalpages)) {
            idlbPrevPrev.hide();
        }
        else {
            idlbPrevPrev.show();
            idlbPrevPrev.html(thispageno - 2);
            idlbPrevPrev.data("PageNo", thispageno - 2);
        }
        if (((thispageno - 1) <= 0) || ((thispageno - 1) > totalpages)) {
            idlbPrev.hide();
            idlbPrevText.hide();
        }
        else {
            idlbPrev.show();
            idlbPrevText.show();
            idlbPrev.html(thispageno - 1);
            idlbPrev.data("PageNo", thispageno - 1);
        }

        if ((thispageno <= 0) || (thispageno > totalpages)) {
            idlbCurrent.hide();
        }
        else {
            idlbCurrent.show();
            idlbCurrent.html(thispageno);
            idlbCurrent.data("PageNo", thispageno);
        }
        if ((thispageno + 1) <= 0 || (thispageno + 1) > totalpages) {
            idlbNext.hide();
            idlbNextText.hide();
        }
        else {
            idlbNext.show();
            idlbNextText.show();
            idlbNext.html(thispageno + 1);
            idlbNext.data("PageNo", thispageno + 1);
        }
        if (((thispageno + 2) <= 0) || ((thispageno + 2) > totalpages)) {
            idlbNextNext.hide();
        }
        else {
            idlbNextNext.show();
            idlbNextNext.html(thispageno + 2);
            idlbNextNext.data("PageNo", thispageno + 2);
        }

        if (((thispageno + 3) <= 0) || ((thispageno + 3) > totalpages)) {
            idlbNextNextNext.hide();
        }
        else {
            idlbNextNextNext.show();
            idlbNextNextNext.html(thispageno + 3);
            idlbNextNextNext.data("PageNo", thispageno + 3);
        }

        if (((thispageno + 4) <= 0) || ((thispageno + 4) > totalpages)) {
            idlbNextNextNextNext.hide();
        }
        else {
            idlbNextNextNextNext.show();
            idlbNextNextNextNext.html(thispageno + 4);
            idlbNextNextNextNext.data("PageNo", thispageno + 4);
        }

        idlbPrevText.data("PageNo", thispageno - 1);
        idlbNextText.data("PageNo", thispageno + 1);
    }
    else {
        
        idlbCurrent.parent('td').parent('tr').hide();
    }
}

function ShowAllFAQExpanded(idModule, themename) {
    //close all Qs, select all open Qs
    var QuestionsToShow = jqDCCAJAX('div#dnn_ctr' + idModule + '_ModuleContent').find('td#dnn_ctr' + idModule + '_ViewFAQ_tdPlaceholder').find('div#faqRoot' + themename).find('div#faq' + themename).find('span[id^="QID"]').next('h2[opened="false"]');
    jqDCCAJAX(QuestionsToShow).each(function() {
        jqDCCAJAX(this).click();
    });
    return false;
}

function openQuestion(idModule, strQuestionOpen, themename) {
   
    if (strQuestionOpen.length > 0) {
        var QuestionToShow = jqDCCAJAX('div#dnn_ctr' + idModule + '_ModuleContent').find('td#dnn_ctr' + idModule + '_ViewFAQ_tdPlaceholder').find('div#faqRoot' + themename).find('div#faq' + themename).find('span#QID' + strQuestionOpen).next('h2').click();
        var destination = jqDCCAJAX(QuestionToShow).offset().top;
        jqDCCAJAX("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination }, 1100, function() {
            //jqDCCAJAX(QuestionToShow)
        });
    }
}
function openAllQuestion(idModule, themename, expandAllText, collapseText) {
    chkExpCollAll = "true";
    var idExpCollLink = jqDCCAJAX('div#dnn_ctr' + idModule + '_ModuleContent').find('td#dnn_ctr' + idModule + '_ViewFAQ_tdPlaceholder').find('span#faqExpColAll' + themename);
    if (jqDCCAJAX(idExpCollLink).html() == expandAllText) {
        jqDCCAJAX(idExpCollLink).html(collapseText);
        //close all Qs, select all open Qs
        var QuestionsToShow = jqDCCAJAX('div#dnn_ctr' + idModule + '_ModuleContent').find('td#dnn_ctr' + idModule + '_ViewFAQ_tdPlaceholder').find('div#faqRoot' + themename).find('div#faq' + themename).find('span[id^="QID"]').next('h2[opened="false"]');
        jqDCCAJAX(QuestionsToShow).each(function() {
            jqDCCAJAX(this).attr("mode", "closeall");
            jqDCCAJAX(this).click();
            jqDCCAJAX(this).removeAttr("mode");
        });
    }
    else {
        jqDCCAJAX(idExpCollLink).html(expandAllText);
        //open all Qs, select all closed Qs
        var QuestionsToShow = jqDCCAJAX('div#dnn_ctr' + idModule + '_ModuleContent').find('td#dnn_ctr' + idModule + '_ViewFAQ_tdPlaceholder').find('div#faqRoot' + themename).find('div#faq' + themename).find('span[id^="QID"]').next('h2[opened="true"]');
        jqDCCAJAX(QuestionsToShow).each(function() {
            jqDCCAJAX(this).attr("mode", "openall");
            jqDCCAJAX(this).click();
            jqDCCAJAX(this).removeAttr("mode");
        });
    }
    var destination = jqDCCAJAX(idExpCollLink).offset().top;
    jqDCCAJAX("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination }, 1100, function() {
        //jqDCCAJAX(QuestionToShow)
    });
    chkExpCollAll = "false";
    return false;
}

function addExpandCollapseButton(idModule, themename, expandCollapseAllText, bshowALLFaqExpanded)
  {
    var index = 0;
    var ExpCollText = expandCollapseAllText.split(":::");
    if (bshowALLFaqExpanded) {
        index = 1;
    }
    var idAddBefore = jqDCCAJAX('div#dnn_ctr' + idModule + '_ModuleContent').find('td#dnn_ctr' + idModule + '_ViewFAQ_tdPlaceholder').find('div#faqRoot' + themename);
    if (themename == '_SkinDefault') {
        jqDCCAJAX(idAddBefore).before('<div id="faqHeader' + themename + '"><span href="#" id="faqExpColAll' + themename + '" class="commandbutton">' + ExpCollText[index] + '</span></div>');
    }
    else {
        jqDCCAJAX(idAddBefore).before('<div id="faqHeader' + themename + '"><span href="#" id="faqExpColAll' + themename + '">' + ExpCollText[index] + '</span></div>');
    }
    jqDCCAJAX('div#dnn_ctr' + idModule + '_ModuleContent').find('td#dnn_ctr' + idModule + '_ViewFAQ_tdPlaceholder').find('span#faqExpColAll' + themename).click(function (event) { openAllQuestion(idModule, themename, ExpCollText[0], ExpCollText[1]) });
   }

