(function($) {
   $.fn.inputs = function( values ) {
      if( values == null )
      {
         values = {};
         this.find( ":input" ).each( function( index, element ) {
            if( element.getAttribute( "type" ) == "checkbox" )
               values[element.id] = ($(this).attr( "checked" ) == "checked" || $(this).attr( "checked" ) == true) ? 1 : 0;
            else if( 
               element.getAttribute( "type" ) != "radio" && 
               element.getAttribute( "type" ) != "submit" && 
               element.getAttribute( "type" ) != "file" && 
               element.getAttribute( "type" ) != "button" && 
               element.getAttribute( "type" ) != "image" && 
               element.getAttribute( "type" ) != "reset" 
            )
               values[element.id] = $(element).val();
         });
         this.find( "input[type=radio]:checked" ).each( function( index, element ) {
            values[element.getAttribute("name")] = $(element).val(); 
         });
         return values;
      }
      else
      {
         this.find( ":input" ).each( function( index, element ) {
            if( values[element.id] == undefined ) {
               if( element.getAttribute( "type" ) == "checkbox" )
                  $(this).removeAttr( "checked" );
               else if( 
                  element.nodeName != "SELECT" && 
                  element.getAttribute( "type" ) != "radio" && 
                  element.getAttribute( "type" ) != "button" && 
                  element.getAttribute( "type" ) != "file" && 
                  element.getAttribute( "type" ) != "submit" && 
                  element.getAttribute( "type" ) != "reset" 
               )
                  $(this).val( "" );
            }
            
            else if( element.getAttribute( "type" ) == "checkbox" )
            {
               if( values[element.id] == 1 )
                  $(this).attr( "checked", "checked" );
               else
                  $(this).removeAttr( "checked" );
            }
            else if( element.getAttribute( "type" ) != "radio" )
               $(this).val( values[element.id] );
         });
         this.find( "input[type=radio]" ).each( function( index, element ) {
            if( values[element.getAttribute("name")] != undefined ) {
               if( $(this).val() == values[element.getAttribute("name")] )
                  $(this).attr( "checked", "checked" );
               else
                  $(this).removeAttr( "checked" );
            }
         });
      } 
      return this;
      
   };
   
})(jQuery); 

