$(document).ready(function() 
{
	$(function( $ )
	{
		$( "input[type='text']" ).keyup(function(){ 
		
			if ($(this).hasClass('no_number_format') || $(this).attr('rel') == 'no_number_format') {
			} else { isnumber(this); 
			} 
		} );
		$( "input[name=prices_per]" ).blur(function(){ if ($(this).attr('class') == 'no_number_format' || $(this).attr('rel') == 'no_number_format') {} else { isnumber(this); } });
	}); 

});
function trim (str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length; --i >= 0;) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}
function isnumber(input)
{
	var str=trim($(input).val());
	if(str!='')
	{
		str = str.replace(/\s*/g, '');
		if(!isNaN(str) && str.indexOf('.')==-1)$(input).val(number_format(str,0,'','  '));
	}
}
function number_format( number, decimals, dec_point, thousands_sep ) {    // Format a number with grouped thousands
    // 
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://crestidg.com)
 
    var i, j, kw, kd, km;
 
    // input sanitation & defaults
    if( isNaN(decimals = Math.abs(decimals)) ){
        decimals = 2;
    }
    if( dec_point == undefined ){
        dec_point = ",";
    }
    if( thousands_sep == undefined ){
        thousands_sep = ".";
    }
 
    i = parseInt(number = (+number || 0).toFixed(decimals)) + "";
 
    if( (j = i.length) > 3 ){
        j = j % 3;
    } else{
        j = 0;
    }
 
    km = (j ? i.substr(0, j) + thousands_sep : "");
    kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep);
    //kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).slice(2) : "");
    kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : "");
 
    return km + kw + kd;
}

$(document).ready(function() {
	$(function( $ ){
		$("input[type='text']").each(function(){
      var str=$(this).val();
      if(str!='' && $(this).attr('class') != 'no_number_format' && $(this).attr('rel') != 'no_number_format')
      {
        str = str.replace(/\s*/g, '');
        if(!isNaN(str) && str.indexOf('.')==-1)$(this).val(number_format(str,0,'','  '));
      }
    });
	});
});

