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._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;

	var _DCloseBtnD=document.createElement("div");
	_DCloseBtnD.className='wpm-dialog-closeb';
	
	this._DialogClose=document.createElement("input");
	this._DialogClose.id=this._DialogName+'C'+this._zIndex;
	this._DialogClose.type='button';
	this._DialogClose.value='Ok';
	_DCloseBtnD.appendChild(this._DialogClose);
	this._Dialog.appendChild(_DCloseBtnD);

	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];

	postop=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';
	this._Dialog.style.visibility='visible';
	if(!this.is_opera)	new Effect.Appear(this._DialogName+this._zIndex, { duration: 0.2, 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);
			}
			}
		}

	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;
			}
			}
	}
//	} catch(e) {}
}

WPMdialog.prototype.close  = function() {
	this._Dialog.style.visibility='hidden';
	document.body.removeChild(this._Dialog);
}

WPMdialog.prototype.setText = function(txt) {
	this._DialogTxt.innerHTML=txt;
}