
function getBrowserSize()
{
	var bodyWidth = document.documentElement.clientWidth;
	var bodyHeight = document.documentElement.clientHeight;

	var bodyWidth, bodyHeight;
	if(self.innerHeight)
	{
		bodyWidth = self.innerWidth;
		bodyHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		bodyWidth = document.documentElement.clientWidth;
		bodyHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		bodyWidth = document.body.clientWidth;
		bodyHeight = document.body.clientHeight;
	}
	return [bodyWidth,bodyHeight];
}
	

function createTransparentDiv()
{

	var brSize = getBrowserSize();
	var bodyWidth = brSize[0];
	var bodyHeight = brSize[1];

	this.transparentDiv = document.createElement('DIV');
	this.transparentDiv.className='transparentDiv';
	this.transparentDiv.style.top='0px';
	this.transparentDiv.style.left='0px';
	this.transparentDiv.style.width=bodyWidth + 'px';
	this.transparentDiv.style.height=bodyHeight + 'px';
	document.body.appendChild(this.transparentDiv);
	// window.refToModMessage = this;
	if (window.addEventListener)
	{
		window.addEventListener("scroll",repositionDivs,false);
		window.addEventListener("resize",repositionDivs,false);
	} else if (window.attachEvent) {
		window.attachEvent("onscroll",repositionDivs);
		window.attachEvent("onresize",repositionDivs);
	}
	// window.addEvent('resize',function(){alert('scrolled')});
	// window.addEvent('resize',function() { repositionTransparentDiv() });
}

function repositionDivs()
{
	var topOffset = Math.max(document.body.scrollTop,document.documentElement.scrollTop);

	this.transparentDiv.style.top = Math.max(document.body.scrollTop,document.documentElement.scrollTop) + 'px';
	this.transparentDiv.style.left = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft) + 'px';
	var brSize = getBrowserSize();
	var bodyWidth = brSize[0];
	var bodyHeight = brSize[1];
	this.transparentDiv.style.width = bodyWidth + 'px';
	this.transparentDiv.style.height = bodyHeight + 'px';		

	var tmpWidth = this.modalDiv.offsetWidth;
  var tmpHeight = this.modalDiv.offsetHeight;
  this.modalDiv.style.left = Math.ceil((bodyWidth - tmpWidth) / 2) + 'px';;
  this.modalDiv.style.top = (Math.ceil((bodyHeight - tmpHeight) / 2) +  topOffset) + 'px';
}

function createModalDiv(s,w,h)
{
	this.modalDiv = document.createElement('DIV');
	this.modalDiv.className='modalDiv';
	this.modalDiv.style.width=w + 'px';
	this.modalDiv.style.height=h + 'px';
	this.modalDiv.innerHTML = s;
	document.body.appendChild(this.modalDiv);
}

function displayModal(s,w,h)
{
	if(!this.transparentDiv)
	{
		createTransparentDiv();
	}

	if(!this.modalDiv)
	{
		createModalDiv(s,w,h);
	}

	this.transparentDiv.style.display='block';
	this.modalDiv.style.display='block';

	this.repositionDivs();
	setTimeout('this.repositionDivs()',150);
}

function closeModal()
{
	this.transparentDiv.style.display='none';
	this.modalDiv.style.display='none';
}
