	function initAutoComplete()
	{
		try
		{
			try{
				tbSettelment		= document.getElementById(tbSettelment_ID);								
				}
			catch(e){}	

			if (!tbSettelment)
			{
				setTimeout("initAutoComplete()",500);	
			}
		}
		catch (e)
		{
			//alert("initAutoComplete(): " + e.description);
		}			
	}	

	//Ajax server call back.
	function GetCities_Callback(res)
	{
		try
		{
			if (res != "")
			{				
				hasSettelments = true;
				ac.divChangePosition(true);
				ac.divInnerHTML(res);
			}
			else
			{
				hasSettelments = false;
				selectSettelment = false;
				ac.divChangePosition(false);
			}
		}
		catch (e)
		{
			//alert("GetCities_Callback: " + e.description);
		}
	}

	function doOnClick(e)
	{		
		
		try
		{
			//Update the current event.
			ac.assignEvent(e);				
			
			//Check witch object call this function.
			switch (ac.object.id)
			{
				case tbSettelment_ID:
					ac.divShow(false);
					return;

				case lbCities_ID:
					doSelectSettelment();
					return;
			}
		}
		catch (ex)
		{
			//alert("doOnClick Error: " + ex.description);
		}							
	}

	//Handles on key events.
	function doOnKeyUp(e)
	{			
		try
		{
			//Update the current event.
			ac.assignEvent(e);			
			//Check which object call this function.
			switch (ac.object.id)
			{
				case tbSettelment_ID:
					hasSettelments		= false;
					selectSettelment	= false;					
					ac.activateTimer("GetCities(escape(tbSettelment.value), DELIVERY_DEST, LANG)", acDelay);
					break;
			}
			
			return false;
		}
		catch (ex)
		{
			//alert("doOnKeyUp Error: " + ex.description);    
		}
	}

	//Handles on key down events.
	function doOnKeyDown(e)
	{		
		try
		{
			//Update the current event.
			ac.assignEvent(e);			
						
			//Check witch object call this function.
			switch (ac.object.id)
			{				
				case tbSettelment_ID:
					return TB_SettelmentsKeyDown();

				case lbCities_ID:
					return LB_SettelmentsKeyDown();
			}

			return true;			
		}
		catch (ex)
		{
			//alert("doOnKeyDown Error: " + ex.description);
		}
	}
	
	//Happens when pressing settelments textbox.
	function TB_SettelmentsKeyDown()
	{
		try
		{
			if ({9:1, 40:1}[ac.keyCode])
			{				
				if (hasSettelments)				
					jumpToListBox(lbCities_ID);
			}
		}
		catch (e)
		{
			//alert("TB_SettelmentsKeyDown: " + e.description);
		}		
	}

	//Happens when pressing on settelments list box.
	function LB_SettelmentsKeyDown()
	{
		try
		{
			if ({9:1, 13:1}[ac.keyCode] && hasSettelments)
			{
				doSelectSettelment();
				return false;
			}
		}
		catch (e)
		{
			//alert("LB_SettelmentsKeyDown: " + e.description);
		}	
	}
	
	function doSelectSettelment()
	{
		ac.event.returnValue = false;
		selectSettelment = true;
		fiilCityTextbox();
		getCityValue();
	}
	
	function jumpToListBox(listBoxID)
	{
		try
		{	
			//Get the cities select box.
			var listBox = document.getElementById(listBoxID);

			//If cities select box exists, set focus on it.
			if (listBox != null)
			{
				ac.event.returnValue = false;
				listBox.focus();
				listBox.options[0].selected = true;			
			}
		}
		catch (e)
		{
			//alert("jumpToListBox: " + e.description);			
		}	
	}
	
	function fiilCityTextbox()
	{
		try
		{
			ac.event.returnValue = false;
			ac.divShow(false);
			
			//Get the city name and attach it to Settelments textbox.
			TB_AutoComplete1_Text = ac.object.options[ac.object.selectedIndex].text;
			
			//Get the city ID.
			TB_AutoComplete1_Value	 = ac.object.options[ac.object.selectedIndex].value;
			
			//If successfuly get the city, attach it to textbox.
			if (TB_AutoComplete1_Text != "" && TB_AutoComplete1_Text != null)
				tbSettelment.value = TB_AutoComplete1_Text;	
		}
		catch (e)
		{
			//alert("fiilCityTextbox: " + e.description);	
		}				
	}
	
	function getCityValue()
	{
		GetDeliveryPrice(TB_AutoComplete1_Value);
	}
	
	function GetDeliveryPrice_Callback(res)
	{
		
		/*var elem = document.getElementById('hiddenCost')
		elem.innerHTML = res;
		
		elem.style.display = 'block';*/
		getDeliverydata(res);
	}

