/*
	Copyright 2003-2009 LigoMaster
*/

///////////////////////////////////////////////////////////////////////////

function get_by_id(id) // поиск обекта 
{
	if(document.all) return(document.all.item(id));
	if(document.getElementById) return(document.getElementById(id));
	return(false);
}

function getXY(obj) 
{
	var o = obj;
	var coords = {left: 0, top: 0}
	while (o && o.tagName != "BODY")
	{
		coords.left += o.offsetLeft;
		coords.top += o.offsetTop;
		o = o.offsetParent;
	}
	return coords;
}

function getXY_by_parentObject(o, parentObject_id)
{
  var c = {left:o.offsetLeft, top:o.offsetTop}, p = o.offsetParent;
  while (p && p.id != parentObject_id)
  {
    c.left += p.offsetLeft;
    c.top += p.offsetTop;
    p = p.offsetParent;
  }
  return c;
}

///////////////////////////////////////////////////////////////////////////
/* KSS: Get next or previous sibling node element */
function get_nextSibling(obj)
{
	var x = obj.nextSibling;
	while (x != null && x.nodeType != 1)
	{
		x = x.nextSibling;
	}
	return x;
}

function get_previousSibling(obj)
{
	var x = obj.previousSibling;
	while (x != null && x.nodeType != 1)
	{
		x = x.previousSibling;
	}
	return x;
}

function setClass(obj, cl, mode)
{
	var c = obj.className || "";
	var mask = new RegExp("(^| )" + cl + "($| )", "gi");
	if (mode == "?") mode = !c.match(mask);
	c = mode ? (c.match(mask) ? c : (c+" "+cl)) : c.replace(mask, " ");
	obj.className = c.replace(/ +/g, " ").replace(/(^ *| *$)/g, "");
}

///////////////////////////////////////////////////////////////////////////
// add/delete events
function addEventHandler(obj, name, func)
{
	if ( document.addEventListener ) obj.addEventListener( name, func, false );
	else if ( document.attachEvent ) obj.attachEvent( 'on' + name, func );
	else throw 'Error';
}

function removeEventHandler(obj, name, func)
{
	if( document.removeEventListener ) obj.removeEventListener( name, func, false );
	else if ( document.detachEvent ) obj.detachEvent( 'on' + name, func );
	else throw 'Error';
}

function cancelEvent( event, allowDefault )
{
	event.cancelBubble=true;
	if (!allowDefault) event.returnValue = false;
	if (event.stopPropagation) event.stopPropagation();
	if (!allowDefault && event.preventDefault) event.preventDefault();
}

///////////////////////////////////////////////////////////////////////////
//
function put_m_text(a1, a2, txt)
{
	var m = a1+String.fromCharCode(60+4)+a2;
	if (txt == null) txt = ml
	document.write('<a href="ma'+'ilto:'+m+'">'+txt+'</a>');
}

///////////////////////////////////////////////////////////////////////////

function get_number(value)
{
	var x = ''+value;
	x = x.replace(',', '.');
	while(x.indexOf(' ') >= 0) { x = x.replace(' ', ''); }
	x = parseFloat(x);
	return isNaN(x) ? 0 : x;
}

///////////////////////////////////////////////////////////////////////////

function limited_text_check_len(id, init)
{
	var txt = get_by_id(id);
	var cnt = get_by_id(id+'_backcounter');
	var	len = get_by_id(id+'_maxlen');
	if (!txt || !cnt || !len) return;
	var maxlen = get_number(len.value);
	if (txt.value.length > maxlen)
	{
		txt.value = txt.value.substring(0, maxlen);
		if (init == null) txt.focus();
	}
	cnt.value = maxlen - txt.value.length;
}

///////////////////////////////////////////////////////////////////////////

function show_item(obj) { obj.style.visibility = 'visible'; }
function hide_item(obj) { obj.style.visibility = 'hidden'; }

///////////////////////////////////////////////////////////////////////////

function text_to_html(str)
{
	str = '' + str;
	var amp = String.fromCharCode(0xFF);
	while(str.indexOf('&') >= 0) { str = str.replace('&', amp); }
	while(str.indexOf(amp) >= 0) { str = str.replace(amp, '&amp;'); }
	while(str.indexOf('<') >= 0) { str = str.replace('<', '&lt;'); }
	while(str.indexOf('>') >= 0) { str = str.replace('>', '&gt;'); }
//	while(str.indexOf(' ') >= 0) { str = str.replace(' ', '&nbsp;'); }
	while(str.indexOf('"') >= 0) { str = str.replace('"', '&quot;'); }
//	document.write(str);
	return str;
}

