function refreshPosition(layerName)
{
	window.scrollTo(0,0);
	var W = Utils.getViewportWidth();
	var H = Utils.getViewportHeight();
    var w_center = parseInt(W/2);
    var h_center = parseInt(H/2);   
    var popup = $('window').down('.popUp');
    if (!popup)
    	var popup = $('window').down('.popUp1');
    if (!popup)
    	var popup = $('window').down('.popUp2');
    if (!popup)
    	return;
    var X = w_center - parseInt(popup.getWidth()/2);
    var Y = h_center - parseInt(popup.getHeight()/2);
    popup.style.left = (X) + 'px';
    popup.style.top = (Y) + 'px';
    resizeOverlay();
}

function showStaticPopup(layerName)
{
	_createPopupLayer(layerName);
	refreshPosition(layerName);        		
}

function _createPopupLayer( innerContentBlockId )
{
	var overlayDiv = $('overlay');
	if( !overlayDiv){
		overlayDiv = document.createElement('div');
		overlayDiv.id="overlay";		
		document.getElementsByTagName('body')[0].appendChild(overlayDiv);
	}
	//overlayDiv.style.height = '100%';//$$('div.all')[0].getHeight()+'px';
	var wH = getPageSize()[1];
	var wW = getPageSize()[0];
	var mainContainer = $$('.all')[0];
	var mH = 0;
	if (mainContainer)
	{
		mH = mainContainer.getHeight();
		if (mH > wH)
		{
			wH = mH;
		}
	}
	overlayDiv.style.height = wH + 'px';
	overlayDiv.style.width = wW + 'px';
	overlayDiv.style.display = "block";
	
	var windowDiv = $('window');
	if( !windowDiv ){
		windowDiv = document.createElement('div');
		windowDiv.id="window";
		document.getElementsByTagName('body')[0].appendChild(windowDiv);
	}
	windowDiv.style.display = "block";
	windowDiv.className = "done";	

	var lbContentDiv = document.createElement('div');
	lbContentDiv.id="lbContent";
	windowDiv.appendChild(lbContentDiv);

	var W = Utils.getViewportWidth();
	var H = Utils.getViewportHeight();
	
	window.scrollTo(0,0);
    var w_center = parseInt(W/2);
    var h_center = parseInt(H/2);
    var X = w_center - $(innerContentBlockId).getWidth()/2;
    var Y = h_center - $(innerContentBlockId).getHeight()/2;

    var _content = $(innerContentBlockId).down(0);
	if(undefined != _content)
	{
		lbContentDiv.appendChild(_content);
		_content.style.left = (X) + 'px';
		_content.style.top = (Y) + 'px';
	}
	var IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
	var IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 7;
	var IE8 = Prototype.Browser.IE && !IE6 && !IE7;
	if((Prototype.Browser.IE && !IE8) || Prototype.Browser.Opera)
	{
		document.body.style.overflow='';
	}
	else
	{
		document.body.style.overflowX='hidden';
	}
	
	var objResizeEvent = refreshPosition.bindAsEventListener(this,innerContentBlockId);
	Event.observe(window, 'resize', objResizeEvent);
}

function closeWindow(layerName)
{
	_destroyPopupLayer(layerName);
	location.reload(true);

}

function _destroyPopupLayer( layerName )
{
//	alert($(layerName));
	$(layerName).innerHTML = $('lbContent').innerHTML;
	//console.log( $(layerName).innerHTML );
	//$(layerName).appendChild( $('win-form').down('div.inner').down(0));
	
	/*
	Element.remove('overlay');
	Element.remove('window');
<div id="overlay"/>
<div id="window" class="loading"/>	 
	*/
	
	$('overlay').style.display ="";
	
	Element.remove( $('window').down(0) );
	$('window').className = "loading";
	$('window').style.display = "";
	if( $('popup-invalid-inputs') && $('bbox-add-inputs'))
	{
		$('popup-invalid-inputs').hide();
		$('popup-valid-inputs').hide();
	}		
	var IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
	var IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 7;
	var IE8 = Prototype.Browser.IE && !IE6 && !IE7;
	if((Prototype.Browser.IE && !IE8) || Prototype.Browser.Opera)
	{
		document.body.style.overflow='';
	}
	else
	{
		document.body.style.overflowX='';
	}
	//Element.clearChildren( $('window') );
}

function getPageSize()
{
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	
	//console.log("xScroll " + xScroll)
	//console.log("windowWidth " + windowWidth)
	
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	
	//console.log("pageWidth " + pageWidth)
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function resizeOverlay()
{
	var overlayDiv = $('overlay');
	if (overlayDiv)
	{
		var wH = getPageSize()[1];
		var wW = getPageSize()[0];
		var mainContainer = $$('.all')[0];
		var mH = 0;
		if (mainContainer)
		{
			mH = mainContainer.getHeight();
			if (mH > wH)
			{
				wH = mH;
			}
		}
		overlayDiv.style.height = wH + 'px';
		overlayDiv.style.width = wW + 'px';
	}	
}

