var g_bIsMoz =  (typeof document.implementation != 'undefined') &&
            (typeof document.implementation.createDocument != 'undefined');

var g_bUseWMP = true;
var g_bUseWMPObject = true;
var g_bUseWMPEmbed  = false;
var g_bUseRP  = false;
var g_mediaPlayer = null;

var g_XmlHttp                   = null;
var g_strXmlHttpUrl             = "";

var g_idAudioClipId             = "";
var g_strAudioClipInfo          = "";
var g_strAudioIPAddress         = "";
var g_strAudioRequestServer     = "";
var g_strAudioReportQueryName   = "";
var g_strAudioHost              = "";
var g_strAudioOrderAffiliateName= "";
var g_strAudioPlayType          = ""; 
var g_strAudioPlayCommand       = "";
var g_strAudioTransId           = "";
var g_bAudioCanPlayAll          = false; 
var g_bAudioCanAdvanceLimited   = true; 
var g_nAudioPlayStart           = 0;
var g_nAudioPlayEnd             = 0;
//var g_strAudioLoginId         = ""; 
//var g_strAudioPassword        = ""; 
var g_nAudioLowPositionSec      = 0;
var g_nAudioHighPositionSec     = 0;
var g_nAudioMaxPositionSec      = 0;
var g_nAudioCheckPositionInterval = 1000;
var g_nStartPosSec              = 0;
var g_nEndPosSec                = 0;
var g_strInnerHTML;
var g_strKey            = "";
var g_bIsSeeking                = false;

var g_nAdjustWidth = -40;
var g_nAdjustHeight = -40;

var g_strSystemVersion          = "";
var g_strBrowserVersion         = "";
var g_strPlayerVersion          = "";

var g_nAudioProcessState                = 1;
var g_nAudioProcessState_Inactive       = 1;
var g_nAudioProcessState_Playing        = 2;
var g_nAudioProcessState_PausedPlaying  = 3;
var g_nAudioProcessState_StartSelected  = 4;
var g_nAudioProcessState_PausedStarted  = 5;
var g_nAudioProcessState_EndSelected    = 6;
var g_nAudioProcessState_PausedEnded    = 7;

var g_formAudio         = null;
var g_lblInstructions   = null;
var g_lblTimeOffset     = null;
var g_strSegStart       = "";
var g_strSegEnd         = "";
var g_strSegLength      = "";
var g_hiddenOp          = null;
var g_hiddenClipId      = null;
var g_hiddenClipInfo    = null;
var g_hiddenStartPos    = null;
var g_hiddenEndPos      = null;
var g_hiddenQueryName   = null;
var g_hiddenRequestServer= null;
var g_hiddenHost        = null;

var g_nRPState_Stopped    = 0;
var g_nRPState_Contacting = 1;
var g_nRPState_Buffering  = 2;
var g_nRPState_Playing    = 3;
var g_nRPState_Paused     = 4;
var g_nRPState_Seeking    = 5;

// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmplay10/mmp_sdk/playerplaystate.asp

var g_nWMPState_Undefined  = 0;  // Windows Media Player is in an undefined state. 
var g_nWMPState_Stopped    = 1;  // Playback of the current media item is stopped. 
var g_nWMPState_Paused     = 2;  // Playback of the current media item is paused. When a media item is paused, resuming playback begins from the same location. 
var g_nWMPState_Playing    = 3;  // The current media item is playing. 
var g_nWMPState_ScanFwd    = 4;  // The current media item is fast forwarding. 
var g_nWMPState_ScanRev    = 5;  // The current media item is fast rewinding. 
var g_nWMPState_Buffering  = 6;  // The current media item is getting additional data from the server. 
var g_nWMPState_Waiting    = 7;  // Connection is established, but the server is not sending data. Waiting for session to begin.
var g_nWMPState_Played     = 8;  // Media item has completed playback.  
var g_nWMPState_Transition = 9;  // Preparing new media item. 
var g_nWMPState_Ready      = 10; // Ready to begin playing. 
var g_nWMPState_Reconnect  = 11; // Reconnecting to stream. 

// **********************

/* Real Player detection on a Web page.
* Version 1.0
* March 09, 2004
* Paul Davis <pdavis@real.com>, Real Networks Inc.
* This example illustrates how to detect an installed copy of Real Player to ensure proper playback of Real Media files embedded in a web page.
* If the user has IE5+, the code will attempt to instantiate the Real Player active X control and query it. If the user doesn't have IE5+, the code will 1st attempt to look for Real Player in the plug-ins array and then the mime-Type array.
* The code won't detect the presence Real Player if Netscape Browser 6+ is installed after installing Real Player. This is a known issue in Netscape browser.
* The code will return a "true" value if Real Player version G2 or above is installed, but it may not be able to detect the correct Real Player version number in all cases.
* The recommended next step, when the detection fails to find Real Player, is to redirect the user to a landing page, and allow the user to choose to either download Real Player or to play the embedded contents anyway. In the example, http://guide.real.com is used as the landing page.
* The URL to download the latest release of RealPlayer is http://www.real.com/player.
* Finally, the Real Player detection logic should be intended to enhance web user experience, and not to be used as a mean to restrict access to contents.
*/

/*
* The version variable will be set when we are able
* to detect the version. Note, we do not do comprehensive
* version detection, because of the time overhead in
* instantiating a plugin. This invloves creating an instance of
* the plugin (on non Windows IE5+ platforms), setting up a
* background thread to check when it is ready and querying
* the plugin for its version.
*/

var g_strRealPlayerVersion = 0;

function fnRPIsObject (type)
{
 return ("undefined" != typeof(type));
}

function fnRPWinIE5upPlyrDetect()
{
 var player;
 var iectl;
 try // attempt to instantiate the IE control to see if activeX is enabled.
 {
  iectl = new ActiveXObject("Shell.Explorer");
 }
 catch(e)
 {
 }
 try
 {
  player = new ActiveXObject("rmocx.RealPlayer G2 Control.1");
  g_strRealPlayerVersion = player.GetVersionInfo() + ":ActiveX";
 }
 catch (e)
 {
 }
 if (!fnRPIsObject(iectl))
 {
  return "unknown"; //ActiveX disabled
 }
 return new String (fnRPIsObject (player));
}

function fnRPCheckPlugin (name)
{
 plugin = navigator.plugins [name];
 if(fnRPIsObject (plugin))
 {
  g_strRealPlayerVersion = plugin.description + ":" + name; // + ":PlugIn";
  return true;
 }
 return false;
}

function fnRPPluginDetect ()
{
 return (
  (fnRPCheckPlugin ("RealPlayer Version Plugin"))
  ||
  (fnRPCheckPlugin ("RealOne Player Version Plugin"))
 );
}

