﻿//jQuery.noConflict();

var WS_URL = "/_layouts/de/portal/WebServicePage.aspx/";


// Test WP
function TestWP_StartUpScript(typeName, xslUrl, controlName, loadingDiv) {
    $(document).ready(function () {
        LoadTest(typeName, xslUrl, controlName, loadingDiv);
    });
}

function LoadTest(typeName, xslUrl, controlName, loadingDiv) {
    $("#" + controlName).hide();
    $.ajax({
        url: WS_URL + "LoadTest",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        error: function (msg) { },
        data: "{'typeName':'" + typeName + "','xslUrl':'" + xslUrl + "'}",
        success: function (msg) {            
            if (msg != null) {
                if (msg.d != null) {
                    $("#" + controlName).html(msg.d);
                    $("#" + loadingDiv).hide();
                    $("#" + controlName).fadeIn("slow");
                }
            }
        }
    });
}

// Events WP
function Events_StartUpScript(typeName, xslUrl, controlName, loadingDiv) {
    $(document).ready(function () {
        LoadEvents(typeName, xslUrl, controlName, loadingDiv);
    });
}

function LoadEvents(typeName, xslUrl, controlName, loadingDiv) {
    $("#" + controlName).hide();
    var substring = window.location.search.substring(1);
    var url = document.location.href;

    $.ajax({
        url: WS_URL + "LoadEvents",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        error: function (msg) { },
        data: "{'typeName':'" + typeName + "','xslUrl':'" + xslUrl + "','eventidString':'" + substring + "','url':'" + url + "'}",
        success: function (msg) {            
            if (msg != null) {
                if (msg.d != null) {
                    $("#" + controlName).html(msg.d);
                    $("#" + loadingDiv).hide();
                    $("#" + controlName).fadeIn("slow");
                }
            }
        }
    });
}

// MyEvents WP
function MyEvents_StartUpScript(typeName, xslUrl, controlName, loadingDiv) {
    $(document).ready(function () {
        LoadMyEvents(typeName, xslUrl, controlName, loadingDiv);
    });
}

function LoadMyEvents(typeName, xslUrl, controlName, loadingDiv) {
    $("#" + controlName).hide();

    $.ajax({
        url: WS_URL + "LoadMyEvents",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        error: function (msg) { },
        data: "{'typeName':'" + typeName + "','xslUrl':'" + xslUrl + "'}",
        success: function (msg) {
            if (msg != null) {
                if (msg.d != null) {
                    $("#" + controlName).html(msg.d);
                    $("#" + loadingDiv).hide();
                    $("#" + controlName).fadeIn("slow");
                }
            }
        }
    });
}

// Employee WP
function Employees_StartUpScript(typeName, xslUrl, controlName, loadingDiv) {
    $(document).ready(function () {
        LoadEmployees(typeName, xslUrl, controlName, loadingDiv);
    });
}

function LoadEmployees(typeName, xslUrl, controlName, loadingDiv) {
    $("#" + controlName).hide();
    $.ajax({
        url: WS_URL + "LoadEmployees",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        error: function (msg) { },
        data: "{'typeName':'" + typeName + "','xslUrl':'" + xslUrl + "'}",
        success: function (msg) {
            if (msg != null) {
                if (msg.d != null) {
                    $("#" + controlName).html(msg.d);
                    $("#" + loadingDiv).hide();
                    $("#" + controlName).fadeIn("slow");
                }
            }
        }
    });
}

// Preferences WP
function Preferences_StartUpScript(typeName, xslUrl, controlName, loadingDiv) {
    $(document).ready(function () {
        LoadPreferences(typeName, xslUrl, controlName, loadingDiv);
    });
}

function LoadPreferences(typeName, xslUrl, controlName, loadingDiv) {
    $("#" + controlName).hide();
    $.ajax({
        url: WS_URL + "LoadPreferences",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        error: function (msg) { },
        data: "{'typeName':'" + typeName + "','xslUrl':'" + xslUrl + "'}",
        success: function (msg) {
            if (msg != null) {
                if (msg.d != null) {
                    $("#" + controlName).html(msg.d);
                    $("#" + loadingDiv).hide();
                    $("#" + controlName).fadeIn("slow");
                }
            }
        }
    });
}

