function doRate(id){
  var xmlhttp;
  
  if (window.XMLHttpRequest){
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  } else if (window.ActiveXObject){
    // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  } else {
    alert("Your browser does not support XMLHTTP!");
  }
  
  xmlhttp.onreadystatechange=function(){

    //alert("readystate = "+xmlhttp.readyState);

    if(xmlhttp.readyState==4){
      createCookie(id);
      //document.getElementById("txtRate"+id).innerHTML="<font size=2><b>You like it!</b></font>";
    }
  }

  /*
  var strURL = "src/doRateHaiku.php";
  strURL += "?";
  strURL += "id="+id;
  xmlhttp.open("GET",strURL,true);
  xmlhttp.send(null);
  */
  
  var strURL = "src/doRateHaiku.php";
  var params = "";
  params += "id="+id;
  
  xmlhttp.open("POST",strURL,true);
  
  //Send the proper header information along with the request
  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlhttp.setRequestHeader("Content-length", params.length);
  xmlhttp.setRequestHeader("Connection", "close");
  
  xmlhttp.send(params);
  
  //
  document.getElementById("txtCount"+id).innerHTML = Number(document.getElementById("txtCount"+id).innerHTML) + 1;
  document.getElementById("txtRate"+id).innerHTML = "<font size=2><b>You like it!</b></font>";
}

function createCookie(id){
  // cookie should be an array of haiku IDs
  myRatings = getCookie('ratings');
  if (myRatings != null && myRatings != ""){
    // add to cookie
    myRatings = myRatings + "," + id;
  } else {
    // create cookie
    myRatings = id;
  }
  setCookie('ratings',myRatings,365);
}

function setCookie(c_name,value,expiredays){
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name){
  if (document.cookie.length>0)
    {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1)
      {
      c_start=c_start + c_name.length+1;
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
        return unescape(document.cookie.substring(c_start,c_end));
      }
    }else{
    return "";
  }
}