<!--
Class Gauges	
Private moCol 'As Dictionary
Private moHTML 'As HTMLDocument
Private mnDataRvcd' As Long
Private moDom' As New DOMDocument
Private XMLPost,XMLPostW
Dim URL	 'wind
Dim URLW 'weather
Dim URLG 'Wind summary for gauges
Dim mnfetchws 'fetch summary counter, see OnReady
Sub Add(oGauge) ' As Gauge
If isempty(moCol) Then
    'Set moCol = New Collection
	Set moCol = CreateObject("Scripting.Dictionary")
End If
moCol.Add oGauge.ID,oGauge
End Sub
Sub Fetch(vCallBack,fForce)		
with XMLPost
if .readyState=0 or	.readyState=4 Or fForce then
	'uninitialized,or complete from last post, or force(reset interval)
	'(fForce becasue we cannot set a timeout)
	if mnfetchws>1 then
		.open  "POST", URLG, 1 'summary
		sSend="Type=GS" '(its a post not Get)
	else
		.open  "POST", URL, 1 'all wind xml
    end if
    .onreadystatechange =vCallBack'//set each time
    .setRequestHeader  "Content-Type", "application/x-www-form-urlencoded"
    .send sSend
end if
end with
end sub
Sub OnReady()
if XMLPost.readyState = 4 then
	NewData XMLPost.responseText		
	mnfetchws=mnfetchws+1  'flag to subsequently get summary		
	if mnfetchws>600 then mnfetchws=0 'reset every so often (get full xml)
end if
end Sub
Sub OnReadyW()
if XMLPostW.readyState = 4 then
	NewData XMLPostW.responseText			
end if
end Sub
sub FetchW(vCallBack,fForce)						
With XMLPostW
if .readyState=0 or	.readyState=4 Or fForce then
	.open  "POST", URLW, 1
    .onreadystatechange =vCallBack';//set each time
    .setRequestHeader  "Content-Type", "application/x-www-form-urlencoded"
    .send ""
end if
end with
end sub

Property Set HTMLDocument(oHTMLDocument)
	Set moHTML = oHTMLDocument
End Property
Sub SetInterval(nInterval)
	Dim v' As Gauge
	For Each v In moCol.items
		v.SetInterval nInterval
	Next
End Sub

'tightly coupled to the script
Sub Init(oHTMLDocument)
Dim o' As Gauge
Dim sNQBase'  As String
mnDataRvcd = 0
set HTMLDocument=oHTMLDocument

if instr(1,oHTMLDocument.location ,"rycv.asn.au",1) then	
	URL="data/WindXML.asp"
	URLW="data/WeatherXML.asp"
	URLG="data/WindXML.asp?Type=GS"
else 'local
	URL="Stations.asmx/WindXML"
	URLW="Stations.asmx/WeatherXML"
	URLG="Stations.asmx/GaugeString"		
'URL="http://www.rycv.asn.au/weather/data/WindXML2.asp"
'	URLW="http://www.rycv.asn.au/weather/data/WeatherXML2.asp"
'	URLG="http://www.rycv.asn.au/weather/data/WindXML2.asp?Type=GS"
end if	
'MSXML2.ServerXMLHTTP would allow the setting of timeouts
'but does not work on @9x
set XMLPost=CreateObject("MSXML2.XMLHTTP")			
set XMLPostW=CreateObject("MSXML2.XMLHTTP")			

'******************
'<!--Marina Wind Gauge (mw), pointer (mwp), max and min and animate tag (amwp)-->
'************************************************************
sNQBase = "//Current[@StationID='MAR']/"
Set o = New Gauge
With o
    .ID = "mwp" 'same as the id of the html
    .NodeQuery = sNQBase & "Degrees"
    .PropertyName = "rotation" 'nb case sensitive
    Set .ValueObject = moHTML.mwp.Style
    Set .AnimateObject = moHTML.amwp
    .IsCompass = True
End With
Add o
'************************************************************
sNQBase = "//WindSummary[@Type='Moving' and @StationID='MAR']/"
Set o = New Gauge
With o
    .ID = "mwpmax" 'same as the id of the html
    .NodeQuery = sNQBase & "DegreesMax"
    .PropertyName = "rotation" 'nb case sensitive
    Set .ValueObject = moHTML.mwpmax.Style
    Set .AnimateObject = moHTML.amwpmax
    .IsCompass = True
