/*
	*@author h.grant 
	
	* Ext JS Library 2.2
*/

Ext.onReady(function(){

	// Tabs
	tabPanel = new Ext.TabPanel({
		renderTo: 'myTabs',
	    activeTab: 0,
	    width:496,
	   	height:600,
	    plain:true,
	    defaults:{autoScroll:true},
	    items:[
	        {	
				id:'tabOverview',
				title: 'Overview',
	        	contentEl: 'overviewContent'
	        },
	        {
				id:'tabTravelers',
				title: 'Travelers',
	        	contentEl: 'travelersContent'
	        },
	        {
	            id:'tabSuppliers',
				title: 'Suppliers',
	            contentEl:'suppliersContent'
	        },
	        {
	            id:'tabPortals',
				title: 'Portals',
	            contentEl:'portalsContent'
	        },
	        {
	            id:'tabTechnology',
				title: 'Technology',
	            contentEl:'technologyContent'
	        },
	        {
				id:'tabContactUs',
	            title: 'Contact Us',
	            contentEl:'contactUsContent'
	        }
		]
	});
	
	//Panel
	var panel = new Ext.Panel({
	        title: 'Bookable Ads at Work',
	        collapsible:false,
	        renderTo: 'myPanel',
	        width:230,
	        height:600,
			autoScroll:true,
	        contentEl:'bookableAdsContent'
	});
	
	var win;
	var windowID;
	var windowTitle;
	var windowWebAddress;
	var button1 = Ext.get('show-banner-and-listing');
	var button2 = Ext.get('show-maps');
	var button3 = Ext.get('show-classification');
	var button4 = Ext.get('show-banner-and-listing-stlucia');
	var button5 = Ext.get('show-featured');
	var button6 = Ext.get('show-map');
	
	button1.on('click', function(){
		windowOpen = true;
		windowID = "banlist1";
		windowTitle = "Banner and Listing";
		windowWebAddress = "http://barbados.org/hotname.htm";
		createWindow();
	})
	
	button2.on('click', function(){
		windowOpen = true;
		windowID = "map1";
		windowTitle = "Maps";
		windowWebAddress = "http://barbados.org/maps_google.htm?mapPoint=292";
		createWindow();
	})
	
	button3.on('click', function(){
		windowOpen = true;
		windowID = "classification";
		windowTitle = "Classifications";
		windowWebAddress = "http://barbados.org/hotwed.htm";
		createWindow();
	})
	
	button4.on('click', function(){
		windowOpen = true;
		windowID = "banlist2";
		windowTitle = "Banner and Listing";
		windowWebAddress = "http://bookingsstlucia.com/encyc/carib/stlucia/hotelrates.cfm";
		createWindow();
	})
	
	button5.on('click', function(){
		windowOpen = true;
		windowID = "featured";
		windowTitle = "Featured";
		windowWebAddress = "http://barbados.org/hotels/finest.htm";
		createWindow();
	})
	

	button6.on('click', function(){
		windowOpen = true;
		windowID = "map2";
		windowTitle = "Bookable Maps";
		windowWebAddress = "http://barbados.org/maps_google.htm?mapPoint=179";
		createWindow();
		
	})

	
	/*
	* ================  Bookable Ads At Work Popup Window  =======================
	*/
	function createWindow(){
		// create the window on the first click and reuse on subsequent clicks
	
		win = new Ext.Window({
			id			: windowID,
			title		: windowTitle,
			layout  	: 'fit',
			width   	: 810,
			height		: 550,
			closeAction	:'close',
			plain		: true,
			maximizable	: true,
			modal		: true,
			autoLoad	:'bookable-ads/iframe.htm?webAddress=' + windowWebAddress
			//autoLoad	:'iframe.cfm?webAddress=' + windowWebAddress
		});
		
	    win.show();
	}

	
	Ext.QuickTips.init();
	
	// turn on validation errors beside the field globally
	Ext.form.Field.prototype.msgTarget = 'side';
	
	/*
	* ================  Contact Us form  =======================
	*/
	var contactUsForm = new Ext.FormPanel({
	    labelWidth: 75, // label settings here cascade unless overridden
	    frame:true,
	    waitMsgTarget:true,
		title:'Get Your TRAVEL SERVICES Consultation',
	    bodyStyle:'padding:5px 5px 0',
	    width:464,

	    items:
		[
			{
				layout: 'column',
				border: false,
				defaults:
				{
					columnWidth: '.5',
					border: false
				}

			},
			{
				/*====================================================================
	 			* Entry Contact Info
	 			*====================================================================*/
				xtype: 'fieldset',
				title: 'Your Info',
				autoHeight: true,
				layout: 'form',
				defaultType:'textfield',
				defaults:{width: 300},
				items:
				[
					{
			            fieldLabel: 'Full Name',
			            name: 'name',
			            allowBlank:false
			        },
					{
			            fieldLabel: 'Email',
			            name: 'email',
			            vtype:'email',				
						allowBlank:false
			        },
					{
			            fieldLabel: 'Organisation',
			            name: 'organisation'
			        },
					{
			            fieldLabel: 'Telephone',
			            name: 'telephone'
			        },
					{
			            fieldLabel: 'Country',
			            name: 'country'
			        },
						new Ext.form.TextArea({
						fieldLabel:'Request/<br/>Questions',
			            name:'comments',
						height:120,
						allowBlank:false
					})
				]
			},
			{
				/*====================================================================
	 			* CheckGroup Interest
	 			*====================================================================*/
				xtype: 'fieldset',
				title: 'Interests',
				autoHeight: true,
				layout: 'form',
				items:
				[
					{
		                xtype: 'checkboxgroup',
		                fieldLabel: 'Options',
						columns: [180, 160],
                		vertical: true,
		                items:
						[
							{
			                    boxLabel: 'Portal Services',
			                    name: 'interest1',
			                    inputValue: 'Portal Services'
			                },	
							{
			                    boxLabel: 'Supplier Services',
			                    name: 'interest2',
			                    inputValue: 'Supplier Services'
			                },
							{
			                    boxLabel: 'Mapping Technology',
			                    name: 'interest3',
			                    inputValue: 'Mapping Technology'
			                },
							{
			                    boxLabel: 'Advertising Technology',
			                    name: 'interest4',
			                    inputValue: 'Advertising Technology'
			                },
							{
			                    boxLabel: 'Global Distribution System',
			                    name: 'interest5',
			                    inputValue: 'GDS'
			                },
							{
			                    boxLabel: 'Booking Engine',
			                    name: 'interest6',
			                    inputValue: 'Booking Engine'
			                },
							{
			                    boxLabel: 'Direct Marketing',
			                    name: 'interest7',
			                    inputValue: 'Direct Marketing'
			                },					
							{
			                    boxLabel: 'Hosting',
			                    name: 'interest8',
			                    inputValue: 'Hosting'
			                },
							{
			                    boxLabel: 'Website',
			                    name: 'interest9',
			                    inputValue: 'Website'
			                },
							{
			                    boxLabel: 'SEO',
			                    name: 'interest10',
			                    inputValue: 'SEO'
			                }	                
						]
		            },
				]
			}		
		],
			
	    buttons:
		[
			{
				id:'sendButton',
				text:'Send Your Request',
				handler:function(){
					Ext.getCmp('sendButton').disable();
					Ext.getCmp('clearButton').disable();
					contactUsForm.form.submit({
						url:'/bookable-ads/bookable-ads-form.php',
						method:'POST',
						waitMsg:'Sending your data...',
						success:function(form, action)
						{
							Ext.getCmp('sendButton').enable();
							Ext.getCmp('clearButton').enable();
						    Ext.MessageBox.alert('Message', 'Your details were sent Successfully! Thank you for your enquiry.');
						},
						failure:function(form, action)
						{
							Ext.getCmp('sendButton').enable();
							Ext.getCmp('clearButton').enable();
							Ext.MessageBox.alert('Message', 'Your details were not sent! An error occured.');
						}
					});
				}
		    },
			{
		        id:'clearButton',
				text: 'Clear',
				handler:function(){
					contactUsForm.form.reset();
				}
		    }
		]
	});
	
	contactUsForm.render('formContactUs');
});

function focusTab(name){
	tabPanel.setActiveTab(name);
}

