VS.WordSearch = { 
	dataSource:null, 
	autoComplete:null,
	init:function(){ 
		E.addListener('AddWordGo','click',this.Listeners.RequestAddWord); 
		
		this.dataSource = new YAHOO.util.XHRDataSource("/words/search/autocomplete");

    // Use an XHRDataSource
    // Set the responseType
    this.dataSource.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT;
    // Define the schema of the delimited results
    this.dataSource.responseSchema = {
        recordDelim: "\n",
        fieldDelim: "\t"
    };
    // Enable caching
    this.dataSource.maxCacheEntries = 5;

    // Instantiate the AutoComplete
    this.autoComplete = new YAHOO.widget.AutoComplete("WordSearchQuery", "AutoCompleteResults", this.dataSource);
    this.autoComplete.queryQuestionMark = false; 
		this.autoComplete.generateRequest = function(sQuery) {
		    return "/" + sQuery;
		};

		
	},
	Listeners:{ 
		RequestAddWord:function(){ 
			var word = $('AddWordWord').value; 
			var list = $('ChooseWordList').value; 
					var txn = YAHOO.util.Connect.asyncRequest('POST', 
																							'/quality/report/type/word', 
																							{success:function(){ } ,failure:function(){ } },
																							'reason=5&comment=User searched for word '+word+' and suggested it be added as VocabSushi word. They selected the word list '+list); 
			$('AddWordBox').innerHTML = '<h2>Add '+word+' to VocabSushi</h2>'
																	+'Thanks for the suggestion! We\'ll take a look at "'+word
																	+'" and if it\'s a good vocab word, add it to VocabSushi!'; 
		} 
	} 
	
} 
VS.Init.initThese[VS.Init.initThese.length] = 'WordSearch';

