
// smartDropDown.js
// -------------------------------------------------------------------------- \\


function smartDropDown_populate (Departure,language,defaultEndLocation){
	var j;
	// Empty destination dropdown
	this.cmpELoc.options.length = 0;
	// Special case of none ("Select an airport") is selected 
	if (Departure == "") {
		this.cmpELoc.options[0] = new Option (this.firstLine,"");
		this.cmpELoc.options[0].selectedIndex = 0;
		this.cmpELoc.options[0].selected = true;
		this.cmpELoc.selectedIndex = indexToSelect;
		return;
	}
	// Add first element of list (ex: -- Select an Airport --)
	if (this.firstLine == "") {
		j = 0;
	} else {
		j = 1;
		this.cmpELoc.options[0] = new Option (this.firstLine,"");
		this.cmpELoc.options[0].selectedIndex = 0;
	}
	// Add all other airport
	var lstLnk = this.lnk[Departure];
	var curDestCode;
	var indexToSelect = 0;
	while(lstLnk.length > 0) {
		curDestCode = lstLnk.substr(0,3);
		this.cmpELoc.options[j] = new Option (this.desc.lbl[curDestCode],curDestCode);
		this.cmpELoc.options[j].selectedIndex = j;
		if (defaultEndLocation!="" && curDestCode==defaultEndLocation) {
			indexToSelect=j;
		}
		j++;
		lstLnk = lstLnk.substr(3);
	}
	// Force selection of correct index
	this.cmpELoc.options[indexToSelect].selected = true;
	this.cmpELoc.selectedIndex = indexToSelect;
}

function smartDropDown_initializeDeparture(strFirstLine,nameCmpB,nameCmpE,language,previousBLocation,userBeginLocation,defaultBeginLocation,defaultEndLocation){
	this.firstLine=strFirstLine;
	this.cmpBLoc=document.getElementById(nameCmpB);
	this.cmpELoc=document.getElementById(nameCmpE);
	eval("this.desc = new desc"+language+"();");
	var j;	// Current position in list

	this.cmpBLoc.options.length = 0;
	// Add first element of list (ex: -- Select an Airport --)
	if (this.firstLine == "") {
		j = 0;
	} else {
		j = 1;
		this.cmpBLoc.options[0] = new Option(this.firstLine,"");
		this.cmpBLoc.options[0].selectedIndex = 0;
	}
	// Add all other airport
	var indexPreviousBLocation = -1;
	var indexUserBeginLocation = -1;
	var indexDefaultBeginLocation = -1;
	var indexToSelect = 0;
	for (var elem in this.lnk) {
		this.cmpBLoc.options[j] = new Option (this.desc.lbl[elem],elem);
		this.cmpBLoc.options[j].selectedIndex = j;
		if (elem == previousBLocation) indexPreviousBLocation = j;
		if (elem == userBeginLocation) indexUserBeginLocation = j;
		if (elem == defaultBeginLocation) indexDefaultBeginLocation = j;
		j++;
	}
	// Force selection of correct index
	if (indexDefaultBeginLocation != -1) indexToSelect = indexDefaultBeginLocation;
	if (indexUserBeginLocation != -1) indexToSelect = indexUserBeginLocation;
	if (indexPreviousBLocation != -1) indexToSelect = indexPreviousBLocation;
	this.cmpBLoc.options[indexToSelect].selected = true;
	this.cmpBLoc.selectedIndex = indexToSelect;
	this.populate(this.cmpBLoc.options[indexToSelect].value,language,defaultEndLocation);
}


