(function($) {
    $.fn.panel = function() {
      return this.each(function() {
        $this = $(this); 
        if(navigator.userAgent.match(/Android/i)){
        	$this.css({ right: "0px", top: "0px" });
        } else {
        	$this.css({ right: "0px", bottom: "0px" });
        }
        bindButtonEvent();
      });
    };
    
    $.fn.slideup = function() {
        $(this).slideDown(200);
        $("#feedback_panel_txtmessagebox").focus();
    }
    
    $.fn.commentAticle = function(useful, comments){
        $.ajax({
      	  url: "commentdocument.form",
      	  type: "POST",
      	  data: {docId: $("#docid").val(), useful: useful, comments: comments},
      	  success: function(data, status, xhr){
      		$this.slideUp(100, function(){
      			alert($("#thanks").val());
      			$("#feedback_panel_txtmessagebox").val('');
                $("input:radio[name='useful']").each(function(){
                	$(this).removeAttr("checked");
                });
      		});
      	  },
      	  error: function(xhr, status, error){
      		alert($("#call_error").val());
      	  }
        });
    }
    
    function bindButtonEvent() {
        var obj = $.fn.panel.defaults;
        var messagebox = $("#feedback_panel_txtmessagebox");
        var messagecount = $(".feedback_message_num");
        var submit = $(".feedback_panel_submit");

        $("#jquery-x-tool-close").click(function() {
        	$this.slideUp(200);
        });

        $("#feedback_panel_submit").click(function() {
            var msg = $.trim(messagebox.val());
            var useful = $("input:radio[name='useful']:checked").val();
            if(!useful){
              useful = '';
            }
            if(msg == '' && useful== ''){
            	alert($("#input_error").val());
            	$("#feedback_panel_txtmessagebox").focus();
            	return;
            }
            $this.commentAticle(useful, msg);
        });
    }
})(jQuery);