	Ext.namespace('EquipmentRental.Settings');
	
	// --------------------------------------------------------
   	//		SETTINGS FORM 	
   	//---------------------------------------------------------
   	EquipmentRental.Settings.Form = Ext.extend(Ext.form.FormPanel, {	    	
	     	border:false
		,frame:true
		,labelWidth:80
		,url:'http://'+host+'/settings/save'	
		,id:'settingsForm'
		,constructor:function(config) {
			config = config || {};
			config.listeners = config.listeners || {};
			Ext.applyIf(config.listeners, {
				actioncomplete:function() {
					if(typeof console!='undefined') {
						console.log('actioncomplete:', arguments);
					}
				}
				,actionfailed:function() {
					if(typeof console!='undefined') {
						console.log('actionfailed:', arguments);
					}
				}
			});
			EquipmentRental.Settings.Form.superclass.constructor.call(this, config);
		}

	    ,initComponent:function() {		
			
			var config = {
				 defaultType:'textfield'
				,defaults:{anchor:'-24'}
				,monitorValid:true
				,autoScroll:true		
				,items: [{				   
				    collapsible: true
				    ,title: 'Company Info'			  
				    ,defaultType: 'textfield'				    
				    ,autoHeight:true	
				    ,xtype:'fieldset'
				    ,items: [{
				    		 layout:'column'
				    		 ,xtype:'panel'
				    		 ,border:true    		 	    		 
				    		 ,items:[{
							columnWidth:.5	
							,layout: 'form'	
							,defaultType: 'textfield'				
							,items: [{							    
							    fieldLabel: 'Name',
							    name: 'company_name',
							    anchor:'95%'
							}, {							    
							    fieldLabel: 'Phone',
							    name: 'company_phone',
							    anchor:'95%'
							}, {							    	
							    	name:'company_fax'
								,fieldLabel:'Fax'
								,anchor:'95%'
							}, {
								name:'company_email'
								,fieldLabel:'E-mail'
								,vtype:'email'					
								,allowBlank:false
								,anchor:'95%'
							},{
							   	name:'company_address_1'
								,fieldLabel:'Address 1'
								,anchor:'95%'
							}]
						    },{
							columnWidth:.5	
							,layout: 'form'	
							,defaultType: 'textfield'					
							,items: [{
							    	 name:'company_address_2'
								,fieldLabel:'Address 2'
								,anchor:'95%'
							},{
							    	 name:'company_city'
								,fieldLabel:'City'
								,anchor:'95%'
							},{
							    	name:'company_state'
								,fieldLabel:'State'
								,anchor:'95%'
							},{
							    	 name:'company_zip'
								,fieldLabel:'Zip'
								,anchor:'95%'
							},{
							    	name:'company_country'
								,fieldLabel:'Country'
								,anchor:'95%'
							}]					    
						}]
					}]
				},{
				    xtype:'fieldset'
				    ,title: 'Invoice Info'
				    ,collapsible: true
				    ,autoHeight:true
				    ,width:'100%'
				    ,items :[
					{
					    fieldLabel: 'Sale Tax'
					    ,name: 'sale_tax'
					    ,xtype:'textfield'
					    ,anchor:'98%'					
				    	}	
				    ]
				},{
				    xtype:'fieldset'
				    ,title: 'Admin Account Info'
				    ,collapsible: true
				    ,autoHeight:true
				    ,width:'100%'				    
				    ,items :[{layout:'column'
				    		 ,xtype:'panel'
				    		 ,border:true    		 	    		 
				    		 ,items:[{
							columnWidth:.5	
							,layout: 'form'	
							,defaultType: 'textfield'				
							,items: [{							    
							     fieldLabel: 'Username'
							    ,name: 'admin_username'
							    ,xtype:'textfield'
							    ,anchor:'98%'
							}]
						    },{
						    	columnWidth:.5	
							,layout: 'form'	
							,defaultType: 'textfield'				
							,items: [{							    
							    fieldLabel: 'Password'
							    ,name: 'admin_password'
							    ,xtype:'textfield'
							    ,anchor:'98%'	
							}]
						    }]
					    				
				    }]
				}]
				,buttons:[{
					 text:'Save'
					,formBind:true
					,scope:this
					,handler:this.submit
					,iconCls:'btn-save'
				}]
			}; 

			
		Ext.apply(this, Ext.apply(this.initialConfig, config));

		// call parent
		EquipmentRental.Settings.Form.superclass.initComponent.apply(this, arguments);
		
		// add custom events
        	this.addEvents('saved');
        	
        	 		
	 
	    }
	    
	    ,onRender:function() {
	 
		// call parent
		EquipmentRental.Settings.Form.superclass.onRender.apply(this, arguments);

		
		this.getForm().waitMsgTarget = this.getEl();
		
		this.load({
			 url:this.url
			 ,waitMsg:'Loading...'
 		});
	 
	    } 		
		
		,submit:function() {			
	
			this.getForm().submit({
				 url:this.url
				,scope:this
				,success:this.onSuccess
				,failure:this.onFailure				
				,waitMsg:'Saving...'
			});
	
		}
		
		,onSuccess:function(form, action) {
			Ext.Msg.show({				
				 title:'Success'
				,scope:this 
				,msg:'Data has been saved'
				,modal:true
				,fn: this.onSuccessProcessResult
				,icon:Ext.Msg.INFO
				,buttons:Ext.Msg.OK
			});
										
		} 
		
		, onSuccessProcessResult: function(buttonId, text){
			if(buttonId=='ok'){
				this.fireEvent('saved');	
			}
			
		}
		
		,onFailure:function(form, action) {
			var responseObj=Ext.decode(action.response.responseText);
			
			this.showError(action.result.error || responseObj.errormsg);
			
		} 
	
		
		,showError:function(msg, title) {
			title = title || 'Error';
			Ext.Msg.show({
				 title:title
				,msg:msg
				,modal:true
				,icon:Ext.Msg.ERROR
				,buttons:Ext.Msg.OK
			});
		} 
	 
	}); // eo extend
	
	
// register xtype
Ext.reg('settingsForm', EquipmentRental.Settings.Form);