function fnRPMimeTypeDetect ()
{
 return (
  fnRPIsObject (navigator.mimeTypes)
  &&
  fnRPIsObject (navigator.mimeTypes ["audio/x-pn-realaudio-plugin"])
  );
}

function fnRPIsWinIE5plus()
{
 var result = false;
 var uaLower = navigator.userAgent.toLowerCase();
 if (uaLower.indexOf ("windows") >= 0)
 {
  g_strSystemVersion = "Win";
  g_strBrowserVersion= uaLower;
  if (uaLower.indexOf ("msie") >= 0)
  {
   var versRX = /msie\s+[5-9]/;
   result = versRX.test (uaLower);
  }
 }
 else
 {
  g_strSystemVersion = "NotWin";
  g_strBrowserVersion= uaLower;
 }
 return result;
}

/*
* Returns a string, "true", "false", "unknown" based on the results
* of player detection.
* "false" will only be returned if the user has IE5+, activeX is 
* enabled, and we can not instantiate the player control.
* That is the only case where we are sure the user does not have
* the player installed. All other cases where the player can not
* be detected will return "unknown".
*/
function fnRPHasRealPlayer()
{
 if (fnRPIsWinIE5plus ())
 {
  return fnRPWinIE5upPlyrDetect ();
 }
 else
 {
  return ((fnRPPluginDetect () || fnRPMimeTypeDetect ()) ? "true" : "unknown");
 }
}

// **********************

function fnPlayAudioAll (_strUrl, _nStartSec)
{
 ndsclipChangeState (g_nAudioProcessState_Playing);

 _strUrl = unescape (_strUrl);

 fnSetSource (_strUrl);

// alert ("URL="+_strUrl);

 fnStartPlay ();

// alert ("StartPlay Start="+_nStartSec);

 setPlayerPosition (_nStartSec);
}

function fnPlayAudioLimited (_strUrl, _nStartSec, _nEndSec, _nInitSec)
{
 g_nAudioLowPositionSec = _nStartSec;
 g_nAudioHighPositionSec = _nEndSec;
 fnPlayAudioAll (_strUrl, _nInitSec);
 ndsclipSelectAll ();
 setTimeout ("fnCheckPlayPosition()", g_nAudioCheckPositionInterval);
}

// --------------------------------------

function fnChangeSize (_newSize)
{
 if (g_bUseRP)
 {
 }
 else
 {
  g_mediaPlayer.displaySize = _newSize;
 }
}

function fnPause ()
{
 if (g_bUseRP)
 {
  document.RealPlayer.DoPause ();
 }
 else
 {
  g_mediaPlayer.controls.pause ();
 }
}

function fnPlay ()
{
 if (g_bUseRP)
 {
  document.RealPlayer.SetWantErrors (true);
  document.RealPlayer.DoPlay ();
 }
 else
 {
  g_mediaPlayer.controls.play ();
 }
}

function fnGetSource ()
{
 if (g_bUseRP)
 {
  return document.RealPlayer.GetSource ();
 }
 else
 {
  if (g_bUseWMPObject)
    return g_mediaPlayer.URL;
  else // g_bUseWMPEmbed
    return g_mediaPlayer.src;
 }
}

function fnSetSource (_strUrl)
{
 if (g_bUseRP)
 {
  fnStopPlay ();
  document.RealPlayer.SetSource (_strUrl);
 }
 else
 {
  fnStopPlay ();
  if (g_bUseWMPObject)
    g_mediaPlayer.URL = _strUrl;    // works when g_mediaPlayer is OBJECT
  else // g_bUseWMPEmbed
    g_mediaPlayer.src = _strUrl;    // works when g_mediaPlayer is EMBED
 }
}

function fnShowPlayState ()
{
 if (g_bUseRP)
 {
 }
 else
 {
  var state = getPlayerState ();
//alert ("State=" + state.toString());
 }
}

var g_strOutput = "";

function fnStartPlay ()
{
 if (g_bUseRP)
 {
  document.RealPlayer.SetWantErrors (true);
  document.RealPlayer.DoPlay ();
 }
 else
 {
fnShowPlayState ();

  var state = getPlayerState ();
  if (state == g_nWMPState_Playing)
  {
   if (g_mediaPlayer.currentMedia)
   {
     //alert (g_mediaPlayer.currentMedia.imageSourceWidth.toString() + ":" + g_mediaPlayer.currentMedia.imageSourceHeight.toString());
     //not for audio ?? g_mediaPlayer.width = g_mediaPlayer.currentMedia.imageSourceWidth + g_nAdjustWidth;
     //not for audio ?? g_mediaPlayer.height = g_mediaPlayer.currentMedia.imageSourceHeight + g_nAdjustHeight;
   }
   else
     alert ("Ready, but no g_mediaPlayer.currentMedia");
   return;
  }
  if (state != g_nWMPState_Ready)
  {
   //alert ("Waiting for Ready:" + state.toString());
   setTimeout ("fnStartPlay ()", 500);
   return;
  }

//g_strOutput = "";
//fnShowNode (g_mediaPlayer);
//displayprops (g_mediaPlayer.controls);
//alert (g_strOutput);
//alert (typeof(g_mediaPlayer.controls));

  if (g_mediaPlayer.settings)
   g_mediaPlayer.settings.enableErrorDialogs = true; // false
  if (g_mediaPlayer.controls)
  {
//alert ("play=" + typeof(g_mediaPlayer.controls.start));
   try
   {
    g_mediaPlayer.controls.play ();
   }
   catch (exc)
   {
//alert ("Exception at 'play'");
   }
  }
 }
}

function fnShowNode (_n)
{
 var attr = _n.attributes; // attributes array
 g_strOutput += "Id=" + _n.Id + "; Tag=" + _n.tagName + "; Attr=" + attr.length.toString() + "\n";
 displayprops (attr);
 var children = _n.childNodes;                // Now get all children of n
 for (var i=0; i < children.length; i++)
 {
  fnShowNode (children[i]);
 }
}

function displayprops (obj)
{
 for (prop in obj)
 {
  g_strOutput += obj + ": " + prop + " = " + obj[prop] + " ";
 }
}

function fnStopPlay ()
{
 if (!getIsStopped ())    // not stopped
 {
  if (g_bUseRP)
  {
   document.RealPlayer.DoStop ()
  }
  else
  {
fnShowPlayState ();
   if (g_mediaPlayer.controls)
   {
    try
    {
     g_mediaPlayer.controls.stop ();
    }
    catch (exc) {}
   }
  }
 }
}

