function Microsoft_Live_Messenger_PresenceButton_startConversation(conversationUrl) {
    var url = conversationUrl + "&buttonhost=" + document.location.hostname;
    window.open(url, '_blank', 'height=300px,width=300px');
}

function Microsoft_Live_Messenger_PresenceButton_onPresence(presence) {
    var idx = presence.id.indexOf('@');
    var count = 0;
    if (idx >= 0) {

        var id = presence.id.substr(0, idx);

        var status = presence.status;
        var className = "div." + id;
        var conversationUrl = "http://settings.messenger.live.com/Conversation/IMMe.aspx?invitee=" + id + "@apps.messenger.live.com&mkt=pt-BR";
        var openUrl = "javascript:Microsoft_Live_Messenger_PresenceButton_startConversation('" + conversationUrl + "');";

        $(className).each(function (i) {

            //if (count == 0) {
            if (status == "Offline") {
                $(this).append('<div class="wlm-off">Offline</div>');
            }
            else {
                var htmInterno = '<div class="wlm-on"><a href="' + openUrl + '" >Online</a></div>';
                $(this).append(htmInterno);
            }
            //}
            count++;
        });
    }
}
