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){
		
		xMoveTo(this.dialog,xScrollLeft()+(xClientWidth()-this.dialog.offsetWidth)/2,this.smesch + xScrollTop()+(xClientHeight()-this.dialog.offsetHeight)/2);}
		
	
	}
};

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){
			e.style.zIndex = this.dialog.greyZIndex;
			xMoveTo(this.dialog, -this.dialog.offsetWidth, 0);
		}
		
		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 = {};