function fnTestSeeking ()
{
 var state = getPlayerState ();
 if (g_bUseRP)
 {
   if (state == g_nRPState_Seeking ||
       state == g_nRPState_Contacting ||
       state == g_nRPState_Buffering)
    return true;
   else
    return false;
 }
 else
 {
   if (state == g_nWMPState_ScanFwd ||
       state == g_nWMPState_ScanRev ||
       state == g_nWMPState_Buffering ||
       state == g_nWMPState_Waiting ||
       state == g_nWMPState_Transition ||
       state == g_nWMPState_Reconnect)
    return true;
   else
    return false;
 }
}

function fnCheckPlayPosition ()
{
 if (g_nAudioProcessState == g_nAudioProcessState_Inactive)
  return;

 if (g_nAudioLowPositionSec  == 0 &&
     g_nAudioHighPositionSec == 0)
  return;

 if (g_bIsSeeking)
 {
  if (!fnTestSeeking ())
     g_bIsSeeking = false;
 }
 if (!g_bIsSeeking)
 {
  if (!getIsStopped ()) // not stopped
  {
   var nCurrPos = getPlayerPosition ();
   if (nCurrPos < g_nAudioLowPositionSec || nCurrPos > g_nAudioHighPositionSec)
   {
    setPlayerPosition (g_nAudioLowPositionSec);
   } 
  }
 }
 setTimeout ("fnCheckPlayPosition()", g_nAudioCheckPositionInterval);
}

function getIsPlaying ()
{
 var state = getPlayerState ();
 if (g_bUseRP)
 {
  if (state == g_nRPState_Playing)
   return true;
  else
   return false;
 }
 else
 {
  if (state == g_nWMPState_Playing)
   return true;
  else
   return false;
 }
}

function getIsStopped ()
{
 var state = getPlayerState ();

 if (g_bUseRP)
 {
  if (state > 0 && state < 8)
   return false;
  else
   return true;
 }
 else
 {
  if (state == g_nWMPState_Stopped || state == g_nWMPState_Paused)
   return true;
  else
   return false;
 }
}

function getPlayerState ()
{
 var state;
 if (g_bUseRP)
 {
  state = document.RealPlayer.GetPlayState ();
 }
 else
 {
  //if (!g_mediaPlayer.playState)
  // alert ("No g_mediaPlayer.playState");

  if (g_mediaPlayer.playState)
   state = g_mediaPlayer.playState;
  else
   state = 0;
 }
 return state;
}

function getPlayerPosition () 
{
 var nPosMS;
 var nPosSec;

 if (g_bUseRP)
 {
  nPosMS = document.RealPlayer.GetLength ();
  nPosSec = (nPosMS / 1000);
  g_nAudioMaxPositionSec = Math.floor (nPosSec);

  nPosMS = document.RealPlayer.GetPosition ();
  nPosSec = (nPosMS / 1000);
  return Math.floor (nPosSec);
 }
 else
 {
  g_nAudioMaxPositionSec = g_mediaPlayer.currentMedia.duration; //  * 1000;
//alert ("Max=" + g_nAudioMaxPositionSec.toString ());

  if (g_mediaPlayer.controls)
   return g_mediaPlayer.controls.currentPosition;
  else
   return 0;
 }
}

function setPlayerPosition (_sec)
{
 if (g_bUseRP)
 {
  document.RealPlayer.SetPosition (_sec * 1000);
 }
 else
 {
  if (g_mediaPlayer.controls)
   g_mediaPlayer.controls.currentPosition = _sec;
 }
 g_bIsSeeking = true;
}

function ndsclipChangeState (_nNewState)
{
 switch (_nNewState)
 {
  case g_nAudioProcessState_Inactive:
   g_nAudioProcessState = _nNewState;
   ndsclipSetInactive ();
   break;
  case g_nAudioProcessState_Playing:
   g_nAudioProcessState = _nNewState;
   ndsclipSetPlaying ();
   break;
  case g_nAudioProcessState_PausedPlaying:
   g_nAudioProcessState = _nNewState;
   ndsclipSetPausedPlaying ();
   break;
  case g_nAudioProcessState_StartSelected:
   g_nAudioProcessState = _nNewState;
   ndsclipSetStartSelected ();
   break;
  case g_nAudioProcessState_PausedStarted:
   g_nAudioProcessState = _nNewState;
   ndsclipSetPausedStarted ();
   break;
  case g_nAudioProcessState_EndSelected:
   g_nAudioProcessState = _nNewState;
   ndsclipSetEndSelected ();
   break;
  case g_nAudioProcessState_PausedEnded:
   g_nAudioProcessState = _nNewState;
   ndsclipSetPausedEnded ();
   break;
 }
}

function ndsclipDoPlayAll ()
{
 var bRestartPlay = false;

 if (g_nAudioProcessState == g_nAudioProcessState_Playing ||
     g_nAudioProcessState == g_nAudioProcessState_StartSelected ||
     g_nAudioProcessState == g_nAudioProcessState_EndSelected)
 {
  if (!getIsStopped ())    // not stopped
  {
   fnPause ();
   bRestartPlay = true;
  }
 }

 var bContinue = confirm ("If you click 'OK', you will be charged for access to the entire file.\nDo you want to continue?");
 if (!bContinue)
 {
  if (bRestartPlay)
    fnPlay ();
  return;
 }

 g_strAudioPlayType = "Play";
 ndsclipCallRequestService1 ();
 // callback will be made to ndsclipDoPlay()
}

