// Usage: lprintf('test', 'xxx');

var jsLocale = {    
    
	/* Common */
	'BracketInterface add field' : 'Add another field to calculate',
	'day'	: 'day',
	'days'	: 'days',
    
    'rating 1'		: 'bad',
    'rating 2'		: 'normal',
    'rating 3'		: 'good',
    'rating 4'		: 'excellent',
    'rating 5'		: 'super!',
	
	/* services/color */
	'Color info': 'Colour info %s',
    'Close to': 'Close to %s',
    'Similiar color':  'Similiar colour',
    'Similiar colors': 'Similiar colours',
    
    /* services/color-compare */
    'absent-he'		: 'absent',
    'weak-he'		: 'weak',
    'notable-he'	: 'notable',
    'optimal-he'	: 'optimal',
    'high-he'		: 'high',
        
    'absent-she'	: 'absent',
    'weak-she'		: 'weak',
    'notable-she'	: 'notable',
    'medium-she'	: 'medium',
    'optimal-she'	: 'optimal',
    'high-she'		: 'high',
    'strong-she'	: 'strong',
    
    /* services/dogs */
	'Search breed'	: 'Search breed by name',
	'Alike breed' 	: 'Alike breed',
	'Alike breeds'	: 'Alike breeds',

	/* services/converter */
	'on cross-rate'	: 'On a cross rate',
	'on rate'		: 'At the rate of %s for %s %s',
	
	/* services/etiquette */
	'serving'		: 'serving',
	'result-article-code': 'Embed image and description',
	'etiquette'     : 'Etiquette',

	/* services/measure */
	'wavelength with frequency'	: 'Length of a wave with frequency of %s %s in %s',
	
	/* services/women-calendar */
	'menstruation'	: 'menstruation',
	'ovulation period' :'ovulation period',
	'probable PMS'	: 'probable PMS',
	'projected'		: 'Projected ',
	
	/* services/clothes */
	'size-ru'       : 'in&nbsp;Russia<br/>and&nbsp;in&nbsp;Ukraine',
	'size-us'       : 'in&nbsp;the&nbsp;USA',
	'size-en'       : 'in&nbsp;England',
	'size-eu'       : 'in&nbsp;Europe',
	'size-de'       : 'in&nbsp;Germany',
	'size-fr'       : 'in&nbsp;France',
	'size-it'       : 'in&nbsp;Italy',
	'size-growth'    : 'growth (cm)',
	'size-neck'     : 'neck (cm)',
	'size-shoulders': 'shoulders width (cm)',
	'size-chest'    : 'chest (cm)',
	'size-waist'    : 'waist (cm)',
	'size-hip'      : 'hip (cm)',
	'size-hand'     : 'leg length (cm)',
	'size-leg'      : 'leg length<br/>from a waist (cm)',
	'size-age'      : 'age',
	'size-head'     : 'head (cm)',
	'size in cm'    : 'Measures in <i>cm</i>',
	'size'          : 'size',
	
	/* services/alcohol */
	'less hour'     : 'less than an hour',
	'hrs'           : 'hrs',
	'right now'     : 'Right now',

	/* money/converterInterface */
	'rate info'		: 'The information on a rate',

	/* money/vat */
	'vat % of x'	: 'VAT %s%% from %s roubles.',

	/* net/net */
	'domain help'	: 'whois',
	'ip help'		: 'whois',
	'server error'	: 'Server not found',
	'domain is free': 'The domain is free',
	'domain is possibly free' : 'Information about the domain could not be found, perhaps it is free',

	/* net/speed */
	'detect download speed'	: 'Calculating download speed',
	'detect upload speed'	: 'Calculating upload speed',
	'wait a time'			: 'it can take a few moments',

	/* net/whoami */
	'flash not set'			: 'Flash plugin not set',

	/* place/ac */
	'plugs and sockets'		: 'AC Plugs and sockets %s',

	/* place/embassy */
	'of russia'		: 'of Russia',
	'embassy-of'	: 'Embassy of',
	'russia-embassy': 'Embassy of Russia',
	'in-russia'		: 'in Russia',
	'embassy-office-consular':	'Consulate',
	'embassy-office-embassy':	'Embassy',
	'embassy-office-visas':		'Visa centre',
	
	/* place/distance */
	'drive-distance': 'Drive distance',
	'km'			: ' km',
    'distance'      : 'the distance',
    'overcome'      : 'To overcome',
    'light'         : 'light needs',
    'sound'         : 'sound',
    'aircraft'      : 'by aircraft',
    'walk'          : 'walking',
    'bicycle'       : 'by bicycle',
    'sapsan'        : "by 'Sapsan' train",
    'us'            : 'μs',
    'ms'            : 'ms',
    's'             : 's',
    'min'           : 'min',
    'h'             : 'h',

	/* time/calendar */
    'holiday in month'  : 'A holiday in this month',
    'holidays in month' : 'Holidays this month',
    'no holidays in month'  : 'No holidays this month',
    'no holidays'       : 'No holidays',
    'memorials'         : 'Memorable dates',
    'memorial in month' : 'Memorable date in this month',
    'memorials in month'    : 'Memorable dates this month',
    'no memorials in month' : 'No memorable dates this month',
    'no memorials'      : 'No memorable dates',
    'on calendar prep'  : '',
    'on calendar after' : '',
    'on calendar bahai prep'    : '',
	'on calendar bahai after'	: '',
	'calendar link text'	: '%s %s %s %s, %6$s',
	
	/* time/days-count */
	'day after'	: ' day after ',
	'comes'		: 'comes ',
	'came'		: 'came ',
	'before'	: 'Before',
	'passed'	 : 'passed ',
	'passed-mult': 'passed ',
	'day'		: ' day',
	'days-gen'	: ' days',
	'days'		: ' days',
	'remain'	 : 'remain ',
	'remain-mult': 'remain ',
	'from'		: 'From ',
	'from-o'	: 'From ',
	'year'		: ' year',
	'between'   : 'Between',
	
	/* measure/numbers */
	'digits'		: ' digits',
	'notation'		: ' notation',
	'converter'		: 'Converter ',
	'numbers'		: ' numbers',
	
	/* blogs/personal */
	'my blog rating'    : 'My blog rating',
	
	/* place/distance */
	'elevation' : 'Elevation (m)',
	
	/* measure/hex */
	'radix'        : ' radix',
	'radix system' : ' radix system',

    'dummy':''
};

