function doMenu(objE)
{
	if (!objE) return;
	var objS	= objE.nextSibling;

	if (objS && (objS.getAttribute('box') == 'b'))
	{
		if (objS.style.display == 'none')
			objE.className = objE.className.replace(/collapsed/, 'expanded');
		else
		{
			objS.style.display	= 'none';
			objE.className = objE.className.replace(/expanded/, 'collapsed');
			return;
		}
	}

	if (objS)
		objS.style.display	= '';
}

function doMenuInit(strMenuBoxID)
{
	var objB	= document.getElementById(strMenuBoxID);
	if (!objB) return;

	var arrD	= objB.getElementsByTagName('div');
	var objE;


	if (typeof(objB.attachEvent) != 'undefined')
	{
		for (var i = arrD.length - 1; i >= 0; i--)
		{
			objE	= arrD[i];
			if (objE.getAttribute('box') == 'm')
			{
				objE.attachEvent('onmouseover', doMenuOver);
				objE.attachEvent('onmouseout', doMenuOut);
			}
		}
	}
	else
	{
		for (var i = arrD.length - 1; i >= 0; i--)
		{
			objE	= arrD[i];
			if (objE.getAttribute('box') == 'm')
			{
				objE.addEventListener('mouseover', doMenuOver, false);
				objE.addEventListener('mouseout', doMenuOut, false);
			}
		}
	}
}

function doMenuOver(event)
{
	var objE	= event.srcElement ? event.srcElement : event.target;
	if (objE)
		objE.className	= objE.className.replace('-normal', '-hover');
}

function doMenuOut(event)
{
	var objE	= event.srcElement ? event.srcElement : event.target;
	if (objE)
		objE.className	= objE.className.replace('-hover', '-normal');
}

//
//	Perform all standart processing then check value.
//	Return FALSE if some checking is failed and TRUE othervise.
//
function fnValueProcess(objE)
{
	if (!objE)
	{
		alert(gstrNoElement);
		return false;
	}

	if (objE.disabled)	return true;

	var intListFlags	= objE.getAttribute('list');
	var intCheckFlags	= objE.getAttribute('check');
	var intCorrectFlags	= objE.getAttribute('correct');
	var strValue		= objE.value;

	if (/^\d+$/.test(intListFlags)) // list
	{
		strValue	= fnValueListCorrect(strValue, intListFlags);

		var	arrValues	= fnValueExplode(strValue, intListFlags);
		var intCount	= arrValues.length;
		var i;

		if (/^\d+$/.test(intCorrectFlags))
		{
			for (i = 0; i < intCount; i++)
				arrValues[i]	= fnValueCorrect(arrValues[i], intCorrectFlags);

			objE.value	= fnValueImplode(arrValues, intListFlags);
		}

		if (/^\d+$/.test(intCheckFlags))
		{
			for (i = 0; i < intCount; i++)
			{
				if (!fnValueCheck(arrValues[i], intCheckFlags))
					return false;
			}
		}
	}
	else // single value
	{
		if (/^\d+$/.test(intCorrectFlags))
		{
			strValue	= fnValueCorrect(strValue, intCorrectFlags);
			objE.value	= strValue;
		}

		if (/^\d+$/.test(intCheckFlags))
			return fnValueCheck(strValue, intCheckFlags);
	}

	// textarea processing
	with (objE)
	{
		if (/textarea/i.test(nodeName))
		{
			var intMax	= getAttribute('maxlength');

			if ((intMax > 0) && (intMax < value.length))
			{
				doFocus(objE);
				alert(gstrTooLongText.replace('{LEN}', value.length).replace('{MAX}', intMax));
				return false;
			}
		}
	}

	return true;
}

