var globalFromlist
var globalTolist
var globalFromlistOB
var globalTolistOB
var globalFromlistIB
var globalTolistIB


var FromTxtValue = ''
var ToTxtValue = ''

var fromTextBoxTextValue = '';
var toTextBoxTextValue = '';
var fromTextBoxTextValueOB = '';
var toTextBoxTextValueOB = '';
var fromTextBoxTextValueIB = '';
var toTextBoxTextValueIB = '';

function PrepareMultiBoxArray(ElemArr)
{
	TheArray = ElemArr.split('*')
	longeur = TheArray.length-1
	TheNodeList = new Array(longeur)
	for (i=0; i < longeur; i++) { TheNodeList[i] = new Array(2) }
	for (c=0;c<longeur;c++)
	{
		TheParts = TheArray[c].split('#')
		TheNodeList[c][0] = TheParts[0]
		TheNodeList[c][1] = TheParts[1]
		TheNodeList[c][2] = TheParts[2]
		TheNodeList[c][3] = TheParts[3]
	}
	
	return(TheNodeList)
}

var oFromTextbox
var oToTextbox
var oFromTextboxOB
var oToTextboxOB
var oFromTextboxIB
var oToTextboxIB


function InitFromBox(isShowAll, type)
{
	//document.getElementById("FromTxtFld").value = fromTextBoxTextValue;
	oFromTextbox = new AutoSuggestControl(document.getElementById("FromTxtFld"), new StateSuggestions(globalFromlist), 'TFW', type);
}

function InitToBox(isShowAll, type)
{
	//document.getElementById("ToTxtFld").value = toTextBoxTextValue;
	oToTextbox = new AutoSuggestControl(document.getElementById("ToTxtFld"), new StateSuggestions(globalTolist), 'TFW', type);      
}

function InitOBFromBox(isShowAll, type)
{
	oFromTextboxOB = new AutoSuggestControl(document.getElementById("FromTxtFldOB"), new StateSuggestions(globalFromlistOB), 'TFW', type);
}

function InitOBToBox(isShowAll, type)
{
	oToTextboxOB = new AutoSuggestControl(document.getElementById("ToTxtFldOB"), new StateSuggestions(globalTolistOB), 'TFW', type);      
}

function InitIBFromBox(isShowAll, type)
{
	oFromTextboxIB = new AutoSuggestControl(document.getElementById("FromTxtFldIB"), new StateSuggestions(globalFromlistIB), 'TFW', type);
}

function InitIBToBox(isShowAll, type)
{
	oToTextboxIB = new AutoSuggestControl(document.getElementById("ToTxtFldIB"), new StateSuggestions(globalTolistIB), 'TFW', type);      
}


function StateSuggestions(ListToLoad) {
	this.List = ListToLoad	
}


/**
 * Request suggestions for the given autosuggest control. 
 * @scope protected
 * @param oAutoSuggestControl The autosuggest control to provide suggestions for.
 */

 
StateSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl,bTypeAhead, ShowAll) {
	var aSuggestions = [];
	var dSuggestions = [];
	var compSuggestions = [];
	this.sTextboxValue = oAutoSuggestControl.textbox.value;
	this.bTypeAhead = bTypeAhead
	this.ShowAll = ShowAll
	var id
	
	//get the list if at least 3 char are entered
	
	if ((this.sTextboxValue.length >= 0 || ShowAll))
	{
		var id = 0;
		for (var i=0; i < this.List.length; i++) 
		{ 
			currelemName = this.List[i][1]
			//if(!ShowAll || ShowAll && currelemName.indexOf(':') == -1)
			{
				currelemDestinationCode = this.List[i][2]
				currelemRedirectURL = this.List[i][3]
				TxtfieldIndexOf = currelemName.toUpperCase().indexOf(this.sTextboxValue.toUpperCase())
				ShowAllValue = ShowAll;
			
				if (TxtfieldIndexOf >= 0 || ShowAll)
				{
					if (ShowAll)
						modcurrelem = '&#160;' + currelemName
					else
						modcurrelem = '&#160;' + currelemName.substring(0, TxtfieldIndexOf) + "<span id=searchText" + id + " class=searchText>" + this.sTextboxValue + "</span>" + currelemName.substring(TxtfieldIndexOf + this.sTextboxValue.length, currelemName.length )
					
					aSuggestions.push([modcurrelem]);
					/* Non formatted hotel list */
					dSuggestions.push([currelemName]);
					compSuggestions.push([currelemName, currelemRedirectURL, currelemDestinationCode]);
					id++
				}
			}
	    }
				
		oAutoSuggestControl.autosuggest(aSuggestions, dSuggestions, compSuggestions, false);
		
    }
	
	else
		oAutoSuggestControl.hideSuggestions();
}

