function LoadingWND() {
	var bIE = (/MSIE (5\.5|6).*Windows/.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent));
	var bOpera = bOpera = (/opera/i.test(navigator.userAgent));
	var wndId = "loading-window-container";
	var imgDir = "http://freepersonals.ru/images/";
	
	this.CreateWindow= function(iWidth,iHeight, sText) {
		this.DropWindow();
		var objWndDiv = document.createElement('DIV');		
		objWndDiv.id = wndId;
		objWndDiv.style.zIndex = 20000;
		objWndDiv.style.position = "absolute";
		objWndDiv.style.left = "0px";
		objWndDiv.style.top = "0px";

		objWndDiv.style.visibility="hidden";
		objWndDiv.style.textAlign = "center";
		
		objWndDiv.innerHTML = '<table cellspacing="0" class="loading-window-main">'+
			'<tr><td class="loading-window-pic"><img src="'+imgDir+'loading.gif"></td><td class="loading-window-text">'+sText+'</td></tr>'+
			'</table>';		;
		
		document.body.appendChild(objWndDiv);

		wndSize = this.GetObjSize(objWndDiv);
		if(iWidth>0) objWndDiv.style.width = iWidth+"px";
		else iWidth = wndSize.x;
		if(iHeight>0) objWndDiv.style.height = iHeight+"px";
		else iHeight = wndSize.y;

		if((objWndDiv.style.height*1)<iHeight) objWndDiv.style.height = iHeight+"px";

		this._moveToCenter(objWndDiv,iWidth,iHeight);

		objWndDiv.style.visibility="visible";
		
		return objWndDiv;
	};	

	this.DropWindow = function() {		
		objWndDiv = document.getElementById(wndId);
		if (objWndDiv) document.body.removeChild(objWndDiv);		
	};	

	this.GetBrowserSize = function() {
		var x,y;
		if (self.innerHeight) {
			x = self.innerWidth;
			y = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
		} else if (document.body) {
			x = document.body.clientWidth;
			y = document.body.clientHeight;
		}
		return {x: x, y: y};
	}
	
	this.GetObjSize = function(obj) {
		var x,y;
		x = obj.offsetWidth || obj.style.pixelWidth || this.__findOffsetWidth(obj);
		y = obj.offsetHeight || obj.style.pixelHeight || this.__findOffsetHeight(obj);
		return {x: x, y: y};
	}
	
	this.GetScrollXY = function() {
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} 
		else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} 
		else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		return {x: scrOfX, y: scrOfY};
	}
	
	this.__findOffsetWidth = function(e) {
		var res = 0;
    		while ((res == 0) && e.parentNode) {
        		e = e.parentNode;
        		res = e.offsetWidth;
    		}
    		return res;
	}
	
	this.__findOffsetHeight = function(e) {
		var res = 0;
		while ((res == 0) && e.parentNode) {
        		e = e.parentNode;
        		res = e.offsetHeight;
    		}
    		return res;
	}

	this._moveToCenter = function (objWnd, iWidth, iHeight) {
		
		scrXY = this.GetScrollXY();		
		wndSize = this.GetObjSize(objWnd);
		if(iWidth<=0) iWidth = wndSize.x;
		if(iHeight<=0) iHeight = wndSize.y;
		
		browserSize = this.GetBrowserSize();

		var marginLeft = ((browserSize.x-iWidth)/2+scrXY.x);
		if(marginLeft<=0) marginLeft = 10;
		objWnd.style.marginLeft=marginLeft+"px";

		var marginTop = ((browserSize.y-iHeight)/2+scrXY.y);
		if(marginTop<=0) marginTop = 10;
		objWnd.style.marginTop=marginTop+"px";
	};
}

var loading = new LoadingWND();
	

