<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#BF5DC5, #010708]" creationComplete="show(event)">

<mx:Script>
	<![CDATA[
		import mx.charts.DateTimeAxis;
		import mx.controls.Alert;
		import mx.utils.URLUtil;
		import mx.managers.BrowserManager;
		import mx.managers.IBrowserManager;
		import mx.messaging.AbstractConsumer;
		import mx.collections.XMLListCollection;
		import mx.rpc.events.ResultEvent;	
	
		private var bm:IBrowserManager;
		private var UName:String;
		private var CityId:String;
		private var FromDate:String;
		private var ToDate:String;
		private var NoOfAdults:int;
		private var NoOfChildren:int;
		private var hid:int;
		
		public function show(e:Event):void
		{
			bm=BrowserManager.getInstance();
			bm.init("","welcome");
			var o:Object=URLUtil.stringToObject(bm.fragment,"&");			
			
			UName=o.UserName;
			CityId=o.CityId;
			FromDate=o.FromId;
			ToDate=o.ToId;
			NoOfAdults=o.NoOfAdults;
			NoOfChildren=o.NoOfChild;
			//Alert.show(CityId);
			hoteldetails();
			UserName.text=UName;
			city.text=CityId;			
		}
		
	public function Home():void
	{
		var url:URLRequest=new URLRequest("Home.html");
			navigateToURL(url,"_self");
	}
	
	public function Logout():void
	{
		var url:URLRequest=new URLRequest("Login.html");
			navigateToURL(url,"_self");
	}
	public function hoteldetails():void
	{
		
		HolidayTripWebService.GetHotels(CityId);
	}
	
		
	public function payment():void
	{		
	//	Alert.show(CmdCardType.selectedItem.toString());
		//HolidayTripWebService.GetPaymentEvents(UserName,city.text,hotel.text,CmdCardType.selectedItem,cardno.text,holdername.text,expdate.text,cvvno.text,paieddate.text,Total.text);
		HolidayTripWebService.Payment(UName,city.text,hotel.text,CmdCardType.selectedItem.toString(),cardno.text,holdername.text,expdate.text,cvvno.text,paieddate.text,Total.text);
	
	}
	
	 [Bindable]
		    public var hotel_details:XMLListCollection;
		    
	public function GetHotelEvents(event:ResultEvent):void
	{
		var query:XML=new XML(event.result);
		hotel_details=new XMLListCollection(query.Hotels);				
	}	
	
	 [Bindable]
		    public var payment_details:XMLListCollection;
		    
	public function GetPaymentEvents(event:ResultEvent):void
	{
		Alert.show("Inserted");	
	}
	public function gettotal():void
	{
	  HolidayTripWebService.GetTotal(hotel.text,NoOfAdults,NoOfChildren);
	}
	public function gettotalmethod(event:ResultEvent):void
	{
		Total.text=event.result.toString();
	} 
	
	]]>
</mx:Script>

<mx:WebService id="HolidayTripWebService" 
		wsdl="http://localhost:50854/HTWS/Service.asmx?WSDL"
		showBusyCursor="true" fault="mx.controls.Alert.show('Error loading WSDL', 'Webservice Error');" >
		<mx:operation name="GetHotels" resultFormat="object" result="GetHotelEvents(event)">
		</mx:operation>
		<mx:operation name="Payment" resultFormat="object" result="GetPaymentEvents(event)">	
		</mx:operation>
		<mx:operation name="GetTotal" resultFormat="object" result="gettotalmethod(event)">
		</mx:operation>
</mx:WebService>

	<mx:VBox x="16" y="73" height="407" width="488" verticalAlign="top" horizontalAlign="center" verticalGap="2">
		<mx:HBox width="418" height="30" verticalAlign="middle" horizontalAlign="center">
			<mx:Label text="User:"/>
			<mx:TextInput enabled="false" id="UserName"/>
		</mx:HBox>
		<mx:HBox width="440" height="30" verticalAlign="middle" horizontalAlign="center">
			<mx:Label text="City:"/>
			<mx:TextInput enabled="false" id="city"/>
		</mx:HBox>
		<mx:HBox width="436" height="30" verticalAlign="middle" horizontalAlign="center">
			<mx:Label text="Hotel:"/>
			<mx:TextInput enabled="true" id="hotel" width="172" focusOut="gettotal()" />
		</mx:HBox>
		<mx:HBox width="444" height="30" verticalAlign="middle" horizontalAlign="center">
			<mx:Label text="Total Amount"/>
			<mx:TextInput enabled="false" id="Total" width="172"/>
		</mx:HBox>
		<mx:HBox width="424" height="30" verticalAlign="middle" horizontalAlign="center">
			<mx:Label text="CardType"/>
			<mx:ComboBox id="CmdCardType" labelField="CardType">
			<mx:ArrayCollection>
				<mx:String>Select Card Type</mx:String>
				<mx:String>Credit Card</mx:String>
				<mx:String>Debit Card</mx:String>
			</mx:ArrayCollection>
			</mx:ComboBox>
		</mx:HBox>
		<mx:HBox width="416" height="30" verticalAlign="middle" horizontalAlign="center">
			<mx:Label text="Card Number:"/>
			<mx:TextInput id="cardno"/>
		</mx:HBox>
		<mx:HBox width="426" height="30" verticalAlign="middle" horizontalAlign="center">
			<mx:Label text="Holder Name:"/>
			<mx:TextInput id="holdername"/>
		</mx:HBox>
		<mx:HBox width="432" height="30" verticalAlign="middle" horizontalAlign="center">
			<mx:Label text="Expiry date:"/>
			<mx:TextInput id="expdate"/>
		</mx:HBox>
		<mx:HBox width="432" height="30" verticalAlign="middle" horizontalAlign="center">
			<mx:Label text="CVV Number:"/>
			<mx:TextInput id="cvvno"/>
		</mx:HBox>
		<mx:HBox width="420" height="30" verticalAlign="middle" horizontalAlign="center">
			<mx:Label text="Payment Date:"/>
			<mx:TextInput id="paieddate"/>
		</mx:HBox>
	</mx:VBox>
	<mx:Button label="Submit" width="80" height="27" borderColor="#259DF1" fillAlphas="[1.0, 1.0]" fillColors="[#D62F2F, #190606]" color="#B6D2D8" cornerRadius="20" id="button1"  x="213" y="511" click="payment()"/>
	<mx:Label x="213" y="30" text="Payment" fontFamily="Courier New" fontSize="25" fontWeight="bold" fontStyle="normal" color="#823824"/>
	
	<mx:DataGrid height="316" id="GridHotels" x="512" y="125" dataProvider="{hotel_details}">
		<mx:columns>
			<mx:DataGridColumn headerText="Sid" dataField="HotelId"/>
			<mx:DataGridColumn headerText="HotelName" dataField="HotelName"/>
			<mx:DataGridColumn headerText="HotelType" dataField="HotelType"/>
			<mx:DataGridColumn headerText="CostForAdult" dataField="CostForBed"/>
			<mx:DataGridColumn headerText="CostForChildren" dataField="CostForChildren"/>
		</mx:columns>
	</mx:DataGrid>
	
</mx:Application>
