$.fn.elem_type = function() {
    if (! $(this).get(0)) {
        return '';
    }

    return $(this).get(0).nodeName.toLowerCase();
}

$.fn.check = function(mode) {
	var mode = mode || 'on'; // if mode is undefined, use 'on' as default
	return this.each(function() {
		switch(mode) {
		case 'on':
			this.checked = true;
			break;
		case 'off':
			this.checked = false;
			break;
		case 'toggle':
			this.checked = ! this.checked;
			break;
		}
	});
};

$.fn.apply_zebra = function() {
    return $("tr:visible", $(this))
	        .filter(':even')
	        .removeClass('even').addClass('odd')
	        .end().filter(':odd')
	        .removeClass('odd').addClass('even');
};


$.uiTableFilter_ = function(jq, phrase, column) {
    phrase = phrase.toLowerCase();

    if (phrase == this.last_phrase && column == this.last_column) {
        return;
    }

    var phrase_length = phrase.length;

    if (phrase == '') {
        jq.find("tbody > tr").show();
    } else {
        var index = null;
        jq.find("thead > tr:last > th").each( function(i){
            if( $(this).text() == column ) {
                index = i;
                return false;
            }
            });

        jq.find("tbody > tr").each(function() {
            if (phrase != $($(this).find("td:eq(" + index + ")")).text().toLowerCase().substr(0, phrase_length)) {
                $(this).hide();
            } else {
                $(this).show();
            }});
    }

    this.last_phrase = phrase;
    this.last_column = column;

    return jq;
};

$.uiTableFilter_.last_phrase = '';
$.uiTableFilter_.last_column = '';
