
	Dim FareHostHTTP
	Dim FareDBHTTP
	Dim FareQueList
	
	Set FareQueList		= CreateObject("Scripting.Dictionary") 
	Set FareHostHTTP	=  CreateObject("Scripting.Dictionary") 
	Set FareDBHTTP		=  CreateObject("Scripting.Dictionary") 

Sub FareRun(XML, DisXML, Slot)
	
	Dim msgQue, HTTP1, HTTP2
	
	if FareQueList.Exists(slot) Then
		Set msgQue = FareQueList.Item(Slot)
		msgQue.ClearParam
		msgQue.DisXML = DisXML

		if FareHostHTTP.Exists(slot) Then
			Set HTTP1 = FareHostHTTP.item(slot)
			HTTP1.Abort
		End If

		if FareDBHTTP.Exists(slot) Then
			Set HTTP2 = FareDBHTTP.item(slot)
			HTTP2.Abort
		End If
	Else
		Set msgQue = new FareMsgQueClass
		msgQue.DisXML = DisXML
		
		FareQueList.Add Slot, msgQue
		
		Set HTTP1 = CreateObject("Microsoft.XMLHTTP")
		Set HTTP2 = CreateObject("Microsoft.XMLHTTP")
		
		FareHostHTTP.Add Slot, HTTP1
		FareDBHTTP.Add Slot, HTTP2
	End if
	
	Call SendFareHost(XML, Slot)
	
End Sub 

Sub SendFareHost(XML, slot)

	Dim msgQue, xmldoc, rootNode, nodeMode, http
	
	Set msgQue		= FareQueList.Item(slot)
	Set http				= FareHostHTTP.Item(slot)
	
	msgQue.inXML	= XML
	
	Set xmldoc = CreateObject("Microsoft.XMLDOM")
	xmldoc.Async = False
	xmldoc.loadXML(XML)
	'-------------------------------------------------------------------------
	' XML LOAD EROR
	'-------------------------------------------------------------------------
	If (xmldoc.parseError.errorCode <> 0) Then
		Set objError = xmldoc.parseError
		msgQue.Code		= "F"
		msgQue.Msg		= "[request Parsing Error]" & objError.reason
		msgQue.outXML = returnXML(msgQue.Code, msgQue.Msg, "")
		Set objError = Nothing
		msgQue.HostState	= True
		msgQue.DBState		= True
		doFareFinish( slot )
		http.abort
		Exit Sub
	End If

	'-------------------------------------------------------------------------
	' ÀÛ¾÷±¸ºÐ XML NODE »ý¼º
	'-------------------------------------------------------------------------
	Set rootnode		= xmldoc.documentElement
	Set nodeCmd		= rootnode.appendChild(xmldoc.createElement("CMD"))
	nodeCmd.Text		= woSelect1
	'-------------------------------------------------------------------------
	' API MODE XML NODE »ý¼º
	'-------------------------------------------------------------------------
	Set nodeMode		= rootnode.appendChild(xmldoc.createElement("MODE"))
	nodeMode.Text	= CONST_API_FARE_MANAGER

	http.onReadyStateChange = GetRef("onFareHostState")
	http.Open "POST", PageName, True
	http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded;charset=euc-kr"
	http.Send( xmldoc )	
	
	'Set xmldoc = nothing
	
End Sub

