
document.onmouseover = doOver;
document.onmouseout  = doOut;
document.onmousedown = doDown;
document.onmouseup   = doUp;


function doOver() {
	var toOl = getReal(window.event.toElement, "className", "linkButton");
	var fromOl = getReal(window.event.fromElement, "className", "linkButton");
	if (toOl == fromOl) return;
	var ol = toOl;
	
//	alert(ol);
	
//	var cDisabled = ol.getAttribute("cDisabled");
	var cDisabled = ol.cDisabled;
//	alert(cDisabled);
	cDisabled = (cDisabled != null); // If CDISABLED atribute is present
	
	if (ol.className == "linkButton")
		ol.onselectstart = new Function("return false");
	
	if ((ol.className == "linkButton") && !cDisabled) {
		makeRaised(ol);
		makeGray(ol,false);
	}
}

function doOut() {
	var toOl = getReal(window.event.toElement, "className", "linkButton");
	var fromOl = getReal(window.event.fromElement, "className", "linkButton");
	if (toOl == fromOl) return;
	var ol = fromOl;

//	var cDisabled = ol.getAttribute("cDisabled");
	var cDisabled = ol.cDisabled;
	cDisabled = (cDisabled != null); // If CDISABLED atribute is present

	var cToggle = ol.cToggle;
	toggle_disabled = (cToggle != null); // If CTOGGLE atribute is present

	if (cToggle && ol.value) {
		makePressed(ol);
		makeGray(ol,true);
	}
	else if ((ol.className == "linkButton") && !cDisabled) {
		makeFlat(ol);
		makeGray(ol,true);
	}

}

function doDown() {
	ol = getReal(window.event.srcElement, "className", "linkButton");
	
	var cDisabled = ol.cDisabled;
	cDisabled = (cDisabled != null); // If CDISABLED atribute is present
	
	if ((ol.className == "linkButton") && !cDisabled) {
		makePressed(ol)
	}
}

function doUp() {
	ol = getReal(window.event.srcElement, "className", "linkButton");
	
	var cDisabled = ol.cDisabled;
	cDisabled = (cDisabled != null); // If CDISABLED atribute is present
	
	if ((ol.className == "linkButton") && !cDisabled) {
		makeRaised(ol);
	}
}


function getReal(ol, type, value) {
	temp = ol;
	while ((temp != null) && (temp.tagName != "BODY")) {
		if (eval("temp." + type) == value) {
			ol = temp;
			return ol;
		}
		temp = temp.parentElement;
	}
	return ol;
}

function findChildren(ol, type, value) {
	var children = ol.children;
	var tmp = new Array();
	var j=0;
	
	for (var i=0; i<children.length; i++) {
		if (eval("children[i]." + type + "==\"" + value + "\"")) {
			tmp[tmp.length] = children[i];
		}
		tmp = tmp.concat(findChildren(children[i], type, value));
	}
	
	return tmp;
}

function disable(ol) {

	if (document.readyState != "complete") {
		window.setTimeout("disable(" + ol.id + ")", 100);	// If document not finished rendered try later.
		return;
	}
	
	var cDisabled = ol.cDisabled;
	
	cDisabled = (cDisabled != null); // If CDISABLED atribute is present

	if (!cDisabled) {
		ol.cDisabled = true;
		
		ol.innerHTML = '<span style="background: buttonshadow; width: 96%; height: 96%; text-align: center;">' +
						'<span style="filter:Mask(Color=buttonface) DropShadow(Color=buttonhighlight, OffX=1, OffY=1, Positive=0); height: 96%; width: 96%%; text-align: center;">' +
						ol.innerHTML +
						'</span>' +
						'</span>';

		if (ol.onclick != null) {
			ol.cDisabled_onclick = ol.onclick;
			ol.onclick = null;
		}
	}
}

function enable(ol) {
	var cDisabled = ol.cDisabled;
	
	cDisabled = (cDisabled != null); // If CDISABLED atribute is present
	
	if (cDisabled) {
		ol.cDisabled = null;
		ol.innerHTML = ol.children[0].children[0].innerHTML;

		if (ol.cDisabled_onclick != null) {
			ol.onclick = ol.cDisabled_onclick;
			ol.cDisabled_onclick = null;
		}
	}
}

function addToggle(ol) {
	var cDisabled = ol.cDisabled;
	
	cDisabled = (cDisabled != null); // If CDISABLED atribute is present
	
	var cToggle = ol.cToggle;
	
	cToggle = (cToggle != null); // If CTOGGLE atribute is present

	if (!cToggle && !cDisabled) {
		ol.cToggle = true;
		
		if (ol.value == null)
			ol.value = 0;		// Start as not pressed down
		
		if (ol.onclick != null)
			ol.cToggle_onclick = ol.onclick;	// Backup the onclick
		else 
			ol.cToggle_onclick = "";

		ol.onclick = new Function("toggle(" + ol.id +"); " + ol.id + ".cToggle_onclick();");
	}
}

function removeToggle(ol) {
	var cDisabled = ol.cDisabled;
	
	cDisabled = (cDisabled != null); // If CDISABLED atribute is present
	
	var cToggle = ol.cToggle;
	
	cToggle = (cToggle != null); // If CTOGGLE atribute is present
	
	if (cToggle && !cDisabled) {
		ol.cToggle = null;

		if (ol.value) {
			toggle(ol);
		}

		makeFlat(ol);
		
		if (ol.cToggle_onclick != null) {
			ol.onclick = ol.cToggle_onclick;
			ol.cToggle_onclick = null;
		}
	}
}

function toggle(ol) {
	ol.value = !ol.value;
	
	if (ol.value)
		ol.style.background = "URL(/pics/clear.gif)";
	else
		ol.style.backgroundImage = "";

//	doOut(ol);	
}


function makeFlat(ol) {
	with (ol.style) {
		background = "";
		border = "1px solid buttonface";
		padding      = "1px";
	}
}

function makeRaised(ol) {
	with (ol.style) {
		borderLeft   = "1px solid buttonhighlight";
		borderRight  = "1px solid buttonshadow";
		borderTop    = "1px solid buttonhighlight";
		borderBottom = "1px solid buttonshadow";
		padding      = "1px";
	}
}

function makePressed(ol) {
	with (ol.style) {
		borderLeft   = "1px solid buttonshadow";
		borderRight  = "1px solid buttonhighlight";
		borderTop    = "1px solid buttonshadow";
		borderBottom = "1px solid buttonhighlight";
		paddingTop    = "2px";
		paddingLeft   = "2px";
		paddingBottom = "0px";
		paddingRight  = "0px";
	}
}

function makeGray(ol,b) {
	var filtval;
	
	if (b)
		filtval = "gray()";
	else
		filtval = "";

	var imgs = findChildren(ol, "tagName", "IMG");
		
	for (var i=0; i<imgs.length; i++) {
		imgs[i].style.filter = filtval;
	}

}
	

document.write("<style>");
document.write(".linkBar	{background: buttonface;border-top: 1px solid buttonhighlight;	border-left: 1px solid buttonhighlight;	border-bottom: 1px solid buttonshadow; border-right: 1px solid buttonshadow; padding: 2px; font: menu;}");
document.write(".linkButton {border: 1px solid buttonface; padding: 1px; text-align: center; cursor: default;}");
document.write(".linkButton IMG	{filter: gray();}");
document.write("</style>");