﻿var keywordMgr =
{
    showDescription: true,

    Init: function(letter) {
        keywordMgr.GetKeywordsByLetter(letter);
    },

    GetKeywordsByLetter: function(letter, link) {
        if (!link) {
            link = document.getElementById(letter);
        }

        // Unselect previously selected link
        $j('.selected').removeAttr('class');

        // select current link
        link.className = 'selected';

        ajaxHelper.ShowProgress('GetKeywordsByLetterHtml', 'keywordsDiv');
        
        SearchEngineService.GetKeywordsByLetterHtml(letter, this.showDescription, keywordMgr.GetKeywords_Complete);
    },

    GetKeywords_Complete: function(result) {
        if (result) {
            ajaxHelper.HideProgress('GetKeywordsByLetterHtml', result);
        }
    },

    // Adapted from namesake in SearchResults.js:
    // Toggles the display of all divs having the given className.  If param "spanId" is passed in, the text in the span is
    //      also toggled.
    // param "className": class whose divs to toggle
    // param "spanId": span whose text to toggle
    // param "property": searchManager property to toggle
    ToggleDisplayByClass: function(className, spanId, property) {
        // Get all divs
        var divs = document.getElementsByTagName('div');
        var wasShowing = this[property];

        for (i = 0; i < divs.length; i++) {
            if (divs[i].className == className)
            // toggle display
                divs[i].style.display = wasShowing ? 'none' : '';
        }

        if (spanId)
            document.getElementById(spanId).innerHTML = wasShowing ? 'הצג' : 'הסתר';

        this[property] = !wasShowing;
    }
}