function xDocSize(){
	var b=document.body, e=document.documentElement;
	var esw=0, eow=0, bsw=0, bow=0, esh=0, eoh=0, bsh=0, boh=0;
	if (e) {esw = e.scrollWidth;eow = e.offsetWidth;esh = e.scrollHeight;eoh = e.offsetHeight;}
	if (b) {bsw = b.scrollWidth;bow = b.offsetWidth;bsh = b.scrollHeight;boh = b.offsetHeight;}
	return {w:Math.max(esw,eow,bsw,bow),h:Math.max(esh,eoh,bsh,boh)};
}

/*



*/


function xModalDialog(sDialogId,smesch,noGray) {

	this.smesch = smesch;
	this.dialog = xGetElementById(sDialogId);
	xModalDialog.instances[sDialogId] = this;
	var e = xModalDialog.grey;
	e = document.createElement('div');
	e.id = 'xMDGE';
	if(noGray) {
		e.className = 'xModalDialogGreyElementTransparent';

	}
	if(!noGray || typeof(noGray) == 'undefined') {
		e.className = 'xModalDialogGreyElement';

	}
	
	xModalDialog.grey = document.body.appendChild(e);
}
xModalDialog.prototype.show = function(){
//	$('helper').show();
	
	var ds, e = xModalDialog.grey;
	if(e)
	{
		ds = xDocSize();
		xMoveTo(e, 0, 0);
		xResizeTo(e, ds.w, ds.h);
		if (this.dialog)
		{
			var x = Math.max(xScrollLeft()+(xClientWidth()-this.dialog.offsetWidth)/2, 0);
			var y = Math.max(this.smesch + xScrollTop()+(xClientHeight()-this.dialog.offsetHeight)/2, 0);
			xMoveTo(this.dialog, x, y);
		}
	}
};

xModalDialog.prototype.hide = function(dialogOnly){
//	$('helper').hide();


	var e = xModalDialog.grey;
	
	if(e){
		if (!dialogOnly) {
			xResizeTo(e, 10, 10);xMoveTo(e, -10, -10);
		}
		
		if (this.dialog){
			this.dialog.style.display = 'none';
		
			//e.style.zIndex = this.dialog.greyZIndex; //this.dialog.greyZIndex = undefined
		//	xMoveTo(this.dialog, -(this.dialog.offsetWidth +(xScrollLeft()+(xClientWidth()-this.dialog.offsetWidth)/2)), 0);
			//alert(this.dialog.greyZIndex);
		}
		
		if(!dialogOnly) {
			while (document.getElementById('xMDGE') != null) {
				$('xMDGE').remove();
			}
		}
		
		
		
//		if (!dialogOnly && document.getElementById('xMDGE') != null ) {
//			$('xMDGE').remove();
//			if (!dialogOnly && document.getElementById('xMDGE') != null ) {
//				$('xMDGE').remove();
//			}
//			if (!dialogOnly && document.getElementById('xMDGE') != null ) {
//				$('xMDGE').remove();
//			}
//		}
		//		if(!dialogOnly) {
		//			$('xMDGE').remove();
		//		}
	}
	
	
};

xModalDialog.grey = null;
xModalDialog.instances = {};
