/*new style popups!
within the html these should be defined in two <div> containers representing the 'title bar' and 'content area' of the popup.
the following is a standard title bar - the div needs the class 'p_titlebar' applied to it, and contains the close window graphic and a title.
its id has the prefix "t_" indicating it's a title bar - this should be followed by the popup name ie "t_thePopup"
		<div class="p_titlebar" id="t_thePopup"><img src="../../Images/popup_infoIcon.gif" class="info_icon" alt="Information"> 
			<h1>title goes here</h1>
			<p class="close"> <a href="javascript:popup('thePopup')">close<img src="../../Images/popup_close.gif" alt="close"></a> </p> 
		</div> 

The main content area will apear as below - with the class 'P_content' and an id prefixed with "c_" followed by the popup name (as in the titlebar)
ie "c_thePopup"
		<div class="p_content" id="c_thePopup"> 
			<p>content goes here </p>
		</div>
		
The text link will appear as below:
this will call the javascript function 'popup' with the name of the popup (in this case 'thePopup' - note this does not contain the Prefixes - these are added
dynamically to access the title bar and content areas. it also has the class "popuplink" to give it the green colour.																		 
	<a href="javascript:(popup('thePopup'));" class="popuplink">open a popopup</a>

*/
var cx=0; //mouse x-ordinent
var cy=0; //mouse y-ordinent

// Some vars to customize window:
// these values don't change the styles of the popups, they just inform the functions of the values already specified in the css.
var titlebar_h 			= 0;		//height of title bar
var toolbar_h 			= 0;		//height of tool bar (not implemented atm ;) )
var statusbar_h 		= 0;		//height of status bar (not implemented either ;) )
var clientarea_margin 	= 0;		//margin around content area
var clientarea_padding 	= 5;		//padding on content area


//show hide popup boxes
//given the id of a popup box, show or hide it's content area and title bar.
function popup(strId,bNewPopup){
	oPopup 			= document.getElementById("a_popup"); //generic popup box container
	oPopup_content 	= document.getElementById("popup_content");  //contents of popup (this is nested in the popup container
								
	strContent_to_display = document.getElementById(strId).innerHTML; //get contents of appropriate terminology.


oPopup_content.innerHTML = strContent_to_display;
								
	if (oPopup.style.visibility=="hidden" || oPopup.style.visibility=="" || bNewPopup){
		oPopup.style.visibility="visible";
		positionPopup("a_popup");
	} else if (oPopup.style.visibility=="visible"){
		oPopup.style.visibility="hidden";
	}
	
	
}


function positionPopup(strId){


	contentW = dd.elements[strId].w;
	contentH = dd.elements[strId].h;

	dd.elements[strId].moveTo(cx,cy);

 	intWinH = dd.getWndH();
	intWinW = dd.getWndW();
	posY = dd.elements[strId].y;
	posX = dd.elements[strId].x;
	
	intScrollY =  dd.getScrollY();
	intScrollX =  dd.getScrollX();

	
	intNewY = cy;
	intNewX = cx;
	
	//alert(intWinH+" "+intWinW+" "+contentW+" "+contentH+" "+cy+" "+cx+" "+intScrollY+" "+intScrollX);
	
	//if the popup is going off the side of the screen;
	if (((cx+contentW)-intScrollX) > intWinW){
		intNewX = ((intWinW-contentW)+intScrollX);
		if (intNewX <0){intNewX = 0;}
	}
	
	//if popup goes off the bottom of the screen:
	if (((cy+contentH)-intScrollY) > intWinH){
		intNewY = ((intWinH-contentH)+intScrollY);
		if (intNewY <0){intNewY = 0;}
	}
	
/*	
	alert (intScrollY+" " +intScrollX)
	if (intScrollY > 0){
		intNewY = cy - intScrollY;
		if(intNewY < 0){
			intNewY = 0;
		}
	}
	if (intScrollX > 0){
		intNewX = cx - intScrollX;
		if(intNewX < 0){
			intNewX = 0;
		}
	}

*/
	dd.elements[strId].maximizeZ();
	dd.elements[strId].moveTo(intNewX, intNewY);
}


//track the position of the mouse.
function mouseTrack() {
  if (window.Event) {
    document.captureEvents(Event.MOUSEMOVE);
  }
  document.onmousemove = getXY;
}

function getXY(e) {
  cx = (window.Event) ? e.pageX : event.clientX;
  cy = (window.Event) ? e.pageY : event.clientY;

  //account for page scrolling;
  cy=cy+dd.getScrollY();
  cx=cx+dd.getScrollX();
  // Use x and y to do what ever you want
}

window.onload=mouseTrack;