// JavaScript Document

var xmlHttp = createXmlHttpRequestObject();

var serverAddress = "base.php?next=1";

var updateInterval = 5;
var errorRetryInterval = 30;
var debugMode =  true;

/*
function get_parseGET(name)
{
get = new String(window.location);
x = get.indexOf("?");
if(x!=-1)
{

// здесь будет основной код
l = get.length;
get = get.substr(x+1, l-x);
l = get.split("&");
    x = 0;
    _GET_Count  = l.length;
    _GET_Keys   = new Array(_GET_Count);
    _GET_Values = new Array(_GET_Count);
	
	for(i in l)
    {
      get = l[i].split("=");
      _GET_Keys[x] = get[0];
      _GET_Values[x] = get[1];
      x++;
    }
var l = _GET_Keys.length;
  for(var i = 0; i < l; i++) 
		{
                
                        if (name === _GET_Keys[i])
                         {name = _GET_Values[i]}      
        }

	alert(name);
}
else alert("Ничего нет");
}	
*/

function createXmlHttpRequestObject()
{
var xmlHttp;
if(window.ActiveXObject)
	{
	try
		{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	catch (e)
		{
		xmlHttp = false;
		}
	}
else
	{
	try
		{
		xmlHttp = new XMLHttpRequest();
		}
	catch (e)
		{
		xmlHttp = false;
		}	
	}
if(!xmlHttp)
	alert ('Ошибка создания объекта XMLHttpRequest');
else
	return xmlHttp;
}



function process ()
{
if (xmlHttp)
	{
	try
		{
			var direction = document.getElementById('direction').value;
		
			//get_parseGET("id");
			if (direction != 0)
			{
				var basetype = document.getElementById('basetype').value;
			}
			
		//	if (basetype == null)
		//	{
		//	xmlHttp.open("GET",serverAddress + "&direction=" + direction + "&basetype=0",true);	
		//	}
		//	else
		//	{
			xmlHttp.open("GET",serverAddress + "&direction=" + direction + "&basetype=" + basetype,true);
		//	}
			
			xmlHttp.onreadystatechange = handleRequestState;
			xmlHttp.send(null);
			//alert('It works');
	
		}
		catch (e)
		{
		alert("Невозможно соединиться с сервером" +e.toString());
		}	
	}
	
}


function handleRequestState()
{

if (xmlHttp.readyState == 4) 
	{
	if (xmlHttp.status == 200)
		{
			try
			{
			handleServerResponse();
			}
			catch(e)
			{
			alert("Ошибка чтения ответа" +e.toString());	
			}
		}
		else alert("Возникла ошибка получения данных:\n" + xmlHttp.statusText);
	}	

}


function handleServerResponse()
{
			var response = xmlHttp.responseText;
			//alert("response");
			if (response.length == 0)
			throw (response.length == 0 ? "Server error": response);
			myDiv = document.getElementById('myDivElement');
			myDiv.innerHTML = response;
}