function xmlhttpPost(qstr, collection, recipe_id, coll)
{
	var strURL = 'addtocoll.php';
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest)
    {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject)
    {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function()
    {
        if (self.xmlHttpReq.readyState == 4)
        {
            updatepage(self.xmlHttpReq.responseText, collection);
        }
    }
    self.xmlHttpReq.send(qstr);
}

function addto(recipe_id, collection, remove, coll)
{
    qstr = 'r=' + escape(recipe_id);
    qstr += '&c=' + escape(collection);
    if(remove) qstr += '&remove=1';
    if(coll) collection=recipe_id;
    xmlhttpPost(qstr, collection);
    return true;
}

function updatepage(str, collection){
    document.getElementById(collection).innerHTML = str;
    if(is_numeric(collection)) document.getElementById(collection).style.display='none';
}

function rate(recipe_id, rating)
{
    qstr = 'r=' + recipe_id;
    qstr += '&rating=' + rating;
    xmlhttpPost(qstr, 'ratingfeedback');
    return true;   
}

function is_numeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber; 
}