/* 
 * demoPopup.js
 * Created: 2007-11-20
 * Author: Jeff McLennan
 * Display a div with the passed in msg and display above all content on page
 *
 * Notes: Button isn't displaying on right as desired.
 */
 
var demoPopupId = 'demoPopup';
var msgDivId = 'msgDiv';
 
function demoPopup(msg) {
  closeDemoPopup();
  
  if (msg == null || msg.length == 0) {
    msg = "This feature is available upon purchase of AdvanceTracker. Please contact your sales representative for more information.";
  }

  // Get demoPopup DIV
  var popupDiv = document.getElementById(demoPopupId);
  var popupDivWidth = 400;
  
  var posLeft = (windowWidth() / 2) - (popupDivWidth / 2); 
  var posTop = (windowHeight() / 3);
  
  // Create DIV holding msg
  var msgDiv = document.createElement('div');
  msgDiv.setAttribute('id',msgDivId);
  msgDiv.innerHTML = msg + '<br/><br/><div style="width: 95%; text-align: right; display: block;"><input type="button" value="   OK   " onclick="closeDemoPopup()" /></div>';
  
  // Append msgDiv to popupDiv
  popupDiv.appendChild(msgDiv);
  
  // Make popupDiv visible
  popupDiv.style.position = 'absolute';
  popupDiv.style.zIndex = 100;
  popupDiv.style.padding = '5px';
  popupDiv.style.left = posLeft + 'px';
  popupDiv.style.top = posTop + 'px';
  popupDiv.style.width = popupDivWidth + 'px';
  popupDiv.style.display = 'block';
}

function closeDemoPopup() {
  // Find the elements needed to clean up
  var popupDiv = document.getElementById(demoPopupId);
  var msgDiv = document.getElementById(msgDivId);
  
  // Hide popupDiv
  popupDiv.style.display = 'none';
  
  // Remove the msg div so next popup is clean
  if (msgDiv) {
    popupDiv.removeChild(msgDiv);
  }
}

function windowWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function windowHeight() {
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}