var created_objects_counter = 0;
var objects_collection = new Array();

function _$(obj)
{
	if (typeof obj == 'string')
	{
		if (typeof objects_collection[obj] != 'object' || objects_collection[obj] == null)
		{
			objects_collection[obj] = document.getElementById(obj);
		}
	}
	return objects_collection[obj] == null ? false : objects_collection[obj];
}

function _$c(type, name, id)
{
	var element = null; 
	try
	{
		element = document.createElement('<' + type + (name != '' && name != undefined ? ' name="' + name + '"' : '') + '>'); 
		element.id = id != '' && id != undefined ? id : 'new_element_' + created_objects_counter;
		created_objects_counter++;
	} catch (e) {} 

	if (!element || element.nodeName != type.toUpperCase())
	{ 
		// Для не IE; использование стандартного метода создания элемента 
		element = document.createElement(type); 
		if (name != '' && name != undefined) element.setAttribute("name", name); 
		element.setAttribute("id", id != '' && id != undefined ? id : 'new_element_' + created_objects_counter); 
		created_objects_counter++;
	} 
	if (typeof element == 'object' && element.id)
		objects_collection[element.id] = element;
	return element; 
}

function _$r(obj)
{
	if (typeof obj == 'string') obj = _$(obj);
	try
	{
		obj = obj.parentNode.removeChild(obj);
		delete obj;
	} catch(e) {}
}

function $ac(owner, child)
{
	if (typeof owner != 'object' || typeof child != 'object')
		return false;
	
	return owner.appendChild(child);
}

function $ib(owner, child, before)
{
	if (typeof owner != 'object' || typeof child != 'object' || typeof before != 'object')
		return false;

	return owner.insertBefore(child, before);
}

function in_array(value, array)
{
	if (typeof array != 'object' || !array || !array.length) return false;
	var l = array.length;
	for(var i = 0; i < l; i++)
	{
		if (value == array[i]) return true;
	}
	
	return false;
}

function array_search(value, array)
{
	l = array.length;
	for(i = 0; i < l; i++)
	{
		if (value == array[i]) return i;
	}
	
	return false;
}

function show(obj)
{
	if (typeof obj != 'object') obj = _$(obj);
	if (obj) obj.style.display = '';
}

function hide(obj)
{
	if (typeof obj != 'object') obj = _$(obj);
	if (obj) obj.style.display = 'none';
}

function isset(obj)
{
	return obj != null && obj != undefined;
}

function set_obj(value)
{
	if (typeof value == 'object')
	{
		var new_value = {};
		for(var k in value)
			new_value[k] = value[k];
	}
	else
		var new_value = value;
	return new_value;
}

function round_value(value,digits)
{
	if (isNaN(digits)) digits = 20;
	value = parseFloat(value);
	if (value == 0) return 0;
	
	var result = '';
	if (digits == 0)
		result = Math.floor(value);

	if (digits < 0)
	{
		digits = Math.abs(digits);
		value *= Math.pow(10, digits);
	}
		
	if (digits > 0)
	{
		value = value.toString();
		value = value.split('.');
		if (isNaN(value[0])) value[0] = '0';
		if (isNaN(value[1])) value[1] = '0';
		result = value[0] + (value[1].length > 0 ? '.' + value[1].substr(0,digits) : '');
	}
	
	var null_pos = parseFloat(result).toString().search(/[0]{8}/);
	if (null_pos > -1)
		result = result.substr(0, null_pos);
	
	return parseFloat(result);
}

function select_set_value(obj, value)
{
	if (!isset(obj) || !obj.tagName || obj.tagName.toLowerCase() != 'select') return;
	for(var i = 0; i < obj.options.length; i++)
	{
		obj.options[i].selected = obj.options[i].value == value;
	}
}

function select_delete_options(obj)
{
	if (!isset(obj) || !obj.tagName || obj.tagName.toLowerCase() != 'select') return;
	while(obj.options.length > 0)
	{
		_$r(obj.options[0]);
	}
}

function select_add_options(obj, options, selected)
{
	if (!isset(obj) || !obj.tagName || obj.tagName.toLowerCase() != 'select') return;
	if (typeof options == 'object')
	{
		for(i = 0; i < options.length; i++)
		{
			opt = _$c("option");
			opt.innerHTML = options[i][1];
			opt.setAttribute("value", options[i][0]);
			if (options[i][0] == selected)
				opt.setAttribute("selected", true);
			$ac(obj, opt);
		}
	}
}

function check_numbers(obj)
{
	var keyCode = (event.charCode) ? event.charCode : event.keyCode;
	return (((event.keyCode == 46) && !Ext.isIE) || (keyCode == 63275) || (keyCode == 0) || (keyCode == 8) || (keyCode == 9) || (keyCode == 37) || (keyCode == 39) || (keyCode > 47 && keyCode < 58));
}