/* Context Box.js v 1.0 
 * @author : bluesky
 * last update: 2009.03.05 
 * (c) 2009 ncsoft Web Development Team */
try {
	if (typeof(Prototype) == "undefined") alert("[ERROR] Prototype library required.");
	if (typeof(AionScriptUtil) != "undefined") alert("[ERROR] ScriptUtil.js is already included.");
} catch(e) {}

var AjaxUtilAction = {};
AjaxUtilAction.msgLoadingPage	= "loading now...\nPlease refresh the webpage if the loading is slow.";
AjaxUtilAction.msgLoadingDiv		= "<div style='text-align:center;' onclick=\"alert('loading now...\\nPlease refresh the webpage if the loading is slow.');return false;\">loading...</div>";
AjaxUtilAction.msgLoadingDivKor		= "<div style='text-align:center;' onclick=\"alert('ローディング中です');return false;\">>ローディング中</div>";

var AjaxUtil = Class.create({
	initialize : function(parameters) {
	},
	callAjaxReturnByMethod : function(action, parameters, returnMethod) {
			new Ajax.Request(action, {
				method : "post",
				asynchronous : false,
				encoding : "UTF-8",
				parameters : parameters,
				onSuccess : function(request) {
					returnMethod(request.responseText, parameters);
				},
				onFailure: function(request) {
					callAjaxFailure(request.status);
				}
			}
		);
	},
	callAjaxReturnByLayerName : function(action, parameters, layerName) {
		AionScriptUtil.displayResponseTextInDiv(AjaxUtilAction.msgLoadingDiv, layerName);
		new Ajax.Request(action, {
				method : "post",
				asynchronous : false,
				encoding : "UTF-8",
				parameters : parameters,
				onSuccess : function(request) {
					AionScriptUtil.displayResponseTextInDiv(request.responseText, layerName);
				},
				onFailure: function(request) {
					callAjaxFailure(request.status);
				}
			}
		);
	}
});
/*
 * ajax failure function 
 */
function callAjaxFailure(status) {
	if (status == 401) GNBLogin();
	else if (status == 403) location.href = "${cl_attribute.ncweb_forbidden}";
	else alert("[ERROR callAjaxFailure]");
}

var AionScriptUtil = new Object();

/*
 * Display Util
 */
Object.extend(AionScriptUtil, (function() {
	function _setDivDisplay(divName, content) {
		if (_checkDiv(divName)) {
			$(divName).innerHTML	= content;
			$(divName).show();
		}
	}
	function _checkDiv(divName) {
		if (typeof $(divName) == "undefined" || $(divName) == null) {
			alert("[ERROR displayResponseTextInDiv] " + divName + " div not found.");
			return false;
		}
		return true;
	}
	return {
		displayResponseTextInDiv : function(request, divName) {
			if (Object.isArray(divName)) for(var i = 0; i < divName.length; i++) _setDivDisplay(divName[i], request);
			else 	_setDivDisplay(divName, request);
		}
	};
})());

/*
 * Cookie Util
 * cookieInfo  = {name, value, expireDate, isDomainCookie}
 */
Object.extend(AionScriptUtil, (function() {
	return {
		getCookie : function (cookieInfo) {
			var first;
			var str = cookieInfo.name + "=";
			if (document.cookie.length > 0) {
				find = document.cookie.indexOf(str);
				if (find == -1) return null;
				first = find + str.length;
				end = document.cookie.indexOf(";", first);
				if (end == -1) end = document.cookie.length;
				return unescape(document.cookie.substring(first, end));
			}
			return null;
		},
		setCookie : function(cookieInfo) {
			document.cookie = cookieInfo.name + "=" + escape(cookieInfo.value) + ((cookieInfo.expireDate == null) ? "" : (";expires=" + cookieInfo.expireDate.toGMTString())) + ((cookieInfo.isDomainCookie | false) ? ";domain=plaync.jp" : "") + "; path=/";
		},
		removeCookie : function(cookieInfo) {
			document.cookie = cookieInfo.name + "=" + ";expires=" + new Date().setTime(new Date().getTime()-1).toGMTString() + "; path=/";
		},
		getCookieExpireDate : function(minute) {
			return minute == null ? null : new Date(new Date().getTime() + minute * 60 * 1000);
		}
	};
})());

if (typeof ajaxUtil == "undefined") var ajaxUtil = new AjaxUtil();