var subUrl = 'http://www.mailinglijst.eu/api';
var subKey = '?key=6e567612-a2f9-4591-aac4-9867e89cf55f';
var subListID = '100457';

function saveEmail()
{
    var email = $('#subemail').val();
    if (/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/.test(email))
    {
        var url = subUrl + subKey;
        url += '&action=SUBSCRIBE';
        url += '&l='+subListID;
        url += '&e='+email;
        url += '&optin=0';
        url += '&welcome=0';
        //  call ajax

        $.ajax({
            url: '/manager.php',
            type: "POST",
            data: "email="+email+"&action=SUBSCRIBE",
            cache: false,
            success: function(xml){
                var id = $(xml).find('api');
                var nr = $(id).find('responsecode').text();
                var msg = $(id).find('description').text();
                var ref = $(id).find('referrer').text();
                if (nr == '200') $('subAdd').html('e-mailadres '+email+' is ingeschreven!');
                else alert('Er is iets misgegaan met inschrijven!\n\nHet e-mailadres is niet ingeschreven.');               
            },
            error:function (xhr, ajaxOptions, thrownError)
            {
//                alert(xhr.status);
//                alert(thrownError);
            }
        });
    }
    else
    {
        alert('Geen geldig e-mailadres!');
    }        
}

function subscribe(list_ID){
    var stroptions, strURL
    var lngtop, lngleft

	strURL = "http://www.mailinglijst.eu/nieuwsbrief/subscribe/?l=" + list_ID
	lngtop = 50
	lngleft = 50
	stroptions= "width=400,height=500,top="+lngtop + ",left=" +lngleft + ",scrollbars=1"
	whandle = window.open(strURL,'nieuwsbrief',stroptions);
	whandle.focus();
}

$(window).scroll(function() {
    var x = $(this).scrollTop() - 200;
    if (x > 0) $('#scrollBlock').css('top', x + "px")
    else $('#scrollBlock').css('top', "0px")
//    $('#scrollBlock').css('top', $(this).scrollTop() + "px");
});


function SwitchCal()
{
    if ($('#CalBlockOC').html() == '+') $('#CalBlockOC').html('-'); else $('#CalBlockOC').html('+');
    $('#CalBlockC').toggle();
    
    if ($('#ArtBlockOC').html() == '-') $('#ArtBlockOC').html('+');
    if ($('#GenBlockOC').html() == '-') $('#GenBlockOC').html('+');
    
    $('#GenBlockC').hide();
    $('#ArtBlockC').hide();
}

function SwitchArt()
{
    if ($('#ArtBlockOC').html() == '+') $('#ArtBlockOC').html('-'); else $('#ArtBlockOC').html('+');
    $('#ArtBlockC').toggle();
    
    if ($('#CalBlockOC').html() == '-') $('#CalBlockOC').html('+');
    if ($('#GenBlockOC').html() == '-') $('#GenBlockOC').html('+');
    
    $('#GenBlockC').hide();
    $('#CalBlockC').hide();
}

function SwitchCat()
{
    if ($('#GenBlockOC').html() == '+') $('#GenBlockOC').html('-'); else $('#GenBlockOC').html('+');
    $('#GenBlockC').toggle();
    
    if ($('#ArtBlockOC').html() == '-') $('#ArtBlockOC').html('+');
    if ($('#CalBlockOC').html() == '-') $('#CalBlockOC').html('+');
    
    $('#CalBlockC').hide();
    $('#ArtBlockC').hide();
}