End With
Add o
'************************************************************
sNQBase = "//WindSummary[@Type='Moving' and @StationID='MAR']/"
Set o = New Gauge
With o
    .ID = "mwpmin" 'same as the id of the html
    .NodeQuery = sNQBase & "DegreesMin"
    .PropertyName = "rotation" 'nb case sensitive
    Set .ValueObject = moHTML.mwpmin.Style
    .IsCompass = True
    Set .AnimateObject = moHTML.amwpmin
End With
Add o

'<!--Marina Speed Gauge (ms), pointer (msp), max and min and animate tag (amsp)-->
'************************************************************
sNQBase = "//Current[@StationID='MAR']/"
Set o = New Gauge
With o
    .ID = "msp"
    .NodeQuery = sNQBase & "Knots"
    .PropertyName = "rotation"
    .Conversion = (360 - 30) / 60 'from knots to a  rotation to suit the dial
                                    'dial does not go full circle
    Set .ValueObject = moHTML.msp.Style
    Set .AnimateObject = moHTML.amsp
End With
Add o
'************************************************************
sNQBase = "//WindSummary[@Type='Moving' and @StationID='MAR']/"
Set o = New Gauge
With o
    .ID = "mspmax" 'same as the id of the html
    .NodeQuery = sNQBase & "SpeedMax"
    .Conversion = (360 - 30) / 60 'from knots to a  rotation to suit the dial
    .PropertyName = "rotation" 'nb case sensitive
    Set .ValueObject = moHTML.mspmax.Style
    Set .AnimateObject = moHTML.amspmax
End With
Add o
'************************************************************
sNQBase = "//WindSummary[@Type='Moving' and @StationID='MAR']/"
Set o = New Gauge
With o
    .ID = "mspmin" 'same as the id of the html
    .NodeQuery = sNQBase & "SpeedMin"
    .PropertyName = "rotation" 'nb case sensitive
    .Conversion = (360 - 30) / 60 'from knots to a  rotation to suit the dial
    Set .ValueObject = moHTML.mspmin.Style
    Set .AnimateObject = moHTML.amspmin
End With
Add o


'<!--Club House Wind Gauge (cw), pointer (cwp), max and min and animate tag (acwp)-->
'************************************************************
sNQBase = "//Current[@StationID='CLU']/"
Set o = New Gauge
With o
    .ID = "cwp" 'same as the id of the html
    .NodeQuery = sNQBase & "Degrees"
    .PropertyName = "rotation" 'nb case sensitive
    Set .ValueObject = moHTML.cwp.Style
    Set .AnimateObject = moHTML.acwp
    .IsCompass = True
End With
Add o
'************************************************************
sNQBase = "//WindSummary[@Type='Moving' and @StationID='CLU']/"
Set o = New Gauge
With o
    .ID = "cwpmax" 'same as the id of the html
    .NodeQuery = sNQBase & "DegreesMax"
    .PropertyName = "rotation" 'nb case sensitive
    Set .ValueObject = moHTML.cwpmax.Style
    Set .AnimateObject = moHTML.acwpmax
    .IsCompass = True
End With
Add o
'************************************************************
sNQBase = "//WindSummary[@Type='Moving' and @StationID='CLU']/"
Set o = New Gauge
With o
    .ID = "cwpmin" 'same as the id of the html
    .NodeQuery = sNQBase & "DegreesMin"
    .PropertyName = "rotation" 'nb case sensitive
    Set .ValueObject = moHTML.cwpmin.Style
    .IsCompass = True
    Set .AnimateObject = moHTML.acwpmin
End With
Add o
'Club House Speed Gauge (cs), pointer (csp), max and min and animate tag (acsp)-->
'************************************************************
sNQBase = "//Current[@StationID='CLU']/"
Set o = New Gauge
With o
    .ID = "csp"
    .NodeQuery = sNQBase & "Knots"
    .PropertyName = "rotation"
    .Conversion = (360 - 30) / 60 'from knots to a  rotation to suit the dial
                                    'dial does not go full circle
    Set .ValueObject = moHTML.csp.Style
    Set .AnimateObject = moHTML.acsp
End With
Add o
'************************************************************
sNQBase = "//WindSummary[@Type='Moving' and @StationID='CLU']/"
Set o = New Gauge
With o
    .ID = "cspmax" 'same as the id of the html
    .NodeQuery = sNQBase & "SpeedMax"
    .Conversion = (360 - 30) / 60 'from knots to a  rotation to suit the dial
    .PropertyName = "rotation" 'nb case sensitive
    Set .ValueObject = moHTML.cspmax.Style
    Set .AnimateObject = moHTML.acspmax
