﻿
function tellAFriendShow() {
    var tellAFriendForm = new Ext.form.FormPanel({
        url: 'tellAFriend.ashx?send=true',
        region: 'center',
        width: 450,
        border: false,
        monitorValid: true,
        monitorPoll: 350,
        margins: '3 0 3 3',
        cmargins: '3 3 3 3',
        labelWidth: 90,
        bodyStyle: 'padding-top: 10px; padding-left: 5px;',
        defaults: { width: 250 },
        defaultType: 'textfield',
        items: [{
            fieldLabel: 'Your Name*',
            name: 'yourName',
            allowBlank: false
        }, {
            fieldLabel: 'Friend\'s Email*',
            name: 'friendsEmail',
            allowBlank: false,
            vtype: 'email'
        }, {
            fieldLabel: 'Comment*',
            name: 'comment',
            xtype: 'textarea',
            height: 140,
            allowBlank: false
        }, {
            xtype: 'label',
            html: 'Fields marked with * are required',
            style: 'font-size:12px;'
        }],       
        buttons: [{
            text: 'Send Message',
            //formBind: true,
            handler: function() {

                if (!ValidateForm(tellAFriendForm)) {
                    return;
                }
                
                Ext.Msg.wait('Sending...', 'Please wait...');
                tellAFriendForm.getForm().submit({
                    success: function(f, a) {     
                        tellAFriendWindow.close();
                        Ext.Msg.alert('Infomation', 'Email was successfully sent.');
                    },
                    failure: function(f, a) {
                        Ext.Msg.alert('Error', 'Email was not sent due to an error.');
                    }
                });
            }
        }, {
            text: 'No thank-you',
            handler: function() {
                tellAFriendWindow.hide();
            }
        }]
    });

    var tellAFriendWindow = new Ext.Window({
        title: 'Tell a Friend',
        closable: true,
        width: 380,
        height: 320,
        //border : false,
        plain: true,
        layout: 'border',
        modal: true,
        resizable: false,
        items: [tellAFriendForm]
    });

    tellAFriendWindow.show();
}
