var divDialog;

function divDialogInit(){
	divDialog = new divDialog();
}

function divDialog(){
	this.dialog = document.getElementById('DIV_DIALOG');
	this.dialogTitle = document.getElementById('DIV_DIALOG_TITLE');
	this.contentContainer = document.getElementById('DIV_DIALOG_CONTENT');
	this.titleContainer = document.getElementById('DIV_DIALOG_TITLE_CONTAINER');
	this.crollContainer = document.getElementById('DIV_DIALOG_SCROLL');
	
	this.close = closeDialog;
	this.setSize = setSize;
	this.setContent = setContent;
	this.show = show;
	this.positionCenter = positionCenter;
	this.setTitle = setTitle;
	
	this.shown = false;
	
	this.setSize(200,300);
}

function setTitle(title){
	this.dialogTitle.innerHTML=title;
}

function show(){
	if(!this.shown) this.positionCenter();
	
	this.dialog.style.display='';
	this.contentContainer.style.display='';
	this.titleContainer.style.display='';
	
	this.shown = true;
}

function positionCenter(){
	var height = (document.all) ? document.body.clientHeight : window.innerHeight;
	var width  = (document.all) ? document.body.clientWidth : window.innerWidth;
	var myScroll = (document.all) ? document.body.scrollTop : window.pageYOffset;
		
	this.dialog.style.top = (height/2-this.dialog_height/2 + myScroll);
	this.dialog.style.left = (width/2-this.dialog_width/2);
}

function setSize(w,h){
	this.dialog_width = w;
	this.dialog_height = h;
	
	this.dialog.style.width = w;
	this.crollContainer.style.width = w;
	this.crollContainer.style.height = h;
}

function setContent(html){
    this.contentContainer.innerHTML = html;
}


function closeDialog(){
	this.contentContainer.innerHTML = '';
	this.dialog.style.display='none';
	this.contentContainer.style.display='none';
	this.titleContainer.style.display='none';
	this.setTitle("");
	this.shown = false;
}

////////////////////////
// Dragging           //
////////////////////////

var ie=document.all;
var nn6=document.getElementById&&!document.all;

var isdrag=false;
var x,y;
var dobj;

function movemouse(e)
{
  if (isdrag)
  {
    dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
    dobj.style.top  = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
    return false;
  }
}

function selectmouse(e) 
{
  var fobj       = nn6 ? e.target : event.srcElement;
  var topelement = nn6 ? "HTML" : "BODY";
	
	
  while (fobj.tagName != topelement){
  	try{
		if( fobj.getAttribute('dragid') != null ){
			break;
		}
	}catch(error){}
    fobj = nn6 ? fobj.parentNode : fobj.parentElement;
  }
  
 
  if (fobj.getAttribute('dragid') != null){
    fobj = document.getElementById(fobj.getAttribute('dragid'));
	isdrag = true;
    dobj = fobj;
    tx = parseInt(dobj.style.left+0);
    ty = parseInt(dobj.style.top+0);
    x = nn6 ? e.clientX : event.clientX;
    y = nn6 ? e.clientY : event.clientY;
    document.onmousemove=movemouse;
    return false;
  }
}

document.onmousedown=selectmouse;
document.onmouseup=new Function("isdrag=false");

