var arrDepAirportGroups = new Array
( 
	[48,'Humberside']
);

var arrDepAirports = new Array
( 
	[79,'Humberside',48],
	[56,'East Midlands',48],
	[113,'Manchester',48],
	[286,'Doncaster',48],
	[95,'Leeds/Bradford',48],
	[23,'Birmingham',48],
	[244,'Coventry Baginton',48],
	[133,'Norwich',48],
	[132,'Newcastle',48],
	[123,'Durham Tees Valley',48]
);

var arrDestAirportGroups = new Array
( 
	[561,'Africa / India / Pakistan'],
	[562,'Spain - Balearics'],
	[563,'Bulgaria'],
	[564,'Canada'],
	[565,'Spain - Canaries'],
	[566,'Caribbean / Central /South America'],
	[567,'Channel Islands'],
	[568,'Croatia'],
	[569,'Cyprus'],
	[570,'Middle / Far East'],
	[571,'France'],
	[572,'Germany'],
	[573,'Greece'],
	[574,'Ireland'],
	[575,'Italy'],
	[576,'Lapland/ Iceland'],
	[577,'Spain - Mainland'],
	[580,'Other European'],
	[581,'Portugal'],
	[582,'Scotland'],
	[583,'Turkey'],
	[584,'UK'],
	[585,'USA'],
	[641,'Eastern Europe'],
	[643,'Australia/ New Zealand/ Pacific']
);

var arrDestAirports = new Array
( 
	[5,'Agadir',561,''],
	[4230,'Alexandria Airport',561,''],
	[4669,'Antananarivo Airport',561,''],
	[26,'Banjul (Gambia)',561,''],
	[360,'Bole International Airport',561,''],
	[239,'Cairo',561,''],
	[243,'Cape Town',561,''],
	[4279,'Casablanca Airport',561,''],
	[40,'Colombo (Sri Lanka)',561,''],
	[47,'Djerba',561,''],
	[4318,'Eldoret Airport',561,''],
	[4330,'Fez Airport',561,''],
	[69,'Goa',561,''],
	[78,'Hurghada',561,''],
	[4371,'Hwange National Park Airport',561,''],
	[1159,'Indira Gandhi International Airport',561,''],
	[1861,'Islamabad International Airport',561,''],
	[1937,'Johannesburg',561,''],
	[4410,'Kisumu Airport',561,''],
	[4440,'Lamu Airport',561,''],
	[4447,'Lokichoggio Airport',561,''],
	[2155,'Lusaka International Airport',561,''],
	[109,'Luxor',561,''],
	[122,'Male (Maldives)',561,''],
	[4502,'Malindi Airport',561,''],
	[4489,'Maputo Airport',561,''],
	[155,'Marrakech',561,''],
	[301,'Marsa Alam',561,''],
	[124,'Mauritius',561,''],
	[114,'Mombasa (Kenya)',561,''],
	[3248,'Nairobi Wilson Airport',561,''],
	[951,'Netaji Subhash Chandra Bose International Airport',561,''],
	[4555,'Praslin Island Airport',561,''],
	[636,'Raja Sansi Airport',561,''],
	[3017,'Sal (Cape Verde Islands)',561,''],
	[3676,'Seychelles',561,''],
	[177,'Sharm El Sheikh',561,''],
	[285,'Taba (Egypt)',561,''],
	[4661,'Tripoli (Italy)',561,''],
	[188,'Tunis',561,''],
	[4800,'Tunisia (Enfidha)',561,''],
	[118,'Tunisia (Monastir)',561,''],
	[4725,'Victoria Falls Airport',561,''],
	[368,'Adelaide International Airport',643,''],
	[3661,'Auckland',643,''],
	[833,'Brisbane Airport',643,''],
	[1062,'Cairns International Airport',643,''],
	[3630,'Canberra',643,''],
	[1002,'Christchurch International Airport',643,''],
	[1231,'Darwin International Airport',643,''],
	[2232,'Melbourne',643,''],
	[2394,'Nadi International Airport',643,''],
	[2634,'Perth Airport',643,''],
	[3658,'Sydney',643,''],
	[4737,'Wellington Airport',643,''],
	[32,'Bourgas (Bulgaria)',563,''],
	[141,'Plovdiv (Bulgaria)',563,''],
	[173,'Sofia (Bulgaria)',563,''],
	[208,'Calgary, Alberta',564,''],
	[202,'Halifax (Canada)',564,''],
	[3390,'Hamilton Airport (Toronto)',564,''],
	[3332,'Lourdes-de-Blanc-Sablon Airport',564,''],
	[206,'Montreal, Quebec (Pierre Elliott)',564,''],
	[205,'Ottawa, Ontario',564,''],
	[3458,'Quebec City, Quebec',564,''],
	[209,'Toronto',564,''],
	[207,'Vancouver',564,''],
	[3562,'Victoria (Canada)',564,''],
	[4750,'Whistler Airport',564,''],
	[3319,'Winnipeg/St. Andrews Airport',564,''],
	[2,'Acapulco',566,''],
	[10,'Antigua',566,''],
	[19,'Barbados',566,''],
	[4240,'Barbuda Airport',566,''],
	[1317,'Beef Island',566,''],
	[290,'Bermuda',566,''],
	[4265,'Brasilia Airport',566,''],
	[4271,'Buenos Aires Airport',566,''],
	[43,'Cancun',566,''],
	[223,'Caya Coco (Cuba)',566,''],
	[292,'Cayman Islands',566,''],
	[289,'Cozumel',566,''],
	[4341,'George Town Airport',566,''],
	[77,'Holguin (Cuba)',566,''],
	[3374,'Kingston Airport',566,''],
	[107,'La Romana',566,''],
	[147,'Margarita',566,''],
	[115,'Montego Bay',566,''],
	[128,'Nassau (Bahamas)',566,''],
	[2764,'Panama (Tocumen)',566,''],
	[4548,'Port Of Spain Airport',566,''],
	[148,'Puerto Plata (Dominican Republic)',566,''],
	[154,'Puerto Vallarta',566,''],
	[151,'Punta Cana',566,''],
	[13,'Reina Beatrix (Aruba)',566,''],
	[287,'Santa Clara',566,''],
	[2971,'Santiago Airport',566,''],
	[162,'Santo Domingo',566,''],
	[168,'St Kitts',566,''],
	[190,'St Lucia',566,''],
	[181,'Tobago',566,''],
	[4673,'Tortola Airport',566,''],
	[197,'Varadero (Cuba)',566,''],
	[1515,'Guernsey Airport',567,''],
	[257,'Jersey',567,''],
	[45,'Dubrovnik',568,''],
	[152,'Pula',568,''],
	[279,'Split',568,''],
	[1285,'Ercan International Airport',569,''],
	[96,'Larnaca',569,''],
	[144,'Paphos',569,''],
	[766,'Belgrade Nikola Tesla Airport',641,''],
	[1977,'Boryspil International Airport',641,''],
	[888,'Bratislava (Slovakia)',641,''],
	[4272,'Bucharest (Romania)',641,''],
	[894,'Budapest (Hungary)',641,''],
	[45,'Dubrovnik',641,''],
	[2016,'Kosice Airport (Slovakia)',641,''],
	[90,'Krakow (Poland)',641,''],
	[104,'Ljubljana (Slovenia)',641,''],
	[2051,'Lodz-Lublinek Airport (Poland)',641,''],
	[2725,'Poznan (Poland)',641,''],
	[149,'Prague (Czech Republic)',641,''],
	[2857,'Riga International Airport (Latvia)',641,''],
	[173,'Sofia (Bulgaria)',641,''],
	[279,'Split',641,''],
	[191,'Varna (Bulgaria)',641,''],
	[229,'Warsaw (Poland)',641,''],
	[3264,'Wroclaw International Airport (Poland)',641,''],
	[801,'Anglet Airport',571,''],
	[4237,'Avignon',571,''],
	[2085,'Bellegarde (Limoges, France)',571,''],
	[1304,'Bergerac Airport',571,''],
	[2666,'Biard Aeroport',571,''],
	[237,'Bordeaux',571,''],
	[771,'Brest Bretagne Airport',571,''],
	[39,'Calvi Catherine (Corsica)',571,''],
	[4284,'Cannes',571,''],
	[946,'Carcassonne (France)',571,''],
	[41,'Chambery',571,''],
	[1213,'Dinard/Plertuit/St. Malo Airport',571,''],
	[61,'Figari (Corsica)',571,''],
	[67,'Grenoble',571,''],
	[4453,'La Rochelle Airport',571,''],
	[4759,'Lyon',571,''],
	[110,'Lyon (Saint-Exupéry)',571,''],
	[2456,'Nantes Atlantique Airport',571,''],
	[131,'Nice',571,''],
	[4334,'Nimes Airport',571,''],
	[903,'Paris - Beauvais',571,''],
	[955,'Paris - Charles De Gaulle',571,''],
	[2643,'Perpignan/Rivesaltes Aeroport',571,''],
	[2335,'Provence Airport',571,''],
	[4458,'St Tropez Airport',571,''],
	[2880,'St. Jacques Airport',571,''],
	[4634,'Strasbourg',571,''],
	[2054,'Tarbes - Lourdes Pyrenees Airport',571,''],
	[184,'Toulouse',571,''],
	[4742,'Versailles Airport',571,''],
	[3139,'Berlin (Schoenefeld)',572,''],
	[828,'Berlin, New Hampshire',572,''],
	[4264,'Bonn',572,''],
	[866,'Bremen',572,''],
	[995,'Cologne/Bonn',572,''],
	[1237,'Dortmund Airport',572,''],
	[1249,'Dusseldorf',572,''],
	[74,'Frankfurt-Hahn',572,''],
	[4329,'Friedrichshafen Airport',572,''],
	[1645,'Hamburg',572,''],
	[1644,'Hanover/Langenhagen',572,''],
	[125,'Munich',572,''],
	[2596,'Paderborn/Lippstadt Airport',572,''],
	[3107,'Stuttgart',572,''],
	[12,'Athens',573,''],
	[37,'Crete (Chania)',573,''],
	[73,'Crete (Heraklion)',573,''],
	[36,'Corfu',573,''],
	[89,'Kalamata',573,''],
	[92,'Kavala',573,''],
	[55,'Kefalonia',573,''],
	[88,'Kos',573,''],
	[153,'Preveza',573,''],
	[158,'Rhodes',573,''],
	[87,'Santorini',573,''],
	[86,'Skiathos',573,''],
	[169,'Thessaloniki',573,''],
	[212,'Zante',573,''],
	[22,'Belfast City',574,''],
	[18,'Belfast',574,''],
	[136,'Cork',574,''],
	[52,'Dublin',574,''],
	[1627,'Galway',574,''],
	[1997,'Kerry',574,''],
	[267,'Knock',574,''],
	[97,'Derry (Northern Ireland)',574,''],
	[172,'Shannon',574,''],
	[3140,'Sligo',574,''],
	[4796,'Waterford',574,''],
	[7,'Alghero (Italy)',575,''],
	[21,'Bergamo (Italy)',575,''],
	[938,'Bozen-Bolzano (Italy)',575,''],
	[35,'Cagliari (Italy)',575,''],
	[42,'Catania (Italy)',575,''],
	[247,'Florence (Italy)',575,''],
	[126,'Milan (Italy)',575,''],
	[127,'Naples (Italy)',575,''],
	[134,'Olbia (Italy)',575,''],
	[4547,'Palermo (Italy)',575,''],
	[150,'Pisa (Italy)',575,''],
	[159,'Rimini (Italy)',575,''],
	[4593,'Rome',575,''],
	[38,'Rome (Ciampino)',575,''],
	[1405,'Rome (Da Vinci)',575,''],
	[4788,'Sicily (Vincenzo Florio)',575,''],
	[4684,'Trieste (Italy)',575,''],
	[4661,'Tripoli (Italy)',575,''],
	[186,'Turin (Italy)',575,''],
	[192,'Venice (Italy)',575,''],
	[198,'Verona (Italy)',575,''],
	[4760,'Verona - Brescia',575,''],
	[1344,'Enontekiö airport',576,''],
	[1875,'Ivalo (Finland)',576,''],
	[91,'Kittila (Finland )',576,''],
	[2839,'Reykjavik (iceland)',576,''],
	[161,'Rovaniemi (Finland)',576,''],
	[361,'Aden International Airport',570,''],
	[1945,'Atarot Airport',570,''],
	[736,'Bahrain International Airport',570,''],
	[28,'Bangkok',570,''],
	[142,'Beijing Capital',570,''],
	[4245,'Berau Airport',570,''],
	[1217,'Doha (Qatar)',570,''],
	[53,'Dubai (United Arab Emirates)',570,''],
	[2941,'El Rahaba Airport',570,''],
	[4358,'Hiroshima Intl Airport',570,''],
	[230,'Hong Kong',570,''],
	[4369,'Hue Airport Airport',570,''],
	[1799,'Incheon International Airport',570,''],
	[2024,'Kuwait International Airport',570,''],
	[75,'Phuket',570,''],
	[503,'Queen Alia International Airport',570,''],
	[774,'Rafic Hariri International Airport',570,''],
	[2212,'Seeb International Airport',570,''],
	[276,'Singapore',570,''],
	[2705,'Supadio Airport',570,''],
	[4667,'Tel Aviv (Israel)',570,''],
	[4703,'Tokyo Airport',570,''],
	[3677,'Amsterdam (Netherlands)',580,''],
	[532,'Antwerp (Belgium)',580,''],
	[4267,'Basel (Switzerland)',580,''],
	[870,'Berne (Switzerland)',580,''],
	[875,'Brussels (Belgium)',580,''],
	[4302,'Brussels (Charleroi)',580,''],
	[242,'Copenhagen (Denmark)',580,''],
	[59,'Funchal (Madeira)',580,''],
	[71,'Geneva',580,''],
	[64,'Gibraltar (Gibraltar)',580,''],
	[1599,'Gothenburg (City) Sweden',580,''],
	[81,'Innsbruck (Austria)',580,''],
	[2158,'Luxembourg',580,''],
	[121,'Malta',580,''],
	[4486,'Moscow',580,''],
	[139,'Oslo (Norway)',580,''],
	[2839,'Reykjavik (iceland)',580,''],
	[2909,'Rotterdam (Netherlands)',580,''],
	[180,'Salzburg (Austria)',580,''],
	[2059,'St. Petersburg',580,''],
	[4772,'Stockholm-Västerås (Sweden)',580,''],
	[3678,'Vienna',580,''],
	[211,'Zurich',580,''],
	[58,'Faro',581,''],
	[59,'Funchal (Madeira)',581,''],
	[103,'Lisbon',581,''],
	[2623,'Ponta Delgada Airport',581,''],
	[1,'Aberdeen',582,''],
	[1209,'Dundee Airport',582,''],
	[54,'Edinburgh',582,''],
	[65,'Glasgow',582,''],
	[256,'Inverness',582,''],
	[80,'Ibiza',562,''],
	[112,'Menorca',562,''],
	[146,'Majorca',562,''],
	[3,'Lanzarote',565,''],
	[63,'Fuerteventura',565,''],
	[105,'Gran Canaria',565,''],
	[183,'Tenerife',565,''],
	[9,'Alicante (Costa Blanca)',577,''],
	[98,'Almeria (Costa de Almeria)',577,''],
	[16,'Barcelona',577,''],
	[70,'Gerona (Costa Brava)',577,''],
	[64,'Gibraltar (Gibraltar)',577,''],
	[4346,'Granada',577,''],
	[4444,'Leon Airport',577,''],
	[111,'Madrid',577,''],
	[6,'Malaga (Costa del Sol)',577,''],
	[120,'Murcia (Costa Calida)',577,''],
	[157,'Reus (Costa Dorada)',577,''],
	[4728,'Valencia Airport',577,''],
	[15,'Antalya',583,''],
	[27,'Bodrum',583,''],
	[49,'Dalaman',583,''],
	[82,'Istanbul',583,''],
	[4,'Izmir',583,''],
	[18,'Belfast',584,''],
	[22,'Belfast City',584,''],
	[23,'Birmingham',584,''],
	[29,'Blackpool',584,''],
	[31,'Bournemouth',584,''],
	[34,'Bristol',584,''],
	[44,'Cardiff',584,''],
	[136,'Cork',584,''],
	[244,'Coventry Baginton',584,''],
	[123,'Durham Tees Valley',584,''],
	[56,'East Midlands',584,''],
	[57,'Exeter',584,''],
	[101,'Gatwick',584,''],
	[1515,'Guernsey Airport',584,''],
	[102,'Heathrow',584,''],
	[1850,'Isle of Man Airport',584,''],
	[106,'Liverpool',584,''],
	[4451,'London (all)',584,''],
	[264,'London City',584,''],
	[108,'Luton',584,''],
	[113,'Manchester',584,''],
	[132,'Newcastle',584,''],
	[4519,'Newquay Airport',584,''],
	[133,'Norwich',584,''],
	[2682,'Plymouth Airport',584,''],
	[4643,'Sheffield Airport',584,''],
	[174,'Southampton',584,''],
	[178,'Stansted',584,''],
	[4640,'Stornoway Airport',584,''],
	[4456,'Sumburgh Airport',584,''],
	[517,'Anchorage, Alaska',585,''],
	[632,'Atlanta, Georgia',585,''],
	[917,'Baltimore, Maryland',585,''],
	[33,'Boston, Massachusetts',585,''],
	[4285,'Chicago, Illinois (all)',585,''],
	[1432,'Fort Lauderdale, Florida',585,''],
	[2908,'Fort Myers, Florida',585,''],
	[1871,'Hilo, Hawaii',585,''],
	[76,'Honolulu, Hawaii',585,''],
	[1730,'Houston (William P. Hobby), Texas',585,''],
	[2497,'Kahului, Hawaii',585,''],
	[2011,'Kona, Hawaii',585,''],
	[93,'Las Vegas, Nevada',585,''],
	[94,'Los Angeles, California',585,''],
	[2233,'Memphis, Tennessee',585,''],
	[117,'Miami, Florida',585,''],
	[2347,'New Orleans, Louisiana',585,''],
	[84,'New York (JFK), New York',585,''],
	[2470,'New York (all), New York',585,''],
	[224,'Newark, New Jersey (for New York City)',585,''],
	[165,'Orlando (Sanford), Florida',585,''],
	[116,'Orlando, Florida',585,''],
	[2654,'Philadelphia, Pennsylvania',585,''],
	[4579,'Raleigh, North Carolina',585,''],
	[2945,'San Diego, California',585,''],
	[166,'San Francisco, California',585,''],
	[287,'Santa Clara',585,''],
	[778,'Scottsbluff, Nebraska',585,''],
	[3140,'Sligo',585,'']
);

