﻿$(document).ready(function () {
    var timer = setTimeout('StartAlertBox();', 4000);
    $('.AlertCloseButton').click(function close() {
        $('#AlertBox').animate({ 'height': 'toggle', 'opacity': '0' }, 1000, function () {
            $('.rel2').animate({ 'opacity': '0' }, 1000).css('display', 'none');
            $('.rel2').remove();
        });
    })
});

function StartAlertBox() {
    var page = 2;
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: '../services/UserServices.asmx/GetAlert',
        dataType: "json",
        data: '{"pageCode":"' + page + '"}',
        success: function (result) {
            var obj = jQuery.parseJSON(result.d);
            if (obj != null) {
                if (obj.Body != '') {
                    if (obj.Title != '') {
                        $("#AlertTitle").html('<NOBR>' + obj.Title + '</NOBR>');
                    } else {
                        $("#AlertTitle").html('?');
                    }

                    var width = (obj.Size + 3.5) * 100;
                    var Height = (obj.Size + 2.8) * 100;
                    $("#AlertBox").height(Height + 'px');
                    $("#AlertBox").width(width + 'px');
                    var a_y = ($(window).height() - Height) / 2;
                    var a_x = ($(window).width() - width) / 2;
                    $("#AlertBox").css('left', a_x + 'px');
                    $("#AlertBox").css('top', a_y + 'px');
                    $("#AlertBody").append(obj.Body);
                    $('.rel2').css('height', '100%');
                    $('.rel2').css('width', '100%');
                    $('.rel2').css('display','block').animate({ 'opacity': '1' }, 1000, function () {
                        $("#AlertBox").fadeTo(2000, 0.85);
                    });
                }
            }
        },
        error: function (e) {

        }
    });
}