End With
Add o
Set o = New Gauge

With o
    .ID = "cspmin" 'same as the id of the html
    .NodeQuery = "//Moving/CLU/SpeedMin"
    .NodeQuery = sNQBase & "SpeedMin"
    .PropertyName = "rotation" 'nb case sensitive
    .Conversion = (360 - 30) / 60 'from knots to a  rotation to suit the dial
    Set .ValueObject = moHTML.cspmin.Style
    Set .AnimateObject = moHTML.acspmin
End With
Add o

'******times of last update
sNQBase = "//Current[@StationID='MAR']/"
Set o = New Gauge
With o
    .ID = "mtr" 'same as the id of the html
    .Conversion=Empty
    .NodeQuery = sNQBase & "TimeRcvd"
    .PropertyName = "innerHTML" 'nb case sensitive
    Set .ValueObject = moHTML.mtr
    set .AnimateObject=nothing
End With
Add o
Set o = New Gauge
sNQBase = "//Current[@StationID='CLU']/"
With o
    .ID = "ctr" 'same as the id of the html
    .Conversion=Empty
    .NodeQuery = sNQBase & "TimeRcvd"
    .PropertyName = "innerHTML" 'nb case sensitive
    Set .ValueObject = moHTML.ctr 'time received
	set .AnimateObject=nothing
End With
Add o

End Sub

Sub NewData(ByVal sXML)
Dim oNode' As IXMLDOMNode
Dim sN' As String

If Len(sXML) = 0 Then Exit sub
'soap message is encoded and embedded inside a string element
sXML = Replace(Replace(sXML, "&gt;", ">"), "&lt;", "<")
sXML = Replace(sXML, "@$", " ") 'known replacement! (in Relay Server)'not required??30 3 03
'soap is wrapped in a string node.
'but asp is plain xml
if isempty(moDom) then
	set moDom=CreateObject("MSXML2.DOMDocument")
end if
If Not moDom.loadXML(sXML) Then
        Exit sub
End If
Set oNode = moDom.selectSingleNode("//")
If oNode Is Nothing Then Exit Sub
If oNode.nodeName = "string" OR oNode.nodeName = "xml" Then
    Set oNode = moDom.selectSingleNode("string")
    If oNode Is Nothing Then Exit Sub
    If oNode.childNodes.Item(0) Is Nothing Then Exit Sub
    sN = oNode.childNodes.Item(0).nodeName
    Set oNode = moDom.selectSingleNode("string/" & sN)
    If oNode Is Nothing Then Exit Sub
End If
If oNode.nodeName = "GS" Then 'string for gauges
    'NewData=
    NewDataGS  oNode.Text
    TotalData sXML
    Exit Sub
ElseIf oNode.nodeName = "WeatherXML" Then
    'moHTML.XMLDSO.XMLDocument.loadXML oNode.xml
    Set oNode = oNode.selectSingleNode("Current")
    If oNode Is Nothing Then Exit Sub
    moHTML.XMLDSO.loadXML oNode.xml
    TotalData sXML
    'NewData=True
    Exit Sub
End If

If moDom.loadXML(oNode.xml) Then
   'tell the gauges
    Dim v    
    For Each v In moCol.Items
       v.NewData moDom
    Next
End If
TotalData sXML
'NewData=True
End sub
Private Sub TotalData(sXML) ' As String
mnDataRvcd = mnDataRvcd + Len(sXML) 'bytes
moHTML.datarcvd.innerHTML = FormatNumber(mnDataRvcd / 1000,2) & " KB @ " & FormatDateTime(Now,3)
End Sub
Sub Update()
Dim v' As Gauge
For Each v In moCol.Items
    v.Update    
Next
End Sub
Private Sub NewDataGS(sData)
'data of a particular string format to reduce xml size downloaded:
' for direct update of gauges. Format is id=value csv. id same as htl id
Dim vItem
Dim sID ' As String
Dim v

For Each vItem In Split(sData, ",")
    v = Split(vItem, "=")
    If UBound(v) > 0 and moCol.Exists(v(0)) Then        
        moCol(v(0)).NewDataValue v(1)
    'else bad data...
    End If
Next
'NewDataGS = true
End Sub

Function HelloWorld()
		HelloWorld="Hello World"
end function
end Class
-->