/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject()
{
	var request_type;
	var browser = navigator.appName;
	
	if(browser == "Microsoft Internet Explorer") {	request_type = new ActiveXObject("Microsoft.XMLHTTP");	}
	else { 	request_type = new XMLHttpRequest();  }
	
	return request_type;
}
/* --------------------------------------- */
/* fill dropdown with localities of a city */
/* --------------------------------------- */

function getLocality()
{
	var http = createObject();
	var nocache = 0;
	// Use encodeURI() to solve some issues about character encoding.
	var cityID = encodeURI(document.getElementById('selCity').value);
	//var page_name = encodeURI(document.getElementById('page_name').value); 
	// Required: verify that filed is not empty.
	if(cityID != '')
	{
		// Optional: Show a waiting message in the layer with ID ajax_response
		document.getElementById('loc_wait').innerHTML = "<img src='images/ajax-loader.gif' height='16' width='16' alt='wait...'/>";
		// Set te random number to add to URL request
		nocache = Math.random();
		// Pass the uid variable like URL variable
		http.open('get', 'get_localities.php?ci='+cityID+'&nocache = '+nocache);
		http.onreadystatechange = function() 
		{
			if(http.readyState == 4)
			{
				var response = http.responseText;
				document.getElementById('loc_span').innerHTML = response;
				document.getElementById('loc_wait').innerHTML = '';
			}
		}
		http.send(null);
	}
}

/* ------------------------- */
/* edit localities of a city */
/* ------------------------- */
function editLocality(li)
{
	var http = createObject();
	var nocache = 0;
	// Use encodeURI() to solve some issues about character encoding.
	var cityID = encodeURI(document.getElementById('selCity').value); 
	// Required: verify that filed is not empty.
	if(cityID != '')
	{
		// Optional: Show a waiting message in the layer with ID ajax_response
		document.getElementById('loc_wait').innerHTML = "<img src='images/ajax-loader.gif' height='16' width='16' alt='wait...'/>";
		// Set te random number to add to URL request
		nocache = Math.random();
		// Pass the uid variable like URL variable
		http.open('get', 'edit_localities.php?ci='+cityID+'&li='+li+'&nocache = '+nocache);
		http.onreadystatechange = function() 
		{
			if(http.readyState == 4)
			{
				var response = http.responseText;
				document.getElementById('loc_span').innerHTML = response;
				document.getElementById('loc_wait').innerHTML = '';
			}
		}
		http.send(null);
	}
}