function ndsclipSetInactive ()
{
 generateBegin ();

 g_strInnerHTML += "<tr><td>" +
"&nbsp;Click&nbsp;" +
"</td><td>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipPlay();return false;\"><span style=\"text-decoration:underline;\"><B>PLAY</B></span></a>&nbsp;" +
"</td><td>" +
"&nbsp;to start." +
"</td></tr><table>";

 g_strInnerHTML += "<table border=0 cellpadding=0 cellspacing=0>";
 g_strInnerHTML += "<tr><td ALIGN=CENTER>&nbsp;</td></tr>";

if (g_bUseRP)
{
 switch (fnRPHasRealPlayer () + "")
 {
  case "true":       // Successful player detection
   if (g_strRealPlayerVersion != 0)
   {
    g_strPlayerVersion = "RP-" + g_strRealPlayerVersion;
    g_strInnerHTML += "<tr><td ALIGN=CENTER><FONT COLOR=#008000>&nbsp;<B>RealPlayer " + g_strRealPlayerVersion + " is installed.</B></FONT></td></tr>";
    g_strInnerHTML += "<tr><td ALIGN=CENTER>&nbsp;<A HREF='http://guide.real.com' ALT='RealPlayer Website' TARGET='_BLANK'><span style='text-decoration:underline'>RealPlayer Website</span></A></td></tr>";
   }
   else
   {
    g_strPlayerVersion = "RP-Unknown";
    g_strInnerHTML += "<tr><td ALIGN=CENTER><FONT COLOR=#000080>&nbsp;<B>RealPlayer is installed.</B></FONT></td></tr>";
    g_strInnerHTML += "<tr><td ALIGN=CENTER>&nbsp;<A HREF='http://guide.real.com' ALT='RealPlayer Website' TARGET='_BLANK'><span style='text-decoration:underline'>RealPlayer Website</span></A></td></tr>";
   }
   break;
  case "unknown":    // Unable to determine if the user has a player
   g_strPlayerVersion = "RP-Undetermined";
   g_strInnerHTML += "<tr><td ALIGN=CENTER><FONT COLOR=#800000>&nbsp;<B>RealPlayer is required.</B></FONT></td></tr>";
   g_strInnerHTML += "<tr><td ALIGN=CENTER>&nbsp;<A HREF='http://guide.real.com' ALT='Get RealPlayer' TARGET='_BLANK'><span style='text-decoration:underline;font-color:#800000'>Get RealPlayer</span></A></td></tr>";
   break;
  case "false":      // Player is definitely not installed
   g_strPlayerVersion = "RP-None";
   g_strInnerHTML += "<tr><td ALIGN=CENTER><FONT COLOR=#800000>&nbsp;<B>RealPlayer is required.</B></FONT></td></tr>";
   g_strInnerHTML += "<tr><td ALIGN=CENTER>&nbsp;<A HREF='http://guide.real.com' ALT='Get RealPlayer' TARGET='_BLANK'><span style='text-decoration:underline;font-color:#800000'>Get RealPlayer</span></A></td></tr>";
   break;
 }
 g_strInnerHTML += "<tr><td ALIGN=CENTER>&nbsp;<A HREF='http://service.real.com/test' ALT='RealPlayer Test' TARGET='_BLANK'><span style='text-decoration:underline'>RealPlayer Test</span></A></td></tr>";
}

 generateEnd ();

 g_strSegStart  = "";
 g_strSegEnd    = "";
 g_strSegLength = "";
}

function ndsclipSetPlaying ()
{
 generateBegin ();

g_strInnerHTML += "<tr><td>" +
"&nbsp;Click&nbsp;" +
"</td><td>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipPausePlaying();return false;\"><span style=\"text-decoration:underline;\"><B>PAUSE</B></span></a>&nbsp;" +
"</td><td>" +
"&nbsp;to pause." +
"</td></tr>";

 ndsclipSetPlayingCommon ();
}

function ndsclipSetPausedPlaying ()
{
 generateBegin ();

g_strInnerHTML += "<tr><td>" +
"&nbsp;Click&nbsp;" +
"</td><td>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipResumePlaying();return false;\"><span style=\"text-decoration:underline;\"><B>RESUME</B></span></a>&nbsp;" +
"</td><td>" +
"&nbsp;to resume." +
"</td></tr>";

 ndsclipSetPlayingCommon ();
}

function ndsclipSetPlayingCommon ()
{
 generateStop ();

 if (g_nAudioLowPositionSec != 0 ||
     g_nAudioHighPositionSec != 0)  // if PlayLimited
 {
  generateLoadAudioFile ();
 }
 else
 {
   generateDownloadAll ();
 }
 generateSelectStart ();

 if (g_nAudioLowPositionSec != 0 ||
     g_nAudioHighPositionSec != 0)  // if PlayLimited
 {
  if (g_bAudioCanAdvanceLimited)
   generateAdvanceLimited ();
 }

//TODO generateEnd ();
 g_lblInstructions.innerHTML = "Playing.";


 g_strSegStart  = "";
 g_strSegEnd    = "";
 g_strSegLength = "";
}

function ndsclipSetStartSelected ()
{
 generateBegin ();

g_strInnerHTML += "<tr><td>" +
"&nbsp;Click&nbsp;" +
"</td><td>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipPauseStarted();return false;\"><span style=\"text-decoration:underline;\"><B>PAUSE</B></span></a>&nbsp;" +
"</td><td>" +
"&nbsp;to pause." +
"</td></tr>";

 ndsclipStartSelectedCommon ();
}

function ndsclipSetPausedStarted ()
{
 generateBegin ();

g_strInnerHTML += "<tr><td>" +
"&nbsp;Click&nbsp;" +
"</td><td>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipResumeStarted();return false;\"><span style=\"text-decoration:underline;\"><B>RESUME</B></span></a>&nbsp;" +
"</td><td>" +
"&nbsp;to resume." +
"</td></tr>";

 ndsclipStartSelectedCommon ();
}

function ndsclipStartSelectedCommon ()
{
 generateStop ();

 if (g_nAudioLowPositionSec != 0 ||
     g_nAudioHighPositionSec != 0)  // if PlayLimited
 {
  generateLoadAudioFile ();
 }
 else
 {
   generateDownloadAll ();
 }
 generateSelectStart ();
 generateSelectEnd ();

 if (g_nAudioLowPositionSec != 0 ||
     g_nAudioHighPositionSec != 0)  // if PlayLimited
 {
  if (g_bAudioCanAdvanceLimited)
   generateAdvanceLimited ();
 }

 generateEnd ();
}                          

function ndsclipSetEndSelected ()
{
 generateBegin ();
 
 g_strInnerHTML += "<tr><td>" +
"&nbsp;Click&nbsp;" +
"</td><td>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipPauseEnded();return false;\"><span style=\"text-decoration:underline;\"><B>PAUSE</B></span></a>&nbsp;" +
"</td><td>" +
"&nbsp;to pause." +
"</td></tr>";

 ndsclipEndSelectedCommon ();
}

function ndsclipSetPausedEnded ()
{
 g_strInnerHTML = "<table border=0 cellpadding=0 cellspacing=0>" +
"<tr><td>" +
"&nbsp;Click&nbsp;" +
"</td><td>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipResumeEnded();return false;\"><span style=\"text-decoration:underline;\"><B>RESUME</B></span></a>&nbsp;" +
"</td><td>" +
"&nbsp;to resume." +
"</td></tr>";

 ndsclipEndSelectedCommon ();
}

