var popUpDiv = null;
var messengerTimeoutHide = 3000;

function messengerObject(text){
	closePopUpDiv();
	
	var bg = document.getElementById('mBg');
	bg.style.display = 'block';
	//bg.style.width = document.body.offsetWidth;
	//bg.style.height = document.body.offsetHeight;
	//alert(innerHeight);
	bg.style.height = document.body.scrollHeight;
	bg.style.width = document.body.scrollWidth;
	
	//bodyW = document.body.scrollWidth;
	//bodyH = document.body.scrollHeight;
	try{
		bodyW = innerWidth;
		bodyH = innerHeight;
	}
	catch(e){
		bodyW = document.body.offsetWidth;
		bodyH = document.body.offsetHeight;
	}
	
	//alert(bodyW + '  ' + bodyH);
	popUpDiv = document.createElement('div');
	var code = '<table height="100%" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td class="messageDivHeader">Message</td></tr><tr><td id="contentPopupDiv" class="contentPopupDiv" valign="top">' + text + '</td></tr><tr><td align="center" height="1" width="1" style="text-align:center !important;width:100%;"><input type="button" value="Close" onclick="closePopUpDiv()"></td></tr></table>';
	popUpDiv.innerHTML = code;
	popUpDiv.style.left = document.body.scrollLeft + (bodyW/2-200);
	popUpDiv.style.top = document.body.scrollTop + (bodyH/2);
	//alert(document.body.scrollHeight);
	//alert(document.body.offsetHeight + '  ' + document.body.scrollTop);
	popUpDiv.className = 'messengerDiv';
	document.body.appendChild(popUpDiv);
	attachEvent(document.body, 'scroll', moveMessengerWnd);
	window.onscroll = moveMessengerWnd;
	popUpDiv.style.marginTop = '0px';
	setTimeout('showSelects(false)', 300);
	//setTimeout('hideMessageDiv()', 2000);
	//setTimeout('closePopUpDiv()', messengerTimeoutHide);
}

function hideMessageDiv(){
	return;
	if(!popUpDiv){
		return;
	}
	//popUpDiv.style.marginTop = 
	var m = parseInt(popUpDiv.style.marginTop);
	if(m + popUpDiv.offsetHeight < 0){
		return closePopUpDiv();	
	}
	//alert(m);
	popUpDiv.style.marginTop = (m - 1) + 'px';
	setTimeout('hideMessageDiv()', 10);
}

function moveMessengerWnd(){
	if(!popUpDiv){
		return;
	}
	popUpDiv.style.left = document.body.scrollLeft + (bodyW/2-200);
	popUpDiv.style.top = document.body.scrollTop + (bodyH/2);
}

function closePopUpDiv(){
	var bg = document.getElementById('mBg');
	bg.style.display = 'none';
	try{
		popUpDiv.parentNode.removeChild(popUpDiv);
		popUpDiv = null;
	}catch(e){}
	//showSelects(true);
}
