

function favorite(user_id, type, id)
{
 
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
   var idname = '';
  if(type == 'comment') {
    idname = "favorite" + id;
    } else { 
	idname = "favorite-publication";
	}
	document.getElementById(idname).innerHTML = 'Загрузка';


   
    xmlHttp.open("GET", "/xml/favorite.php?user_id=" + user_id + "&type=" + type + "&id=" + id, true);  
	
    
    xmlHttp.onreadystatechange = handleRequestStateChangeFavorite;
    
    xmlHttp.send(null);
  }
}
function handleRequestStateChangeFavorite() 
{
  // when readyState is 4, we are ready to read the server response
  if (xmlHttp.readyState == 4) 
  {
    // continue only if HTTP status is "OK"
    if (xmlHttp.status == 200) 
    {
      try
      {
        // do something with the response from the server
        handleServerResponseFavorite();
      }
      catch(e)
      {
        // display error message
        alert("Error reading the response: " + e.toString());
      }
    } 
    else
    {
      // display status message
      alert("There was a problem retrieving the data:\n" + 
            xmlHttp.statusText);
    }
  }
}
function handleServerResponseFavorite() 
{

  if (xmlHttp.readyState == 4) 
  {
    
    if (xmlHttp.status == 200) 
    {
  
       var xmlResponse = xmlHttp.responseXML;

  xmlRoot = xmlResponse.documentElement;  
    

favoriteid = xmlRoot.getElementsByTagName("favoriteid");
smt = xmlRoot.getElementsByTagName("smt");
type = xmlRoot.getElementsByTagName("type");


    if(type.item(0).firstChild.data == 'comment') 

	      document.getElementById("favorite" + favoriteid.item(0).firstChild.data).innerHTML = smt.item(0).firstChild.data;
		  else  document.getElementById("favorite-publication").innerHTML = smt.item(0).firstChild.data;
      
    } 
  
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}

function delete_favorite(user_id, id)
{
 
  




   
    xmlHttp.open("GET", "/xml/favorite-delete.php?user_id=" + user_id +  "&id=" + id, true);  
	
    
    xmlHttp.onreadystatechange = handleRequestStateChangeFavoriteDelite;
    
    xmlHttp.send(null);
  
}
function handleRequestStateChangeFavoriteDelite() 
{
  // when readyState is 4, we are ready to read the server response
  if (xmlHttp.readyState == 4) 
  {
    // continue only if HTTP status is "OK"
    if (xmlHttp.status == 200) 
    {
      try
      {
        // do something with the response from the server
        handleServerResponseFavoriteDelite();
      }
      catch(e)
      {
        // display error message
        alert("Error reading the response: " + e.toString());
      }
    } 
    else
    {
      // display status message
      alert("There was a problem retrieving the data:\n" + 
            xmlHttp.statusText);
    }
  }
}
function handleServerResponseFavoriteDelite() 
{

  if (xmlHttp.readyState == 4) 
  {
    
    if (xmlHttp.status == 200) 
    {
  
       var xmlResponse = xmlHttp.responseXML;

  xmlRoot = xmlResponse.documentElement;  
    

favoriteid = xmlRoot.getElementsByTagName("favoriteid");
smt = xmlRoot.getElementsByTagName("smt");



  if(smt.item(0).firstChild.data == 0) document.getElementById("fav" + favoriteid.item(0).firstChild.data).innerHTML = '';
else
	      document.getElementById("delete" + favoriteid.item(0).firstChild.data).innerHTML = smt.item(0).firstChild.data;
		  
      
    } 
  
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}


