function set_focus(d, el)
{
	if (!el)	// if form element not set - do nothing
		return;

	if ((x = findObj(e, d)) != null) {
		if (x.focus)
			x.focus();
		if (x.select)
			x.select();
	}
}

function syn(s)
{
	if (!s || !s.options || !s.options.length) 
		return false;
	
	if (s.options[s.options.length - 1].selected)
		s.options[s.options.length - 1].selected = false;
}

function plesk_scroll(w)
{
	var nav = navigator.appName;
	var ver = parseInt(navigator.appVersion);
	if ((nav.indexOf('Netscape') != -1) && (ver == 4) && w.document.location.hash) {
		var aname = w.document.location.hash.substr(1);
		var an = w.document.anchors[aname];
		if (an)
			w.scrollTo(an.x, an.y);
	}
}

function MM_reloadPage(init)	// reloads the window if Nav4 resized
{
	if (init == true)
		with (navigator) {
			if ((appName == 'Netscape') && (parseInt(appVersion) == 4)) {
				document.MM_pgW = innerWidth;
				document.MM_pgH = innerHeight;
				onresize = MM_reloadPage;
			}
		}
	else
		if ((innerWidth != document.MM_pgW) || (innerHeight != document.MM_pgH))
			location.reload();
}

MM_reloadPage(true);

function getButtonName(name)
{
    re = /^bname_([A-Za-z0-9-]+)$/;
    return name.replace(re,"$1");
}


function isFramed()
{
	return !("undefined" == typeof top.workFrame ||
			 "undefined" == typeof top.topFrame ||
			 "undefined" == typeof top.leftFrame);
}

function topLoaded()
{
	return !("undefined" == typeof top);
}

function workFrameLoaded()
{
	return topLoaded() && !("undefined" == typeof top.workFrame ||
		"undefined" == typeof top.workFrame.document);
}

function topFrameLoaded()
{
	return topLoaded() && !("undefined" == typeof top.topFrame ||
		"undefined" == typeof top.topFrame.document);
}

function leftFrameLoaded()
{
	return topLoaded() && !("undefined" == typeof top.leftFrame ||
		"undefined" == typeof top.leftFrame.document);
}

function conhelpLoaded()
{
	return leftFrameLoaded() && !("undefined" == typeof top.leftFrame.document.forms[0] ||
		"undefined" == typeof top.leftFrame._c);
}

function contextLoaded()
{
	return topLoaded() && !("undefined" == typeof top._context);
}

function helpPrefixLoaded()
{
	return topLoaded() && !("undefined" == typeof top._help_prefix);
}

function helpPermLoaded()
{
	return topLoaded() && !("undefined" == typeof top._helpPerm);
}

function setActiveButtonByName(name)
{
	if (!conhelpLoaded())
		return false;
	
	return top.leftFrame.setActiveNode(name);
}
	
function setActiveButton(o)
{
	if (!conhelpLoaded())
		return false;
	
	return top.leftFrame.setActiveNode(o.id);
}
	
function setScrollInIE()
{
	if (!leftFrameLoaded())
		return;

	var navL = top.leftFrame.document.getElementById ('navArea');
	top.leftFrame.document.body.scroll = (navL.clientHeight > top.leftFrame.document.documentElement.clientHeight || navL.clientWidth > top.leftFrame.document.documentElement.clientWidth) ? 'yes' : 'no';
}

//---------------------------------- redirect

function go_to(href)
{
	return go_to_workframe(href);
}

function go_to_workframe(href)
{
	if (!isFramed())
		return _go_to(this, href);
	if (!workFrameLoaded())
		false;
	else 
		return _go_to(top.workFrame, href);
}

function refresh_leftframe()
{
	go_to_leftframe("/left.php3");
}

function go_to_leftframe(href)
{
	if (!leftFrameLoaded())
		return false;
	else
		return _go_to(top.leftFrame, href);
}

function refresh_topframe()
{
	return go_to_topframe("/top.php3");
}

function go_to_topframe(href)
{
	if (!topFrameLoaded())
		return false;
	else
		return _go_to(top.topFrame, href);
}

function go_to_top(href)
{
	if (!topLoaded())
		return false;
	else
		return _go_to(top, href);
}

function _go_to(target, href)
{
	target.location = href;
	return false;
}

//---------------------------------- conhelp & help

function SetConHelp(conhelp_name, direct)
{
	if (!conhelpLoaded())
		return false;
	return top.leftFrame._SetConHelp(conhelp_name, direct);
}

function SetContext(context)
{
	if (!contextLoaded())
		return false;
	if (context)
		top._context = context;
	return SetConHelp();
}

function GetContext()
{
	if (!contextLoaded())
		return false;
	return top._context;
}

function GetHelpPrefix()
{
	if (!helpPrefixLoaded())
		return false;
	return top._help_prefix;
}

function getHelpPerm()
{
	if (!helpPermLoaded())
		return false;
	return top._helpPerm;
}

function resetHelpPerm()
{
	if (!helpPermLoaded())
		return false;
	top._helpPerm = true;
	return true;
}

function denyHelpPerm()
{
	if (!helpPermLoaded())
		return false;
	top._helpPerm = false;
	return true;
}

function mouse_move(context, direct)
{
	return SetConHelp(context, direct);
}