function ndsclipEndSelectedCommon ()
{
 generateStop ();

 if (g_nAudioLowPositionSec  == 0 &&
     g_nAudioHighPositionSec == 0)  // if not PlayLimited
 {
  generateDownloadAll ();
  generateSelectStart ();
  generateSelectEnd ();
 }
 else if (g_bAudioCanPlayAll)
 {
  generateDownloadAll ();
  generateLoadAudioFile ();
 }

 if (g_nAudioLowPositionSec  == 0 &&
     g_nAudioHighPositionSec == 0)  // if not PlayLimited
 {
  generatePreview ();
  generateDownload ();
  generateTranscript ();
 }
 else // PlayLimited
 {
  if (!g_bAudioCanPlayAll) // and only PlayLimited
  {
   generateOrder ();
  }
 }

 if (g_nAudioLowPositionSec != 0 ||
     g_nAudioHighPositionSec != 0)  // if PlayLimited
 {
  if (g_bAudioCanAdvanceLimited)
   generateAdvanceLimited ();
 }

 generateEnd ();
}

function generateAdvanceLimited ()
{
 g_strInnerHTML += "<tr><td VALIGN=TOP>" +
"&nbsp;Click&nbsp;" +
"</td><td VALIGN=TOP>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipAdvanceLimited();return false;\"><span style=\"text-decoration:underline;\"><B>ADVANCE PREVIEW</B></span></a>&nbsp;" +
"</td><td VALIGN=TOP>" +
"&nbsp;to advance the preview segment by 10 seconds." +
"</td></tr>";
}

function generateDownload ()
{
/*
 g_strInnerHTML += "<tr><td VALIGN=TOP>" +
"&nbsp;Click&nbsp;" +
"</td><td VALIGN=TOP>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipDownload();return false;\"><span style=\"text-decoration:underline;\"><B>DOWNLOAD</B></span></a>&nbsp;" +
"</td><td VALIGN=TOP>" +
"&nbsp;to download the selected segment." +
"</td></tr>";
*/
}

function generateLoadAudioFile ()
{
/*
 g_strInnerHTML += "<tr><td>" +
"&nbsp;Click&nbsp;" +
"</td><td>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipDoPlayAll();return false;\"><span style=\"text-decoration:underline;\"><B>LOAD AUDIO FILE</B></span></a>&nbsp;" +
"</td><td>" +
"&nbsp;to mark in/out points or to download entire file." +
"</td></tr>";
*/
}

function generateOrder ()
{
 g_strInnerHTML += "<tr><td VALIGN=TOP>" +
"&nbsp;Click&nbsp;" +
"</td><td VALIGN=TOP>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipOrder();return false;\"><span style=\"text-decoration:underline;\"><B>ORDER</B></span></a>&nbsp;" +
"</td><td VALIGN=TOP>" +
"&nbsp;to order this clip from '" +
g_strAudioOrderAffiliateName + "'." +
"</td></tr>";
}

function generatePreview ()
{
 g_strInnerHTML += "<tr><td VALIGN=TOP>" +
"&nbsp;Click&nbsp;" +
"</td><td VALIGN=TOP>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipPreview();return false;\"><span style=\"text-decoration:underline;\"><B>PREVIEW</B></span></a>&nbsp;" +
"</td><td VALIGN=TOP>" +
"&nbsp;to preview the selected segment before downloading." +
"</td></tr>";
}

function generateDownloadAll ()
{
/*
 g_strInnerHTML += "<tr><td>" +
"&nbsp;Click&nbsp;" +
"</td><td>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipDownloadAll();return false;\"><span style=\"text-decoration:underline;\"><B>DOWNLOAD ALL</B></span></a>&nbsp;" +
"</td><td>" +
"&nbsp;to download the entire file." +
"</td></tr>";
*/
}

function generateSelectAll ()
{
/*
 g_strInnerHTML += "<tr><td>" +
"&nbsp;Click&nbsp;" +
"</td><td>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipSelectAll();return false;\"><span style=\"text-decoration:underline;\"><B>SELECT ALL</B></span></a>&nbsp;" +
"</td><td>" +
"&nbsp;to download the entire file." +
"</td></tr>";
*/
}

function generateSelectEnd ()
{
/*
 g_strInnerHTML += "<tr><td>" +
"&nbsp;Click&nbsp;" +
"</td><td>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipSelectEnd();return false;\"><span style=\"text-decoration:underline;\"><B>END SEGMENT</B></span></a>&nbsp;" +
"</td><td>" +
"&nbsp;to mark the out point." +
"</td></tr>";

 if (g_strSegEnd != "")
 {
  g_strInnerHTML += "<tr><td colspan=2>&nbsp;</td><td>&nbsp;" + g_strSegEnd + "<br>&nbsp;" + g_strSegLength + "</td></tr>";
 }
*/
}

function generateSelectStart ()
{
/*
 g_strInnerHTML += "<tr><td>" +
"&nbsp;Click&nbsp;" +
"</td><td>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipSelectStart();return false;\"><span style=\"text-decoration:underline;\"><B>START SEGMENT</B></span></a>&nbsp;" +
"</td><td>" +
"&nbsp;to mark the in point." +
"</td></tr>";

 if (g_strSegStart != "")
 {
  g_strInnerHTML += "<tr><td colspan=2>&nbsp;</td><td>&nbsp;" + g_strSegStart + "</td></tr>";
 }
*/
}

function generateStop ()
{
 g_strInnerHTML += "<tr><td>" +
"&nbsp;Click&nbsp;" +
"</td><td>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipStop();return false;\"><span style=\"text-decoration:underline;\"><B>STOP</B></span></a>&nbsp;" +
"</td><td>" +
"&nbsp;to stop." +
"</td></tr>";
}

function generateBegin ()
{
 g_strInnerHTML = "<table border=0 cellpadding=0 cellspacing=0>";
}

function generateEnd ()
{
 g_strInnerHTML += "</table>";
 g_lblInstructions.innerHTML = g_strInnerHTML;
}

function generateTranscript ()
{
/*
 g_strInnerHTML += "<tr><td VALIGN=TOP>" +
"&nbsp;Click&nbsp;" +
"</td><td VALIGN=TOP>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipTranscriptRegular();return false;\"><span style=\"text-decoration:underline;\"><B>REGULAR TRANSCRIPT</B></span></a>&nbsp;" +
"</td><td VALIGN=TOP>" +
"&nbsp;to order a transcript of the selected segment" +
"<br>&nbsp;to be emailed by 8:00 AM (ET) the next business day." +
"</td></tr><tr><td VALIGN=TOP>" +
"&nbsp;Click&nbsp;" +
"</td><td VALIGN=TOP>" +
"&nbsp;<a href=\"#\" onClick=\"ndsclipTranscriptExpress();return false;\"><span style=\"text-decoration:underline;\"><B>EXPRESS TRANSCRIPT</B></span></a>&nbsp;" +
"</td><td VALIGN=TOP>" +
"&nbsp;to order a transcript of the selected segment" +
"<br>&nbsp;to be emailed within three hours." +
"</td></tr>";
*/
}

