/**
 * jQuery instance methods
 *
 * $(selector).methodName();
 *
 */
(function($) {

    /**
     * check a radiobutton or checkbox
     */    
    $.fn.check = function() {
        return $(this).attr('checked','checked');
    };

    /**
     * uncheck a radiobutton or checkbox
     */    
    $.fn.uncheck = function() {
        return $(this).attr('checked', false );
    };
    
    /**
     * is the radiobutton or checkbox checked?
     */
    $.fn.isChecked = function() {
        return $(this).is(':checked');
    };
    
    /**
     * remove all classnames from an element
     */    
    $.fn.removeClasses = function() {
        return $(this).attr( 'className', '' );
    };
    
    /**
     * check if a collection holds any elements
     */ 
    $.fn.exists = function() {
        return ( $(this).size() > 0 );
    };
    
    $.fn.fullHeight = function() {
        return $(this).height() + 
            $.intval( $(this).css('marginTop') ) +
            $.intval( $(this).css('marginBottom') ) +
            $.intval( $(this).css('paddingTop') ) +
            $.intval( $(this).css('paddingBottom') ) +            
            $.intval( $(this).css('borderTopWidth') ) +
            $.intval( $(this).css('borderBottomWidth') );
    };
    
    $.fn.fullWidth = function() {
        return $(this).width() + 
            $.intval( $(this).css('marginLeft') ) +
            $.intval( $(this).css('marginRight') ) +
            $.intval( $(this).css('paddingLeft') ) +
            $.intval( $(this).css('paddingRight') ) +             
            $.intval( $(this).css('borderLeftWidth') ) +
            $.intval( $(this).css('borderRightWidth') );
    };
    
    /**
     * replace part of a string
     */ 
    $.fn.replaceText = function( oldStr, newStr ) {
        return $(this).text( $(this).text().split( oldStr ).join( newStr ) );
    };
    
    /**
     * reverse the elements childnodes
     */    
    $.fn.reverse = function() {
        var c = $.makeArray( $(this).children() ).reverse();
        return $(this).empty().append(c);
    };

    /**
     * create textselection
     */  
    $.fn.selectRange = function(start, end) {
        var e = document.getElementById( $(this).attr('id') );
        if ( e ) {
            if ( e.setSelectionRange ) { 
                e.focus(); 
                e.setSelectionRange(start, end); 
            } else if (e.createTextRange) {
                var range = e.createTextRange(); 
                range.collapse(true); 
                range.moveEnd('character', end); 
                range.moveStart('character', start); 
                range.select(); 
            } else if (e.selectionStart) { 
                e.selectionStart = start; 
                e.selectionEnd = end; 
            }
        }
        return $(this);
    };

})(jQuery);



/**
 * jQuery utility methods
 *
 * $.methodName() or jQuery.methodName()
 *
 */
(function($) {

    $.extend( {   	
        stripTags : function( str ) {
            return $.trim( str.replace(/<\/?[^>]+>/gi, '') );
        },
        intval : function( num ) {
            return parseInt( $.trim( num ), 10 )
        },
        
        loadCss : function(href) {
            var link = document.createElement('link');
            link.setAttribute('rel', 'stylesheet' );
            link.setAttribute('type', 'text/css' );
            link.setAttribute('href', href );
            document.getElementsByTagName('head')[0].appendChild(link);
        }
               
    });
    
})(jQuery);
