//ActiveX Object Defines
var AXOBJECT_ID = "AxPlayer";
var AXOBJECT_PATH = "AxViewer/";
var AXOBJECT_GEN_PATH = "AxViewer_GEN/";
var AXOBJECT_NAME = "AxMediaPlayer.cab";
var AXOBJECT_GEN_NAME = "AxMediaPlayer.exe";
var AXOBJECT_VER = "2,11,0,6224";
var user = SendCGICMD("/cgi-bin/view/hello");
var TEMP_USER_NAME = GetQueryVariableEx2("UserName", user);
var TEMP_PASSWORD = GetQueryVariableEx2("Password", user);
// do NOT change these two lines
//var GET_USER_NAME = "";
//var GET_PASSWORD = "";
// do NOT change these two lines
//Video Stream Defines
var PROFILE = "0";
var PROTOCOL_TYPE = "3"; //(set as cookie on client PC) 1->TCP, 2->UDP, 3->HTTP 4->Multicast  ,default connect order  TCP->UDP->HTTP
var g_szProtocolType = "3";
var MPEG4_ACCESS_NAME = "video.mp4";
var MJPEG_ACCESS_NAME = "video.mjpg";
var MULTICAST_ACCESS_NAME = "multicast.mp4";
var RECORDER_SUPPORT = "1";
var VIDEO_FMT = 1;
var PLUGIN_LANG=0;
var INITMODE = "none";
var CAPTEXT = "Live view";
var STATUSBAR = 0;
var TOOLBAR = 0;
var TOOLTIP = 0;
var CONTEXTMENU = 0;
var TOOLBARCONF = "stream+rec+mic+zoom+time";
var AUTOSTART = 0;
var VIEW_SIZE = "320x240";
var vdoWidth = 710;
var vdoHeight = 410;
var Buffer_Enable = getBufferEn();
var _platform = navigator.platform;
var HOST_NAME=location.hostname;
var HOST_PORT = location.port;
var HOST_SSL_PORT = 0;
var HOST_PROTOCOL = location.protocol;
var PUPOPS = 0;
var ADVANCED = 0;
var RecordSize = 200;
if(HOST_PROTOCOL=="https:")
{
  if(HOST_PORT==0 || HOST_PORT=="")
    HOST_SSL_PORT = 443;
  else
    HOST_SSL_PORT = HOST_PORT;
}
if(HOST_PORT==0 || HOST_PORT=="")
  HOST_PORT = 80; //default port
