/*
 * Ext JS Library 2.2
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
	
Ext.onReady(function(){
	
	Ext.QuickTips.init();
	 
	// reference local blank image
	Ext.BLANK_IMAGE_URL = '../../../js/ext-2.2/resources/images/default/s.gif';

	var box_id = 1;
	
   	var sidebar_form = new Ext.FormPanel({
    width: 450,
    height: 480,
    frame: true,
    region: 'center',
    id: 'sidebar_form', 
	//frame:true,
	 url: location.href,
   // autoHeight: true,
    bodyStyle: 'padding: 10px 10px 10px 10px;',
    items: [{
            xtype:'fieldset',
            title: 'Appointment Phone Number',
            collapsible: false,
            autoHeight:true,
            defaults: {width: 210},
            defaultType: 'textfield',
            items :[{
                    fieldLabel: 'Title',
                    name: 'box_appt_title'
                },{
                    fieldLabel: 'Number',
                    name: 'box_appt_number'
                }
            ]
    	},{
            xtype:'fieldset',
            checkboxToggle:true,
            id:'box_online_display',
            title: 'Online Appointment Request Form',
            collapsed: true,
            autoHeight:true,
            defaults: {width: 210},
            defaultType: 'textfield',
            items :[{
                    fieldLabel: 'Title',
                    name: 'box_online_title'
                },{
                   	xtype:'textarea',
                    fieldLabel: 'Content',
                    name: 'box_online_text'
                }
            ]
        },{
            xtype:'fieldset',
            title: 'Library',
            collapsible: false,
            autoHeight:true,
            defaults: {width: 210},
            defaultType: 'textfield',
            items :[{
                    fieldLabel: 'Title',
                    name: 'box_library_title'
                },{
                   	xtype:'textarea',
                    fieldLabel: 'Content',
                    name: 'box_library_text'
                }
            ]
        }
    ],
	buttons: [{
        text: 'Save', 
        handler: function() {
            // check form value 
            if (sidebar_form.getForm().isValid()) {
 		        sidebar_form.getForm().submit({
					params: {box_id:1,box_delete:0,cmd:'save',edit_boxes:1},
		            //waitMsg:'In processing',
		            failure: function(form, action) {
					    Ext.MessageBox.alert('Error Message', action.result.errorInfo);
					},
					success: function(form, action) {
					    //Ext.MessageBox.alert('Confirm', action.result.info);
					    sidebar_window.hide();
					    location=location.href;
					}
		        });                   
            } else{
				Ext.MessageBox.alert('Errors', 'Please fix the errors noted.');
			}             
        }
    },{
        text: 'Cancel',
        //handler: function(){window.hide();}
        handler: function()
        {
        	sidebar_window.hide();
        	//location=location.href;
        }
    }],
    listeners:{
		actioncomplete:function(o,a){
			if(a.result.data.box_online_display==1)
    			Ext.getCmp("box_online_display").expand();
		}
	}
 });

     
/*
 * ================  BorderLayout config  =======================
 */

    // define window and show it in desktop
    var sidebar_window = new Ext.Window({
        title: 'Sidebar',
        width: 500,
        height:500,
        minWidth: 500,
        minHeight: 500,
        animate:true,
        frame: true,
        //minHeight: 250,
        layout: 'border',
        plain:true,
        closeAction:'hide',
        bodyStyle:'padding:5px;',
        buttonAlign:'center',
        id:'sidebar_window',
    	items:[sidebar_form]
    });
	//////////////////////////////
	 	sidebar_window.show(); 
		sidebar_window.hide();
	//////////////////////////////
});
		
function show_boxes_window()
{
 	Ext.getCmp("sidebar_window").show(); 

	Ext.getCmp("sidebar_form").load({
			url:location.href,
			failure:function(){Ext.getCmp("sidebar_form").getForm().reset();},
			method: 'post',
			params: {box_id:box_id,cmd:'load',edit_boxes:1}
		});	
}



