Ext.onReady(function(){
	Ext.form.TriggerField.override({
	    afterRender : function(){
	        Ext.form.TriggerField.superclass.afterRender.call(this);
	        var y;
	        if(Ext.isIE && !this.hideTrigger && this.el.getY() != (y = this.trigger.getY())){
	            this.el.position();
	            this.el.setY(y);
	        }
	    }
	});	
	
	//configs
	var tbar_line_height = 24;
	var current_uri = top.location.href;
	//this is because Restaurants.jsp uses grey theme while other pages use blue theme
	//line_height set to 25 for grey theme, 24 for blue theme
	if (current_uri.indexOf('.jsp')==-1 || current_uri.indexOf('/Restaurants.jsp')!=-1) {
		tbar_line_height = 24;
	}
	
	//define stores*****************************************************************************************
	var districtStore = new Ext.data.SimpleStore({
	    fields: ['district', 'id', 'lvl'],
	    data: [
	    	['Singapore', 'district-00', '1'], 
	    	['01 City - Business District', 'district-01', '1'],
	    	['Boat Quay', 'district-01-001', '2'], ['City Hall', 'district-01-002', '2'], ['Havelock Road', 'district-01-003', '2'], ['Marina Square', 'district-01-004', '2'], ['Raffles Place', 'district-01-005', '2'], ['Suntec City', 'district-01-006', '2'], 
	    	['02 City - Business District', 'district-02', '1'], 
	    	['Anson Road', 'district-02-001', '2'], ['Marina Bay', 'district-02-007', '2'], ['Neil Road', 'district-02-003', '2'], ['Shenton Way', 'district-02-005', '2'], ['Tanjong Pagar', 'district-02-006', '2'], 
	    	['03 Central South', 'district-03', '1'], 
	    	['Alexandra Road', 'district-03-001', '2'], ['Tiong Bahru', 'district-03-002', '2'], ['Queenstown', 'district-03-003', '2'], 
	    	['04 South', 'district-04', '1'], 
	    	['Bukit Merah', 'district-04-005', '2'], ['Keppel', 'district-04-001', '2'], ['Mount Faber', 'district-04-002', '2'], ['Sentosa', 'district-04-003', '2'], ['Telok Blangah', 'district-04-004', '2'], 
	    	['05 South West', 'district-05', '1'],
	    	['Buona Vista', 'district-05-001', '2'], ['Dover', 'district-05-002', '2'], ['Pasir Panjang', 'district-05-003', '2'], ['West Coast', 'district-05-004', '2'], 
	    	['06 City - Business District', 'district-06', '1'],
	    	['Chinatown', 'district-06-001', '2'], ['High Street', 'district-06-002', '2'], ['North Bridge Road', 'district-06-003', '2'], 
	    	['07 City', 'district-07', '1'],
	    	['Beach Road', 'district-07-001', '2'], ['Bencoolen Road', 'district-07-002', '2'], ['Bugis', 'district-07-003', '2'], ['Dhoby Ghaut', 'district-07-005', '2'], ['Rochor', 'district-07-004', '2'], 
	    	['08 Central', 'district-08', '1'],
	    	['Little India', 'district-08-001', '2'], ['Farrer Park', 'district-08-002', '2'], ['Serangoon Road', 'district-08-003', '2'], 
	    	['09 Central - Orchard', 'district-09', '1'],
	    	['Cairnhill', 'district-09-001', '2'], ['Killiney', 'district-09-002', '2'], ['Leonie Hill', 'district-09-003', '2'], ['Orchard', 'district-09-004', '2'], ['Oxley', 'district-09-005', '2'], 
	    	['10 Central - Near Orchard', 'district-10', '1'],
	    	['Balmoral', 'district-10-001', '2'], ['Bukit Timah', 'district-10-002', '2'], ['Grange Road', 'district-10-003', '2'], ['Holland', 'district-10-004', '2'], ['Orchard Boulevard', 'district-10-005', '2'], ['River Valley', 'district-10-006', '2'], ['Tanglin Road', 'district-10-007', '2'], 
	    	['11 Central - Near Orchard', 'district-11', '1'],
	    	['Chancery', 'district-11-001', '2'], ['Dunearn Road', 'district-11-003', '2'], ['Newton', 'district-11-004', '2'], 
	    	['12 Central', 'district-12', '1'],
	    	['Balestier', 'district-12-001', '2'], ['Moulmein', 'district-12-002', '2'], ['Novena', 'district-12-003', '2'], ['Toa Payoh', 'district-12-004', '2'], 
	    	['13 Central East', 'district-13', '1'],
	    	['Potong Pasir', 'district-13-001', '2'], ['Machpherson', 'district-13-002', '2'], 
	    	['14 Central East', 'district-14', '1'],
	    	['Eunos', 'district-14-001', '2'], ['Geylang', 'district-14-002', '2'], ['Kembangan', 'district-14-003', '2'], ['Paya Lebar', 'district-14-004', '2'], 
	    	['15 East Coast', 'district-15', '1'],
	    	['East Coast Park', 'district-15-005', '2'], ['Katong', 'district-15-001', '2'], ['Marine Parade', 'district-15-002', '2'], ['Siglap', 'district-15-003', '2'], ['Tanjong Rhu', 'district-15-004', '2'], 
	    	['16 Upper East Coast', 'district-16', '1'],
	    	['Bayshore', 'district-16-001', '2'], ['Bedok', 'district-16-002', '2'], ['Chai Chee', 'district-16-003', '2'], ['Expo', 'district-16-004', '2'],
	    	['17 Far East', 'district-17', '1'],
	    	['Changi', 'district-17-001', '2'], ['Loyang', 'district-17-002', '2'], ['Pasir Ris', 'district-17-003', '2'], 
	    	['18 Far East', 'district-18', '1'],
	    	['Simei', 'district-18-001', '2'], ['Tampines', 'district-18-002', '2'], 
	    	['19 North East', 'district-19', '1'],
	    	['Hougang', 'district-19-001', '2'], ['Punggol', 'district-19-002', '2'], ['Sengkang', 'district-19-003', '2'], 
	    	['20 Central North', 'district-20', '1'],
	    	['Ang Mo Kio', 'district-20-001', '2'], ['Bishan', 'district-20-002', '2'], ['Braddell Road', 'district-20-003', '2'], ['Thomson', 'district-20-004', '2'], 
	    	['21 Central West', 'district-21', '1'],
	    	['Clementi', 'district-21-001', '2'], ['Jurong East', 'district-21-004', '2'], ['Upper Bukit Timah', 'district-21-002', '2'], ['Hume Avenue', 'district-21-003', '2'], 
	    	['22 Far West', 'district-22', '1'],
	    	['Boon Lay', 'district-22-001', '2'], ['Jurong', 'district-22-002', '2'], ['Tuas', 'district-22-003', '2'], 
	    	['23 North West', 'district-23', '1'],
	    	['Bukit Batok', 'district-23-001', '2'], ['Bukit Panjang', 'district-23-005', '2'], ['Choa Chu Kang', 'district-23-002', '2'], ['Hillview Avenue', 'district-23-003', '2'], ['Upper Bukit Timah', 'district-23-004', '2'], 
	    	['24 Far North West', 'district-24', '1'],
	    	['Kranji', 'district-24-001', '2'], ['Lim Chu Kang', 'district-24-002', '2'], ['Sungei Gedong', 'district-24-003', '2'], ['Tengah', 'district-24-004', '2'], 
	    	['25 Far North', 'district-25', '1'],
	    	['Admiralty', 'district-25-001', '2'], ['Woodlands', 'district-25-002', '2'], 
	    	['26 North', 'district-26', '1'],
	    	['Tagore', 'district-26-001', '2'], ['Yio Chu Kang', 'district-26-002', '2'], 
	    	['27 Far North', 'district-27', '1'],
	    	['Khatib', 'district-27-003', '2'], ['Sembawang', 'district-27-001', '2'], ['Yishun', 'district-27-002', '2'], 
	    	['28 North East', 'district-28', '1'],
	    	['Seletar', 'district-28-001', '2']
		]
	});

	var cuisineStore = new Ext.data.SimpleStore({
	    fields: ['cuisine', 'id', 'lvl'],
	    data: [ 
			['All', 'cuisine-00', '1'],
	    	['Buffet (%E8%87%AA%E5%8A%A9%E9%A4%90)', 'cuisine-13-008', '1'], 
	    	['Crab/Seafood (%E8%9E%83%E8%9F%B9/%E6%B5%B7%E9%B2%9C)', 'cuisine-13-004', '1'], 
	    	['Chinese (%E4%B8%AD%E9%A4%90)', 'cuisine-01', '1'], ['Anhui (%E5%BE%BD%E8%8F%9C)', 'cuisine-01-019', '2'], ['Beijing (%E4%BA%AC%E8%8F%9C)', 'cuisine-01-001', '2'], ['Cantonese (%E7%B2%A4%E8%8F%9C)', 'cuisine-01-002', '2'], ['Dong Bei (%E4%B8%9C%E5%8C%97%E8%8F%9C)', 'cuisine-01-003', '2'], ['Hainanese (%E6%B5%B7%E5%8D%97%E8%8F%9C)', 'cuisine-01-020', '2'], ['Hakka (%E5%AE%A2%E5%AE%B6%E8%8F%9C)', 'cuisine-01-004', '2'], ['Hokkien (%E7%A6%8F%E5%BB%BA%E8%8F%9C)', 'cuisine-01-005', '2'], ['Huaiyang (%E6%B7%AE%E6%89%AC%E8%8F%9C)', 'cuisine-01-006', '2'], ['Hubei (%E6%B9%96%E5%8C%97%E8%8F%9C)', 'cuisine-01-007', '2'], ['Hunanese (%E6%B9%96%E5%8D%97%E8%8F%9C)', 'cuisine-01-008', '2'], ['Mongolian (%E8%92%99%E5%8F%A4%E8%8F%9C)', 'cuisine-01-021', '2'], ['Shandong (%E9%B2%81%E8%8F%9C)', 'cuisine-01-009', '2'], ['Shanghai (%E4%B8%8A%E6%B5%B7%E6%9C%AC%E5%B8%AE%E8%8F%9C)', 'cuisine-01-010', '2'], ['Suzhou/Hangzhou (%E8%8B%8F%E6%9D%AD%E8%8F%9C)', 'cuisine-01-011', '2'], ['Szechuan (%E5%B7%9D%E8%8F%9C)', 'cuisine-01-012', '2'], ['Taiwanese (%E5%8F%B0%E6%B9%BE%E8%8F%9C)', 'cuisine-01-013', '2'], ['Teochew (%E6%BD%AE%E5%B7%9E%E8%8F%9C)', 'cuisine-01-014', '2'], ['Xinjiang (%E6%96%B0%E7%96%86%E8%8F%9C)', 'cuisine-01-015', '2'], ["Xi'an (%E8%A5%BF%E5%AE%89%E8%8F%9C)", 'cuisine-01-016', '2'], ['Yunnan/Guizhou (%E4%BA%91%E8%B4%B5%E8%8F%9C)', 'cuisine-01-017', '2'], ['Others (%E5%85%B6%E4%BB%96%E8%8F%9C%E7%B3%BB)', 'cuisine-01-018', '2'], 
	    	['Brazilian', 'cuisine-02', '1'],
	    	['Fusion', 'cuisine-03', '1'],
	    	['Indian', 'cuisine-04', '1'],
	    	['International', 'cuisine-14', '1'], 
	    	['Japanese', 'cuisine-05', '1'],
	    	['Korean', 'cuisine-06', '1'], 
	    	['Mediterranean', 'cuisine-07', '1'], 
	    	['Mexican', 'cuisine-08', '1'], 
	    	['Middle Eastern', 'cuisine-09', '1'], 
	    	['Russian', 'cuisine-10', '1'], 
	    	['South-East Asia', 'cuisine-11', '1'], ['Burmese', 'cuisine-11-006', '2'], ['Indonesian', 'cuisine-11-001', '2'], ['Malay', 'cuisine-11-002', '2'], ['Nepalese', 'cuisine-11-007', '2'], ['Philippine', 'cuisine-11-008', '2'], ['Singaporean', 'cuisine-11-009', '2'], ['Thai', 'cuisine-11-003', '2'], ['Vietnamese', 'cuisine-11-004', '2'], ['Others', 'cuisine-11-005', '2'],  
	    	['Western', 'cuisine-12', '1'],	['American', 'cuisine-12-001', '2'], ['Australian', 'cuisine-12-008', '2'], ['European ', 'cuisine-12-002', '2'], ['French', 'cuisine-12-003', '2'], ['German', 'cuisine-12-004', '2'], ['Italian', 'cuisine-12-005', '2'], ['Spanish', 'cuisine-12-006', '2'], ['Others', 'cuisine-12-007', '2'], 
	    	['More', 'cuisine-13', '1'], ['Halal', 'cuisine-13-001', '2'], ['Herbal', 'cuisine-13-002', '2'], ['Local Delights', 'cuisine-13-003', '2'], ['Peranakan/Nonya', 'cuisine-13-005', '2'], ['Steamboat', 'cuisine-13-006', '2'], ['Vegetarian', 'cuisine-13-007', '2']
	    ]//end data
	});
	//decode cuisineStore
	cuisineStore.each(function(cuisineRec){
		var cuisine = cuisineRec.get('cuisine');
		var decodedCuisine = Url.decode(cuisine);
		cuisineRec.set('cuisine', decodedCuisine);
	});

	var expenseStore = new Ext.data.SimpleStore({
	    fields: ['expense', 'id'],
	    data: [["I don't mind", 'expense-00'], 
	    	['S$10', 'expense-01'], 
	    	['S$15', 'expense-02'], 
	    	['S$20', 'expense-03'], 
	    	['S$25', 'expense-04'],
	    	['S$30', 'expense-05'],
	    	['S$35', 'expense-06'],
	    	['S$40', 'expense-07'],
	    	['S$45', 'expense-08'],
	    	['S$50', 'expense-09']]
	});

	var expenseBoundaryStore = new Ext.data.SimpleStore({
	    fields: ['boundary'],
	    data: [["About"], 
	    	['Above'], 
	    	['Below']]
	});

	var occasionStore = new Ext.data.SimpleStore({
	    fields: ['occasion', 'id'],
	    data: [["Any", 'occasion-00'], 
	    	['Business/Company', 'occasion-01'], 
	    	['Wedding', 'occasion-02'], 
	    	['Birthday', 'occasion-03'], 
	    	['Friends', 'occasion-04'],
	    	['Lovers', 'occasion-05']]
	});

	var vipRoomStore = new Ext.data.SimpleStore({
	    fields: ['viproom', 'id'],
	    data: [["I don't mind", 'vip-room-00'], ['Required', 'vip-room-01'], ['Required, with projector', 'vip-room-02'], ['Required, with karaoke', 'vip-room-03'], ['Required, with both', 'vip-room-04']]
	});

	var discountStore = new Ext.data.SimpleStore({
	    fields: ['discount', 'id'],
	    data: [["I don't mind", 'discount-00'], ['Required', 'discount-01']]
	});

	//load
	var landmarkTitleStore = new Ext.data.JsonStore({
    	url: '/RestaurantBookingServlet?action=getRestaurantPanelTitles&id=restaurant_landmark'
       ,root: 'results'
       ,fields: ['id', 'icon_css_class', 'title']
    });
	
	//get panel expand/collapse info*******************************************************************
	var panelDisplayNode = Ext.get("req-param-searchformtabs-panel");
	var collapse = false;
	var activeTab = 0;
	if (panelDisplayNode) {
		var panelDisplay = panelDisplayNode.dom.innerHTML;
		if (panelDisplay == 'collapse') {
//			collapse = true;
		} else if (panelDisplay == 'book') {
			activeTab = 1;
		}
	}
	
	//get previous search params*****************************************************************
	var searchedDistrict = Ext.get("req-param-district-idx");
	var districtValue = 'district-00';
	if (searchedDistrict) {
		districtValue = searchedDistrict.dom.innerHTML;
	}
	
	var searchedCuisine = Ext.get("req-param-cuisine-idx");
	var cuisineValue = 'cuisine-00';
	if (searchedCuisine) {
		cuisineValue = searchedCuisine.dom.innerHTML;
	}
	
	var searchedExpense = Ext.get("req-param-expense-idx");
	var expenseValue = 'expense-00';
	if (searchedExpense) {
		expenseValue = searchedExpense.dom.innerHTML;
	}
	var expenseBoundaryDisabled = false;
	if (expenseValue=='expense-00') {
		expenseBoundaryDisabled = true;
	}
	
	var searchedExpenseBoundary = Ext.get("req-param-expense-boundary");
	var expenseBoundaryValue = 'About';
	if (searchedExpenseBoundary) {
		expenseBoundaryValue = searchedExpenseBoundary.dom.innerHTML;
	}
	
	var searchedDiscount = Ext.get("req-param-discount-idx");
	var discountValue = 'discount-00';
	if (searchedDiscount) {
		discountValue = searchedDiscount.dom.innerHTML;
	}
	
	var searchedOccasion = Ext.get("req-param-occasion-idx");
	var occasionValue = 'occasion-00';
	if (searchedOccasion) {
		occasionValue = searchedOccasion.dom.innerHTML;
	}
	
	var searchedVipRoom = Ext.get("req-param-vip-room-idx");
	var vipRoomValue = 'vip-room-00';
	if (searchedVipRoom) {
		vipRoomValue = searchedVipRoom.dom.innerHTML;
	}
	
	var searchedKeyword = Ext.get("req-param-keywordx");
	var keywordValue = '';
	if (searchedKeyword) {
		keywordValue = searchedKeyword.dom.innerHTML;
		keywordValue = Url.replaceEscape(keywordValue);
	}
	
	//handle submit*****************************************************************************
    var doSearchSubmit = function(){
    	var district = Ext.getCmp('search-form-district').getValue();
    	var cuisine = Ext.getCmp('search-form-cuisine').getValue();
    	var expense = Ext.getCmp('search-form-expense').getValue();
    	var expenseBoundary = Ext.getCmp('search-form-expense-boundary').getValue();
    	var discount = Ext.getCmp('search-form-discount').getValue();
    	var occasion = Ext.getCmp('search-form-occasion').getValue();
    	var vipRoom = Ext.getCmp('search-form-vip-room').getValue();
    	var keyword = Url.encode(Ext.getCmp('search-form-keyword').getValue());
    	window.location = '/showSummary.jsp?district-idx='+district+'&cuisine-idx='+cuisine+'&expense-idx='+expense+'&expense-boundary='+expenseBoundary+'&discount-idx='+discount+'&occasion-idx='+occasion+'&vip-room-idx='+vipRoom+'&keywordx='+keyword;
    }
	var doSearchReset = function(){
		Ext.getCmp('search-form-district').setValue('district-00');
		Ext.getCmp('search-form-cuisine').setValue('cuisine-00');
		Ext.getCmp('search-form-expense').setValue('expense-00');
		Ext.getCmp('search-form-expense-boundary').setValue('About');
		Ext.getCmp('search-form-expense-boundary').disable();
		Ext.getCmp('search-form-discount').setValue('discount-00');
		Ext.getCmp('search-form-occasion').setValue('occasion-00');
		Ext.getCmp('search-form-vip-room').setValue('vip-room-00');
		Ext.getCmp('search-form-keyword').setValue('');
	}
	
	var doListAll = function(){
		doSearchReset();
		doSearchSubmit();
	}
	
	//define 'book now' tab parameters**************************************************************
    var ds = new Ext.data.JsonStore({
    	url: '/RestaurantBookingServlet?action=getRestaurantSummary'
       ,root: 'results'
       ,totalProperty: 'totalCount'
       ,id: 'id'
       ,fields: ['id', 'name', 'photo', 'district', 'cuisine', 'discount', 'occasion', 'viproom', 'expense', 'address', 'points_rate', 'other_benefits', 'buffet']
    });
    
    // Custom rendering Template
    var resultTpl = new Ext.XTemplate(
        '<tpl for="."><div class="search-item" style="line-height:18px;">',
        	'<h3>',
        		'<table width="96%">',
        			'<tr valign="middle">',
        				'<td width="98%">{name}</td>',
        				'<td width="2%" align="right"><span style="{points_rate:this.getPointsRateDisplayCss}"><img src="/shared/sir/images/goldaward.gif" width="16" height="16" ext:qtip="Business Partner"/></td>',
        			'</tr>',
        		'</table>',
        	'</h3>',
        	'<table width="96%">',
        		'<tr valign="top">',
        			'<td width="15%" class="sub-info">Discount:</td>',
        			'<td width="85%" class="sub-info">{discount:this.getBenefitStr}</td>',
        		'</tr>',
        		'<tr valign="top" style="{other_benefits:this.getDisplayCss}">',
        			'<td class="sub-info">Other benefits:</td>',
        			'<td class="sub-info">{other_benefits:this.getBenefitStr}</td>',
        		'</tr>',
        		'<tr valign="top">',
        			'<td class="sub-info">Points rate:</td>',
        			'<td class="sub-info">{points_rate:this.getPointsRateStr}</td>',
        		'</tr>',
        		'<tr valign="top">',
        			'<td class="sub-info">Cuisine:</td>',
        			'<td class="sub-info">{cuisine}</td>',
        		'</tr>',
	    		'<tr valign="top">',
	    			'<td class="sub-info">VIP room:</td>',
	    			'<td class="sub-info">{viproom}</td>',
	    		'</tr>',
	    		'<tr valign="top" style="{buffet:this.getDisplayCss}">',
	    			'<td class="sub-info">Buffet:</td>',
	    			'<td class="sub-info">{buffet}</td>',
	    		'</tr>',
	    		'<tr valign="top">',
	    			'<td class="sub-info">Address:</td>',
	    			'<td class="sub-info">{address}</td>',
	    		'</tr>',
        	'</table>',
        '</div></tpl>',
        {
        	getBenefitStr: function(benefit) {
        		if (benefit && benefit.length != 0) {
        			return '<div style="color:#FF7700;">'+benefit+'</div>';
        		}
        		return 'No';
        	}
        },
        {
        	getPointsRateStr: function(points_rate) {
        		if (points_rate == 0) {
        			return points_rate;
        		}
        		return '<div style="color:#FF7700;">'+points_rate+'</div>';
        	}
        },
        {
        	getPointsRateDisplayCss: function(rate) {
        		if (rate!=0) {
        			return "";
        		}
        		return 'display:none;';
        	}
        },
		{
    		getDisplayCss: function(str){
    			if (str && str.length != 0) {
    				return '';
    			}
    			return 'display:none;';
    		}
    	}
    );
	
	//define landmarks store
    var landmark_store = new Ext.data.JsonStore({
    	url: '/RestaurantBookingServlet?action=getRestaurantTopLandmarks'
       ,root: 'results'
       ,fields: ['name', 'pos', 'url']
    });
    
    var tbar;
    landmark_store.on("load", function(st, recs){
	    var landmark_html = "";
	    var landmark_title = "";
	    if (landmarkTitleStore.getTotalCount() > 0) {
	    	var titleRec = landmarkTitleStore.getAt(0);
	    	landmark_title = Url.replaceEscape(titleRec.get('title'));
	    }
		landmark_html += '<span style="line-height:'+tbar_line_height+'px;font-size:12px;">';
		//landmark_html += '<span style="color:#A63737;font-size:14px;"><b>Landmarks <font style="font-size:13px;">&#22320;&#26631;</font>:</b></span>&nbsp;&nbsp;&nbsp;';
		landmark_html += landmark_title + '&nbsp;&nbsp;&nbsp;';
    	for (var i = 0; i < recs.length; i++) {
    		var url = recs[i].get('url');
     		var name = recs[i].get('name');
    		landmark_html += '<a href="'+url+'">'+name+'</a>&nbsp;&nbsp;&nbsp;';
    	}
		landmark_html += '</span>';
		
	    tbar = { 
			width:680, 
			tbar: [
				landmark_html
			]
		};
		tabpanel.config.toolbar = tbar;
		tabpanel.renderToolbar();
		
    });
    
    var tabpanel = new Ext.ux.InlineToolbarTabPanel({
//      xtype:'tabpanel',
		//toolbar: tbar,
        activeTab: activeTab,
        layoutOnTabChange:true,
        border: false,
        bodyStyle:'padding:10px 15px',
        defaults:{autoHeight:true}, 
        items:[{
            title:'<span style="font-size:12px;">Search Restaurants</span>',
            layout:'column',
	        labelAlign: 'top',

            items: [
            {
            	columnWidth:.225,
            	layout:'form',
                items: [{
                	xtype:'combo',
                	id:'search-form-district',
                	fieldLabel: 'District &#22320;&#21306; <span style="font-size:11px;color:blue">(<a href="javascript:showMap2()">Select from map</a>)</span>',
                    store: districtStore,
				    displayField: 'district',
                    valueField: 'id',
				    mode: 'local',
				    editable: false,
				    triggerAction: 'all',
				    tpl: '<tpl for="."><div class="x-combo-list-item combo-list-item-lvl{lvl}">{district}</div></tpl>',
                    name: 'district',
                    value: districtValue
                }]
            }
            ,{
            	columnWidth:.258,
            	layout:'form',
                items: [{
                    xtype:'combo',
                    id:'search-form-cuisine',
                	width:200,
                	fieldLabel: 'Cuisine &#33756;&#31995;',
                    store: cuisineStore,
				    displayField: 'cuisine',
                    valueField: 'id',
				    mode: 'local',
				    editable: false,
				    triggerAction: 'all',
				    tpl: new Ext.XTemplate(
				    	'<tpl for="."><div class="x-combo-list-item combo-list-item-lvl{lvl}">{cuisine}</div></tpl>',
				    	{
				    		decode: function(str){
				    			return str;
				    		}
				    	}
				    ),
                    name: 'cuisine',
                    value: cuisineValue
                }]
            }
            ,{
            	columnWidth:.085,
            	layout:'form',
                items: [{
                    xtype:'combo',
                    id:'search-form-expense-boundary',
                    fieldLabel: 'Expense per',
                    labelSeparator: '',
                    store: expenseBoundaryStore,
                    width:70,
				    displayField: 'boundary',
                    valueField: 'boundary',
				    mode: 'local',
				    editable: false,
				    disabled:expenseBoundaryDisabled,
				    triggerAction: 'all',
				    tpl: '<tpl for="."><div class="x-combo-list-item combo-list-item-lvl1">{boundary}</div></tpl>',
                    name: 'expense-boundary',
                    value: expenseBoundaryValue
                }]
            }
            ,{
            	columnWidth:.141,
            	layout:'form',
                items: [{
                    xtype:'combo',
                    id:'search-form-expense',
                    fieldLabel: 'person &#20154;&#22343;&#28040;&#36153;',
                    width:95,
                    store: expenseStore,
				    displayField: 'expense',
                    valueField: 'id',
				    mode: 'local',
				    editable: false,
				    triggerAction: 'all',
				    tpl: '<tpl for="."><div class="x-combo-list-item combo-list-item-lvl1">{expense}</div></tpl>',
                    name: 'expense',
                    value: expenseValue
                }]
            }
            ,{
            	columnWidth:.139,
            	layout:'form',
                items: [{
                    xtype:'combo',
                    id:'search-form-discount',
                    fieldLabel: 'Discount &#25240;&#25187;',
                    width:95,
                    store: discountStore,
				    displayField: 'discount',
                    valueField: 'id',
				    mode: 'local',
				    editable: false,
				    triggerAction: 'all',
				    tpl: '<tpl for="."><div class="x-combo-list-item combo-list-item-lvl1">{discount}</div></tpl>',
                    name: 'discount',
                    value: discountValue
                }]
            }
            ,{
            	columnWidth:.152,
            	layout:'form',
                items: [{
                    xtype:'combo',
                    id:'search-form-occasion',
                	fieldLabel: 'Occasion &#36866;&#21512;&#29992;&#36884;',
                    width:135,
                    store: occasionStore,
				    displayField: 'occasion',
                    valueField: 'id',
				    mode: 'local',
				    editable: false,
				    triggerAction: 'all',
				    tpl: '<tpl for="."><div class="x-combo-list-item combo-list-item-lvl1">{occasion}</div></tpl>',
                    name: 'occasion',
                    value: occasionValue
                }]
            }
            ,{
            	columnWidth:1,
                items: [{
                	xtype:'panel',
                	height:1,
                	html:'&nbsp;'
                }]
            }
            ,{
            	columnWidth:.225,
            	layout:'form',
                items: [{
                    xtype:'combo',
                    id:'search-form-vip-room',
                    fieldLabel: 'VIP room &#21253;&#21410;',
                    store: vipRoomStore,
				    displayField: 'viproom',
                    valueField: 'id',
				    mode: 'local',
				    editable: false,
				    triggerAction: 'all',
				    tpl: '<tpl for="."><div class="x-combo-list-item combo-list-item-lvl1">{viproom}</div></tpl>',
                    name: 'viproom-search',
                    value: vipRoomValue
                }]
            }
            ,{
            	columnWidth:.484,
            	layout:'form',
                items: [{
                    xtype:'textfield',
                    id:'search-form-keyword',
                    width: 402,
                    fieldLabel: 'Keyword &#20851;&#38190;&#23383;',
                    name: 'keyword',
                    emptyText: "Enter keywords of restaurant name or address, separated by space",
                    value: keywordValue
                }]
            }
            ,{
            	columnWidth:.133,
                items: [{
                	xtype:'button',
                	style:"margin-top:18px",
                    text: '<span style="font-weight:bold">Search & Book</span>',
                    tooltip: 'Search restaurants and make a booking',
                    handler: doSearchSubmit
                }]
            }
            ,{
            	columnWidth:.096,
                items: [{
                	xtype:'button',
                	style:"margin-top:18px",
                    text: '<span style="font-weight:bold">Show All</span>',
                    tooltip: 'List all restaurants',
                    handler: doListAll
                }]
            }
            ,{
            	columnWidth:.062,
                items: [{
                	xtype:'button',
                	style:"margin-top:18px",
                    text: '<span style="font-weight:bold">Reset</span>',
                    tooltip: 'Reset the search form',
                    handler: doSearchReset
                }]
            }],//end column layout
            keys: [{
	            key: Ext.EventObject.ENTER,
	            fn: doSearchSubmit
	        }]
        }
        //end tab "Custom Rest. Search"
        //start 2nd tab**************************************************************************************
        ,{
            title:'<span style="font-size:12px;">Book now</span>',
            height: 30,
            layout:'form',
	        labelAlign: 'top',
	        labelWidth: 75,

            items: [
                {
                	xtype: 'combo',
			        store: ds,
			        fieldLabel: 'Enter keyword of the restaurant name and select the one you want to book',
			        emptyText: '',
			        displayField:'name',
			        typeAhead: false,
			        loadingText: 'Searching...',
			        width: 600,
			        bodyStyle:'padding-top:40px;',
			        pageSize:10,
			        minChars: 1,
			        queryDelay: 1000,
			        hideTrigger:true,
			        emptyText: "Enter keyword of the restaurant name",
			        tpl: resultTpl,
			        itemSelector: 'div.search-item'
			        ,onSelect: function(record){ // override default onSelect to do redirect
			            this.setValue(record.get("name"));
			            this.collapse();
			        	showRestaurantBookingForm(record.get("id"));
			            //window.location = String.format('/RestaurantBooking.jsp?rest-id={0}', record.id);
			        }
			    }
			]
        }]
    });
        
	//form tabs*************************************************************************************
    var tabs = new Ext.FormPanel({
    	id: 'search-form',
    	labelWidth: 75, // label settings here cascade unless overridden
        width: 940,
        bodyStyle: 'background: white;',
        frame:true,
        collapsible:true,
        title:'<span class="home-centerpanel-header">Search & Book Restaurants <span style="font-weight:normal;">&#39184;&#21381;&#25628;&#32034;&#21644;&#39044;&#35746;</span></span>',
        iconCls: 'icon-magnifier',
        items: tabpanel
	});

	tabs.on('render', function(){
		landmarkTitleStore.load();
	});
	landmarkTitleStore.on('load', function(){
		landmark_store.load();
	});
	
	tabs.on('render', function(){
		if (collapse) {
			this.collapse();	//here, this = tabs
		}
		Ext.getCmp('search-form-expense').on('select', function(combo, rec, index){
			var value = combo.value;
			if (value=='expense-00') {
				Ext.getCmp('search-form-expense-boundary').disable();
			} else {
				Ext.getCmp('search-form-expense-boundary').enable();
			}
		});
	});
    tabs.render("search_and_book_form_tabs");

});

