NM_E_NOT_ACTIVE = 0x81000203;

        
//Use NetMeeting API to launch NetMeeting and drive it into the conference
function Handle_NetMeeting_API(strProtocol, strMCUAddress, strMeetingID, strPassword, isPrivate)
{
    var ErrNo = 0;
            
    ErrNo = NetMeetingCAC.ClientJoinConference(strProtocol, strMCUAddress, strMeetingID, strPassword);

    //If NetMeeting was once open and has been closed; have user restart                
    while (NM_E_NOT_ACTIVE == ErrNo)
    {
        L_NetMeetingStopped_ErrorMessage = "Exchange Conferencing Service 偵測到您已經關閉 NetMeeting。請重新啟動 NetMeeting，再按一下 [確定]。";
                    
        //Allow the user to get out of the loop by clicking CANCEL
        if (!window.confirm(L_NetMeetingStopped_ErrorMessage))
        {
            //Clear the error so the user doesn't get a nasty dialog
            ErrNo = 0;
            break;
        }
        ErrNo = NetMeetingCAC.ClientJoinConference(strProtocol, strMCUAddress, strMeetingID, strPassword);
    }
                
    if (0 != ErrNo) //On any random kind of error resort to manual use                
        Handle_Manual_Launch(isPrivate)
    else
        Show_Info_Window();
}

// Displays the NetMeeting ActiveX control in the client frame
function Handle_NetMeeting_ActiveX(strProtocol, strMCUAddress, strMeetingID, strPassword, strIsPrivate, ErrNo)
{
    var bIssueCall;
    var strCallTo;
            
    L_NetMeetingID_Text = "NetMeeting";
    L_NetMeeting_Text   = "連帶啟動 NetMeeting 3.0";
    L_NetMeetingTitle_HTMLText = "<FONT STYLE=font:verdana><U><B>Microsoft Exchange Data Conferencing Service</B></U></FONT>";
    L_NetMeetingShare_HTMLText = "<nobr><B>Share an application</B>. <wbr>First, start the application. <wbr>Then click this button and <wbr>select the application<wbr> from the dialog box. <wbr>To give another meeting participant <wbr>control of the application, <wbr>click <B>Allow control</B>.</nobr>";
    L_NetMeetingChat_HTMLText  = "<nobr><B>Chat</B>. <wbr>Click to chat with other participants.</nobr>";
    L_NetMeetingDraw_HTMLText  = "<nobr><B>Draw on a whiteboard</B>. <wbr>Click to open a whiteboard that <wbr>participants can use to make <wbr>sketches or share graphics.</nobr>";
    L_NetMeetingSend_HTMLText  = "<nobr><B>Send a file</B>. <wbr>Click to send a file to <wbr>one or more participants.</nobr>";
    L_NetMeetingSecure_HTMLText= "安全呼叫";
            
    document.write('</HEAD>');
    document.write('<BODY BGCOLOR=#D4D0C8>');
    document.write('<table border="0" width="680" cellspacing="0" cellpadding="0" align="left" height="207">');
    document.write('<tr>');
    // Include the ActiveX control
    document.write('  <td width="302" rowspan="5" valign="top" height="207"><object ID=NetMeeting CLASSID="CLSID:3E9BAF2D-7A79-11d2-9334-0000F875AE17 alt="'+L_NetMeeting_Text+'"><PARAM NAME="MODE" VALUE="DataOnly"></object>');

    if ("1" == strIsPrivate)
    {
        document.write('<br>&nbsp&nbsp&nbsp&nbsp' + L_NetMeetingSecure_HTMLText);
    }

    document.write('</td>');
    document.write('</tr>');
    // Add in text descriptions for help
    document.write('<tr>');
    document.write('  <td width="31" valign="top" height="59"><img border="0" src="Share.gif" align="texttop" width="31" height="24"></td>');
    document.write('  <td>' + L_NetMeetingShare_HTMLText + '</td>');
    document.write('</tr>');
    document.write('<tr>');
    document.write('  <td width="31" valign="top" height="26"><img border="0" src="chat.gif" align="texttop" width="31" height="24"></td>');
    document.write('  <td>' + L_NetMeetingChat_HTMLText + '</td>');
    document.write('</tr>');
    document.write('<tr>');
    document.write('  <td width="31" valign="top" height="40"><img border="0" src="whiteboard.gif" align="texttop" width="31" height="24"></td>');
    document.write('  <td>' + L_NetMeetingDraw_HTMLText + '</td>');
    document.write('</tr>');
    document.write('<tr>');
    document.write('  <td width="31" valign="top" height="26"><img border="0" src="send_file.gif" align="texttop" width="31" height="24"></td>');
    document.write('  <td>' + L_NetMeetingSend_HTMLText + '</td>');
    document.write('</tr>');
    document.write('</table>');

    bIssueCall = true;
            
    while (0 != NetMeeting.IsInConference())
    {
        L_NetMeetingInConference_ErrorMessage = "Exchange Conferencing Service 偵測到您已經開啟 NetMeeting 連線。請掛斷目前的 NetMeeting 連線，再按一下 [確定]。";
                    
        //Allow the user to get out of the loop by clicking CANCEL
        if (!window.confirm(L_NetMeetingInConference_ErrorMessage))
        {
            bIssueCall = false;
            break;
        }
    }

    // Make sure we should still issue the call and that the user
    // didn't have problems setting up the certificate to use
    if (true != bIssueCall)
        return;

    // Set the certificate to use only for secure conferences where
    // the user didn't have problems selecting a certificate
    if ("1" == strIsPrivate && 0 == ErrNo)
    {
        ErrNo = NetMeetingCAC.SetClientCertificate();
                
        //if (0 != ErrNo)
        //{
        //    L_ErrorSettingClientCertificate_ErrorMessage = "The Data Conferencing Service was unable to properly set the certificate that will be used for this secure conference.";
                        
        //    alert(L_ErrorSettingClientCertificate_ErrorMessage);
        //}
    }
    // Set up a basic T.120 call with no Audio/video and no H.323 preliminary negotiation
    strCallTo = strMCUAddress+"+type=host+";

    if ("H323.A" == strProtocol)
        strCallTo += "av=true+H323=true";
    else
        strCallTo += "av=false+H323=false";

    strCallTo += "+conference="+strMeetingID;
                
    if ("1" == strIsPrivate)
        strCallTo += "+secure=true";
    else
        strCallTo += "+secure=false";
                    
    if ("" != strPassword)
        strCallTo += "+password="+strPassword;
                    
    NetMeeting.CallTo(strCallTo);
}

function Notify_Private_Unsupported_Client()
{
    L_UnsupportedClient_ErrorMessage = "若要加入私人的資料會議，您需要支援私人會議的會議用戶端程式，例如 Microsoft  NetMeeting 3.01 或更新的版本。您可以從下列位置下載最新版本的 NetMeeting： http://www.microsoft.com/msdownload/iebuild/netmeet/TW/netmeet.htm";
            
    alert(L_UnsupportedClient_ErrorMessage);
}

function Handle_Manual_Launch(isPrivate)
{
    //if private, we can't handle invites - redirect the
    //client to join instructions
    if ("1" == isPrivate)
    {
        Server_Invite();
    }
    else
    {
        L_StartClient_ErrorMessage = "若要受邀參加資料會議，請啟動 Microsoft NetMeeting 或其他 T.120 用戶端，然後按一下 [確定]。";
    
        Show_Info_Window();
        
        //Have the user start their T.120 client                
        if (window.confirm(L_StartClient_ErrorMessage))
            Server_Invite(); //Invite them into the conference
    }
}