var arrDepGroupsDestGroups = new Array
( 
	[48,33554431],
	[584,16777215],
	[574,327954],
	[582,327954]
);

var arrDepAirportsDestGroups = new Array
( 
	[79,33554431],
	[23,16777215],
	[132,33521023],
	[95,16776567],
	[101,16777215],
	[54,32988511],
	[108,12017559],
	[113,33554431],
	[1,20382994],
	[4451,33029943],
	[244,476226],
	[44,14095647],
	[133,12547538],
	[106,12016690],
	[145,9915410],
	[65,33029951],
	[178,16219959],
	[123,12547542],
	[31,16776691],
	[264,2760768],
	[18,14114111],
	[174,3099650],
	[102,33554223],
	[257,2753536],
	[34,14638583],
	[29,327698],
	[56,16776567],
	[286,16216439],
	[1850,2228224],
	[57,1512722],
	[22,23069696],
	[343,1024],
	[4519,131072],
	[1515,132096],
	[256,2097152]
);


			var arrDepAirportsDestAirports = {
		
				
				23 : {
			132 : [''], 1 : [''], 3 : [''], 4 : [''], 5 : [''], 6 : [''], 9 : [''], 15 : [''], 16 : [''], 18 : [''], 21 : [''], 22 : [''], 27 : [''], 32 : [''], 36 : [''], 37 : [''], 38 : [''], 41 : [''], 43 : [''], 45 : [''], 49 : [''], 52 : [''], 53 : [''], 54 : [''], 55 : [''], 58 : [''], 59 : [''], 63 : [''], 65 : [''], 67 : [''], 69 : [''], 70 : [''], 71 : [''], 73 : [''], 74 : [''], 78 : [''], 80 : [''], 81 : [''], 86 : [''], 87 : [''], 88 : [''], 89 : [''], 90 : [''], 91 : [''], 92 : [''], 96 : [''], 98 : [''], 103 : [''], 104 : [''], 105 : [''], 109 : [''], 110 : [''], 111 : [''], 112 : [''], 118 : [''], 120 : [''], 121 : [''], 125 : [''], 126 : [''], 127 : [''], 131 : [''], 134 : [''], 136 : [''], 144 : [''], 146 : [''], 148 : [''], 149 : [''], 150 : [''], 152 : [''], 157 : [''], 158 : [''], 169 : [''], 172 : [''], 173 : [''], 177 : [''], 180 : [''], 183 : [''], 184 : [''], 186 : [''], 191 : [''], 198 : [''], 209 : [''], 211 : [''], 212 : [''], 224 : [''], 229 : [''], 237 : [''], 242 : [''], 256 : [''], 257 : [''], 267 : [''], 279 : [''], 636 : [''], 771 : [''], 801 : [''], 870 : [''], 875 : [''], 888 : [''], 955 : [''], 995 : [''], 1159 : [''], 1213 : [''], 1249 : [''], 1304 : [''], 1515 : [''], 1627 : [''], 1644 : [''], 1645 : [''], 1850 : [''], 1861 : [''], 2335 : [''], 2643 : [''], 2666 : [''], 3107 : [''], 3677 : [''], 4453 : [''], 4519 : [''], 4684 : [''], 4788 : [''], 4796 : ['']
				}
			,
				79 : {
			23 : [''], 31 : [''], 56 : [''], 95 : [''], 113 : [''], 123 : [''], 132 : [''], 133 : [''], 244 : [''], 1 : ['Direct'], 2 : [''], 3 : [''], 4 : [''], 5 : [''], 6 : [''], 9 : ['Direct','Direct'], 10 : [''], 12 : [''], 13 : [''], 15 : ['Direct','Direct'], 16 : [''], 18 : [''], 19 : [''], 22 : [''], 26 : [''], 27 : [''], 28 : [''], 29 : [''], 32 : ['Direct'], 33 : [''], 34 : [''], 36 : [''], 40 : [''], 41 : [''], 43 : [''], 44 : [''], 45 : [''], 47 : [''], 49 : ['Direct','Direct'], 52 : [''], 53 : [''], 54 : [''], 57 : [''], 58 : [''], 59 : [''], 63 : [''], 65 : [''], 69 : [''], 70 : [''], 71 : [''], 73 : ['Direct'], 75 : [''], 76 : [''], 77 : [''], 80 : [''], 81 : [''], 82 : [''], 88 : [''], 90 : [''], 91 : [''], 93 : [''], 94 : [''], 96 : ['Direct'], 97 : [''], 98 : [''], 101 : [''], 102 : [''], 103 : [''], 105 : [''], 106 : [''], 108 : [''], 109 : [''], 110 : [''], 111 : [''], 112 : [''], 114 : [''], 115 : [''], 116 : [''], 117 : [''], 120 : [''], 121 : [''], 122 : [''], 124 : [''], 125 : [''], 126 : [''], 127 : [''], 131 : [''], 136 : [''], 139 : [''], 141 : [''], 142 : [''], 144 : [''], 146 : ['Direct'], 148 : [''], 149 : [''], 150 : [''], 151 : [''], 155 : [''], 158 : [''], 159 : [''], 161 : ['Direct'], 162 : [''], 166 : [''], 172 : [''], 173 : [''], 174 : [''], 178 : [''], 180 : [''], 181 : [''], 183 : [''], 184 : [''], 186 : [''], 188 : [''], 190 : [''], 192 : [''], 197 : [''], 198 : [''], 205 : [''], 206 : [''], 207 : [''], 208 : [''], 209 : [''], 211 : [''], 212 : [''], 229 : [''], 230 : [''], 239 : [''], 242 : [''], 243 : [''], 247 : [''], 256 : [''], 257 : ['Direct'], 264 : [''], 276 : [''], 279 : [''], 290 : [''], 292 : [''], 360 : [''], 361 : [''], 368 : [''], 503 : [''], 517 : [''], 736 : [''], 766 : [''], 774 : [''], 778 : [''], 833 : [''], 866 : [''], 875 : [''], 894 : [''], 917 : [''], 951 : [''], 955 : [''], 995 : [''], 1002 : [''], 1062 : [''], 1159 : [''], 1209 : [''], 1217 : [''], 1231 : [''], 1237 : [''], 1249 : [''], 1317 : [''], 1344 : ['Direct'], 1432 : [''], 1515 : [''], 1599 : [''], 1644 : [''], 1645 : [''], 1730 : [''], 1850 : [''], 1861 : [''], 1871 : [''], 1937 : [''], 1945 : [''], 1977 : [''], 2011 : [''], 2024 : [''], 2054 : [''], 2059 : [''], 2085 : [''], 2155 : [''], 2158 : [''], 2212 : [''], 2232 : [''], 2233 : [''], 2347 : [''], 2394 : [''], 2470 : [''], 2497 : [''], 2634 : [''], 2682 : [''], 2705 : [''], 2764 : [''], 2839 : [''], 2908 : [''], 2941 : [''], 2945 : [''], 3017 : [''], 3107 : [''], 3139 : [''], 3264 : [''], 3458 : [''], 3562 : [''], 3630 : [''], 3658 : [''], 3661 : [''], 3676 : [''], 3677 : ['Direct'], 3678 : [''], 4230 : [''], 4240 : [''], 4245 : [''], 4265 : [''], 4271 : [''], 4272 : [''], 4279 : [''], 4284 : [''], 4318 : [''], 4329 : [''], 4330 : [''], 4341 : [''], 4358 : [''], 4369 : [''], 4371 : [''], 4410 : [''], 4440 : [''], 4444 : [''], 4447 : [''], 4456 : [''], 4458 : [''], 4486 : [''], 4489 : [''], 4502 : [''], 4519 : [''], 4548 : [''], 4555 : [''], 4593 : [''], 4634 : [''], 4640 : [''], 4643 : [''], 4667 : [''], 4669 : [''], 4673 : [''], 4703 : [''], 4725 : [''], 4737 : [''], 4742 : [''], 4750 : [''], 4800 : ['']
				}
			,
				113 : {
			133 : ['Direct','Direct'], 1 : ['Direct','Direct'], 3 : ['Direct','Direct'], 4 : ['Direct','Direct'], 5 : ['Direct','Direct'], 6 : ['Direct','Direct'], 9 : ['Direct','Direct'], 12 : ['Direct','Direct'], 15 : ['Direct','Direct'], 16 : ['Direct','Direct'], 18 : ['Direct','Direct','Direct','Direct'], 19 : ['Direct','Direct'], 21 : ['Direct','Direct'], 22 : ['Direct','Direct','Direct','Direct'], 26 : ['Direct','Direct'], 27 : ['Direct','Direct'], 32 : ['Direct','Direct'], 34 : ['Direct','Direct'], 35 : [''], 36 : ['Direct','Direct'], 37 : ['Direct','Direct'], 41 : ['Direct','Direct'], 42 : [''], 43 : ['Direct','Direct'], 45 : ['Direct','Direct','Direct','Direct'], 47 : [''], 49 : ['Direct','Direct'], 52 : ['Direct','Direct'], 53 : ['Direct','Direct'], 54 : ['Direct','Direct'], 55 : ['Direct','Direct'], 57 : ['Direct','Direct'], 58 : ['Direct','Direct'], 59 : ['Direct','Direct','Direct','Direct'], 61 : ['Direct','Direct'], 63 : ['Direct','Direct'], 64 : [''], 65 : ['Direct','Direct'], 67 : ['Direct','Direct'], 69 : [''], 70 : ['Direct','Direct'], 71 : ['Direct','Direct'], 73 : ['Direct','Direct'], 74 : ['Direct','Direct'], 77 : ['Direct','Direct'], 78 : ['Direct','Direct'], 80 : ['Direct','Direct'], 81 : ['Direct','Direct'], 82 : ['Direct','Direct'], 84 : ['Direct','Direct'], 86 : ['Direct','Direct'], 87 : ['Direct','Direct'], 88 : ['Direct','Direct'], 89 : ['Direct','Direct'], 90 : [''], 92 : ['Direct','Direct'], 93 : ['Direct','Direct'], 94 : [''], 96 : ['Direct','Direct'], 98 : ['Direct','Direct'], 101 : ['Direct','Direct'], 102 : ['Direct','Direct'], 103 : ['Direct','Direct'], 104 : [''], 105 : ['Direct','Direct'], 109 : ['Direct','Direct'], 110 : ['Direct','Direct'], 111 : [''], 112 : ['Direct','Direct'], 114 : ['Direct','Direct'], 115 : ['Direct','Direct'], 118 : [''], 120 : ['Direct','Direct'], 121 : ['Direct','Direct'], 122 : ['Direct','Direct'], 125 : ['Direct','Direct'], 126 : ['Direct','Direct'], 127 : ['Direct','Direct'], 131 : ['Direct','Direct'], 134 : [''], 136 : ['Direct','Direct','Direct','Direct'], 139 : ['Direct','Direct'], 144 : ['Direct','Direct'], 146 : ['Direct','Direct'], 147 : [''], 148 : ['Direct','Direct'], 149 : ['Direct','Direct'], 150 : ['Direct','Direct'], 151 : ['Direct','Direct'], 152 : ['Direct','Direct'], 153 : ['Direct','Direct'], 154 : [''], 155 : ['Direct','Direct'], 157 : ['Direct','Direct'], 158 : ['Direct','Direct'], 159 : ['Direct','Direct'], 161 : ['Direct','Direct'], 165 : ['Direct','Direct'], 169 : ['Direct','Direct'], 172 : ['Direct','Direct'], 173 : ['Direct','Direct','Direct','Direct'], 174 : ['Direct','Direct'], 177 : ['Direct','Direct'], 178 : [''], 180 : ['Direct','Direct'], 183 : ['Direct','Direct'], 184 : ['Direct','Direct'], 186 : ['Direct','Direct'], 190 : [''], 191 : ['Direct','Direct'], 192 : ['Direct','Direct'], 197 : ['Direct','Direct'], 198 : [''], 207 : ['Direct','Direct'], 208 : ['Direct','Direct'], 209 : ['Direct','Direct'], 211 : ['Direct','Direct'], 212 : ['Direct','Direct'], 223 : ['Direct','Direct'], 224 : ['Direct','Direct'], 229 : [''], 237 : ['Direct','Direct'], 242 : ['Direct','Direct'], 256 : ['Direct','Direct'], 257 : ['Direct','Direct'], 264 : [''], 267 : ['Direct','Direct'], 276 : ['Direct','Direct'], 279 : ['Direct','Direct','Direct','Direct'], 285 : ['Direct','Direct'], 287 : [''], 289 : [''], 301 : [''], 532 : ['Direct','Direct'], 632 : ['Direct','Direct'], 771 : ['Direct','Direct'], 866 : ['Direct','Direct'], 875 : ['Direct','Direct'], 888 : ['Direct','Direct'], 894 : ['Direct','Direct'], 938 : [''], 955 : ['Direct','Direct'], 995 : ['Direct','Direct'], 1217 : [''], 1249 : ['Direct','Direct'], 1285 : [''], 1405 : [''], 1515 : ['Direct','Direct','Direct','Direct'], 1627 : ['Direct','Direct'], 1644 : ['Direct','Direct'], 1645 : ['Direct','Direct'], 1850 : ['Direct','Direct'], 1861 : ['Direct','Direct'], 1997 : [''], 2054 : [''], 2158 : [''], 2596 : ['Direct','Direct'], 2643 : ['Direct','Direct'], 2654 : ['Direct','Direct'], 2682 : ['Direct','Direct'], 2725 : [''], 2839 : ['Direct','Direct','Direct','Direct'], 2880 : [''], 2909 : ['Direct','Direct'], 3017 : [''], 3107 : ['Direct','Direct'], 3140 : [''], 3390 : ['Direct','Direct'], 3677 : ['Direct','Direct'], 4267 : [''], 4285 : [''], 4519 : ['Direct','Direct'], 4593 : [''], 4661 : [''], 4667 : ['Direct','Direct'], 4760 : ['Direct','Direct'], 4796 : ['Direct','Direct']
				}
			,
				132 : {
			23 : [''], 1 : [''], 3 : [''], 4 : [''], 5 : [''], 6 : [''], 9 : [''], 15 : [''], 16 : [''], 18 : [''], 21 : [''], 22 : [''], 27 : [''], 32 : [''], 34 : [''], 36 : [''], 37 : [''], 38 : [''], 44 : [''], 49 : [''], 52 : [''], 55 : [''], 57 : [''], 58 : [''], 59 : [''], 63 : [''], 70 : [''], 71 : [''], 73 : [''], 80 : [''], 81 : [''], 86 : [''], 87 : [''], 88 : [''], 89 : [''], 96 : [''], 101 : [''], 102 : [''], 105 : [''], 112 : [''], 118 : [''], 120 : [''], 121 : [''], 127 : [''], 131 : [''], 136 : [''], 141 : [''], 144 : [''], 146 : [''], 148 : [''], 149 : [''], 150 : [''], 157 : [''], 158 : [''], 169 : [''], 174 : [''], 177 : [''], 178 : [''], 180 : [''], 183 : [''], 186 : [''], 191 : [''], 192 : [''], 198 : [''], 209 : [''], 212 : [''], 242 : [''], 256 : [''], 257 : [''], 264 : [''], 828 : [''], 875 : [''], 894 : [''], 955 : [''], 1249 : [''], 1644 : [''], 1850 : [''], 3677 : ['']
				}
			,
				133 : {
			113 : [''], 1 : [''], 3 : [''], 35 : [''], 36 : [''], 41 : [''], 45 : [''], 49 : [''], 52 : [''], 54 : [''], 57 : [''], 59 : [''], 65 : [''], 70 : [''], 71 : [''], 73 : [''], 80 : [''], 96 : [''], 105 : [''], 112 : [''], 121 : [''], 127 : [''], 146 : [''], 183 : [''], 257 : [''], 955 : [''], 1515 : [''], 3677 : [''], 4547 : ['']
				}
			,
				1 : {
			6 : [''], 9 : [''], 16 : [''], 58 : [''], 120 : [''], 146 : [''], 183 : ['']
				}
			,
				18 : {
			3 : [''], 6 : [''], 9 : [''], 16 : [''], 58 : [''], 63 : [''], 105 : [''], 120 : [''], 144 : [''], 146 : [''], 183 : ['']
				}
			,
				29 : {
			6 : [''], 9 : [''], 58 : [''], 70 : [''], 120 : [''], 146 : [''], 183 : ['']
				}
			,
				31 : {
			2 : ['Direct','Direct'], 3 : ['Direct','Direct'], 6 : ['Direct','Direct'], 9 : ['Direct','Direct'], 19 : ['Direct','Direct'], 26 : [''], 36 : ['Direct','Direct'], 49 : ['Direct','Direct'], 52 : ['Direct','Direct'], 58 : ['Direct','Direct'], 59 : ['Direct','Direct','Direct','Direct'], 63 : ['Direct','Direct'], 65 : [''], 67 : [''], 70 : ['Direct','Direct'], 71 : ['Direct','Direct'], 73 : ['Direct','Direct'], 80 : ['Direct','Direct'], 81 : ['Direct','Direct'], 91 : [''], 96 : ['Direct','Direct'], 105 : ['Direct','Direct'], 109 : [''], 112 : ['Direct','Direct'], 121 : ['Direct','Direct'], 127 : ['Direct','Direct'], 131 : [''], 134 : [''], 144 : ['Direct','Direct'], 146 : ['Direct','Direct'], 150 : ['Direct','Direct'], 152 : ['Direct','Direct'], 158 : ['Direct','Direct'], 161 : ['Direct','Direct'], 172 : [''], 180 : ['Direct','Direct'], 183 : [''], 186 : ['Direct','Direct'], 192 : ['Direct','Direct'], 224 : [''], 257 : [''], 946 : ['Direct','Direct'], 995 : ['Direct','Direct'], 1344 : ['Direct','Direct'], 1515 : [''], 2347 : [''], 2596 : [''], 3677 : [''], 4759 : [''], 4760 : ['Direct','Direct']
				}
			,
				34 : {
			3 : [''], 6 : [''], 9 : [''], 16 : [''], 49 : [''], 58 : [''], 63 : [''], 70 : [''], 96 : [''], 105 : [''], 120 : [''], 144 : [''], 146 : [''], 183 : ['']
				}
			,
				44 : {
			3 : [''], 6 : [''], 9 : [''], 58 : [''], 63 : [''], 105 : [''], 146 : [''], 183 : ['']
				}
			,
				54 : {
			3 : [''], 6 : [''], 9 : [''], 16 : [''], 58 : [''], 120 : [''], 146 : [''], 183 : ['']
				}
			,
				56 : {
			1 : ['Direct','Direct'], 2 : ['Direct','Direct'], 3 : ['Direct','Direct'], 4 : [''], 6 : ['Direct','Direct'], 7 : [''], 9 : ['Direct','Direct'], 15 : ['Direct','Direct'], 16 : ['Direct','Direct'], 18 : ['Direct','Direct','Direct','Direct'], 19 : [''], 22 : ['Direct','Direct','Direct','Direct'], 26 : ['Direct','Direct'], 27 : ['Direct','Direct'], 32 : ['Direct','Direct'], 36 : ['Direct','Direct'], 38 : ['Direct','Direct'], 41 : ['Direct','Direct'], 43 : ['Direct','Direct'], 49 : ['Direct','Direct'], 52 : ['Direct','Direct'], 54 : ['Direct','Direct'], 55 : [''], 58 : ['Direct','Direct'], 59 : [''], 63 : [''], 65 : ['Direct','Direct'], 67 : ['Direct','Direct'], 69 : ['Direct','Direct'], 70 : ['Direct','Direct'], 71 : ['Direct','Direct'], 73 : ['Direct','Direct'], 78 : [''], 80 : ['Direct','Direct'], 81 : ['Direct','Direct'], 86 : ['Direct','Direct'], 88 : ['Direct','Direct'], 90 : ['Direct','Direct'], 91 : ['Direct','Direct'], 92 : [''], 96 : ['Direct','Direct'], 97 : [''], 98 : [''], 105 : [''], 111 : [''], 112 : ['Direct','Direct'], 116 : ['Direct','Direct'], 118 : ['Direct','Direct'], 120 : ['Direct','Direct'], 121 : ['Direct','Direct'], 126 : ['Direct','Direct'], 127 : ['Direct','Direct'], 131 : ['Direct','Direct'], 136 : [''], 139 : [''], 141 : [''], 144 : ['Direct','Direct'], 146 : ['Direct','Direct'], 148 : [''], 149 : ['Direct','Direct'], 150 : ['Direct','Direct'], 157 : ['Direct','Direct'], 158 : ['Direct','Direct'], 159 : ['Direct','Direct'], 161 : [''], 165 : [''], 169 : ['Direct','Direct'], 172 : [''], 173 : ['Direct','Direct','Direct','Direct'], 177 : ['Direct','Direct'], 180 : ['Direct','Direct'], 183 : ['Direct','Direct'], 191 : ['Direct','Direct'], 192 : ['Direct','Direct'], 212 : ['Direct','Direct'], 229 : [''], 242 : [''], 256 : ['Direct','Direct'], 257 : [''], 267 : ['Direct','Direct'], 828 : [''], 875 : ['Direct','Direct'], 888 : [''], 894 : ['Direct','Direct'], 903 : ['Direct','Direct'], 946 : ['Direct','Direct'], 955 : ['Direct','Direct'], 995 : ['Direct','Direct'], 1213 : ['Direct','Direct'], 1304 : [''], 1344 : [''], 1515 : [''], 1850 : ['Direct','Direct'], 2051 : [''], 2085 : [''], 2456 : ['Direct','Direct'], 2725 : [''], 2857 : ['Direct','Direct'], 3264 : ['Direct','Direct'], 3677 : ['Direct','Direct'], 4334 : [''], 4346 : ['']
				}
			,
				57 : {
			6 : [''], 9 : [''], 58 : ['']
				}
			,
				65 : {
			3 : [''], 6 : [''], 9 : [''], 16 : [''], 58 : [''], 63 : [''], 105 : [''], 144 : [''], 146 : [''], 183 : ['']
				}
			,
				95 : {
			1 : [''], 2 : [''], 3 : [''], 6 : [''], 9 : [''], 15 : [''], 16 : [''], 18 : [''], 19 : [''], 22 : [''], 27 : [''], 32 : [''], 34 : [''], 35 : [''], 36 : [''], 38 : [''], 41 : [''], 49 : [''], 52 : [''], 54 : [''], 57 : [''], 58 : [''], 63 : [''], 65 : [''], 71 : [''], 73 : [''], 80 : [''], 81 : [''], 90 : [''], 96 : [''], 98 : [''], 102 : [''], 105 : [''], 111 : [''], 112 : [''], 117 : [''], 120 : [''], 121 : [''], 126 : [''], 131 : [''], 136 : [''], 144 : [''], 146 : [''], 149 : [''], 150 : [''], 157 : [''], 158 : [''], 172 : [''], 174 : [''], 180 : [''], 183 : [''], 184 : [''], 191 : [''], 192 : [''], 198 : [''], 212 : [''], 242 : [''], 256 : [''], 257 : [''], 875 : [''], 955 : [''], 1249 : [''], 1304 : [''], 1645 : [''], 1850 : [''], 1861 : [''], 1875 : [''], 2682 : [''], 3677 : [''], 4237 : [''], 4453 : [''], 4519 : ['']
				}
			,
				101 : {
			3 : [''], 6 : [''], 9 : [''], 15 : [''], 16 : [''], 49 : [''], 58 : [''], 63 : [''], 70 : [''], 73 : [''], 88 : [''], 96 : [''], 98 : [''], 105 : [''], 109 : [''], 112 : [''], 120 : [''], 121 : [''], 144 : [''], 146 : [''], 157 : [''], 158 : [''], 177 : [''], 183 : ['']
				}
			,
				106 : {
			6 : [''], 9 : [''], 16 : [''], 58 : [''], 70 : [''], 120 : [''], 146 : [''], 157 : [''], 183 : ['']
				}
			,
				108 : {
			3 : [''], 6 : [''], 9 : [''], 16 : [''], 58 : [''], 63 : [''], 70 : [''], 105 : [''], 112 : [''], 120 : [''], 121 : [''], 146 : [''], 157 : [''], 183 : ['']
				}
			,
				123 : {
			1 : [''], 3 : [''], 6 : [''], 9 : [''], 16 : [''], 27 : [''], 32 : [''], 36 : [''], 49 : [''], 52 : [''], 58 : [''], 70 : [''], 80 : [''], 96 : [''], 102 : [''], 112 : [''], 127 : [''], 131 : [''], 144 : [''], 146 : [''], 152 : [''], 157 : [''], 183 : [''], 198 : [''], 229 : [''], 257 : [''], 875 : [''], 3677 : ['']
				}
			,
				174 : {
			6 : [''], 9 : [''], 58 : [''], 120 : [''], 146 : ['']
				}
			,
				178 : {
			3 : [''], 6 : [''], 9 : [''], 16 : [''], 49 : [''], 58 : [''], 63 : [''], 70 : [''], 80 : [''], 96 : [''], 98 : [''], 105 : [''], 112 : [''], 120 : [''], 146 : [''], 157 : [''], 183 : ['']
				}
			,
				244 : {
			6 : [''], 9 : [''], 16 : [''], 58 : [''], 80 : [''], 146 : [''], 150 : [''], 180 : [''], 257 : [''], 3677 : ['']
				}
			,
				286 : {
			3 : ['Direct'], 6 : ['Direct'], 9 : ['Direct'], 19 : [''], 22 : [''], 27 : [''], 32 : [''], 36 : [''], 49 : [''], 52 : [''], 58 : [''], 70 : ['Direct'], 71 : [''], 73 : [''], 80 : ['Direct'], 90 : [''], 96 : [''], 105 : ['Direct'], 112 : ['Direct'], 115 : [''], 117 : [''], 118 : [''], 121 : [''], 127 : [''], 141 : [''], 144 : [''], 146 : ['Direct'], 149 : [''], 150 : [''], 157 : ['Direct'], 158 : [''], 162 : [''], 177 : [''], 180 : [''], 183 : ['Direct'], 186 : [''], 191 : [''], 198 : [''], 212 : [''], 229 : [''], 257 : ['Direct'], 1432 : [''], 2347 : [''], 2725 : [''], 3264 : ['']
				}
			
			};
		
			var cfgAirportsMatrixMaxBits = 31;
			var cfgMaxChildren = 7;
			var cfgMaxRooms = 8;
			var required_fields = new Array('airportcombinedfromid','airportgrouptoid','airporttoid');
			
			Array.prototype.contains = function (el)
			{
				for (var i=0; i<this.length; i++)
					if (this[i] == el)
						return true;
				
				return false;
			}
			
			// Build keyed version of airports and groups, for easier lookups
			
			var objDepAirports = {};
			var objDestAirports = {};
			var objDestGroups = {};
			
			for (var a=0; a<arrDepAirports.length; a++)
			{
				objDepAirports[arrDepAirports[a][0]] = {};
				objDepAirports[arrDepAirports[a][0]].airportId = arrDepAirports[a][0];
				objDepAirports[arrDepAirports[a][0]].name = arrDepAirports[a][1];
				objDepAirports[arrDepAirports[a][0]].groupId = arrDepAirports[a][2];
			}
			
			for (var a=0; a<arrDestAirports.length; a++)
			{
				objDestAirports[arrDestAirports[a][0]] = {};
				objDestAirports[arrDestAirports[a][0]].airportId = arrDestAirports[a][0];
				objDestAirports[arrDestAirports[a][0]].name = arrDestAirports[a][1];
				objDestAirports[arrDestAirports[a][0]].groupId = arrDestAirports[a][2];
			}
			
			for (var a=0; a<arrDestAirportGroups.length; a++)
			{
				objDestGroups[arrDestAirportGroups[a][0]] = {};
				objDestGroups[arrDestAirportGroups[a][0]].groupId = arrDestAirportGroups[a][0];
				objDestGroups[arrDestAirportGroups[a][0]].name = arrDestAirportGroups[a][1];
			}
			
	/* Generic Search Form Functions */
	
	// Avoid risk of corrupting UTF-8 in source file
	var laquo = '\u00ab';
	var raquo = '\u00bb';
	
	function create_xml_http_request()
	{
		if (window.XMLHttpRequest)
		{
			// If IE7, Mozilla, Safari, etc: Use native object
			return new XMLHttpRequest()
	
		}
		else if (window.ActiveXObject)
		{
			// Microsoft recommended fallback for old IEs (5 & 6)
			// http://blogs.msdn.com/ie/archive/2006/01/23/516393.aspx
			return new ActiveXObject("Microsoft.XMLHTTP");
		}
		return false;
	}
	
	function srhfrm_filter_both_ways(parent_value, group_value, all_child_options, filter, child_dropdown, first_option, append)
	{
		var group = 1;
		var textPrefix='';
		var textSuffix='';
		var idPrefix='';
		var intOldVal=child_dropdown.value;
		var option_container = child_dropdown;
		var optgroup;
		
		// Need to detect if group or airport is selected.
		if (!append)
		{
			//child_dropdown.options.length = keep_first;
			child_dropdown.innerHTML = '';
			if (first_option)
			{
				child_dropdown[child_dropdown.length] = new Option
				(
					first_option,
					-1
				);
			}
			
		}


		// Add UK group
		new_option = new Option
		(
			'',//textPrefix + 'UK' + textSuffix,
			idPrefix + '48',
			false,
			('UK' == intOldVal)
		);
		
		// To cope with IE's poor optgroup support
		new_option.appendChild(document.createTextNode(textPrefix + 'UK' + textSuffix));
		option_container.appendChild(new_option);

		
		// look up group in arrDestAirportGroups array
//			for (var j = 0; j < all_child_options.length; j++)
//			{
//				if(all_child_options[j][0] == group_value)
//				{
//					group_index = j;
//					break;
//				}
//			}
//			
//			var bit = group_index;
//
//			// loop through departure airports			
//			for(var j = 0; j < arrDepAirports.length; j++)
//			{
//				// find filter
//				for (var i = 0; i < filter.length; i++)
//				{
//					if(arrDepAirports[j][0] == filter[i][0])
//					{
//						// Bitwise AND (don't add another &)
//						if ((1 << bit) & filter[i][group])
//						{
//							new_option = new Option
//							(
//								'',//textPrefix + arrDepAirports[j][1] + textSuffix,
//								idPrefix + arrDepAirports[j][0],
//								false,
//								(arrDepAirports[j][0] == intOldVal)
//							);
//									
//							// To cope with IE's poor optgroup support
//							new_option.appendChild(document.createTextNode(textPrefix + arrDepAirports[j][1] + textSuffix));
//							option_container.appendChild(new_option);
//						}
//					}
//				}
//			}



//			if (child_dropdown.length <= 1)
//			{
//				// Check through all the possible options
//				for (var j = 0; j < all_child_options.length; j++)
//				{
//					if (all_child_options[j][2] != current_group_id)
//					{
//						option_container = child_dropdown;
//						current_group_id = 0;
//					}
//				
//					// Bitwise AND (don't add another &)
//					if (all_child_options[j][3] && all_child_options[j][3] != '')
//					{
//						// Add the previous optgroup to the dropdown before creating a new one
//						if (optgroup && optgroup.childNodes.length > 0)
//						{
//							child_dropdown.appendChild(optgroup);
//						}
//						current_group = all_child_options[j][3];
//						current_group_id = all_child_options[j][2];
//						optgroup = document.createElement('optgroup');
//						optgroup.setAttribute('label', all_child_options[j][3]);
//						option_container = optgroup;
//						
//					}
//					else
//					{
//						if ((!group_value) || (all_child_options[j][2] == group_value))
//						{
//							new_option = new Option
//							(
//								'',//textPrefix + all_child_options[j][1] + textSuffix,
//								idPrefix + all_child_options[j][0],
//								false,
//								(all_child_options[j][0] == intOldVal)
//							);
//							// To cope with IE's poor optgroup support
//							new_option.appendChild(document.createTextNode(textPrefix + all_child_options[j][1] + textSuffix));
//							option_container.appendChild(new_option);
//						}
//					}
//				}
//			}
//			
		child_dropdown.disabled = (child_dropdown.length <= 1) ? 'disabled' : false;
	}
	
	/**
	 * @param int parent_value The value selected in the parent dropdown
	 * @param int group_value
	 * @param array all_child_options The list of potential options for the child dropdown
	 * @param array filter Bit-based array containing information about the mappings from one airport to another
	 * @param HTML_select_element child_dropdown The dropdown to put the new options into
	 * @param int first_option The display string of the first option in the dropdown (e.g. Any) which will have a value of -1
	 * @param boolean append If true, add additional options without deleting any existing options (keep_first will be ignored)
	 */
	function srhfrm_filter_options(parent_value, group_value, all_child_options, filter, child_dropdown, first_option, append)
	{
		var matchGroup = false;
		var textPrefix='';
		var textSuffix='';
		var idPrefix='';
		var intOldVal=child_dropdown.value;
		var current_group = '';
		var current_group_id = 0;
		var option_container = child_dropdown;
		var optgroup;
		var group_found = false;
		var group_index;
		var goup = 1;
		
		/* parent_value  - airport value */
		/* group_value - null */
		
		/* all_child_options - aiport group options */
		/* filter - bit map */
		
		/* child_dropdown - select element */
		/* first_option - please select string */
		/* append - false */
				
		
		// Need to detect if group or airport is selected.
		if (!append)
		{
			//child_dropdown.options.length = keep_first;
			child_dropdown.innerHTML = '';
			
			if (first_option == laquo+' Any '+raquo)
			{
				child_dropdown[child_dropdown.length] = new Option
				(
					first_option,
					'Any'
				);
			}
			else if (first_option)
			{
				child_dropdown[child_dropdown.length] = new Option
				(
					first_option,
					-1
				);
			}
		}
		
		if(filter.length == 0)
		{
			group_found = true;
		}
		
		for (var i = 0; i < filter.length; i++)
		{
			// Check through the filter array to find the values to filter on.
			if (filter[i][0] == parent_value)
			{
				var strTest = '';
				var bit = 0;
				var group = 1;
				group_found = true;
				// Check through all the possible options
				for (var j = 0; j < all_child_options.length; j++)
				{
					if (all_child_options[j][2] != current_group_id)
					{
						option_container = child_dropdown;
						current_group_id = 0;
					}

					if (all_child_options[j].length == 4 && all_child_options[j][3] != '')
					{
						// Add the previous optgroup to the dropdown before creating a new one
						if (optgroup && optgroup.childNodes.length > 0)
						{
							child_dropdown.appendChild(optgroup);
						}
						current_group = all_child_options[j][3];
						current_group_id = all_child_options[j][2];
						optgroup = document.createElement('optgroup');
						optgroup.setAttribute('label', all_child_options[j][3]);
						option_container = optgroup;
						
					}
					// Bitwise AND (don't add another &)
					else if ((1 << bit) & filter[i][group])
					{
						if ((!group_value) || (all_child_options[j][2] == group_value))
						{
							new_option = new Option
							(
								'',//textPrefix + all_child_options[j][1] + textSuffix,
								idPrefix + all_child_options[j][0],
								false,
								(all_child_options[j][0] == intOldVal)
							);
							// To cope with IE's poor optgroup support
							new_option.appendChild(document.createTextNode(textPrefix + all_child_options[j][1] + textSuffix));
							option_container.appendChild(new_option);
//								This is for combined destination airports
//								if ( mixAirports )
//								{
//									// append airports underneath this group
//									alert('Run filter airports again');
//									//filterAirports(child_dropdown, 'dep_airports_combined_groups', 0, all_child_options[j][0], resortid_dropdownid);
//								}
						}
					}
					
					bit++;
					if (bit == cfgAirportsMatrixMaxBits)
					{
						bit = 0;
						group++;
					}
				}
				
				// Add the last remaining optgroup to the dropdown
				if (optgroup && optgroup.childNodes.length > 0)
				{
					child_dropdown.appendChild(optgroup);
				}
			}
		}
		// ****************************************************************
		// ***** departure outside the UK *********************************
		// ****************************************************************
		if(!group_found && !group_value)
		{
			// Add UK group
			new_option = new Option
			(
				'',//textPrefix + 'UK' + textSuffix,
				idPrefix + '48',
				false,
				('UK' == intOldVal)
				);
		
			// To cope with IE's poor optgroup support
			new_option.appendChild(document.createTextNode(textPrefix + 'UK' + textSuffix));
			option_container.appendChild(new_option);
		}			
		
		else if(group_value == 48)
		{
			for (var j = 0; j < arrDestAirportGroups.length; j++)
			{
				if(arrDestAirportGroups[j][0] == 99)
				{
					group_index = j;
					break;
				}
			}

			var bit = group_index;
			
			// loop through departure airports	

			for(var j = 0; j < arrDepAirports.length; j++)
			{
				// find filter
				for (var i = 0; i < arrDepAirportsDestGroups.length; i++)
				{
					if(arrDepAirports[j][0] == arrDepAirportsDestGroups[i][0])
					{
						
						// Bitwise AND (don't add another &)
						if ((1 << bit) & arrDepAirportsDestGroups[i][1])
						{
							
							new_option = new Option
							(
								'',//textPrefix + arrDepAirports[j][1] + textSuffix,
								idPrefix + arrDepAirports[j][0],
								false,
								(arrDepAirports[j][0] == intOldVal)
							);
									
							// To cope with IE's poor optgroup support
							new_option.appendChild(document.createTextNode(textPrefix + arrDepAirports[j][1] + textSuffix));
							option_container.appendChild(new_option);
						}
					}
				}
			}
		}
		if (child_dropdown.length <= 1)
		{
			// Check through all the possible options
			for (var j = 0; j < all_child_options.length; j++)
			{
				if (all_child_options[j][2] != current_group_id)
				{
					option_container = child_dropdown;
					current_group_id = 0;
				}
			
				// Bitwise AND (don't add another &)
				if (all_child_options[j][3] && all_child_options[j][3] != '')
				{
					// Add the previous optgroup to the dropdown before creating a new one
					if (optgroup && optgroup.childNodes.length > 0)
					{
						child_dropdown.appendChild(optgroup);
					}
					current_group = all_child_options[j][3];
					current_group_id = all_child_options[j][2];
					optgroup = document.createElement('optgroup');
					optgroup.setAttribute('label', all_child_options[j][3]);
					option_container = optgroup;
					
				}
				else
				{
					if ((!group_value) || (all_child_options[j][2] == group_value))
					{
						new_option = new Option
						(
							'',//textPrefix + all_child_options[j][1] + textSuffix,
							idPrefix + all_child_options[j][0],
							false,
							(all_child_options[j][0] == intOldVal)
						);
						// To cope with IE's poor optgroup support
						new_option.appendChild(document.createTextNode(textPrefix + all_child_options[j][1] + textSuffix));
						option_container.appendChild(new_option);
					}
				}
			}
		}
		
		child_dropdown.disabled = (child_dropdown.length <= 1) ? 'disabled' : false;
	}
	
	function srhfrm_update_destination_airport_groups(srhfrm)
	{
		if(srhfrm['resort_dd[1]'])
		{
			srhfrm_update_resort_dd(srhfrm, 1);
		}
		else
		{
			srhfrm_fill_dropdown('srhfrm_destination_airport', new Array({'value': '', 'display': laquo+' Please Select '+raquo}), 0);
			srhfrm_fill_dropdown('srhfrm_resort', new Array({'value': '', 'display': laquo+' Any '+raquo}), 0);
			srhfrm_fill_dropdown('srhfrm_accomm', new Array({'value': '', 'display': laquo+' Any '+raquo}), 0);
			departure_airport = -1;
			departure_airport_group = -1;	
			onewayrow = document.getElementById('onewaydepartures');
			
			if ( srhfrm.onewayairportfromid && onewayrow.style.display != 'none')
			{
				departure_airport_combined = srhfrm.onewayairportfromid.value;
				
				if ( departure_airport_combined.substring(0, 1) == "|" )
				{
					departure_airport = departure_airport_combined.substring(1);
					departure_airport_group = -1;
				}
			}			
			else if ( srhfrm.airportcombinedfromid )
			{
				departure_airport_combined = srhfrm.airportcombinedfromid.value;
				if ( departure_airport_combined.substring(0, 1) == "|" )
				{
					departure_airport = departure_airport_combined.substring(1);
					departure_airport_group = -1;
				}
				else
				{
					departure_airport = -1;
					departure_airport_group = departure_airport_combined;
				}
			}
			else
			{
				departure_airport = srhfrm.airportfromid.value;
				departure_airport_group = srhfrm.airportgroupfromid.value;
			}
			
			if (departure_airport == -1 && departure_airport_group == -1)
			{		
				srhfrm_fill_dropdown('srhfrm_destination_airport_group', new Array({'value': '', 'display': laquo+' Please Select '+raquo}), 0);
			}
			else if(departure_airport != -1)
			{
				if (srhfrm.airportgrouptoid)
				{
					srhfrm_filter_options(
						departure_airport,
						null,
						arrDestAirportGroups,
						arrDepAirportsDestGroups,
						srhfrm.airportgrouptoid, 
						laquo+' Please Select '+raquo,
						false
					);
					
					// If there is only one option, choose it
					if (srhfrm.airportgrouptoid.length == 2 && (srhfrm.airportgrouptoid.options[0].value == -1 || srhfrm.airportgrouptoid.options[0].value == ''))
					{
						srhfrm.airportgrouptoid.selectedIndex = 1;
					}

					// Repopulate if the option is in the list.
					else if (srhfrm.repop_srhfrm_destination_airport_group && srhfrm.repop_srhfrm_destination_airport_group.value) 
					{
						srhfrm.airportgrouptoid.value = srhfrm.repop_srhfrm_destination_airport_group.value;
					}
					if (srhfrm.airportgrouptoid.value && srhfrm.airportgrouptoid.value != -1)
					{
						srhfrm_update_destination_airports(srhfrm);
					}
				}
				else if (document.getElementById('srhfrm_destination_airport_combined'))
				{
					var destination_airport_select = document.getElementById('srhfrm_destination_airport_combined');
					var current_selected = destination_airport_select.value.substring(1);
					
					var current_destination_airport;
					var current_destination_airport_group;
					
					// Keyed on group id, each element is an array of airport ids
					var matching_destination_airports = {};
					var matched_groups = new Array();
					
					// If any destination mappings exist...
					if (arrDepAirportsDestAirports[departure_airport])
					{
						// iterate over them...
						for (var current_destination_airport_id in arrDepAirportsDestAirports[departure_airport])
						{
							current_destination_airport = objDestAirports[current_destination_airport_id];
							
							if (!current_destination_airport)
							{
								continue;
							}
							
							if (document.getElementById('srhfrm_show_only_direct').checked
							    && !arrDepAirportsDestAirports[departure_airport][current_destination_airport_id].contains('Direct'))
							{
								continue;
							}
							
							if (!matched_groups.contains(current_destination_airport.groupId))
							{
								matching_destination_airports[current_destination_airport.groupId] = new Array();
								matched_groups.push(current_destination_airport.groupId);
							}
							
							matching_destination_airports[current_destination_airport.groupId].push(current_destination_airport.airportId)
						}
					}
					
					destination_airport_select.innerHTML = '';
					
					// Wow, there really isn't a count method for object keys...
					var airport_count = 0;
					
					for (var ii in matching_destination_airports)
					{
						airport_count++;
					}
					
					if (airport_count == 0)
					{
						var new_option = new Option(
							'No current availability',
							'Any'
						);
						
						new_option.innerText = 'No current availability';
						
						destination_airport_select.appendChild(new_option);
						
						destination_airport_select.disabled = 'disabled';
					}
					
					else
					{
						var new_option = new Option(
							'Please Select',
							'Any'
						);
						
						new_option.innerText = 'Please Select';
						
						destination_airport_select.appendChild(new_option);
						
						for (var dest_group_id in matching_destination_airports)
						{
							var dest_optgroup = document.createElement("optgroup")
							dest_optgroup.label = objDestGroups[dest_group_id].name;
							
							for (var j=0; j<matching_destination_airports[dest_group_id].length; j++)
							{
								var new_option = new Option(
									objDestAirports[matching_destination_airports[dest_group_id][j]].name,
									"|" + objDestAirports[matching_destination_airports[dest_group_id][j]].airportId,
									current_selected == objDestAirports[matching_destination_airports[dest_group_id][j]].airportId,
									current_selected == objDestAirports[matching_destination_airports[dest_group_id][j]].airportId
								);
							
								new_option.innerText =
										objDestAirports[matching_destination_airports[dest_group_id][j]].name;
								
								dest_optgroup.appendChild(new_option);
							}
							
							destination_airport_select.appendChild(dest_optgroup);
						}
						
						destination_airport_select.disabled = false;
						
						srhfrm_update_resorts(srhfrm);
					}
				}
			}
			else // have departure_airport_group ID
			{
				if (srhfrm.airportgrouptoid)
				{
					srhfrm_filter_options(
						departure_airport_group,
						null,
						arrDestAirportGroups,
						arrDepGroupsDestGroups,
						srhfrm.airportgrouptoid, 
						laquo+' Please Select '+raquo,
						false
					);
					
					// Repopulate if the option is in the list.
					if (srhfrm.repop_srhfrm_destination_airport_group && srhfrm.repop_srhfrm_destination_airport_group.value) 
					{
						srhfrm.airportgrouptoid.value = srhfrm.repop_srhfrm_destination_airport_group.value;
					}
					if (srhfrm.airportgrouptoid.value && srhfrm.airportgrouptoid.value != -1)
					{
						srhfrm_update_destination_airports(srhfrm);
					}
				}
//				else if (document.getElementById('srhfrm_destination_airport_combined'))
//				{
//					alert('Update combined destination airport dropdown');
//				}
			}
		}
		srhfrm_append_subsites();
		srhfrm_highlight_required(srhfrm);
		srhfrm_save_values(srhfrm);
	}
	
	function srhfrm_append_subsites()
	{
		if (document.forms && document.forms.srhfrm && document.forms.srhfrm.airportgrouptoid)
		{
			// //// If we include the subsites in the destination drop down - or other stuff declared in optionSubsites array
			if(typeof(optionSubsites)!= 'undefined' && optionSubsites.length > 0)
			{	
				var subsites_optgroup = document.createElement('optgroup');
				subsites_optgroup.setAttribute('label', optionSubsitesTitle);
							
				// Add extra options
				for (var i = 0; i < optionSubsites.length; i++)
				{
					new_option = new Option
					(
						'',
						optionSubsitesValues[i]
					);
					// To cope with IE's poor optgroup support
					new_option.appendChild(document.createTextNode(optionSubsites[i]));
					subsites_optgroup.appendChild(new_option);
				}
				
				document.getElementById('srhfrm_destination_airport_group').appendChild(subsites_optgroup);
			}
		}
	}
	
	function srhfrm_update_destination_airports(srhfrm)
	{	
		// //// Change tab - onClick event
		if((typeof(optionSubsites)!= 'undefined') && (document.getElementById('srhfrm_destination_airport_group').value.substr(0,8) == 'onchange'))
		{
			type = document.getElementById('srhfrm_destination_airport_group').value.substr(9);
			changeTab(type);
		}
		
		srhfrm_fill_dropdown('srhfrm_resort', new Array({'value': '', 'display': laquo+' Any '+raquo}), 0);
		srhfrm_fill_dropdown('srhfrm_accomm', new Array({'value': '', 'display': laquo+' Any '+raquo}), 0);
		if (document.getElementById('srhfrm_departure_airport_combined'))
		{
			departure_airport = document.getElementById('srhfrm_departure_airport_combined').value;
			if(departure_airport.substring(0, 1) == "|")
			{
				departure_airport = departure_airport.substring(1);
			}
		}
		else
		{
			departure_airport = -1;
		}
		
		if(srhfrm.airportgrouptoid.value == 'Any')
		{
			srhfrm_fill_dropdown('srhfrm_destination_airport', new Array({'value': 'Any', 'display': laquo+' Any '+raquo}), 0);
		}
		
		else if (srhfrm.airporttoid && srhfrm.airportgrouptoid.value)
		{
			srhfrm_filter_options(
				departure_airport,
				srhfrm.airportgrouptoid.value,
				arrDestAirports,
				arrDepAirportsDestAirports,
				srhfrm.airporttoid, 
				laquo+' Please Select '+raquo,
				false
			);
				
			// If there is only one option, choose it
			if (srhfrm.airporttoid.length == 2 && (srhfrm.airporttoid.options[0].value == -1 || srhfrm.airporttoid.options[0].value == ''))
			{
				srhfrm.airporttoid.selectedIndex = 1;
			}
			// Repopulate if the option is in the list.
			else if (srhfrm.repop_srhfrm_destination_airport && srhfrm.repop_srhfrm_destination_airport.value) 
			{
				srhfrm.airporttoid.value = srhfrm.repop_srhfrm_destination_airport.value;
			}
			else
			{
				// Make sure we at least select something
				srhfrm.airporttoid.selectedIndex = 0;
			}
		}
		else if (document.getElementById('srhfrm_destination_airport_combined'))
		{
			alert('Update combined destination airport dropdown');
		}
		srhfrm_update_resorts(srhfrm);
		srhfrm_highlight_required(srhfrm);
		srhfrm_save_values(srhfrm);
	}
	
	function srhfrm_update_departure_airports(srhfrm)
	{
		var textPrefix='';
		var textSuffix='';
		
		if ( srhfrm.airportfromid )
		{
			srhfrm.airportfromid.length = 1;
			for (var i = 0; i < arrDepAirports.length; i++)
			{
				if (arrDepAirports[i][2] == srhfrm.airportgroupfromid.value)
		{
					srhfrm.airportfromid.appendChild(new Option
					(
						textPrefix + arrDepAirports[i][1] + textSuffix,
						arrDepAirports[i][0],
						false
					));
				}
			}
			srhfrm.airportfromid.disabled = srhfrm.airportfromid.length > 1 ? false : true;
		}
		srhfrm_save_values(srhfrm);
	}
	
	function srhfrm_update_departure_airports(srhfrm)
	{
		var textPrefix='';
		var textSuffix='';
		
		if ( srhfrm.airportfromid )
		{
			srhfrm.airportfromid.length = 1;
			for (var i = 0; i < arrDepAirports.length; i++)
			{
				if (arrDepAirports[i][2] == srhfrm.airportgroupfromid.value)
		{
					new_option = new Option
					(
						'',
						arrDepAirports[i][0],
						false
					);
					// To cope with IE's poor optgroup support
					new_option.appendChild(document.createTextNode(textPrefix + arrDepAirports[i][1] + textSuffix));
					srhfrm.airportfromid.appendChild(new_option);
				}
			}
			srhfrm.airportfromid.disabled = srhfrm.airportfromid.length > 1 ? false : true;
		}
		srhfrm_save_values(srhfrm);
	}
	
	function srhfrm_update_resort_dd(srhfrm, level_num, old_values, old_accomm)
	{
		var resort_dd_element = srhfrm['resort_dd['+level_num+']'];
		
		// Clear the accommodation dd, but only if the resort dropdowns are visible
		if (!document.getElementById('srhfrm_resort_dd_'+level_num))
		{
			if (document.getElementById('srhfrm_resort_dd_'+(level_num-1)))
			{
				srhfrm_update_accomm(srhfrm, old_accomm);
			}
			return false;
		}
		
		if (!old_values)
		{
			old_values = new Array();
			for (var i = level_num; srhfrm['resort_dd['+i+']']; i++)
			{
				old_values.push(srhfrm['resort_dd['+i+']'].value);
			}
		}
		if (!old_accomm && srhfrm.property_id)
		{
			old_accomm = srhfrm.property_id.value;
		}
		
		// Variable number of dots to show what is doing the updating
		var loading_text = 'Loading.........';
		loading_text = loading_text.substr(0, 7 + level_num);
		for (var i = level_num; srhfrm['resort_dd['+i+']']; i++)
		{
			srhfrm_fill_dropdown('srhfrm_resort_dd_'+i, new Array({'value': '', 'display': loading_text}), 0);
		}
		if (srhfrm['resort_dd['+level_num+']'])
		{
			srhfrm_fill_dropdown('srhfrm_accomm', new Array({'value': '', 'display': loading_text}), 0);
		}
		if (level_num > 1)
		{
			var parent_level_num = level_num - 1;
			var parent_resort_dd_id = srhfrm['resort_dd['+parent_level_num+']'].value;
			if (parent_resort_dd_id.substr(0, 2) == -1 || srhfrm['resort_dd['+parent_level_num+']'].disabled)
			{
				srhfrm_fill_dropdown('srhfrm_resort_dd_'+level_num, new Array({'value': '', 'display': laquo+' Please select '+raquo}), 0);
				// Fill any lower level dropdowns with 'any' and update the accommodation
				srhfrm_update_resort_dd(srhfrm, level_num + 1);
				return;
			}
		}
		
		var resort_dd_set_id = srhfrm['resort_dd_set_id'].value;
		
		if (srhfrm['airportfromid'])
		{
			var dep_airport_id = srhfrm['airportfromid'].value;
		}
		else if (srhfrm['airportcombinedfromid'])
		{
			if (srhfrm['airportcombinedfromid'].value == -1)
			{
				var dep_airport_id = -1;
			}

			else
			{
				var dep_airport_id = srhfrm['airportcombinedfromid'].value.substr(1, srhfrm['airportcombinedfromid'].length);
			}
		}
		else
		{
			var dep_airport_id = -1;
		}
		
//			if (document.getElementById('srhfrm_destination_airport') 
//				&& document.getElementById('srhfrm_destination_airport').value 
//				&& document.getElementById('srhfrm_destination_airport').value != -1)
//			{
//				var airport_to_id = document.getElementById('srhfrm_destination_airport').value;
//			}
//			else if (document.getElementById('srhfrm_destination_airport_combined') 
//					 && document.getElementById('srhfrm_destination_airport_combined').value
//					 && document.getElementById('srhfrm_destination_airport_combined').value != -1)
//			{
//				var airport_to_id = document.getElementById('srhfrm_destination_airport_combined').value;
//			}
//			else
//			{
//				// No destination airport - Don't get resorts 
//				srhfrm_fill_dropdown('srhfrm_resort', new Array({'value': '', 'display': laquo+' Any '+raquo}), 0);
//				return true;
//			}
//			srhfrm_highlight_required(srhfrm);
//			srhfrm_save_values(srhfrm);
		
		var xmlhttprequest = create_xml_http_request();
		xmlhttprequest.onreadystatechange = function()
		{
			if(xmlhttprequest.readyState == 4 && xmlhttprequest.status == 200)
			{
				var doc = xmlhttprequest.responseXML;
				var root = doc.documentElement;
				var nds;
				resort_dd_element.options.length = 0;
						
				if(root.hasChildNodes()) 
				{
					nds=root.childNodes;
					var len = nds.length;
					for (var i = 0; i < len; i++)
					{
						if(nds[i].nodeName == 'ResortDD')
						{
							resort_dd_element.options[resort_dd_element.options.length] = new Option(nds[i].getAttribute("name"), nds[i].getAttribute("value") + ',' + nds[i].getAttribute("is_searchable"));
						}
					}
				}
				if (resort_dd_element.length > 1)
				{
					resort_dd_element.disabled = false;
					// If there is only one option, choose it
					if (resort_dd_element.length == 2 && (resort_dd_element.options[0].value == -1 || resort_dd_element.options[0].value == ''))
					{
						resort_dd_element.selectedIndex = 1;
					}
					// Repopulate if the option is in the list.
					else if (old_values[0])
					{
						srhfrm['resort_dd['+level_num+']'].value = old_values[0];
					}
					else
					{
						// Make sure we at least select something
						resort_dd_element.selectedIndex = 0;
					}
					if (resort_dd_element.selectedIndex == -1)
					{
						// Make sure we at least select something
						resort_dd_element.selectedIndex = 0;
					}
				}
				else
				{
					resort_dd_element.disabled = true;
					srhfrm_fill_dropdown('srhfrm_resort_dd_'+level_num, new Array({'value': '', 'display': laquo+' Any '+raquo}), 0);
					resort_dd_element.selectedIndex = 0;
				}
				srhfrm_update_resort_dd(srhfrm, level_num + 1, old_values.slice(1), old_accomm);
			}
		}
		xml_url = '/fetch_opts.php?mode=resort_dd&resort_dd_set_id='+resort_dd_set_id+'&level_num='+level_num+'&dep_airport_id='+dep_airport_id;
		if (parent_resort_dd_id)
		{
			xml_url += '&parent_resort_dd_id='+parent_resort_dd_id;
		}
		xmlhttprequest.open('GET', xml_url, true);
		xmlhttprequest.send(null);
		srhfrm_save_values(srhfrm);
	}
	
	function srhfrm_update_resorts(srhfrm)
	{
		srhfrm_fill_dropdown('srhfrm_resort', new Array({'value': '', 'display': 'Loading...'}), 0);
		
		if (document.getElementById('srhfrm_destination_airport') 
			&& document.getElementById('srhfrm_destination_airport').value 
			&& document.getElementById('srhfrm_destination_airport').value != -1)
		{
			var airport_to_id = document.getElementById('srhfrm_destination_airport').value;
		}
		else if (
			   document.getElementById('srhfrm_destination_airport_combined') 
			&& document.getElementById('srhfrm_destination_airport_combined').value
			&& document.getElementById('srhfrm_destination_airport_combined').value != -1
			&& document.getElementById('srhfrm_destination_airport_combined').value != -1
			&& document.getElementById('srhfrm_destination_airport_combined').value.substring(0,1) == '|'
		)
		{
			// The value here will be of the form "|airport_id"
			var airport_to_id = document.getElementById('srhfrm_destination_airport_combined').value.substring(1);
		}
		else
		{
			// No destination airport - Don't get resorts 
			srhfrm_fill_dropdown('srhfrm_resort', new Array({'value': '', 'display': laquo+' Any '+raquo}), 0);
			return true;
		}
		srhfrm_highlight_required(srhfrm);
		srhfrm_save_values(srhfrm);
		
		var xmlhttprequest = create_xml_http_request();
		xmlhttprequest.onreadystatechange = function()
		{
			if(xmlhttprequest.readyState == 4 && xmlhttprequest.status == 200)
			{
				var doc = xmlhttprequest.responseXML;
				var root = doc.documentElement;
				var resorts = document.getElementById('srhfrm_resort');
				if ( ! resorts )
				{
					return false;
				}
				resorts.options.length = 0;
				var nds;		
						
				if(root.hasChildNodes()) 
				{
					nds=root.childNodes;
					var len = nds.length;
					for (var i = 0; i < len; i++)
					{
						if(nds[i].nodeName == 'resort')
						{
							resorts.options[resorts.options.length] = new Option(nds[i].getAttribute("name"), nds[i].getAttribute("value"));
						}
					}
				}
				
				
				if (resorts.length > 1)
				{
					resorts.disabled = false;
					// If there is only one option, choose it
					if (resorts.length == 2 && (resorts.options[0].value == -1 || resorts.options[0].value == ''))
					{
						resorts.selectedIndex = 1;
					}
					// Repopulate if the option is in the list.
					else if (srhfrm.resortid && srhfrm && srhfrm.repop_srhfrm_resort && srhfrm.repop_srhfrm_resort.value) 
					{
						srhfrm.resortid.value = srhfrm.repop_srhfrm_resort.value;
					}
				}
				else
				{
					resorts.disabled = true;
					srhfrm_fill_dropdown('srhfrm_accomm', new Array({'value': '', 'display': laquo+' Any '+raquo}), 0);
				}
				srhfrm_update_accomm(srhfrm);
			}
		}
		xmlhttprequest.open('GET', '/fetch_opts.php?mode=resorts&airport_to_id='+airport_to_id, true);
		xmlhttprequest.send(null);
		srhfrm_save_values(srhfrm);
	}
	
	function srhfrm_update_accomm(srhfrm, old_accomm)
	{
		var select_element = srhfrm.property_id;
		srhfrm_save_values(srhfrm);
		if (!select_element) { return true; }
		if (!old_accomm)
		{
			old_accomm = select_element.value;
		}
		srhfrm_fill_dropdown('srhfrm_accomm', new Array({'value': '', 'display': 'Loading...'}), 0);
		var xmlhttprequest = create_xml_http_request();
			
		// Resort dd set based
		if (srhfrm['resort_dd[1]'] || srhfrm['resort_dd[2]'])
		{
			for (var i = 5; i > 0; i--)
			{
				if (srhfrm['resort_dd[' + i + ']'] 
					&& srhfrm['resort_dd[' + i + ']'].selectedIndex
					&& srhfrm['resort_dd[' + i + ']'].selectedIndex != -1 // Aparently IE thinks -1 is a natural number
					&& srhfrm['resort_dd[' + i + ']'][srhfrm['resort_dd[' + i + ']'].selectedIndex]
					&& srhfrm['resort_dd[' + i + ']'][srhfrm['resort_dd[' + i + ']'].selectedIndex].value 
					&& srhfrm['resort_dd[' + i + ']'][srhfrm['resort_dd[' + i + ']'].selectedIndex].value != -1
					&& srhfrm['resort_dd[' + i + ']'][srhfrm['resort_dd[' + i + ']'].selectedIndex].value != "-1,null"
				)
				{
					var param = 'resort_dd_id='+srhfrm['resort_dd[' + i + ']'][srhfrm['resort_dd[' + i + ']'].selectedIndex].value;
					break;
				}
			}
			if (!param)
			{
				srhfrm_fill_dropdown('srhfrm_accomm', new Array({'value': '', 'display': laquo+' Any '+raquo}), 0);
				return true;
			}
		}
		// Airport group set based
		else if (document.getElementById('srhfrm_resort') 
			&& document.getElementById('srhfrm_resort').value 
			&& document.getElementById('srhfrm_resort').value != -1)
		{
			var param = 'region_id=' + document.getElementById('srhfrm_resort').value;
		}
		else if (document.getElementById('srhfrm_destination_airport') 
			&& document.getElementById('srhfrm_destination_airport').value 
			&& document.getElementById('srhfrm_destination_airport').value != -1)
		{
			var param = 'airport_to_id=' + document.getElementById('srhfrm_destination_airport').value;
		}
		else if (document.getElementById('srhfrm_destination_airport_combined') 
				 && document.getElementById('srhfrm_destination_airport_combined').value
				 && document.getElementById('srhfrm_destination_airport_combined').value != -1)
		{
			var param = 'airport_to_id=' + document.getElementById('srhfrm_destination_airport_combined').value;
		}
		else
		{
			// No destination - Don't get accomm 
			srhfrm_fill_dropdown('srhfrm_accomm', new Array({'value': '', 'display': laquo+' Any '+raquo}), 0);
			return true;
		}
		
		xmlhttprequest.onreadystatechange = function()
		{
			if(xmlhttprequest.readyState == 4 && xmlhttprequest.status == 200)
			{
				var doc = xmlhttprequest.responseXML;
				var root = doc.documentElement;
				var accomm = document.getElementById('srhfrm_accomm');
				if ( ! accomm )
				{
					return false;
				}
				accomm.options.length = 0;
				var nds;		
						
				if(root.hasChildNodes()) 
				{
					nds=root.childNodes;
					var len = nds.length;
					for (var i = 0; i < len; i++)
					{
						
						if(nds[i].nodeName == 'AccommItem')
						{
							accomm.options[accomm.options.length] = new Option(nds[i].getAttribute("name"), nds[i].getAttribute("value"));
						}
					}
				}
	
				accomm.disabled = false;
				// Repopulate if the option is in the list.
				if (old_accomm)
				{
					accomm.value = old_accomm;
				}
				else if (srhfrm.repop_srhfrm_accomm && srhfrm.repop_srhfrm_accomm.value) 
				{
					// TODO: jquery would probably handle this nastyness better,
					//       but we're not currently dependent on jquery

					// In most browers, if value is not in the select list then the
					//  first option ("< any >") will be selected.
					accomm.value = srhfrm.repop_srhfrm_accomm.value;
					if (!accomm.value)
					{
						// In IE we need to explictly reset it to "< any >".
						accomm.value = '';
					}
				}
			}
		}
		xml_url = '/fetch_opts.php?mode=accomm&'+param;
		if (srhfrm.rating && srhfrm.rating.value)
		{
			xml_url += '&min_rating='+srhfrm.rating.value;
		}
		xmlhttprequest.open('GET', xml_url, true);
		xmlhttprequest.send(null);
		// srhfrm_save_values(srhfrm);
	}
	
	function srhfrm_fill_dropdown(dropdown_id, options, keep_first)
	{
		var select_element = document.getElementById(dropdown_id);
		
		if (!select_element) { return true; }
		
		// Clear out elements (if keepFirst is 1, the first item, probably "Any", will be kept)
		select_element.length = keep_first
		
		for (var i = 0; i < options.length; i++)
		{
			select_element.options[i] = new Option(options[i]['display'], options[i]['value']);
		}
		if (options.length <= 1)
		{
			select_element.disabled = true;
		}
		else
		{
			select_element.disabled = false;
		}
		
		select_element.selectedIndex = 0; // Make sure we have a sensible item selected (IE defaults to -1!)
	}
	
	function srhfrm_update_children(srhfrm)
	{
		var total_children = 0; 
		if (document.getElementById('srhfrm_num_rooms'))
		{
			var selected_rooms = document.getElementById('srhfrm_num_rooms').value;
		}
		else
		{
			var selected_rooms = 1;
		}

		if (document.getElementById('srhfrm_children'))
		{
			total_children = parseInt(document.getElementById('srhfrm_children').value);
		}
		else
		{
			for (var j = 1; j <= selected_rooms; j++)
			{
				total_children = total_children + parseInt(document.getElementById('srhfrm_children_' + j).value);
			}
		}
		
		for (var i = 1; i <= cfgMaxChildren; i++)
		{
			if (document.getElementById('srhfrm_child_' + i + '_row'))
			{
				if (i <= total_children)
				{
					// Set display to inherit value from parent because IE needs block and Moz needs table-row
					document.getElementById('srhfrm_child_' + i + '_row').style.display = '';
				}
				else if (document.getElementById('srhfrm_child_' + i))
				{
					document.getElementById('srhfrm_child_' + i + '_row').style.display = 'none';
					document.getElementById('srhfrm_child_' + i).value = '';
				}
			}
		}
		srhfrm_save_values(srhfrm);
	}
	
	function srhfrm_update_rooms_rows(srhfrm)
	{
		for (var i = 1; i <= cfgMaxRooms; i++)
		{
			if (document.getElementById('srhfrm_room_' + i + '_row'))
			{
				if (srhfrm.numrooms && 
					i <= srhfrm.numrooms.value)
				{
					// Set display to inherit value from parent because IE needs block and Moz needs table-row
					document.getElementById('srhfrm_room_' + i + '_row').style.display = '';
				}
				else if (document.getElementById('srhfrm_room_' + i + '_row'))
				{
					document.getElementById('srhfrm_room_' + i + '_row').style.display = 'none';
				}
			}
		}
		srhfrm_update_children(srhfrm);
		srhfrm_save_values(srhfrm);
	}
	
	function srhfrm_highlight_required(srhfrm)
	{
		for (var i = 0; i < required_fields.length; i++)
		{
			if ( eval('srhfrm.' + required_fields[i]) )
			{
				if (eval('srhfrm.' + required_fields[i]).value && eval('srhfrm.' + required_fields[i]).value != -1)
				{
					eval('srhfrm.' + required_fields[i]).className = 'srhfrm_dropdown';
				}
				else
				{
					eval('srhfrm.' + required_fields[i]).className = 'srhfrm_dropdown srhfrm_required';
				}
			}
		}
	}
	
	function srhfrm_save_rating_value(srhfrm)
	{
		if(document.getElementById('srhfrm_rating').value 
		   && document.getElementById('srhfrm_rating').value != -1)
		   {
			  srhfrm_save_values(srhfrm);
		   }
	}
	
	function srhfrm_save_board_value(srhfrm)
	{
		if(document.getElementById('srhfrm_board_basis').value 
		   && document.getElementById('srhfrm_board_basis').value != -1)
		   {
			   srhfrm_save_values(srhfrm)
		   }
	}
	
	function srhfrm_save_property_value(srhfrm)
	{
		if(document.getElementById('srhfrm_accomm').value 
		   && document.getElementById('srhfrm_accomm').value != -1)
		   {
			   srhfrm_save_values(srhfrm)
		   }
	}
	
	// Store form values in a cookie for when user clicks 'back'
	function srhfrm_save_values(objForm)
	{
		/* General Params */
		var cookieString = '';
		
		if(objForm.departure_monthyear && objForm.departure_day)
		{
			cookieString += 'general_params,departure_date,' 
				+ objForm.departure_monthyear.value + '-' + objForm.departure_day.value + '|';
		}
		else if(objForm.departure)
		{
			cookieString += 'general_params,departure_date,' + objForm.departure.value + '|';
		}
		
		var resort_dd_ids = '';
		for (var i = 1; objForm['resort_dd['+i+']']; i++)
		{
			if (resort_dd_ids) { resort_dd_ids += ','; }
			resort_dd_ids += objForm['resort_dd['+i+']'].value.substr(0, objForm['resort_dd['+i+']'].value.indexOf(','));
		}
		if (resort_dd_ids) { cookieString += 'general_params,resort_dd_ids,' + resort_dd_ids + '|'; }
		
		if(objForm.duration) 		{ cookieString += 'general_params,duration,' + objForm.duration.value + '|'; }
		
		/* Flight Section */
		var airportfromgroup, airportfrom;
		if ( objForm.airportcombinedfromid )
		{
			var fromairports = objForm.airportcombinedfromid.value.split('|');
			if( fromairports.length == 1 )
			{
				airportfromgroup = fromairports[0];
				airportfrom = undefined;
			}
			else
			{
				airportfromgroup = undefined;
				airportfrom = fromairports[1];
			}
		}
		else
		{
			if(objForm.airportgroupfromid) 	{ airportfromgroup = objForm.airportgroupfromid.value; }
			if(objForm.airportfromid) 	{ airportfrom = objForm.airportfromid.value; }
		}
		if(airportfromgroup) 		{ cookieString += 'flight,airport_group_from_id,' + airportfromgroup + '|'; }
		if(airportfrom)			{ cookieString += 'flight,airport_from_id,' + airportfrom + '|'; }
		
		var airporttogroup, airportto;
		if ( objForm.airportcombinedtoid )
		{
			var toairports = objForm.airportcombinedtoid.value.split('|');
			if( toairports.length == 1 )
			{
				airporttogroup = toairports[0];
				airportto = undefined;
			}
			else
			{
				airporttogroup = undefined;
				airportto = toairports[1];
			}
		}
		else
		{
			if(objForm.airportgrouptoid) 	{ airporttogroup = objForm.airportgrouptoid.value; }
			if(objForm.airporttoid) 	{ airportto = objForm.airporttoid.value; }
		}
		if(airporttogroup) 		{ cookieString += 'flight,airport_group_to_id,' + airporttogroup + '|'; }
		if(airportto) 			{ cookieString += 'flight,airport_to_id,' + airportto + '|'; }
		
		/* Accommodation Section */
		if(objForm.resorttoid) 		{ cookieString += 'accommodation,resort_id,' + objForm.resorttoid.value + '|'; }
		if(objForm.boardbasis) 		{ cookieString += 'accommodation,board_code,' + objForm.boardbasis.value + '|'; }
		if(objForm.rating) 		{ cookieString += 'accommodation,rating,' + objForm.rating.value + '|'; }
		
		/* Occupancy Section */
		if(objForm.numrooms) 		{ cookieString += 'occupancy,num_rooms,' + objForm.numrooms.value + '|'; }
		if(objForm.adults) 		{ cookieString += 'occupancy,adults,' + objForm.adults.value + '|'; }
		if(objForm.infants)		{ cookieString += 'occupancy,infants,' + objForm.infants.value + '|'; }
		if(objForm.children)
		{
			if (objForm.children.value == 0)
			{
				cookieString += 'occupancy,childages,undefined|';
			}
			else
			{
				for (i = 1; objForm['child'+i]; i++)
				{
					if (i <= objForm.children.value)
					{
						if(i == 1)
						{
							childages = objForm['child'+i].value;
						}
						else
						{
							childages += ","+objForm['child'+i].value;
						}
					}
				}
				if (childages)
				{
					cookieString += 'occupancy,childages,' + childages + '|';
				}
			}
		}
		
		if (objForm.show_only_direct)
		{
			cookieString += 'flight,show_only_direct,' + objForm.show_only_direct.value + '|';
		}
		
		document.cookie = 'SearchFormValues=' + encodeURIComponent(cookieString) + '; path=/';
		return true;
	}
	
	function srhfrm_update_return(srhfrm)
	{
		srhfrm_save_values(srhfrm);

		if (document.getElementById("srhfrm_duration") == null 
			|| document.getElementById("srhfrm_departure_date") == null
			|| document.getElementById("srhfrm_return_text") == null)
		{
			
			return;
		}
		
		var duration = document.getElementById("srhfrm_duration").value.split("-");
		var deps = document.getElementById("srhfrm_departure_date").value.split("-");
		var return_text = document.getElementById("srhfrm_return_text");
					
		// Add extra 12 hours so we are always looking midday - avoids problems with Daylight Saving changes.
		var departure = new Date(deps[0], deps[1] - 1, deps[2], 12);
		var checkout = new Date(departure.getTime() + (duration[0] * 1000 * 60 * 60 * 24));
							
		var datestring = checkout.toDateString();
		
		// Not sure why, but this regex doesn't seem to have any effect, so using split() instead.
		 datestring = datestring.replace(/^(\w{3})\s(\w{3})\s(\d{1,2})(.*)/, "$1, $3 $2$4");

		return_text.innerHTML = datestring;
		 
		//var datearray = datestring.split(' ');
		//return_text.innerHTML = datearray[0] + ', ' + datearray[2] + ' ' + datearray[1] + ' ' + datearray[3];
	}
	
	function srhfrm_validate(srhfrm)
	{
		var errors = new Array();
					
		for (var i = 0; i < required_fields.length; i++)
		{
			if (srhfrm[required_fields[i]] && (!srhfrm[required_fields[i]].value || srhfrm[required_fields[i]].value == -1))
			{
				// Would be better not to hard code the field labels here.
				if (required_fields[i] == 'airportgroupfromid')
				{
					errors.push('Departure airport group');
				}
				else if (required_fields[i] == 'airportcombinedfromid' || required_fields[i] == 'airportfromid')
				{
					errors.push('Departure airport');
				}
				else if (required_fields[i] == 'airportgrouptoid')
				{
					errors.push('Destination airport group');
				}
				else if (required_fields[i] == 'airportcombinedtoid' || required_fields[i] == 'airporttoid')
				{
					errors.push('Destination airport');
				}
				else 
				{
					errors.push(required_fields[i]);
				}
			}
		}
		
		if (srhfrm['resort_dd[1]'])
		{
			var selected_dropdown_is_searchable = false;
			var lowest_not_selected;
			for (var i = 1; i < 10; i++)
			{
				if (srhfrm['resort_dd['+i+']'])
				{
					// Negative substring indexes don't work in IE, so:
					if (srhfrm['resort_dd['+i+']'].value.substr(
						srhfrm['resort_dd['+i+']'].value.length - 4
					) == 'true')
					{
						selected_dropdown_is_searchable = true;
					}
					
					else if (
						!selected_dropdown_is_searchable
						&& !lowest_not_selected
						&& srhfrm['resort_dd['+i+']'].value
						&& srhfrm['resort_dd['+i+']'].value.substr(0, 2) == '-1'
					)
					{
						lowest_not_selected = i;
						errors.push(srhfrm['dd_'+i+'_label'].value);
					}
				}
				else
				{
					break;
				}
			}
		}
		
		// Check that ages have been entered for all children specified.
		if (srhfrm['children'] && srhfrm['children'].value > 0)
		{
			for (var i = 1; i <= srhfrm['children'].value; i++)
			{
				
				if (srhfrm['child' + i])
				{
					if (isNaN(parseInt(srhfrm['child' + i].value, 10)))
					{
						if (srhfrm['children'].value == 1)
						{
							errors.push('Child age');
						}
						else
						{
							errors.push('Child ' + i + ' age');
						}
					}
					else if (parseInt(srhfrm['child' + i].value, 10) < 2)
					{
						if (srhfrm['children'].value == 1)
						{
							errors.push('Child is under minimum age.');
						}
						else
						{
							errors.push('Child ' + i + ' is under minimum age.');
						}
					}
					else if (parseInt(srhfrm['child' + i].value, 10) >= 18)
					{
						if (srhfrm['children'].value == 1)
						{
							errors.push('Child is over maximum age.');
						}
						else
						{
							errors.push('Child ' + i + ' is over maximum age.');
						}
					}
				}
			}
		}
		
		if ( typeof srhfrm_validate_callback == 'function' )
		{
			srhfrm_validate_callback(errors);
		}
		
		if (errors.length > 0)
		{
			error_message = 'Please enter or correct the following information:\n';
			for (var j = 0; j < errors.length; j++)
			{
				error_message += '\n' + errors[j];
			}
			alert(error_message);
			return false;
		}
		else
		{
			return true;
		}
	}
	
	function duration_display(flight_type, srhfrm)
	{
		duration_row = document.getElementById('srhfrm_duration_row');
		duration = document.getElementById('srhfrm_duration');
		one_way_departures = document.getElementById('onewaydepartures');
		normal_departures = document.getElementById('normaldepartures');
		one_way_select_field = document.getElementById('srhfrm_one_way_departure_airport');
		
		normal_departures_field = document.getElementById('srhfrm_departure_airport');
		
		var str_one_way_dep = one_way_select_field.value;
		
		if(flight_type.value == 'one_way')
		{
			duration_row.style.display = 'none';
			duration.value = "-1";
			one_way_departures.style.display = '';
			normal_departures.style.display = 'none';
			one_way_select_field.style.display = '';
			// Set value to that of normal departures field
			one_way_select_field.value = "|" + normal_departures_field.value;
		}
		else
		{
			duration_row.style.display = '';
			duration.value = "7-7";
			one_way_departures.style.display = 'none';
			normal_departures.style.display = '';
			one_way_select_field.style.display = 'none';
			
			normal_departures_field.value = str_one_way_dep.replace('|', '');
		}
		
		// update destination fields
		srhfrm_update_destination_airport_groups(srhfrm);
	}

	function srhfrm_save_cookie(srhfrm)
	{
		var cookie_values = new Array();
		for (var i = 0; i < srhfrm.elements.length; i++)
		{
			cookie_values.push(srhfrm[i].name + '=' + srhfrm[i].value);
		}
		var cookie_name = 'srhfrm_' + srhfrm['search_id'];
		document.cookie=cookie_name + "=" +escape(cookie_values.join('|'));
	}

