// JavaScript Document

if ((navigator.appName == "Microsoft Internet Explorer") &&
    (navigator.platform != "MacPPC") &&
    (navigator.platform != "Mac68k")) {
  var browser = "IE"
} else {
  var browser = "Netscape"
}







function listVideoSources()
{
  var formInt = document.listFormInt
  var formExt = document.listFormExt
  var presetForm = document.listFormPreset;
  var form = document.WizardForm
  var imageType = '/mjpg/';
  var imageSource = 'video.mjpg';

  if ((1 > 1) ||
      ext_sources
     ) {
    document.write('<select name="videoList" onChange="selectView()" >');

    if ((1 == 1) &&
        !ext_sources
       ) {
      document.write('<option class="gray">&nbsp;----------------</option>');
    } else {
      for (i = 0; i < 1; i++) {
        var camera_nice_nbr = i + 1;
        document.write('<option value="' + imageType + '' + imageSource + '"');
        if (imageType + '' + imageSource == '/mjpg/video.mjpg' ||
            '/jpg/image.jpg' == '/mjpg/video.mjpg') {
          document.write(' selected');
        }

        document.write('>' + formInt['root_ImageSource_I' + i + '_Name'].value + '</option>');
      }
    }
var viewAppletIE = "no";
var viewAppletOther = "no";
// Don't show external sources while using Java applet as Default Viewer. An unsigned applet doesn't have permission to access remote hosts.
if (((browser == "IE") && (viewAppletIE == "no")) || ((browser != "IE") && (viewAppletOther == "no"))) {
    if (formExt.elements.length > 0) {
      for (i = 0; i < formExt.elements.length; i += 3) {
        var aTempString = formExt.elements[i].name
        var videoNr = aTempString.substring(20, aTempString.lastIndexOf('_'))
        var external = escape(formExt['root_ExternalVideo_E' + videoNr + '_ImagePath'].value);

          document.write('<option value="' + external + '"');
          if (formExt['root_ExternalVideo_E' + videoNr + '_ImagePath'].value == '/mjpg/video.mjpg')
            document.write(' selected');
          document.write('>' + formExt['root_ExternalVideo_E' + videoNr + '_Name'].value + '</option>');
      }
    }
}
    document.write('</select>');
//} else {
//  document.write(formInt.root_ImageSource_I0_Name.value);
  }
}

function zoom(size)
{
  var url = document.URL;

  if (url.indexOf("?") == -1) {
    url += "?size=" + size
  } else if (url.indexOf("size=") == -1) {
    url += "&size=" + size
  } else {
    var searchStr = "size=1"
    var replaceStr = "size=" + size
    var re = new RegExp(searchStr , "g")
    url = url.replace(re, replaceStr)
  }

  document.location = url;
}

var aNewImagePath;

function reloadPage()
{
  document.location = aNewImagePath;
}

function selectView()
{
  var form = document.WizardForm;
  var source = form.videoList.options[form.videoList.selectedIndex].value;
  var params = source.split('&');
  var newCamera = null;
  var presetName = null;

  if ((params[1] != null) && ("no" == "no")) {
    newCamera = (params[1].split('='))[1];
    presetName = unescape((params[2].split('='))[1]);
    changeView(params[0], newCamera, presetName);
  } else {
    changeView(source, newCamera, presetName);
  }
}

function changeView(imagePath)
{
  var args = changeView.arguments;
  var newCamera  = (args.length >= 2 ? args[1] : null);
  var presetName = (args.length >= 3 ? args[2] : null);
  var newSize    = (args.length >= 4 ? args[3] : null);
  var other      = (args.length >= 5 ? args[4] : null);

  var reload = false;
  // the whole Live View design is built on page reload >-(
  // must reload initial sequence mode view to toggle buttons etc
  reload = (other != null && other.search("seq=yes"));
  var delay = 0;

  reload |= (imagePath != '/mjpg/video.mjpg');
  if (reload) {
    var size = newSize;

    if (size == null) {
      size = 1;
    }
    if (size != null) {
      size = '&size=' + size;
    }
    aNewImagePath = '/view/view.shtml?imagePath=' + imagePath + size;
    if (other != null)
      aNewImagePath += other;
    setTimeout("reloadPage()", delay);
  }
}

