//Begin msgboxFunction.fun

// emulates VB Msgbox
var mbDone = false

function ShowMsgBox(parent, msg, style, sHeight, sWidth, sButton1Text, OnCloseFunc, bForceRealForm) {

	if (oLibPage.bSimulateModal) {
		// Use native alerts and confirms when simulating modals
		var bUseConfirm = false
		var bUseAlert = false
		var buttonStyle = getStyleNoImage(style)
		var retAffirmative
		var retNegative
		switch (buttonStyle){
			case oLibPage.mb_OKCancel:
				bUseConfirm = true
				retAffirmative = oLibPage.mb_OK
				retNegative = oLibPage.mb_Cancel
				break
			case oLibPage.mb_YesNo:
				bUseConfirm = true
				retAffirmative = oLibPage.mb_Yes
				retNegative = oLibPage.mb_No
				break
			case oLibPage.mb_OKOnly:
				bUseAlert = true
				break
		}
		// If not passed in, bForceRealForm should be undefined, and not undefined is true.
		if (!bForceRealForm) {
		    if (bUseAlert) {
			    alert(msg)
			    return true
		    }else if (bUseConfirm) {
			    return confirm(msg) ? retAffirmative : retNegative
		    }
		}
	}

	var oDoc=parent.document
	var oSpan = oDoc.createElement('SPAN')
	oSpan.innerText = msg
	// abw 5/23/05 need to supply the innerHTML for Firefox
	oSpan.innerHTML = msg
	oSpan.style.fontFamily = 'verdanna, tahoma'
	oSpan.style.fontSize = '10pt'
	oSpan.style.visibility = 'hidden'
	oDoc.body.appendChild(oSpan)

	var dialogHeight
	var dialogWidth
	var nSpanWidth = oSpan.offsetWidth
	var hFluff = 0
	var vFluff = 0
	var nMaxMsgLineLen = 400
	var nMinMsgLineLen = 250
	if (nSpanWidth < nMinMsgLineLen) {
		oSpan.style.width=nMinMsgLineLen + 'px'
		nSpanWidth = oSpan.offsetWidth
	}else{

		//limit the width
		//we're good for two lines but if we get to 3 or more need add more height
		//re-get the len after changing the width
		if (nSpanWidth > nMaxMsgLineLen) {
			oSpan.style.width=nMaxMsgLineLen + 'px'
			nSpanWidth = oSpan.offsetWidth
		}
	}
	var nSpanHeight = oSpan.offsetHeight
	hFluff = hFluff + 32 //make room for image 
	hFluff = hFluff + 5 //image rt margin
	hFluff = hFluff + 9 //window frame + ?
	hFluff = hFluff + 25 //body l/r margins

	vFluff = vFluff + 46 //window frame
	vFluff = vFluff + 30 //toolbar
	vFluff = vFluff + 30 //vertical body padding, margins
	vFluff = vFluff + 10 //toolbar top margin

	if (nSpanHeight < 35) {
		nSpanHeight = 35 //at least as tall as the image
	}

	dialogHeight = oLibPage.DialogHeight(nSpanHeight + vFluff)
	dialogWidth = oLibPage.DialogWidth(nSpanWidth + hFluff)

	oDoc.body.removeChild(oSpan)

	if (sHeight) {
		dialogHeight = sHeight
	}

	if (sWidth) {
		dialogWidth = sWidth
	}

	dialogHeight = parseInt(dialogHeight)
	dialogWidth = parseInt(dialogWidth)

	if (oLibPage.bIsMacIE) {
		if (dialogWidth < 201) {dialogWidth = 201}
		if (dialogHeight < 201) {dialogHeight = 201}
	}
	
	var sCaption = "";
	if (ShowMsgBox.arguments.length >= 6) {
		sCaption = ShowMsgBox.arguments[5];
	}

	var oArgs = new Object();
	oArgs.libPage = oLibPage;
	oArgs.message = escape(msg);
	oArgs.msgBoxStyle = style;
	oArgs.macYesCaption = sCaption;
	oArgs.OnCloseFunc = OnCloseFunc;
	parent.myModalArguments = oArgs;

	
	var sURL = "/bbwebclient/scripts/helpers/messagebox.htm";
	if (oLibPage.bIsMacIE){
		var sURL = "/bbwebclient/scripts/helpers/messageboxmac.htm";
	}
	var sFeatures = oLibPage.BuildModalFeaturesString(self, dialogHeight, dialogWidth)


	//obj = window.showModalDialog(sURL,parent,sFeatures)
	
	if (!oLibPage.bSimulateModal) {
		obj = _ShowModalDialog(sURL,parent,sFeatures)
    } else {
		// determine which window should 'host' this dialog
		var oWhichWin 
		if (moModals.length > 0) {
			oWhichWin = moModals[moModals.length-1].oModal
		} else {
			oWhichWin=window
		}
		obj = _ShowModalDialog(sURL,parent,sFeatures)
		var obj = new Object()
		obj.returnValue = oLibPage.mb_Cancel
	}
	
	// now continue.
    if (obj != null) { 
        return obj.returnValue
    } 
}

function getStyleNoImage(style){
	var buttonStyle
	if ((style & oLibPage.mb_Exclamation) == oLibPage.mb_Exclamation){
		buttonStyle=style-oLibPage.mb_Exclamation;
	}else{
		if ((style & oLibPage.mb_Critical) == oLibPage.mb_Critical){
			buttonStyle=style-oLibPage.mb_Critical;
		}else{
			if ((style & oLibPage.mb_Question) == oLibPage.mb_Question){
				buttonStyle=style-oLibPage.mb_Question;
			}else{
				if ((style & oLibPage.mb_Information) == oLibPage.mb_Information){
					buttonStyle=style-oLibPage.mb_Information;
				}
			}
		}
	}
	
	return buttonStyle;
	
}


//End msgboxFunction.fun