// Services WP
function Services_StartUpScript(typeName, xslUrl, controlName, loadingDiv) {
    $(document).ready(function () {
        LoadServices(typeName, xslUrl, controlName, loadingDiv);
    });
}

function LoadServices(typeName, xslUrl, controlName, loadingDiv) {
    $("#" + controlName).hide();
    $.ajax({
        url: WS_URL + "LoadServices",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        error: function (msg) { },
        data: "{'typeName':'" + typeName + "','xslUrl':'" + xslUrl + "'}",
        success: function (msg) {
            if (msg != null) {
                if (msg.d != null) {
                    $("#" + controlName).html(msg.d);
                    $("#" + loadingDiv).hide();
                    $("#" + controlName).fadeIn("slow");                    
                }
            }
        }
    });
}

// DefaultInformation WP
function DefaultInformation_StartUpScript(typeName, xslUrl, controlName, loadingDiv) {
    $(document).ready(function () {
        LoadDefaultInformation(typeName, xslUrl, controlName, loadingDiv);
    });
}

function LoadDefaultInformation(typeName, xslUrl, controlName, loadingDiv) {
    $("#" + controlName).hide();
    $.ajax({
        url: WS_URL + "LoadDefaultInformation",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        error: function (msg) { },
        data: "{'typeName':'" + typeName + "','xslUrl':'" + xslUrl + "'}",
        success: function (msg) {
            if (msg != null) {
                if (msg.d != null) {
                    $("#" + controlName).html(msg.d);
                    $("#" + loadingDiv).hide();
                    $("#" + controlName).fadeIn("slow");
                }
            }
        }
    });
}

// DefaultInformation WP
function Teasers_StartUpScript(typeName, xslUrl, controlName, loadingDiv, listUrl, teasersToShow) {
    $(document).ready(function () {
        LoadTeasers(typeName, xslUrl, controlName, loadingDiv, listUrl, teasersToShow);
    });
}

function LoadTeasers(typeName, xslUrl, controlName, loadingDiv, listUrl, teasersToShow) {
    $("#" + controlName).hide();
    $.ajax({
        url: WS_URL + "LoadTeasers",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        error: function (msg) { },
        data: "{'typeName':'" + typeName + "','xslUrl':'" + xslUrl + "','listUrl':'" + listUrl + "','teasersToShow':'" + teasersToShow + "'}",
        success: function (msg) {
            if (msg != null) {
                if (msg.d != null) {
                    $("#" + controlName).html(msg.d);
                    $("#" + loadingDiv).hide();
                    $("#" + controlName).fadeIn("slow");
                }
            }
        }
    });
}

// EventSpot
function EventSpot_StartUpScript(typeName, xslUrl, controlName, loadingDiv) {
    $(document).ready(function () {
        LoadEventSpot(typeName, xslUrl, controlName, loadingDiv);
    });
}

function LoadEventSpot(typeName, xslUrl, controlName, loadingDiv) {
    $("#" + controlName).hide();
    $.ajax({
        url: WS_URL + "LoadEventSpot",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        error: function (msg) { },
        data: "{'typeName':'" + typeName + "','xslUrl':'" + xslUrl + "'}",
        success: function (msg) {
            if (msg != null) {
                if (msg.d != null) {
                    $("#" + controlName).html(msg.d);
                    $("#" + loadingDiv).hide();
                    $("#" + controlName).fadeIn("slow");
                    // initialize scrollable with mousewheel support
                    $("#EventSpotScroll").scrollable({ vertical: true, mousewheel: true, circular: true }).autoscroll(10000);
                }
            }
        }
    });
}

// CampaignSpot
function CampaignSpot_StartUpScript(typeName, xslUrl, controlName, loadingDiv) {
    $(document).ready(function () {
        LoadCampaignSpot(typeName, xslUrl, controlName, loadingDiv);
    });
}

