//Based on http://luke.breuer.com/tutorial/javascript-modal-dialog.aspx by Luke Bruer

function Popup(div)
{
    this.modalWindow = div;    
}
    
Popup.prototype.Open = function() 
{
    this.modalWindow.style.display = 'block';
    $get('modalBackground').style.display = 'block';

    // call once to center everything
    this.OnWindowResize();   
}

Popup.prototype.Close = function() 
{
    this.modalWindow.style.display = 'none';
    $get('modalBackground').style.display = 'none';
}

Popup.prototype.OnWindowResize = function() 
{
    // we only need to move the dialog based on scroll position if
    //   we're using a browser that doesn't support position: fixed, like < IE 7
    var left = window.XMLHttpRequest == null ? document.documentElement.scrollLeft : 0;
    var top = window.XMLHttpRequest == null ? document.documentElement.scrollTop : 0;
    
    this.modalWindow.style.left = Math.max((left + (GetWindowWidth() - this.modalWindow.offsetWidth) / 2), 0) + 'px';
    this.modalWindow.style.top = Math.max((top + (GetWindowHeight() - this.modalWindow.offsetHeight) / 2), 0) + 'px';
}

//Utility functions
function GetWindowWidth()
{
	var width =
		document.documentElement && document.documentElement.clientWidth ||
		document.body && document.body.clientWidth ||
		document.body && document.body.parentNode && document.body.parentNode.clientWidth ||
		0;
		
	return width;
}

function GetWindowHeight()
{
    var height =
		document.documentElement && document.documentElement.clientHeight ||
		document.body && document.body.clientHeight ||
  		document.body && document.body.parentNode && document.body.parentNode.clientHeight ||
  		0;
  		
  	return height;
}