function ShowFullFromList()
{	
	
	
	if(oFromTextbox.layer.style.visibility == 'hidden')
	{
		document.getElementById("FromTxtFld").focus()
		//document.getElementById("FromTxtFld").value = ''
		fromTextBoxTextValue = ''
			
		//InitFromBox();

		oFromTextbox.provider.requestSuggestions(oFromTextbox, true, true);

	}
	else
		oFromTextbox.hideSuggestions()
	
}

function ShowFullToList()
{
	if(oToTextbox.layer.style.visibility == 'hidden')
	{
		document.getElementById("ToTxtFld").focus()
		//document.getElementById("ToTxtFld").value = ''
		toTextBoxTextValue = ''
		//InitToBox();
		oToTextbox.provider.requestSuggestions(oToTextbox, true, true);
	}
	else
		oToTextbox.hideSuggestions()
}

function ShowFullFromListOB()
{	
		
	if(oFromTextboxOB.layer.style.visibility == 'hidden')
	{
		document.getElementById("FromTxtFldOB").focus()
					
		//InitFromBox();

		oFromTextboxOB.provider.requestSuggestions(oFromTextboxOB, true, true);

	}
	else
		oFromTextboxOB.hideSuggestions()
	
}

function ShowFullToListOB()
{
	if(oToTextboxOB.layer.style.visibility == 'hidden')
	{
		document.getElementById("ToTxtFldOB").focus()
		
		//InitToBox();
		oToTextboxOB.provider.requestSuggestions(oToTextboxOB, true, true);
	}
	else
		oToTextboxOB.hideSuggestions()
}

function ShowFullFromListIB()
{	
		
	if(oFromTextboxIB.layer.style.visibility == 'hidden')
	{
		document.getElementById("FromTxtFldIB").focus()
					
		//InitFromBox();

		oFromTextboxIB.provider.requestSuggestions(oFromTextboxIB, true, true);

	}
	else
		oFromTextboxIB.hideSuggestions()
	
}

function ShowFullToListIB()
{
	if(oToTextboxIB.layer.style.visibility == 'hidden')
	{
		document.getElementById("ToTxtFldIB").focus()
		
		//InitToBox();
		oToTextboxIB.provider.requestSuggestions(oToTextboxIB, true, true);
	}
	else
		oToTextboxIB.hideSuggestions()
}

function SelectAutoSuggestElem(params, selElemType, selElemValue, type)
{
	if (selElemType == "FromTxtFld"){
		fromTextBoxTextValue = selElemValue;
	}
	if (selElemType == "ToTxtFld"){
		toTextBoxTextValue = selElemValue;
	}
	if (selElemType == "FromTxtFldOB"){
		fromTextBoxTextValueOB = selElemValue;
	}
	if (selElemType == "ToTxtFldOB"){
		toTextBoxTextValueOB = selElemValue;
	}
	if (selElemType == "FromTxtFldIB"){
		fromTextBoxTextValueIB = selElemValue;
	}
	if (selElemType == "ToTxtFldIB"){
		toTextBoxTextValueIB = selElemValue;
	}
	
	var cleanParams = params.replace(/&amp;/g, '&')
	
	
	ChangeTFW(type, cleanParams)
}