
/**
 * 
 * 
 *
 */
if ( typeof( gfx ) == 'undefined' ) gfx = {};

/**
 * 
 * mozhet proveryat tolko svoystva ob'ektov, no ne sami ob'ekti
 * 
 */
gfx.exist = function( objectProperty ) {

	return ( typeof( objectProperty ) != 'undefined' );
};

/**
 * damp massiva dlya prosmotra
 * «38. Malenkie hitrosti JavaScript» D.Koterov
 */
gfx.dump = function( d, l ) {
	
	if ( l == null ) l = 1;

    var s = '';

    if ( typeof( d ) == "object" ) {
		
		s += typeof(d) + " {\n";
        
		for (var k in d) {
            
			for ( var i=0; i<l; i++ ) s += "  ";
            
			s += k+": " + dump( d[k], l+1 );
        }
		for ( var i=0; i<l-1; i++ ) s += "  ";
        
		s += "}\n"
    
	} else {
        
		s += "" + d + "\n";
    }
	return s;
};


/**
 * ne yunikodniy analog escape()
 * IE 5.5+
 * http://xpoint.ru/know-how/JavaScript/PoleznyieFunktsii?26#EscapeSovmestimyiySRusskimiBuk
 */
(function(){
	
	// Initsializiruem tablitsu perevoda
	var trans = [];
	for (var i = 0x410; i <= 0x44F; i++) trans[i] = i - 0x350; // À-ßà-ÿ
	trans[0x401] = 0xA8;    // Yo
	trans[0x451] = 0xB8;    // yo

	gfx.escape = function(str) {
		
		var ret = [];
		// Sostavlyaem massiv kodov simvolov, poputno perevodim kirillitsu
		for ( var i = 0; i < str.length; i++ ) {
			
			var n = str.charCodeAt(i);
			
			if (typeof trans[n] != 'undefined') n = trans[n];
			if (n <= 0xFF) ret.push(n);
		}
		return escape( String.fromCharCode.apply(null, ret) );
	}
})();

/**
 *
 * not unicode analogue encodeURIComponent()
 * http://www.softtime.ru/forum/read.php?id_theme=42665&id_forum=4
 *
 */
gfx.encodeURIComponent = function( value ) {
	
	value = escape(value);

	var utf, win, pos=value.indexOf("%u"); 

	while (pos > -1) { 
		
		utf = value.substring(pos, pos+6); 
		win = "%" + ("BCDEF").charAt(utf.charAt(4)) + utf.charAt(5); 
		value = value.replace(utf, win); 
		pos = value.indexOf("%u"); 
	} 
	return value; 
};

/**
 * 
 * PHP: round
 *
 */
Math.roundWithPrecision = function( value, precision ) {

	var mn = Math.pow( 10, precision );
	
	return Math.round( value * mn ) / mn;
};

/**
 * 
 * 0.7*0.75 == 0.53 !!!
 *
 */
Math.superRoundWithPrecision = function( value, precision ) {

	value = Math.roundWithPrecision( value, precision + 1 );
	value = Math.roundWithPrecision( value, precision );
	
	return value;
};

/**
 * 
 * 
 *
 */
function selectInputObject( inputObject ) {
		
	if ( typeof( inputObject.createTextRange ) != 'undefined' ) { // IE4+
		
		var textRange = inputObject.createTextRange();
		textRange.select();

	} else if ( typeof( inputObject.selectionStart ) != 'undefined' ) { // Mozilla/Gecko
		
		var end = inputObject.value.length;
		inputObject.setSelectionRange( 0, end );
		inputObject.focus();
	}
}