Sub onFareHostState()
	Dim i, msgQue, xmldoc, rootNode, http, dbHTTP, KeyList, KeyIndex, objDOM1
	Dim ErrLog
	
	Set xmldoc	= CreateObject("Microsoft.XMLDOM")
	Set objDOM1	= CreateObject("Microsoft.XMLDOM")
	
	KeyList	= FareHostHTTP.Keys
	
	For i = 0 to FareHostHTTP.Count - 1 
		KeyIndex		= KeyList(i)
		Set http			= FareHostHTTP.Item( KeyIndex )
		Set dbHTTP		= FareDBHTTP.Item( KeyIndex )

		if FareQueList.Exists(KeyIndex) Then
			Set msgQue = FareQueList.Item(KeyIndex)
			 
			if (http.readyState = 4) and ( (not msgQue.DBState) and (not msgQue.HostState) ) Then
				Set msgQue = FareQueList.Item(KeyIndex)
				'-------------------------------------------------------------------------
				' Booking API Return XML 
				'-------------------------------------------------------------------------
				msgQue.HostXML = http.responseXML.xml
				msgQue.HostXML = Replace(msgQue.HostXML, "<?xml version=""1.0""", "<?xml version=""1.0"" encoding=""euc-kr""")
				msgQue.HostXML = Replace(msgQue.HostXML, "<!DOCTYPE fare_output SYSTEM ""http://asp.cyberbooking.co.kr/TopasApp/xml/fm_output.dtd"">", "")
				
				Set xmldoc = CreateObject("Microsoft.XMLDOM")
				xmldoc.Async = False
				xmldoc.loadXML(msgQue.HostXML)
				'http.abort

				'-------------------------------------------------------------------------
				' XML LOAD EROR
				'-------------------------------------------------------------------------
				If (xmldoc.parseError.errorCode <> 0) Then
					Set objError = xmldoc.parseError
					msgQue.Code		= "F"
					msgQue.Msg		= "[Host XML Parsing Error] "& objError.reason
					msgQue.outXML 	= returnXML(msgQue.Code, msgQue.Msg, "")
					ErrLog				= LogXML(msgQue.DisXML, msgQue.inXML, msgQue.HostXML)
					Set objError			= Nothing
					
					msgQue.HostState	= True
					msgQue.DBState		= True
					
					http.abort
					doFareFinish( KeyIndex )
					Exit Sub
				End If
				'-------------------------------------------------------------------------
				' HOST RESPONSE XML Error À¯¹« Ã¼Å©
				'-------------------------------------------------------------------------
				Set rootNode = xmldoc.documentElement
				Select Case UCase(rootNode.nodeName)
					'--------------------------------------------------------------------
					' Booking Engine°ú ¿¬°áÀº Á¤»óÀûÀ¸·Î ‰çÀ¸³ª Á¶È¸ °á°ú°ªÀÌ ¿¡·¯ÀÎ °æ¿ì 
					'--------------------------------------------------------------------
					Case "ERRORPAGE"
						msgQue.Code			= "F"
						msgQue.Msg			= rootNode.selectSingleNode("OutMessage").text

						if rootNode.selectNodes("HostMessage").Length >= 1 Then
							msgQue.HostMsg		= rootNode.selectSingleNode("HostMessage").text
						End If
						msgQue.outXML		= returnXML(msgQue.Code, msgQue.Msg, msgQue.HostMsg)
						ErrLog					= LogXML(msgQue.DisXML, msgQue.inXML, msgQue.HostXML)
						
						msgQue.HostState	= True
						msgQue.DBState		= True
						doFareFinish( KeyIndex )
						http.abort

					Case "CONNECTERROR"
						'--------------------------------------------------------------------
						' Booking Engine°ú ¿¬°á ¿¡·¯
						'--------------------------------------------------------------------
						msgQue.Code			= "F"
						msgQue.Msg			= rootNode.firstChild.Text
						msgQue.outXML		= returnXML(msgQue.Code, msgQue.Msg, "")
						ErrLog					= LogXML(msgQue.DisXML, msgQue.inXML, msgQue.HostXML)
						msgQue.HostState	= True
						msgQue.DBState		= True
						doFareFinish( KeyIndex )
						http.abort

					Case Else
					
						Dim orgNode
						Dim disRootNode

						objDOM1.loadXML( msgQue.DisXML )
						'-------------------------------------------------------------------------
						' È­¸é Display¿ë XML Parsing Error
						'-------------------------------------------------------------------------
						If (objDOM1.parseError.errorCode <> 0) Then
							Set objError				= objDOM1.parseError
							msgQue.Code			= "F"
							msgQue.Msg			= "[DisXML Parsing Error]" & objError.reason
							msgQue.outXML		= returnXML(msgQue.Code, msgQue.Msg, "")
							Set objError				= Nothing
							msgQue.HostState	= True
							msgQue.DBState		= True
							doFareFinish( KeyIndex )
							http.abort
						End If
						
						'-------------------------------------------------------------------------
						' ÀÛ¾÷±¸ºÐ XML NODE »ý¼º
						'-------------------------------------------------------------------------
						Set node1 = xmldoc.documentElement
						Set node2 = node1.appendChild(xmldoc.createElement("CMD"))
						node2.Text = "B2C_FAREMANAGER"
						'-------------------------------------------------------------------------
						' Host Response XML °ú DisXML º´ÇÕ
						'-------------------------------------------------------------------------
						Set node3		= node1.appendChild(xmldoc.createElement("DisXML"))
						node3.appendChild( objDOM1.documentElement )
						'-------------------------------------------------------------------------
						' AJAX Page È£Ãâ
						'-------------------------------------------------------------------------
						dbHTTP.onReadyStateChange = GetRef("onFareDBStateChange")
						dbHTTP.Open "POST", PageName, True
						dbHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded;charset=euc-kr"
						dbHTTP.Send(xmldoc)
						msgQue.HostState	= True
						'FareFinish( KeyIndex )
				End Select
			End If
		End If
		
		'Set dbHTTP = nothing
		'Set xmldoc = nothing
	Next
	
