
	if(!searchHotelsLabel) {var searchHotelsLabel='Search Hotels';}
	if(!searchHolidaysLabel) {var searchHolidaysLabel='Search Holidays';}
	if(!selectDestinationLabel) {var selectDestinationLabel= 'Please select a destination';}
	if(!selectDepartureCityLabel) {var selectDepartureCityLabel= 'Please select departure city';}


	var activeForm='hotel_searchform';

	var oHotelSearchFormMaker = '';
	var oHotelClassicSearchFormMaker = '';
	var oHolidaySearchFormMaker = '';
	var oFlightSearchFormMaker = '';
	var oFlightHotelSearchFormMaker = '';



	var clickHoliday = function ()	{

			$('#serchBoxTitle').html(searchHolidaysLabel);
			if(oHolidaySearchFormMaker == '') {
				try {
					oHolidaySearchFormMaker = new HolidaySearchFormMaker({

						//form ID
						'sElementId' : 'holiday_searchform',

						//will pass in jquery object and element name, 
						//so we can manipulate it here with 3rd party date picker
						'DateFormat':'dd-mm-yyyy',
						'DateHandler' : function( oStartDate, oEndDate, oNight ) {

							oStartDate.attr('readOnly', true);
							oEndDate.attr('readOnly', true);

							oStartDate.datePickerMultiMonth({
								numMonths: 2,
								clickInput:true,
								displayClose:true
							});
							oEndDate.datePickerMultiMonth({
								numMonths: 2,
								clickInput:true,
								displayClose:true
							});

							$(document).bind('keyup keypress', function(e){
								if(e.which==27){
									oStartDate.dpClose();
									oEndDate.dpClose();
								}
							});
									
							//Initial date correction
							var iAddDaysAhead = 1;
							var d = new Date();
							oStartDate.val(d.addDays(iAddDaysAhead).asString());
							oEndDate.val(d.addDays(parseInt(oNight.val())+1).asString());
							oStartDate.dpSetSelected(oStartDate.val());
							oEndDate.dpSetSelected(oEndDate.val());
							return true;
						}, 
						// indate/outdate checker, trigger on change, return true for OK
						// ichange, 1 = start date, 2 = end date, 3 = night change
						'DateValidator' : function( ichange, oStartDate, oEndDate, oNight, mData1, mData2 ) {
							//alert('> '+oNight.val()+' , '+mData1+' , '+mData2);

							//StartDate change
							if(ichange==1){

								var d = new Date();
								if(d.asString() == oStartDate.val()){
								   alert('Your CHECK IN date must be a  least 1 day from now');
									oStartDate.val(d.addDays(1).asString());
								}else{
									//update end date base on selected night
									oEndDate.val(mData2); 
									oEndDate.dpSetSelected(oEndDate.val());
								}
							}
							//endDate change
							if(ichange==2){
								if(mData1<1){
									alert('Your CHECK OUT date must  be greater than CHECK IN date');
									oEndDate.val(mData2); //auto correction for invalid date
									oEndDate.dpSetSelected(oEndDate.val());
								}else{
									//update night selection box
									if(mData1>14){
										alert('Your interval between CHECK IN and  CHECK OUT date must be less than 14 days');
										var oEndD = Date.fromString(oStartDate.val());
										oEndDate.dpSetSelected(oEndD.addDays(14).asString());
										oNight.selectOptions(14+'');
									}else{
										mData1--;
										oNight.selectOptions(mData1+'');
									}
								}
							}

							//night change
							if(ichange==3){
								//update end date base on night
								oEndDate.val(mData2); 
								oEndDate.dpSetSelected(oEndDate.val());
							}
							return true;
						}, 
						'SubmitValidator' : function(oType, oDestination, oAirPort) {

							if(oDestination.val()=='') {
								alert(selectDestinationLabel);
								return false;
							}
							if(oType.val()=='Holiday+Flight' &&  oAirPort.val()=='') {
								alert(selectDepartureCityLabel);
								return false;
							}
							return true;
						},

						//select box option list

						'sHolidayTypesSource' : '/holidays/theme-list?true=1',
						'sHolidayTypesDefault' :'I don\'t mind',

						'sHolidayDestinationSource' : '/holidays/town-list?true=1',
						'sDestinationsDefault' :'',

						'sHolidayAirportSource' : '/holidays/departure-airport-list?true=1', 
						'sDepartureAirPortDefault' :'',

						'oNumberNight' : [1,2,3,4,5,6,7,8,9,10,11,12,13,14],
						'sNumberNightDefault' :4,

						'aRoomList' : [1,2,3,4],
						'iRoomDefault' : 1,

						'aAdultList' : [1,2,3],
						'iAdultDefault' : 2,
						'aChildList' : [0,1,2],
						'iChildDefault' : 0,
						'aInfantList' : [0,1,2],
						'iInfantDefault' : 0
					});

					//generate the form
					oHolidaySearchFormMaker.draw();
				}catch(e){}
			}

			if($('#search_types_holiday').attr("checked") == true) {
				$('#'+activeForm).hide();
				$('#holiday_searchform').show();
				$('#departure_city').hide();
				$('#sHolidayType').val('Holiday');
			}

			if($('#search_types_holiday_flight').attr("checked") == true) {
				$('#'+activeForm).hide();
				$('#holiday_searchform').show();
				$('#departure_city').show();
				$('#sHolidayType').val('Holiday+Flight');
			} 
			activeForm='holiday_searchform';
		}




			// ==================================================================
			var clickFlight = function ()	{
					$('#serchBoxTitle').html(searchFlightLabel);

					if(oFlightSearchFormMaker == '') {
						try {
							oFlightSearchFormMaker = new FlightSearchFormMaker({

								//form ID
								'sElementId' : 'flight_searchform',
								
								//location form handler
								'LoactionHandler' : function(oCountryCode,oRegion,oLocationList, oElementId) {
									
									//Auto compliter start
									var oAutoCompleter = new AutoCompleter({

										'sUrl' : '/flights2/airport-list?pattern=SEARCH_KEYWORD',
										'iCharLimit' : 2,
										'iRenderLimit' : 10,
										'sElementId' : oElementId,
										'sResultShowAllCSS' : {},
										'sResultShowMinCSS' : {},
										'bNoEscForSearchField':false,
										'bShowSearchFieldAfterEsc':true,
										'bPersisField':false,
										'onData' : function(oData, sKeyword) {

											var sDivOut = [];
											var h =0;
											//loop through data
											for ( var i in oData ) {
												for ( var j in oData[i] ) {
													sDivOut.push({
													  'id':h,
													  'value':{'i':i,'j':j}, 
													  'displaytxt':''+j+', '+i, 
													  'count':oData[i][j],
													  'display': '<div style="float:left;">'+j+', '+i+'</div> <div class="__cl" style="float:right;"></div> <div style="clear:both;"/>'
													});
													h++;
												}
											} 
											return sDivOut;
										},
										'onSelect' : function(id,value,Display){
											//this will let you define how to handle selected data
											oCountryCode.val(value.i);
											oRegion.val(''); //PYO2 didnt have region
											oLocationList.val(value.j);
										}
									});
									oAutoCompleter.start();
									//Auto completer end
								},


								//will pass in jquery object and element name, 
								//so we can manipulate it here with 3rd party date picker
								'DateFormat':'dd-mm-yyyy',

								'DateHandler' : function( oStartDate, oEndDate, oNight ) {
									oStartDate.attr('readOnly', true);
									oEndDate.attr('readOnly', true);

									oStartDate.datePickerMultiMonth({
										numMonths: 2,
										clickInput:true,
										displayClose:true
									});
									oEndDate.datePickerMultiMonth({
										numMonths: 2,
										clickInput:true,
										displayClose:true
									});

									$(document).bind('keyup keypress', function(e) {
										if(e.which==27) {
											oStartDate.dpClose();
											oEndDate.dpClose();
										}
									});

									
									//Initial date correction
									var iAddDaysAhead = 5;
									var d = new Date();
									oStartDate.val(d.addDays(iAddDaysAhead).asString());
									oEndDate.val(d.addDays(parseInt(oNight.val())).asString());
									oStartDate.dpSetSelected(oStartDate.val());
									oEndDate.dpSetSelected(oEndDate.val());
									return true;
								}, 

								// indate/outdate checker, trigger on change, return true for OK
								// ichange, 1 = start date, 2 = end date, 3 = night change
								'DateValidator' : function( ichange, oStartDate, oEndDate, oNight, mData1, mData2 ) {


									//StartDate change
									if(ichange==1) {
										var d = new Date();

										var darr=oStartDate.val().split('-');
//										alert(darr[0]+' '+darr[1]+' '+darr[2]);

										var d2=new Date(parseInt(darr[2],10), parseInt(darr[1],10)-1, parseInt(darr[0],10));
										var one_day=1000*60*60*24;
										var days=Math.ceil((d2.getTime()-d.getTime())/(one_day));

//										alert("now="+d.asString()+"\nd2=="+d2.asString()+"\nstartdate="+oStartDate.val()+"\ndays="+days+' nights='+oNight.val()+' md1='+mData1+' md2='+mData2);

//										if(d.asString() == oStartDate.val()) {
										if(days<5) {
											alert('Your departure date must be a  least 5 days from now');
											oStartDate.val(d.addDays(5).asString());
										} else {
											var darr=oEndDate.val().split('-');
											var ed=new Date(parseInt(darr[2],10), parseInt(darr[1],10)-1, parseInt(darr[0],10));
											var days=Math.ceil((ed.getTime()-d2.getTime())/(one_day));
//											alert('xxxx:'+days);	

											if(days<1) {
//   												ed.setDate(d2.getDate()+10);
												ed=new Date(d2.getTime() + 10*24*60*60*1000);

//    												alert(ed.asString());

												//update end date 
												oEndDate.val(ed.asString()
); 
												oEndDate.dpSetSelected(oEndDate.val());

											}

/*
											//update end date base on selected night
											oEndDate.val(mData2); 
											oEndDate.dpSetSelected(oEndDate.val());
*/
										}
										
									}

									//EndDate change
									if(ichange==2) {
										if(mData1<1){
											alert('Return date must be later than departure date');
											oEndDate.val(mData2); //auto correction for invalid date
											oEndDate.dpSetSelected(oEndDate.val());
										} else {
											//update night selection box
											if(mData1>365){
												alert('Your interval between departure/return dates must be less than 1 year');
												var oEndD = Date.fromString(oStartDate.val());
												oEndDate.dpSetSelected(oEndD.addDays(14).asString());
												oNight.selectOptions(14+'');
											}else{
												oNight.selectOptions(mData1+'');
											}
										}
									}

									return true;
								}, 

								//select box option list

								'sHolidayTypesSource' : '/holidays/theme-list?true=1',
								'sHolidayTypesDefault' :'I don\'t mind',

								'sHolidayDestinationSource' : '/holidays/town-list?true=1',
								'sDestinationsDefault' :'',

								'sHolidayAirportSource' : '/holidays/departure-airport-list?true=1', 
								'sDepartureAirPortDefault' :'',

								'oNumberNight' : [1,2,3,4,5,6,7,8,9,10,11,12,13,14],
								'sNumberNightDefault' :4,

								'aRoomList' : [1,2,3,4],
								'iRoomDefault' : 1,

								'aAdultList' : [1,2,3,4],
								'iAdultDefault' : 2,
								'aChildList' : [0,1,2],
								'iChildDefault' : 0,
								'aInfantList' : [0,1,2],
								'iInfantDefault' : 0

							});

							//generate the form
							oFlightSearchFormMaker.draw();

						} catch(e){ alert('yell flight');}

					}

					if($('#search_types_flight').attr("checked") == true) {
						$('#'+activeForm).hide();
						$('#flight_searchform').show();
						activeForm='flight_searchform';
					}
				}


			// ==================================================================
			var clickFlightHotel = function () {
					setSection('Flight+Hotel');

					$('#serchBoxTitle').html(searchFlightHotelLabel);
					if(oFlightHotelSearchFormMaker == '') {
						try {
							oFlightHotelSearchFormMaker = new FlightHotelSearchFormMaker({

								//form ID
								'sElementId' : 'flight_hotel_searchform',

								//will pass in jquery object and element name, 
								//so we can manipulate it here with 3rd party date picker
								'DateFormat':'dd-mm-yyyy',
								'DateHandler' : function( oStartDate, oEndDate, oNight ) {

									
									oStartDate.attr('readOnly', true);
									oEndDate.attr('readOnly', true);

									oStartDate.datePickerMultiMonth({
										numMonths: 2,
										clickInput:true,
										displayClose:true
									});
									oEndDate.datePickerMultiMonth({
										numMonths: 2,
										clickInput:true,
										displayClose:true
									});

									$(document).bind('keyup keypress', function(e){
										if(e.which==27){
											oStartDate.dpClose();
											oEndDate.dpClose();
										}
									});
									
									//Initial date correction
									var iAddDaysAhead = 1;
									var d = new Date();
									oStartDate.val(d.addDays(iAddDaysAhead).asString());
									oEndDate.val(d.addDays(parseInt(oNight.val())+1).asString());
									oStartDate.dpSetSelected(oStartDate.val());
									oEndDate.dpSetSelected(oEndDate.val());
									return true;

								}, 
								// indate/outdate checker, trigger on change, return true for OK
								// ichange, 1 = start date, 2 = end date, 3 = night change
								'DateValidator' : function( ichange, oStartDate, oEndDate, oNight, mData1, mData2 ) {
									//alert('> '+oNight.val()+' , '+mData1+' , '+mData2);

									//StartDate change
									if(ichange==1){

										var d = new Date();
										if(d.asString() == oStartDate.val()){
											alert('Your CHECK IN date must be a  least 1 day from now');
											oStartDate.val(d.addDays(1).asString());
										}else{
											//update end date base on selected night
											oEndDate.val(mData2); 
											oEndDate.dpSetSelected(oEndDate.val());
										}
									}
									//endDate change
									if(ichange==2){
										if(mData1<1){
											alert('Your CHECK OUT date must  be greater than CHECK IN date');
											oEndDate.val(mData2); //auto correction for invalid date
											oEndDate.dpSetSelected(oEndDate.val());
										}else{
											//update night selection box
											if(mData1>14){
												alert('Your interval between CHECK IN and  CHECK OUT date must be less than 14 days');
												var oEndD = Date.fromString(oStartDate.val());
												oEndDate.dpSetSelected(oEndD.addDays(14).asString());
												oNight.selectOptions(14+'');
											}else{
												mData1--;
												oNight.selectOptions(mData1+'');
											}
										}
									}

									//night change
									if(ichange==3){
										//update end date base on night
										oEndDate.val(mData2); 
										oEndDate.dpSetSelected(oEndDate.val());
									}
									return true;
								}, 
								'SubmitValidator' : function(oType, oDestination, oAirPort) {

									if(oDestination.val()=='') {
										alert(selectDestinationLabel);
										return false;
									}
									if(oType.val()=='Holiday+Flight' &&  oAirPort.val()=='') {
										alert(selectDepartureCityLabel);
										return false;
									}
									return true;
								},

								//select box option list

								'sHolidayTypesSource' : '/holidays/theme-list?true=1',
								'sHolidayTypesDefault' :'I don\'t mind',

								'sHolidayDestinationSource' : '/holidays/town-list?true=1',
								'sDestinationsDefault' :'',

								'sHolidayAirportSource' : '/holidays/departure-airport-list?true=1', 
								'sDepartureAirPortDefault' :'',

								'oNumberNight' : [1,2,3,4,5,6,7,8,9,10,11,12,13,14],
								'sNumberNightDefault' :4,

								'aRoomList' : [1,2,3,4],
								'iRoomDefault' : 1,

								'aAdultList' : [1,2,3],
								'iAdultDefault' : 2,
								'aChildList' : [0,1,2],
								'iChildDefault' : 0,
								'aInfantList' : [0,1,2],
								'iInfantDefault' : 0

							});

							//generate the form
							oFlightHotelSearchFormMaker.draw();

						}catch(e){}


						if($('#search_types_flight_hotel').attr("checked") == true){
							$('#'+activeForm).hide();
							$('#flight_hotel_searchform').show();
							activeForm='flight_hotel_searchform';
						}

					}
				}

			//====================================================================
			$('#search_types_holiday_flight').click(
				function() {
					setSection('Holidays+Flights');
					return clickHoliday();
				}
			);

			//====================================================================
			$('#search_types_holiday').click(

				function() {
					setSection('Holidays');
					$('#serchBoxTitle').html(searchHolidaysLabel);
					return clickHoliday();
				}
			);
			//====================================================================
			$('#search_types_flight').click(
				function() {
					setSection('Flight');
					return clickFlight();
				}
			);

			//====================================================================
			$('#search_types_flight_hotel').click(
				function() {
					setSection('Flight+Hotel');
					return clickFlightHotel();
				}
			);



			//====================================================================


			$('#search_types_hotel').click(
				function() {
					setSection('Hotels');

					$('#serchBoxTitle').html(searchHotelsLabel);
					if(oHotelSearchFormMaker == ''){
						try{
							oHotelSearchFormMaker = new HotelSearchFormMaker({

								//form ID
								'sElementId' : 'hotel_searchform',
								
								//location form handler
								'LoactionHandler' : function(oCountryCode,oRegion,oLocationList) {
									
									//Auto compliter start
									//auto completer is 3rd party lib
									var oAutoCompleter = new AutoCompleter({

										'sUrl' : '/hotels/town-list?pattern=SEARCH_KEYWORD',
										'iCharLimit' : 2,
										'iRenderLimit' : 10,
										'sElementId' : 'location_search',
										'sResultShowAllCSS' : {},
										'sResultShowMinCSS' : {},
										'bNoEscForSearchField':false,
										'bShowSearchFieldAfterEsc':true,
										'bPersisField':false,
										'onData' : function(oData, sKeyword) {

											//this function let you process the return from json/ajax to standard array and it only trigger after ajax fetch or cache not found, plz make sure you had supply all data for render
											//id = id, val = internal value, display = list to auto compliter
											//you may your hardcoded data in here if you wish to disable the ajax
											//alert(oData);
											var sDivOut = [];
											var h =0;
											//loop through data
											for ( var i in oData ) {
												for ( var j in oData[i] ) {
													sDivOut.push({
													  'id':h,
													  'value':{'i':i,'j':j}, 
													  'displaytxt':''+j+', '+i, 
													  'count':oData[i][j],
													  'display': '<div style="float:left;">'+j+', '+i+'</div> <div class="__cl" style="float:right;">'+oData[i][j]+' products</div> <div style="clear:both;"/>'
													});
													h++;
												}
											} 
											return sDivOut;
										},
										'onSelect' : function(id,value,Display){
											//this will let you define how to handle selected data
											oCountryCode.val(value.i);
											oRegion.val(''); //PYO2 didnt have region
											oLocationList.val(value.j);
										}
									});
									oAutoCompleter.start();
									//Auto completer end
								},

								//will pass in jquery object and element name, 
								//so we can manipulate it here with 3rd party date picker
								'DateFormat':'dd-mm-yyyy',
								'DateHandler' : function( oStartDate, oEndDate, oNight ) {
									
									oStartDate.attr('readOnly', true);
									oEndDate.attr('readOnly', true);

									oStartDate.datePickerMultiMonth({
										numMonths: 2,
										clickInput:true,
										displayClose:true
									});
									oEndDate.datePickerMultiMonth({
										numMonths: 2,
										clickInput:true,
										displayClose:true
									});

									$(document).bind('keyup keypress', function(e){
										if(e.which==27){
											oStartDate.dpClose();
											oEndDate.dpClose();
										}
									});
									
									//Initial date correction
									var iAddDaysAhead = 1;
									var d = new Date();
									oStartDate.val(d.addDays(iAddDaysAhead).asString());
									oEndDate.val(d.addDays(parseInt(oNight.val())).asString());
									oStartDate.dpSetSelected(oStartDate.val());
									oEndDate.dpSetSelected(oEndDate.val());
									return true;
								}, 

								// indate/outdate checker, trigger on change, return true for OK
								// ichange, 1 = start date, 2 = end date, 3 = night change
								'DateValidator' : function( ichange, oStartDate, oEndDate, oNight, mData1, mData2 ) {
									//alert('> '+oNight.val()+' , '+mData1+' , '+mData2);

									//StartDate change
									if(ichange==1){

										var d = new Date();
										if(d.asString() == oStartDate.val()){
											alert('Your CHECK IN date must be a  least 1 day from now');
											oStartDate.val(d.addDays(1).asString());
										}else{
											//update end date base on selected night
											oEndDate.val(mData2); 
											oEndDate.dpSetSelected(oEndDate.val());
										}
										
									}

									//endDate change
									if(ichange==2){
										if(mData1<1){
											alert('Your CHECK OUT date must  be greater than CHECK IN date');
											oEndDate.val(mData2); //auto correction for invalid date
											oEndDate.dpSetSelected(oEndDate.val());
										}else{
											//update night selection box
											if(mData1>14){
												alert('Your interval between CHECK IN and  CHECK OUT date must be less than 14 days');
												var oEndD = Date.fromString(oStartDate.val());
												oEndDate.dpSetSelected(oEndD.addDays(14).asString());
												oNight.selectOptions(14+'');
											}else{
												oNight.selectOptions(mData1+'');
											}
										}
									}

									//night change
									if(ichange==3){
										//update end date base on night
										oEndDate.val(mData2); 
										oEndDate.dpSetSelected(oEndDate.val());
									}
									return true;
								}, 

								'SubmitValidator' : function(oCountryCode,oRegion,oLocationList) {
									//var test=$('#hotel_searchform .search_input').val();
									//alert('H#1: '+test+' '+oCountryCode);
									if($('#hotel_searchform .search_input').val().length > 0 ){
										return true;
									}else{
										alert(selectRequiredLocation);
										return false;
									}

								},

								//select box option list
								'aNightList' : [1,2,3,4,5,6,7,8,9,10,11,12,13,14],
								'iNightDefault' : 1,
								'aRoomList' : [1,2,3,4],
								'iRoomDefault' : 1,
								'aAdultList' : [1,2,3],
								'iAdultDefault' : 1,
								'aChildList' : [0,1,2],
								'iChildDefault' : 0,
								'aInfantList' : [],
								'iInfantDefault' : ''
							});
							//generate the form
							oHotelSearchFormMaker.draw();
						}catch(e){}

					}

					if($('#search_types_hotel').attr("checked") == true){
						$('#'+activeForm).hide();
						$('#hotel_searchform').show();
						activeForm='hotel_searchform';
					}

				}

			);



			if($('#search_types_hotel').attr("checked")==true){ $('#search_types_hotel').trigger('click', null ) }
			if($('#search_types_holiday').attr("checked")==true){ $('#search_types_holiday').trigger('click', null ) }
			if($('#search_types_holiday_flight').attr("checked")==true){ $('#search_types_holiday_flight').trigger('click', null ) }
			if($('#search_types_flight').attr("checked")==true){ $('#search_types_flight').trigger('click', null ) }
			if($('#search_types_flight_hotel').attr("checked")==true){ $('#search_types_flight_hotel').trigger('click', null ) }

			//$('#search_types_hotel').trigger('click', null );


			/**
			 * Handle the click on the radio-botton to switch between one-way and return flights.
			 */
			$('#flight-type-one-way').click(function() {
				$('#flight-return-date').hide();
			});

			$('#flight-type-return').click(function() {
				$('#flight-return-date').show();
			});


			/**
			 * Support classic dropdown selection on the hotel search form.
			 */
			$('#auto_complete_hotel_search').click(function(){
					$('#classic_hotel_search_section').hide();
					$('#auto_complete_hotel_search_section').show();
			});

			$('#classic_hotel_search').click(function() {
					if(oHotelClassicSearchFormMaker == '') {
						try {
							oHotelClassicSearchFormMaker = new HotelClassicSearchFormMaker({
								//form ID
								'sElementId' : 'hotel_searchform',

								'sHotelLocationSource' : '/hotels/town-list',
								'sHotelDefault' :''
							});							
							// render.
							oHotelClassicSearchFormMaker.draw();
						} catch(e){}
					}
					$('#auto_complete_hotel_search_section').hide();
					$('#classic_hotel_search_section').show();
			});
