// JavaScript Document

pSize = "manual"
pWidth = 400;
pHeight = 580;

pLoc = "manual";
pTop = 280;
pLeft = -50;

pDelay = 1000;
pSflag = true;


function ddInit(e)
{
  topDog=isIE ? "BODY" : "HTML";
  whichDog=isIE ? document.all.popContainer : document.getElementById("popContainer");  
  hotDog=isIE ? event.srcElement : e.target;  
  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()
{
	oDiv = document.getElementById("popContent")
	if(parseInt(pWidth) == 0 || pSize == "auto") {oDiv.style.width = "auto"} else {oDiv.style.width = parseInt(pWidth) + "px"}
	if(parseInt(pHeight) == 0 || pSize == "auto") {oDiv.style.height = "auto"} else {oDiv.style.height = parseInt(pHeight) + "px"}

	oDiv = document.getElementById("popContainer")
	if(parseInt(pTop) == 0 || pLoc == "auto") {} else {oDiv.style.top = parseInt(pTop) + "px"}
	if(parseInt(pLeft) == 0 || pLoc == "auto") {} else {oDiv.style.left = parseInt(pLeft) + "px"}
	
//	oDiv = document.getElementById("popContainer")
//	if(parseInt(pTop) == 0 || pLoc == "auto") {} else {oDiv.style.top = parseInt(pTop) + "px"}
//	if(parseInt(pLeft) == 0 || pLoc == "auto") {} else {oDiv.style.left = parseInt(pLeft) + "px"}
}

function hideMe()
{
  if (isIE||isNN) whichDog.style.visibility="hidden";
  else if (isN4) document.popContainer.visibility="hide";
}

function showMe()
{
  clearTimeout(pTimer);
  pTimer=null;
  
  if(new Date().getTime() >= pNow + pDelay)
  {
	  if (!whichDog){whichDog=isIE ? document.all.popContainer : document.getElementById("popContainer");}
	  if (isIE||isNN) whichDog.style.visibility="visible";
	  else if (isN4) document.popContainer.visibility="show";
  }
  else
  {
	  pTimer = setTimeout('showMe()', 8);  
  }
}

function centerMe()
{
	oDiv = whichDog;
	var client = new clientInfo()

	layerw=oDiv.clientWidth;
	layerh=oDiv.clientHeight;

	oDiv.style.left = (client.scrollLeft + (client.width/2)) + (pLeft);
	oDiv.style.top = (pTop);
	
//	oDiv.style.left = (client.scrollLeft + (client.width/2)) - (layerw/2);
//	oDiv.style.top = (client.scrollTop + (client.height/2)) - (layerh/2);

}

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();
	pNow = new Date().getTime();

	session = new TCM_InfoCtrl("session_cookie");
	pSession = session.getSubValue("iX2_popup");

	if (pSession == null || pSession == '') 
	{
		pSession = false;
		session.setSubValue("iX2_popup", "false");
	}
	centerMe();
	ok2show = (pSession == false && pSflag == true) || pSflag == false;
	if(ok2show)
	{
		showMe();
		session = new TCM_InfoCtrl("session_cookie");
		session.setSubValue("iX2_popup", "true");	
		pSession = session.getSubValue("iX2_popup");
	}

}

document.onmousedown=ddInit;
document.onmouseup=ddDrop;