var message2;
var objhttp1;

function getXMLHTTPObject()
{
	var xmlhttp;
	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E)
		{
			xmlhttp = false;
		}
	}

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try
		{
			xmlhttp = new XMLHttpRequest();
		}
		catch (e)
		{
			xmlhttp = false;
		}
	}
	return xmlhttp;
}



function sendRequestSearch(url, data)
{
	method='post';
	mode=true;
	header='Content-Type:application/x-www-form-urlencoded; charset=UTF-8';

	objhttp1.open(method, url, mode);
	objhttp1.setRequestHeader(header.split(':')[0],header.split(':')[1]);
	objhttp1.send(data);
}

function callServerSearch(message, url)
{
	message2 = message;
	objhttp1 = getXMLHTTPObject();
	
	objhttp1.onreadystatechange = getRequestDataSearch;
	sendRequestSearch(url);

	function getRequestDataSearch()
	{
		if (objhttp1.readyState == 0)
		{
			//document.getElementById('div_grid_message').innerHTML = "";
		}

		if (objhttp1.readyState == 1)
		{
			document.getElementById('s_country').disabled=true;
			document.getElementById('s_edition').disabled=true;
			document.getElementById('div_grid_message_search').innerHTML = message2;
		}

		if (objhttp1.readyState == 2)
		{
			//document.getElementById('div_grid_message').innerHTML = "";
		}

		if (objhttp1.readyState == 3)
		{
			//document.getElementById('div_grid_message').innerHTML = "";
		}

		if (objhttp1.readyState == 4)
		{
			var response = objhttp1.responseText;
			document.getElementById('div_grid_message_search').innerHTML = "";
			//Clear all the existing options of combo box
			document.getElementById('s_country').disabled=false;
			document.getElementById('s_edition').disabled=false;
			document.getElementById('s_edition').options.length=1;
			/*var len = document.getElementById('s_edition').options.length;
			len = len-1;
			for (i=len; i>0; i--)
			{
				document.getElementById('s_edition').options[i]=null;
			}
			*/
			//Fill new options to combo box
			var arr_options = response.split(",");
			if (arr_options.length > 0)
			{
				index=0;
				for (i=0; i<arr_options.length; i++)
				{
					index++;
					arr_vals=arr_options[i].split(":");
					document.getElementById('s_edition').options[index]=new Option(arr_vals[1],arr_vals[0]);
					if (selected_val == parseInt(arr_vals[0]))
					{
						document.getElementById('s_edition').options[index].selected=true;
					}
				}
			}
		}
	}
}

function fnFillEditionsSearch(country_id, url, message)
{
	
    if (country_id != "")
	{
		callServerSearch(message, url);
	}
}
