var Xoffset = 0;
var Yoffset = 0;
var DragDialogTrue = false;
var DialogboxName = "";
var DialogboxObject;
var nn6=document.getElementById&&!document.all;
var zIndex = 2000;
var spopwcount = 0;

function DialogBoxDiv(dialogbox,title,body,top,left,right,bottom,url)
{
 if (!url)
  url = "onClick=\"CloseDialogBox('" + dialogbox + "');\"";

  dialog = "";
  if (top || left || right || bottom)
  { 
   dialog += "<table border=\"0\">\n<tr>\n<td>";
   if (top)
   {
    dialog += top + "</td></tr>\n<tr>\n<td>";
   }
   if (left)
   {
    dialog += left + "</td><td>\n";
   }
  }
  dialog += "<div class=\"dialogs\">";
  dialog += "<div class=\"dheaders\">";
  dialog += "<div class=\"dtops\">";
  dialog += "<div class=\"dcontainers\">";
  dialog += "<div class=\"dtitles\">" + title + "<a " + url + "  class=\"dialogcloses\"></a></div></div></div></div>";
  dialog += "<div class=\"dmiddles\">\n";
  dialog += "<div class=\"dcontainers\">\n";
  dialog += "<div class=\"dbodys\">\n";
  dialog += "<div class=\"dtextbodys\">\n";
  dialog +=  body;
  dialog += "</div></div></div></div>\n";
  dialog += "<div class=\"dfooters\"><div class=\"dbottoms\"><div class=\"dcontainers\"></div></div></div></div>\n";
  if (top || left || right || bottom)
  { 
   dialog += "</td>";
   if (right)
   {
    dialog += "<td>" + right + "</td>\n";
   }
   if (bottom)
   {
    dialog += "</tr>\n<tr>\n<td align=\"left\" colspan=\"3\">" + bottom + "</td>\n";  
   }  
   dialog += "</tr>\n<table>\n";
  }
 return dialog;
}

function DialogBox(dialogbox,title,body,width,height,url)
{
 DialogBoxFull(dialogbox,title,body,width,height,"","","","",url)
}

function DialogBoxFull(dialogbox,title,body,width,height,top,left,right,bottom,url)
{
 wwidth = document.documentElement.clientWidth - 40;
 hheight = document.documentElement.clientHeight - 156;
 posX = PosXSearch(width);
 posY = PosYSearch(height);
 document.getElementById(dialogbox).innerHTML = DialogBoxDiv(dialogbox,title,body,top,left,right,bottom,url);

 document.getElementById(dialogbox).style.display = "block";
 document.getElementById(dialogbox).style.width = width + 80 + "px";
 document.getElementById(dialogbox).style.height = height + 50 + "px";
 document.getElementById(dialogbox).style.top = posY + "px";
 document.getElementById(dialogbox).style.left = posX + "px";
 DialogboxName = dialogbox;

}

function PosXSearch(width)
{
 wwidth = document.documentElement.clientWidth;
 posX = wwidth - (width+50);
 if (posX < 1) posX = 0;
 if (posX > 0)
 {
  posX = Math.round(posX / 2);
 }
 return posX;
}

function PosYSearch(height)
{
 hheight = document.documentElement.clientHeight;
 posY = hheight - (height + 155);
 if (posY < 1) posY = 0;
 if (posY > 0)
 {
  posY = Math.round(posY / 2);
 }
 posY = posY + YOffset()
 -10;
 return posY;
}

 function YOffset()
 {
 Yoffset = window.pageYOffset; if(!Yoffset)
 Yoffset = document.body.scrollTop;
 if(!Yoffset)
 Yoffset = document.documentElement.scrollTop;
 if(!Yoffset)
 Yoffset = 0;
 return Yoffset;
}

function CloseDialogBox(dialogbox)
{
 document.getElementById(dialogbox).innerHTML = '';
 document.getElementById(dialogbox).style.width = "0px";
 document.getElementById(dialogbox).style.height = "0px"; 
 document.getElementById(dialogbox).style.display = "none";
}

//function CloseImageBoxAndClearBox(dialogbox,imagetarget)
//{
// document.getElementById(imagetarget).innerHTML = '';
// document.getElementById(dialogbox).style.display = "none";
//}


function DragDialogBox(e)
{
if (e == null)
 e = window.event;
 if (DragDialogTrue && e.button <= 1)
 {
  DialogboxObject.style.left = e.clientX - Xoffset + 'px';
  DialogboxObject.style.top  = e.clientY - Yoffset + 'px';
 }
}

function DropDialogBox(e)
{
 document.onmousemove = '';
 document.onmouseup = '';
 DragDialogTrue = false;
}

function SearchPopupWindow(object)
{
 object = nn6 ? object.parentNode : object.parentElement;
 if (object.className == "popupwindow")
 {
  DialogboxObject = object;
  return true;
 }
 spopwcount++;
 if (spopwcount == 20) return false;
 
 SearchPopupWindow(object);
}

function DragAndDropDialogbox(e)
{
 if (e == null)
  e = window.event;
 var target = e.target != null ? e.target : e.srcElement;
 if (target.className == "dialogTitleIE" || target.className == "dtitles" || target.className == "selectdialog")
 {
  SearchPopupWindow(target);
  if (spopwcount == 20)
  {
   spopwcount = 0;
   return false;
  }
  DragDialogTrue = true;
  zIndex = zIndex + 1;
  DialogboxObject.style.zIndex =  zIndex;
  Xoffset = e.clientX - parseInt(DialogboxObject.style.left);
  Yoffset = e.clientY - parseInt(DialogboxObject.style.top);
  document.onmousemove = DragDialogBox;
  document.onmouseup = DropDialogBox;
 }
}

document.onmousedown = DragAndDropDialogbox;


