$(document).ready(function() {

    $('#cc_subscribe_go').click(function() {

        var _email = $('#cc_email').val();

        if (_email == '' || _email == 'undefined') {
            alert('Sorry, please input your email address.');
            return false;
        }

        var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
        if (!filter.test(_email)) {
            alert('Sorry, thats an invalid email address.');
            return false;
        }

        $('#div_safesub_msg').html('<img src="/images/ajax-loader.gif"> One moment, please...');
        $('#div_safesub_inputs').hide();
        $('#div_safesub_msg').show();

        $.post("/include/ajax_subscribe.php", { "mode": "add", "email": _email},
            function(data) {
                $('#div_safesub_msg').html(data.msg);
                setTimeout('reset_cc_form()',3500);
            }, "json"
        );

    });

    $('#cc_subscribe_go1').click(function() {

        var _email = $('#cc_email1').val();

        if (_email == '' || _email == 'undefined') {
            alert('Sorry, please input your email address.');
            return false;
        }

        var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
        if (!filter.test(_email)) {
            alert('Sorry, thats an invalid email address.');
            return false;
        }

        $('#div_safesub_msg1').html('<img src="/images/ajax-loader.gif"> One moment, please...');
        $('#div_safesub_inputs1').hide();
        $('#div_safesub_msg1').show();

        $.post("/include/ajax_subscribe.php", { "mode": "add", "email": _email},
            function(data) {
                $('#div_safesub_msg1').html(data.msg);
                setTimeout('reset_cc_form1()',3500);
            }, "json"
        );

    });

    $('#cc_subscribe_go2').click(function() {

        var _email = $('#cc_email2').val();

        if (_email == '' || _email == 'undefined') {
            alert('Sorry, please input your email address.');
            return false;
        }

        var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
        if (!filter.test(_email)) {
            alert('Sorry, thats an invalid email address.');
            return false;
        }

        $('#div_safesub_msg2').html('<img src="/images/ajax-loader.gif"> One moment, please...');
        $('#div_safesub_inputs2').hide();
        $('#div_safesub_msg2').show();

        $.post("/include/ajax_subscribe.php", { "mode": "add", "email": _email},
            function(data) {
                $('#div_safesub_msg2').html(data.msg);
                setTimeout('reset_cc_form2()',3500);
            }, "json"
        );

    });


});

function reset_cc_form()
{
    $('#div_safesub_msg').fadeOut('fast');
    $('#div_safesub_msg').html('');
    $('#div_safesub_inputs').show();
    $('#cc_email').val('');
}


function reset_cc_form1()
{
    $('#div_safesub_msg1').fadeOut('fast');
    $('#div_safesub_msg1').html('');
    $('#div_safesub_inputs1').show();
    $('#cc_email1').val('');
}

function reset_cc_form2()
{
    $('#div_safesub_msg2').fadeOut('fast');
    $('#div_safesub_msg2').html('');
    $('#div_safesub_inputs2').show();
    $('#cc_email2').val('');
}

