var SearchEngine = null;

(function()
{
	if (SearchEngine == null)
	{
		SearchEngine = new Object();
	}
	SearchEngine.Execute = function(request)
	{
		var
			channel = null;

		if (request != '')
		{
			try
			{
				channel = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				try
				{
					channel = new XMLHttpRequest();
				}
				catch (e)
				{
					channel = null;
				}
			}
			//---------------------------------------------------------------------
			if (channel != null)
			{
				//channel.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
				channel.onreadystatechange = function()
				{
					if(channel.readyState == 4)
					{
						if(channel.status == 200)
						{
							var
								response = eval('(' + channel.responseText + ')');

							if (response["status"] == "url")
							{
								window.location = response["content"];
							}
							if (response["status"] == "txt")
							{
                              document.getElementById('result').innerHTML = response["content"];
                              document.getElementById('result').style.visibility='visible';
							}
						}
						else
						{   document.getElementById('result').innerHTML = '<nobr><b>Произошла ошибка.</nobr> Попробуйте позже!</b>';
						    document.getElementById('result').style.visibility='visible';
						}
					}
				}
				// if (channel.open("GET", "/meteoinfo/search/process.php?request=" + encodeURIComponent(request), true) || true)
				   if (channel.open("GET", "/search/process.php?_rnd=" + Math.random() + "&request=" + encodeURIComponent(request), true) || true)
				{
					channel.send(null);
				}
			}
			else
			{
				//window.location = '/meteoinfo/search/?request=' + encodeURIComponent(request);
				  window.location = 'http://pogoda.by/search/?request=' + encodeURIComponent(request);
			}
		}
	}
})();
