/*
 * Alert, Confirm Java Script written by gagamel.
 *
 * Copyright (c) 2010 gagamel
 * Dual licensed under GPL (GPL-LICENSE.txt) licenses.
 *
 * $Date: 2019-07-01 $
 */

var gagaAlert = {
	obj : {
		message : '',
		callback : '',
		cancelCallback : ''
	},
	
	show : function(type, message) {
		var liTag = '<ul class="popup modal" data-width="350" style="min-width: 350px;">\n';
		liTag += '		<li class="mdPopContent">' + message + '</li>\n';
		liTag += '		<li class="mdPopBtnB aR">\n';
		liTag += '			<button id="okBtn" type="button" class="btn btn-primary btn-lg" onclick="gagaAlert.ok();">확인</button>\n';
		
		if (type == 'confirm') {
			liTag += '			<button type="button" class="btn btn-dark btn-lg" onclick="gagaAlert.cancel();">취소</button>\n';
		}
		
		liTag += '		</li>\n';
		liTag += '	</ul>\n';

		if ($('#customAlert').length == 0) {
			var tag = '<div class="popupWrap bgTrans" id="customAlert" style="z-index:900;">\n';
			tag += liTag;
			tag += '</div>';
			$('body').append(tag);
		} else {
			$('#customAlert').append(liTag);
		}
		uifnMpopup('customAlert');
		$("#okBtn").attr("tabindex", -1).focus();
	},
	
	alert : function(message,callback) {
		this.obj.callback = null;
		gagaAlert.show('alert', message);
		this.obj.callback = callback;
	},
	
	confirm : function(message, callback, cancelCallback) {
		gagaAlert.show('confirm', message);
		this.obj.callback = callback;
		this.obj.cancelCallback = cancelCallback;
	},
	
	ok : function() {
		uifnPopClose('customAlert');
		if (typeof(this.obj.callback) != undefined && typeof(this.obj.callback) == 'function' && this.obj.callback != null ) {
			this.obj.callback('abc');
		}
	},
	
	cancel : function() {
		uifnPopClose('customAlert');
		if (typeof(this.obj.cancelCallback) != undefined && typeof(this.obj.cancelCallback) == 'function' && this.obj.cancelCallback != null ) {
			this.obj.cancelCallback('abc');
		}
	}
	
}
