﻿//Default.js

$(function()
{
    try
    {
        if (__downloadUrl)
        {
            var downloadScript = 'window.top.location = \"' + __downloadUrl + '\";';
            setTimeout(downloadScript, 1500); //start download after specified milliseconds
        }
    }
    catch (err)
    {
        //ignore if no-download-url
    }
});

//////////////////////
//asynchronous methods

function ReceiveServerData(arg, msg)
{
    var generalResult = GeneralReceiveServerData(arg, msg);
    if (generalResult) return; //if handled by general, then return

    //process result
    var callbackResult = JSON.parse(arg);
    switch (callbackResult.CallbackAction)
    {
        case 'NewDownloadEntry':
            {
                var isSuccess = callbackResult.ReturnValue.IsSuccess;
                var articleFilePath = callbackResult.ReturnValue.ArticleFilePath;
                if (isSuccess)
                {
                    window.top.location = '/DownloadFile.aspx?path=/' + articleFilePath;
                    //window.open('/DownloadFile.aspx?path=/' + articleFilePath);
                }
                break;
            }
        case 'NewComment':
            {
                var isSuccess = callbackResult.ReturnValue.IsSuccess;
                if (isSuccess)
                {
                    ShowMessageBox('Your comment has been posted successfully.\nIt will appear after it has been approved.', 'Comment', function() { window.top.location = window.top.location; });
                }
                break;
            }
    }
}

