/**
 * $Id: Ext.ux.neteor.Messages.js 4114 2010-01-20 17:06:20Z vincent $
 **/

/**
 * Functions used for display Message boxes
 */

function winConfirm(message, callbackFunction, additionalParams, callbackNoFunction) {
	// build callback function to call if answer is "yes"
	callback = function (btn, text) {
		if (btn == 'yes') {
			if (additionalParams != undefined) {
				callbackFunction(additionalParams);
			} else {
				callbackFunction();
			}
		} else if (btn == 'no' && callbackNoFunction != undefined) {
			callbackNoFunction();
		}
	}
	Ext.MessageBox.confirm('', message, callback);
}

function winWait(message, progressMessage) {
	Ext.MessageBox.wait(message, '', {text: progressMessage, interval:100});
}

function winCancel(titleText, messageText, callbackfunction) {
	Ext.MessageBox.show({
		title: titleText,
		msg: messageText,
		buttons: Ext.MessageBox.YESNOCANCEL,
		fn: callbackfunction,
		icon: Ext.MessageBox.QUESTION
	});
}

/**
 * Display an ajax message box
 * @param	string	type	Type of the message box, included in ERROR, MESSAGE, WARNING
 * @param	string	title	Title of the box
 * @param	string	message	Message displayed in the box
 */
function winMessage(type, title, message, callback) {
	var settings;
	switch (type) {
		case 'MESSAGE':
			settings = {
				title: title,
				msg: message
			};
			break;

		case 'ERROR':
			settings = {
				title: title,
				msg: message,
				buttons: Ext.MessageBox.OK,
				icon: Ext.MessageBox.ERROR
			};
			break;
		case 'WARNING':
			settings = {
				title: title,
				msg: message,
				buttons: Ext.MessageBox.OK,
				icon: Ext.MessageBox.WARNING
			};
			break;
		case 'YESNO':
			settings = {
				title: title,
				msg: message,
				buttons: Ext.MessageBox.YESNO,
				fn: callback,
				icon: Ext.MessageBox.QUESTION
			};
			break;
		case 'YESNOCANCEL':
			settings = {
				title: title,
				msg: message,
				buttons: Ext.MessageBox.YESNOCANCEL,
				fn: callback,
				icon: Ext.MessageBox.QUESTION
			};
			break;
		default:
			settings = {
				title: title,
				msg: message,
				buttons: Ext.MessageBox.OK,
				icon: Ext.MessageBox.INFO
			};
			
	}
	Ext.MessageBox.show(settings);
}
