/* 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.msgLoadingDivByImg		= "<div id=\"data_loading\" onclick=\"alert('loading now...\\nPlease refresh the webpage if the loading is slow.');return false;\"><div class='loading_cnt'><img src='http://static.plaync.co.kr/aion/common/loading.gif' alt='' /></div></div>";
AjaxUtilAction.msgLoadingDivByText	= "<div onclick=\"alert('Chargement en cours.\\nSi l`operation prend trop de temps, essayez de rafraichir votre navigateur.');return false;\" style=\"align:center\">Loading</div>";

var AjaxUtil = Class.create({
	initialize : function(parameters) {
	},
	callAjaxReturnByMethod : function(action, parameters, returnMethod) {
			new Ajax.Request(action, {
				method : "post"
				, asynchronous : true
				, 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.msgLoadingDivByImg, layerName);
		new Ajax.Request(action, {
				method : "post"
				, asynchronous : true
				, 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 = "http://info.plaync.co.kr/util/service_info";
	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 {
		displayLoadingInDiv : function() {
			var obj = document.createElement("div");
			
			var obj = $(AjaxUtilAction.msgLoadingDiv);
			obj.innerHTML	= content;
			var _x = document.body.clientWidth/2 - parseInt(31)/2;
			var _y = 200;
			obj.style.left =  _x + "px";
			obj.style.top = _y + "px";
			obj.show();
		}
		, 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.co.kr" : "") + "; 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();
