wasFocus = null;
// pWidth .... sets the Width in pixels of the popup (0=auto width regardless of pSize setting)
// pHeight ... sets the Height in pixels of the popup (0=auto height regardless of pSize setting)
// pSize ..... sets Size mode for popup
//		manual ... use pWidth & pHeight variables
//		auto ..... autosize popup based on content (overrides pWidh & pHeight)

pWidth = 400;
pHeight = 200;
pSize = "manual"

// pTop ...... pixel location for the Top of the popup (0=center Yaxis regardless of pLoc setting)
// pLeft ..... pixel location for the Left of the popup (0=center Xaxis regardless of pLoc setting)
// pLoc ...... sets Location mode for popup
//		manual ... use pTop & pLeft variables
//		auto ..... auto center popup based on content (overrides pTop & pLeft)

pTop = 0;
pLeft = 0;
pLoc = "manual";

// pOffX .... pixel offset to add to Xaxis location of popup
// pOffY .... pixel offset to add to Yaxis location of popup

pOffX = 0;
pOffY = 0;


// pDelay .... number of miliseconds to delay before showing popup (0=none)
// pSflag .... use Session Cookie to only show once (true=use Cookie)

pDelay = 1000;
pSflag = false;



function zdFocus(who)
{
//	wDivs = document.getElementsByTagName('DIV');


	wDivs = document.getElementsByName("popWin");

	for(i=0; i < wDivs.length; i++)
	{
//		if(wDivs[i].className == "popContainer" && wDivs[i] != who)
//		{
			oDiv = wDivs[i];
			fDivs = oDiv.getElementsByTagName('DIV');
			for(j=0; j < fDivs.length; j++){if(fDivs[j].id == 'popFocus'){fDiv=fDivs[j]; j=fDivs.length;}}
			fDiv.style.left = 0
			fDiv.style.top = 0
			oDiv.style.zIndex = "0";
	}
//		}
//		else if(wDivs[i].className == "popContainer" && wDivs[i] == who)
//
//		{
			oDiv = who		//wDivs[i];
			fDivs = oDiv.getElementsByTagName('DIV');
			for(j=0; j < fDivs.length; j++){if(fDivs[j].id == 'popFocus'){fDiv=fDivs[j]; j=fDivs.length;}}
			fDiv.style.left = -3000
			fDiv.style.top = -3000
			oDiv.style.zIndex = "240";
//		}
//	}
}

function ddFocus(who)
{

	if(who == wasFocus) return;

	wDivs = document.getElementsByTagName("DIV");

	for(i=0; i < wDivs.length; i++)
	{
	  if(wDivs[i].name == "popWin")
	  {
		oDiv = wDivs[i];
		fDivs = oDiv.getElementsByTagName('DIV');
		for(j=0; j < fDivs.length; j++){if(fDivs[j].id == 'popFocus'){fDiv=fDivs[j]; j=fDivs.length;}}
		fDiv.style.left = 0
		fDiv.style.top = 0
		oDiv.style.zIndex = "0";
	  }
	}

	oDiv = who		//wDivs[i];
	fDivs = oDiv.getElementsByTagName('DIV');
	for(j=0; j < fDivs.length; j++){if(fDivs[j].id == 'popFocus'){fDiv=fDivs[j]; j=fDivs.length;}}
	fDiv.style.left = -3000
	fDiv.style.top = -3000
	oDiv.style.zIndex = "240";

	wasFocus = who;
}

function puCount()
{
	wDivs = document.getElementsByTagName('DIV');
	pCount = 0;
	for(i=0; i < wDivs.length; i++)
	{
		if(wDivs[i].className == "popContainer")
		{
			pCount++;
		}
	}
	return(pCount-1);
}


function puCaption(who)
{
	wDivs = who.getElementsByTagName('DIV');
	for(i=0; i < wDivs.length; i++)
	{
		if(wDivs[i].id == "popCaption")
		{
			if(isIE) wDivs[i].innerText = "Caption for " + who.id;
			if(!isIE) wDivs[i].textContent = "Caption for " + who.id;
			return;
		}
	}
}

function ddInit(e)
{
  topDog=isIE ? "BODY" : "HTML";
  hotDog=isIE ? event.srcElement : e.target;  

  if(hotDog == undefined || hotDog.tagName == "HTML" || hotDog.tagName == "BODY") return(false);
  
//Find Container
  whichDog = hotDog;


  while (whichDog.className != "popContainer" && whichDog.tagName != topDog){
    whichDog=isIE ? whichDog.parentElement : whichDog.parentNode;
  }
  
  if(whichDog.className == "popContainer") ddFocus(whichDog);

  while (hotDog.id!="titleBar"&&hotDog.tagName!=topDog){
    hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
  }  
  if (hotDog.id=="titleBar"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichDog.style.left);
    nowY=parseInt(whichDog.style.top);
    ddEnabled=true;
    hotDog.style.cursor = "move";
    document.onmousemove=dd;
  }
}

