
/**
 * Provides suggestions for committee names.
 * @class
 * @scope public
 */
/**
 * Request suggestions for the given autosuggest control. 
 * @scope protected
 * @param oAutoSuggestControl The autosuggest control to provide suggestions for.
 */
AllComSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl /*:AutoSuggestControl*/,
                                                          bTypeAhead /*:boolean*/) {
    var aSuggestions = [];
	var aSuggestionsLink = [];
    var sTextboxValue = oAutoSuggestControl.textbox.value;
    
    if (sTextboxValue.length > 0){
    
        //convert value in textbox to lowercase
        var sTextboxValueLC = sTextboxValue.toLowerCase();

        //search for matching committees
        for (var i=0; i < this.committees.length; i++) { 

            //convert committee name to lowercase
            var sComLC = this.committees[i].toLowerCase();
           
            //compare the lowercase versions for case-insensitive comparison
            if (sComLC.indexOf(sTextboxValueLC) >= 0) {
				aSuggestions.push(this.committees[i]);
				aSuggestionsLink.push(this.urls[i]);
            } 
        }
    }

    //provide suggestions to the control
    //oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
    oAutoSuggestControl.autosuggest(aSuggestions,aSuggestionsLink, false);
};

AllComSuggestions.prototype.requestSuggestionLinks = function (oAutoSuggestControl /*:AutoSuggestControl*/) {
    var aSuggestions = "";
    var sTextboxValue = oAutoSuggestControl.textbox.value;
    var bOdd = true;
	var sJustOneURL = "";
	
    if (sTextboxValue.length > 0){
    
        //convert value in textbox to lowercase
        var sTextboxValueLC = sTextboxValue.toLowerCase();

        //search for matching committees
        for (var i=0; i < this.committees.length; i++) { 

            //convert committee name to lowercase
            var sComLC = this.committees[i].toLowerCase();
           
            //compare the lowercase versions for case-insensitive comparison
            if (sComLC.indexOf(sTextboxValueLC) >= 0) {
				if (sJustOneURL == "") {
					sJustOneURL = this.urls[i];
				} else {
					sJustOneURL = "na";
				}
				if (bOdd) {
					aSuggestions += "<div class='committee_name_odd'><a href='" + this.urls[i] + "'>" + this.committees[i]+ "</a></div>";
					bOdd = false;
				} else {
					aSuggestions += "<div class='committee_name_even'><a href='" + this.urls[i] + "'>" + this.committees[i]+ "</a></div>";
					bOdd = true;
				}
            } 
        }
		if (sJustOneURL != "" && sJustOneURL != "na") {
			oAutoSuggestControl.textbox.value = "";  //clear the criteria field to avoid infinite loop on clicking "Back" button
			document.location = sJustOneURL;
			aSuggestions = "";
		}
		if (aSuggestions.length > 0) {
			aSuggestions = "<div class='committee_name_head'><b>委員會</b></div>" + aSuggestions;
		}
    }
	return aSuggestions;
}


