//<script language="javascript">  //This tag is to fake Interdev into recognizing this file as a javascript file 
// Copyright (c) 2000-2002 Onyx Software Corporation All rights reserved.

// Button Configuration Constants (piButtons parameter)
var mbBUTTONS_OK = 0;
var mbBUTTONS_OKCANCEL = 1;
var mbBUTTONS_ABORTRETRYCANCEL = 2;
var mbBUTTONS_YESNOCANCEL = 3;
var mbBUTTONS_YESNO = 4;
var mbBUTTONS_RETRYCANCEL = 5;

// Default button constants (add to piButtons parameter) - provides focus to button
var mbBUTTONS_DEFAULT_1 = 100
var mbBUTTONS_DEFAULT_2 = 200
var mbBUTTONS_DEFAULT_3 = 300

// Icon type constants (piIcon parameter)
var mbICON_CRITICAL = 1
var mbICON_QUESTION = 2
var mbICON_EXCLAMATION = 3
var mbICON_INFO = 4


function jsGetDefaultButton(piButtons) {
	var iRem;
	
	// override default button if user specified
	if (piButtons > 100) {
		iRem = piButtons - 100;
		if (iRem < 100) {
			return 1;
		}
		iRem = piButtons - 200;
		if (iRem < 100) {
			return 2;
		}
		iRem = piButtons - 300;
		if (iRem < 100) {
			return 3;
		}
	}
	return 0;
}

/*COMMENT-----------------------------------------------------------------------------
FUNCTION:		jsMessageBox
DESCRIPTION	Displays a modal IE window with the passed message
	
PARAMETERS
	psPrompt						The main body of the message to be displayed
	piButtons						A long defining what buttons to display		
	piIcon							A long defining the icon to display
	psTitle							The title of the message box window
RETURN VALUES
	A long indicating which button was selected by the user
CALLED PROCEDURES
	NONE
-----------------------------------------------------------------------------COMMENT*/	
function jsMessageBox(psPrompt, piButtons, piIcon, psTitle)
{
	//These do not need to use sPathtoRoot as we know that alert.htm is in the Root
	var mbINFORMATION = "images/mbinformation.gif";
	var mbCRITICAL    =  "images/mbcritical.gif";
	var mbEXCLAMATION =  "images/mbexclamation.gif";
	var mbQUESTION    = "images/mbquestion.gif";
	
	var iResult = 0;
	var sPromptIcon = "";
	var sTempPrompt
	var iDefaultButton
	var iUserDefaultButton;
	
	var aParamsArray;
	var oArgs = new Object();

	var sHREF = window.location.href;
	var aHREF = sHREF.split("/");
	var sProtocol = window.location.protocol;
	var sURL = gsPathtoRoot + "alert.htm";
	var e
	
	// allow a single argument to be passed (used if we are replacing alert() with jsMessageBox)
	if (arguments.length == 1 ) {
		piButtons = 0; // 'OK'
		piIcon = 4; // 'Informational'
		psTitle = '';
	}
	
	
	if (piIcon == 1) { sPromptIcon = mbCRITICAL; }
	if (piIcon == 2) { sPromptIcon = mbQUESTION; }
	if (piIcon == 3) { sPromptIcon = mbEXCLAMATION; }
	if (piIcon == 4) { sPromptIcon = mbINFORMATION; }

	iUserDefaultButton = jsGetDefaultButton(piButtons);
	piButtons -= (100 * iUserDefaultButton);
		
	switch (piButtons) {
		case 0:
			aParamsArray = new Array(res_aAlert[0]);
			iDefaultButton = 1;
			//OK
			break;
		case 1:
			aParamsArray = new Array(res_aAlert[0],res_aAlert[1]);
			iDefaultButton = 2;
			//OK, Cancel
			break;
		case 2:
			aParamsArray = new Array(res_aAlert[2],res_aAlert[3],res_aAlert[1]);
			iDefaultButton = 2;
			//Abort, Retry, Cancel
			break;
		case 3:
			aParamsArray = new Array(res_aAlert[4],res_aAlert[5],res_aAlert[1]);
			iDefaultButton = 3;
			//Yes, //No, //Cancel
			break;
		case 4:
			aParamsArray = new Array(res_aAlert[4],res_aAlert[5]);
			iDefaultButton = 2;
			//Yes, No
			break;
		case 5:
			aParamsArray = new Array(res_aAlert[3],res_aAlert[1]);
			iDefaultButton = 1;
			break;
	}

	if (iUserDefaultButton != 0) {
		// override default with user set default
		iDefaultButton = iUserDefaultButton;
	}
	
	oArgs.title = psTitle;
	// replace all cariage return line feeds with <BR>
	sTempPrompt = psPrompt.replace(/\r\n/g, "<BR>");
	
	oArgs.prompt = sTempPrompt;
	oArgs.icon = sPromptIcon;
	oArgs.buttons = aParamsArray;
	oArgs.defaultButton = iDefaultButton.toString();
	
	// Try and give focus to the window that called the alert, so if it is behind other 
	// windows it comes to the front.
	try{
		window.focus();
	}catch(e){
		// Throw away any errors
	}

	try {jsTimerPauseAll() } catch (e) {}	
	iResult = window.showModalDialog(sURL, oArgs, "dialogWidth:450px;dialogHeight:220px;Help:no;Status=no;Scroll=no");
	try {jsTimerUnPauseAll() } catch (e) {}
	if (iResult == 0) { return 0; }
	
	switch (piButtons) {
		case 0:
			iResult = 1;
			break;
		case 1:
			if (iResult == 1) { iResult = 1; }
			if (iResult == 2) { iResult = 0; }
			break;
		case 2:
			if (iResult == 1) { iResult = 2; }
			if (iResult == 2) { iResult = 1; }
			if (iResult == 3) { iResult = 0; }
			break;
		case 3:
			if (iResult == 1) { iResult = 1; }
			if (iResult == 2) { iResult = 2; }
			if (iResult == 3) { iResult = 0; }
			break;
		case 4:
			if (iResult == 1) { iResult = 1; }
			if (iResult == 2) { iResult = 0; }
			break;
		case 5:
			if (iResult == 1) { iResult = 1; }
			if (iResult == 2) { iResult = 0; }
			break;
	}
	return iResult;	
}


