Dim myAjax
Dim webPageResults

Call checkAjaxInBrowser()

Sub processWebPage()
	If (myAjax.ajaxObject.readyState = 4) Then
		If (myAjax.ajaxObject.status = 200) Then
				webPageResults = myAjax.ajaxObject.responseText
		End If
	End If
End Sub

Sub checkAjaxInBrowser()
	Dim tempAjax
	
	Err.Clear
	On Error Resume Next
	Set tempAjax = CreateObject("Microsoft.XMLHTTP")
	
	If (Not IsObject(tempAjax)) Then
		MsgBox("Your browser is not compatible with this program, you must activate the ActiveX elements for this site." & vbCrLf &_
		"Go to Extras->Internet Options->Security, Select Custom and Enable ActiveX controls that are safe")
	End If
	
	Err.Clear
	Set tempAjax = Nothing
End Sub

Function callWebPage(urlToCall)
    webPageResults = ""
    Set myAjax = New AjaxPack
    
	Call myAjax.getAjaxRequest(urlToCall, "", "", "txt")

	callWebPage = webPageResults
End Function

Class AjaxPack
		Private m_ajaxObject
		Private m_fileType
		Private m_baseDomain
		Private m_addRandomNumber

    Private Sub Class_Initialize
        Set m_ajaxObject = CreateObject("Microsoft.XMLHTTP")
        m_fileType = "txt"
        m_baseDomain = "http://" & Window.location.hostname
        m_addRandomNumber = 0
    End Sub

    Private Sub Class_Terminate
        If IsObject(m_ajaxObject) Then
			    Set m_ajaxObject = Nothing
        End If
    End Sub

		Public Property Get fileType
			fileType = m_fileType
		End Property

		Public Property Let fileType(ByVal value)
			m_fileType = value
		End Property

		Public Property Get addRandomNumber
			addRandomNumber = m_addRandomNumber
		End Property

		Public Property Let addRandomNumber(ByVal value)
			m_addRandomNumber = value
		End Property

		Public Property Get ajaxObject
			Set ajaxObject = m_ajaxObject
		End Property

    Public Function getAjaxRequest(url, parameters, callBackFunc, fileType)
	    If (m_addRandomNumber = 1) Then
		    parameters = parameters & "&ajaxcachebust=" & Hour(Now) & Minute(Now) & Second(Now)
	    End If

      If IsObject(m_ajaxObject) Then
		    m_fileType = fileType
		    m_ajaxObject.onReadyStateChange = GetRef("processWebPage" & CStr(m_index))
		    'Call m_ajaxObject.Open("GET", url & "?" & parameters, True)
		    Call m_ajaxObject.Open("GET", url, False)
		    Call m_ajaxObject.Send()
	    End If
    End Function

    Public Function postAjaxRequest (url, parameters, callBackFunc, fileType)
      If IsObject(m_ajaxObject) Then
		    m_fileType = fileType
		    m_ajaxObject.onReadyStateChange = callBackFunc
		    Call m_ajaxObject.open("POST", url, False)
		    Call m_ajaxObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
		    Call m_ajaxObject.setRequestHeader("Content-length", Len(parameters))
		    Call m_ajaxObject.setRequestHeader("Connection", "close")
		    Call m_ajaxObject.send(parameters)
	    End If
    End Function
End Class