End Sub

Sub onFareDBStateChange()
	Dim i, msgQue, xmldoc, oErr, KeyList, KeyIndex, http

	Set xmldoc = CreateObject("Microsoft.XMLDOM")

	KeyList = FareDBHTTP.Keys
	
	For i = 0 to FareDBHTTP.Count - 1 
	
		KeyIndex = KeyList(i)
		Set http = FareDBHTTP.Item( KeyIndex )
	
		if http.readyState = 4 Then

			if FareQueList.Exists(KeyIndex) Then
				Set msgQue = FareQueList.Item(KeyIndex)
				
				'-------------------------------------------------------------------------
				' AJAX Page Ã³¸®°á°ú XML ¸®ÅÏ
				'-------------------------------------------------------------------------
				msgQue.outXML	= http.responseXML.xml
				msgQue.outXML	= Replace(msgQue.outXML, "<?xml version=""1.0""?>", "<?xml version=""1.0"" encoding=""euc-kr""?>")
				xmldoc.loadXML(msgQue.outXML)
				'http.abort
				'-------------------------------------------------------------------------
				' AJAX Page¿¡¼­ ¸®ÅÏµÈ XMLÀÇ Parsing Error
				'-------------------------------------------------------------------------
				If (xmldoc.parseError.errorCode <> 0) Then
					Set oErr				= xmldoc.parseError
					msgQue.Code		= "F"
					msgQue.Msg		= "[DB Response XML Parsing Error]" & oErr.reason
					msgQue.outXML 	= returnXML( msgQue.Code, msgQue.Msg, "" )
					ErrLog			= LogXML(msgQue.DisXML, msgQue.inXML, msgQue.HostXML)
					
					msgQue.HostState	= True
					msgQue.DBState		= True
					Set oErr					= Nothing
					doFareFinish( KeyIndex )
					Exit Sub
				End If
				'-------------------------------------------------------------------------
				' Ã³¸®°á°ú ¹× Ã³¸®¸Þ¼¼Áö ¼³Á¤
				'-------------------------------------------------------------------------
				msgQue.Code			= xmldoc.documentElement.selectSingleNode("strRtn").Text
				msgQue.Msg			= xmldoc.documentElement.selectSingleNode("strData").Text
				msgQue.DBState		= True
				doFareFinish( KeyIndex )
				http.abort
			End If
			
		End If
		
		'Set xmldoc 	= nothing
		'Set http 	= nothing
	Next
	
End Sub

Sub doFareQueListClear
	FareQueList.RemoveAll
	FareDBHTTP.RemoveAll
	FareHostHTTP.RemoveAll	
End Sub


Sub doFareItemRemove( Slot )

  Dim i , http

  set http = FareHostHTTP.item( Slot )
  Set http = nothing
  FareHostHTTP.remove( Slot )

  set http = FareDBHTTP.item( Slot )
  set http = nothing 
  FareDBHTTP.Remove( Slot )

  set msgQue = FareQueList.item( Slot ) 
  set msgQue = nothing

  FareQueList.Remove( Slot )

