var req;
var divid;
function ajaxInclude(id, url)
{
	divid = id;
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = writeContent;
		req.open("GET", url, true);
		req.send(null);

	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = writeContent;
			req.open("GET", url, true);
			req.send();

		}
	}
}

function writeContent()
{
	if (req.readyState == 4) {
		if (req.status == 200) {
			var response  = req.responseText;
			document.getElementById(divid).innerHTML = response;
		}
	}
}

function ajax_search(county, id)
{
	url = "city.php?county=" + county;
	ajaxInclude(id, url);
}

function ajax_advsearch(county, id)
{
	url = "adv_city.php?county=" + county;
	ajaxInclude(id, url);
}

/*
function addToList(availist, citylist) {
	for(i=0; i<availist.length; i++)
	{
		if(availist[i].selected)
		{
			flg = 0;
			for(j=0; j<citylist.length; j++)
			{
				if(availist[i].value == citylist[j].value)
				{
					flg = 1;
					break;
				}
			}
			if(flg == 0)
			{
				var len = citylist.length++; // Increase the size of list and return the size
				citylist.options[len].value = availist[i].value;
				citylist.options[len].text = availist[i].text;
			}
		}
	}
}	*/

function removeFromList(citylist) 
{
	var aryTempSourceOptions = new Array();
	var x = 0;
	var city_ary = new Array();

   	if ( citylist.length == -1) {  // If the list is empty
      	alert("There are no values which can be removed!");
   	} 
	else 
	{
		for (var i = 0; i < citylist.length; i++) 
		{
			if(! citylist.options[i].selected)
			{
				var objTempValues = new Object();
				objTempValues.text = citylist.options[i].text;
				objTempValues.value = citylist.options[i].value;
				aryTempSourceOptions[x] = objTempValues;
				x++;
			}
		}
		//resetting length of source
		citylist.length = aryTempSourceOptions.length;
		//looping through temp array to recreate source select element
		for (var i = 0; i < aryTempSourceOptions.length; i++) 
		{
			citylist.options[i].text = aryTempSourceOptions[i].text;
			citylist.options[i].value = aryTempSourceOptions[i].value;
			citylist.options[i].selected = false;
		}
	}
}

function MoveOption(objSourceElement, objTargetElement)
{
	var aryTempSourceOptions = new Array();
	var x = 0;
	
	//looping through source element to find selected options
	for (var i = 0; i < objSourceElement.length; i++) {
		if(objSourceElement.options[i].selected)
		{
			flg = 0;
			for(j=0; j<objTargetElement.length; j++)
			{
				if(objSourceElement.options[i].value == objTargetElement.options[j].value)
				{
					flg = 1;
					break;
				}
			}
			if(flg == 0)
			{
				//need to move this option to target element
				var intTargetLen = objTargetElement.length++;
				objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text;
				objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;
			}
		}
	}
	
}

function ajax_subtype(proptype, id)
{
	url = "subtype.php?proptype=" + proptype;
	ajaxInclude(id, url);
}

