function TemplateAddDialog() {
	this.openerId = 'addTemplate';
	this.dialogId = 'addTemplate-dlg';
	YAHOO.util.Event.addListener(window, 'load', this.initialize, this, true);
}

TemplateAddDialog.prototype = {
	
	dialogId : null,
	
	openerId : null,
	
	dialog : null,
	
	showBtn : null,
	
	updateManager : null,
	
	initialize : function() {
		 this.showBtn = getEl(this.openerId);
		 YAHOO.util.Event.addListener(this.openerId, 'click', this.showDialog, 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:550,
                    height:450,
                    shadow:true,
                    minWidth:550,
                    minHeight:450,
                    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.submitButton = this.dialog.addButton('Save Template', this.saveTemplate, this);
			
			var layout = this.dialog.getLayout();
	        this.dialog.beginUpdate();
			
			var newUserTab = new YAHOO.ext.ContentPanel('newTemplateTab', {title: 'New Template'});
			this.updateManager = new YAHOO.ext.UpdateManager('newTemplateTab');
			layout.add('center', newUserTab);
			layout.getRegion('center').showPanel('newTemplateTab');
	        this.dialog.endUpdate();
	    }
	    this.dialog.show(this.showBtn.dom);
	},
	
	saveTemplate : function() {
		if(document.getElementById('addTemplateForm') != null) {
			this.postForm();			
		}else {
			this.dialog.hide();
		}
	},
	
	postForm : function() {
		
		var callback = {
			upload : function(response) {
				this.dialog.getLayout().getRegion('center').getActivePanel().setContent(response.responseText);
			},
			failure: function(response) {
				
			},
			scope: this
		}
		YAHOO.util.Connect.setForm(document.getElementById('addTemplateForm'), true);
		YAHOO.util.Connect.asyncRequest('POST', 'ajaxRequests.php', callback);
		this.dialog.getLayout().getRegion('center').getActivePanel().setContent(YAHOO.ext.UpdateManager.defaults.indicatorText);
	}
	
}