//	dhtml

//	uses utilities;

//	custom alert()

function setBack(obj, hasFocus)
{
	var msgTitle = getEl('wTitle');
	if (hasFocus)
	{
		obj.style.borderColor = mainColor[0];
		msgTitle.style.backgroundColor = mainColor[0];
		msgTitle.style.color = "white";
	}
	else
	{
		obj.style.borderColor = filetColor[1];
		msgTitle.style.backgroundColor = mainColor[1];
		msgTitle.style.color = "black";
	}
}

function myAlert(message, showIt, title)
{
	if (title == undefined) title = "Message";
	if (showIt == undefined) showIt = true;
	var msgWindow = getEl('wAlert');
	if (showIt)
	{
		var msgTitle = getEl('wTitle');
		var msgText = getEl('wText');

		if (title == undefined) title = "Message";
		msgTitle.innerHTML = title;
		msgText.innerHTML = message;
		
		setBack(msgWindow, false);

		msgWindow.style.visibility = "visible";	
		msgWindow.style.left  = xKeep;	
		msgWindow.style.top = yKeep;	
	}
	else msgWindow.style.visibility = "hidden";	
}

function searchId(obj, srchId)
{
	if (obj != null)
	{
		if (obj.id != undefined)
		{
			if (obj.id == srchId) return obj;
		};
		return searchId(obj.parentNode, srchId);
	}
	else return null;
};

//	styles

function getCSSAttribute(ruleName, at)
{
	//	getCSSAttribute(".infoNumber", "backgroundColor")
	with (document)
	{
		for (var j = 0; j <= styleSheets.length - 1; j += 1)
		{
			var ss = styleSheets[j];
			with (ss)
				if (isIE())
					for (var i = 0; i <= rules.length - 1; i += 1)
					{
						if (rules[i].selectorText.toUpperCase() == ruleName.toUpperCase()) return rules[i].style[at];
					}
				else
					for (var i = 0; i <= cssRules.length - 1; i += 1)
					{
						if (cssRules[i].selectorText.toUpperCase() == ruleName.toUpperCase()) return cssRules[i].style[at];
					};
		};
	};
};

function getCSSText(ruleName)
{
	with (document)
	{
		for (var j = 0; j <= styleSheets.length - 1; j += 1)
		{
			var ss = styleSheets[j];
			with (ss)
				if (isIE())
					for (var i = 0; i <= rules.length - 1; i += 1)
					{
						if (rules[i].selectorText.toUpperCase() == ruleName.toUpperCase()) return rules[i].style.cssText;
					}
				else
					for (var i = 0; i <= cssRules.length - 1; i += 1)
					{
						if (cssRules[i].selectorText.toUpperCase() == ruleName.toUpperCase()) return cssRules[i].style.cssText;
					};
		};
	};
};

function setCls(obj, className)
{
	obj.className = className;
};

function searchCls(obj, srchCls)
{
	if (obj != null)
	{
		if (obj.className != undefined)
		{
			if (left(obj.className, srchCls.length) == srchCls)	return obj;
		};
		return searchCls(obj.parentNode, srchCls);
	}
	else return null;
};

function getRuleFromStyle(styleTitle, ruleName)
{
	with (document)
	{
		for (var j = 0; j <= styleSheets.length - 1; j += 1)
		{
			var ss = styleSheets[j];
			if (ss.title == styleTitle)
			{
				with (ss)
				{
					if (isIE())
						for (var i = 0; i <= rules.length - 1; i += 1)
						{
							if (rules[i].selectorText == ruleName) return rules[i].style;
						}
					else
						for (var i = 0; i <= cssRules.length - 1; i += 1)
						{
							if (cssRules[i].selectorText == ruleName) return cssRules[i].style;
						};
				};
			};
		};
	};
};

function posObj(src, dest, styleName, l, t, h)
{
	if (l == undefined) l = 0;
	if (t == undefined) t = 0;
	if (h == undefined) h = 0;

	var stop = (dest.style.position == 'absolute');
	if (!stop)
		if (dest.className != "")
		{
			var obj = getRuleFromStyle(styleName, '.' + dest.className);
			if (obj != undefined) stop = (obj.position == 'absolute');
		};
	if (stop)
	{
		src.style.left = l ;
		src.style.top = t + h ;
	}
	else
	{
		if (dest.offsetParent == null)
		{
			src.style.left = dest.offsetLeft + l;
			src.style.top = dest.offsetTop + t + h;
		}
		else
			posObj(src, dest.offsetParent, styleName, l + dest.offsetLeft, t + dest.offsetTop, h);
	};
};

function bodyDim(isWidth)
{
	if (isIE())
	{
		if (isWidth)
			return document.body.offsetWidth;
		else
			return document.body.offsetHeight;
	}
	else
	{
		if (isWidth)
			return innerWidth;
		else
			return innerHeight;
	};
};

function dumpOffset(id)
{
	var obj = getEl(id);
	var tmp = "";
	tmp += "id=" + obj.id;
	tmp += ";offsetLeft=" + obj.offsetLeft;
	tmp += ";offsetTop=" + obj.offsetTop;
	tmp += ";offsetWidth=" + obj.offsetWidth;
	tmp += ";offsetHeight=" + obj.offsetHeight;
	return tmp;
};

function dumpStyle(id)
{
	var obj = getEl(id).style;
	var tmp = "";
	tmp += "id=" + id;
	tmp += ";left=" + obj.left;
	tmp += ";top=" + obj.top;
	tmp += ";width=" + obj.width;
	tmp += ";height=" + obj.height;
	return tmp;
};
