﻿// Copyright (c) Microsoft Corporation. All rights reserved.

function Microsoft_Live_Messenger_PresenceButton_startConversation(conversationUrl)
{
    window.open(conversationUrl, '_blank', 'height=350px,width=436px');
}

function Microsoft_Live_Messenger_PresenceButton_onStyleChange(element)
{
    if (element && element.presence)
    {
        Microsoft_Live_Messenger_PresenceButton_onPresence(element.presence);
    }
}

function Microsoft_Live_Messenger_PresenceButton_onPresence(presence)
{
    var idx = presence.id.indexOf('@');
    if (idx >= 0)
    {
        var id = presence.id.substr(0, idx);

        var element = document.getElementById('Microsoft_Live_Messenger_PresenceButton_' + id);
        if (element)
        {
            element.innerHTML = "";
        
            var conversationUrl = element.attributes['msgr:conversationUrl'].value;


            var link = document.createElement('a');

            link.href = 'javascript:Microsoft_Live_Messenger_PresenceButton_startConversation("' + conversationUrl + '");';


            var statusIcon = document.createElement('img');
            statusIcon.style.border = 'none';
            statusIcon.style.verticalAlign = 'middle';
            statusIcon.src = presence.icon.url;
            statusIcon.width = presence.icon.width;
            statusIcon.height = presence.icon.height;
            statusIcon.alt = presence.statusText;
            statusIcon.title = presence.statusText;

            link.appendChild(statusIcon);
 	    link.appendChild(document.createTextNode('在线客服'));
            element.appendChild(link); 
            element.presence = presence;
        }
    }
}
