// NAME
//      $RCSfile: makeApplet.js,v $
// DESCRIPTION
//      This file inserts the code to create a PFH applet at the point in
//      the HTML where the function is called.
//
//      There are two reasons for this approach. First it makes life easier because
//      there is only one place to maintain the code. Second it works around the
//      plugin activation step required by the patent dispute between Eolas and
//      Microsoft. If the object is in the HTML it will not work on IE after
//      the middle of June 2006.
//
//      To use the object include the js in the HTML header:
//        <script src="script/makeApplet.js" type="text/javascript"></script>
//
//      And call the function from the HTML body (I recommend making it the last
//      before closing the body):
//        <script type="text/javascript">makeApplet();</script>
//
// DELTA
//      $Revision: 1.5 $
// CREATED
//      $Date: 2008/01/24 17:30:26 $
// AUTHOR
//      Ray Tran <birgit@westhawk.co.uk>
// COPYRIGHT
//      Westhawk Ltd
// TO DO
//

// Returns text. Do element.innerHTML = "returned text"
function makeApplet(debug, username, password)
{
  var appletText = '<applet';
  appletText += '   code="com.phonefromhere.softphone.Phonefromhere"';
  appletText += '   archive="lib/signedsoftphone.jar,lib/njiax-signed.jar" ';
  appletText += '   id="phonefromhere" ';
  appletText += '   name="phonefromhere" ';
  appletText += '   height="1"';
  appletText += '   width="1"';
  appletText += '   hspace="0"';
  appletText += '   vspace="0"';
  appletText += '   align="middle"';
  appletText += '   mayscript="true" >';
  appletText += '      <param name="debug" value="' + debug + '"/>';
  appletText += '      <param name="username" value="' + username + '"/>';
  appletText += '      <param name="password" value="' + password + '"/>';
  appletText += '      <param name="autostart" value ="false"/>';
  appletText += '      <param name="statusCallback" value="phonefromherestatus"/>';
  appletText += '      <param name="dtmfCallback" value="phonefromhereGotDtmf"/>';
  appletText += '      <param name="textCallback" value="phonefromhereGotText"/>';
  appletText += '      <param name="doEC" value="false"/>';
  appletText += '      <param name="technology" value="com.phonefromhere.softphone.njiax.NjiaxPhone"/>';
  appletText += '      <param name="mayscript"/>';
  appletText += '  </applet>';
  return appletText;
}


// This doesn't work in Safari. Sigh!!!
// Returns an element. Do parentElem.appendChild(appletElem) to
// incorperate
function makeApplet_not(debug, username, password)
{
    if (debug == null)
    {
        debug = 0;
    }

    var applet = document.createElement("applet");
    applet.setAttribute("code", 
        "com.phonefromhere.softphone.Phonefromhere");
    applet.setAttribute("archive", 
        "lib/signedsoftphone.jar,lib/njiax-signed.jar");
    applet.setAttribute("id", "phonefromhere");
    applet.setAttribute("name", "phonefromhere");
    applet.setAttribute("height", "1");
    applet.setAttribute("width", "1");
    applet.setAttribute("hspace", "0");
    applet.setAttribute("vspace", "0");
    applet.setAttribute("align", "middle");
    applet.setAttribute("mayscript", "true");

    addParam(applet, "debug", debug);
    addParam(applet, "username", username);
    addParam(applet, "password", password);
    addParam(applet, "autostart", "false");
    addParam(applet, "statusCallback", "phonefromherestatus");
    addParam(applet, "dtmfCallback", "phonefromhereGotDtmf");
    addParam(applet, "textCallback", "phonefromhereGotText");
    addParam(applet, "doEC", "false");
    addParam(applet, "technology", "com.phonefromhere.softphone.njiax.NjiaxPhone");
    addParam(applet, "mayscript");

    return applet;
}


function addParam(parent_element, name, value)
{
    var param = document.createElement("param");
    param.setAttribute("name", name);
    if (value)
    {
        param.setAttribute("value", value);
    }
    parent_element.appendChild(param);
}

