pic1= new Image();
pic1.src=siteroot+"images/loader.gif";
// stores the reference to the XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject(); 
// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{  
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)


    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

// make asynchronous HTTP request using the XMLHttpRequest object 
var span_id;

function AddToFav(book_id)
{
	if(book_id!="")
	{
		span_id = book_id;
		//	document.getElementById("indicatorDIV").innerHTML = "<img src='./images_en/indicator.gif' valign='absmiddle' border='0' alt='validating...'>";
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
		{
			// execute the quickstart.php page from the server
			document.getElementById("fav_id_"+book_id).innerHTML = "<img src='"+siteroot+"images/loader.gif' valign='absmiddle' border='0' alt='Processing...'>";
			xmlHttp.open("GET", siteroot+"add_to_favourite.php?bid=" + book_id, true);
			//alert(siteroot+"add_to_favourite.php?bid=" + book_id);
		// define the method to handle server responses
			xmlHttp.onreadystatechange = AddFav;
			// make the server request
			xmlHttp.send(null);
		}
		else
		{
			// if the connection is busy, try again after one second  
			setTimeout('1000',AddToFav);
		}
	}
	else
	{
			alert("To add to this book on your favourite list you need to be logged in!");
			return false();
	}
}

function AddFav()
{
	 if (xmlHttp.readyState == 4) 
  	{
    	// status of 200 indicates the transaction completed successfully
    	if (xmlHttp.status == 200) 
    	{
			var output = xmlHttp.responseText;
			if(output!="Added to your favourite list.")
			{
				alert(output);
			}
			document.getElementById("fav_id_"+span_id).innerHTML = output;
    	} 
    	// a HTTP status different than 200 signals an error
    	else 
    	{
      		alert("here was a problem accessing the server: " + xmlHttp.statusText);
    	}
	}
}
