﻿
$(document).ready(function() {
    jQuery.fn.fadeToggle = function(speed, easing, callback) {
        return this.animate({ opacity: 'toggle' }, speed, easing, callback);
    };
});

function GetValue(value) {
    if (value == null)
        return "";

    return value;
}

function showDeleteArticleDialog(settingid) {
    $("#delete_articleid").val(settingid);
    $('#dialog_deleteArticle').dialog('open');
}



//Begin Delete methods
function DeleteArticle() {
    var id = $("#delete_articleid").val();
    DeletePageMethod("DeleteArticle", null, null, "ArticleId", id);
    row1 = $("#artId_" + id);
    row2 = $("#articleId_" + id);
    row1.remove();
    row2.remove();
}

function DeletePageMethod(methodName, onSuccess, onFail) {

    var args = '';
    var l = arguments.length;
    if (l > 3) {
        for (var i = 3; i < l - 1; i += 2) {
            if (args.length != 0) args += ',';
            args += '"' + arguments[i] + '":"' + arguments[i + 1] + '"';
        }
    }
    var loc = window.location.href;
    loc = loc.replace('#', '');
    loc = (loc.substr(loc.length - 1, 1) == "/") ? loc + "default.aspx" : loc;


    $.ajax({
        type: "POST",
        url: loc + "/" + methodName,
        data: "{" + args + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(result) {

            if (result.d > 0) {
                //remove row of feed
                $("#feed" + result.d).remove();
            }
            else {
                alert('verwijderen is mislukt!');
            }
        },
        fail: function(result) { alert(result); }
    });
}
//end save methods

//Service method
//Basic proxy for talking with a JSON service
//Use the invoke method to make the call
function serviceProxy(serviceUrl) {
    var _instance = this;
    this.serviceUrl = serviceUrl;

    this.invoke = function (method, data, callback, error) {
        var url = _instance.serviceUrl + method;
        $.ajax({
            url: url,
            data: data,
            type: "POST",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (res) {
                if (!callback) return;
                callback($.parseJSON(res.d));
            },
            error: function (xhr) {
                if (!error) return;
                error($.parseJSON(xhr.responseText));
            }
        });
    }
}
//end Service method

// Replaces all instances of the given substring.
String.prototype.replaceAll = function (
	        strTarget, // The substring you want to replace
	        strSubString // The string you want to replace in.
	        ) {
    var strText = this;
    var intIndexOfMatch = strText.indexOf(strTarget);

    // Keep looping while an instance of the target string
    // still exists in the string.
    while (intIndexOfMatch != -1) {
        // Relace out the current instance.
        strText = strText.replace(strTarget, strSubString)

        // Get the index of any next matching substring.
        intIndexOfMatch = strText.indexOf(strTarget);
    }

    // Return the updated string with ALL the target strings
    // replaced out with the new substring.
    return (strText);
}

// hide popup
function hideHelpPopUp(panelId, backgroundId) {
    var mpu = $('#ctl00_ctl00_Content_ContentPlaceHolder1_pnlHelp');
    mpu.hide();

    var bg = $('#HelpExtender_backgroundElement');
    bg.hide();
}
