Class ToolsClass
	Private XMLHTTP

	Private Sub Class_Initialize()
		set XMLHTTP = createobject("Microsoft.XMLHTTP")
	End Sub

	Public Function GetXML(URL)
		Dim Dir
		Randomize 1
		'if left(URL,37) = "/TopContent/webservices/Summary.asmx/" then
		'	alert(URL)
		'end if
		'Alert(URL)
		set XMLDOMDocument = CreateObject("MSXML2.DOMDocument")
		if right(URL,1)<>"?" then
			Q = URL & "&"
		else
			Q = URL
		end if
		Q = Q & MakeURL("{SESSIONID}&{COMMUNITYID}&{RND}")
		window.status = Q
		'Alert(Q)
		Err.Clear
		'on error resume next
		XMLHTTP.open "get", Q, false
		XMLHTTP.send
		'if left(URL,37) = "/TopContent/webservices/Summary.asmx/" then
		'	alert(XMLHTTP.responseText)
		'end if
		'alert(XMLHTTP.responseText)
		'window.status = "Hallo Stef *A1*"
		XMLDOMDocument.load XMLHTTP.responseXML
		'window.status = "Hallo Stef *A2*"
		if err then
		'window.status = "Hallo Stef *A3*"
			Set GetXML = Nothing
		else
		'window.status = "Hallo Stef *A4*"
			set GetXML = XMLDomDocument
		end if
		'window.status = "Hallo Stef *A5*"
	End Function

	Public Function GetHtml(URL)
		Dim Dir
		Randomize 1
		'Alert(URL)
		set XMLDOMDocument = CreateObject("MSXML2.DOMDocument")
		if right(URL,1)<>"?" then
			Q = URL & "&"
		else
			Q = URL
		end if
		Q = Q & MakeURL("{SESSIONID}&{COMMUNITYID}&{RND}")
		'window.status = Q
		'Alert(Q)
		Err.Clear
		'on error resume next
		XMLHTTP.open "get", Q, false
		XMLHTTP.send
		getHtml = XMLHTTP.responseText
	End Function



	Public Function MakeURL(url)
		url = Replace(url, "{RND}", "rnd=" & rnd(1))
		url = Replace(url, "{SESSIONID}", "SessionID=" & Data.Objects("session").ID & "&MenuMask=" & Data.Objects("session").MenuMask & "&companyid=" & Data.Objects("session").CompanyID)
		url = Replace(url, "{COMMUNITYID}", "CommunityID=" & Data.Objects("session").CommunityID)
		url = Replace(url, "{TIMEOFFSET}", "TimeOffset=" & Data.Objects("session").TimeOffset)
		For each key in Data.Objects("urlreplacements").Keys
			url = Replace(url, "{" & key & "}" , urlReplacements(key))
		Next
		MakeURL = url
	End Function

	Public Sub QSort(aData, iLb, iUb, CompareFunction, SwapFunction)
		Dim lbStack(32), ubStack(32), sp
		Dim iLbx, iUbx         ' current lower and upper-bound
		Dim m, p               ' index to pivot
		Dim i,j,t              ' temp used for exchanges

		if ubound(aData) < 0 then exit sub

		' Init stacks
		lbStack(0) = iLb
		ubStack(0) = iUb
		sp = 0
		Do While sp >= 0
			iLbx = lbStack(sp)
			iUbx = ubStack(sp)
			Do While (iLbx < iUbx)
				p = iLbx + (iUbx - iLbx) \ 2
				set t = aData(iLbx)
				set aData(iLbx) = aData(p)
				set aData(p) = t
				i = iLbx + 1
				j = iUbx
				Do
					Do While i < j
						if CompareFunction(aData(iLbx),aData(i)) then Exit Do
						i = i + 1
					Loop

					Do While j >= i
						if CompareFunction(aData(j),aData(iLbx)) then Exit Do
						j = j - 1
					Loop
					If i >= j Then Exit Do
					call SwapFunction(aData(i),aData(j))
					j = j - 1
					i = i + 1
				Loop

				call SwapFunction(aData(iLbx),aData(j))
				m = j
				If m - iLbx <= iUbx - m Then
					If m + 1 < iUbx Then
						lbStack(sp) = m + 1
						ubStack(sp) = iUbx
						sp = sp + 1
					End If
					iUbx = m - 1
				Else
					If m - 1 > iLbx Then
						lbStack(sp) = iLbx
						ubStack(sp) = m - 1
						sp = sp + 1
					End If
					iLbx = m + 1
				End If
			Loop
			sp = sp - 1
		Loop
	End Sub
End Class
