dim wsQSIF,wsSIF,wsVGA 
wsQSIF = 0
wsSIF = 1
wsVGA = 2

dim caCamera_Up,caCamera_Left,caCamera_Right,caCamera_Down
caCamera_Up = 1  
caCamera_Left = 2
caCamera_Right = 4
caCamera_Down = 5 

dim caCamera_ZoomIn,caCamera_ZoomOut
caCamera_ZoomIn = 6 
caCamera_ZoomOut = 7

sub window_onunload()
   StreamSession1.StopSession
'   StreamSession2.StopSession

   Server.StopSession
end sub

sub button1_onClick()
  StreamSession1.Attach VideoWindow1.ObjectHandle
'  StreamSession2.Attach VideoWindow2.Handle 

  Server.Attach StreamSession1.Handle
'  Server.Attach StreamSession2.Handle
  
  dim ConnectInfo
  set ConnectInfo = CreateObject("SVActiveX.ConnectionInfo")
  ConnectInfo.PrimaryIP = serverip.value
  ConnectInfo.PrimaryPort = CInt(serverport.value)
  ConnectInfo.Username =  username.value
  ConnectInfo.Password = password.value
  
  Server.ConnectionInfo = ConnectInfo

  divConnect.style.visibility = "hidden"
end sub

sub CameraAction(id,Action)
  dim Executed,StreamSession
  set StreamSession = document.all(id)
  
  Executed = StreamSession.CameraAction(Action)
  if not Executed then msgbox "error!" + Cstr(Executed)
end sub


sub btnQSIF(id,video_id,desc_id)
  dim StreamInfo,StreamSession,VideoWindow
  set StreamSession = document.all(id)
  set VideoWindow = document.all(video_id)

  set StreamInfo = StreamSession.StreamInfoEx
  StreamInfo.StreamSize = wsQSIF
  StreamInfo.ProfileID = 0	
  
 
  if Not StreamSession.ChangeEx(StreamInfo) then exit sub

  VideoWindow.WindowSize = wsQSIF
  document.all(desc_id).InnerText = "CHANGING to QSIF"
end sub

sub btnSIF(id,video_id,desc_id)
  dim StreamInfo,StreamSession,VideoWindow
  set StreamSession = document.all(id)
  set VideoWindow = document.all(video_id)

  set StreamInfo = StreamSession.StreamInfoEx
  StreamInfo.StreamSize = wsSIF
  StreamInfo.ProfileID = 0		
  

  if Not StreamSession.ChangeEx(StreamInfo) then exit sub

  VideoWindow.WindowSize = wsSIF
  document.all(desc_id).InnerText = "CHANGING to SIF"
end sub

sub btnVGA(id,video_id,desc_id)
  dim StreamInfo,StreamSession,VideoWindow
  set StreamSession = document.all(id)
  set VideoWindow = document.all(video_id)

  set StreamInfo = StreamSession.StreamInfoEx
  StreamInfo.StreamSize = wsVGA
  
  StreamInfo.ProfileID = 0

  if Not StreamSession.ChangeEx(StreamInfo) then exit sub

  VideoWindow.WindowSize = wsVGA
  document.all(desc_id).InnerText = "CHANGING to VGA"
end sub

sub Item_Click(id)
  dim StreamInfo
  set StreamInfo = CreateObject("SVActiveX.StreamInfoEx")
  
  StreamInfo.ID = id
  StreamInfo.ProfileID = 0	




  StreamInfo.StreamSize = VideoWindow1.WindowSize
  
  StreamSession1.StartCameraSessionEx StreamInfo

  if pstreaminfo1.InnerText = "" then
	pstreaminfo1.InnerText = "CONNECTING"
  else
	pstreaminfo1.InnerText = "CHANGING Camera"
  end if
end sub

sub EventClick(id,EventTime,EventDuration)
  if EventDuration < 10 then EventDuration = 10 

  dim StreamInfo
  set StreamInfo = CreateObject("SVActiveX.StreamInfoEx")

  StreamInfo.ID = id
  StreamInfo.ProfileID = 0	
  StreamInfo.StreamSize = VideoWindow1.WindowSize
  
  dim Found
  Found = StreamSession1.StartPlaybackSessionEx(StreamInfo,CDate(EventTime),EventDuration)
  if not Found then
    pstreaminfo1.InnerText = "Record not found"
    exit sub
  end if 

  divVideoWindow1.style.visibility = "visible" 

  if pstreaminfo1.InnerText = "" then
    pstreaminfo1.InnerText = "CONNECTING"
  else
    pstreaminfo1.InnerText = "CHANGING to Recording"
  end if
end sub

sub window_onselectstart()
  window.status = "window_onselectstart"
  window.document.selection = ""
end sub

sub window_onselect()
  window.status = "window_onselect"
  window.document.selection = ""
end sub