﻿var dm;
var pageId;
var linkId;
var gdh = false;

function Nav(me)
{
	var u = new String(me.href);
	u = u.toLowerCase();
	u = u.shave(dm.toLowerCase());
	u = u.shave('.aspx');

	if (u.toLowerCase() == pageId.toLowerCase())
	{
		if (IsVisible('ContentBox') == true)
		{
			CollapseContentBox();
		}
		else
		{
			showElm('ContentBox');
			getElm(linkId).className = 'On';
			try { window.focus(); } catch (e) { }
		}
		return false;
	}
	else
	{
		return true;
	}

}

function CollapseContentBox()
{
	hideElm('ContentBox');
	getElm(linkId).className = 'OnArrow';
	try { window.focus(); } catch (e) { }
}

function OpenBoxDelay()
{
	setTimeout('showElm(\'ContentBox\')', 1000);

	if (gdh == true)
	{
		var aif = document.getElementsByTagName('IFRAME');
		if (aif)
		{
			if (aif.length > 0)
			{
				try { SetElementStyles(getElm(aif[0]), { 'display': 'none' }); } catch (e) { }
				document.body.style.margin = '30px';
			}
		}
	}
}

//#################################

function $(i) { return document.getElementById(i); }

function getElm(s)
{
	if (typeof s == 'object') { return s; }
	else { return $(s); }
}

function hideElm()
{
	a = hideElm.arguments;
	var elm = null;
	for (i = 0; i < a.length; i++)
	{
		try { SetElementStyles(getElm(a[i]), { 'display': 'none' }); } catch (e) { }
	}
}

function showElm()
{
	a = showElm.arguments;
	for (i = 0; i < a.length; i++)
	{
		try { SetElementStyles(getElm(a[i]), { 'display': '' }); } catch (e) { }
	}
}

function hideElmAfterDelay(elm, delay)
{
	window.setTimeout('hideElm(' + elm + ')', delay);
}

function SetElementStyles(elm, styleDict)
{
	var style = elm.style;
	for (var styleName in styleDict)
	{
		style[styleName] = styleDict[styleName];
	}
}

function IsVisible(elm)
{
	return (getElm(elm).style.display != 'none' && getElm(elm).style.visibility.toLowerCase() != 'hidden');
}

/* USEFUL */
String.prototype.lTrim = function ()
{
	return this.replace(/^(\s|\xA0)*/, "");
};
String.prototype.rTrim = function ()
{
	return this.replace(/(\s|\xA0)*$/, "");
};
String.prototype.trim = function ()
{
	return this.rTrim().lTrim();
};
String.prototype.endsWith = function (c)
{
	return this.substr(this.length - c.length) == c;
};
String.prototype.startsWith = function (e)
{
	return this.substr(0, e.length) == e;
};
String.prototype.format = function ()
{
	var s = this;
	for (var i = 0;
    i < arguments.length; i++)
	{
		s = s.replace("{" + i + "}", arguments[i]);
	}
	return s;
};
String.prototype.shave = function (f)
{
	var s = this;

	if (s.startsWith(f)) { s = s.substring(f.length, s.length); }
	if (s.endsWith(f)) { s = s.substring(0, s.length - f.length); }

	return s;
};