var seqNext = null;

function doSequence(size) {
  var formSeq = document.listFormSeq;
  var formExt = document.listFormExt;
  var presetForm = document.listFormPreset;
  var seqSources = new Array();
  var seqNumbers = new Array();
  var seqTimes = new Array();
  var cameraNbr;
  var presetName = null;
  var imagePath;
  var next;

  for (var i = 0; i < formSeq['root_Sequence_S0_NbrOfSources'].value; i++) {
    seqSources[i] = formSeq['root_Sequence_S0_Source_S' + i + '_Type'].value;
    seqNumbers[i] = formSeq['root_Sequence_S0_Source_S' + i + '_Number'].value;
    seqTimes[i] = formSeq['root_Sequence_S0_Source_S' + i + '_Time'].value;
  }

  if (seqNext != null) {

    next = seqNext;
  } else {
    next = 0;
  }

  imagePath = "";
  if (seqSources[next] == 'Ext') {
    imagePath = formExt['root_ExternalVideo_E' + seqNumbers[next] + '_ImagePath'].value;
  }
  else if (seqSources[next] == 'Quad') {
    cameraNbr = 'quad';
  } else {
    cameraNbr = parseInt(seqNumbers[next]) + 1;
  }

  if (imagePath == "") {
      imagePath = '/mjpg/' + cameraNbr + '/video.mjpg';
  }

  var nextNext;
  if (formSeq['root_Sequence_S0_RandomEnabled'].value == "yes")
    nextNext = Math.floor(Math.random() * formSeq['root_Sequence_S0_NbrOfSources'].value);
  else
    nextNext = next + 1;
  if (nextNext >= formSeq['root_Sequence_S0_NbrOfSources'].value)
    nextNext = 0;

  seqNext = nextNext;
    changeView(imagePath, cameraNbr, presetName, size, '&seq=yes&next=' + nextNext + '&sequencetime=' + seqTimes[next]);

    t1 = setTimeout("doSequence(size)", 1000 * seqTimes[next]);
}


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=' + 320
  openPopUp(page, 'Take_snapshot' + [no] + '', 320 + 45, 240 + 75 )
}
function movepic(img_name, img_src)
{
  document[img_name].src = img_src;
}

function auto(Path)
{
  parent.frames[1].location = Path
}

function AbsoluteOrRelative(form)
{
  var url = document.URL;
  if (form.AbsOrRel.selectedIndex == 0)
    var relative = "no";
  else
    var relative = "yes_no_cross";
  if (url.indexOf("?") == -1) {
    url += "?relative=" + relative;
  } else if (url.indexOf("relative=") == -1) {
    url += "&relative=" + relative;
  } else {
    var searchStr = "relative=";
    var replaceStr = "relative=" + relative;
    var re = new RegExp(searchStr , "g");
    url = url.replace(re, replaceStr);
  }
  document.location = url;
}  

