﻿////////////////////////////////////////////////////////////////////////////////////////////////////
//
//	Modal.js
//
//	Author: Ben Allred
//
//	Version 1
//
//	Provides convenient functions for dealing with modals.
//
////////////////////////////////////////////////////////////////////////////////////////////////////

var ModalMaskId;
var VisibleModalCount = 0;

// iOpacity		Number between 0 and 1
/*function CreateModalMask(sBackgroundColor, iOpacity, iZIndex)
{
	document.write('<div id="' + ModalMaskId + '" style="position:fixed; left:0px; top:0px; width:100%; height:100%; z-index:' + iZIndex + '; background-color:' + sBackgroundColor + '; opacity:' + iOpacity + '; filter:alpha(opacity=' + (iOpacity * 100) + '); display:none;"></div>');
}*/

function CreateModalMask(sModalMaskId)
{
	ModalMaskId = sModalMaskId;
	document.write('<div id="' + ModalMaskId + '" style="position:fixed; left:0px; top:0px; width:100%; height:100%; display:none;"></div>');
}

function ShowModal(sModalId, iWidth, iHeight)
{
	document.getElementById(ModalMaskId).style.display = 'block';
	
	var modal = document.getElementById(sModalId);
	modal.style.left = '50%';
	modal.style.top = '50%';
	modal.style.width = iWidth + 'px';
//	modal.style.height = iHeight + 'px';
	modal.style.margin = '-' + (iHeight / 2) + 'px 0px 0px -' + (iWidth / 2) + 'px';
	if (modal.style.display != 'block')
	{
		modal.style.display = 'block';
		VisibleModalCount++;
	}
}

function HideModal(sModalId)
{
	var modal = document.getElementById(sModalId);
	if (modal.style.display != 'none')
	{
		modal.style.display = 'none';
		VisibleModalCount--;
	}
	if (VisibleModalCount <= 0)
	{
		document.getElementById(ModalMaskId).style.display = 'none';
	}
}