function dd(e)
{
  if (!ddEnabled) return;
  whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;  
}

function ddDrop(e)
{
	hotDog.style.cursor = "default";
	ddEnabled=false;
}

function ddN4(whatDog)
{
  if (!isN4) return;
  N4=eval(whatDog);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function configMe(who)
{
	if(!who || who == "" || who == undefined)
	{
		pDiv = document.getElementById("popContainer");
		cDiv = document.getElementById("popContent");
	}
	else
	{
		pDiv = who;
		
		d = who.getElementsByTagName('DIV');
		for(i=0; i < d.length; i++)
		{
			if(d[i].id == "popContent"){cDiv = d[i]; i=d.length;}
		}
	}

//	oDiv = document.getElementById("popContent")
	if(parseInt(pWidth) == 0 || pSize == "auto") {cDiv.style.width = "auto"} else {cDiv.style.width = parseInt(pWidth) + "px"}
	if(parseInt(pHeight) == 0 || pSize == "auto") {cDiv.style.height = "auto"} else {cDiv.style.height = parseInt(pHeight) + "px"}

//	oDiv = document.getElementById("popContainer")
	if(parseInt(pTop) == 0 || pLoc == "auto") {} else {pDiv.style.top = parseInt(pTop) + parseInt(pOffY) + "px"}
	if(parseInt(pLeft) == 0 || pLoc == "auto") {} else {pDiv.style.left = parseInt(pLeft) + parseInt(pOffX) + "px"}	

//	if(parseInt(pWidth) == 0 || pSize == "auto") {cDiv.style.width = "auto"} else {cDiv.style.width = parseInt(pWidth) + "px"}
//	if(parseInt(pHeight) == 0 || pSize == "auto") {cDiv.style.height = "auto"} else {cDiv.style.height = parseInt(pHeight) + "px"}

//	if(parseInt(pTop) == 0 || pLoc == "auto") {} else {pDiv.style.top = parseInt(pTop) + "px"}
//	if(parseInt(pLeft) == 0 || pLoc == "auto") {} else {pDiv.style.left = parseInt(pLeft) + "px"}

	fDivs = pDiv.getElementsByTagName('DIV');
	for(i=0; i < fDivs.length; i++){if(fDivs[i].id == 'popFocus'){fDiv=fDivs[i]; i=fDivs.length;}}
	fDiv.style.width = pDiv.clientWidth
	fDiv.style.height = pDiv.clientHeight
}

function hideMe()
{
  if (isIE||isNN) whichDog.style.visibility="hidden";
  else if (isN4) document.popContainer.visibility="hide";

  document.body.removeChild(whichDog);
}

function showMe(who)
{
	oDiv = document.getElementById("popContainer");
	nDiv = oDiv.cloneNode(true);

	sID = new Date();
	sID = sID.getTime();

	nDiv.id = sID;
	nDiv.name = 'popWin';
	puCaption(nDiv);

	if(isIE){whichDog = document.body.insertBefore(nDiv);}else{whichDog = document.body.appendChild(nDiv);}

	whichDog = document.getElementById(sID);
	configMe(whichDog);
	centerMe(whichDog);
	if (isIE||isNN) whichDog.style.visibility="visible";

	ddFocus(whichDog);
	return(sID);
}

function centerMe()
{
	oDiv = whichDog;
	var client = new clientInfo()

	layerw=oDiv.clientWidth;
	layerh=oDiv.clientHeight;

	if(parseInt(pLeft) == 0 || pLoc == "auto")
	{
		oDiv.style.left = parseInt((client.scrollLeft + (client.width/2)) - (layerw/2)) + parseInt(pOffX) + "px";
	}
	
	if(parseInt(pTop) == 0 || pLoc == "auto")
	{
		oDiv.style.top = parseInt((client.scrollTop + (client.height/2)) - (layerh/2)) + parseInt(pOffY) + "px";
	}

}

function clientInfo()
{
	var iebody = (document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;

	this.width = document.all ? iebody.clientWidth : self.innerWidth;
	this.height = document.all ? iebody.clientHeight : self.innerHeight;
	this.scrollLeft = document.all ? iebody.scrollLeft : pageXOffset;
	this.scrollTop = document.all ? iebody.scrollTop : pageYOffset;
}

window.onload = function()
{
	isHot = false;
	pTimer = null;
	isIE=document.all;
	isNN=!document.all&&document.getElementById;
	isN4=document.layers;
	whichDog=isIE?document.all.popContainer:document.getElementById("popContainer");
	
	configMe();
	centerMe();
}

document.onmousedown=ddInit;
document.onmouseup=ddDrop;

