//This function is used to create a XMLHttpRequest() object.
function GetXmlHttpObject()
{
	var xmlHttp = null;

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

			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//Internet Explorer.
			}
			catch(e){}
		}
	}

	return xmlHttp;
}

/* auther: Mansab Khan */

/*

url = www.sample.com/getCities.php?id=1

callback = void(int message, mixed result)

int message = {
0.  error
1. connected
2. sending request
3. waiting for result
4. completed successfully (url found)
5. completed with error (url not found)}

mixed result = Server response

*/
function CallServerScript(url,callback)
{
		var ajaxObject = GetXmlHttpObject();
		if(ajaxObject == null)
		{
			alert("Your browser doesn't support ajax.");
			callback(0, null);
			return;
		}
		ajaxObject.open("GET",url);
		ajaxObject.onreadystatechange = function()
		{
			switch(ajaxObject.readyState)
			{
				case 1:
					callback(1, null);
					break;
				case 2:
					callback(2, null);
					break;
				case 3:
					callback(3, null);
					break;
				case 4:
					if(ajaxObject.status == 200)
					{
						callback(4, ajaxObject.responseText);
					}
					else
					{
						callback(5, ajaxObject.responseText);
					}
					break;
			}
		}
		ajaxObject.send(null);
}