// JavaScript Document

Ext.onReady(function(){

Ext.get('mailLnk').on('click', function(){

		   var form = new Ext.form.FormPanel({

        baseCls: 'x-plain',

        labelAlign: 'top',

		waitMsgTarget: true,

        url:'includes/news_process.php',

        defaultType: 'textfield',

        items: [{

            fieldLabel: 'Your Name',

            name: 'name',

            anchor:'100%',

			allowBlank: false  // anchor width by percentage

        }, {

		fieldLabel: 'Email Address',

            name: 'email',

            anchor: '100%',

			vtype: 'email',

			allowBlank: false // anchor width by percentage and height by raw adjustment

        }]

    });

    var window = new Ext.Window({

        title: 'Subscribe to our newsletter',

        width: 400,

        height:180,

        minWidth: 300,

        minHeight: 180,
		
		constrain: true,

        layout: 'fit',

		id: 'fWin',

		iconCls: 'addM8',

        plain:true,

        bodyStyle:'padding:5px;',

        buttonAlign:'center',

        items: form,

        buttons: [{

            text: 'Send',

			handler: function(){

				if(form.form.isValid()){

			form.form.submit({

				params:{

					action:'submit'

					},

					success:function(form, action){

					     Ext.MessageBox.show({

           msg: 'Sending your request, please wait...',

           progressText: 'Saving...',

           width:300,

           wait:true,

           waitConfig: {interval:200},

           icon:'ext-mb-download'

       });

						  setTimeout(function(){

            //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: 'Subscribe to our newsletter',

		   msg: 'Subscription Successful',

           width:300,

		   buttons: Ext.MessageBox.OK,

           icon:'ext-mb-success'

       });

        }, 1000);

			window.hide();

					//

					    },

					failure:function(form, action){

						if(action.result.errors.length > 0){

						 Ext.MessageBox.show({

           title: 'Submission Error',

		   msg: action.result.errors,

           width:300,

		   buttons: Ext.MessageBox.OK,

           icon: Ext.MessageBox.WARNING

       });

						}

					}

			});

		}else{

			Ext.MessageBox.show({

           title: 'Form Error',

		   msg: 'Please correct the indicated errors',

           width:300,

		   buttons: Ext.MessageBox.OK,

           icon: Ext.MessageBox.WARNING

       });

		}

        }

		},{

            text: 'Cancel',

			handler: function(){

			window.hide();

			}

        }]

    });

    window.show();

});

});