﻿//<![CDATA[

function createModal() {

	$('modalWindow').style.display = $('modalBackground').style.display = 'block';

	// special < IE7 -only processing for windowed elements, like select	
//	if (window.XMLHttpRequest == null)
//	{
//		var type = $('hideType').value;
//		
//		if (type == 'iframe')
//			$('modalIframe').style.display = 'block';
//	}

	// call once to center everything
	OnWindowInit();
	
	if (window.attachEvent)
		window.attachEvent('onresize', OnWindowResize);
	else if (window.addEventListener)
		window.addEventListener('resize', OnWindowResize, false);
	else
		window.onresize = OnWindowResize;
	
	// we won't bother with using javascript in CSS to take care
	// keeping the window centered
	if (document.all)
		document.documentElement.onscroll = OnWindowResize;

}

function OnWindowInit() {

	// 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;
	var div = $('modalWindow');
	
	div.style.left = Math.max((left + (GetWindowWidth() - div.offsetWidth) / 2), 0) + 'px';
	div.style.top = Math.max((top + (GetWindowHeight() - div.offsetHeight) / 2), 0) + 'px';

}

function OnWindowResize() {

	OnWindowInit();
	
	var div = $('modalWindow');
	div.style.marginLeft = 0;
	div.style.marginTop = 0;
}

function OnModalWindowClick() {

	$('modalWindow').style.display = $('modalBackground').style.display = 'none';

	// special IE-only processing for windowed elements, like select	
//	if (document.all)
//	{
//		var type = $('hideType').value;
//		
//		if (type == 'iframe')
//			$('modalIframe').style.display = 'none';
//	}
	
	if (window.detachEvent)
		window.detachEvent('onresize', OnWindowResize);
	else if (window.removeEventListener)
		window.removeEventListener('resize', OnWindowResize, false);
	else
		window.onresize = null;
		
}

function $(id) {
	return document.getElementById(id);
}

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;
}

//]]>