function doShowObject (_obj, _bShow)
{
 if (_bShow)
 {
  _obj.style.visibility = "visible";
 }
 else
 {
  _obj.style.visibility = "hidden";
 }
}

function ndsclipAdvanceLimited ()
{
 g_bAudioCanAdvanceLimited = false; // can only do this once

 var nEndSec = g_nAudioHighPositionSec;
 var nMaxSec = g_nAudioMaxPositionSec;
 nEndSec += 10;
 if (nEndSec > nMaxSec)
  nEndSec = nMaxSec;
 var nStartSec = nEndSec - 10;
 if (nStartSec < 0)
  nStartSec = 0;

 fnPlayAudioLimited (fnGetSource (), nStartSec, nEndSec, nStartSec);
}

function ndsclipFindHiddenFields ()
{
 if (g_formAudio == null)
  g_formAudio           = document.forms [0];
 g_hiddenOp             = ndsjsFindChildById (g_formAudio, "OP");
 g_hiddenClipId         = ndsjsFindChildById (g_formAudio, "ClipId");
 g_hiddenClipInfo       = ndsjsFindChildById (g_formAudio, "ClipInfo");
 g_hiddenStartPos       = ndsjsFindChildById (g_formAudio, "StartPos");
 g_hiddenEndPos         = ndsjsFindChildById (g_formAudio, "EndPos");
 g_hiddenQueryName      = ndsjsFindChildById (g_formAudio, "QueryName");
 g_hiddenRequestServer  = ndsjsFindChildById (g_formAudio, "ReqServer");
 g_hiddenHost           = ndsjsFindChildById (g_formAudio, "Host");
}

function ndsclipSetHiddenValues ()
{
 if (g_hiddenClipId == null)
  ndsclipFindHiddenFields ();
 g_hiddenClipId.value       = g_idAudioClipId;
 g_hiddenClipInfo.value     = g_strAudioClipInfo;
 g_hiddenStartPos.value     = g_nStartPosSec.toString ();
 g_hiddenEndPos.value       = g_nEndPosSec.toString ();
 g_hiddenQueryName.value    = g_strAudioReportQueryName;
 g_hiddenRequestServer.value= g_strAudioRequestServer;
 g_hiddenHost.value         = g_strAudioHost;
}

function ndsclipLoadRequestService1 (_strUrl)
{
//alert ("ndsclipLoadRequestService1");

 if (g_XmlHttp == null)
 {
  if (!g_bIsMoz)
  {
   try
   {
     g_XmlHttp = new ActiveXObject ("Msxml2.XMLHTTP");
   }
   catch (e1)
   {
    try
    {
    g_XmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
    }
    catch (e2)
    {
     g_XmlHttp = null;
     alert("IE XmlHttp Not supported.");
    }
   }
  }
  else
  {
   try
   {
    g_XmlHttp = new XMLHttpRequest();
   }
   catch (e3)
   {
    g_XmlHttp = null;
    alert("XMLHttpRequest Not supported.");
   }
  }
 }
 if (_strUrl.length > 5 && _strUrl.substring(0,5)=="http:")
  g_strXmlHttpUrl = _strUrl;
 else
  g_strXmlHttpUrl = ndsjsdecode (_strUrl);
 g_formAudio        = document.forms [0];
 g_lblInstructions  = document.getElementById("lblInstructions");// ndsjsFindChildById (g_formAudio, "lblInstructions");
 g_lblTimeOffset    = document.getElementById("lblTimeOffset");
 ndsclipFindHiddenFields ();

// g_mediaPlayer        = ndsjsFindChildById (g_formAudio, "MediaPlayer");
 g_mediaPlayer      = document.getElementById ("MediaPlayer");
 if (g_mediaPlayer == null && document.MediaPlayer != null)
 {
  g_mediaPlayer = document.MediaPlayer;
  if (g_mediaPlayer != null)
  {
   g_bUseWMPObject = false;
   g_bUseWMPEmbed  = true;
  }
 }
 else
 {
  //alert ("document.getElementById found MediaPlayer");
  g_bUseWMPObject = true;
  g_bUseWMPEmbed  = false;
 }

if (g_mediaPlayer == null)
 alert ("No Player found.");
//else
// alert ("Player found:" + typeof (g_mediaPlayer));

 ndsclipChangeState (g_nAudioProcessState_Inactive);
}

function ndsclipCallRequestService1 ()
{
//alert ("ndsclipCallRequestService1");

 if (g_XmlHttp != null)
 {
  var strIPAddress = g_strAudioIPAddress + ":" + g_strPlayerVersion + ":" + g_strSystemVersion + ":" + g_strBrowserVersion;

  var msg = "";
  msg += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  msg += "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n";
  msg += " <soap:Body>\n";
  msg += "  <GetClipInfo xmlns=\"http://newsdataservice.com/webservices/\">\n";
  msg += "   <Id>"            + g_idAudioClipId           + "</Id>\n";
  msg += "   <Operation>"     + g_strAudioPlayType        + "</Operation>\n";
  msg += "   <TransId>"       + g_strAudioTransId         + "</TransId>\n";
  msg += "   <IPAddress>"     + strIPAddress              + "</IPAddress>\n";
  msg += "   <QueryName>"     + g_strAudioReportQueryName + "</QueryName>\n";
  msg += "   <RequestServer>" + g_strAudioRequestServer   + "</RequestServer>\n";
  msg += "   <Host>"          + g_strAudioHost            + "</Host>\n";
  msg += "   <Info>"          + g_strAudioClipInfo        + "</Info>\n";
  msg += "  </GetClipInfo>\n";
  msg += " </soap:Body>\n";
  msg += "</soap:Envelope>\n";

  try
  {
//POST /RequestService1/service1.asmx HTTP/1.1
//Host: localhost
//Content-Type: text/xml; charset=utf-8
//Content-Length: length
//SOAPAction: "http://newsdataservice.com/webservices/GetClipInfo"

   g_XmlHttp.open ("POST", g_strXmlHttpUrl, true);
   g_XmlHttp.onreadystatechange = ndsclipDoPlay;
   g_XmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
   g_XmlHttp.setRequestHeader("Content-Length", msg.length);
   g_XmlHttp.setRequestHeader("SOAPAction", "\"http://newsdataservice.com/webservices/GetClipInfo\"");
   g_XmlHttp.send (msg);
  }
  catch (ex)
  {
   alert ("Failed posting the message: " + ex.name + " " + ex.message);
   alert (msg);
  }
 }
}

