var tripOptionList = 
[	// list of Trip Options
	['1',tripType_1,	// for Single Trip
		[	// list of Destinations
			['3',destination_3,	// for Europe
				null,	// list of duration
				[	// list of Age Bands
					['29',ageBand_29,
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['39',ageBand_39,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['49',ageBand_49,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['59',ageBand_59,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['69',ageBand_69,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['79',ageBand_79,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['17',ageBand_17,		
						[['3',insuredGroup_3]]	// list of Insured Groups
					]
				]
			],
			['4',destination_4,	// for World wide excluding N. America
				null,	// list of duration
				[	// list of Age Bands
					['29',ageBand_29,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['39',ageBand_39,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['49',ageBand_49,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['59',ageBand_59,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['69',ageBand_69,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['79',ageBand_79,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['17',ageBand_17,		
						[['3',insuredGroup_3]]	// list of Insured Groups
					]
				]
			],
			['5',destination_5,	// for World wide including N. America
				null,	// list of duration
				[	// list of Age Bands
					['29',ageBand_29,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['39',ageBand_39,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['49',ageBand_49,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['59',ageBand_59,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['69',ageBand_69,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['17',ageBand_17,		
						[['3',insuredGroup_3]]	// list of Insured Groups
					]
				]
			]
		]
	],
	['0',tripType_0,	// for Annual Trip
		[	// list of Destinations
			['3',destination_3,	// for Europe
				null,	// list of duration
				[	// list of Age Bands
					['29',ageBand_29,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['39',ageBand_39,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['49',ageBand_49,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['59',ageBand_59,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['65',ageBand_65,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['69',ageBand_669,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['79',ageBand_79,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['17',ageBand_17,		
						[['3',insuredGroup_3]]	// list of Insured Groups
					]
				]
			],
			['4',destination_4,	// for World wide excluding N. America
				null,	// list of duration
				[	// list of Age Bands
					['29',ageBand_29,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['39',ageBand_39,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['49',ageBand_49,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['59',ageBand_59,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['69',ageBand_69,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['17',ageBand_17,		
						[['3',insuredGroup_3]]	// list of Insured Groups
					]
				]
			],
			['5',destination_5,	// for World wide including N. America
				null,	// list of duration
				[	// list of Age Bands
					['29',ageBand_29,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['39',ageBand_39,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['49',ageBand_49,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['59',ageBand_59,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['69',ageBand_69,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['17',ageBand_17,		
						[['3',insuredGroup_3]]	// list of Insured Groups
					]
				]
			]
		]
	],
	['2',tripType_2,	// for Gap Cover
		[	// list of Destinations
			['3',destination_3,	// for Europe
				[
					['3',duration_3],
					['4',duration_4],
					['6',duration_6],
					['9',duration_9],
					['12',duration_12],
					['13',duration_13],
					['15',duration_15],
					['18',duration_18],
					['20',duration_20],
					['24',duration_24]
				],	// list of durations
				[	// list of Age Bands
					['29',ageBand_29,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['39',ageBand_39,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['49',ageBand_49,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
						['17',ageBand_17,		
						[['3',insuredGroup_3]]	// list of Insured Groups
					]
				]
			],
			['4',destination_4,	// for World wide excluding N. America
				[
					['3',duration_3],
					['4',duration_4],
					['6',duration_6],
					['9',duration_9],
					['12',duration_12]
					//['13',duration_13],
					//['15',duration_15],
					//['18',duration_18],
					//['20',duration_20],
					//['24',duration_24]
				],	// list of durations
				[	// list of Age Bands
					['29',ageBand_29,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['39',ageBand_39,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['49',ageBand_49,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					//['59',ageBand_59,		
					//	[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					//],
					//['65',ageBand_65,		
					//	[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					//],
					['17',ageBand_17,		
						[['3',insuredGroup_3]]	// list of Insured Groups
					]
				]
			],
			['5',destination_5,	// for World wide including N. America
				[
					['3',duration_3],
					['4',duration_4],
					['6',duration_6],
					['9',duration_9]
					//['12',duration_12],
					//['13',duration_13],
					//['15',duration_15],
					//['18',duration_18],
					//['20',duration_20],
					//['24',duration_24]
				],	// list of durations
				[	// list of Age Bands
					['29',ageBand_29,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['39',ageBand_39,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['49',ageBand_49,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					//['59',ageBand_59,		
					//	[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					//],
					//['65',ageBand_65,		
					//	[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					//],
					['17',ageBand_17,		
						[['3',insuredGroup_3]]	// list of Insured Groups
					]
				]
			]
		]
	],
	['4',tripType_4,	// for Annual Trip with WinterSports added bh Bhaskar
		[	// list of Destinations
			['3',destination_3,	// for Europe
				null,	// list of duration
				[	// list of Age Bands
					['29',ageBand_29,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['39',ageBand_39,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['49',ageBand_49,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['59',ageBand_59,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['65',ageBand_65,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['69',ageBand_669,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['79',ageBand_79,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['17',ageBand_17,		
						[['3',insuredGroup_3]]	// list of Insured Groups
					]
				]
			],
			['4',destination_4,	// for World wide excluding N. America
				null,	// list of duration
				[	// list of Age Bands
					['29',ageBand_29,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['39',ageBand_39,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['49',ageBand_49,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['59',ageBand_59,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['69',ageBand_69,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['17',ageBand_17,		
						[['3',insuredGroup_3]]	// list of Insured Groups
					]
				]
			],
			['5',destination_5,	// for World wide including N. America
				null,	// list of duration
				[	// list of Age Bands
					['29',ageBand_29,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['39',ageBand_39,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['49',ageBand_49,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['59',ageBand_59,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['69',ageBand_69,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['17',ageBand_17,		
						[['3',insuredGroup_3]]	// list of Insured Groups
					]
				]
			]
		]
	],
	['3',tripType_3,	// for Single Trip with WinterSports added by Bhaskar
		[	// list of Destinations
			['3',destination_3,	// for Europe
				null,	// list of duration
				[	// list of Age Bands
					['29',ageBand_29,
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['39',ageBand_39,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['49',ageBand_49,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['59',ageBand_59,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['69',ageBand_69,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['79',ageBand_79,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['17',ageBand_17,		
						[['3',insuredGroup_3]]	// list of Insured Groups
					]
				]
			],
			['4',destination_4,	// for World wide excluding N. America
				null,	// list of duration
				[	// list of Age Bands
					['29',ageBand_29,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['39',ageBand_39,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['49',ageBand_49,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['59',ageBand_59,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['69',ageBand_69,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['79',ageBand_79,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['17',ageBand_17,		
						[['3',insuredGroup_3]]	// list of Insured Groups
					]
				]
			],
			['5',destination_5,	// for World wide including N. America
				null,	// list of duration
				[	// list of Age Bands
					['29',ageBand_29,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['39',ageBand_39,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['49',ageBand_49,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['59',ageBand_59,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['69',ageBand_69,		
						[['0',insuredGroup_0],['1',insuredGroup_1],['2',insuredGroup_2]]	// list of Insured Groups
					],
					['17',ageBand_17,		
						[['3',insuredGroup_3]]	// list of Insured Groups
					]
				]
			]
		]
	]
]


function init(){
	document.getElementById('tripType').options.length = 0;
	document.getElementById('destination').options.length = 0;
	document.getElementById('duration').options.length = 0;
	document.getElementById('ageBand').options.length = 0;
	document.getElementById('insuredGroup').options.length = 0;
}
	
function populate(){
	for(tripIndex = 0;tripIndex < tripOptionList.length;tripIndex++){
		// creating trip options
		document.getElementById('tripType').options[tripIndex] = new Option(tripOptionList[tripIndex][1],tripOptionList[tripIndex][0]);
		var destinationList = tripOptionList[tripIndex][2];
		
		if(destinationList != null && selected[0] == tripOptionList[tripIndex][0]){
			// selecting the trip option
			document.getElementById('tripType').options[tripIndex].selected = true;
			for(destinationIndex = 0;destinationIndex < destinationList.length;destinationIndex++){
				// creating the destinations
				document.getElementById('destination').options[destinationIndex] = new Option(destinationList[destinationIndex][1],destinationList[destinationIndex][0]);
				var durationList = destinationList[destinationIndex][2];
				
				if(durationList != null && selected[1] == destinationList[destinationIndex][0]){
					for(durationIndex = 0;durationIndex < durationList.length;durationIndex++){
						// creating the durations
						document.getElementById('duration').options[durationIndex] = new Option(durationList[durationIndex][1],durationList[durationIndex][0]);
						if(selected[2] == durationList[durationIndex][0]){
							//selecting the duration
							document.getElementById('duration').options[durationIndex].selected = true;
						}
					}					
				}
				var ageBandList = destinationList[destinationIndex][3];
				
				if(ageBandList != null && selected[1] == destinationList[destinationIndex][0]){
					// selecting the destination
					document.getElementById('destination').options[destinationIndex].selected = true;
					for(ageBandIndex = 0;ageBandIndex < ageBandList.length;ageBandIndex++){
						// creating age bands
						document.getElementById('ageBand').options[ageBandIndex] = new Option(ageBandList[ageBandIndex][1],ageBandList[ageBandIndex][0]);
						var insuredGroupList = ageBandList[ageBandIndex][2];
						
						if(insuredGroupList != null && selected[3] == ageBandList[ageBandIndex][0]){
							// selecting the age band
							document.getElementById('ageBand').options[ageBandIndex].selected = true;
							for(insuredGroupIndex = 0;insuredGroupIndex < insuredGroupList.length;insuredGroupIndex++){
								// creating the insured groups
								document.getElementById('insuredGroup').options[insuredGroupIndex] = new Option(insuredGroupList[insuredGroupIndex][1],insuredGroupList[insuredGroupIndex][0]);
								if(selected[4] == insuredGroupList[insuredGroupIndex][0]){
									// selecting the insured group
									document.getElementById('insuredGroup').options[insuredGroupIndex].selected = true;
								}
							}
						}
					}
				}
			}
		}
	}
}


function setSelected(index, value){
	selected[index] = value;
}

function refreshList(index, value){
	setSelected(index, value);
	init();
	populate();	
	changeNoOfPeople();
}
function showAgeLabel(value){
var obj1 = document.getElementById("ageLabel1")
var obj2 = document.getElementById("ageLabel2")
if(value == 1 ||value == 3 ){ // modified by Bhaskar as part of SH134
obj1.style.visibility = 'hidden'
obj1.style.display = 'none'

obj2.style.display = ''
obj2.style.visibility = 'visible'
}else{
obj2.style.visibility = 'hidden'
obj2.style.display = 'none'

obj1.style.display = ''
obj1.style.visibility = 'visible'
}
}

function createNumberedOptions(select, start, count, selected, disabled){
	var value = start;
	for(index = 0;index < count;index++){
		select.options[index] = new Option(value,value);
		if(value == selected){
			select.options[index].selected = true;
		}
		value++;
	}	
	select.disabled = disabled;
}

function clearNoOfPeople(){
	document.getElementById("noOfAdults").options.length = 0;
	document.getElementById("noOfChildren").options.length = 0;
}

function changeNoOfPeople(init){

	var noOfAdults = document.getElementById("noOfAdults");
	var noOfChildren = document.getElementById("noOfChildren");
	
	var tripType = document.getElementById('tripType').value;
	var insuredGroup = document.getElementById('insuredGroup').value;	
	var adultStart = 0;
	var adultCount = 2;
	var adultSelected = 0;
	var adultDisabled = false;
	var childStart = 0;
	var childCount = 2;
	var childSelected = 0;
	var childDisabled = false;
	
	document.getElementById("premierPlusMessage").style.display = 'none';
	
	clearNoOfPeople()
	if(insuredGroup == '0'){	// Individuals
		childCount = 1;
		childDisabled = true;
		
		// commenting the special case for Single trip as all the trips will have the same behaviour
		
		/*
		if(tripType == '1'){	// Single
			adultCount = 11;
			adultSelected = 1;
			adultDisabled = false;
		} else if(tripType == '0' || tripType == '2'){	//Annual & Gap
		*/
			adultCount = 2;
			adultSelected = 1;
			adultDisabled = true;			
		//}
	} else if(insuredGroup == '1'){	// Individual and spouse
		childCount = 1;
		childDisabled = true	
		adultCount = 3;
		adultSelected = 2;
		adultDisabled = true;
	} else if(insuredGroup == '2'){	// Family
		if(tripType == '0'|| tripType == '4'){	// Annual or Annual WinetrSports as part of SH134
			document.getElementById("premierPlusMessage").style.display = 'block';
		}
		adultStart = 1;
		adultCount = 2;
		adultSelected = 2;
		adultDisabled = false;
		childDisabled = false;
		childStart = 1;
		if(tripType == '2'){ // to set max of 6 children for Gap Family
			childCount = 6;
		} else{	// to set max of 12 children for Single and Annual Family
			childCount = 12;
		}
	} else if(insuredGroup == '3'){	//children
		adultCount = 1;
		adultDisabled = true;
		childDisabled = false;
		childStart = 1;
		childCount= 1;
		childSelected = 1;		
	}
	if(init){
		adultSelected = selected[5];
		childSelected = selected[6];
	}
	createNumberedOptions(noOfAdults, adultStart, adultCount, adultSelected, adultDisabled);
	createNumberedOptions(noOfChildren, childStart, childCount, childSelected, childDisabled);
	selected[5] = adultSelected;
	selected[6] = childSelected;
}