var IE5=(document.getElementById && document.all)? true : false;
var W3C=(document.getElementById)? true: false;
var currIDb=null, currIDs=null, xoff=0, yoff=0; zctr=0; totz=0, ElmIDb=null, ElmIDs=null, ElmIDh=null;
var hideonclick=true;
var ElasticHeight = false ;
var ElasticWidth = false ;

function trackmouse(evt)
{
   if((currIDb!=null) && (currIDs!=null))
   {
      var x=(IE5)? event.clientX+document.body.scrollLeft : evt.pageX;
      var y=(IE5)? event.clientY+document.body.scrollTop : evt.pageY;
      currIDb.style.left=x+xoff+'px';
      currIDs.style.left=x+xoff+6+'px';
      currIDb.style.top=y+yoff+'px';
      currIDs.style.top=y+yoff+6+'px';
      return false;
   }
}

function stopdrag()
{
   currIDb=null;
   currIDs=null;
}

function grab_id(evt)
{
   xoff=parseInt(ElmIDb.style.left)-((IE5)? event.clientX+document.body.scrollLeft : evt.pageX);
   yoff=parseInt(ElmIDb.style.top)-((IE5)? event.clientY+document.body.scrollTop : evt.pageY);
   currIDb=ElmIDb;
   currIDs=ElmIDs;
}

function incrzindex()
{
   zctr=zctr+2;
   ElmIDb.style.zIndex=zctr;
   ElmIDs.style.zIndex=zctr-1;
}

function createPopup(id, width, height, x , y , boxcolor, bordercolor, borderwidth, shadowcolor  )
{
   if(W3C)
   {
      zctr+=2;
      totz=zctr;
      var txt='';
		var ZZH = 'height:'+height+'px;';
		var ZZW = 'width:'+width+'px;';
		if ( height==9999) { ElasticHeight= true; ZZH=''; }
		if ( width ==9999) { ElasticWidth = true; ZZW=''; }
      txt+='<div id="'+id+'_s" style="position:absolute; left:'+(x+6)+'px; top:'+(y+6)+'px; ' + ZZW + ' '+ ZZH +' background-color:'+shadowcolor+'; filter:alpha(opacity=20); z-index:250; visibility:hidden"></div>';
      txt+='<div id="'+id+'_b" style="border:solid '+bordercolor+' '+borderwidth+'px;  position:absolute; left:'+x+'px; top:'+y+'px; ' + ZZW + ' overflow:hidden; '+ ZZH +' background-color:'+boxcolor+'; z-index:250; visibility:hidden">';
      txt+='<div id="'+id+'_ov" style="padding:0px;"><div id="'+id+'_contains"></div></div></div>';
		document.write(txt);
      IDs=document.getElementById(id+'_s');
      if(!IE5)
         IDs.style.MozOpacity=.5;	
   }
}

function GrabIt(id)
{
	ElmIDh=document.getElementById(id+'_h');
	ElmIDb=document.getElementById(id+'_b');
	ElmIDs=document.getElementById(id+'_s');
	ElmIDb.onmousedown=incrzindex;

	if (ElmIDh){
		ElmIDh.onmousedown=grab_id;
		ElmIDh.onmouseup=stopdrag;
	}
}
function showPopup( id ) 
{
      if ( document.getElementById(id+'_s') )  
      {
			GrabIt(id) ;
			document.getElementById(id+'_b').style.visibility='visible' ;
			if ( ElasticHeight) document.getElementById(id+'_s').style.height = document.getElementById(id+'_b').offsetHeight+'px';
			if ( ElasticWidth)  document.getElementById(id+'_s').style.width  = document.getElementById(id+'_b').offsetWidth+'px';
			document.getElementById(id+'_s').style.visibility='visible' ;
      }
	
}
function showPopupT( id, text ) 
{
      if ( document.getElementById(id+'_s') )  
      {
			document.getElementById(id+'_contains').innerHTML = text;
	
			document.getElementById(id+'_s').style.visibility='visible' ;
			document.getElementById(id+'_b').style.visibility='visible' ;      							
			GrabIt(id) ;
      }
	
}

function showPopupEncoded( id, title, text, hiding ) 
{
      if ( document.getElementById(id+'_s') )  
      {
			document.getElementById(id+'_h').innerHTML = unescape(title);
			document.getElementById(id+'_ov').innerHTML = unescape(text);
      	document.getElementById(id+'_s').style.visibility='visible' ;
      	document.getElementById(id+'_b').style.visibility='visible' ;
			hideonclick=hiding ;
      }
	
}

function hidePopup( id ) 
{
      if ( ( document.getElementById(id+'_s') )  )
      {
      	document.getElementById(id+'_s').style.visibility='hidden' ;
      	document.getElementById(id+'_b').style.visibility='hidden' ;
	  }
}

if(W3C && WantTrackMouse)document.onmousemove=trackmouse;

