/**
 * Open a modal window
 * 
 * @param title
 * @param url
 * @param width
 * @param height
 * @param callback
 */
var win = '';
function modalWindow(title,url,width,height,callback) {
	flashGame(1);
	win = new Window({
		className: "alphacube", 
		title: title, 
        width:width,
        height:height,
        url: url,
        resizable: false,
        maximizable: false,
        minimizable: false,
        //destroyOnClose: true,
        showEffectOptions: {duration:1.5},
        onClose: function() {
        	flashGame(2);
        }
	});

	win.showCenter(true);
}

function modalClose() {
	win.destroy();
}

/**
 * Show a modal alert
 * 
 * @param msg
 */
function modalAlert(msg,callback,width) {
	if( msg != '' && msg != undefined && msg != null ) {
		flashGame(1);

		width = (width != undefined && width != null && width != '' ? parseInt(width) : 400);

		Dialog.alert(msg, {
			okLabel: "ok",
			className: "alphacube",
			width: width,
			destroyOnClose: true,
			onClose: function() {
				flashGame(2);

				if(callback != undefined && callback != null && callback != '') eval(callback);
			}
		});
	}
}

/**
 * Show a modal alert
 * 
 * @param msg
 */
function modalSubAlert(msg,callback,width) {
	if( msg != '' && msg != undefined && msg != null ) {
		width = (width != undefined && width != null && width != '' ? parseInt(width) : 400);

		Dialog.alert(msg, {
			okLabel: "ok",
			className: "alphacube",
			width: width,
			destroyOnClose: true,
			onClose: function() {
				if(callback != undefined && callback != null && callback != '') eval(callback);
			}
		});
	}
}

/**
 * Show a modal confirmation
 * 
 * @param url
 * @param data
 * @param target
 * @param msg
 */
function modalConfirm(url,data,target,msg) {
	if( msg != '' && msg != undefined && msg != null ) {
		flashGame(1);
		Dialog.confirm(msg,{
			width:300,
			okLabel: "yes",
			cancelLabel: "no",
			className: "alphacube",
			ok:function(win) {
				ajax(url,data,target);
				return true;
			},
			onClose: function() {
				flashGame(2);
			}
		});
	}
}

/**
 * Show a modal confirmation
 * 
 * @param url
 * @param data
 * @param target
 * @param msg
 */
function modalConfirmRecover(url,msg) {
	if( msg != '' && msg != undefined && msg != null ) {
		Dialog.confirm(msg,{
			width:300,
			okLabel: "alternative way",
			cancelLabel: "try again",
			className: "alphacube",
			ok:function(win) {
				top.win.setURL(url);
				top.win.setSize(500,230);
				return true;
			}
		});
	}
}


/**
 * Show a modal confirmation
 * 
 * @param url
 * @param data
 * @param target
 * @param msg
 */
function modalConfirmRegister(msg) {
	if( msg != '' && msg != undefined && msg != null ) {
		Dialog.confirm(msg,{
			width:400,
			okLabel: "register",
			cancelLabel: "close",
			className: "alphacube",
			ok:function(win) {
				top.modalWindow('','user_register.php',500,350);
				return true;
			}
		});
	}
}
