FOS.Mail = function(){
};

FOS.Mail.show = function(eventId, email){

    if (FOS.Mail.view == null) 
        FOS.Mail.view = new Ext.Window({
        
            labelAlign: 'top',
            layout: 'form',
            xtype: 'form',
            frame: true,
            title: 'Email Message',
            bodyStyle: 'padding:5px 5px 0',
            width: 600,
            height: 400,
            items: [{
                xtype: 'textfield',
                fieldLabel: 'To',
                id: 'to',
                
                anchor: '95%'
            
            
            }, {
                xtype: 'textfield',
                fieldLabel: 'Subject',
                id: 'subject',
                
                anchor: '95%'
            
            
            }, {
                xtype: 'htmleditor',
                id: 'message',
                fieldLabel: 'Message Body',
                autoHeight: true,
                anchor: '98%'
            }],
            
            buttons: [{
                text: 'Send',
                handler: function(){
					
					Ext.Ajax.request({
						url: 'action.php',
						params : {
							module : 'participants',
							action : 'email',
							to :  Ext.getCmp('to').getValue(),
							subject :  Ext.getCmp('subject').getValue(),
							message :  Ext.getCmp('message').getValue()
						},
						success : function () {
							Ext.MessageBox.alert ('Full On Sport', 'Mail sent sucessfully');
							
						},
						failure : function () {
							Ext.MessageBox.alert ('Full On Sport', 'Failure: mail was NOT sent sucessfully');
						}
					});
					
                    FOS.Mail.clear();
                    FOS.Mail.view.hide()
                }
            }, {
                text: 'Cancel',
                handler: function(){
                    FOS.Mail.clear();
                    FOS.Mail.view.hide()
                }
            }]
        });
    
    
    
    FOS.Mail.view.show(this);
    
    Ext.getCmp('to').setValue(email);
    
};

FOS.Mail.clear = function(){

    Ext.getCmp('message').setValue('');
    Ext.getCmp('subject').setValue('');
    Ext.getCmp('to').setValue('');
    
}

