function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	var arrayPageSize = [w,h];
	return arrayPageSize;
}

function getPageSizeScroll(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		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
		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;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
}

function bodyOverlay() {
	  var objBody = document.getElementsByTagName('body').item(0);
	  var pageSize = getPageSize();
	  var bodyOverlay = document.createElement("div");
	  bodyOverlay.setAttribute('id','bodyOverlay');
	  bodyOverlay.style.height = pageSize[1] + 'px';
	  bodyOverlay.style.width = pageSize[0] + 'px';	  
	  if (!document.getElementById('bodyOverlay')) {
		    objBody.insertBefore(bodyOverlay, objBody.firstChild);		    
		    FadeIn(document.getElementById('info'), 0);
		    document.getElementById('info').style.display = 'block';
		    document.getElementById('info').style.zIndex = '9999';
		    document.getElementById('user').value = '';
		    document.getElementById('user').focus();
	  }	  
}

function removeOverlay() {	 
	  var bodyOverlay = document.getElementById('bodyOverlay');
	  if (bodyOverlay) {
		    bodyOverlay.parentNode.removeChild(bodyOverlay);		    		    
		    FadeOut(document.getElementById('info'), 100);		    
	  }	  
}

function handleBodyResize()
{
	var bodyOverlay = document.getElementById("bodyOverlay");	
	
	if(bodyOverlay) {
		var pageSize = getPageSize();
		bodyOverlay.style.height = pageSize[1] + 'px'; 
		bodyOverlay.style.width = pageSize[0] + 'px'; 		
	}
}

function FadeIn(element, opacity) {
	var reduce_opacity_by = 10;
	var rate = 30;	// 15 fps


	if (opacity < 100) {
		opacity += reduce_opacity_by;
		if (opacity > 100) opacity = 100;

		if (element.filters) {
			try {
				element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
			} catch (e) {
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
			}
		} else {
			element.style.opacity = opacity / 100;
		}
	}

	if (opacity < 100) {
		setTimeout(function() { FadeIn(element, opacity); }, rate);
	}
}

function FadeOut(element, opacity) {
	var reduce_opacity_by = 10;
	var rate = 30;	// 15 fps

	if (opacity > 0) {
		opacity -= reduce_opacity_by;
		if (opacity < 0) opacity = 0;

		if (element.filters) {
			try {
				element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
			} catch (e) {
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
			}
		} else {
			element.style.opacity = opacity / 100;
		}
	}

	if (opacity > 0) {
		setTimeout(function() { FadeOut(element, opacity); }, rate);
	}
	else {
		element.style.display = "none";
	}
}

