/*
 * Ext JS Library 2.1
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
Ext.onReady(function(){
	
	var domNode = Ext.get('modify-restaurant-booking-form');
	if (domNode) {
		var maxLengthOtherRequirements = 500;
		var validationDelayInMillis = 2000;
		
		var restTpl = new Ext.XTemplate(
		    '<tpl for="."><div class="search-item" style="width:700px;">',
		    	'<div style="margin-bottom:5px;">',
			    	'<table width="100%" cellspacing="0" cellpadding="0">',
			    		'<tr>',
			    			'<td width="80%"><h3><span style="{points_rate:this.getPointsRateDisplayCss}"><img src="/shared/sir/images/goldaward.gif" width="16" height="16" ext:qtip="Business Partner"/>&nbsp;&nbsp;</span><a class="link" href="/singapore/restaurant/{name_identifier}/" target="_blank" ext:qtip="Click to view details of this restaurant.">{name}</a></h3></td>',
			    			'<td width="30%" align="right"><a href="/singapore/restaurant/{name_identifier}/" target="_blank">View Restaurant Details</a></td>',
			    		'</tr>',
			    	'</table>',
			    '</div>',
		    	'<div style="line-height:18px;">',
			    	'<table width="100%" cellspacing="3">',
			    		'<tr valign="top">',
			    			'<td width="15%">Discount:</td>',
			    			'<td width="85%">{discount:this.getDiscountStr}</td>',
			    		'</tr>',
		        		'<tr valign="top" style="{other_benefits:this.getDisplayCss}">',
		        			'<td>Other benefits:</td>',
		        			'<td>{other_benefits:this.getOtherBenefitsStr}</td>',
		        		'</tr>',
		        		'<tr valign="top">',
		        			'<td>Points rate:</td>',
		        			'<td>{points_rate:this.getPointsRateStr}</td>',
		        		'</tr>',
			    		'<tr valign="top">',
			    			'<td>Cuisine:</td>',
			    			'<td>{cuisine}</td>',
			    		'</tr>',
			    		'<tr valign="top">',
			    			'<td>VIP room:</td>',
			    			'<td>{viproom}</td>',
			    		'</tr>',
			    		'<tr valign="top">',
			    			'<td>Address:</td>',
			    			'<td>{address}</td>',
			    		'</tr>',
			    	'</table>',
		    	'</div>',
		    '</div></tpl>',
	        {
	        	getDiscountStr: function(discount) {
	        		if (discount && discount.length != 0) {
	        			return '<font style="color:red;font-weight:bold;">'+discount+'</font>';
	        		}
	        		return 'No';
	        	}
	        },
	        {
	        	getOtherBenefitsStr: function(other_benefits) {
	        		if (other_benefits && other_benefits.length != 0) {
	        			return '<font style="color:red;">'+other_benefits+'</font>';
	        		}
	        		return 'No';
	        	}
	        },
	        {
	        	getPointsRateStr: function(points_rate) {
	        		if (points_rate == 0) {
	        			return points_rate;
	        		}
	        		return '<font style="color:red;">'+points_rate+'</font>';
	        	}
	        },
	        {
	        	getPointsRateDisplayCss: function(rate) {
	        		if (rate!=0) {
	        			return "";
	        		}
	        		return 'display:none;';
	        	}
	        },
			{
	    		getDisplayCss: function(str){
	    			if (str && str.length != 0) {
	    				return '';
	    			}
	    			return 'display:none;';
	    		}
	    	}
		);
		
		RestSummaryPanel = Ext.extend(Ext.DataView, {
			frame: true
			,loadingText: 'loading...'
			,itemSelector: 'table'
			,tpl: restTpl
		});
		
	
		//get parameters
		var restIdNode = Ext.get("req-param-restid");
		var restId = '';
		if (restIdNode) {
			restId = restIdNode.dom.innerHTML;
		}

		//get parameters
		var bookingIdNode = Ext.get("req-param-bookingid");
		var bookingId = '';
		if (bookingIdNode) {
			bookingId = bookingIdNode.dom.innerHTML;
		}
		
		//define stores*******************************************************************************************
	    var restStore = new Ext.data.JsonStore({
	    	url: '/RestaurantServlet?action=getRestaurantSummary&rest-id='+restId
	       ,root: 'results'
	       ,totalProperty: 'totalCount'
	       ,id: 'id'
	       ,fields: ['id', 'name', 'photo', 'district', 'cuisine', 'discount', 'occasion', 'viproom', 'expense', 'address', 
	       		'points_rate', 'other_benefits', 'name_identifier']
	       ,autoLoad: true
	    });
		
		//define stores*******************************************************************************************
	    var bookingStore = new Ext.data.JsonStore({
	    	url: '/RestaurantServlet?action=getUserRestaurantBookingRecords&bookingid='+bookingId
	    	,root: 'results'
	       	,totalProperty: 'totalCount'
	       	,id: 'id'
	       	,fields: ['id', 'booking_date2', 'booking_time2', 'dining_date2', 'dining_time2',
	       			'rest_id', 'rest_name', 'rest_address', 'no_of_persons', 'viproom', 'title', 'name', 
	       			'mobile', 'mobile_ctry_code', 'email', 'contact_via', 'points', 'status', 'book_via', 
	       			'diner_preferred_language', 'other_requirements', 'total_bill']
	    });
		
		var timeStore = new Ext.data.SimpleStore({
		    fields: ['time', 'id'],
		    data: [
		    	['10:00 AM', 'time-000'], ['10:15 AM', 'time-001'], ['10:30 AM', 'time-002'], ['10:45 AM', 'time-003'],
		    	['11:00 AM', 'time-004'], ['11:15 AM', 'time-005'], ['11:30 AM', 'time-006'], ['11:45 AM', 'time-007'],
		    	['12:00 PM', 'time-008'], ['12:15 PM', 'time-009'], ['12:30 PM', 'time-010'], ['12:45 PM', 'time-011'],
		    	['1:00 PM', 'time-012'], ['1:15 PM', 'time-013'], ['1:30 PM', 'time-014'], ['1:45 PM', 'time-015'],
		    	['2:00 PM', 'time-016'], ['2:15 PM', 'time-017'], ['2:30 PM', 'time-018'], ['2:45 PM', 'time-019'],
		    	['3:00 PM', 'time-020'], ['3:15 PM', 'time-021'], ['3:30 PM', 'time-022'], ['3:45 PM', 'time-023'],
		    	['4:00 PM', 'time-024'], ['4:15 PM', 'time-025'], ['4:30 PM', 'time-026'], ['4:45 PM', 'time-027'],
		    	['5:00 PM', 'time-028'], ['5:15 PM', 'time-029'], ['5:30 PM', 'time-030'], ['5:45 PM', 'time-031'],
		    	['6:00 PM', 'time-032'], ['6:15 PM', 'time-033'], ['6:30 PM', 'time-034'], ['6:45 PM', 'time-035'],
		    	['7:00 PM', 'time-036'], ['7:15 PM', 'time-037'], ['7:30 PM', 'time-038'], ['7:45 PM', 'time-039'],
		    	['8:00 PM', 'time-040'], ['8:15 PM', 'time-041'], ['8:30 PM', 'time-042'], ['8:45 PM', 'time-043'],
		    	['9:00 PM', 'time-044'], ['9:15 PM', 'time-045'], ['9:30 PM', 'time-046'], ['9:45 PM', 'time-047'],
		    	['10:00 PM', 'time-048'], ['10:15 PM', 'time-049'], ['10:30 PM', 'time-050'], ['10:45 PM', 'time-051'],
		    	['11:00 PM', 'time-052'], ['11:15 PM', 'time-053'], ['11:30 PM', 'time-054'], ['11:45 PM', 'time-055']
		    ]
		});
	
		var titleStore = new Ext.data.SimpleStore({
		    fields: ['title', 'id'],
		    data: [['Mr.', 'title-0'], ['Ms.', 'title-1']]
		});
		
		var viproomStore = new Ext.data.SimpleStore({
		    fields: ['viproom'],
		    data: [["I don't mind"], ['Preferred'], ['Required']]
		});
		
		var contactviaStore = new Ext.data.SimpleStore({
		    fields: ['contactvia'],
		    data: [["SMS"], ['Phone'], ['E-mail']]
		});
		
		var preferredLanguageStore = new Ext.data.SimpleStore({
		    fields: ['language'],
		    data: [["English"], ['Chinese']]
		});
		
		//Create error window*****************************************************************************
	    var errWindow = new Ext.Window({
	        title: 'Invalid input!',
	        width: 350,
	        height:'auto',
	        layout: 'fit',
	        plain:true,
	        bodyStyle:'padding:5px;',
	        buttonAlign:'center',
	        closeAction: 'hide',
	        html: '',
	
	        buttons: [{
	            text: 'Close',
	            handler: function(){errWindow.hide()},
	            scope: this
	        }]
	    });
		
		var errMsg = '';
		errWindow.on('show', function(){
			this.body.dom.innerHTML = "<div style='padding:10px;color:red;font: 12px;'>"+errMsg+"</div>";
		});
		
		var diningDate;
		var diningTime;
		var noOfPerson;
		var vipRoom;
		var otherRequirements;
		var contactTitle;
		var contactName;
		var contactMobileCtryCode;
		var contactMobile;
		var contactEmail;
		var contactVia;
		var contactPreferredLanguage;
		//handle submit*****************************************************************************************
		 var doSubmit = function(){
		 	//detect content change
	    	var newDiningDate = Ext.getCmp('booking-form-date').getRawValue();
			var newDiningTime = Ext.getCmp('booking-form-time').getValue();
	    	var newNoOfPerson = Ext.getCmp('booking-form-noofperson').getValue();
	    	var newVipRoom = Ext.getCmp('booking-form-viproom').getValue();
	    	var newOtherRequirements = Ext.getCmp('booking-form-other-requirements').getRawValue();
            var newContactTitle = Ext.getCmp('booking-form-title').getValue();
            var newContactName = Ext.getCmp('booking-form-name').getValue();
            var newContactMobileCtryCode = Ext.getCmp('booking-form-mobile-ctrycode').getValue();
            var newContactMobile = Ext.getCmp('booking-form-mobile').getValue();
            var newContactEmail = Ext.getCmp('booking-form-email').getValue();
            var newContactVia = Ext.getCmp('booking-form-contactvia').getValue();

            var newContactPreferredLanguage = Ext.getCmp('booking-form-preferred-language').getValue();

            if (diningDate==newDiningDate&&diningTime==newDiningTime&&noOfPerson==newNoOfPerson&&vipRoom==newVipRoom&&otherRequirements==newOtherRequirements
				&&contactTitle==newContactTitle&&contactName==newContactName&&contactMobileCtryCode==newContactMobileCtryCode&&contactMobile==newContactMobile
				&&contactEmail==newContactEmail&&contactVia==newContactVia&&contactPreferredLanguage==newContactPreferredLanguage) {
	    		errMsg = "You haven't changed anything.";
	    		errWindow.show();
	    		return;
			}
			
	    	var isDateValid = Ext.getCmp('booking-form-date').isValid();
	    	var isTimeValid = Ext.getCmp('booking-form-time').isValid();
	    	var isNoOfPersonValid = Ext.getCmp('booking-form-noofperson').isValid();
	    	var isNameValid = Ext.getCmp('booking-form-name').isValid();
	    	var isMobileValid = Ext.getCmp('booking-form-mobile').isValid();
	    	var isEmailValid = Ext.getCmp('booking-form-email').isValid();
	    	var isOtherRequirementsValid = Ext.getCmp('booking-form-other-requirements').isValid();
	    	if (!isDateValid || !isNoOfPersonValid || !isNameValid || !isMobileValid || !isEmailValid || !isOtherRequirementsValid) {
	    		errMsg = 'Some fields contain errors. Please correct them first.';
	    		errWindow.show();
	    		return;
	    	}
	    	
	    	var record = restStore.getAt(0);
	    	var hasVipRoom = record.get('viproom');
	    	var optVipRoom = Ext.getCmp('booking-form-viproom').getValue();
	    	if (optVipRoom == 'Required' && hasVipRoom == 'No') {
	    		Ext.getCmp('booking-form-viproom').markInvalid("This restaurant doesn't have VIP room.");
	    		errMsg = 'Some fields contain errors. Please correct them first.';
	    		errWindow.show();
	    		return;
	    	}
			
			var mobile = Ext.getCmp('booking-form-mobile').getValue();
			var email = Ext.getCmp('booking-form-email').getValue();
			var contactvia = Ext.getCmp('booking-form-contactvia').getValue();
			if (contactvia == 'E-mail') {
				contactvia = 'Email';
			}
			if (contactvia == 'SMS') {
				if (mobile.length == 0) {
					Ext.getCmp('booking-form-mobile').markInvalid("Mobile number is required if you want to be contacted by sms.");
		    		errMsg = 'Some fields contain errors. Please correct them first.';
		    		errWindow.show();
		    		return;
				}

			} else if (contactvia == 'Phone') {
				if (mobile.length == 0) {
					Ext.getCmp('booking-form-mobile').markInvalid("Phone number is required if you want to be contacted by phone.");
		    		errMsg = 'Some fields contain errors. Please correct them first.';
		    		errWindow.show();
		    		return;
				}

			} else if (contactvia == 'Email') {
				if (email.length == 0) {
					Ext.getCmp('booking-form-email').markInvalid("Email is required if you want to be contacted by email.");
		    		errMsg = 'Some fields contain errors. Please correct them first.';
		    		errWindow.show();
		    		return;
				}
			}
			
			var otherRequirementsCmp = Ext.getCmp('booking-form-other-requirements');
			if(otherRequirementsCmp.getRawValue() == ''){
				Ext.getCmp('booking-form-other-requirements').setRawValue('');
			}
			
			Ext.getCmp('submit-btn').disable();
			Ext.getCmp('cancel-btn').disable();
			panel.submit();
		 }
		
		//define main view****************************************************************************************
	    var panel = new Ext.FormPanel({
	    	url:'/restaurants/RestaurantBooking.jsp',
	        autoHeight: true,
	        autoScroll: false,
	        frame: true,
	        title: '<span class="panel-title">Restaurant Booking Form &#20462;&#25913;&#39184;&#21381;&#39044;&#35746;&#34920;&#26684;</span>',
	        layout: 'column',
	        submit: function() {
	            this.getForm().getEl().dom.submit();
	        },
	
	        items: [
		        new RestSummaryPanel({
		            store: restStore
		        })
	        	,{
			        columnWidth:1,
	        		items:[
	        			{
	        				xtype:'panel',
	        				html: '<div style="padding:20px 10px 10px;"><h3>Booking Info</h3></div>'
	        			}
	        		]
	            }
                ,{
                	columnWidth:.31,
                	height: 30,
                	layout:'form',
                	labelWidth: 90,
					bodyStyle:'padding:0px 10px;',
	                items: [{
	                    xtype:'datefield',
	                    fieldLabel: 'Date/Time',
	                    //minValue: new Date(),
	                    allowBlank: false,
	                    width: 100,
	                    id: 'booking-form-date',
	                    name: 'booking-form-date'
	                }]
                }
                ,{
                	columnWidth:.69,
                	height: 30,
                	layout:'form',
                	labelWidth: 1,
	                items: [{
	                    xtype:'combo',
	                    width: 102,
	                    fieldLabel: '',
	                    labelSeparator: '',
	                    editable: false,
					    mode: 'local',
	                    store: timeStore,
					    displayField: 'time',
	                    valueField: 'time',
					    triggerAction: 'all',
					    allowBlank: false,
	                    tpl: '<tpl for="."><div class="x-combo-list-item combo-list-item-lvl1">{time}</div></tpl>',
	                    id: 'booking-form-time',
	                    name: 'booking-form-time', 
	                    value:'7:00 PM'
	                }]
                }
                ,{
                	columnWidth:1,
                	height: 30,
                	layout:'form',
					bodyStyle:'padding:0px 10px;',
                	labelWidth: 90,
	                items: [{
	                    xtype:'numberfield',
	                    width: 100,
	                    fieldLabel: 'No of person',
		                allowBlank: false,
		                allowDecimals: false,
		                allowNegative: false,
	                    id: 'booking-form-noofperson',
	                    name: 'booking-form-noofperson'
	                }]
                }
                ,{
                	columnWidth:1,
                	height: 30,
                	layout:'form',
					bodyStyle:'padding:0px 10px;',
                	labelWidth: 90,
	                items: [{
	                    xtype:'combo',
	                    width: 100,
	                    fieldLabel: 'VIP room',
	                    store: viproomStore,
					    displayField: 'viproom',
	                    valueField: 'viproom',
					    mode: 'local',
					    editable: false,
					    triggerAction: 'all',
					    tpl: '<tpl for="."><div class="x-combo-list-item combo-list-item-lvl1">{viproom}</div></tpl>',
	                    id: 'booking-form-viproom',
	                    name: 'booking-form-viproom',
		                value: "I don't mind"
	                }]
                }
                ,{
                	columnWidth:1,
                	autoHeight: true,
                	layout:'form',
					bodyStyle:'padding:0px 10px 5px 10px;border-bottom:1px solid #eeeeee;',
                	labelWidth: 90,
	                items: [{
	                    xtype:'textarea',
	                    border:false,
	                    width: 400,
	                    height: 100,
	                    maxLength: maxLengthOtherRequirements,
	                    fieldLabel: 'Other requirements<br/>(<span id="charcount">'+maxLengthOtherRequirements+'</span> chars left)',
	                    emptyText: 'Enter your other requirements here. We will do our best to help you.',
	                    id: 'booking-form-other-requirements',
	                    name: 'booking-form-other-requirements',
	                    enableKeyEvents:true,
	                    value:'',
	                    listeners: {
	                    	'keyup': function(cmp, e) {
	                    		var textLength = cmp.getValue().length;
	                    		var left = maxLengthOtherRequirements-textLength;
	                    		if (left < 0) {
	                    			left = '<span style="color:red">'+left+'</span>';
	                    		}
	                    		Ext.get('charcount').dom.innerHTML = left;
	                    	}
	                    }
		                
	                }]
                }
	        	,{
			        columnWidth:1,
	        		items:[
	        			{
	        				xtype:'panel',
	        				html: '<div style="padding:20px 10px 10px;"><h3>Your Info</h3></div>'
	        			}
	        		]
	            }
                ,{
                	columnWidth:.23,
                	height: 30,
                	bodyStyle:'padding:0px 10px;',
                	labelWidth: 90,
                	layout:'form',
	                items: [{
	                    xtype:'combo',
	                	width:50,
	                	listWidth: 50,
	                    fieldLabel: 'Your name',
	                    store: titleStore,
					    displayField: 'title',
	                    valueField: 'title',
					    mode: 'local',
					    editable: false,
					    triggerAction: 'all',
					    tpl: '<tpl for="."><div class="x-combo-list-item combo-list-item-lvl1">{title}</div></tpl>',
	                    id: 'booking-form-title',
	                    name: 'booking-form-title',
	                    value: 'Mr.'
	                }]
                }
                ,{
                	columnWidth:.67,
                	height: 30,
                	layout: 'form',
	                labelWidth: 1,
	                items: [{
	                    xtype:'textfield',
	                    width: 150,
	                    fieldLabel: '',
	                    labelSeparator: '',
	                    allowBlank: false,
	                    id: 'booking-form-name',
	                    name: 'booking-form-name'
	                }]
                }
                ,{
                	columnWidth:.21,
                	height: 30,
                	bodyStyle:'padding:0px 0px 0px 10px;',
                	layout:'form',
                    labelWidth: 90,
	                items: [{
	                    xtype:'numberfield',
	                    width: 40,
	                    fieldLabel: 'Your phone no',
		                allowDecimals: false,
		                allowNegative: false,
	                    maxLength: 3,
	                    value:'65',
	                    id: 'booking-form-mobile-ctrycode',
	                    name: 'booking-form-mobile-ctrycode'
	                }]
                }
                ,{
                	columnWidth:.17,
                	layout: 'form',
	                labelWidth: 1,
	                items: [{
	                    xtype:'numberfield',
	                    width: 106,
	                    fieldLabel: '',
		                allowDecimals: false,
		                allowNegative: false,
	                    labelSeparator: '',
	                    maxLength: 16,
	                    id: 'booking-form-mobile',
	                    name: 'booking-form-mobile'
	                }]
                }
	            ,{
	        		columnWidth:.62,
			        border: false,
	        		items:[
	        			{
		                	xtype:'panel',
					        border: false,
		                	style:'',
		                    html: 'Use <b>international format</b>. Remove leading 0 or + if any. Example: 65 91234567 where 65 is country code. Note that you need to provide mobile phone no if you want to be contacted via SMS.'
	        			}
	        		]
	            }
                ,{
                	columnWidth:1,
                	height: 30,
                	bodyStyle:'padding:0px 10px;',
                	layout:'form',
                    labelWidth: 90,
	                items: [{
	                    xtype:'textfield',
	                    width: 157,
	                    fieldLabel: 'Your email',
        				maxLength: 128,
        				validationDelay: validationDelayInMillis,
	                    validator: function(value){
							return validateEmail(value);
						},
	                    id: 'booking-form-email',
	                    name: 'booking-form-email'
	                }]
                }
                ,{
                	columnWidth:1,
                	height: 30,
                	layout:'form',
					bodyStyle:'padding:0px 10px',
                	labelWidth: 90,
	                items: [{
	                    xtype:'combo',
	                    width: 157,
	                    fieldLabel: 'Contact you via',
	                    store: contactviaStore,
					    displayField: 'contactvia',
	                    valueField: 'contactvia',
					    mode: 'local',
					    editable: false,
					    triggerAction: 'all',
					    tpl: '<tpl for="."><div class="x-combo-list-item combo-list-item-lvl1">{contactvia}</div></tpl>',
	                    id: 'booking-form-contactvia',
	                    name: 'booking-form-contactvia',
		                value: "SMS"
	                }]
                }
                ,{
                	columnWidth:1,
                	height: 35,
                	layout:'form',
					bodyStyle:'padding:0px 10px 0px 10px',
                	labelWidth: 90,
	                items: [{
	                    xtype:'combo',
	                    width: 157,
	                    fieldLabel: 'Your preferred language',
	                    store: preferredLanguageStore,
					    displayField: 'language',
	                    valueField: 'language',
					    mode: 'local',
					    editable: false,
					    triggerAction: 'all',
					    tpl: '<tpl for="."><div class="x-combo-list-item combo-list-item-lvl1">{language}</div></tpl>',
	                    id: 'booking-form-preferred-language',
	                    name: 'booking-form-preferred-language',
		                value: "English"
	                }]
                }
                ,{
                	columnWidth:1,
                	layout:'form',
                	border:false,
	                items: [{
	                    xtype:'hidden',
	                    border:false,
	                    id: 'update-form-modify',
	                    name: 'update-form-modify',
	                    value: 'true'
	                }]
                }
                ,{
                	columnWidth:1,
                	height: 20
                }
		    ]
	        ,buttonAlign:'center'
		    ,buttons: [
		    	{
		    		id: 'submit-btn',
		    		text: '<b>Save Changes</b>',
		    		handler: doSubmit
		    	},
		    	{
		    		id: 'cancel-btn',
		    		text: '<b>Cancel</b>',
		    		handler: function() {
		    			history.back();
		    		}
		    	}
		    ]
	    });
	    
	    panel.on('render', function(){
	    	bookingStore.load({
				params: {
			    },
			    callback: function(records){
			    	diningDate = records[0].get('dining_date2');
					diningTime = records[0].get('dining_time2');
					if (diningTime.charAt(0) == '0') {
						diningTime = diningTime.substring(1, diningTime.length);
					}
			    	Ext.getCmp('booking-form-date').setValue(diningDate);
					Ext.getCmp('booking-form-time').setValue(diningTime);
			    	
			    	noOfPerson = records[0].get('no_of_persons');
			    	Ext.getCmp('booking-form-noofperson').setValue(noOfPerson);
			    	
			    	vipRoom = Url.replaceEscape(records[0].get('viproom'));
			    	Ext.getCmp('booking-form-viproom').setValue(vipRoom);
			    	
			    	otherRequirements = Url.replaceEscape(records[0].get('other_requirements'));
			    	Ext.getCmp('booking-form-other-requirements').setValue(otherRequirements);
			    	
		            contactTitle = Url.replaceEscape(records[0].get('title'));
		            Ext.getCmp('booking-form-title').setValue(contactTitle);
		            
		            contactName = Url.replaceEscape(records[0].get('name'));
		            if (contactName && contactName.length != 0) {
			            Ext.getCmp('booking-form-name').setValue(contactName);
		            }
		            
		            contactMobileCtryCode = records[0].get('mobile_ctry_code');
		            Ext.getCmp('booking-form-mobile-ctrycode').setValue(contactMobileCtryCode);
		            
		            contactMobile = records[0].get('mobile');
		            Ext.getCmp('booking-form-mobile').setValue(contactMobile);
		            
		            contactEmail = Url.replaceEscape(records[0].get('email'));
		            Ext.getCmp('booking-form-email').setValue(contactEmail);
		            
		            contactVia = records[0].get('contact_via');
		            if (contactVia == 'Email') {
		            	contactVia = 'E-mail';
		            }
		            Ext.getCmp('booking-form-contactvia').setValue(contactVia);
		            
		            contactPreferredLanguage = records[0].get('diner_preferred_language');
		            Ext.getCmp('booking-form-preferred-language').setValue(contactPreferredLanguage);
			    }
	    		
	    	});
	    });
	    
	    panel.render('modify-restaurant-booking-form');
	}

	//validate email*******************************************************
	function validateEmail() {
		var cmp = Ext.getCmp('booking-form-email');
		var email = cmp.getValue();
		if (email.length == 0) {
			return true;
		}
		var msg = checkEmail(email);
		if (msg.length != 0) {
			return msg;
		}
		return true;
	}

	//validate mobile number***************************************************
	function validateMobileNumber() {
		var cmp = Ext.getCmp('booking-form-mobile');
		var mobile = cmp.getValue();
		if (mobile.length == 0) {
			return true;
		}
		var msg = checkMobileNumber(mobile);
		if (msg.length != 0) {
			return msg;
		}
		return true;
	}

});


