﻿var CDDLG_tmr;
var CDDLG_ID;

if(window.addEventListener)
{
  window.addEventListener("onresize",CDDLG_WindowResize,false);
  window.addEventListener("onscroll",CDDLG_WindowResize,false);
}
else
{
  window.attachEvent("onresize",CDDLG_WindowResize);
  window.attachEvent("onscroll",CDDLG_WindowResize);
}

function CDDLG_WindowResize(){
  if(document.getElementById(CD_Prefix+"DialogBackDrop")!=null&&document.getElementById(CD_Prefix+"DialogBackDrop").style.display=="block"){
    CDDLG_ResizeBackdrop();
  }
}

function CDDLG_PositionBackDrop(){
  if(CDDLG_tmr){
    window.clearInterval(CDDLG_tmr);
    CDDLG_tmr=null;
  }
  CDDLG_ResizeBackdrop();
  var dlg=document.getElementById(CDDLG_ID);
  if(dlg){
    dlg.style.visibility="visible";
    dlg.style.top=((CDDLG_clientHeight()-dlg.offsetHeight)/2+CDDLG_scrollTop())+"px";    
    dlg.style.left=((CDDLG_clientWidth()-dlg.offsetWidth)/2+CDDLG_scrollLeft())+"px";
  }
}
function CDDLG_ResizeBackdrop()
{
  var c=document.getElementById(CD_Prefix+"DialogBackDrop"); 
  document.body.appendChild(c);
  c.style.width=(CDDLG_scrollWidth())+"px";
  c.style.height=(CDDLG_scrollHeight())+"px";
  c.style.display="block";
}
function CDDLG_clientHeight() {
	return CDDLG_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function CDDLG_clientWidth() {
	return CDDLG_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function CDDLG_scrollTop() {
	return CDDLG_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function CDDLG_scrollLeft() {
	return CDDLG_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function CDDLG_scrollHeight() {	
  if(document.body){
    return CDDLG_filterResults (
      0,
	    0,
	    document.body ? document.body.scrollHeight : 0
	  );
  }
  else{
    return CDDLG_filterResults (
      0,
	    document.documentElement ? document.documentElement.scrollHeight : 0,
	    document.body ? document.body.scrollHeight : 0
	  );
  }		
}
function CDDLG_scrollWidth() {	
  if(document.body){
    return CDDLG_filterResults (
      0,
	    0,
	    document.body ? document.body.scrollWidth : 0
	  );
  }
  else{
    return CDDLG_filterResults (
      0,
	    document.documentElement ? document.documentElement.scrollWidth : 0,
	    document.body ? document.body.scrollWidth : 0
	  );
  }		
}
function CDDLG_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function CDDLG_Help(e,id)
{
  var c=document.getElementById(id);
  c.style.top=((CDDLG_clientHeight()-c.offsetHeight)/2+CDDLG_scrollTop())+"px";    
  c.style.left=((CDDLG_clientWidth()-c.offsetWidth)/2+CDDLG_scrollLeft())+"px";
  c.style.visibility="visible";
}
function CDDLG_CloseHelp(id)
{
  document.getElementById(id).style.visibility="hidden";
}