Ext.onReady(function()
{
    var temp_tf = new Ext.form.TextField(
    {
        vtype:'email'
    });
    
    Ext.email_subscribe = function(enewsletter_pk)
    {
        var email = Ext.get('email_address').dom.value;
        
        if (Ext.util.Format.trim(email) != '')
        {
            if (temp_tf.validateValue(email))
            {
                Ext.MessageBox.show({title: 'Processing...',
                msg: 'Processing your subscription. Please wait.<br/>',
                width:240,
                closable:false});
                
                Ext.Ajax.request({
                    url: '/common/ajax/enewsletters.php',
                    success: function(result)
                    {
                        Ext.MessageBox.hide();
                        if (1 == result.responseText)
                        {
                            var msg = 'Thank you for subscribing to our email newsletter. Your first issue will ' + 
                                      'arrive to your email during our next scheduled delivery. ';
                            Ext.Msg.alert('Successful Subscription', msg);
                        }
                        else
                        {
                            Ext.Msg.alert('Unsuccessful Subscription', 'Unfortunately, we were unable to subscribe you.');
                        }
                    },
                    params: {0:'subscribe',1:email,2:enewsletter_pk}
                });
            }
            else
            {
                Ext.Msg.alert('Incorrect Input', 'Invalid Email Address');
            }
            
        }
        else
        {
            Ext.Msg.alert('Incorrect Input', 'Invalid Email Address');
        }
    }
    
    //------------------------------------------------------------------------------------
    Ext.email_subscribe2 = function(enewsletter_pk)
    {
        var choice = document.getElementById("enewsletter_choice");
        if(choice.value == 0)
        {
            return  Ext.Msg.alert('Incorrect Input', 'Please select a newsletter');
        }   
        return Ext.email_subscribe(choice.value);
        
    }
    
});