/**
#===========================================================================
# Copyright 2006, University of Auckland
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# For a copy of the GNU General Public License write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
# ===========================================================================
# Craig Housley <c.housley@auckland.ac.nz> , WenChen <w.hol@auckland.ac.nz>
*/

	var elmIframeDiv;
	function hidePopUpDiv() {
		var elmDiv = document.getElementById('popupDivMessage')

		if (elmDiv) {

			elmDiv.parentNode.removeChild(elmDiv) // removes the div from the document
	
		}
		if ( isMSIE ) {
			try {
				elmIframeDiv.style.display='none';
			}
			catch (e){ }
		}
	}
	
	function showPopUpDiv( event, args ) {
		
		var w = 200;
		var html = "";
		var lower = 0;
		var left = 0;
		
		if ( args.width ) {
			w = args.width;
		}
		if ( args.hint ) {
			html = args.hint;
		}
		if ( args.lower ) {
			lower = args.lower;
		}
		if ( args.left ) {
			left = args.left;
		}
		
		updateCoordsPopUpDiv( event, w );
		hidePopUpDiv();
		
		var elmDiv = document.createElement('div');
		
		elmDiv.id  = 'popupDivMessage';
		elmDiv.className="popup"; // assigns a style named "mediaFile" to the div element from the .css stylsheet
		elmDiv.zIndex=999;

		//elmDiv.style.position="absolute";
      elmDiv.innerHTML = html;
		
		// hack for msie, to place the message box centre align to mouse pointer
		if ( isMSIE ) {
			xpos = xpos - w/2;
		}
		elmDiv.style.cssText = 'left:' + (xpos) + 'px; width: ' + w + 'px; font-style:italic;';
		
		//targ.appendChild(elmDiv);
		document.body.appendChild( elmDiv );
		
		if (lower) {
			elmDiv.style.top = ypos + yoffset + 10 + "px";
		}
		else {
			elmDiv.style.top = ypos + yoffset - elmDiv.offsetHeight - 20 + "px";
		}
		
		/*try to avoid mouse over message div problem*/
		if ( ypos < ( parseInt( elmDiv.top) + elmDiv.offsetHeight ) ) {
			//alert( "ypos:" + ypos + " offsetHeightDiv:" + ( parseInt( elmDiv.top) + elmDiv.offsetHeight ) );
		}
		/**/
		if (left)
			elmDiv.style.left = (elmDiv.style.left.slice(0,-2))/1 - w + "px";
		
		//IE need special hack, using iframe to fix the flashing float box
		if ( isMSIE ) {
			elmIframeDiv= document.createElement( 'iframe' );
			elmIframeDiv.style.left=elmDiv.style.left;
			elmIframeDiv.style.top=elmDiv.style.top;
			elmIframeDiv.style.width = elmDiv.style.width;
		}
		//elmDiv.style.cssText += 'background-color:#eff7df; border-color:#000; color:#000';
	}

	function updateCoordsPopUpDiv( e, winWidth ) {
		var st = Math.max( document.body.scrollTop, document.documentElement.scrollTop );
		var bodyWidth = Math.max( document.body.clientWidth, document.documentElement.clientWidth ) - 20 ;
		isMSIE=0;
		if (objBrowse == "Microsoft Internet Explorer") {
			isMSIE=1;
			//xpos = e.srcElement.offsetLeft - 25;
			//xpos = e.srcElement.offsetLeft + e.srcElement.parentElement.offsetLeft ;
			xpos = e.clientX;
			
			//ypos = e.srcElement.offsetTop - e.srcElement.parentElement.offsetTop;
			//ypos = e.srcElement.offsetTop;
			ypos = e.clientY + st - 10;

			targ = e.srcElement.parentElement;
			
			//try to avoid mouse over message Div problem by moving up the offset a bit
			if ( e.srcElement.offsetHeight > 20 ) {
				yoffset = e.srcElement.offsetHeight - 20 ;
			} else {
				yoffset = e.srcElement.offsetHeight;
			}

			//alert(xpos + " " + ypos);

		}

		else {
			/*use prototype to get the position more correctly cross browsers*/
			var posArray = Position.positionedOffset( e.currentTarget );
			xpos = posArray[0];
			ypos = posArray[1];
			
			/*if you do not want prototype js, uncomment the following 2 line to get it work*/
			//xpos = e.currentTarget.offsetLeft;
			//ypos = e.currentTarget.offsetTop;
			
			//try to avoid mouse over message Div problem by moving up the offset a bit
			if ( e.currentTarget.offsetHeight> 20 ) {
				yoffset = e.currentTarget.offsetHeight -20 ;
			}
			else {
				yoffset = e.currentTarget.offsetHeight;
			}

		}
		/*
		try {
			if ( ( xpos + winWidth ) > bodyWidth ) {
				xpos = xpos + winWidth - bodyWidth;
			}
		} catch(e){}
		*/
		
	}
	
