function openPopUp(thePage, theName, theWidth, theHeight)
{
  var someFeatures = 'scrollbars=yes,toolbar=0,location=no,directories=0,status=0,menubar=0,resizable=1,width=' + theWidth + ',height=' + theHeight;
  var aPopUpWin = window.open(thePage, theName, someFeatures);

  if (navigator.appName == "Netscape") {
    aPopUpWin.focus();
  }
}

if ((navigator.appName == "Microsoft Internet Explorer") &&
    (navigator.platform != "MacPPC") &&
    (navigator.platform != "Mac68k")) {
  var browser = "IE";
} else {
  var browser = "Netscape";
}

function snapshot(imagepath)
{
  var no = document.WizardForm.amount.value++
  var picturepath = imagepath.replace(/video/, "image")
  if (imagepath.indexOf("mpeg4") != -1)
  {
    picturepath = picturepath.replace(/rtsp/, "http")
    picturepath = picturepath.replace(/mpeg4/g, "jpg")
    picturepath = picturepath.replace(/media.amp/g, "image.jpg")
  } else {
    picturepath = picturepath.replace(/mjpg/g, "jpg")
  }
  var page = 'snapshot.shtml?picturepath=' + picturepath
  var time = new Date()
  var timestamp = time.getTime()

  page += '&timestamp=' + timestamp + '&width=' + 704
  openPopUp(page, 'Take_snapshot' + [no] + '', 704 + 45, 480 + 75 )
}

function video(imagepath)
{
  var resolution = "550x375" // 1.466666666666, 22/15, 550x375, 704x480
  var width = 550
  var height = 375

  if (imagepath.indexOf("resolution=") != -1) {
    var resStart = imagepath.indexOf("resolution=")
    var resStop = imagepath.indexOf("&", resStart)
    if (resStop == -1) resStop = imagepath.length
    resolution = imagepath.substring(resStart + 11, resStop)
    width = parseInt(resolution.substring(0, resolution.indexOf('x')))
    height = parseInt(resolution.slice((resolution.indexOf('x') + 1)))
  }

  if ((imagepath.indexOf("rotation=90") != -1) || (imagepath.indexOf("rotation=270") != -1)) {
    var aTempWidth = width
    width = height
    height = aTempWidth
    resolution = width + 'x' + height
  }
  var width_height = 'width="' + width + '" height="' + height + '"';
  var use_activex = 0;
  var use_java = 0;
  var use_spush = 0;
  var use_flash = 0;
  var use_still = 0;
  var viewer = "still";
  var use_quicktime = 0;

  if ((navigator.appName == "Microsoft Internet Explorer") && (navigator.platform != "MacPPC") && (navigator.platform != "Mac68k")) {
    viewer = "activex";
    use_activex = 1;
  } else {
    viewer = "spush";
    use_spush = 1;
    use_quicktime = 0;
    use_still = 0;
  }

  if (use_activex) {
	// IE support
    height = height + 54
    var notAuthorizedText = "The installation of the MPEG-4 Decoder has been disabled. Contact the Administrator of this AXIS 241S.";
    var authorizedText = "Click here to install or upgrade the MPEG-4 Decoder.";
    var installDecoderText1 = "<b>MPEG-4 Decoder</b>, which enables streaming video in Microsoft Internet Explorer, has not been installed or could not be registered on this computer.";

    var installDecoderText2 = "To install or upgrade the MPEG-4 Decoder, you must have Administration rights on this computer and you must answer Yes <br>when asked if you wish to allow the installation. AXIS 241S can also be configured to show still images.";

    var installText1 = "which enables streaming";
    var videoText = "video";
    var audioText = "audio";
    var installText2 = "in Microsoft Internet Explorer, has not been installed or could not be registered on this computer.";
    var installText3 = "To install or upgrade the";
    var installText4 = ", you must have Administration rights on this computer and you must answer Yes <br>when asked if you wish to allow the installation. AXIS 241S can also be configured to show still images.";

	// draw the activeX media control -- imagepath is key
    DrawAMC("AXIS 241S", "AXIS Media Control", height, width, imagepath, "745395C8-D0E1-4227-8586-624CA9A10A8D", "AMC.cab", "4,01,0,0", "yes", "no", "no", "1", "no", "yes", "no", "no", "554", "no", installText1, videoText, installText2, installText3, installText4, "0");
  }

  if (use_spush) {
	// firefox support
      var output = '<img src="' + imagepath + '" ' + width_height;
      var view_NoImageTxt = "If no image is displayed, there might be too many viewers, please try again."
      output += ' border="0" alt="' + view_NoImageTxt + '" />';
      //output += '<br />';
      document.write(output);
  }
}

// ActiveX Functions

function DrawTB(UseAudio, ImagePath, CamNbr, MediaRecording, HideMicSettings) // NOTE: HideMicSettings = "yes" for 207, otherwise it should be "no" (or undefined)
{
  if (document.Player) {
	  document.Player.ToolbarConfiguration = "+play,+snapshot,+fullscreen";
  }
}

function DrawAMC(prodName, ID, height, width, imagepath, CLSID_AMC, cab, ver_AMC, ShowAMCToolbar, ptzgui, useWithCam, camnbr, UseRel, ShowRelCross, UseMotion, UseAudio, rtspPort, external, installText1, text, installText2, installText3, installText4, mediaRecording, HideMicSettings) // NOTE: HideMicSettings = "yes" for 207, otherwise it should be "no" (or undefined)
{
  if (imagepath.indexOf("mjpg") != -1) {
	var mjpg = "yes";
  }
  document.write('<object id="Player" height="' + height + '" width="' + width + '" border="0" classid="CLSID:' + CLSID_AMC + '" codebase="/activex/' + cab + '#version=' + ver_AMC + '" standby="Loading Axis Media Control components...">');
  document.write('<param name="MediaURL" value="' + imagepath + '" />');
  if (mjpg == "yes") {
	document.write('<param name="MediaType" value="mjpeg-unicast" />');
  }
  if (HideMicSettings == "yes") {  // HideMicSettings defines 207 - No other relation between HideMicSettings and Volume=70
	document.write('<param name="Volume" value="70" />');
  }
  document.write('<param name="ShowStatusBar"');
  if (ShowAMCToolbar == "yes") {
	document.write('value="1">');
  } else {
	document.write('value="0">');
  }
  document.write('<param name="ShowToolbar"');
  if (ShowAMCToolbar == "yes") {
	document.write('value="1" />');
  } else {
	document.write('value="0" />');
  }
  document.write('<param name="AutoStart" value="1">');
  document.write('<param name="StretchToFit" value="1">');
  document.write('<b>' + ID + '</b>&nbsp;' + installText1 + '&nbsp;' + text + '&nbsp;' + installText2 + '&nbsp;' + installText3 + '<br />' + ID + '&nbsp;' + installText4);
  document.write('</object>');


  if (document.Player.ShowToolbar) { // This line is essential when installing AMC or else volume and mute buttons will show until reload
	document.Player.ToolbarConfiguration = "+play,+snapshot,+fullscreen";
  }
  document.Player.EnableContextMenu = "1";
}