function SearchDialog() {
	this.openerId = 'searchButton';
	this.dialogId = 'search-dlg';
	YAHOO.util.Event.addListener(window, 'load', this.initialize, this, true);
}

SearchDialog.prototype = {
	
	dialogId : null,
	
	openerId : null,
	
	dialog : null,
	
	showBtn : null,
	
	initOpen : false,
	
	initialize : function() {
		 this.showBtn = getEl(this.openerId);
		 YAHOO.util.Event.addListener(this.openerId, 'click', this.showDialog, this, true);
		 YAHOO.util.Event.addListener('ClassID', 'change', this.getResultCount, this, true);
		 YAHOO.util.Event.addListener('ServerTypeID', 'change', this.getResultCount, this, true);
		 YAHOO.util.Event.addListener('Level', 'change', this.getResultCount, this, true);
		 YAHOO.util.Event.addListener('SubmittedBy', 'keyup', this.getResultCount, this, true);
		 YAHOO.util.Event.addListener('keywords', 'keyup', this.getResultCount, this, true);
	},
	
	showDialog : function(){
	    if(!this.dialog){ // lazy initialize the dialog and only create it once
	        this.dialog = new YAHOO.ext.LayoutDialog(this.dialogId, { 
	                width:460,
                    height:250,
                    shadow:true,
                    minWidth:460,
                    minHeight:250,
                    center: {
                        autoScroll:true,
                        tabPosition: 'top',
                        closeOnTab: true,
                        alwaysShowTabs: true
                    }
	        });
	        this.dialog.addKeyListener(27, this.dialog.hide, this.dialog);
	        this.dialog.addButton('Close', this.dialog.hide, this.dialog);
			this.dialog.addButton('View Results', this.searchTemplates, this);
			
			var layout = this.dialog.getLayout();
	        this.dialog.beginUpdate();
			
			var infoTab = new YAHOO.ext.ContentPanel('templateSearchTab', {title: 'Template Search'});
			layout.add('center', infoTab);
			layout.getRegion('center').showPanel('templateSearchTab');
	        this.dialog.endUpdate();
	    }
		
	    this.dialog.show(this.showBtn.dom);
	},
	
	searchTemplates : function() {
		document.getElementById('searchForm').submit();
	},
	
	getResultCount : function() {
		var callback = {
			success: function(response) {
				document.getElementById('resultCountDiv').innerHTML = 'Matching Results: ' + response.responseText;
			},
			failure: function(response) {
				
			},
			scope: this
		}
		YAHOO.util.Connect.setForm(document.getElementById('searchForm'));
		document.getElementById('resultCountDiv').innerHTML = YAHOO.ext.UpdateManager.defaults.indicatorText;
		var transaction = YAHOO.util.Connect.asyncRequest('GET', 'ajaxRequests.php', callback);
	}
	
}