//
//	Correct value
//
//	1:	remove spaces
//	2:	remove terminal spaces
//	4:	convert space sequences to single spaces
//	8:	preserve CRLF and convert it to double and more CRLFs into double
//	16:	allow inline HTML
//	32:	allow HTML
//	64: URL
//
function fnValueCorrect(strValue, intFlags)
{
	// spaces
	strValue	= strValue.replace(/[ \t]+(?=[\r\n])/g, '');
	strValue	= strValue.replace(/(\r\n)[ \t]+/g, '$1');
	strValue	= strValue.replace(/([\r\n])[ \t]+/g, '$1');

	if (intFlags & 1)
	{
		strValue	= strValue.replace(/\s+/g, '');
	}
	else
	{
		if (intFlags & 2)
		{
			strValue	= strValue.replace(/(^\s+)|(\s+$)/g, '');
		}

		if (intFlags & 8)
		{
			strValue	= strValue.replace(/(\r\n){2,}/g, '#CRLF2#');
			strValue	= strValue.replace(/(\n{2,})|(\r{2,})/g, '#CRLF2#');
			strValue	= strValue.replace(/(\r\n)/g, '#CRLF#');
			strValue	= strValue.replace(/[\r\n]/g, '#CRLF#');

			if (intFlags & 4)
				strValue	= strValue.replace(/\s{2,}/g, ' ');

			strValue	= strValue.replace(/#CRLF#/g, '\n');
			strValue	= strValue.replace(/#CRLF2#/g, '\n\n');
		}
		else if (intFlags & 4)
		{
			strValue	= strValue.replace(/\s{2,}/g, ' ');
		}
	}

	// HTML
	if (intFlags & 32) // remove hazardous tags
	{
		strValue	= strValue.replace(/<\/?(iframe|script|applet|body|frame|frameset|object|embed)[^>]*>/ig, ' ');
	}
	else
	{
		if (intFlags & 16) // remove block HTML
		{
			strValue	= strValue.replace(/<\/?(h\d+|p|div|iframe|ol|ul|menu|li|dl|dt|dd|table|tbody|thead|tfoot|tr|td|th|script|applet|object|embed)[^>]*>/ig, ' ');
		}
		else // remove all
		{
			strValue	= strValue.replace(/<\/?[a-z]+[^>]*>/ig, ' ');
		}
	}

	// remove javascript:
	strValue	= strValue.replace(/href=(\x22|\x27)javascript:[^>]*>/ig, '>');

	// URL
	if (intFlags & 64)
	{
		if (!/^https?\:\/\//i.test(strValue) && strValue)
		{
			strValue	= 'http://' + strValue;
		}
	}

	return strValue;
}

//
//	Return FALSE if some checking is failed and TRUE othervise
//
//	1: must be non-empty
//	2: must be integer
//	4: must be real
//	8: may be negative
//	16: phone
//	32: mail
//	64: URL
//	128: must have HTML file extension
//	256: ICQ
//	512: must be positive
//	1024: hexadecimal color
//
function fnValueCheck(strValue, intFlags)
{
	if (fnValueFaul(strValue))
	{
		alert(gstrFaulForbidden);
		return false;
	}

	if ((intFlags & 1) && (strValue == ''))
	{
		alert(gstrNoValue);
		return false;
	}

	if (strValue == '')
	{
		return true;
	}

	if ((intFlags & 2) && (!/^(\+|-)?\d+$/.test(strValue)))
	{
		alert(gstrNeedInt);
		return false;
	}

	if ((intFlags & 4) && (!/^(\+|-)?\d+(\.\d+)?$/.test(strValue)))
	{
		alert(gstrNeedReal);
		return false;
	}

	if (intFlags & 6)
	{
		if (intFlags & 512)
		{
			if (strValue <= 0)
			{
				alert(gstrNeedPositive);
				return false;
			}
		}
		else if (!(intFlags & 8))
		{
			if (/-/.test(strValue))
			{
				alert(gstrNeedNonNegative);
				return false;
			}
		}
	}

	if ((intFlags & 16) && (/[^\d\s\-\+\(\)]/.test(strValue) || (strValue.length < 5)))
	{
		alert(gstrInvalidPhone.replace('{PHONE}', strValue));
		return false;
	}

	//if ((intFlags & 32) && (!/^[^@\/\\:]+@([^@\.\/\\:]+\.)+[a-z]{2,4}$/i.test(strValue)))
	if ((intFlags & 32) && (!/^[^@\/\\:]+@([^@\.\/\\:]+\.)+[a-zà-ÿ]{2,4}$/i.test(strValue)))
	{
		alert(gstrInvalidMail.replace('{MAIL}', strValue));
		return false;
	}

	if ((intFlags & 64) && (!/^https?\:\/\/([^\/\\:\s\?]+\.)+[a-z]{2,4}/i.test(strValue)))
	{
		alert(gstrInvalidURL);
		return false;
	}

	if ((intFlags & 128) && (!/\.html?$/i.test(strValue)))
	{
		alert(gstrNeedHTML);
		return false;
	}

	if ((intFlags & 256) && (!/^\d+(-?\d+)*$/i.test(strValue)))
	{
		alert(gstrInvalidICQ);
		return false;
	}

	if ((intFlags & 1024) && !/^[0-9a-f]{6}$/i.test(strValue))
	{
		alert(gstrInvalidColor);
		return false;
	}

	return true;
}

//
//	Check language-specific characters
//
function fnValueCheckLang(strValue, intLang, bolStrict)
{
	if (intLang == 1)
	{
		if (/[a-z]/i.test(strValue))
		{
			if (bolStrict)
			{
				alert(gstrLatinFound);
				return false;
			}
			else
				return confirm(gstrConfirmLatin);
		}
	}
	else if (intLang > 1)
	{
		if (/[à-ÿ]/.test(strValue))
		{
			alert(gstrCyrillicFound);
			return false;
		}
	}

	return true;
}

//
//	Remove terminal and double separators from the list
//
//	1:	preserve space after separator
//	2:	preserve empty elements
//
function fnValueListCorrect(strValue, intFlags)
{
	if (!(intFlags & 2))
	{
		strValue	= strValue.replace(/(^(\s*,\s*)+)|((\s*,\s*)+$)/g, '');
		strValue	= strValue.replace(/(\s*,\s*){2,}/g, ',');
	}

	return strValue;
}

//
//	Replace all ',' with '.'
//
function doValueRealCorrect(objE)
{
	if (objE)
		objE.value	= objE.value.replace(/,/g, '.');
}

//
//	Explode list to array
//
function fnValueExplode(strValue, intFlags)
{
	var arrMatches	= strValue.split(/\s*,\s*/);
	return arrMatches ? arrMatches : [];
}

//
//	Implode array elements to string
//
function fnValueImplode(arrValues, intFlags)
{
	var intCount	= arrValues.length;

	if (!intCount) return '';

	var strValue	= arrValues[0];
	var strSep		= ',' + (intFlags & 1 ? ' ' : '');

	for (var i = 1; i < intCount; i++)
	{
		strValue	+= strSep + arrValues[i];
	}

	return strValue;
}

function fnValueFaul(strValue)
{
	return /(^|[\s\r\n_])(õó[é¸åÿ])|((î|çà|ïðè|ïåðå)õó[åÿ])|(ñ?ï(è|å)çä)|((âû|ïðî)?áëÿä)|(áëÿ([\b\.,]|$))|(ïåäèê)|(ï(è|å)äîð)|((âû|ó|çà|ïåðå)?(å|¸)á(à|è))/i.test(strValue);
}

function fnDateCheck(intDay, intMonth, intYear, intResult)
{
	var objDate = new Date();

	intDay		= intDay * 1 || 0;
	intMonth	= intMonth * 1 || 0;
	intYear		= intYear * 1 || 0;

	// year
	if (intYear < 2004)
	{
		alert(gstrDateInvalidYear);
		return 3;
	}

	if (intYear < objDate.getFullYear())
	{
		if (!confirm(gstrDateConfirmPastYear))
		{
			return 3;
		}
	}

	// month
	if ((intMonth < 1) || (intMonth > 12))
	{
		alert(gstrDateInvalidMonth);
		return 2;
	}

	// check date
	var intMaxDay;

	switch (intMonth)
	{
		case 4: case 6: case 9: case 11:
		{
			intMaxDay = 30; break;
		}
		case 2:
		{
			intMaxDay = 29 - (intYear % 4 ? 1 : 0); break;
		}
		default:
		{
			intMaxDay = 31; break;
		}
	
	}

	// day
	if ((intDay < 1) || (intDay > intMaxDay))
	{
		alert(gstrDateInvalidDate);
		return 1;
	}

	// date
	var objNewDate	= new Date();
	objNewDate.setFullYear(intYear, intMonth - 1, intDay);

	if (objNewDate <= objDate && !confirm(gstrDateConfirmPast))
	{
		return 1;
	}

	return 0;
}

function fnDateObjectCheck(objDate)
{
	if (!objDate) return false;

	with (objDate)
	{
		if (!checked) return true;

		var objD	= form.elements[name + '_day'];
		var objM	= form.elements[name + '_month'];
		var objY	= form.elements[name + '_year'];
	}

	var intError;
	if (intError = fnDateCheck(objD.value, objM.value, objY.value, intError))
	{
		switch (intError)
		{
			case 1: doFocus(objD); break;
			case 2: doFocus(objM); break;
			case 3: doFocus(objY); break;
		}
		return false;
	}

	return true;
}

function doDateEnable(objE)
{
	with (objE)
	{
		var bolOff	= !checked;
		try
		{
			
			var objD	= form.elements[name + '_day'];
			var objM	= form.elements[name + '_month'];
			var objY	= form.elements[name + '_year'];

			objD.disabled	= bolOff;
			objM.disabled	= bolOff;
			objY.disabled	= bolOff;

			if (!bolOff)
			{
				var objDate	= new Date();
				objDate.setTime(objDate.getTime() + 61 * 24 * 3600 * 1000);

				if (objD.value == '')
					objD.value	= objDate.getDate();
				if (objM.value < 1)
					objM.value	= objDate.getMonth() + 1;
				if (objY.value == '')
					objY.value	= objDate.getFullYear();
			}
		}
		catch(e){}
	}
}

function doFocus(objE)
{
	if (objE)
	{
		doOpen(objE);
		if (!objE.disabled)
		{
			objE.focus();
			if (objE.select) objE.select();
		}
	}
}

function doOpen(objE)
{
	if (objE)
	{
		var strCode;
		var objP	= objE;
		while (objP = objP.parentNode)
		{
			if (/^body$/i.test(objP.nodeName))
			{
				break;
			}


			if ((objP.style.display == 'none') && (strCode = objP.getAttribute('openCode')))
			{
				eval(strCode);
			}
		}
	}
}

function fnElementHide(strID)
{
	var objE	= document.getElementById(strID);
	if (objE) objE.style.visibility	= 'hidden';
	return objE;
}

function doElementHide(strID)
{
	fnElementHide(strID);
}

function fnElementContent(strID, strDefaultText)
{
	var objE	= document.getElementById(strID);
	return objE ? objE.innerHTML : strDefaultText;
}

// 
//	Increase textarea
//
function doRowsInc(strID)
{
	var objE	= document.getElementById(strID);
	if (objE) objE.rows	*=2;
}

// 
//	Decrease textarea
//
function doRowsDec(strID, intMin)
{
	var objE	= document.getElementById(strID);
	if (objE) 
	{
		var intRows = Math.floor(objE.rows	/ 2);
		objE.rows	= intRows > intMin ? intRows : intMin;
	}
}

function doNodesInit(intTree, intState)
{
	var oNode, strID;
	if (!intState) intState	= 0;

	for (var intID in gobjNodes[intTree])
	{
		oNode	= gobjNodes[intTree][intID];
		strID	= intTree + '_' + intID;

		oNode.state		= intState;
		oNode.body		= document.getElementById('mt' + strID);
		oNode.childBox	= document.getElementById('nt' + strID);
		oNode.menuImg	= document.getElementById('ni' + strID);
	}
}

//
//	Expand/collapse tree node
//
function doNode(intTree, intID)
{
	var objInfo	= gobjNodes[intTree][intID];

	if (objInfo.state == 1)
	{
		objInfo.state	= 0;
		if (objInfo.menuImg) objInfo.menuImg.src				= gstrBoxPlus;
		if (objInfo.childBox) objInfo.childBox.style.display	= 'none';
	}
	else
	{
		objInfo.state	= 1;
		if (objInfo.menuImg) objInfo.menuImg.src				= gstrBoxMinus;
		if (objInfo.childBox) objInfo.childBox.style.display	= '';
	}
}

function doNodePath(intTree, intID)
{
	if (!gobjNodes[intTree][intID])
		return;

	var objNode, intNodeID = gobjNodes[intTree][intID].p;

	while (objNode = gobjNodes[intTree][intNodeID])
	{
		objNode.state	= 1;
		if (objNode.menuImg) objNode.menuImg.src				= gstrBoxMinus;
		if (objNode.childBox) objNode.childBox.style.display	= '';

		intNodeID	= gobjNodes[intTree][intNodeID].p;
	}
}

function doNodesAll(intTree, bolExpand)
{
	var intState, strImg, strDisplay;

	if (bolExpand)
	{
		intState	= 1;
		strImg		= gstrBoxMinus;
		strDisplay	= '';
	}
	else
	{
		intState	= 0;
		strImg		= gstrBoxPlus;
		strDisplay	= 'none';
		scrollTo(0,0);
	}

	for (var intID in gobjNodes[intTree])
	{
		objInfo	= gobjNodes[intTree][intID];

		objInfo.state	= intState;
		if (objInfo.menuImg) objInfo.menuImg.src				= strImg;
		if (objInfo.childBox) objInfo.childBox.style.display	= strDisplay;
	}
}

function doNodeOption(objE, objParams)
{
	if (!objE.checked) return;

	if (!objParams)
		objParams	= {};
	if (!objParams.attrTreeID)
		objParams.attrTreeID	= 'treeID';
	if (!objParams.attrNodeID)
		objParams.attrNodeID	= 'nodeID';
	if (!objParams.inputPrefix)
		objParams.inputPrefix	= 'gintNode_';

	var intTree	= objE.getAttribute(objParams.attrTreeID);
	var intNode	= objE.getAttribute(objParams.attrNodeID);

	// switch off children
	for (var i = gobjNodes[intTree][intNode].c.length - 1; i >= 0; i--)
		doNodeOptionChildren(intTree, gobjNodes[intTree][intNode].c[i], objParams);

	// switch off parents
	while (intNode = gobjNodes[intTree][intNode].p)
	{
		if (objE = document.getElementById(objParams.inputPrefix + intTree + '_' + intNode))
		{
			if (objE.checked)
			{
				objE.checked	= false;
				if (objParams.onSwitchOff)
					objParams.onSwitchOff(objE);
			}
		}
	}
}

function doNodeOptionChildren(intTree, intNode, objParams)
{
	var objE	= document.getElementById(objParams.inputPrefix + intTree + '_' + intNode);
	if (objE && objE.checked)
	{
		objE.checked	= false;
		if (objParams.onSwitchOff)
			objParams.onSwitchOff(objE);
	}

	for (var i = gobjNodes[intTree][intNode].c.length - 1; i >= 0; i--)
		doNodeOptionChildren(intTree, gobjNodes[intTree][intNode].c[i], objParams);
}

//
//	To enable drag set style='position:absolute' to draggable box and
//	attach three functions below to event handlers. fnOffset() is necessary.
//	IE 5+, Mz1+, Op7+
//
function doDragStart(event)
{
	var objE	= event.srcElement ? event.srcElement : event.target;
	var objB	= objE;
	var bolBox	= false;

	while (objB)
	{
		if (objB.style.position == 'absolute')
		{
			bolBox	= true;
			break;
		}
		objB	= objB.offsetParent;
	}

	if (!bolBox) return;

	var arrOffset	= fnOffset(objB);

	objB.setAttribute('dX', arrOffset[0]);
	objB.setAttribute('dY', arrOffset[1]);
	objB.setAttribute('sX', event.clientX);
	objB.setAttribute('sY', event.clientY);
	objE.setAttribute('oldCursor', objE.style.cursor);
	objE.style.cursor	= 'move';
	
	window.gobjDragElement	= objE;
	window.gobjDragBox		= objB;

	if (!window.gbolDrag)
	{
		window.gbolDrag	= 1;
		var objBody	= document.body;

		if (objBody.addEventListener)
		{
			objBody.addEventListener('mouseup', doDragFinish, false);
			objBody.addEventListener('mousemove', doDrag, false);
		}
		else
		{
			objBody.attachEvent('onmouseup', doDragFinish);
			objBody.attachEvent('onmousemove', doDrag);
		}
	}
}


function doDrag(event)
{
	var objB	= window.gobjDragBox;
	if (!objB) return;

	objB.style.left	= event.clientX - parseInt(objB.getAttribute('sX')) + parseInt(objB.getAttribute('dX')) + 'px';
	objB.style.top	= event.clientY - parseInt(objB.getAttribute('sY')) + parseInt(objB.getAttribute('dY')) + 'px';
}


function doDragFinish()
{
	var objE	= window.gobjDragElement;
	if (objE)
	{
		objE.style.cursor		= objE.getAttribute('oldCursor');
		window.gobjDragElement	= null;
		window.gobjDragBox		= null;
	}
}


function fnOffset(objElement)
{
	var arrOffset	= [0,0];
	var objE		= objElement;

	while (objE)
	{
		arrOffset[0]	+= objE.offsetLeft;
		arrOffset[1]	+= objE.offsetTop;
		objE	= objE.offsetParent;
	}

	return arrOffset;
}

function doScrollIntoView(objE)
{
	var intTop		= fnOffset(objE)[1];
	var intScroll	= document.body.scrollTop;

	if (intTop < intScroll)
		document.body.scrollTop	= intTop;
	else if (intTop + objE.offsetHeight > intScroll + document.body.clientHeight)
		document.body.scrollTop	= intTop + objE.offsetHeight - document.body.clientHeight;
}

function doTab(objControlData, strTabID)
{
	var strDisplay, strClass, objE, objC;
	var objD	= objControlData.sections;

	for (var strID in objD)
	{
		objC	= objD[strID];

		// find tab objects
		if (!objC.outer_box)
		{
			objC.outer_box	= document.getElementById(strID);
			objC.inner_box	= document.getElementById(strID + '_content');
		}

		// show/hide tab
		strDisplay	= strID == strTabID || strTabID == 'all' ? '' : 'none';

		if (objC.inner_box)
			objC.inner_box.style.display	= strDisplay;

		if (objC.outer_box)
			objC.outer_box.style.display	= strDisplay;

		// find menus
		if (!objC.menus)
		{
			objC.menus	= [];

			for (var i = 0; i < objControlData.number; i++)
				if (objE = document.getElementById(objControlData.name + '_' + strID + '_' + i))
					objC.menus[objC.menus.length]	= objE;
		}

		// set menu state
		strClass	= objControlData[strID == strTabID ? 'c_select' : 'c_normal'];

		for (var intMenu in objC.menus)
			objC.menus[intMenu].className	= strClass;
	}
}

function fnFloatTableShow(objE, strTableID, objParams)
{
	if (!objParams)	objParams	= {};

	// correct params
	if (objParams.x_pos != null)
		objParams.x_pos	= objParams.x_pos.toLowerCase();
	if (objParams.y_pos != null)
		objParams.y_pos	= objParams.y_pos.toLowerCase();

	// check params
	if (!/((before|after)_(begin|end))|middle/.test(objParams.x_pos))
		objParams.x_pos	= 'after_end';
	if (!/((before|after)_(begin|end))|middle/.test(objParams.y_pos))
		objParams.y_pos	= 'after_end';
	if (!/^-?\d+$/.test(objParams.x_offset))
		objParams.x_offset	= 0;
	if (!/^-?\d+$/.test(objParams.y_offset))
		objParams.y_offset	= 0;

	var arrOffset	= fnOffset(objE);
	var	intWidth	= objE.offsetWidth;
	var	intHeight	= objE.offsetHeight;
	var objT		= document.getElementById(strTableID ? strTableID : 'tableFloat');
	if (!objT) return;

	// calculate position
	var intTop, intLeft;

	switch (objParams.x_pos)
	{
		case 'before_begin':
			intLeft	= arrOffset[0] - objT.offsetWidth + objParams.x_offset;
			break;

		case 'after_begin':
			intLeft	= arrOffset[0] + objParams.x_offset;
			break;

		case 'middle':
			intLeft	= arrOffset[0] + Math.floor((objE.offsetWidth - objT.offsetWidth) / 2) + objParams.x_offset;
			break;

		case 'before_end':
			intLeft	= arrOffset[0] + objE.offsetWidth - objT.offsetWidth + objParams.x_offset;
			break;

		case 'after_end':
			intLeft	= arrOffset[0] + objE.offsetWidth + objParams.x_offset;
			break;
	}

	switch (objParams.y_pos)
	{
		case 'before_begin':
			intTop	= arrOffset[1] - objT.offsetHeight + objParams.y_offset;
			break;

		case 'after_begin':
			intTop	= arrOffset[1] + objParams.y_offset;
			break;

		case 'middle':
			intTop	= arrOffset[1] + Math.floor((objE.offsetHeight - objT.offsetHeight) / 2) + objParams.y_offset;
			break;

		case 'before_end':
			intTop	= arrOffset[1] + objE.offsetHeight - objT.offsetHeight + objParams.y_offset;
			break;

		case 'after_end':
			intTop	= arrOffset[1] + objE.offsetHeight + objParams.y_offset;
			break;
	}

	// adjust position
	var objBody	= document.body;
	if (intTop + objT.offsetHeight > objBody.scrollTop + objBody.clientHeight)
		intTop	= objBody.scrollTop + objBody.clientHeight - objT.offsetHeight;
	if (intTop < 0)
		intTop	= 0;


	// apply position
	with (objT.style)
	{
		top		= intTop + 'px';
		left	= intLeft + 'px';
		visibility	= 'visible';
	}

	if (intTop > objBody.scrollTop + objBody.clientHeight)
		doScrollIntoView(objT);

	return objT;
}


function doFloatTableShow(objE, strTableID, objParams)
{
	fnFloatTableShow(objE, strTableID, objParams);
}


function doFloatTableHide(strTableID)
{
	var objT	= fnElementHide(strTableID);
	if (objT)
		eval(objT.getAttribute('actionOnClose'));
}

function fnFormRadioValue(arrRadio)
{
	if (!arrRadio)
		return null;

	arrRadio		= arrRadio.length ? arrRadio : [arrRadio];
	var intCount	= arrRadio.length;
	
	for (var i = 0; i < intCount; i++)
		if (arrRadio[i].checked) return arrRadio[i].value;

	return null;
}

function fnFormOptions(arrE, regPrefix)
{
	var arrResult	= {total:0, checked:0};

	for (var i = arrE.length - 1; i >= 0; i--)
	{
		if (regPrefix.test(arrE[i].name))
		{
			arrResult.total++;
			if (arrE[i].checked) arrResult.checked++
		}
	}

	return arrResult;
}

function doForum(objImg)
{
	var strTextID	= objImg.id.replace(/^img/, 'text');
	var objE;

	if (gobjForumData[strTextID])
	{
		objE	= gobjForumData[strTextID];
	}
	else
	{
		gobjForumData[strTextID]	= objE = document.getElementById(strTextID);
	}

	if (objE)
	{
		if (objE.style.display == 'none')
		{
			objE.style.display	= '';
			objImg.src			= gobjForumData['img_collapse'];
		}
		else
		{
			objE.style.display	= 'none';
			objImg.src			= gobjForumData['img_expand'];
		}
	}
}

function doSetRubricTitleAttrs()
{
	for (var i = document.anchors.length - 1; i >= 0; i--)
	{
		switch (document.anchors[i].name)
		{
			case 'ric':
			{
				document.anchors[i].setAttribute('title', gstrCountInRubric);
				break;
			}
			case 'rif':
			{
				document.anchors[i].setAttribute('title', gstrCountInSubRubrics);
				break;
			}
		}
	}
}

function doUpdateLink(strLink, objE)
{
	if (!fnValueProcess(objE))
	{
		doFocus(objE);
		document.getElementById(strLink).href	= 'about:blank';
		return false;
	}

	document.getElementById(strLink).href	= objE.value;
}

function doHover(objE, bolHover)
{
	objE.className	= bolHover ? objE.className.replace('normal', 'hover') : objE.className.replace('hover', 'normal');
}

function doSelect(objE)
{
	objE.className	= /hover/.test(objE.className) ? objE.className.replace('hover', 'selected') : objE.className.replace('selected', 'hover');
}

function doClass(objE, regFrom, strTo)
{
	objE.className = objE.className.replace(regFrom, strTo);
}

function doMsgMenu(objC, intMsg, intTree)
{
	with (gobjMsgs)
	{
		if (objC == objSwitcher) 
		{
			doElementHide('gobjMsgMenuBox');
			if (objSwitcher)
			{
				objSwitcher.src	= strImgMenuOn;
				objSwitcher		= null;
			}
		}
		else
		{
			if (objSwitcher)
			{
				doElementHide('gobjMsgMenuBox');
				objSwitcher.src	= strImgMenuOn;
			}

			gobjMsgs.intMsgID	= intMsg;

			objSwitcher		= objC;
			objSwitcher.src	= strImgMenuOff;

			var objTable	= fnFloatTableShow(objC, 'gobjMsgMenuBox', {x_offset: -29});
			if (objTable)
				objTable.setAttribute('actionOnClose', 'doMsgMenu(gobjMsgs.objSwitcher)');
		}
	}
}

function doMsgFormClear(objC, strMsg)
{
	if (!confirm(strMsg)) return;

	var objForm	= objC.form;
	objForm.gstrTitle.value	= '';
	objForm.gstrText.value	= '';
}

function fnMsgRe(strText)
{
	var arrMatches	= strText.match(/^Re\s*(\[(\d+)\])?\:\s+/i);

	return arrMatches ? (strText.replace(arrMatches[0], arrMatches[2] ? ('Re[' + (parseInt(arrMatches[2]) + 1) + ']: ') : 'Re[1]: ')) : ('Re: ' + strText);
}

function doMsg(intTree, intMsg)
{
	doMsgExpand(intTree, intMsg);
	doNodePath(intTree, intMsg);
	doScrollIntoView(fnBoxHighlight('mt' + gobjMsgs.intTreeID + '_' + intMsg, true));
}

function doMsgParent(intMsgID)
{
	fnBoxHighlight('mt' + gobjMsgs.intTreeID + '_' + fnMsgSiblingsCollapse(gobjMsgs.intTreeID, intMsgID, true), true, true);
}

function doMsgParentShow()
{
	doFloatTableHide('gobjMsgMenuBox');

	if (gobjMsgs.intMsgID && gobjNodes[gobjMsgs.intTreeID])
		fnBoxHighlight('mt' + gobjMsgs.intTreeID + '_' + fnMsgSiblingsCollapse(gobjMsgs.intTreeID, gobjMsgs.intMsgID, true), true, true);
}

function doMsgRootShow()
{
	doFloatTableHide('gobjMsgMenuBox');

	if (gobjMsgs.intMsgID && gobjNodes[gobjMsgs.intTreeID])
	{
		var intMsg	= gobjMsgs.intMsgID;
		var intFirstID;

		while (intMsg)
		{
			intMsg	= fnMsgSiblingsCollapse(gobjMsgs.intTreeID, intMsg, true);
			fnBoxHighlight('mt' + gobjMsgs.intTreeID + '_' + intMsg, true, false);
			if (!intFirstID) intFirstID	= intMsg;
		}

		if (intFirstID)
		{
			var objE	= document.getElementById('mt' + gobjMsgs.intTreeID + '_' + intFirstID);
			if (objE) doScrollIntoView(objE);
		}
	}
}

function fnMsgSiblingsCollapse(intTree, intMsg, bolSkipTail)
{
	var intParent, objTree	= gobjNodes[intTree];

	if (!(objTree[intMsg] && objTree[intParent = objTree[intMsg].p]))
		return 0;

	var aSiblings	= objTree[intParent].c;
	var intSib, objE;

	for (var i = 0, nCount = aSiblings.length; i < nCount; i++)
	{
		if ((intSib = aSiblings[i]) != intMsg)
		{
			if (objTree[intSib].state) 
				doNode(intTree, intSib);

			if (objE = objTree[intSib].body)
			{
				objE.style.display	= 'none';
				if (objE = objE.previousSibling) objE.style.display	= 'block';
			}
		}
		else if (bolSkipTail)
			break;
	}

	return intParent;
}

function doMsgExpand(intTree, intMsg)
{
	var objNode, objE, objTree	= gobjNodes[intTree];

	if (objTree && (objNode = objTree[intMsg]) && (objE = objNode.body))
	{
		objE.style.display	= '';
		if (objE = objE.previousSibling) objE.style.display	= 'none';
	}
}

function doMsgChildrenExpand()
{
	doFloatTableHide('gobjMsgMenuBox');

	var objNode, objTree = gobjNodes[gobjMsgs.intTreeID];

	if (objTree && (objNode = objTree[gobjMsgs.intMsgID]))
		fnMsgChildBodiesExpand(objTree, objNode.c)
}

function fnMsgChildBodiesExpand(objTree, arrChildren)
{
	var objE;

	for (var i = 0, nCount = arrChildren.length; i < nCount; i++)
	{
		if (objE = objTree[arrChildren[i]].body)
		{
			objE.style.display	= '';
			if (objE = objE.previousSibling) objE.style.display	= 'none';
		}
	}
}

function doMsgAllExpand()
{
	doFloatTableHide('gobjMsgMenuBox');

	var objNode, objE, objTree	= gobjNodes[gobjMsgs.intTreeID];

	if (objTree)
		for (var intMsg in objTree)
			fnMsgChildBodiesExpand(objTree, objTree[intMsg].c);
}

function doMsgShift()
{
	var objBody	= document.getElementById('cellDataRight');
	if (!objBody) return;

	var arrDivs	= objBody.getElementsByTagName('div');
	if (!arrDivs) return;

	var intCount	= arrDivs.length;
	var objE, strOldClass, strNewClass;

	for (var i = 0; i < intCount; i++)
	{
		objE	= arrDivs[i];
		if (/shift-(left|none)/.test(objE.className))
		{
			if (/shift-left/.test(objE.className))
			{
				strOldClass	= 'shift-left';
				strNewClass	= 'shift-none';
			}
			else
			{
				strOldClass	= 'shift-none';
				strNewClass	= 'shift-left';
			}
			break;
		}
	}

	for (i = 0; i < intCount; i++)
		arrDivs[i].className	= arrDivs[i].className.replace(strOldClass, strNewClass);
}

function fnBoxHighlight(strID, bolOn, bolMove)
{
	var objE	= document.getElementById(strID);
	if (objE)
	{
		if (bolOn)
		{
			objE.className	= objE.className + ' highlight-border';
			if (bolMove) doScrollIntoView(objE);
			setTimeout('fnBoxHighlight("' + strID + '")', 2000);
		}
		else
		{
			objE.className	= objE.className.replace(' highlight-border', '');
		}
	}
	return objE;
}

function doBoxExp(strPrefix)
{
	var objHead	= document.getElementById(strPrefix + '-head');
	var objBox	= document.getElementById(strPrefix + '-box');
	if (objBox && objHead)
	{
		if (objBox.style.display == 'none')
		{
			objBox.style.display	= '';
			objHead.className		= objHead.className.replace('-closed', '-opened');
		}
		else
		{
			objBox.style.display	= 'none';
			objHead.className		= objHead.className.replace('-opened', '-closed');
			doScrollIntoView(objHead);
		}
	}
}

function doInfoBox(objE)
{
	var objStyle	= objE.nextSibling.style;
	if (objStyle.display == 'none')
	{
		objStyle.display	= '';
		objE.className	= objE.className.replace('-closed', '-opened');
	}
	else
	{
		objStyle.display	= 'none';
		objE.className	= objE.className.replace('-opened', '-closed');
	}
}

function doEnableForum()
{
	var objForm	= document.forma;

	if (!objForm.gintOption_4) return;

	var bolDisabled	= objForm.gintOption_4.checked;
	var objE;
	var intGroup	= 1;

	for (var intIndex = 1; intIndex < 33; intIndex++)
	{
		if (objE = objForm['gintForum_' + intGroup]) objE.disabled = bolDisabled;
		if (objE = objForm['gintDisc_' + intGroup]) objE.disabled = bolDisabled;
		intGroup *= 2;
	}

	if (objE = objForm.gintSubscriptControl)
		objE.disabled	= bolDisabled;
}

function doEnableDeletion()
{
	var objForm	= document.forma;
	var objE	= objForm.btnDelete;

	if (objForm.gintFlag_8 && objE)
		objE.disabled = objForm.gintFlag_8.checked;
}

function doEM()
{
	var strMail	= arguments[0] + '@' + arguments[1];

	for (var i = 2, nCount = arguments.length; i < nCount; i++)
		strMail	+= '.' + arguments[i];

	document.write('<A href="mailto:' + strMail + '">' + strMail + '</A>');
}

function doMenuIco(strID)
{
	document.write('<DIV class="menu-ico"><DIV class="menu-ico-bg"><DIV id="' + strID + '"></DIV></DIV></DIV>');
}

function doTop(objE)
{
	window.scrollTo(0,0);
	if (objE && objE.blur) objE.blur();
}

function doEnableNext(objE)
{
	objE.nextSibling.value	= objE.checked ? 1 : 0;
}

function fnElementStyle(strID, strProperty)
{
	var objE = document.getElementById(strID);
	if (!objE) return '';

	if (objE.currentStyle)
	{
		return objE.currentStyle[strProperty] || '';
	}
	else 
	{
		var oStyle	= window.getComputedStyle(objE, null);
		return oStyle[strProperty] || '';
	}
}

function doSetupColorPicker(objCP, strOldColor, strBoxID)
{
	if (strOldColor)
	{
		objCP.doPutHex(strOldColor);
	}
	else
	{
		var strColor = fnElementStyle(strBoxID, 'backgroundColor').replace(/(^\s+)|(\s+$)/g, '');

		if (/^#/.test(strColor))
			objCP.doPutHex(strColor);
		else
		{
			var arrMatches	= strColor.match(/\d+/g);
			objCP.doPutRGB(arrMatches[0], arrMatches[1], arrMatches[2]);
		}
	}
}
