
function clearList(objList)
{
	for (var i = (objList.options.length - 1); i > 0; i --)
		objList.options[i] = null;
}

function updateTopicsList(iFlag)
{
	clearList($('Topic'));
	
	var iTypeId = $F("Type");
	
	if (iTypeId != "")
	{
		$("Topic").disable( );
		$('Processing').show( );
		
		var sUrl    = "ajax/jobs/get-topics-list.php"; 
		var sParams = ("TypeId=" + iTypeId + "&Flag=" + iFlag);
	
		new Ajax.Request(sUrl, { method:'post', parameters:sParams, onFailure:_showError, onSuccess:_updateTopicsList });
	}
	
	else
		$("Topic").enable( );
}

function _updateTopicsList(sResponse)
{
	if (sResponse.status == 200 && sResponse.statusText == "OK")
	{
		var sParams = sResponse.responseText.split('|-|');
		
		if (sParams[0] == "OK")
		{
			for (var i = 1; i < sParams.length; i ++)
			{			
				var sOption = sParams[i].split("||");
			
				$("Topic").options[i] = new Option(sOption[1], sOption[0], false, false);

			}

			$("Topic").enable( );
		}
			
		else
			_showError(sParams[1]);
			
		$('Processing').hide( );
	}
	
	else
		_showError( );
}

function updateCitiesList(iFlag)
{
	clearList($('City'));
	
	var iCountryId = $F("Country");
	
	if (iCountryId != "")
	{
		$("City").disable( );
		$('Processing').show( );
		
		var sUrl    = "ajax/jobs/get-cities-list.php"; 
		var sParams = ("CountryId=" + iCountryId + "&Flag=" + iFlag);
	
		new Ajax.Request(sUrl, { method:'post', parameters:sParams, onFailure:_showError, onSuccess:_updateCitiesList });
	}
	
	else
		$("City").enable( );
}

function _updateCitiesList(sResponse)
{
	if (sResponse.status == 200 && sResponse.statusText == "OK")
	{
		var sParams = sResponse.responseText.split('|-|');
		
		if (sParams[0] == "OK")
		{
			for (var i = 1; i < sParams.length; i ++)
				$("City").options[i] = new Option(sParams[i], sParams[i], false, false);

			$("City").enable( );
		}
			
		else
			_showError(sParams[1]);
			
		$('Processing').hide( );
	}
	
	else
		_showError( );
}
