function predictDrop(e, id)
{
	var unicode=e.keyCode? e.keyCode : e.charCode;
	if(unicode == 8 || (unicode >= 65 && unicode <= 90) || unicode == 32)
	{
		var key_str;
		var actualkey;
		
		if(unicode == 8)
		{
			key_str = document.getElementById("country_str").value;
			if(key_str.substr((key_str.length-3), 3) == '%20')
			{
				key_str = key_str.substr(0, (key_str.length-3));
			}
			else
			{
				key_str = key_str.substr(0, (key_str.length-1));
			}
		}
		else if(unicode == 32)
		{
			key_str = document.getElementById("country_str").value;
			if(key_str != '')
			{
				key_str = key_str+'%20';
			}
		}
		else
		{
			actualkey=String.fromCharCode(unicode);
			key_str = document.getElementById("country_str").value+actualkey;
		}
		
		document.getElementById("country_str").value = key_str;
		
		var xmlHttp=GetXmlHttpObject()
		
		if (xmlHttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		} 

		var url=location.protocol+"//"+location.host+"/query/country/name/";
		url=url+key_str;
		
		xmlHttp.onreadystatechange=function()
		{ 
			if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{ 
				document.getElementById("country_id").innerHTML=xmlHttp.responseText;
				predictCityDrop(document.getElementById("country").value);
			} 
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	else
	{
		predictCityDrop(id);
	}
	
	return false;
}
	
function predictCityDrop(id)
{
	xmlHttp=GetXmlHttpObject()
	var url=location.protocol+"//"+location.host+"/query/city/country_id/";
	url=url+id;
	xmlHttp.onreadystatechange=function()
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			document.getElementById("city_id").innerHTML=xmlHttp.responseText;
			document.getElementById("country").focus();
		} 
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function changeBBVisibility(elem)
{
	xmlHttp=GetXmlHttpObject()
	var url=location.protocol+"//"+location.host+"/profile/blackboard/visibility/";
	url = url + elem.value;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
