	/************************************************************************/
	/*                                                                      */
	/* Copyright 2010 by Stan Reckard     (www.artbylogic.com)              */
	/*                                                                      */
	/* This file and its contents are copyrighted by Stan Reckard.  All     */
	/* rights reserved. No content, programming code or images may be sold, */
	/* published or distributed without express permission from the author. */
	/* Do not remove copyright notices.  By violating these terms you may   */
	/* be held liable for any resulting loss or damage.                     */
	/*                                                                      */
	/* No support, guarantee or warranty is offered or implied. By using    */
	/* any of this code you assume full risk and responsibility for that    */
	/* use.  Written permission must be obtained before any use.            */
	/*                                                                      */
	/************************************************************************/

function findPositionWithScrolling( oElement ) {
  if( typeof( oElement.offsetParent ) != 'undefined' ) {
    var originalElement = oElement;
    for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
      posX += oElement.offsetLeft;
      posY += oElement.offsetTop;
      if( oElement != originalElement && oElement != document.body && oElement != document.documentElement ) {
        posX -= oElement.scrollLeft;
        posY -= oElement.scrollTop;
      }
    }
    //return [ posX, posY ];
    return { x:posX, y:posY };
  } else {
    //return [ oElement.x, oElement.y ];
    return { x:oElement.x, y:oElement.y };
  }
}

function findPositionWithScrollingEx( oElement ) {
  function getNextAncestor( oElement ) {
    var actualStyle;
    if( window.getComputedStyle ) {
      actualStyle = getComputedStyle(oElement,null).position;
    } else if( oElement.currentStyle ) {
      actualStyle = oElement.currentStyle.position;
    } else {
      //fallback for browsers with low support - only reliable for inline styles
      actualStyle = oElement.style.position;
    }
    if( actualStyle == 'absolute' || actualStyle == 'fixed' ) {
      //the offsetParent of a fixed position element is null so it will stop
      return oElement.offsetParent;
    }
    return oElement.parentNode;
  }
  if( typeof( oElement.offsetParent ) != 'undefined' ) {
    var originalElement = oElement;
    for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
      posX += oElement.offsetLeft;
      posY += oElement.offsetTop;
    }
    if( !originalElement.parentNode || !originalElement.style || typeof( originalElement.scrollTop ) == 'undefined' ) {
      //older browsers cannot check element scrolling
      return [ posX, posY ];
    }
    oElement = getNextAncestor(originalElement);
    while( oElement && oElement != document.body && oElement != document.documentElement ) {
      posX -= oElement.scrollLeft;
      posY -= oElement.scrollTop;
      oElement = getNextAncestor(oElement);
    }
    //return [ posX, posY ];
    return { x:posX, y:posY };
  } else {
    //return [ oElement.x, oElement.y ];
    return { x:oElement.x, y:oElement.y };
  }
}

function getPosXY(obj) {
	var curleft = curtop = 0;

	// If the browser supports offsetParent we proceed.
	if (obj.offsetParent) {
		// Every time we find a new object, we add its offsetLeft and offsetTop to curleft and curtop.
		do {
			if (obj.tagName == 'DIV') {  // WHY????
				continue;
			}
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			alert(obj.offsetTop + '  tag=' + obj.tagName + ' id=' + obj.id + '  position: ' + obj.style.position);
		} while (obj = obj.offsetParent);

		return {x:curleft, y:curtop};
	}
	else
		return {x:obj.offsetLeft, y:obj.offsetTop};
}



// set the opacity of the passed object
function setOpacity(obj, value) {
	obj.style.opacity = value/10;
	obj.style.filter = 'alpha(opacity=' + value*10 + ')';
}

