﻿function initialiseActvityPopup() {
    // intially hide the activity popup div
    $("#ActivityWindow").hide();
    // get the activity detial via ajax
    $(".activity-link").click(function () {
        getActivity($(this).text(), $(this).attr("longdesc"));
    });

    // close modal functon
    $(".activity-window-close").click(function () {
        $('#mask').hide();
        $("#ActivityWindow").hide();
    });

    // close modal window when clicking the background
    $('#mask').click(function () {
        $(this).hide();
        $('#ActivityWindow').hide();
    });
}
// get activity via ajax
function getActivity(activityTitle, activityType) {

    var ActivityTypeJson =
        {
            Name: activityTitle,
            Type: activityType
        }

    $.ajax({
        type: 'POST',
        url: '/Activities/?option=get',
        //contentType: 'application/json; charset=utf-8',
        dataType: 'html',
        data: JSON.stringify(ActivityTypeJson),
        success: updateActivity,
        error: function (request, status, error) {
            alert("error: " + request.responseText)
        }
    });
    return false;
}
// update the activity popup
function updateActivity(data, status) {
    if (data != null) {
        // show the activity popup  
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });		
        $('#mask').fadeIn(200);
        $('#mask').fadeTo("slow", 0.8);
        var winH = $(window).height();
        var winW = $(window).width();
        $('#ActivityWindow').css('position', 'fixed');
        $('#ActivityWindow').css('top', ((winH / 2) - ($('#ActivityWindow').height() / 2) - 30));
        $('#ActivityWindow').css('left', (winW / 2) - ($('#ActivityWindow').width() / 2));
        $('#ActivityWindow').fadeIn(500);
        // insert data payload into pop div
        $("#activity-content").empty();
        $("#activity-content").html(data);
        // reload popup when popup link clicked inside popup
        $(".popup-activity-link").click(function () {
            getActivity($(this).text(), $(this).attr("longdesc"));
        });
    }
}

// set party type via ajax
function setPartyType(partyType) {
    $.ajax({
        type: 'POST',
        url: '/Default.aspx?option=get',
        //contentType: 'application/json; charset=utf-8',
        dataType: 'html',
        data: JSON.stringify(partyType),
        // success: updateActivity,
        error: function (request, status, error) {
            alert("error: " + request.responseText)
        }
    });
    return false;
}

// json callback error
function OnError(request, status, error) {
}
