(function($){
    // Shell for your plugin code
    $.fn.poll_result=function(){
	return this.each(function(){
	    $.extend(this,{
		show:function(){
		if(!$(this).is(':visible')){
		    $(elem).show();
		}
	    }
	    });
	});
    };
})(jQuery);

(function($){
    // Shell for your plugin code
  $.fn.poll_form=function(options){
    return this.each(function(){
	    $.extend(this,options);
	    $.extend(this,{
        show:function(){
          if(!$(this).is(':visible')){
            $(elem).show();
          }
        }
	    });
      var obj=this;
      var form=$('form',this);
      form.bind('submit', function(event) {
        if ($(':checked',form).val())
        {
          send(obj,form);
        }
        return false;
      });
      function send(obj,form){
        obj.iframe.ready(function(){
            writeCookie('sondage'+ obj.content_id,obj.content_id,60,'/',null,null);
            obj.result.show();
            $(obj).hide();
          }
        );
        obj.iframe.attr("src",obj.url + $(":checked", form).val());
      }
    });
  };
})(jQuery);

function initSondage(form_sondage, div_sondage, id_sondage)
{
	var $form_sondage = jQuery(form_sondage);
	var $div_sondage = jQuery(div_sondage);
  var intHasVoted = getCookie('sondage' + id_sondage);

  $div_sondage.hide();
  $form_sondage.hide();
	if (intHasVoted == id_sondage)
  {
		$div_sondage.show();
	}
	else
  {
    $form_sondage.show();

    $form_sondage.live('submit', function(event) {
      event.preventDefault();
      event.stopPropagation();

      var rep = $form_sondage.find(':checked').val();
      if (rep == "")
      {
        alert('Choisissez une réponse avant de procéder au vote.');
        return false;
      }
      else
      {
        jQuery.ajax({
          url: '/includes/ajax/sondagevote.asp',
          type: 'POST',
          data: {   
            content_id: id_sondage,
            namespace: "poll",
            name: rep
          },
          success: function() {
            writeCookie('sondage' + id_sondage, id_sondage, 60, '/', null, null);
            $div_sondage.show();
            $form_sondage.hide();
          },
          error: function() {
            alert('Une erreur s\'est produite, veuillez essayer à nouveau dans quelques instants.');
          }
        });
      }
    });
	}
}