function video(imagepath,hostcam,resolution_string,Xwidth,Yheight)
{
  var resolution = resolution_string
  var width = Xwidth
  var height = Yheight
  
 
    
  
	//------------------------ IF
  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)))
   
  }
  	//------------------------ end if
	

	//------------------------ IF
  if ((imagepath.indexOf("rotation=90") != -1) || (imagepath.indexOf("rotation=270") != -1)) {
    var aTempWidth = width
    width = height
    height = aTempWidth
    resolution = width + 'x' + height
  }
  	//------------------------ end if
 
    
	//------------------------ IF
  if ('1' != '1') {
    width = width * 1
    height = height * 1
  }
  	//------------------------ END IF
	
  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
  if ((navigator.appName == "Microsoft Internet Explorer") && (navigator.platform != "MacPPC") && (navigator.platform != "Mac68k")) {
    viewer = "activex";
  } else {
    viewer = "spush";
  }
  	//------------------------ end if


  if (viewer.indexOf("activex") != -1) {
    use_activex = 1;
  }
  if (viewer.indexOf("spush") != -1) {
    use_spush = 1;
  }
  if (viewer.indexOf("flash") != -1) {
    use_flash = 1;
  }
  if (viewer.indexOf("quicktime") != -1) {
    use_quicktime = 1;
  }
  ///mjpg/video.mjpg
  	//------------------------ IF
  if (imagepath.indexOf("mpeg4") != -1) {
    if ((navigator.appName == "Microsoft Internet Explorer") && (navigator.platform != "MacPPC") && (navigator.platform != "Mac68k")) {
        use_quicktime = 0;
        use_activex = 1;
    } else {
      use_quicktime = 1;
      use_spush = 0;
      use_still = 0;
    }
  } else {
    if ((navigator.appName == "Microsoft Internet Explorer") && (navigator.platform != "MacPPC") && (navigator.platform != "Mac68k")) {
        use_quicktime = 0;
        use_activex = 1;
    } else {
      use_quicktime = 0;
      use_spush = 1;
      use_still = 0;
    }
  }
  	//------------------------ end if
	
		//------------------------ IF
  if (viewer.indexOf("java") != -1) {
    if (imagepath.indexOf("mpeg4") == -1) {
      use_java = 1;
      use_activex = 0;
      use_spush = 0;
      use_flash = 0;
      use_still = 0;
      use_quicktime = 0;
    }
  }
  	//------------------------ end if
	
  	//------------------------ IF
  if ((viewer.indexOf("still") != -1) || !(use_activex || use_spush || use_flash || use_java || use_quicktime)) {
    if (imagepath.indexOf("mpeg4") == -1) {
      use_still = 1;
      use_quicktime = 0;
      use_spush = 0;
      use_activex = 0;
    } else {
      if ((navigator.appName == "Microsoft Internet Explorer") && (navigator.platform != "MacPPC") && (navigator.platform != "Mac68k")) {
        use_activex = 1;
      } else {
        use_quicktime = 1;
      }
    }
  }
   	//------------------------ end if
	
	
  if (navigator.userAgent.indexOf("Safari") != -1) {
    if (use_spush) {
      use_java = 1;
      use_spush = 0;
    }
  }

  //document.write ("use_activex " + use_activex + "<br>");
  
  	//------------------------ IF
  if (use_activex) {
   //document.write ("use_activex " + use_activex + " - true <br>");
    height = height + 54
    var notAuthorizedText = "The installation of the MPEG-4 Decoder has been disabled. Contact the Administrator of this AXIS 211A.";
    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 <a href=\"javascript:launch('/incl/license.shtml')\">install or upgrade</a> 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 211A 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 211A can also be configured to show still images.";

	//testAMC (hostcam);
	//alert ("0 - " + hostcam);
    DrawAMC("AXIS 211A", "AXIS Media Control", height, width, imagepath, "DE625294-70E6-45ED-B895-CFFA13AEB044", "AMC.cab", "3,32,14,0", "yes", "", "", "1", "", "", "no", "yes", "554", "no",installText1, videoText, installText2, installText3, installText4, "0", "no", hostcam);
	


    if (imagepath.indexOf("mpeg4") != -1) {
	alert('mpeg4')
      InstallDecoder("AXIS 211A", "MPEG-4 Decoder", "32c11e38-e587-4be9-9abb-d69158c21ce5", "NotFound.cab", "1,2,53,50725", "yes", notAuthorizedText, authorizedText, installDecoderText1, installDecoderText2);
      InstallFilter("AXIS 211A", "MPEG RTP Reader", "67B1A88A-B5D2-48B1-BF93-EB74D6FCB077", "1,4,13,0", "AMC.cab", installText1, videoText, installText2, installText3, installText4,hostcam);
      InstallFilter("AXIS 211A", "Image Notify Component", "0173EEF5-1FDE-479C-9F24-34C3CB0B3243", "1,2,0,0", "AMC.cab", installText1, videoText, installText2, installText3, installText4,hostcam);
    }

    InstallFilter("AXIS 211A", "AudioComponent", "C111A91F-D4EC-4D22-8D27-C3BCB0389F43", "1,11,3,8", "AMC.cab", installText1, audioText, installText2, installText3, installText4,hostcam);

    document.write("<br>");
  }
  	//------------------------ end if


	//------------------------ IF
  if (use_spush) {
     document.write ("use_spush " + use_spush + "<br>");
      var output = '<img SRC="' + imagepath + '" ' + width_height;
      var view_NoImageTxt = "If no image is displayed, there might be too many viewers, or the browser configuration may have to be changed. See help for detailed instructions on how to do this."
      output += ' border=0 ALT="' + view_NoImageTxt + '">';
    output += '<br>';
    document.write(output);
  }
  	//------------------------ end if

	//------------------------ IF
  if (use_quicktime) {
    var DisplayWidth = width;
    var DisplayHeight = height  + 16;
    if (imagepath.indexOf("://") == -1)
      //var MediaURL = "rtsp://" + location.hostname + imagepath
	  var MediaURL = "rtsp://" + imagepath
    else
      var MediaURL = imagepath
    var output = "";
    output  = '<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width=' + DisplayWidth + ' height=' + DisplayHeight + ' CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">';
    output += '<param name="src" value="AxisMoviePoster.mov">';
    output += '<param name="autoplay" value="true">';
    output += '<param name="controller" value="true">';
    output += '<param name="qtsrc" value="' + MediaURL + '">';
    output += '<embed src="AxisMoviePoster.mov" width=' + DisplayWidth + ' height=' + DisplayHeight + ' qtsrc="' + MediaURL + '" autoplay="true" controller="true" target="myself" PLUGINSPAGE="http://www.apple.com/quicktime/download/"></embed>';
    output += '</OBJECT>';
    document.write(output);
  }
  	//------------------------ end if

	//------------------------ IF
  if (use_flash) {
    var view_NeedFlashPluginTxt = "You need a Shockwave Flash plugin, get it from:"
    document.write('<EMBED src="/axis-cgi/mjpg/video.swf?resolution=' + resolution +'&camera=1" ' +
    'quality=high bgcolor=#000000 ' + width_height +
    ' TYPE="application/x-shockwave-flash" swLiveConnect=TRUE' +
    ' PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">' +
    '</EMBED>' +
    '<NOEMBED>' + view_NeedFlashPluginTxt +
    '<a href="http://www.macromedia.com/shockwave/download/">Macromedia</a>.' +
    '</NOEMBED><br>');
  }
  	//------------------------ end if

	//------------------------ IF
  if (use_java) {
    var playerWidth = 320
    if (("yes" == "yes") || ("" == "yes")) {
      if (("yes" == "yes") && ("" == "yes")) {
        if (playerWidth < 431)
          playerWidth = 431
      } else {
        if (playerWidth < 288)
          playerWidth = 288
      }
    }
      var playerHeight = 240 + 85
    if (imagepath.indexOf("http") != -1) {
      var addrEnd = imagepath.indexOf("/", 8)
      var addr = imagepath.substring(0, addrEnd)
    } else {
      var addr = ""
    }
    document.write('<APPLET archive="ama.jar" codeBase="/java" code="AxisMediaApplet" width="' + playerWidth + '" height="' + playerHeight + '">');
    document.write('<PARAM NAME="code" VALUE="AxisMediaApplet">');
    document.write('<PARAM NAME="archive" VALUE="ama.jar">');
    document.write('<PARAM NAME="codebase" VALUE="/java">');
    document.write('<PARAM NAME="cache_archive" VALUE="ama.jar, ama-audio.jar">');
    document.write('<PARAM NAME="cache_version" VALUE="0.12.0.0, 0.12.0.0">');
    document.write('<PARAM NAME="type" VALUE="application/x-java-applet;version=1.4">');
    document.write('<PARAM NAME="ama_url" VALUE="' + addr + '/axis-cgi/mjpg/video.cgi?camera=1&resolution=640x480">');
    document.write('<PARAM NAME="ama_audio" VALUE="yes">');
    document.write("</APPLET><br>");
  }
  	//------------------------ end if


  if (use_still) {
  document.write ("use_still " + use_still + "<br>");
    var picturepath = imagepath.replace(/video/, "image")
    picturepath = picturepath.replace(/mjpg/g, "jpg")
    picturepath = picturepath.replace(/rtsp/, "http")
    picturepath = picturepath.replace(/mpeg4/g, "jpg")
    picturepath = picturepath.replace(/media.amp/g, "image.jpg")

    document.write('<img SRC="' + picturepath + '" border=0 ' + width_height +'><br>');
  }
  
}

function goto_camera(cam)
{
  cam = '';

  var imagePath;
    imagePath = '/mjpg/' + cam + 'video.mjpg';
  changeView(imagePath);
}

// -->