End Sub


'-------------------------------------------------------------------------
' ¼³¸í	: ¿îÀÓ Response Class
'-------------------------------------------------------------------------
Class FareMsgQueClass
	Dim f_msg
	Dim f_code
	Dim f_hostmsg
	Dim f_inXML
	Dim f_outXML
	Dim f_HostXML
	Dim f_HostSate
	Dim f_DBState
	Dim f_DisXML
	
	Private Sub Class_Initialize
		f_HostSate	= false
		f_DBState	= false
	End Sub
    '-------------------------------------------------------------------------
    ' Ã³¸®°á°ú ¸Þ¼¼Áö
    '-------------------------------------------------------------------------
	Public Property Let Msg(Value)
		f_msg = Value
	End Property
	Public Property Get Msg
		Msg = f_msg
	End Property
    '-------------------------------------------------------------------------
    ' Ã³¸®°á°ú ÄÚµå
    '-------------------------------------------------------------------------
	Public Property Let Code(Value)
		f_code = Value
	End Property
	
	Public Property Get Code
		Code = f_Code
	End Property
    '-------------------------------------------------------------------------
    ' Host Error Msg
    '-------------------------------------------------------------------------
	Public Property Let HostMsg(Value)
		f_hostmsg = Value
	End Property
	
	Public Property Get HostMsg
		HostMsg = f_hostMsg
	End Property
    '-------------------------------------------------------------------------
    ' DisXML
    '-------------------------------------------------------------------------
   Public Property Let DisXML(Value)
		f_DisXML = Value
   End Property 
   
   Public Property Get DisXML
		DisXML = f_DisXML
   End Property
    '-------------------------------------------------------------------------
    ' Host Request XML
    '-------------------------------------------------------------------------
	Public Property Let inXML(Value)
		f_inXML = Value
	End Property
	
	Public Property Get inXML
		inXML = f_inXML
	End Property
    '-------------------------------------------------------------------------
    ' DB Response XML
    '-------------------------------------------------------------------------
	Public Property Let outXML(Value)
		f_outXML = Value
	End Property
	
	Public Property Get outXML
		outXML = f_outXML
	End Property
    '-------------------------------------------------------------------------
    ' Host Response XML
    '-------------------------------------------------------------------------
	Public Property Let HostXML(Value)
		f_HostXML = Value
	End Property
	
	Public Property Get HostXML
		HostXML = f_HostXML
	End Property
    '-------------------------------------------------------------------------
    ' Host Ã³¸®¿©ºÎ
    '-------------------------------------------------------------------------
	Public Property Let HostState(Value)
		f_HostSate = Value
	End Property
	
	Public Property Get HostState 
		HostState = f_HostSate
	End Property
    '-------------------------------------------------------------------------
    ' DB Ã³¸®¿©ºÎ
    '-------------------------------------------------------------------------
	Public Property Let DBState(Value)
		f_DBState = Value
	End Property
	
	Public Property Get DBState
		DBState = f_DBState
	End Property 
    '-------------------------------------------------------------------------
    ' Ç×¸ñÃÊ±âÈ­
    '-------------------------------------------------------------------------
	Public Sub ClearParam
		f_msg		= ""
		f_code		= ""
		f_inXML		= ""
		f_outXML	= ""
		f_HostXML	= ""
		f_DisXML	= ""
		f_HostSate	= false
		f_DBState	= false
	End Sub

