﻿

PB = {

	loader: null,
	autocomplete: null,
	autocomplete2: null,
	autocomplete3: null,
	data: null,
	keywords: null,
	datasource: null,
	datasource2: null,
	datasource3: null,
	init: function() {

		Dom.addClass(document.body, 'yui-skin-sam');

		//this.loader = new YAHOO.util.YUILoader();

		//this.loader.insert({
		//	require: ['autocomplete', 'json', 'connection'],
		//	onFailure: function() { alert('Failed to Initialize'); },
		//	scope: this,
		//	onSuccess: this.build
		//});

		this.build();

	},

	build: function() {

		var callback =
		{
			scope: this,
			success: function(o) {
				if (o.responseText !== null) {
					this.keywords = YAHOO.lang.JSON.parse(o.responseText);

					// Use a LocalDataSource
					this.datasource3 = new YAHOO.util.LocalDataSource(this.keywords);


					// Optional to define fields for single-dimensional array
					this.datasource3.responseSchema = { fields: ["Keyword"] };

					// Instantiate the AutoComplete
					this.autocomplete3 = new YAHOO.widget.AutoComplete("keyword", "keywordContainer", this.datasource3);
					this.autocomplete3.prehighlightClassName = "yui-ac-prehighlight";
					this.autocomplete3.useShadow = true;
					this.autocomplete3.useIFrame = true;
					this.autocomplete3.allowBrowserAutocomplete = false;
				}
			}
		};

		var callback2 =
		{

			scope: this,

			success: function(o) {

				if (o.responseText !== null) {
					this.data = YAHOO.lang.JSON.parse(o.responseText);

					// Use a LocalDataSource
					this.datasource = new YAHOO.util.LocalDataSource(this.data);
					//this.datasource2 = new YAHOO.util.LocalDataSource(this.data);

					// Optional to define fields for single-dimensional array
					this.datasource.responseSchema = { fields: ["familyName"] };
					//this.datasource2.responseSchema = { fields: ["givenName"] };

					// Instantiate the AutoComplete
					this.autocomplete = new YAHOO.widget.AutoComplete("familyName", "lastNameContainer", this.datasource);
					this.autocomplete.prehighlightClassName = "yui-ac-prehighlight";
					this.autocomplete.useShadow = true;
					this.autocomplete.useIFrame = true;
					this.autocomplete.allowBrowserAutocomplete = false;

					/*this.autocomplete2 = new YAHOO.widget.AutoComplete("givenName", "firstNameContainer", this.datasource2);
					this.autocomplete2.prehighlightClassName = "yui-ac-prehighlight";
					this.autocomplete2.useShadow = true;
					this.autocomplete2.useIFrame = true;
					this.autocomplete2.allowBrowserAutocomplete = false;*/


				}
			}
		};

		var callback3 =
		{

			scope: this,

			success: function(o) {

				if (o.responseText !== null) {
					this.data = YAHOO.lang.JSON.parse(o.responseText);

					// Use a LocalDataSource
					//this.datasource = new YAHOO.util.LocalDataSource(this.data);
					this.datasource2 = new YAHOO.util.LocalDataSource(this.data);

					// Optional to define fields for single-dimensional array
					//this.datasource.responseSchema = { fields: ["familyName"] };
					this.datasource2.responseSchema = { fields: ["givenName"] };

					// Instantiate the AutoComplete
					/*this.autocomplete = new YAHOO.widget.AutoComplete("familyName", "lastNameContainer", this.datasource);
					this.autocomplete.prehighlightClassName = "yui-ac-prehighlight";
					this.autocomplete.useShadow = true;
					this.autocomplete.useIFrame = true;
					this.autocomplete.allowBrowserAutocomplete = false;*/

					this.autocomplete2 = new YAHOO.widget.AutoComplete("givenName", "firstNameContainer", this.datasource2);
					this.autocomplete2.prehighlightClassName = "yui-ac-prehighlight";
					this.autocomplete2.useShadow = true;
					this.autocomplete2.useIFrame = true;
					this.autocomplete2.allowBrowserAutocomplete = false;


				}
			}
		};
		var cObj2 = YAHOO.util.Connect.asyncRequest('POST', '/AutoComplete.asp?action=keywords', callback);
		var cObj3 = YAHOO.util.Connect.asyncRequest('POST', '/AutoComplete.asp?action=givenname', callback3);
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/AutoComplete.asp?action=familyname', callback2);
	}
}

Event.onDOMReady(PB.init, PB, true);