Class LocatorClass
	Public XML
	Private UpdateXML, LocatorType, URL, CacheDir, CacheTimeOut, FileName, XPath
	Private UpdateID, p_UpdateClients, p_UpdateClientID
	
	Private Sub Class_Initialize()
		UpdateID = -1
		p_UpdateClientID = 0
		Set p_UpdateClients = CreateObject("Scripting.Dictionary")
	End Sub

	Public Sub Initialize(setType, setURL, setCacheDir, setCacheTimeOut, SetFileName)
		LocatorType = setType
		URL = setURL
		'Alert(URL)
		CacheDir = setCacheDir
		CacheTimeOut = setCacheTimeOut
		FileName = setFileName
		set XML = Data.Objects("tools").GetXML(replace(URL,"{1}","-1"), CacheTimeOut, True, CacheDir, FileName)
		if XML is Nothing then exit Sub
		'Alert(left(XML.xml,200))
		UpdateID = Clng(XML.SelectSingleNode("//UpdateID").GetAttribute("Value"))
		'Alert(UpdateID)
		'alert("In LocatorClass type=" & LocatorType & vbcrlf & join(Data.Objects.keys,","))
	End Sub
	
	Public Sub Update()
		'Alert("Updating with updateid=" & UpdateID)
		set UpdateXML = Data.Objects("tools").GetXML(replace(URL,"{1}","" & UpdateID), 0, True, "", "")
		if UpdateXML is Nothing then exit Sub
		'Alert(UpdateXML.xml)
		For Each Node In UpdateXML.Selectnodes(LocatorType & "/L")
			'Alert(Node.Xml)
			Flag = True
			set oldNode = XML.SelectSingleNode(LocatorType & "/L[@ID=" & node.getattribute("ID") & "]")
			If Not IsNull(oldNode) then
				'alert("Oldnode:" & vbcrlf & oldNode.Xml & vbcrlf & "NewNode:" & vbcrlf & node.xml)
				For each a in Node.Attributes
					OldNode.SetAttribute a.Name, a.value
				Next
			End If
			on error resume next
				For Each Cl In p_UpdateClients.Items
					For Each N In GetLocators(OldNode, "." & Cl.Query)
										'if instr(CL.Query,"ID") > 0 then
										'	Alert(N.xml & vbcrlf & Cl.Query)
										'end if
						Cl.Obj.Update LocatorType, N, false
					Next
					if Data.Objects("session").DisplayTimeOut then
						For Each N In GetLocators(Node, ".[@DT='true']")
							Cl.Obj.Update LocatorType, N, false
						Next
					end if
				Next
			on error goto 0
		Next
		if Flag then
			UpdateID = Clng(UpdateXML.SelectSingleNode("//UpdateID").GetAttribute("Value"))
		end if
		'Alert(UpdateID)
	End Sub

	Public Function GetLocators(sXML, Query)
			Set GetLocators = sXML.Selectnodes(Query)
			'Alert("Getlocators.length=" & GetLocators.Length)
	End Function

	Public Function ShowLocators(Query)
		'Alert("Locator.class ShowLocators:" & vbcrlf & "LocatorType:" & LocatorType & vbcrlf & "Query:" & Query)
		set ShowLocators = GetLocators(XML, LocatorType & "/L" & Query)
	End Function
	
	Public Function RegisterForUpdate(Obj, Query)
		'Alert("In RegisterForUpdate")
		Set newUpdateClient = New UpdateClientClass
		Set newUpdateClient.Obj = Obj
				newUpdateClient.Query = Query
		Set p_UpdateClients.Item(p_UpdateClientID) = newUpdateClient
		registerForUpdate = p_UpdateClientID
		p_UpdateClientID = p_UpdateClientID + 1
	End Function

	Public Sub Unregister(ID)
		'Alert("In UnRegister")
		If p_UpdateClients.Exists(ID) Then
			p_UpdateClients.Remove(ID)
		End If
	End Sub	

End Class

Class UpdateClientClass
	Public	Obj, Query
End Class

