// JavaScript code copyright (c)2000 TOP PRODUCER Systems Inc.
// Last modification time: $Modtime: 3-26-01 3:54p $
// Revision No: $Revision: 40 $
// $NoKeywords: $


// ---------------------------------------------------------
function ShowError (sMessage, sURL, nLine)
{
  alert ('Error:\t' + sMessage + '\nURL:\t' + sURL + '\nLine #:\t' + nLine);
  return true;
}


// ---------------------------------------------------------
// Set hidden form fields which are used as parameters to child window
function ShowPopup (sFiletype, sFilename, nWidth, nHeight)
{
  var frmPopup = window.document.frmPopupHolder;
  frmPopup.Filetype.value = sFiletype;
  frmPopup.Filename.value = sFilename;

  var nXPos = (screen.availWidth  - nWidth)  / 2;
  var nYPos = (screen.availHeight - nHeight) / 2;
  var sWndFeatures = 'status,dependent,resizable,width=' + nWidth + ',height=' + nHeight;
  if (bIsNN)
  {
    sWndFeatures = sWndFeatures + ',ScreenX=' + nXPos + ',ScreenY=' + nYPos;
  }
  else
  {
    sWndFeatures = sWndFeatures + ',left=' + nXPos + ',top=' + nYPos;
  }

  var wndPopup = window.open ('Popup.html', 'Popup' + sFiletype, sWndFeatures);
  wndPopup.moveTo (nXPos, nYPos);
  wndPopup.focus ();

  return wndPopup;
}

// We don't use direct function call because in Netscape it doesn't work.
// This is because the event handler is raised inside the java virtual machine (or plugin).
// However we then want to launch another window which uses a plugin, this instantiates
// another java virtual machine (or plugin). For whatever reason, that does not seem to work.

// all widths and heights are through trial and error
function ShowPopupFlash (sFilename)
{
  window.setTimeout ('ShowPopup ("Flash", "' + sFilename + '", 425, 350);', 100);
}

function ShowPopupInformation ()
{
  window.setTimeout ('ShowPopup ("Image", "AboutBox.png", 425, 350);', 100);
}

var IPIXFiles = new Array (
  ""        // Index starts from 1
  
  // , "", "http://www.TopProducer.com", "Tour3.exe", "Tour4.ipx"
);
function ShowPopupIPIX (sArgs)
{
  if (0 == sArgs.length) return;
  var sFilename = IPIXFiles [sArgs.substring (4, sArgs.length - 4)];

  var nLength = sFilename.length;
  if (0 == nLength) return;

  var bIsHTTP = (nLength > 7 && sFilename.substring (0, 7).toLowerCase () == "http://");
  var bIsIPX  = (nLength > 4 && sFilename.substring (nLength - 4, nLength).toLowerCase () == ".ipx");

  if (!bIsHTTP && bIsIPX)
    window.setTimeout ('ShowPopup ("IPIX", "' + sFilename + '", 425, 350);', 100);
  else
    window.open (sFilename);
}


// ---------------------------------------------------------
function GetFlashObject (sID, nWidth, nHeight, nBGColor)
{
  var sNNText = '<embed' +
      ' src="%1"' +
      ' type="application/x-shockwave-flash"' +
      ' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"' +
      ' name="' + sID + '"' +
      ' play="false"' +
      ' border="0"' +
      ' quality="high"' +
      ' bgcolor="' + nBGColor + '"' +
      ' loop="false"' +
      ' menu="false"' +
      ' swliveconnect="true"' +
      ' width="' + nWidth + '" height="' + nHeight + '"' +
      // Netscape quirk which creates a space between this and the next row
      '></embed>';

  if (bIsNN)
  {
    return sNNText;
  }

  return '<object' +
    ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
    ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"' +
    ' id="' + sID + '"' +
    ' width="' + nWidth + '" height="' + nHeight + '">' +
    '  <param name="movie"   value="%1">' +
    '  <param name="play"    value="false">' +
    '  <param name="quality" value="high">' +
    '  <param name="bgcolor" value="' + nBGColor + '">' +
    '  <param name="loop"    value="false">' +
    '  <param name="menu"    value="false">' +
    sNNText +
    '</object>';
}

