Voter = {
  vote : function(what_in){
    var what = what_in.substring(0,what_in.indexOf("."));
    var up_down = what_in.substring(what_in.indexOf(".")+1,what_in.length);

    var voted = Cookies.read(what);
    if(voted == null){
	this.voted=true;
	Cookies.create(what,"voted",1);
	var cooked = Cookies.read(what);
	if(cooked == null){
		alert("Seu navegador nao esta aceitando cookies.\n\nDesculpe-nos, mas voce nao pode avaliar este comentario!");
	}else{
	 	$(what_in).innerHTML = parseInt($(what_in).innerHTML)+1;
		pars="avaliacao="+up_down+"&comentario="+what;
		var myAjax = new Ajax.Request('avaliar.php', { method: 'get', parameters: pars, onComplete: this.showResponse });
	}
   }else{
	alert("Voce ja avaliou este comentario!");
    }
  },
  showResponse : function(originalRequest){
	$('result').innerHTML = originalRequest.responseText;
  }
}
var myrules = {
  '.concordo' : function(element){
	element.onclick = function(){
	  Voter.vote(this.id);
	  return false;
	},
	element.onmouseover = function(){
	  this.title = 'Concordo';
	}
  },
  '.discordo' : function(element){
	element.onclick = function(){
	  Voter.vote(this.id);
	  return false;
	},
	element.onmouseover = function(){
	  this.title = 'Discordo';
	}
  }
};
Behaviour.register(myrules);
