function populate_rails_flash() {
  var cookie_data = $.cookie("flash");
  $.cookie('flash', '', {expires: -1, path:"/"});
  if (cookie_data && cookie_data != "") {
    var data = $.parseJSON(cookie_data);
    if(!data) data = {};
	
    var keys = ["notice", "error"];
    jQuery.each(keys, function() {
      if(data[this]) {
        var content = unescape(data[this].replace(/\+/g, " "));
        var flash_container = $("#flash_"+this);
        if (flash_container.length > 0) {
          flash_container.html(content);
          flash_container.addClass("visible");
        }
      }
    })
  }
  
  // flash[:title] can be used to change page's title'
  if (data && data["title"]) {
    // $("title").text(); wont work on firefox (neither ie?)
    document.title = unescape(data["title"].replace(/\+/g, " "))
  }
}; 

