var arOutputKeys = [];
var arOutputValues = [];
var bGetValues = false;
var bTypeAhead = false;
var bLocalTypeAhead = false;

function handleSearchSuggest(sStrIn) {
	eval(sStrIn);
	if (bGetValues) {
		oTextbox.provider.names = arOutputValues;
		oTextbox.provider.requestSuggestions(oTextbox, bLocalTypeAhead);
	}
}

function getPostParameters(sValue){
    var poststr = "sSearch=" + encodeURI(sValue);
	return poststr;
}
	
function ForenameSuggestions() {
	this.names = [];
}

ForenameSuggestions.prototype.requestSuggestions = function(oAutoSuggestControl /*:AutoSuggestControl*/,
                                                          bTypeAhead /*:boolean*/) {
    var aSuggestions = [];
    var sTextboxValue = oAutoSuggestControl.textbox.value;

    if (sTextboxValue.length > 0) {

        //search for matching names

        for (var i = 0; i < this.names.length; i++) {
            if (this.names[i].toLowerCase().indexOf(sTextboxValue.toLowerCase()) === 0) {
                aSuggestions.push(this.names[i]);

            }
        }
    }
    //provide suggestions to the control
    oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
};

ForenameSuggestions.prototype.populateSuggestions = function(oAutoSuggestControl /*:AutoSuggestControl*/,
																	bAsynch /*:boolean*/) {
    oTextbox = oAutoSuggestControl;
    bGetValues = true;

    var sInput = oAutoSuggestControl.textbox;

    if (sInput.value.length < 2) {
        bGetValues = false;
    }

    if (bGetValues === true) {
        var sValue = sInput.value;
        if (sValue.indexOf(' - ') > 0) {
            sValue = sValue.substr(0, sValue.indexOf(' - '));
        }
        var path = '/Suggest.ashx?WCI=SuggestForenames&member_key=0&' + 'sSearch=' + encodeURI(sValue);
        $.get(path, handleSearchSuggest);
    }
};
	
function SurnameSuggestions() {
	this.names = [];
}

SurnameSuggestions.prototype.requestSuggestions = function(oAutoSuggestControl , bTypeAhead ) {
    var aSuggestions = [];
    var sTextboxValue = oAutoSuggestControl.textbox.value;

    if (sTextboxValue.length > 0) {
        for (var i = 0; i < this.names.length; i++) {
            if (this.names[i].toLowerCase().indexOf(sTextboxValue.toLowerCase()) === 0) {
                aSuggestions.push(this.names[i]);

            }
        }

        oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
    }
};

SurnameSuggestions.prototype.populateSuggestions = function(oAutoSuggestControl ,bAsynch ) {
    oTextbox = oAutoSuggestControl;
    bGetValues = true;

    var sInput = oAutoSuggestControl.textbox;

    if (sInput.value.length < 2) {
        bGetValues = false;
    }

    if (bGetValues === true) {
        var sValue = sInput.value;
        if (sValue.indexOf(' - ') > 0) {
            sValue = sValue.substr(0, sValue.indexOf(' - '));
        }
        var path = '/Suggest.ashx?WCI=SuggestSurnames&member_key=0&' + 'sSearch=' + encodeURI(sValue);
        $.get(path, handleSearchSuggest);
    }
};
