var WPM_DragMouse=Array(0,0,0,null,0,0); //0,0,0,dialog obj,Dialog width, Dialog height

var WPMdialog = function (dialog_name,w,offsX,offsY,z,ttl,txt) {
	this._Dialog = null;
	this._DialogHdr = '';
	this._DialogClose = '';
	this._DialogTxt = '';
	this._offsX=offsX;
	this._offsY=offsY;
	this._DialogName=dialog_name;
	this._Width=w;
	this._zIndex=z;
	this._DialogTitle=ttl;
	this._DialogText=txt;
	this.agt = navigator.userAgent.toLowerCase();

	this.is_ie = ((this.agt.indexOf("msie") != -1) && (this.agt.indexOf("opera") == -1));
	this.ie_version = parseFloat(this.agt.substring(this.agt.indexOf("msie")+5));
	this.is_opera = (this.agt.indexOf("opera") != -1);
	this.opera_version = navigator.appVersion.substring(0, navigator.appVersion.indexOf(" "))*1;
	this.is_khtml = (this.agt.indexOf("khtml") != -1);
	this.is_safari = (this.agt.indexOf("safari") != -1);
	this.is_mac = (this.agt.indexOf("mac") != -1);
	this.is_mac_ie = (this.is_ie && this.is_mac);
	this.is_win_ie = (this.is_ie && !this.is_mac);
	this.is_gecko = (navigator.product == "Gecko" && !this.is_safari); // Safari lies!

}

WPMdialog.prototype.show  = function() {
	//	try{
	var w_size=getWorkAreaSize();

	this._Dialog=document.createElement("div");
	this._Dialog.className='wpm-dialog';
	this._Dialog.id=this._DialogName+this._zIndex;
	if(this._Width!='') this._Dialog.style.width=this._Width+'px';
	this._Dialog.style.zIndex=this._zIndex;

	_DHDR=document.createElement("div");
	_DHDR.className='wpm-dialog-header';
	
	this._DialogHdr=document.createElement("div");
	this._DialogHdr.id=this._DialogName+'H'+this._zIndex;
	_DHDR.appendChild(this._DialogHdr);

	this._DialogClose=document.createElement("a");
	this._DialogClose.id=this._DialogName+'C'+this._zIndex;
	_DHDR.appendChild(this._DialogClose);

	this._Dialog.appendChild(_DHDR);

	this._DialogTxt=document.createElement("div");
	this._DialogTxt.className='wpm-dialog-content';
	this._Dialog.appendChild(this._DialogTxt);

	this._DialogHdr.innerHTML=this._DialogTitle;
	this._DialogTxt.innerHTML=this._DialogText;

	document.body.appendChild(this._Dialog);

	var posleft=(w_size[0]/2-this._Dialog.clientWidth/2)+w_size[2];
	var postop=(w_size[1]/2-this._Dialog.clientHeight/2)+w_size[3];

	if(this._offsY!=0) postop=this._offsY;
	posleft=posleft+this._offsX;
	this._Dialog.style.top=postop+'px';
	this._Dialog.style.left=posleft+'px';
	//if(!this.is_opera)	this._Dialog.style.display='none';
	var settings = {
      tl: { radius: 8 },
      tr: { radius: 8 },
      bl: { radius: 8 },
      br: { radius: 8 },
      antiAlias: true
    }
  curvyCorners(settings, this._Dialog);
  this._Dialog.style.display='block';
	this._Dialog.style.visibility='visible';
	//if(!this.is_opera)	new Effect.Appear(this._DialogName+this._zIndex, { duration: 0.4, from: 0, to: 1 });
	this._zIndex++;

	this._DialogClose.onclick = function(event) {
  	event = event || window.event;
  	var el = event.target || event.srcElement
		if(el) {
			el=document.getElementById(el.id);
			while (el.className!='wpm-dialog' && el!=null) {
				el = el.offsetParent;
			}
			if(el && el.className=='wpm-dialog') {
				el.style.visibility='hidden';
				document.body.removeChild(el);
			}
			}
			event.cancelBubble = true;
		}

	this._DialogHdr.onmousedown = function(event) {
		event = event || window.event;
	  WPM_DragMouse[0] = event.offsetX || event.layerX;
 		WPM_DragMouse[1] = event.offsetY || event.layerY;
		k = event.button || event.which;
		WPM_DragMouse[2]=k;

		preventSelection(document);
 		var el = event.target || event.srcElement
		if(el) {
			el=document.getElementById(el.id);
			while (el.className!='wpm-dialog' && el!=null) {
				el = el.offsetParent;
			}
			if(el && el.className=='wpm-dialog') {
				WPM_DragMouse[3]=el;
				WPM_DragMouse[4]=el.clientWidth;
				WPM_DragMouse[5]=el.clientHeight;
			}
			}
		event.cancelBubble = true;
	}

 	this._DialogHdr.onmousemove = function(event) {
		event = event || window.event;
		event.cancelBubble = true;
		DragX = event.x || event.clientX;
		DragY = event.y || event.clientY;
		w_size=getWorkAreaSize();

		DragX+=w_size[2]; DragY+=w_size[3];

		if(WPM_DragMouse[0] && WPM_DragMouse[1] && WPM_DragMouse[2]=='1' && WPM_DragMouse[3]) {
			w_size=getWorkAreaSize();
			if(DragX-WPM_DragMouse[0]<0) return;
			if(DragY-WPM_DragMouse[1]<0) return;
			if(DragX-WPM_DragMouse[0]+WPM_DragMouse[4]>document.body.clientWidth) return;
			if(DragY-WPM_DragMouse[1]+WPM_DragMouse[5]>document.body.clientHeight) return;

			WPM_DragMouse[3].style.left=DragX-WPM_DragMouse[0]+'px';
			WPM_DragMouse[3].style.top=DragY-WPM_DragMouse[1]+'px';
		}
	}

 	this._DialogHdr.onmouseup = function(event) {
 		event = event || window.event;
		WPM_DragMouse=Array(0,0,0,null);
		event.cancelBubble = true;
		unpreventSelection(document);
	}

 	this._DialogHdr.onmouseout = function(event) {
 		event = event || window.event;
		WPM_DragMouse=Array(0,0,0,null);
		event.cancelBubble = true;
	}

//	} catch(e) {}
}

WPMdialog.prototype.close  = function() {
	this._Dialog.style.visibility='hidden';
}

WPMdialog.prototype.resizeDialog = function() {
	//document.getElementById('txt').value+='resize';
}

WPMdialog.prototype.setText = function(txt) {
	this._DialogTxt.innerHTML=txt;
}