function LoadCampaignSpot(typeName, xslUrl, controlName, loadingDiv) {
    $("#" + controlName).hide();
    $.ajax({
        url: WS_URL + "LoadCampaignSpot",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        error: function (msg) { },
        data: "{'typeName':'" + typeName + "','xslUrl':'" + xslUrl + "'}",
        success: function (msg) {
            if (msg != null) {
                if (msg.d != null) {
                    $("#" + controlName).html(msg.d);
                    $("#" + loadingDiv).hide();
                    $("#" + controlName).fadeIn("slow");
                    // initialize scrollable with mousewheel support
                    $("#CampaignSpotScroll").scrollable({ vertical: true, mousewheel: true, circular: true }).autoscroll(10000);
                }
            }
        }
    });
}

function SubmitEvent(eventid, title) {
    $("#Events_StartUpScript").hide();
    $("#Events_StartUpScript_loadingDiv").show();
    $.ajax({
        url: WS_URL + "SubmitEvent",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        error: function (msg) { },
        data: "{'eventId':'" + eventid + "', 'title':'" + title + "'}",
        success: function (msg) {
            if (msg != null) {
                if (msg.d != null) {
                    $("#Events_StartUpScript").html(msg.d);
                    $("#Events_StartUpScript_loadingDiv").hide();
                    $("#Events_StartUpScript").fadeIn("slow");
                }
            }
        }
    });
}

function UnSubmitEvent(eventid, title) {
    $("#Events_StartUpScript").hide();
    $("#Events_StartUpScript_loadingDiv").show();
    $.ajax({
        url: WS_URL + "UnSubmitEvent",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        error: function (msg) { },
        data: "{'eventId':'" + eventid + "', 'title':'" + title + "'}",
        success: function (msg) {
            if (msg != null) {
                if (msg.d != null) {
                    $("#Events_StartUpScript").html(msg.d);
                    $("#Events_StartUpScript_loadingDiv").hide();
                    $("#Events_StartUpScript").fadeIn("slow");
                }
            }
        }
    });
} 

function SaveBenefits() {
    $("#Services_StartUpScript").hide();
    $("#Services_StartUpScript_loadingDiv").show();
    var checkedBenefits = "";
    $("#benefitDefinitions :checked").each(function () {
        checkedBenefits += $(this).val() + ",";
    });
	 $.ajax({
	     url: WS_URL + "SaveBenefits",
	     type: "POST",
	     contentType: "application/json; charset=utf-8",
	     dataType: "json",
	     async: true,
	     error: function (msg) { },
	     data: "{'checkedBenefits':'" + checkedBenefits + "'}",
	     success: function (msg) {
	         $("#Services_StartUpScript").html(msg.d);
	         $("#Services_StartUpScript_loadingDiv").hide();
	         $("#Services_StartUpScript").show();
             $.scrollTo("#Services_StartUpScript");
	     }
	 });
}

function SavePreferences() {
    $("#Preferences_StartUpScript").hide();
    $("#Preferences_StartUpScript_loadingDiv").show();
    var checkedPreferences = "";
    $("#preferences :checked").each(function () {
        checkedPreferences += $(this).val() + ";";
    });
    $.ajax({
        url: WS_URL + "SavePreferences",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        error: function (msg) { },
        data: "{'checkedPreferences':'" + checkedPreferences + "'}",
        success: function (msg) {
            $("#Preferences_StartUpScript").html(msg.d);
            $("#Preferences_StartUpScript_loadingDiv").hide();
            $("#Preferences_StartUpScript").show();
            $.scrollTo("#Preferences_StartUpScript");
        }
    });
}

function GetAccount(membernumber) {
    $("#PanelMessage").hide();
    $("#PanelLoadingImage").show();
    $.ajax({
        url: WS_URL + "GetAccount",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        error: function (msg) { },
        data: "{'membernumber':'" + membernumber + "'}",
        success: function (msg) {
            if (msg != null) {
                if (msg.d != null) {
                    $("#PanelMessage").html(msg.d);
                    $("#PanelLoadingImage").hide();
                    $("#PanelMessage").fadeIn("slow");
                }
            }
        }
    });
}

