﻿var strFun = "";
var BCinitialized = false;
function initializeBadgeCall(list) {
    var jsonText = JSON.stringify({ list: list });
    var now = new Date();
    try {
	$.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/lifewebservice/BadgeService.asmx/GetCallBackFunction?ts=" + now,
        data: jsonText,
        dataType: "json",
        success: function (data) {			
            strFun = data.d;
        }
    });
	} catch(e) {}
}
function CallBadgeAction(customKey) {
    if (strFun != "") {
        $.each(strFun, function (index, result) {
            if (customKey == result[0]) {             
                $("#trkImg").append("<img src='" + result[1] + "'/>");	
				if ($('#hiddenbtn').length) { 
					window.setTimeout("$('#hiddenbtn').click()", 2000);
				}
				if ($('#publish').length) { 
					window.setTimeout("$('#publish').click()", 2000);
				}	
            }			
        });        
    } else {
        if (!BCinitialized) {
            initializeBadgeCall(Keylist);
            BCinitialized = true;
        }
        setTimeout(function () { CallBadgeAction(customKey); }, 1000);        
    }
}
