

// ##### common


function rcAutoComplete_PrepareCitySearchAutoCompleteString(strText, objElement) {
	var strTextOriginal = strText;

	strText = strText.replace(/^\s*(.+)$/, "$1"); 
	strText = strText.replace(/\s+$/, " ");

	if(strTextOriginal != strText) {
		objElement.value = strText;
	}	
	return(strText);
};


// ##### for City

function rcAutoComplete_City_TipToString(oTip) {
	var strIcon = "";
	if(oTip.ty == "AIRPORT") {
		strIcon = rcAutoComplete_AirportOrCity_AirportIcon;
	}
	var strResult = strIcon + oTip.fdn;
	return(strResult);
};


function rcAutoComplete_City_TipToTextInput(oTip) {
	var strResult = oTip.fdn;
	return(strResult);
};



function rcAutoComplete_City_USE(strFieldIDs, strTheme, intSearchCharCount, intMaxListItems) {

	if(isNaN(intSearchCharCount) || intSearchCharCount < 3) {
		intSearchCharCount = 3;
	}

	var strUseTheme = strTheme;
	if(strTheme == null || String(strTheme) == "null" || String(strTheme) == "undefined" || strTheme == "") {
		strUseTheme = "pcln";
	} 
	strUseTheme = "/zp/zpautocomplete/themes/" + strUseTheme ;

	var arrIDs = strFieldIDs.split("\|");

	new Zapatec.PclnAutoComplete({

		fields: arrIDs,

		productID: 8,

		searchType: "city",

		searchBaseURL: rcAutoComplete_SearchBaseURL,

		dataOnDemand: true,

		// true if onBlur should assume/prepop item(0) if no item selected
		prepopFirstItemOnBlur: false,

		theme: strUseTheme,

		overflow: "auto",

		maxListItems: intMaxListItems,

		searchOnCharacterCount: intSearchCharCount,

		convertTipToTextInput: rcAutoComplete_City_TipToTextInput,

		getTipFilterString: rcAutoComplete_City_TipToTextInput,
		
		prepareAutoCompleteStringFunc:  rcAutoComplete_PrepareCitySearchAutoCompleteString,

		convertTip: rcAutoComplete_City_TipToString

	});

}



// ##### for Airport or City

function rcAutoComplete_AirportOrCity_TipToString(oTip) {
	var strIcon = "";
	if(oTip.ty == "AIRPORT") {
		strIcon = rcAutoComplete_AirportOrCity_AirportIcon;
	}
	var strResult = strIcon + oTip.fdn;
	return(strResult);
};


function rcAutoComplete_AirportOrCity_TipToTextInput(oTip) {
	var strResult = oTip.fdn;
	return(strResult);
};



function rcAutoComplete_AirportOrCity_USE(strFieldIDs, strTheme, intSearchCharCount, intMaxListItems) {

	if(isNaN(intSearchCharCount) || intSearchCharCount < 3) {
		intSearchCharCount = 3;
	}
	var strUseTheme = strTheme;
	if(strTheme == null || String(strTheme) == "null" || String(strTheme) == "undefined" || strTheme == "") {
		strUseTheme = "pcln";
	} 
	strUseTheme = "/zp/zpautocomplete/themes/" + strUseTheme ;

	var arrIDs = strFieldIDs.split("\|");


	new Zapatec.PclnAutoComplete({

		fields: arrIDs,

		productID: 8,

		searchType: "cityOrAirport",

		searchBaseURL: rcAutoComplete_SearchBaseURL,


		dataOnDemand: true,

		// true if onBlur should assume/prepop item(0) if no item selected
		prepopFirstItemOnBlur: false,

		theme: strUseTheme,

		overflow: "auto",

		maxListItems: intMaxListItems,

		searchOnCharacterCount: intSearchCharCount,

		convertTipToTextInput: rcAutoComplete_AirportOrCity_TipToTextInput,

		getTipFilterString: rcAutoComplete_AirportOrCity_TipToTextInput,
		
		prepareAutoCompleteStringFunc:  rcAutoComplete_PrepareCitySearchAutoCompleteString,

		convertTip: rcAutoComplete_AirportOrCity_TipToString

	});

}


// legacy function name
function useCitySearchAjax_RENTALCARS(strFieldIDs, strTheme, intSearchCharCount, intMaxListItems) {
	rcAutoComplete_AirportOrCity_USE(strFieldIDs, strTheme, intSearchCharCount, intMaxListItems);
}




// ##### for Landmarks

function rcAutoComplete_Landmark_TipToString(oTip) {
	var strResult = oTip.fdn;
	return(strResult);
};


function rcAutoComplete_Landmark_TipToTextInput(oTip) {
	var strResult = oTip.fdn;
	return(strResult);
};



function rcAutoComplete_Landmark_USE(strFieldIDs, strTheme, intSearchCharCount, intMaxListItems) {

	if(isNaN(intSearchCharCount) || intSearchCharCount < 4) {
		intSearchCharCount = 4;
	}

	var strUseTheme = strTheme;
	if(strTheme == null || String(strTheme) == "null" || String(strTheme) == "undefined" || strTheme == "") {
		strUseTheme = "pcln";
	} 
	strUseTheme = "/zp/zpautocomplete/themes/" + strUseTheme ;

	var arrIDs = strFieldIDs.split("\|");


	new Zapatec.PclnAutoComplete({

		fields: arrIDs,

		productID: 8,

		searchType: "landmark",

		searchBaseURL: rcAutoComplete_SearchBaseURL,


		dataOnDemand: true,

		// true if onBlur should assume/prepop item(0) if no item selected
		prepopFirstItemOnBlur: false,

		theme: strUseTheme,

		overflow: "auto",

		maxListItems: intMaxListItems,

		searchOnCharacterCount: intSearchCharCount,

		convertTipToTextInput: rcAutoComplete_Landmark_TipToTextInput,

		getTipFilterString: rcAutoComplete_Landmark_TipToTextInput,
		
		prepareAutoCompleteStringFunc:  rcAutoComplete_PrepareCitySearchAutoCompleteString,

		convertTip: rcAutoComplete_Landmark_TipToString

	});

}