function GetIPIXObject ()
{
  var sNNText = '<embed' +
      ' src="%1"' +
      ' name="IPIXMovie"' +
      ' type="application/x-ipix"' +
      ' pluginspage="http://www.ipix.com/cgi-bin/download.cgi"' +
      ' palette="Foreground"' +
      ' width="400" height="300"' +
      '></embed>';

  if (bIsNN)
  {
    return sNNText;
  }

  return '<object' +
    ' classid="CLSID:11260943-421B-11D0-8EAC-0000C07D88CF"' +
    ' codebase="http://www.ipix.com/viewers/ipixx.cab#version=6,0,0,2"' +
    ' id="IPIXMovie"' +
    ' width="400" height="300">' +
    ' <param name="IPXFilename" value="%1">' +
    ' <param name="_ExtentX" value="10571">' +
    ' <param name="_ExtentY" value="7925">' +        // All numbers through trial and error
    sNNText +
    '</object>';
}

function GetImageObject ()
{
  return '<img src="%1" alt="Hot Marketer Multimedia Presentation."' +
    ' width="400" height="300"' +
    '>';
}

function WriteButtonBar ()
{
  var sText;
  sText = GetFlashObject ('HMButtonBar', 400, 22, '#FFFFFF');  // White BG
  window.document.write (sText.replace (/%1/, 'ButtonBar.swf'));
}

function WriteObject (sObjectType, sFilename)
{
  var sText;
  if ('Flash' == sObjectType)       sText = GetFlashObject ('HMMovie', 400, 300, '#000000');  // Black BG
  else if ('IPIX' == sObjectType)   sText = GetIPIXObject ();
  else if ('Image' == sObjectType)  sText = GetImageObject ();
  else
  {
    // window.alert ('Unknown object type ' + sObjectType);
  }

  window.document.write (sText.replace (/%1/, sFilename));
}


// ---------------------------------------------------------
// Event handler from flash movie
function HMMovie_DoFSCommand (command, args)
{
  command = command.toLowerCase ();
  if ('sendemail' == command)
  {
    window.open ('mailto:' + args); // opens two windows; unavoidable
  }

  else if ('showipix' == command)
  {
    ShowPopupIPIX (args);
  }

  else if ('showflashfile' == command)
  {
    ShowPopupFlash (args);
  }

  else if ('stopped' == command)
  {
    PlayButtonBar (nCurrSegment >= c_nNumSegments ? 'lblRewind' : 'lblNext');
  }

  else
  {
    // window.alert ('Movie command ' + command + ' (' + args + ') not implemented!');
  }
}


// ---------------------------------------------------------
// Event handler from Button Bar
function PlayNextSegment ()
{
  PlayButtonBar ('lblBlank');

  oHMMovie.Play ();
  ++nCurrSegment;
}

function PlayButtonBar (sLabel)
{
  if (oHMButtonBar.PercentLoaded () < 100)
  {  // not fully loaded; try again after 1 sec
    window.setTimeout ('PlayButtonBar ("' + sLabel + '");', 100);
  }
  else
  {
    with (oHMButtonBar)
    {
      TGotoLabel ('/', sLabel);
      Play ();
    }
  }
}


function HMButtonBar_DoFSCommand (command, args)
{
  command = command.toLowerCase ();
  if ('next' == command)
  {
    PlayNextSegment ();
  }

  else if ('contact' == command)
  {
    ShowPopupFlash ('Contact.swf');
  }

  else if ('back' == command)
  { // popup windows only
    window.close ();
  }

  else if ('rewind' == command)
  {
    nCurrSegment = 0;
    oHMMovie.Rewind ();
    PlayNextSegment ();
  }

  else if ('about' == command)
  {
    ShowPopupInformation ();
  }

  else if ('close' == command)
  {
    window.close ();
  }

  else
  {
    // window.alert ('Button bar command ' + command + ' (' + args + ') not implemented!');
  }
}


// ---------------------------------------------------------
// code being executed
window.onError = ShowError;
var bIsNN = (navigator.appName == 'Netscape') ? true : false;
