
var dialogDivWait = null;
function dialogOpen(txt, buttons, dimensions)
{
   dialogClose();

   var width=0;
   var height=0;

   if (dimensions != null && dimensions != "undefined")
   {
      width = dimensions.width;
      height = dimensions.height;
   }

   if (width == 0)
   {
      width = (31) + (txt.length * 8.75);
      if (width > 800)
      {
         if (height == 0) height = (width - 800) / 10;
         width = 800;
      }
      else if (width < 250) width = 250;
   }

   if (height < 100) height = 100;

   var wc = dialogGetCurrentCentreXY();

   var noPx = document.childNodes ? 'px' : 0;
   var body = document.getElementsByTagName("BODY")[0];

   dialogDivWait = document.createElement("DIV");
   styleRef = dialogDivWait;
   if (styleRef.style) { styleRef = styleRef.style; }
   styleRef.backgroundColor = "rgb(207,222,183)";
   styleRef.position = "absolute";
   styleRef.left = ((wc[0] - (width/2)) - 0) + noPx;
   styleRef.top = ((wc[1] - (height/2)) - 0) + noPx;
   styleRef.width = "450" + noPx;
   styleRef.height = height + noPx;
   styleRef.borderStyle = "solid";
   styleRef.borderWidth = "2" + noPx;
   styleRef.marginLeftWidth = "0";
   styleRef.marginRightWidth = "0";
   styleRef.marginBottomWidth = "0";
   styleRef.borderColor = "rgb(0,0,0)";

   var divTitleImg = document.createElement("DIV");
   styleRef = divTitleImg;
   if (styleRef.style) { styleRef = styleRef.style; }
   styleRef.color = "white";
   styleRef.paddingLeft = "0";
   styleRef.fontWeight = "bold";
   styleRef.display = "block";
   styleRef.paddingTop = "0";
   styleRef.paddingBottom = "0";
   styleRef.paddingLeft = "0";
   styleRef.paddingLeft = "0";
   styleRef.paddingLeft = "0";
   styleRef.fontSize = "9pt";

   var img = document.createElement("IMG");
   img.src = "smartplanner/images/popupHeader.gif";
   styleRef = img;
   if (styleRef.style) { styleRef = styleRef.style; }
   styleRef.height = "30px";
   styleRef.width = "450px";

   divTitleImg.appendChild(img);
   dialogDivWait.appendChild(divTitleImg);

   var divContent = document.createElement("DIV");
   styleRef = divContent;
   if (styleRef.style) { styleRef = styleRef.style; }
   divContent.id = "divContent";
   styleRef.backgroundColor = "rgb(207,222,183)";
   styleRef.paddingTop = "10" + noPx;
   styleRef.borderStyle = "solid";
   styleRef.borderColor = "green";
   styleRef.borderWidth = "0" + noPx;  // MUST BE ZERO
   styleRef.margin = "0" + noPx;
   styleRef.width = "450" + noPx;
   styleRef.height = (height - 40) + noPx;
   dialogDivWait.appendChild(divContent);

   var tabContent = document.createElement("TABLE");
   styleRef = tabContent;
   if (styleRef.style) { styleRef = styleRef.style; }
   tabContent.borderStyle = "none";
   tabContent.borderWidth = "0" + noPx;
   tabContent.borderColor = "blue";
   tabContent.borderCollapse = "collapse";

   divContent.appendChild(tabContent);
   var tabBody = document.createElement("TBODY");
   tabContent.appendChild(tabBody);
   var trContent = document.createElement("TR");
   tabBody.appendChild(trContent);

   var tdText = document.createElement("TD");
   styleRef = tdText;
   if (styleRef.style) { styleRef = styleRef.style; }
   styleRef.paddingLeft = "1em";
   styleRef.fontSize = "10pt";
   styleRef.borderStyle = "none";
   styleRef.borderWidth = "0" + noPx;
   styleRef.borderColor = "blue";
   styleRef.borderCollapse = "collapse";
   tdText.borderStyle = "none";
   tdText.borderWidth = "0" + noPx;
   tdText.borderColor = "blue";
   tdText.borderCollapse = "collapse";
   tdText.id = "tdText";
   tdText.innerHTML = txt;
   trContent.appendChild(tdText);

   if (buttons != null)
   {
      var divButton = document.createElement("DIV");
      styleRef = divButton;
      if (styleRef.style) { styleRef = styleRef.style; }
      styleRef.marginTop = "1em";
      styleRef.textAlign = "center";
      for (var i=0; i<buttons.length; i++)
      {
         var btn = document.createElement("BUTTON");
         styleRef = btn;
         if (styleRef.style) { styleRef = styleRef.style; }
         styleRef.marginLeft = "0.12em";
         styleRef.marginRight = "0.12em";
         btn.innerHTML = buttons[i].text;
         btn.hiddenClick = buttons[i].action;
         btn.onclick = function() { eval(this.hiddenClick); }
         divButton.appendChild(btn);
      }
      divContent.appendChild(divButton);
   }

   body.appendChild(dialogDivWait);

   var mycontent = document.getElementById("mycontent");
   mycontent.className="semiopaque";

   return(divContent);
}

function dialogClose()
{
   if (dialogDivWait == null) return;
   var body = document.getElementsByTagName("BODY")[0];
   body.removeChild(dialogDivWait);
   dialogDivWait = null;

   var mycontent = document.getElementById("mycontent");
   mycontent.className="layout";
}

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

function dialogGetScrollXY()
{
   var scrOfX = 0, scrOfY = 0;
   if (typeof(window.pageYOffset) == 'number')
   {
      // Netscape compliant
      scrOfY = window.pageYOffset;
      scrOfX = window.pageXOffset;
   }
   else if (document.body && (document.body.scrollLeft || document.body.scrollTop))
   {
      // DOM compliant
      scrOfY = document.body.scrollTop;
      scrOfX = document.body.scrollLeft;
   }
   else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
   {
      // IE6 standards compliant mode
      scrOfY = document.documentElement.scrollTop;
      scrOfX = document.documentElement.scrollLeft;
   }
   return [ scrOfX, scrOfY ];
}

function dialogGetCurrentCentreXY()
{
   var ws = dialogGetWindowSize();
   var so = dialogGetScrollXY();

   var x = (ws[0] / 2) + so[0];
   var y = (ws[1] / 2) + so[1];

   //y -= 50;    // Compensate for frame.html header

   return [ x, y ];
}

function DialogButton(text, action)
{
   this.text = text;
   this.action = action;
}

function DialogDimension(width, height)
{
   this.width = width;
   this.height = height;
}

