/* ---------------------------- */
/*  (c) 2008 NCsoft UIDev Team
/* ---------------------------- */

/* Flash Banner Link */
function lolgamebanner(myurl, mywidth, myheight, isscroll, logid) {if(logid){try{_trk_clickTrace("EVT", logid);}catch(_e){} } if(mywidth == "0" && myheight == "0") {if(isscroll == "0" ) {document.location.href= myurl;} else {window.open(myurl,"_blank");}} else {open_popup(myurl,mywidth,myheight,isscroll,"lolgamebanner" );}}
function evalEx(str) {return (new Function('', 'return ' + str + ';'))();}
function goServer(myurl,mywidth,myheight,isscroll){if(mywidth=="0"&&myheight=="0"){if(isscroll=="0"){document.location.href=myurl;}else{window.open(myurl,"_blank");}}else{open_popup(myurl,mywidth,myheight,isscroll,"goServer");}}
function goClass(myurl,mywidth,myheight,isscroll){if(mywidth=="0"&&myheight=="0"){if(isscroll=="0"){document.location.href=myurl;}else{window.open(myurl,"_blank");}}else{open_popup(myurl,mywidth,myheight,isscroll,"goClass");}}
function l2MoviePlayer(movieCode, playerWidth, playerHeight){
	if(isNaN(Number(playerWidth)) || isNaN(Number(playerHeight)) || playerWidth<320 || playerHeight<240) {playerWidth = 320;playerHeight = 240;}
	var playerSrc='http://static.plaync.co.kr/plaza/pcc/view/viewskin_s.swf?logo_sta=3&movie_id='+movieCode+'&allowfullscreen=true';
	document.write('<div class="movie_player">');
	document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0" width="'+playerWidth+'" height="'+playerHeight+'" id="playncPlayer" align="middle">');
	document.writeln('<param name="allowFullScreen" value="true" />');
	document.writeln('<param name="scale" value="noscale" />');
	document.writeln('<param name="movie" value="'+playerSrc+'" />');
	document.writeln('<param name="allowScriptAccess" value="always" />');
	document.writeln('<param name="menu" value="false" />');
	document.writeln('<param name="quality" value="high" />');
	document.writeln('<param name="bgcolor" value="#FFF" />');
	document.writeln('<param name="wmode" value="transparent" />');
	document.writeln('<embed src="'+playerSrc+'" allowFullScreen="true" allowScriptAccess="always" menu="false" quality="high" bgcolor="#FFF" wmode="transparent" width="'+playerWidth+'" height="'+playerHeight+'" name="playncPlayer" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.writeln('</object>');
	document.write('</div>');
};


// start of common function
if(String.prototype.trim == null)
	String.prototype.trim=function(){return this.replace(/^\s*/,"").replace(/\s*$/,"");}

//ajax login - start of common function
if(String.prototype.trim == null)
	String.prototype.trim=function(){return this.replace(/^\s*/,"").replace(/\s*$/,"");}
var DEFAULT_LOGIN_SVC_COOKIE = "DEF_LOGIN_SVC";
var DEFAULT_LOGIN_SVC_COOKIEDOMAIN = "plaync.co.kr";
var LOGIN_FORM_NAME = "loginFrm1";
function getDefaultLoginService() {
	var str = DEFAULT_LOGIN_SVC_COOKIE + "=";
	if(document.cookie.length > 0) {
		var find = document.cookie.indexOf(str);
		if(find == -1) return null;
		var first = find + str.length;
		var end = document.cookie.indexOf(";", first);
		if(end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring(first, end));
	}
}
function setDefaultLoginService(value) {
	var expDate = new Date();
	expDate.setTime(expDate.getTime() + (365*24*60*60*1000));
	document.cookie = DEFAULT_LOGIN_SVC_COOKIE + "=" + escape(value) + ";expires=" + expDate.toGMTString() + "; path=/;domain="+DEFAULT_LOGIN_SVC_COOKIEDOMAIN;
}
function delDefaultLoginService() {
	var exp = new Date();
	exp.setTime(exp.getTime()-1);
	document.cookie = DEFAULT_LOGIN_SVC_COOKIE + "=" + ";expires=" + exp.toGMTString() + "; path=/;domain="+DEFAULT_LOGIN_SVC_COOKIEDOMAIN;
}
function checkLeftLoginCondition() {
	var frm = document.getElementById(LOGIN_FORM_NAME);
	var inputID = frm.id.value.trim();
	var inputPWD = frm.pwd.value;
	var gameID = frm.game_id.value;
	 if(inputID == "") {
		alert("아이디 또는 이메일을 입력해 주세요.");
		frm.id.focus();
		return false;
	}
	else if(frm.pwd.value == "") {
		alert("비밀번호를 입력해 주세요.");
		frm.pwd.focus();
		return false;
	}
	return true;
}

var classNaming = "user_id";
function setMaxLengthForIdPwd() {
	var frm = document.getElementById(LOGIN_FORM_NAME);
	var gameId = frm.game_id.value;
	var id = frm.id;
	var pwd = frm.pwd;
	switch(gameId) {
	case "13" :// plaync
		id.maxLength = 64;
		pwd.maxLength = 16;
		classNaming = "user_id";
		if(!id.value) frm.id.className = classNaming;
		break;
	case "31" :// Lineage1
		if (id.value.length > 12) id.value = id.value.substring(0, 12);
		id.maxLength = 12;
		pwd.maxLength = 16;
		break;
	case "32" :// Lineage2
		id.maxLength = 14;
		pwd.maxLength = 16;
		classNaming = "user_id_game";
		if(!id.value) frm.id.className = classNaming;
		break;
	}
}
//ajax login - end of common function


//login_area : memo : exposer체험계정 가입일 가져옴 - 20090313 로그인존 변경 작업시 추가 된 부분
function getCreateDate(){
var url = "/common/inc/userexpinfo/getcreatedate";
	new Ajax.Request(url, {
	asynchronous : false,
	method: 'post',
	encoding: 'UTF-8',
	onSuccess: function(request)
	{
		viewCreateDate(request, 'expdate');
	},onFail: function (transport) {
		$(divName).innerHTML = "오류발생";
	}
});
}

function viewCharacterArticle(worldID, charID, charName, userEmoticon, serviceId) {
	if (typeof serviceId == "undefined" || serviceId == "undefined" || serviceId == 13)
		serviceId = 32;

	if (charID != "" && charName != "") location.href = encodeURI("/board/user/user_list?worldID=" + worldID + "&charID=" + charID + "&charName=" + charName + "&userEmoticon=" + userEmoticon);
	else alert('다른글 정보가 없습니다. ');
}

// 로거 등록(Ajax 및 Layer 용)
var Logger = {};

Logger.update = function(logger_area, request_url) {
	try {
		new Ajax.Updater(logger_area, request_url, {
				method:'get',
				encoding: 'UTF-8',
				evalScripts: true
			}
		);
	}catch(e) { }
}


/* game start */
function loadLauncherActiveX() {
	var html ='<object ID="NCWebLauncher" style="left: 0px; top: 0px" codeBase="http://static.plaync.co.kr/plugin/gamelauncher/ncweb.cab#version=1,0,0,2" height="0" width="0" classid="CLSID:7C6E92FA-4429-4FB6-909B-798E2EFFAEF0" VIEWASTEXT></object>';
	var div = document.createElement("DIV");
	div.name = div.id = "divLauncherObject";
	document.body.appendChild(div);
	div.innerHTML = html;
}
function gameStart() {
	try {if(document.readyState != "complete") return;}catch(e){}
	GetClickCountRate('gameLauncherCount.xml');
	launch(4);
}
function GetClickCountRate(fileName) {
	try {
		var xmlhttp = null;

		try{xmlhttp=new XMLHttpRequest();}
		catch(e) {
			try {xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');}
			catch(e){
				try{xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');}
				catch(e){}
			}
		}
		if(xmlhttp != null) {
			var strURL	= "/statistics/" + fileName;
			xmlhttp.Open("POST", strURL, false);
			xmlhttp.setRequestHeader("Content-type:", "application/x-www-form-urlencoded");
			xmlhttp.send(null);
		}
	}
	catch(e) {}
}

//show Flash, Media Object setting
var paramInfo = new Array;
function initParam()
{
	var oldSize = paramInfo.length;
	for (var i=0; i<oldSize; i++) {
		paramInfo.length--;
	}
}
function setParam(paramName, paramValue)
{
	var idx = paramInfo.length;
	paramInfo[idx] = [];
	paramInfo[idx][0] = paramName;
	paramInfo[idx][1]= paramValue;
}

function goCharacterHome(serverId, charStrId){
	if (charStrId == '') {
		charStrId = '00000';
	}
	document.location.href = "/mypage/character/"+charStrId+"/charInfo?serverId="+serverId;
}
function goCharacterHomeBoard(serverId, charStrId){
	if (charStrId == '') {
		charStrId = '00000';
	}
	document.location.href = "/mypage/character/"+charStrId+"/charInfo?serverId="+serverId + "&tab=board";
}


function commonAjaxError(jsonResult) {
	if (jsonResult.error != null && jsonResult.error == "redirect" && jsonResult.redirect.indexOf("login/loginform")!= -1) {
		if (confirm("로그인 후 이용 가능합니다.\n로그인하시겠습니까?")) {
			GNBLogin();
		}
		return false;
	} else if (jsonResult.error != null && jsonResult.error == "redirect") {
		location.href = jsonResult.redirect;
		return false;
	} else if (jsonResult.error != null && jsonResult.error == "alert"){
		alert(jsonResult.message);
		return false;
	}
	return true;
}

function goBoardServer(serverId) {
	location.href="/board/serverchannel?serverId=" + serverId;
}

function goBoardClass(classId) {
	location.href="/board/classchannel?classId=" + classId;
}

