var gEmailSubscriptionCaption = 'Enter Your E-mail Address Here'

$.ajaxSetup({
    error: function (x, e) {
        if (x.status == 0) {
            alert('You are offline!!\n Please Check Your Network.');
        } else if (x.status == 404) {
            alert('Requested URL not found.');
        } else if (x.status == 500) {
            alert('Internal Server Error. ' + x.responseText);
        } else if (e == 'parsererror') {
            alert('Error.\nParsing JSON Request failed.');
        } else if (e == 'timeout') {
            alert('Request Time out.');
        } else {
            alert('Unknow Error.\n' + x.responseText);
        }
    }
});

var objEmail = {

    toggleCaption: function () {
        if ($('#frmSubscribe input[name=fldEmail]').val() == gEmailSubscriptionCaption) {
            $('#frmSubscribe input[name=fldEmail]').val('');
        } else if ($('#frmSubscribe input[name=fldEmail]').val() == '') {
            $('#frmSubscribe input[name=fldEmail]').val(gEmailSubscriptionCaption);
        }
    },

    subscribe: function (vListID) {
        if ($('#frmSubscribe input[name=fldEmail]').val() != '' && $('#frmSubscribe input[name=fldEmail]').val() != gEmailSubscriptionCaption) {
        $.get('/members/memberService.asp', { callMethod: 'subscribe', fldEmail: $('#frmSubscribe input[name=fldEmail]').val(), fldListID: vListID }, function (vResponse) {
            arrResponse = vResponse.split('||');
            if (arrResponse[0] == '1') {
                alert('Thank you for subscribing. You\'ll begin receiving updates by email soon.');
            } else {
                alert(arrResponse[1]);
            }
        });
        } else {
            alert('Please enter your email address before attempting to subscribe.');
        }
    }

}
