
/**
 * Provides suggestions for development names.
 * @class
 * @scope public
 */
function RemoteModelSuggestions(tag_type) {

	this.http = createHTTPRequest();
	this.tag_type = tag_type;
	this.mutex = 0;

}

/**
 * Request suggestions for the given autosuggest control. 
 * @scope protected
 * @param oAutoSuggestControl The autosuggest control to provide suggestions for.
 */
RemoteModelSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl /*:AutoSuggestControl*/,
                                                          bTypeAhead /*:boolean*/) {
	var me = this;

	//if there is already a live request, cancel it
	if (me.mutex == 1)
	{
		me.http.abort();
		me.http = createHTTPRequest();
		me.mutex = 0;
	}
	me.mutex = 1;
	//build the URL
	//alert(type);
	var sURL = "ajax/suggestions.php?userInput=" + encodeURIComponent(oAutoSuggestControl.textbox.value) + "&tag_type=" + encodeURIComponent(this.tag_type);
	
	//open connection to states.txt file
	me.http.open("get", sURL , true)
	
	me.http.onreadystatechange = function () {
		try
		{
			if (me.http.readyState == 4) {
				if (me.http.status == 200) {
					//evaluate the returned text JavaScript (an array)
					var aSuggestions = eval(me.http.responseText);
				
					//provide suggestions to the control
					oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
				}
				me.mutex = 0;
			}   
		}
		catch(ex)
		{
		//ignore errors
		}
	};
	
	me.http.send(null);

};

function createHTTPRequest() {
	var http = null;
	if (typeof XMLHttpRequest != "undefined") {
		http = new XMLHttpRequest();
	} else if (typeof ActiveXObject != "undefined") {
		http = new ActiveXObject("MSXML2.XmlHttp");
	}
	return http;
}
