function itemOnMouseOver(obj){
	with (obj) {
		with (style) {
			backgroundColor = "highlight"
			color = "highlighttext"
			
		}		
	}
}
function itemOnMouseOut(obj){
	with (obj) {
		with (style) {
			backgroundColor = ""
			color = ""
		}
	}
}

function fGetXY(aTag){
	var oTmp = aTag;
	//var oTmp = document.getElementsByName(aTag)[0];
	var pt = new Point(0,0);
	do {
		pt.x += oTmp.offsetLeft;
		pt.y += oTmp.offsetTop;
		oTmp = oTmp.offsetParent;

	} while(oTmp.tagName!="BODY");
	return pt;
}
function Point(iX, iY){
	this.x = iX;
	this.y = iY;
}

function popup(selectCtrl,popCtrl) {
	if (selectCtrl.style.visibility=="hidden") {
//		var point = fGetXY(popCtrl);
		with (selectCtrl.style) {
//			left = point.x;				  
//			top  = point.y + popCtrl.offsetHeight;
			left = window.event.clientX;
			top = window.event.clientY;
			width = selectCtrl.offsetWidth;
			height = selectCtrl.offsetHeight;	
		}
		selectCtrl.style.visibility="visible";
	} else {
		selectCtrl.style.visibility="hidden";
	}	
}

function option(label,value) {
	this.label = label;
	this.value = value;
}

var _popupObjs = new Array();

function popupObj(id) {
	this.id = id;
	this.options = new Array();
	this.binds = new Array();
	_popupObjs[_popupObjs.length] = this;
}

popupObj.prototype.getVisibility = function() {
	return document.getElementById(this.id).style.visibility;
}

popupObj.prototype.setVisibility = function(visibility) {
	document.getElementById(this.id).style.visibility = visibility;
}

popupObj.prototype.add = function(option) {
	var len = this.options.length;
	this.options[len] = option;
}

popupObj.prototype.bind = function(obj) {
	this.binds[this.binds.length] = obj;
}

popupObj.prototype.write = function() {
	with (document) {
		write("<div id='" + this.id + "' style='OVERFLOW:hidden;POSITION:absolute;VISIBILITY:hidden;cursor:hand;z-index:1000;'>");
		write("<table cellpadding=1 cellspacing=1 align=center style='border: 1px;background-color:#aaaaaa;'>");
		write("<tr><td style='background-color: #FFFFFF;'><table cellpadding=0 cellspacing=0>");
		for (var i=0; i<this.options.length; i++)
		{
			write("<tr style='line-height: 120%;' onmouseover='itemOnMouseOver(this);' onmouseout='itemOnMouseOut(this);' onclick='" + this.options[i].value + "'>");
			write("<td nowrap style='font-size: 12px;'>&nbsp;" + this.options[i].label + "&nbsp;</td>");
			write("</tr>");
		}

		write("</table></td></tr></table>");

		write("<iframe src='javascript:false' style='position:absolute; visibility:inherit; top:0px; left:0px; z-index:-1;'></iframe>");
		write("</div>");
	}
}

popupObj.prototype.create = function() {
	var objWindow = window.document.createElement("DIV") ;
	var txtHTML = "<table cellpadding=1 cellspacing=1 align=center style='border: 1px;background-color:#aaaaaa'>";
	txtHTML += "<tr><td style='background-color: #FFFFFF;'><table cellpadding=0 cellspacing=0>";
	for (var i=0; i<this.options.length; i++)
	{
		txtHTML += "<tr style='line-height: 120%;' onmouseover='itemOnMouseOver(this);' onmouseout='itemOnMouseOut(this);' onclick='" + this.options[i].value + "'>";
		txtHTML += "<td nowrap style='font-size: 12px;'>&nbsp;" + this.options[i].label + "&nbsp;</td>";
		txtHTML += "</tr>";
	}
	txtHTML += "</table></td></tr></table>";

	txtHTML += "<iframe src='javascript:false' style='position:absolute; visibility:inherit; top:0px; left:0px; z-index:-1;'></iframe>";

	with (objWindow) {
		id = this.id ;
		innerHTML = txtHTML ;
		with (style) {
			overflow = "hidden";
			position = "absolute";
			visibility = "hidden";
			zIndex = 1000;
			cursor = "hand";
		}
	}
	window.document.body.insertAdjacentElement("afterBegin", objWindow) ;
}

document.onclick = hitTest;

function hitTest(){
	for (var i=0; i<_popupObjs.length; i++)
	{
		if(_popupObjs[i].getVisibility() == "visible") {
			var flag = true;
			for (var j=0; j<_popupObjs[i].binds.length; j++)
			{
				if (event.srcElement == _popupObjs[i].binds[j])
				{
					flag = false;
					break;
				}
			}
			if (flag)
			{
				_popupObjs[i].setVisibility("hidden");
			}
		}
	}
};