var mydate = new Date();
var imgURL;
var imgSrc = new Image();
GetDeviceInfo('Properties.Firmware.ActiveXID&group=Properties.PTZ.PTZ&group=General.Network&group=ImageSource.RecordIndex&group=Properties.IVS&group=IVS','view');
var CLASS_ID=GetQueryVariable('Properties.Firmware.ActiveXID');
var PTZSupport=GetQueryVariable('Properties.PTZ.PTZ');
var PTZMouseCtl = 0;
var RTSP_PORT = GetQueryVariable('General.Network.RTSP.Port');
var RecordIndex = GetQueryVariable('ImageSource.RecordIndex');
var system_ivs_support = GetQueryVariableEx2("root.Properties.IVS.IVSSupport", devCfg);
function SetPTZMouseCtrl()
{
  if(PTZtype=="ExtPTZ" || PTZtype == "PT" || PTZtype == "ExtPT")
  {
    PTZMouseCtl = 1;
  }else{
    PTZMouseCtl = 0;
  }
	
	if(Lenstype == "fisheye")
	{
		PTZMouseCtl = 1;
	}
}
function RGB(r,g,b)
{
  return (b*65536+g*256+r);
}
function refreshImg()
{
  var imgObj = document.getElementById('jpeg');
  var newURL;
  if (imgObj)
  {
	  newURL = '/cgi-bin/view/image?pro_' + RecordIndex + '&' + (new Date()).getTime();
    imgObj.src = newURL;
    imgObj.onload=refreshImg;
    imgObj.onerror=refreshImg;
  }
}
function DispImage()
{
	var imgObj = document.getElementById('jpeg');
	imgObj.src=imgURL;
}
function Viewer()
{
  if( getOs().indexOf("IE") >= 0 ){
    SetPTZMouseCtrl();
  	document.open();
    if(STATUSBAR==1)
  	  vdoHeight+=25;
  	if(TOOLBAR==1)
  	  vdoHeight+=30;
  	document.write("");
  	document.close();
	}else{
    if(INITMODE == "md" || INITMODE == "ad" || INITMODE == "mask")
    {
      return;
    }else{
      document.open();
      document.write("![]() ");
      document.close();
      imageProfile = RecordIndex;
      updateImgByProfile("jpeg");
    }
  }
}
function IVS_Viewer(tri_width, tri_height, type)
{
	 var IVS_enable,Polygon;
	 
   SetPTZMouseCtrl();
		
  	document.open();
		vdoWidth = tri_width;
		vdoHeight = tri_height;
	
	PROFILE = "4";
  	document.write("");
  	document.close();
}
function NormalViewer(width,height,rotate)
{
  var tmp = "";
  if(_platform.toLowerCase().indexOf("mac") >= 0)
  {
    if (PlatformSupport=="HI3516C")
    {
      if(VIEW_SIZE == "Large")
        {AppletWidth=800;AppletHeight=(450+58);vdoWidth=800;vdoHeight=450;}
      else if(VIEW_SIZE == "Medium")
        {AppletWidth=400;AppletHeight=(225+58);vdoWidth=400;vdoHeight=225;}
      else
        {AppletWidth=400;AppletHeight=395;}
    }
    else
    {
      if(VIEW_SIZE == "Large")
        {AppletWidth=640;AppletHeight=(480+58);vdoWidth=640;vdoHeight=480;}
      else if(VIEW_SIZE == "Medium")
        {AppletWidth=320;AppletHeight=(240+58);vdoWidth=320;vdoHeight=240;}
      else
        {AppletWidth=320;AppletHeight=315;}     
    }
    if (rotate == true)
    {
        tmp = AppletWidth;
        AppletWidth = AppletHeight;
        AppletHeight = tmp;
        tmp = vdoWidth;
        vdoWidth = vdoHeight;
        vdoHeight = tmp;
    }
    document.writeln('
");
      document.close();
      imageProfile = RecordIndex;
      updateImgByProfile("jpeg");
    }
  }
}
function IVS_Viewer(tri_width, tri_height, type)
{
	 var IVS_enable,Polygon;
	 
   SetPTZMouseCtrl();
		
  	document.open();
		vdoWidth = tri_width;
		vdoHeight = tri_height;
	
	PROFILE = "4";
  	document.write("");
  	document.close();
}
function NormalViewer(width,height,rotate)
{
  var tmp = "";
  if(_platform.toLowerCase().indexOf("mac") >= 0)
  {
    if (PlatformSupport=="HI3516C")
    {
      if(VIEW_SIZE == "Large")
        {AppletWidth=800;AppletHeight=(450+58);vdoWidth=800;vdoHeight=450;}
      else if(VIEW_SIZE == "Medium")
        {AppletWidth=400;AppletHeight=(225+58);vdoWidth=400;vdoHeight=225;}
      else
        {AppletWidth=400;AppletHeight=395;}
    }
    else
    {
      if(VIEW_SIZE == "Large")
        {AppletWidth=640;AppletHeight=(480+58);vdoWidth=640;vdoHeight=480;}
      else if(VIEW_SIZE == "Medium")
        {AppletWidth=320;AppletHeight=(240+58);vdoWidth=320;vdoHeight=240;}
      else
        {AppletWidth=320;AppletHeight=315;}     
    }
    if (rotate == true)
    {
        tmp = AppletWidth;
        AppletWidth = AppletHeight;
        AppletHeight = tmp;
        tmp = vdoWidth;
        vdoWidth = vdoHeight;
        vdoHeight = tmp;
    }
    document.writeln('