
var eCurDlg = null;

function BCMouseOver()
{
	if (this.className!="ButtonInactive")
		this.className = "ButtonHover";
}
function BCMouseOut()
{
	if (this.className!="ButtonInactive")
		this.className = "Button";
}
function SetupButton(eB)
{
	eB.className = "Button";
	eB.onmouseover = BCMouseOver;
	eB.onmouseout = BCMouseOut;
}

function SetupButtons()
{
	var arrBC = document.getElementsByName("ButtonC");
	var nStop = arrBC.length;
	for (var i=0; i<nStop; i++)
		SetupButton(arrBC[i]);
}

function MakeCaptionBanner(sCaption)
{
	var eImg, eTR, eTD, eTBody, eTable;
	
	eTR = document.createElement("TR");

	eImg = document.createElement("IMG");
	eImg.src = "/Maps/images/BanLeft.gif";
	eTD = document.createElement("TD");
	eTD.className = "BanLeft";
	eTD.appendChild(eImg);
	eTR.appendChild(eTD);

	eTD = document.createElement("TD");
	eTD.className = "BanMiddle";
	eTD.appendChild(document.createTextNode(sCaption));
	eTR.appendChild(eTD);

	eImg = document.createElement("IMG");
	eImg.src = "/Maps/images/BanRight.gif";
    eTD = document.createElement("TD");
	eTD.className = "BanRight";
	eTD.appendChild(eImg);
	eTR.appendChild(eTD);

	eTBody = document.createElement("TBODY");
	eTBody.appendChild(eTR);

    eTable = document.createElement("TABLE");
	eTable.className = "PopBanner";
	eTable.cellSpacing = "0px";
	eTable.cellPadding = "0px";
	eTable.appendChild(eTBody);

	return eTable;
}

function GetElWidth(el)
{
	var sVis = el.style.visibility;
	el.style.visibility = "hidden";
	document.body.appendChild(el);
	var nWidth = el.offsetWidth;
	document.body.removeChild(el);
	el.style.visibility = sVis;
	return nWidth;
}

function StringToDiv(sString)
{
	var eDiv = document.createElement("DIV");
	var eSpan;
	var nWidth, nMaxWidth = 0;
	var aLines = sString.split("\n");
	var nStop = aLines.length;
	for (var i=0; i<nStop; i++)
	{
		eSpan = document.createElement("SPAN");
		eSpan.appendChild(document.createTextNode(aLines[i]));

		nWidth = GetElWidth(eSpan);
		if (nWidth>nMaxWidth)
			nMaxWidth = nWidth;

		if (i)
			eDiv.appendChild(document.createElement("BR"));
		eDiv.appendChild(eSpan)
	}

	eDiv.nWidth = nMaxWidth;
	return eDiv;
}

function MakeDialog(sCaption, eContents, nMaxWidth)
{
	if (top.HideFormPageProblems)
		top.HideFormPageProblems(true);

	var eDiv = document.createElement("DIV");
	eDiv.className = "FormDiv";
	var eBanner = MakeCaptionBanner(sCaption);
	eDiv.appendChild(eBanner);
	eDiv.appendChild(eContents);

	document.body.appendChild(eDiv);

	if (nMaxWidth)
		eDiv.style.width = String(nMaxWidth+16) + "px";

	eDiv.style.visibility = "visible";

	return eDiv;
}

function MakeFormContainer(sCaption, eForm)
{
	var nWidth = 0;
	if (eForm.SavedWidth)
		nWidth = eForm.SavedWidth;
	else
	{
		var eTR, eTB = eForm.eTable.firstChild;
		var nStop = eTB.childNodes.length;
		var i;

		document.body.appendChild(eForm);
		nWidth = eForm.eTable.offsetWidth;
		document.body.removeChild(eForm);

		eForm.SavedWidth = nWidth;

		for (var i=0; i<nStop; i++)
		{
			eTR = eTB.childNodes[i];
			if (eTR.style.display=="none")
				eTR.style.display = "";
		}
	}

	var eDiv = MakeDialog(sCaption, eForm, nWidth);
	if (eForm.eFirstField)
		eForm.eFirstField.focus();

	return eDiv;
}

function RemoveFormContainer(eContainer)
{
	document.body.removeChild(eContainer);

	if (top.HideFormPageProblems)
		top.HideFormPageProblems(false);
}


function DlgClose()
{
	RemoveFormContainer(eCurDlg);
	eCurDlg = null;
}

function AnnounceDlg(sCaption, sString)
{
	if (eCurDlg)
		RemoveFormContainer(eCurDlg);

	var eDiv = StringToDiv(sString);

	var eDivB = document.createElement("DIV");
	eDivB.style.whiteSpace = "nowrap";
	eDivB.style.textAlign = "center";
	var eB = document.createElement("BUTTON");
	SetupButton(eB);
	eB.onclick = DlgClose;
	eB.appendChild(document.createTextNode("OK"));
	eB.style.width = "40px";

	eDivB.appendChild(eB);
	eDiv.appendChild(eDivB);

	eCurDlg = MakeDialog(sCaption, eDiv, eDiv.nWidth);
	eB.focus();
}

function GetXMLReq()
{
	var oReq = null;
	try
	{
		if (window.XMLHttpRequest)
			oReq = new XMLHttpRequest();
		else
		{
			try { oReq = new ActiveXObject("Msxml2.XMLHTTP"); }
			catch(e)
			{
				try { oReq = new ActiveXObject("Microsoft.XMLHTTP"); }
				catch(e){;}
			}
		}
	}
	catch(e)
	{
		alert("Caught exception: " + e.description);
	}

	return oReq;
}