var jsLocaleUnit = {
    day  : ['day', 'days'],
    year : ['year', 'years'],
    hour : ['hour', 'hours'],
    month: ['month', 'months'],
    week : ['week', 'weeks'],
    'hour ago' : ['hour ago', 'hours ago'],
    horse: ['horse', 'horses'],
    rub  : ['ruble', 'rubles'],
    cigarette : ['cigarette', 'cigarettes'],
    
    dummy: ''
}

var locale_months_genitive = ['January', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var locale_months_nominative = locale_months_genitive;
var locale_months_full = locale_months_genitive;

function ordinal_number(i) {
    var o = i % 10;
    var suffix = 'th';
    if (o == 1)
        suffix = 'st';
    if (o == 2)
        suffix = 'nd';
    if (o == 3)
        suffix = 'rd';
    return i + suffix;
}

String.prototype.number = function (roundValue) 
{
    function num (n) { return n.replace('-','–').replace(',','.') }
    
    var n = typeof roundValue != 'undefined' && !isNaN(roundValue) 
        ? parseFloat(this).toFixed(roundValue).toString()
        : this;
    
    if (Math.abs(parseFloat(n)) < 10000) return num (n);
       
    if (n.substring(0,1) == '-')
    {
        var sign = '-';
        n = n.substr(1);
    }    
    
    var int_frac = n.split('.'),
        frac = int_frac[1];
        
    n = int_frac[0];
    
    var a = [];         
    while (n)
    {
        a.push(
            n.substr(n.length < 3 ? 0 : n.length - 3, 3)
        );
        n = n.substring(0, n.length - 3);        
    }
    
    return num ( 
        (sign ? sign : '') + a.reverse().join(' ') + (frac ? '.' + frac : '')
    );
}

Number.prototype.number = function (roundValue) {
    return this.toString().number(roundValue)
}

String.prototype.declansion = function (unit)
{
    return parseFloat(this).declansion (unit);
}
Number.prototype.declansion = function (unit)
{
    return UnitCase (unit, this);
}

function UnitCase (unitStr, num) //Array of word cases for count 1, 2
{
    if (!jsLocaleUnit[unitStr]) return '';
    
    units = jsLocaleUnit[unitStr];
    
    if (Math.abs(num) == 1) 
		return units[0];
	else
		return units[1];
}

