function toggleDisplayBlock(id){
	$('#' + id).toggleClass('hidden');
}

function toggleInfo(short_id, full_id){
	$('#' + short_id).toggleClass('hidden');
	$('#' + full_id).toggleClass('hidden');
}

function formatDate(format, date){
	
	var day = date.getDate();
	var month = date.getMonth() + 1;
	var year = date.getFullYear();
	
	resultDateInFormat = format;
	resultDateInFormat = resultDateInFormat.replace('%d', (day < 10 ? '0' : '') + day);
	resultDateInFormat = resultDateInFormat.replace('%m', (month < 10 ? '0' : '') + month);
	if (resultDateInFormat.match('%Y')) {
		resultDateInFormat = resultDateInFormat.replace('%Y', year);
	}
	else if (resultDateInFormat.match('%y')) {
		var cuttedYear;
		cuttedYear = (year + '').substring(2, 4);
		resultDateInFormat = resultDateInFormat.replace('%y', cuttedYear);
	}
	
	return resultDateInFormat;
}

function checkEmail(value){
	var email = /^(\w+)([-+.][\w]+)*@(\w[-\w]*\.){1,5}([A-Za-z]){2,4}$/;	
	return email.test(value);
}

function array_rand ( input, num_req ) {
    // Return key/keys for random entry/entries in the array  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/array_rand
    // +   original by: Waldo Malqui Silva
    // *     example 1: array_rand( ['Kevin'], 1 );
    // *     returns 1: 0
    var indexes = [];
    var ticks = num_req || 1;
    var checkDuplicate = function ( input, value ) {
        var exist = false, index = 0;
        while ( index < input.length ) {
            if ( input [ index ] === value ) {
                exist = true;
                break;
            }
            index++;
        }
        return exist;
    };

    if ( input instanceof Array && ticks <= input.length ) {
        while ( true ) {
            var rand = Math.floor( ( Math.random( ) * input.length ) );
            if ( indexes.length === ticks ) { break; }
            if ( !checkDuplicate( indexes, rand ) ) { indexes.push( rand ); }
        }
    } else {
        indexes = null;
    }

    return ( ( ticks == 1 ) ? indexes.join( ) : indexes );
}

function rusCaseNumber(string, param1, param2, param3)
{	
	string = parseInt(string.toString().slice(-2));
	if (string >= 20)
	{
		string = parseInt(string.toString().slice(-1));
	}
	if (string == 1)
	{
		return param1;
	}
	if (string > 1 && string < 5)
	{
		return param2;
	}
	if (string == 0 || (string > 4 && string < 20))
	{
		return param3;
	}
	return '';
}

function check(r){
	var ua = navigator.userAgent.toLowerCase();
	return r.test(ua);
}

jQuery.extend({
	isOpera: check(/opera/),
	isChrome: check(/chrome/),
	isWebKit: check(/webkit/),
	isSafari: !this.isChrome && check(/safari/),
	isSafari2: this.isSafari && check(/applewebkit\/4/), // unique to Safari 2
	isSafari3: this.isSafari && check(/version\/3/),
	isSafari4: this.isSafari && check(/version\/4/),
	isIE: !this.isOpera && check(/msie/),
	isIE7: this.isIE && check(/msie 7/),
	isIE8: this.isIE && check(/msie 8/),
	isIE6: this.isIE && !this.isIE7 && !this.isIE8,
	isGecko: !this.isWebKit && check(/gecko/),
	isGecko2: this.isGecko && check(/rv:1\.8/),
	isGecko3: this.isGecko && check(/rv:1\.9/)
});


function tick(){}