End Class
'-------------------------------------------------------------------------
' ¼³¸í	: ¿îÀÓÁ¶È¸¸¦ À§ÇÑ Class
'-------------------------------------------------------------------------
' Input : 
'			ModeCode		: Æíµµ, ¿Õº¹, ´Ù±¸°£ ±¸ºÐ
'			OwnerCode		: 
'			AgentCode		:
'			TripType			: 
'			BranchCode	:
'			CityCode
'			DepYear			:
'			DepMonth		:
'			DepDate			:
'			DepHour		:
'			OpenCase		:
'			AdultCount		:
'			ChildCount		:
'			InfantCount	:
'			Compartment	:
'			Carror			:
'-------------------------------------------------------------------------
Class FareManagerClass

	Dim f_ModeCode
	Dim f_OwnerCode
	Dim f_AgentCode
	Dim f_TripType
	Dim f_BranchCode
	Dim f_CityCode
	Dim f_DepYear
	Dim f_DepMonth
	Dim f_DepDate
	Dim f_DepHour
	Dim f_OpenCase
	Dim f_AdultCount
	Dim f_ChildCount
	Dim f_InfantCount
	Dim f_Compartment
	Dim f_Carrior
	
	Dim f_PassengerType
	Dim f_OneCarrior
	Dim f_FromPgmUrl
	Dim f_MbrId
	Dim f_Url
	Dim f_Tastaff
	Dim f_Sort
	Dim f_OutputMode
	
	Dim f_CRS
	Dim f_Trip
	Dim f_Language
	Dim f_Mode
	
	Private Sub Class_Initialize
		f_ModeCode		= ""
		f_OwnerCode		= ""
		f_AgentCode		= ""
		f_TripType			= ""
		f_BranchCode		= ""
		f_CityCode			= ""
		f_DepYear			= ""
		f_DepMonth		= ""
		f_DepDate			= ""
		f_DepHour			= ""
		f_OpenCase			= ""
		f_AdultCount		= ""
		f_ChildCount		= ""
		f_InfantCount		= ""
		f_Compartment	= ""
		f_Carrior				= ""
		
		f_code				= ""
		f_msg				= ""
		
		REQXML				= ""
		RESXML				= ""
		APIXML				= ""
		
		f_PassengerType	= "YYY"
		f_OneCarrior		= "N"
		f_FromPgmUrl		= ""
		f_MbrId				= ""
		f_Url					= ""
		f_Tastaff				= "N"
		f_Sort					= "1"
		f_OutputMode		= "XML"
	
		f_CRS			= CONST_CRS
		f_Trip			= CONST_INT_TRIP
		f_Language	= CONST_LANGUAGE
		f_Mode		= ""
	End Sub
	
	Public Property Let ModeCode(Value)
		f_ModeCode = Value
	End Property

	Public Property Let OwnerCode(Value)	
		f_OwnerCode = Value
	End Property
	
	Public Property Let AgentCode(Value)
		f_AgentCode = Value
	End Property

	Public Property Let TripType(Value)
		f_TripType = Value
	End Property
	
	Public Property Let BranchCode(Value)
		f_BranchCode = Value
	End Property
	
	Public Property Let CityCode(Value)
		f_CityCode = Value
	End Property
	
	Public Property Let DepYear(Value)
		f_DepYear = Value
	End Property
	
	Public Property Let DepMonth(Value)
		f_DepMonth = Value
	End Property
	
	Public Property Let DepDate(Value)
		f_DepDate = Value
	End Property
	
	Public Property Let DepHour(Value)
		f_DepHour = Value
	End Property
	
	Public Property Let OpenCase(value)
		f_OpenCase = Value
	End Property
	
	Public Property Let AdultCount(Value)
		f_AdultCount = Value
	End Property
	
	Public Property Let ChildCount(Value)
		f_ChildCount = Value
	End Property
	
	Public Property Let InfantCount(Value)
		f_InfantCount = Value
	End Property
	
	Public Property Let Compartment(Value)
		f_Compartment = Value
	End Property
	
	Public Property Let Carrior(Value)
		f_Carrior = Value
	End Property
	
   Public Property Get GenXML
		GenXML = makeXML
   End Property
	
	'--------------------------------------------------------------------
	' XML »ý¼º
	'--------------------------------------------------------------------
	Private Function makeXML
	
		Dim i
		Dim arrCity, arrYear, arrMonth, arrDate, arrHour, arrOpen

		REQXML = "<?xml version=""1.0""?>"																		& Chr(13)
		REQXML = REQXML & "<fm_input>"																		& Chr(13)
		REQXML = REQXML	& "    <mode_code>"	&	f_ModeCode	& "</mode_code>"			& Chr(13)
		REQXML = REQXML & "    <owner_code>"	& f_AgentCode	& "</owner_code>"			& Chr(13)		
		REQXML = REQXML & "    <agent_code>"	& f_AgentCode	& "</agent_code>"			& Chr(13)
		REQXML = REQXML & "    <trip_type>"		& f_TripType		& "</trip_type>"				& Chr(13)
		REQXML = REQXML & "    <branch_code>"	& f_BranchCode	& "</branch_code>"		& Chr(13)
		
		arrCity		= Split(f_CityCode, "/")
		arrYear		= Split(f_DepYear, "/")
		arrMonth	= Split(f_DepMonth, "/")
		arrDate		= Split(f_DepDate, "/")
		arrHour		= Split(f_DepHour, "/")
		arrOpen		= Split(f_OpenCase, "/")
		
		For i = 0 To UBound(arrCity)
			REQXML = REQXML & "    <city_code>"		& arrCity(i)				& "</city_code>"			& Chr(13)
		Next
		
		'------------------------------------------------------------------------------------------------
		' ´Ù±¸°£ open¿©Á¤ ÀÌ»óÀÛµ¿À¸·Î If±¸¹® Ãß°¡ÇÏ¿´À½0000ÀÏ¶§´Â ÇÑÁÙ¸¸ »ý±âµµ·Ï(2008/01/09 °­»ó±¸ ¼öÁ¤)
		'------------------------------------------------------------------------------------------------
		For i = 0 to UBound(arrYear)
			If arrYear(i) <> "0000" Then
				REQXML = REQXML & "    <dep_year>"		& arrYear(i)				& "</dep_year>"				& Chr(13)
			End If
		Next
		
		For i = 0 to UBound(arrMonth)
			If arrMonth(i) <> "00" Then
				REQXML = REQXML & "    <dep_month>"	& arrMonth(i)			& "</dep_month>"			& Chr(13)
			End If
		Next

		
		For i = 0 to UBound(arrDate)
			If arrDate(i) <> "00" Then
				REQXML = REQXML & "    <dep_date>"		& arrDate(i)			& "</dep_date>"				& Chr(13)
			End If
		Next
		
		For i = 0 to UBound(arrHour)
			If arrHour(i) <> "00" Then
				REQXML = REQXML & "    <dep_hour>"		& arrHour(i)			& "</dep_hour>"				& Chr(13)
			End If
		Next
		
		For i = 0 to UBound(arrOpen)
				REQXML = REQXML & "    <open_case>"		& arrOpen(i)			& "</open_case>"			& Chr(13)
		Next
		
		REQXML = REQXML & "    <passenger_adult>"		& f_AdultCount		&	"</passenger_adult>"	& Chr(13)
		REQXML = REQXML & "    <passenger_child>"		& f_ChildCount		& "</passenger_child>"	& Chr(13)
		REQXML = REQXML & "    <passenger_infant>"	& f_InfantCount		& "</passenger_infant>"	& Chr(13)
		REQXML = REQXML & "    <compartment>"		& f_Compartment	& "</compartment>"		& Chr(13)
		REQXML = REQXML & "    <carrior>"					& f_Carrior				& "</carrior>"					& Chr(13)
		REQXML = REQXML & "    <passenger_type>"		& f_PassengerType	& "</passenger_type>"		& Chr(13)
		REQXML = REQXML & "    <one_carrior>"			& f_OneCarrior		& "</one_carrior>"			& Chr(13)
		REQXML = REQXML & "    <from_pgm_url>"		& f_FromPgmUrl		& "</from_pgm_url>"		& Chr(13)
		REQXML = REQXML & "    <mbr_id>"					& f_MbrId				& "</mbr_id>"				& Chr(13)
		REQXML = REQXML & "    <tastaff>"					& f_Tastaff				& "</tastaff>"					& Chr(13)
		REQXML = REQXML & "    <sort>"						& f_Sort					& "</sort>"					& Chr(13)
		REQXML = REQXML & "    <output_mode>"		& f_OutputMode		& "</output_mode>"		& Chr(13)
		REQXML = REQXML & "</fm_input>"																            		& Chr(13)
		
		makeXML = REQXML
	End Function

End Class