function text_to_html_br(str)
{
	str = text_to_html(str);
	while(str.indexOf('\n') >= 0) { str = str.replace('\n', '<BR />'); }
//	document.write(str);
	return str;
}

///////////////////////////////////////////////////////////////////////////

function tree_onclick(e)
{
	var ns6=document.getElementById&&!document.all

	if (!document.all&&!ns6) return
	var etarget=ns6?e.target:event.srcElement
	var imagetarget=etarget
	if (etarget.id=="foldheader"||ns6&&etarget.parentNode.id=="foldheader")
	{
		if (ns6&&etarget.parentNode.id=="foldheader")
		{
			nested=etarget.parentNode.nextSibling.nextSibling
			imagetarget=etarget.parentNode
		}
		else nested =ns6?etarget.nextSibling.nextSibling:document.all[etarget.sourceIndex+1]
		if (nested.style.display=="none")
		{
			nested.style.display=''
			imagetarget.style.listStyleImage="url(/img/icons/tree_minus.gif)"
		}
		else
		{
			nested.style.display="none"
			imagetarget.style.listStyleImage="url(/img/icons/tree_plus.gif)"
		}
	}
}

///////////////////////////////////////////////////////////////////////////

function submit_form(formID)
{
	document.forms[formID].submit();
}

function show_mes_focus(id, text, lost)
{
	var o = get_by_id(id);
	if (!o) return;
	if (lost)
	{
		if (!o.value) o.value = text;
	}
	else
	{
		if (o.value == text) o.value = '';
	}
}

/*
startList = function()
{
	if (document.all&&document.getElementById)
	{
		navRoot = document.getElementById("submenu_nav");
		for (i=0; i<navRoot.childNodes.length; i++)
		{
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI")
			{
				node.onmouseover = function() { this.className+=" over"; }
				node.onmouseout=function() { this.className=this.className.replace(" over", ""); }
			}
		}
	}
}

window.onload=startList;
*/

///////////////////////////////////////////////////////////////////////////
/**
 * Main Menu Animation
 */

function mm_move_over(evt)
{
	evt = evt || window.event;
	var ns6 = document.getElementById && !document.all;
	var etarget = ns6 ? evt.target : evt.toElement;
	switch (etarget.tagName)
	{
	case 'A':
		var div = etarget.parentNode;
		setClass(etarget, 'pressed', true);
//		etarget.style.top = '35px';
		etarget.style.backgroundPostion = '';
		if (ns6) div.style.backgroundImage = 'url(/img/style/but_mm_active.png)';
		else div.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/img/style/but_mm_active.png')"; // ,sizingMethod='scale'

		if (ns6) evt.stopPropagation();	// I?ae?auaao aaeuiaeoaa ?ani?ino?aiaiea niauoey.
		else evt.cancelBubble = false;	// I?ina?eaaaony ee aaiiia niauoea.
		break;
	}
}

function mm_move_out(evt)
{
	evt = evt || window.event;
	var ns6 = document.getElementById && !document.all;
	var etarget = ns6 ? evt.target : evt.fromElement;
	switch (etarget.tagName)
	{
	case 'A':
		var div = etarget.parentNode;
		setClass(etarget, 'pressed', false);
//		etarget.style.top = '24px';
		if (ns6) div.style.backgroundImage = 'url(/img/style/but_mm.png)';
		else div.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/img/style/but_mm.png')"; // ,sizingMethod='scale'

		if (ns6) evt.stopPropagation();	// I?ae?auaao aaeuiaeoaa ?ani?ino?aiaiea niauoey.
		else evt.cancelBubble = false;	// I?ina?eaaaony ee aaiiia niauoea.
	}
}

function mm_move_init(menu_id)
{
	var ns6 = document.getElementById && !document.all;
	var div = get_by_id(menu_id);
	var as = div.getElementsByTagName('LI');
	for(var k = 0; k < as.length; k++)
	{
		var a = as[k];
		if (ns6) a.style.backgroundImage = 'url(/img/style/but_mm.png)';
		else a.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/img/style/but_mm.png')"; // ,sizingMethod='scale'
	}
	var as = div.getElementsByTagName('A');
	for(var k = 0; k < as.length; k++)
	{
		var a = as[k];
		addEventHandler(a, 'mouseover', mm_move_over);
		addEventHandler(a, 'mouseout', mm_move_out);
/*		if (!ns6)
		{
			alert(a.id+'='+a.style.backgroundImage)
//			setClass(a, 'ie6', true);
		}*/
	}
}

