/**
 * @author George Miller
 */
Ext.onReady(function(){
	 Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';
		   var form = new Ext.form.FormPanel({
		frame: true,
        bodyStyle:'padding:5px',
        labelAlign: 'top',
		waitMsgTarget: true,
		height: 320,
		width: 400,
        url:'includes/call_process.php',
        defaultType: 'textfield',
        items: [{
            fieldLabel: 'Your Name',
            name: 'name',
            anchor:'40%',
			allowBlank: false  // anchor width by percentage
        }, {
		fieldLabel: 'Telephone',
            name: 'telephone',
            anchor: '40%',
			allowBlank: false // anchor width by percentage and height by raw adjustment
        },{
			name: 'uid',
			fieldLabel: 'Unique Reference Number(if applicable)',
			anchor: '40%'
		},{
			xtype: 'radio',
			name: 'day',
			boxLabel: 'Today',
			checked: true,
			fieldLabel: 'What day would you like us to phone you',
			inputValue: 'today'
		},{
			xtype: 'radio',
			name: 'day',
			boxLabel: 'Tomorrow',
			hideLabel: true,
			inputValue: 'tomorrow'
		},{
			xtype: 'timefield',
			name: 'time',
			allowBlank: false,
			fieldLabel: 'Select a time for us to call',
			anchor: '30%',
			maxValue: '8:00 PM',
			minValue: '8:00 AM'
		}],
		        buttons: [{
            text: 'Send',
			handler: function(){
				if(form.form.isValid()){
					Ext.MessageBox.show({
           msg: 'Sending your request, please wait...',
           progressText: 'Sending...',
           width:310,
           wait:true,
           waitConfig: {interval:200},
           icon:'ext-mb-tel'
       });
			form.form.submit({
				params:{
					action:'submit'
					},
					success:function(form, action){
						  
            //This simulates a long-running operation like a database save or XHR call.
            //In real code, this would be in a callback function.
            Ext.MessageBox.hide();
			Ext.MessageBox.show({
           title: 'Call Enquiry',
		   msg: 'Your call request was sent,<br>an agent will call you at the time specified',
           width:300,
		   buttons: Ext.MessageBox.OK,
           icon:'ext-mb-tel'
       });
        
			form.reset();
					//
					    },
					failure:function(form, action){
						if(action.result.msg.length > 0){
						 Ext.MessageBox.show({
           title: 'Form Error',
		   msg: action.result.msg,
           width:300,
		   buttons: Ext.MessageBox.OK,
           icon: 'ext-mb-warning'
       });
						}
					}
			});
		}else{
			Ext.MessageBox.show({
           title: 'Form Error',
		   msg: 'Please correct the indicated errors',
           width:300,
		   buttons: Ext.MessageBox.OK,
           icon: 'ext-mb-warning'
       });
		}
        }
		},{
            text: 'Cancel',
			handler: function(){
			form.form.reset();
			}
        }]
    });
 var win = new Ext.Window({
 	title: 'Organise a time for us to call you back'
	,items: form
	,renderTo: 'form'
	 ,width:400
        ,id:'agwin'
        ,height:340
        ,layout:'fit'
        ,border:false
		,plain:true
        ,closable:false
 });
 win.show();
});
