function select_article(id)
{	if(id!='')
	{
		document.getElementById('sel_'+id).style.display = 'none';
		document.getElementById('proc_'+id).style.display = 'inline';
		http = createRequestObject();
	  var url='/select.php?add='+id;

	  //http.onreadystatechange = handleResponse; // FF 1.0 and 1.5 do not call it if open(,,false) used
	  http.open("GET", url, false);
	  http.send(null);
	  handleSelectResponse();
	}
}

function handleSelectResponse()
{
	if(http.readyState == 4 && http.status == 200)
	{		var xmldoc = http.responseXML;
		var coll = xmldoc.getElementsByTagName('add');
		if(coll.length)
		{
			var id = coll[0].childNodes[0].nodeValue;
			document.getElementById('proc_'+id).style.display = 'none';
			document.getElementById('desel_'+id).style.display = 'inline';
      update_n_items(xmldoc);
		}
		else
			alert('Error occured! Please refresh page');
		delete http;
	}
}

function deselect_article(id)
{
	if(id!='')
	{
		document.getElementById('desel_'+id).style.display = 'none';
		document.getElementById('proc_'+id).style.display = 'inline';
		http = createRequestObject();
	  var url='/select.php?del='+id;

	  //http.onreadystatechange = handleResponse; // FF 1.0 and 1.5 do not call it if open(,,false) used
	  http.open("GET", url, false);
	  http.send(null);
	  handleDeselectResponse();
	}
}

function handleDeselectResponse()
{
	if(http.readyState == 4 && http.status == 200)
	{
		var xmldoc = http.responseXML;
		var coll = xmldoc.getElementsByTagName('del');
		if(coll.length)
		{
			var id = coll[0].childNodes[0].nodeValue;
			document.getElementById('proc_'+id).style.display = 'none';
			document.getElementById('sel_'+id).style.display = 'inline';
      update_n_items(xmldoc);
		}
		else
			alert('Error occured! Please refresh page');
		delete http;
	}
}

function update_n_items(xmldoc)
{
	var coll = xmldoc.getElementsByTagName('n_items')[0].childNodes;
  var n_items = coll.length>0 ? coll[0].nodeValue : '';
	var n_items_obj = document.getElementById('n_items');
	if(n_items_obj)
	  n_items_obj.innerHTML = n_items;
}

var http = false;

function createRequestObject()
{
   var req;
   if(window.XMLHttpRequest)
   {
      // Firefox, Safari, Opera...
      req = new XMLHttpRequest();
   }
   else if(window.ActiveXObject)
   {
      // Internet Explorer 5+
      req = new ActiveXObject("Microsoft.XMLHTTP");
   }
   else
   {
      // There is an error creating the object,
      // just as an old browser is being used.
      alert('Problem creating the XMLHttpRequest object');
   }
   return req;
}


