var country;

function setupDropdown() {

    country = jQuery('#cboAdCountry');
	county = jQuery('#cboAdCounty');

	if (country != null)
	{
		country.change(PopulateCounty);
		//PopulateCounty();
	}

	if (county != null)
	{
		county.change(ShowCounty);
		//ShowCounty();
	}
};

function PopulateCounty()
{
	if (country == null)
		return;

	county.remove;
	//clearCombo (county);
	AddToOptionList (county, "0", "Loading...");

	AJAXrequest(countyUrl + '?c=' + jQuery('#cboAdCountry option:selected').val(), ajaxRet);
}

function ajaxRet(obj)
{
	if (obj.status == '200')
	{
		county.empty();
		//clearCombo (county);
		
		var html = obj.responseText;
		if (html != '')
		{
			var lines = html.split('\r\n');
			for (var i = 0; i < lines.length; i++)
			{
				if (lines[i] != '')
				{
					var opt = document.createElement("OPTION");
					var xx = lines[i].split(',');
					opt.value = xx[0];
					opt.text = xx[1];
							
					AddToOptionList (county, xx[0], xx[1]);
					
					if (i == 0)
					{
					    jQuery('regionText').innerText = xx[2];
					}
				}
			}
			if (!constrain)
				AddToOptionList (county, '0', ' Not in List');
		}
		else
		{
			if (!constrain)
				AddToOptionList (county, '0', ' Not in List');
            jQuery('regionText').innerText = 'Region';
		}
	}
	else
	{
		clearCombo (county);
		AddToOptionList (county, "-1", "Error loading regions");
		jQuery('regionText').innerText = 'Region';
	}
	
	//if ($('CountryContainer'))
	//{
	//	if (country.value == '0')
	//	{
	//		$('CountryContainer').style.display = 'block';
	//	}
	//	else
	//	{
	//		$('CountryContainer').style.display = 'none';
	//	}
	//}
		
	//ShowCounty();
}

function ShowCounty()
{
	//if (county == null)
	//	return;

	//if ($('CountyContainer'))
	//{
	//	if (county.value == '0')
	//	{
	//		$('CountyContainer').style.display = 'block';
	//	}
	//	else
	//	{
	//		$('CountyContainer').style.display = 'none';
	//	}
	//}
}
