var index = 0;
function doBox(obj, boxp, open) 
{
	var boxdiv = document.getElementById(boxp.id);

	log("doBox:|boxp.id:" + boxp.id + "|boxdiv:" + boxdiv + "|obj:" + obj + "|open:" + open);
	
	if (boxdiv != null) 
	{
		//log("boxdiv:" + boxdiv.style.display);
		if (boxdiv.style.display == 'none') 
		{
			boxdiv.style.display = 'block';
			boxdiv.style.position = 'absolute';
			boxdiv.style.width = boxp.width + 'px';
			boxdiv.style.height = boxp.height + 'px';
			boxdiv.style.border = boxp.border;
			boxdiv.style.backgroundColor = '#ffffff';
			boxdiv.style.zIndex = 100;
			moveBox(obj, boxdiv);
			boxp.status = 1;
			return;
		} 
		else
		{
			//log("boxdiv.id:" + boxdiv.id);
			
			//if (boxdiv.id != 'ap')
			//{
				document.body.removeChild(boxdiv);
			//}
			//else
			//{
			//	boxdiv.style.display = "none";
			//}
			boxp.status = 0;
		}
		if (!open || typeof(obj) == "undefined" || !obj)
		{
			return false;
		}
	}
	else if (!open)
	{
		return false;
	}
	
	boxdiv = document.createElement('div');
	boxdiv.setAttribute('id', boxp.id);
	boxdiv.style.display = 'block';
	boxdiv.style.position = 'absolute';
	boxdiv.style.width = boxp.width + 'px';
	boxdiv.style.height = boxp.height + 'px';
	//boxdiv.style.border = boxp.border;
	//boxdiv.style.backgroundColor = '#ffffff';
  
	if (!useIframe)
	{
	  	//TODO, for using iframe, parse "paramString".
		boxdiv.innerHTML = boxp.txt;
		log(boxp.txt);
	}
	else
	{
		var contents = document.createElement('iframe');
		contents.scrolling = 'no';
		contents.frameBorder = '0';
		contents.style.width = width + 'px';
		contents.style.height = height + 'px';
		contents.src = "popupbox.jsp?" + p;
		boxdiv.appendChild(contents);
	}
  
	document.body.appendChild(boxdiv);
	boxp.status = 1;
	moveBox(obj, boxdiv);

	return false;
}

function moveBox(an, box) 
{
	if (debug) log("mov=>an.top:" + an.offsetTop + "|an.left:" + an.offsetLeft + "|box.id:" + box.id);
	
	var l = 0;
	var t = 0;
	var obj = an;
  
	while (obj.offsetParent) 
	{
		l += obj.offsetLeft;
		t += obj.offsetTop;
		obj = obj.offsetParent;
    
		if (debug) log("obj:" + obj + "|t:" + t + "|l:" + l);
	}
  
	//if (box.id != "ap")
	//{
		box.style.left = (l + 20) + 'px';
	//}
	//else
	//{
	//	box.style.left = (l - 20) +  'px';
	//}
  
	t += an.offsetHeight - 2;
 
	if (debug) log("mov to=>" + t + "|" + l);
  
	if (document.body.currentStyle && document.body.currentStyle['marginTop']) 
	{
		t += parseInt(document.body.currentStyle['marginTop']);
	}

	/*
	if (box.id == "ap")
	{
		t = t - 180;
		var smy = window.scrollMaxY ? window.scrollMaxY : document.documentElement.scrollHeight;
		
		log("===>" + smy + "|" + t + "|" + (smy-t));
		
		if ((smy - t) < (isIE?950:330))// 
		{
			log("not high enough to show tree. " + "|" + (smy-t));
			t = t - 650;
		}
	}
	*/
  
	box.style.top = t + 'px';
	if (debug) log("mov to=>top:" + box.style.top + "|" + l);
}

var useIframe = false;

