var Xoffset = 0;
var Yoffset = 0;   
var DragDialogTrue = false; 
var DialogboxName = "";

   
function DialogBoxDiv(dialogbox,title,body)
{
 
  dialog = "<div class=\"dialogs\">";
  dialog += "<div class=\"dheaders\">";
  dialog += "<div class=\"dtops\">";
  dialog += "<div class=\"dcontainers\">";
  dialog += "<div class=\"dtitles\">" + title + "<a onClick=\"CloseDialogBox('" + dialogbox + "')\"  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";
 return dialog;
}

function DialogBox(dialogbox,title,body,width,height)
{
 wwidth = document.documentElement.clientWidth - 40;
 hheight = document.documentElement.clientHeight - 156;
 posX = PosXSearch(width);
 posY = PosYSearch(height);
 document.getElementById(dialogbox).innerHTML = DialogBoxDiv(dialogbox,title,body);

 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).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)
 {
  document.getElementById(DialogboxName).style.left = e.clientX - Xoffset + 'px';
  document.getElementById(DialogboxName).style.top  = e.clientY - Yoffset + 'px';		 
 }
}

function DropDialogBox(e)
{
 document.onmousemove = '';
 document.onmouseup = '';
 DragDialogTrue = false;
}

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")
 {  
  DragDialogTrue = true;
  Xoffset = e.clientX - parseInt(document.getElementById(DialogboxName).style.left);
  Yoffset = e.clientY - parseInt(document.getElementById(DialogboxName).style.top);
  document.onmousemove = DragDialogBox;
  document.onmouseup = DropDialogBox;
 }
}
  
document.onmousedown = DragAndDropDialogbox;  