// navigator.appVersion is not reliable so we use navigator.userAgent
// Example value:  Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)
// Returns -1 if not in IE
function getIEVersion() {
	var verStr = navigator.userAgent;
	var pos = verStr.indexOf("MSIE ");

	if (pos == -1)
		return -1;

	var ver = parseFloat(verStr.substr(pos+5));
	//alert('IE version ' + ver);
	return ver;
} // end getIEVersion()

 
// This "modal dialog" is actually written (until later removed) to the document's HTML
function showDialog(contentHTML, parentEl, isModal, posX, posY, width, height, menuCnt) {
	// Margin, top, left, width and height center the iframe horizontally and vertically:
	// If the isModal parameter is not passed, then default to being modal
	if (!menuCnt)
		menuCnt = 1;
	
	if (width)
		width = parseInt(width);

	if (height)               
		height = parseInt(height);

	if (isModal == null)
		isModal = true;
				   

	// If no position is specified, then use the current mouse position           
	if (!posX)
		posX = 0;

	if (!posY)
		posY = 0;

	if (!parentEl)
		parentEl = document.body;

	var menuZ = 500;
	var modalZ = menuZ - 100;														  
	var ieVer = getIEVersion();
	
	//alert('posX=' + posX + ' posY=' + posY + '  width=' + width + '  height=' + height);
	
			   
	//menuCnt++;
   
	var icd;
	var pageCoverDIV;         

	//alert(ieVer);
	if ((ieVer < 7) && (ieVer != -1)) {
		// Create an iFrame shim so that drop down controls won't overlay our DIVs under IE 6.
		// Note: On IE6 if there is a drop down on the dialog it may cause a repaint when the user
		// selects an item from the drop down on the dialog.
		var iFrameDivID = 'iModalShim';
		icd = document.createElement("iFrame");
		//icd.setAttribute("id", iFrameDivID);
		icd.className = 'iFrameDIV';
		icd.setAttribute("src", "javascript:false;");
		icd.setAttribute("scrolling", "no");
		icd.setAttribute ("frameborder", "0");
		icd.style.zIndex = parseInt(menuZ) - 1;   // '499';  // place just below the container DIV
		icd.style.overflow = 'hidden';
		//icd.style.width ="100%";
		//icd.style.height = "100%";

		if (width)
			icd.style.width = parseInt(width + 4) + 'px';

		if (height)
			icd.style.height = parseInt(height + 4) + 'px';      
		//document.body.appendChild(icd);
	}


	//create container DIV
	var cd = document.createElement('div');             

	cd.id = 'modalDlgContainer' + menuCnt;
	cd.className = 'modalDlgContainer';

//cd.style.background = document.bgColor;

	//cd.style.MozOpacity = '0.75';
	cd.style.position = 'absolute';    

	//cd.style.top = '50px'; 
	//cd.style.left = '50px';

	cd.style.top = parseInt(posY) + 'px';
	cd.style.left = parseInt(posX) + 'px';

	if (width)
		cd.style.width = parseInt(width + 4) + 'px';

	if (height)
		cd.style.height = parseInt(height + 4) + 'px';

	//cd.style.overflow = 'hidden';
cd.style.overflow = 'visible';		
	cd.style.zIndex = parseInt(menuZ);  // '500';

	//               if (isModal)
	//                   cd.onmouseleave = function() { removeMenu(parentEl, cd, pageCoverDIV); };
	//               else
	//                   cd.onmouseleave = function() { removeMenu(parentEl, cd); };
  
	//create modal div
	md = document.createElement('div');   
	md.id = 'modalDlgContent' + menuCnt;
	md.className = 'modalDlgContent';
//md.style.background = document.bgColor;        
	////md.style.border = '4px ridge #ddd';        
	md.style.position = 'absolute';
	md.style.left = '0';
	md.style.top = '0';
	//md.style.width = '100%';

	if (width)
		md.style.width = width + 'px';

	//md.style.height = '100%';
	if (height)
		md.style.height = height + 'px';

	md.style.padding = '0';
	md.style.paddingBottom = '0px';  // 50
	md.style.paddingTop = '0px';  // 30
	md.style.margin = '2px';

//md.style.overflow = 'hidden';
md.style.overflow = 'visible';

	//md.style.zIndex = parseInt(menuZ);  // '500';
	// Set the guts of the "modal dialog"
	md.innerHTML = contentHTML;               
//md.onclick = function() { removeMenu(parentEl, cd, pageCoverDIV); };

	cd.appendChild(md);
	if ((ieVer < 7) && (ieVer != -1))
		cd.appendChild(icd);  // add iFrame shim to prevent drop down from showing thru on IE  

	if (isModal) {
		// Add a transparent DIV over the document and under the modal dialog so that the user can't click on
		// something other than the modal dialog and get functionality.
		pageCoverDIV = document.createElement('div');
		pageCoverDIV.style.zIndex = parseInt(modalZ);  // '400';  // make this higher than the background document but less than the dialog
		pageCoverDIV.id = 'disableNonDlg' + menuCnt;
		pageCoverDIV.style.width = '100%';
		pageCoverDIV.style.height = '100%';
		pageCoverDIV.style.position = 'absolute';
		pageCoverDIV.style.top = '0';
		pageCoverDIV.style.left = '0';
		pageCoverDIV.style.position = 'absolute';
		pageCoverDIV.style.backgroundColor = 'gray';
		setOpacity(pageCoverDIV, 4);     // set opacity to 40%
	}

	// For IE 6 to prevent the user from interacting with drop downs on the background page, add an iFrame that covers the
	// background with a z-index higher than the background but lower than the modal dialog.  This prevents the user from
	// seeing drop downs that would otherwise bleed through the dialog as well.
	var pageCoverIFrame;

	if ((ieVer < 7) && (ieVer != -1) && isModal) {
		//alert('IE version = ' + ieVer);
		pageCoverIFrame = document.createElement("iFrame");
		pageCoverIFrame.setAttribute("id", 'iModalBackground');
		pageCoverIFrame.setAttribute("src", "javascript:false;");
		pageCoverIFrame.setAttribute("scrolling", "no");
		pageCoverIFrame.setAttribute ("frameborder", "0");
		pageCoverIFrame.style.zIndex = parseInt(modalZ) - 1;  // '399';  // place just below the modal dialog but above the background
		pageCoverIFrame.style.overflow = 'hidden';
		pageCoverIFrame.style.width = "100%";
		pageCoverIFrame.style.height = "100%";
		pageCoverIFrame.style.top = '0';
		pageCoverIFrame.style.left = '0';
		pageCoverIFrame.style.position = 'absolute';
		//pageCoverIFrame.style.border = "3px solid red";
		//pageCoverIFrame.style.backgroundColor = 'gray';
		setOpacity(pageCoverIFrame, 0);     // set opacity to 0%
	}

	
	
	if ((ieVer < 7) && (ieVer != -1) && isModal)
		pageCoverDIV.appendChild(pageCoverIFrame);             

	parentEl.appendChild(cd);      

	if (isModal)
		document.body.appendChild(pageCoverDIV);                 
			
	return cd;           
} // end showMenu()
 
function closeDialog(menuNum) {
	if (!menuNum)
		menuNum = 1;
		
	var elID = 'modalDlgContainer' + menuNum;
	var el = document.getElementById(elID);
	if (el)
		el.parentNode.removeChild(el);
	
	elID = 'disableNonDlg' + menuNum;
	el = document.getElementById(elID);
	if (el)
		el.parentNode.removeChild(el);
}
 