/*
 * Plugin dodaje diva zamykaj�cego wyszukujacego przycisk toggle i clikajacy go
 */
;
(function($) {
    $.fn.closeButton = function(options) {
        options = jQuery.extend({
            fullClass: "closer",
            searchClass: ".generatorTitle .helpHide",
            text:""
        }, options);
        //-------------------------//
        return this.each(function(index) {
            var $this = $(this);
            $this.prepend("<div class='" + options.fullClass + "'>" + options.text + "</div>");
            $("." + options.fullClass, $this).click(function() {
                $("" + options.searchClass).click()
            });
        });
    };
    $.fn.preFillInput = function(options){
        options = jQuery.extend({
            fillText: "Wpisz swoją wiadomość...",
            reinitEmptyField:true,
            noTextClass: "lightGreyText"
        });
        return this.each(function(index){
            var $this = $(this);
            if($this.data("isPreFill")){
                return;
            }else{
               $this.data("isPreFill", true); 
            }
            var fillText = $this.attr('title');
            if(fillText == null || fillText == undefined){
                fillText =  options.fillText;
            }
            if($this.val()==""){
                $this.addClass(options.noTextClass);
                $this.data("isFilled", false);
            }else{
                $this.data("isFilled", true);
            }
            $this.focus(function(){
                var userFilled = $this.data("isFilled");
                if(!userFilled){
                    $this.val("");
                    $this.removeClass(options.noTextClass);
                }
            }).blur(function(){
                var userFilled = $this.data("isFilled");
                if(!userFilled){
                    $this.val(fillText);
                    $this.addClass(options.noTextClass);
                }
            }).blur();
            $this.keyup(function(){
                if($this.val()!=""){
                    $this.removeClass(options.noTextClass);
                    $this.data("isFilled", true);
                }else{
                    $this.addClass(options.noTextClass);
                    $this.data("isFilled", false);
                }
            });
        });
    },
    $.fn.clearColumn = function(options){
        options = jQuery.extend({
            parentSelector: function(element){
                return $(element).parents("table:eq(0)");
            },
            rowSelector: function(parent){
                return $('tbody tr',parent);
            },
            elementsSelector: function(row, column){
                return $('td:eq('+column+') input',row);
            }
        });

        return this.each(function(index){
            var $this = $(this);
            $this.click(function(){
                var $parent = options.parentSelector($this);
                var $rows = options.rowSelector($parent);
                $rows.each(function(i){
                    var rowx = $($rows[i]);
                    options.elementsSelector(rowx,index).removeAttr('checked');
                });
            });
        });
    }
})(jQuery);