function ndsclipDoPlay ()
{  
//<?xml version="1.0" encoding="utf-8"?>
//<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
//  <soap:Body>
//    <GetClipInfoResponse xmlns="http://newsdataservice.com/webservices/">
//      <GetClipInfoResult>
//        <PlayCommand>string</PlayCommand>
//        <PlayStart>int</PlayStart>
//        <PlayEnd>int</PlayEnd>
//        <QueryName>string</QueryName>
//      </GetClipInfoResult>
//    </GetClipInfoResponse>
//  </soap:Body>
//</soap:Envelope>

 if (g_XmlHttp.readyState != 4)
  return;
 if (g_XmlHttp.status == 200)
 {
// var strText = g_XmlHttp.responseText.replace (/\>/g, ">\n");
// alert("Status is: " + g_XmlHttp.status + " Response Text:[" + strText + "]");
  var el;
  var nAVPlayInit;
  g_strAudioReportQueryName = "";

  el = g_XmlHttp.responseXML.getElementsByTagName ("PlayCommand");
  if (el.length > 0)    g_strAudioPlayCommand               = el[0].firstChild.data;
  el = g_XmlHttp.responseXML.getElementsByTagName ("PlayStart");
  if (el.length > 0)    g_nAudioPlayStart                   = parseInt(el[0].firstChild.data,10);
  el = g_XmlHttp.responseXML.getElementsByTagName ("PlayEnd");
  if (el.length > 0)    g_nAudioPlayEnd                     = parseInt(el[0].firstChild.data,10);
  el = g_XmlHttp.responseXML.getElementsByTagName ("PlayInit");
  if (el.length > 0)    nAVPlayInit                         = parseInt(el[0].firstChild.data,10);
  else nAVPlayInit = g_nAudioPlayStart;
  el = g_XmlHttp.responseXML.getElementsByTagName ("QueryName");
  if (el.length > 0 && el[0].firstChild)    g_strAudioReportQueryName = el[0].firstChild.data;

 //alert("PlayCommand=" + g_strAudioPlayCommand);

  if (g_strAudioPlayType == "Play")
  {
   var nPlayStart       = g_nAudioPlayStart; // save current start
   g_nAudioPlayStart    = 0;
   g_nAudioPlayEnd      = 0;
   g_nAudioLowPositionSec  = 0;
   g_nAudioHighPositionSec = 0;
   fnPlayAudioAll (g_strAudioPlayCommand, nPlayStart);
  }
  else      // PlayLimited
  {
   fnPlayAudioLimited (g_strAudioPlayCommand, g_nAudioPlayStart, g_nAudioPlayEnd, nAVPlayInit);
  }
 }
 else
 {
  var strText = g_XmlHttp.responseText.replace (/\>/g, ">\n");
  alert("4<>200-Status is: " + g_XmlHttp.status + " Response Text:[" + strText + "]");
 }
}

function ndsclipPlay ()
{  
 ndsclipCallRequestService1 ();
 // callback will be made to ndsclipDoPlay()
}

function ndsclipPausePlaying ()
{
 if (getIsPlaying ())    // must be playing
 {
  fnPause ();

  ndsclipChangeState (g_nAudioProcessState_PausedPlaying);
 }
 else
  alert ("Pause, but not playing.");
}

function ndsclipPauseStarted ()
{
 if (getIsPlaying ())    // must be playing
 {
  fnPause ();

  ndsclipChangeState (g_nAudioProcessState_PausedStarted);
 }
}

function ndsclipPauseEnded ()
{
 if (getIsPlaying ())    // must be playing
 {
  fnPause ();

  ndsclipChangeState (g_nAudioProcessState_PausedEnded);
 }
}

function ndsclipResumePlaying ()
{
 if (getIsStopped ())    // stopped
 {
  fnPlay ();
 }

 ndsclipChangeState (g_nAudioProcessState_Playing);
}

function ndsclipResumeStarted ()
{
 if (getIsStopped ())    // stopped
 {
  fnPlay ();
 }

 ndsclipChangeState (g_nAudioProcessState_StartSelected);
}

function ndsclipResumeEnded ()
{
 if (getIsStopped ())    // stopped
 {
  fnPlay ();
 }

 ndsclipChangeState (g_nAudioProcessState_EndSelected);
}

function ndsclipStop ()
{
 fnStopPlay ();

 ndsclipChangeState (g_nAudioProcessState_Inactive);
}

function ndsclipSelectStart ()
{
 var nStartPosSec = getPlayerPosition ();

 if (g_nAudioLowPositionSec != 0 ||
     g_nAudioHighPositionSec != 0)  // if PlayLimited
 {
  if (nStartPosSec < g_nAudioLowPositionSec || nStartPosSec > g_nAudioHighPosition)
   return;
 }

 ndsclipMarkStart (nStartPosSec);

 if (g_nAudioProcessState == g_nAudioProcessState_PausedPlaying ||
     g_nAudioProcessState == g_nAudioProcessState_PausedStarted ||
     g_nAudioProcessState == g_nAudioProcessState_PausedEnded)
  ndsclipChangeState (g_nAudioProcessState_PausedStarted);
 else
  ndsclipChangeState (g_nAudioProcessState_StartSelected);
}

function ndsclipMarkStart (_nStartPosSec)
{
 g_nStartPosSec = _nStartPosSec;
 var strHMS = ndsjsFormatHMSFromSeconds (g_nStartPosSec);
 g_strSegStart = "Segment start: " + strHMS;

 g_nEndPosSec = 0;
 g_strSegEnd = "";
 g_strSegLength = "";

 if (g_lblTimeOffset != null)
  g_lblTimeOffset.innerHTML = strHMS;
}

function ndsclipMarkEnd (_nEndPosSec)
{
 g_nEndPosSec = _nEndPosSec;
 var strHMS = ndsjsFormatHMSFromSeconds (g_nEndPosSec);
 g_strSegEnd = "Segment end: " + strHMS;

 if (g_lblTimeOffset != null)
 {
  var strT = g_lblTimeOffset.innerHTML;
  var n = strT.indexOf (" to ");
  if (n < 0)
   g_lblTimeOffset.innerHTML = strT + " to " + strHMS;
  else
  {
   strT = strT.substring (0, n+4);
   g_lblTimeOffset.innerHTML = strT + strHMS;
  }
 }

 var nLength = g_nEndPosSec - g_nStartPosSec;
 strHMS = ndsjsFormatHMSFromSeconds (nLength);
 g_strSegLength = "Segment length: " + strHMS;
}

