var Vote = function(){};
Vote.block = {
  onFocus : function(tArea,xoops_url)
  {
      tArea.className = 'pollBlockBlank';
  },
  onBlur  : function(tArea,xoops_url)
  {
      if (tArea.value.length==0){
          tArea.className = 'pollBlockComment';
      }
  },
  onPost  : function(poll_id, dirname, xoops_url)
  {
      var form_params = Form.serialize('pollBlock'+poll_id);
      var url = xoops_url+'/modules/'+dirname+'/json.php';
      var flipInput = function(bool){
          Form.getElements('pollBlock'+poll_id).each(function(ele){ele.disabled=bool;}); // disabled
          $('pollBlockComment'+poll_id).className = 'pollBlockLoading';
      };
      flipInput(true);

      var ajax = new Ajax.Request(url, {
        method : 'post',
        parameters: 'action_json_opinion_vote=1&'+form_params+'&'+Math.random()*100,
        requestHeaders: ['Referer', xoops_url],
        onSuccess: function(httpobj,json){
            if (json && json.result==1){
                var _className = 'pollBlockVoted';
                Element.show('show_log_'+poll_id);
            } else {
                flipInput(false);
                var _className = $('pollBlockComment'+poll_id).value ? 'pollBlockBlank' : 'pollBlockComment';
            }
            alert(json.message);
            $('pollBlockComment'+poll_id).className = _className;

        },
        onFailurer: function(httpobj, json){alert("Connection Failed"); flipInput(false);}
      });

  }
};

