UtilsIncluded = true;
//Check user agent. If it is Microsoft Internet Explorer function will return true, if no - false
function IsMSIE()
{
	return navigator.userAgent.indexOf("MSIE") > -1;
}
// Incapsulates alghoritm of retriving custom node attribute depend on user agent type
// Example: If you have attribute <input id="Control" type="text" SomeAttribute="test"> You cannot
// retrive it as Control.SomeAttribute, becouse it not will work in Netscape or Mosilla. 
function GetAttribute(Control, Attribute)
{
	if(IsMSIE())
		return eval("Control." + Attribute);
	if(Control.attributes == null || Control.attributes[Attribute] == null)
		return null;
	return Control.attributes[Attribute].value;
}
// Trim's string value
function Trim(src)
{
	var res=src.replace(/^ +/,''); 
	res=res.replace(/ +$/,'');
	return res;
}
// Mark's option for provided select as selected depend on it value
function SelectOption(SelectID, SelectedValue)
{
	var select = SearchControl(SelectID);
	if(select == null)
		uRaiseError("Object with id \"" + SelectID + "\" not found.");
	if(select.type != "select-one")
		uRaiseError("Object with id \"" + SelectID + "\" have incorrect type \"" + select.type + "\".");
	for(var i=0; i<select.options.length; i++)
	{
		if(select.options[i].value == SelectedValue)
		{
			select.options[i].selected = true; 
			break;
		}
	}
}

// Clear's all options in select
function ClearOptions(SelectID)
{
	var select = SearchControl(SelectID);
	if(select == null)
		uRaiseError("Object with id \"" + SelectID + "\" not found.");
	if(select.type != "select-one")
		uRaiseError("Object with id \"" + SelectID + "\" have incorrect type \"" + select.type + "\".");
	//This method tested on MSIE5+, Firefox 1.0.1
	select.options.length = 0;
	//if not work try to
	//while(select.options.length != 0) 
	//{
	//	select.remove(0);
	//}
}

// Add new option to select
function AddOption(SelectID, OptionValue, OptionText)
{
	var select = SearchControl(SelectID);
	if(select == null)
		uRaiseError("Object with id \"" + SelectID + "\" not found.");
	if(select.type != "select-one")
		uRaiseError("Object with id \"" + SelectID + "\" have incorrect type \"" + select.type + "\".");
	//This method tested on MSIE5+, Firefox 1.0.1
	if(IsMSIE())
	{
		//For MSIE last parameter null(in the else cause) throwed exception
		select.add(new Option(OptionText, OptionValue, false, false));
	}
	else
	{
		select.add(new Option(OptionText, OptionValue, false, false), null);
	}
}

// Mark's option for provided select as selected depend on it value
function SelectRadioButton(GroupName, SelectedValue)
{
	var namedElements = document.getElementsByName(GroupName);
	if(namedElements.length == 0)
		uRaiseError("Cannot Find Object, Object not found. Provided Group Name: \"" + GroupName + "\"");

	//var i;
	for(var i = 0; i < namedElements.length; i++)
	{
		namedElements[i].checked = (namedElements[i].value == SelectedValue);
		if(namedElements[i].checked) break;
	}
}

function SearchControl(ControlID)
{
	var Control = document.getElementById(ControlID);
	if(Control == null)
	{
		var namedElements = document.getElementsByName(ControlID);
		if(namedElements.length == 0)
			uRaiseError("Cannot Find Object, Object not found. Provided ID: \"" + ControlID + "\"");
		if(namedElements.length == 1)
			Control = namedElements[0];
		else if(namedElements.length > 1)
			uRaiseError("Cannot Find Object, the are several objects with same name. Provided ID: \"" + ControlID + "\"");
	}
	return Control;
}

function uRaiseError(Message)
{
	alert("Incorrect usage of Utils.js module\r\n" + Message);
	throw Message;
}

function SetDisable(ControlID)
{
	var Control = SearchControl(ControlID);
	Control.style.color = "#5C5C5C";
	Control.disabled = true;
}

function SetEnable(ControlID)
{
	var Control = SearchControl(ControlID);
	Control.style.color = "#000000";
	Control.disabled = false;
}