function ndsclipPreview ()
{
 if (g_nAudioProcessState == g_nAudioProcessState_Inactive)
  return;

 if (g_bIsSeeking)
 {
   if (!fnTestSeeking ())
     g_bIsSeeking = false;
 }
 if (!g_bIsSeeking)
 {
  if (!getIsStopped ()) // not stopped
  {
   var nCurrPos = getPlayerPosition ();
   if (nCurrPos != g_nStartPosSec)
   {
    setPlayerPosition (g_nStartPosSec);
   } 
  }
  else // stopped, check again later
   setTimeout ("ndsclipPreview()", g_nAudioCheckPositionInterval);
 }
 else // seeking, check again later
  setTimeout ("ndsclipPreview()", g_nAudioCheckPositionInterval);
}

function ndsclipSelectEnd ()
{
 var nEndPosSec = getPlayerPosition ();

 if (g_nAudioLowPositionSec != 0 ||
     g_nAudioHighPositionSec != 0)  // if PlayLimited
 {
  if (nEndPosSec < g_nAudioLowPositionSec || nEndPosSec > g_nAudioHighPositionSec)
   return;
 }

 if (nEndPosSec <= g_nStartPosSec)
 {
  alert ('End of segment must be after start of segment.\nPlease try again.');
  return;
 }

 ndsclipMarkEnd (nEndPos);

 if (g_nAudioProcessState == g_nAudioProcessState_PausedPlaying ||
     g_nAudioProcessState == g_nAudioProcessState_PausedStarted ||
     g_nAudioProcessState == g_nAudioProcessState_PausedEnded)
  ndsclipChangeState (g_nAudioProcessState_PausedEnded);
 else
  ndsclipChangeState (g_nAudioProcessState_EndSelected);
}

function ndsclipSelectAll ()
{
 var nStartPosSec = g_nAudioLowPositionSec;

 var nEndPosSec;
 if (g_nAudioLowPositionSec != 0 ||
     g_nAudioHighPositionSec != 0)  // if PlayLimited
 {
  nEndPosSec = g_nAudioHighPositionSec;
 }
 else
 {
  nEndPosSec = g_nAudioMaxPositionSec;
 }

 ndsclipMarkStart (nStartPosSec);
 ndsclipMarkEnd (nEndPosSec);

 if (g_nAudioProcessState == g_nAudioProcessState_PausedPlaying ||
     g_nAudioProcessState == g_nAudioProcessState_PausedStarted ||
     g_nAudioProcessState == g_nAudioProcessState_PausedEnded)
  ndsclipChangeState (g_nAudioProcessState_PausedEnded);
 else
  ndsclipChangeState (g_nAudioProcessState_EndSelected);
}

function ndsclipDownload ()
{
 if (g_nAudioProcessState == g_nAudioProcessState_EndSelected)
 {
  if (!getIsStopped ())    // not stopped
  {
   fnPause ();
  }
 }

 var bContinue = confirm ("If you click 'OK', you will be charged for downloading a clip.\nDo you want to continue?");
 if (!bContinue)
 {
  if (g_nAudioProcessState == g_nAudioProcessState_EndSelected)
   fnPlay ();
  return;
 }
    
 ndsclipFindHiddenFields ();

 if (g_hiddenOp == null)
 {
  alert ("Unable to process Download request (1).");
 }
 else
 {
  g_hiddenOp.value = "Download";
  ndsclipSetSegmentParameters ();
 }
}

function ndsclipDownloadAll ()
{
 var bDidPause = false;

 if (!getIsStopped ())    // not stopped
 {
  fnPause ();
  bDidPause = true;
 }

 var bContinue = confirm ("If you click 'OK', you will be charged for downloading a clip.\nDo you want to continue?");
 if (!bContinue)
 {
  if (bDidPause)
   fnPlay ();
  return;
 }
    
 ndsclipFindHiddenFields ();

 if (g_hiddenOp == null)
 {
  alert ("Unable to process Download request (1).");
  if (bDidPause)
   fnPlay ();
  return;
 }

 var nStartPosSec = g_nAudioLowPositionsec;

 var nEndPosSec;
 if (g_nAudioLowPositionSec != 0 ||
     g_nAudioHighPositionSec != 0)  // if PlayLimited
 {
  nEndPosSec = g_nAudioHighPositionSec;
 }
 else
 {
  nEndPosSec = g_nAudioMaxPositionSec;
 }

 ndsclipMarkStart (nStartPosSec);
 ndsclipMarkEnd (nEndPosSec);

 g_hiddenOp.value = "Download";
 ndsclipSetSegmentParameters ();
}

function ndsclipOrder ()
{
 if (g_nAudioProcessState == g_nAudioProcessState_EndSelected)
 {
  if (!getIsStopped ())    // not stopped
  {
   fnPause ();
  }
 }

 ndsclipFindHiddenFields ();

 if (g_hiddenOp == null)
 {
  alert ("Unable to process Order request (1).");
 }
 else
 {
  g_hiddenOp.value = "Order";
  ndsclipSetSegmentParameters ();
 }
}

function ndsclipTranscriptExpress ()
{
 if (g_nAudioProcessState == g_nAudioProcessState_EndSelected)
 {
  if (!getIsStopped ())    // not stopped
  {
   fnPause ();
  }
 }

 var bContinue = confirm ("If you click 'OK', you will be charged for ordering a transcript.\nDo you want to continue?");
 if (!bContinue)
 {
  if (g_nAudioProcessState == g_nAudioProcessState_EndSelected)
   fnPlay ();
  return;
 }
    
 ndsclipFindHiddenFields ();

 if (g_hiddenOp == null)
 {
  alert ("Unable to process TranscriptExpress request (1).");
 }
 else
 {
  g_hiddenOp.value = "TranscriptExpress";
  ndsclipSetSegmentParameters ();
 }
}

function ndsclipTranscriptRegular ()
{
 if (g_nAudioProcessState == g_nAudioProcessState_EndSelected)
 {
  if (!getIsStopped ())    // not stopped
  {
   fnPause ();
  }
 }

 var bContinue = confirm ("If you click 'OK', you will be charged for ordering a transcript.\nDo you want to continue?");
 if (!bContinue)
 {
  if (g_nAudioProcessState == g_nAudioProcessState_EndSelected)
   fnPlay ();
  return;
 }
    
 ndsclipFindHiddenFields ();

 if (g_hiddenOp == null)
 {
  alert ("Unable to process Transcript request (1).");
 }
 else
 {
  g_hiddenOp.value = "Transcript";
  ndsclipSetSegmentParameters ();
 }
}

function ndsclipSetSegmentParameters ()
{
 ndsclipSetHiddenValues ();

 var strOrigAction = g_formAudio.action;
 var i = strOrigAction.indexOf ('?');
 if (i > 0)
 {
  g_formAudio.action = strOrigAction.substring (0, i);
 }
 g_formAudio.submit ();
 g_formAudio.action = strOrigAction;
}
