/*
 * jquery.value.filter.js
 *
 * Copyright(C) 2008 codecheck.in/101000code/101000LAB/
 * http://trac.codecheck.in
 * http://code.101000lab.org
 *
 * Licensed under The MIT License
 */
    (function($) {

             $.fn.money = function(elm) {
                 var self = this;

                 if (self.val() != undefined) {
                     self.val(
                         "￥"+ self.val().replace(/[^0-9]/g,'').replace(/((?:^[-+])?\d{1,3})(?=(?:\d{3})+(?!\d))/g, "$1,")
                     );
                 };

                 self.blur(
                     function(){
                         $(this).val(
                         "￥" + $(this).val().replace(/[^0-9]/g,'').replace(/((?:^[-+])?\d{1,3})(?=(?:\d{3})+(?!\d))/g, "$1,")
                         );
                     }
                 );

                 return self;
             };
             
             $.fn.gram = function(elm) {
                 var self = this;

                 if (self.val() != undefined) {
                     self.val(
                         self.val().replace(/[^0-9]/g,'').replace(/((?:^[-+])?\d{1,3})(?=(?:\d{3})+(?!\d))/g, "$1,")
                     );
                 };

                 self.blur(
                     function(){
                         $(this).val(
                        	$(this).val().replace(/[^0-9]/g,'').replace(/((?:^[-+])?\d{1,3})(?=(?:\d{3})+(?!\d))/g, "$1,")
                         );
                     }
                 );

                 return self;
             };             
 
             $.fn.numberonly = function(elm) {
                 var self = this;

                 if (self.val() != undefined) {
                     self.val(
                         self.val().replace(/[^0-9]/g,'')
                     );
                 };

                 self.blur(
                     function(){
                         $(this).val(
                             $(this).val().replace(/[^0-9]/g,'')
                         );
                     }
                 );


                 return self;
             };
 
             $.fn.numberdot = function(elm) {
                 var self = this;

                 if (self.val() != undefined) {
                     self.val(
                         self.val().replace(/[^0-9\.]/g,'')
                     );
                 };

                 self.blur(
                     function(){
                         $(this).val(
                             $(this).val().replace(/[^0-9\.]/g,'')
                         );
                     }
                 );


                 return self;
             };
 

     })(jQuery); // function($)
  
 
