//version 1.0
var isMac = (navigator.userAgent.toLowerCase().indexOf('mac') != -1);
var isPC = (navigator.userAgent.toLowerCase().indexOf('windows') != -1);
var isIE = (navigator.userAgent.toLowerCase().indexOf('msie') != -1);
var isIE5 = (navigator.userAgent.toLowerCase().indexOf('msie 5.0') != -1);
var isPCIE50 = (isPC && isIE5);
var isFireFox = (navigator.userAgent.toLowerCase().indexOf('firefox') != -1);
var isSafari = (navigator.userAgent.toLowerCase().indexOf('safari') != -1);
var isMacIE = (isIE && isMac);

function truebody(){
	//handles Opera spoofing as IE as well a identifying pages that are labeled as STRICT in the DOCTYPE.  A;so sets the appropriate body object.
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat" && document.documentElement)? document.documentElement : document.body;
}

function getDocWidth(){
	//Gets the entire document width
	//if IE (document.all?)
	docWidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth;
	return docWidth;

}

function getDocHeight(){
	//Gets the entire document height
	//if IE (document.all?)
	//docHeight=document.all? truebody().scrollHeight : document.body.offsetHeight;	
	docHeight=truebody().scrollHeight;
	return docHeight;
}

function getClientWidth(){
	//Gets the width of the actual browser window inner space
	//if IE (document.all?)		
	cltWidth=document.all? truebody().clientWidth : window.innerWidth;	
	if (getDocHeight() > getClientHeight()) cltWidth = cltWidth -18;
	
	return cltWidth;	
}

function getClientHeight(){
	//Gets the height of the actual browser window inner space
	//if IE (document.all?)
	cltHeight=document.all? truebody().clientHeight : window.innerHeight;	
	return cltHeight;
}

function refreshMessage(message, width, height){	
	var conWidth = width;
	var conHeight = height;
	if (!document.getElementById('sessionCounterIframe')) {
      var iframeNode = document.createElement('iframe');
      iframeNode.setAttribute('id', 'sessionCounterIframe');      
    }
	else {
		iframeNode = document.getElementById('sessionCounterIframe');
	}
	
	if (!document.getElementById('pageCanvasDiv')) {
      var canvasNode = document.createElement('div');
     canvasNode.setAttribute('id', 'pageCanvasDiv');      
    }
	else {
		canvasNode = document.getElementById('pageCanvasDiv');
	}
	
	
	if (!document.getElementById('messageDiv')) {
      var messageNode = document.createElement('div');
     messageNode.setAttribute('id', 'messageDiv');      
    }
	else {
		messageNode = document.getElementById('counterDiv');
	}
	
	canvasNode.style.width = getClientWidth() + 'px';
	
	if (getDocHeight() > getClientHeight())	canvasNode.style.height = getDocHeight() + 'px';	
	else canvasNode.style.height = getClientHeight() + 'px';
	
	canvasNode.style.top = '0px';
	canvasNode.style.left ='0px';
	canvasNode.style.backgroundColor = '#EBEBEB';
	canvasNode.style.filter = 'Alpha(opacity=70)';
	canvasNode.style.opacity = '0.70';
	canvasNode.style.position = 'absolute';
	

	if (getDocHeight() > getClientHeight()){
		var finalXPos = Math.round((getClientWidth()/2) - (conWidth/2));	
		var finalYPos = Math.round((getClientHeight()/2) - (conHeight/2) + truebody().scrollTop);
	}	
	else if (getDocHeight() < conHeight) {
		var finalXPos = Math.round((getDocWidth()/2) - (conWidth/2));	
		var finalYPos = 0;
		}
		
	else {
		var finalXPos = Math.round((getDocWidth()/2) - (conWidth/2));	
		var finalYPos = Math.round((getDocHeight()/2) - (conHeight/2) + truebody().scrollTop);
		}
	messageNode.style.position = 'absolute';
	messageNode.style.width = conWidth + 'px';
	messageNode.style.height = conHeight + 'px';
	messageNode.style.backgroundColor = 'white';
	messageNode.style.padding = '5px';
	messageNode.style.border = '10px solid #999999';
	
	messageNode.style.fontSize = '13px';
	
	messageNode.style.top = finalYPos + 'px';
	messageNode.style.left = finalXPos + 'px';	
	messageNode.style.paddingTop = '10px';
	messageNode.innerHTML =  message;
	
	iframeNode.style.top = finalYPos + 'px';
	iframeNode.style.left = finalXPos + 'px';
	iframeNode.style.width = conWidth + 'px';
	iframeNode.style.height = conHeight + 'px';
	iframeNode.style.position = 'absolute';
	iframeNode.style.padding = '5px';
	iframeNode.src = '';
	
	document.body.appendChild(canvasNode);
	
	if (isIE) document.body.appendChild(iframeNode);
	
	document.body.appendChild(messageNode);
}

function closeRefreshMessage(){
	if (document.getElementById('pageCanvasDiv')) {
		var canvasDiv = document.getElementById('pageCanvasDiv');
		document.body.removeChild(canvasDiv);
		}	
	if (document.getElementById('sessionCounterIframe')) {
      var iframeNode = document.getElementById('sessionCounterIframe');
	  	document.body.removeChild(iframeNode);
		}
	if (document.getElementById('messageDiv')) {
      var messageNode = document.getElementById('messageDiv');
	  document.body.removeChild(messageNode);
	}
	
	}