/* ---------------------------- */
/*  (c) 2009 NCsoft UIDev Team
/* ---------------------------- */
function bookmarksite (title, url) {if (window.sidebar) window.sidebar.addPanel(title, url, ""); else if (window.opera && window.print) { var elem = document.createElement('a');elem.setAttribute('href', url);elem.setAttribute('title', title);elem.setAttribute('rel', 'sidebar');elem.click();} else if (document.all) window.external.AddFavorite(url, title);}
function startPage(Obj,urlStr) {if (document.all && window.external){ Obj.style.behavior='url(#default#homepage)'; Obj.setHomePage(urlStr);} else {alert('리니지를 시작페이지로 버튼을 드래그 하여 브라우저 상단의 홈아이콘 위에 올려주세요.');}}
function setPng24(obj) {obj.width=obj.height=1; obj.className=obj.className.replace(/\bpng24\b/i,''); obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"; obj.src=''; return '';}

// layer show&hide
function overLayer(layerArea, tag, layerId) {
var tags = document.getElementById(layerArea).getElementsByTagName(tag);
for (i=0;i<tags.length;i++) {
tags[i].name = layerId + (i+1);
tags[i].onmouseover = showData;
tags[i].onmouseout = hideData;
}
}
function showData(layerId){
var layer = (layerId != null && layerId.type != "mouseover" && layerId.type != "mouseout") ? layerId : this.name;
document.getElementById(layer).style.display="block";
}
function hideData(layerId){
var layer = (layerId != null && layerId.type != "mouseover" && layerId.type != "mouseout") ? layerId : this.name;
document.getElementById(layer).style.display="none";
}

// layer show&hide2
function overLayer2(layerArea, tag, layerId) {
var tags = document.getElementById(layerArea).getElementsByTagName(tag);
for (i=0;i<tags.length;i++) {
tags[i].name = layerId + (i+1);
tags[i].onmouseover = function() { showLayer(this.name); classOver(this); };
tags[i].onmouseout = function() { hideLayer(this.name); classOut(this); };

document.getElementById(tags[i].name).onmouseover = function() { showLayer(this.id); };
document.getElementById(tags[i].name).onmouseout = function() { hideLayer(this.id); };
}
}

// layer display toggle (display:none을 기본으로 함)
function displayToggle(layerId) {
	var layerState = document.getElementById(layerId).style;
	if(layerState.display=="" || layerState.display=="none") layerState.display = "block";
	else layerState.display = "none";
}

function evalEx(str) {
	return (new Function('', 'return ' + str + ';'))();
}

// LOGIN
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;
}
function doLogin(){
	var frm = document.getElementById(LOGIN_FORM_NAME);

	if(checkLeftLoginCondition()) {
		if(frm.save.checked)
			setDefaultLoginService(frm.game_id.value);
		else
			delDefaultLoginService();

		try {
			loginKey();
		} catch(e) {}
		frm.submit();
	} else
		return false;
}
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=="") id.className = classNaming;
		break;
	case "31" :// Lineage1
		if (id.value.length > 12) {
			id.value = id.value.substring(0, 12);
		}
		pwd.maxLength = 16;
		id.maxLength = 12;
		classNaming = "user_id_game";
		if(id.value=="") id.className = classNaming;
		break;
	case "32" :// Lineage2
		id.maxLength = 14;
		pwd.maxLength = 16;
		classNaming = "user_id_game";
		if(id.value=="") id.className = classNaming;
	}
}


// end of common function
function openAgreement(idx) {
	var agreement_off = document.getElementById("agreement_off");
	var agreement_on = document.getElementById("agreement_on");
	if (idx == 0) {
		agreement_off.style.display = "block";
		agreement_on.style.display = "none";
	} else {
		agreement_off.style.display = "none";
		agreement_on.style.display = "block"
	}
}

function openDenyPopup(url, winW, winH, scroll, winName)
{
	var setup = "width=" + winW + ",height=" + winH + ",toolbar=no,location=no,status=no,menubar=no,top=20,left=20,scrollbars=" + scroll +",resizable=no";
	if (!winName) winName = "";
	var win = window.open(url, winName, setup);
	if (win == null) alert("차단된 팝업창을 허용해 주십시오.");
	else win.focus();
}

/* 로그인 - 플레이엔씨 서비스 */
function showService(num) {
var serviceTabStatus = 0;
var sTab = document.getElementById('tab').getElementsByTagName('li');
var sInfo = document.getElementById('service_info').getElementsByTagName('p');
	for (var i=1; i<=sTab.length; i++) {
		$("show"+i).style.display = "none";
		sTab[i-1].className = '';
	}
	if (serviceTabStatus != num ) {
		$("show"+num).style.display = "block";
		$('tab').className = 'm_tab'+num;
		sTab[num-1].className = 'on';
		serviceTabStatus = num;
	} else {
		$("show"+num).style.display = "none";
		$('tab').className = 'm_tab';
		serviceTabStatus = 0;
	}
}
function shortNcoin (arg){
	if(!arg) return;
	var maxLength=9;
	for (var i=0; i<arg.length;i++)
	{
		var n = $$('.' + arg[i] + ' strong')[0];
		if(!n) continue;
		var nText=n.innerHTML;
		if (nText.length>maxLength){
			n.title = (i === 0) ? nText + '원' : nText + '점';
			nText = nText.substr(0,8)+".."
			n.innerHTML=nText;
		}
	}
}

function getCreateDate() {
	new Ajax.Request('/main/getCreateDate',
	{
		method:'post',
		encoding:'UTF-8',
		onComplete:function(request){
			if(request.responseText != "FAIL") {
				viewCreateDate(request, "create_date");
			}
		}
	}
	);
}

//BOARD - SNOW3 RENEW
// # start View (동영상퍼가기, Html복사, Url복사)
function copy_to_clipboard_for_url() {
	var url = location.href;
	window.clipboardData.setData("text", url);
	alert("복사되었습니다. 편집기에 Ctrl + V로 붙여 넣을 수 있습니다.");
	return;
}

function copy_to_clipboard_for_html(header, footer) {
	var target = $("view_contents");
	var contents = view_contents.innerHTML;

	if (header != null) {
		contents = header + contents;
	}
	if (footer != null) {
		contents = contents + footer;
	}

	window.clipboardData.setData("text", contents);
	alert("복사되었습니다. 편집기에 Ctrl + V로 붙여 넣을 수 있습니다.");
	return;
}

function copy_to_clipboard_for_media(targetString, type, isAll, header, footer) {
	var targetNames = targetString.split(',');
	var html = "";

	for (var i = 0; i < targetNames.length; i++) {
		var target = $(targetNames[i]);
		if (target != null) {
			if (type == "image") {
				var imgTags = _find_element_type_images(target, isAll);
				if (imgTags != "" && !isAll) {
					html += imgTags;
					break;
				} else {
					html += imgTags
				}
			} else if (type == "movie") {
				var movieTags = _find_element_type_movies(target, isAll);
				if (movieTags != "" && !isAll) {
					html += movieTags
					break;
				} else {
					html += movieTags
				}
			} else {
				break;
			}
		}
	}

	if (header != null) {
		html = header + html;
	}
	if (footer != null) {
		html = html + footer;
	}

	window.clipboardData.setData("text", html);
	alert("복사되었습니다. 편집기에 Ctrl + V로 붙여 넣을 수 있습니다.");
	return;
}

function getCreateDate() {
	new Ajax.Request('/main/getCreateDate',
	{
		method:'post',
		encoding:'UTF-8',
		onComplete:function(request){
			if(request.responseText != "FAIL") {
				viewCreateDate(request, "create_date");
			}
		}
	}
	);
}

// 댓글 counter
var TextAreaCounter = Class.create();
TextAreaCounter.prototype = {
	initialize : function(textArea, counterField, maxCount) {
		this.textArea = textArea;
		this.counterField = counterField;
		this.maxCount = maxCount;

		if (this.textArea == null) {
			return;
		}

		// bind event handler to this object
		this.checkCount.bindCheckCount = this.checkCount.bindAsEventListener(this);
		this.showCount.bindShowCount = this.showCount.bindAsEventListener(this);

		// set event handler
		Event.observe(this.textArea, "keyup", this.checkCount.bindCheckCount);
		Event.observe(this.textArea, "keyup", this.showCount.bindShowCount);
	},

	checkCount : function(event) {
		if (this.textArea == null) {
			return;
		}
		if(this.textArea.value.length > this.maxCount) {
			alert(this.maxCount + " 글자를 초과 입력할 수 없습니다.");
			this.textArea.value = this.textArea.value.substr(0, this.maxCount);
			this.showCount();
		}
	},

	showCount : function(event) {
		if (this.textArea == null) {
			return;
		}
		this.counterField.innerHTML = this.textArea.value.length;
	}
}

function playncPlayer(movieCode, playerWidth, playerHeight, autostart){
	if(isNaN(Number(playerWidth)) || isNaN(Number(playerHeight)) || playerWidth<320 || playerHeight<240) {playerWidth = 320;playerHeight = 240;}
	if(autostart!=1) autostart=3;
	else autostart=0;
	var playerSrc='http://static.plaync.co.kr/plaza/pcc/view/viewskin_s.swf?logo_sta='+autostart+'&movie_id='+movieCode+'&allowfullscreen=true';
	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+'" allowScriptAccess="always" menu="false" quality="high" allowfullscreen="true" 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>');
};

function selectServerToggle(){
	var divState = $('div_select_server').style.display;
	if(divState=="none"){
		$('div_select_server').style.display = "block";
		$('btn_select_server').className += " block";
	} else {
		$('div_select_server').style.display = "none";
		$('btn_select_server').className = "btn_select";
	}
}

function setPageing(layerArea, selectTag, crtpg){
	var pages = layerArea.select(selectTag);
	var crrentPage = layerArea.down('.current_page');
	var totalPage = layerArea.down('.total_page');

	if(crtpg==0){
		crrentPage.innerHTML=1;
		crrentPage.name=crtpg=1;
	} else {
		crrentPage.name+=crtpg;
		if(pages.length<crrentPage.name) crrentPage.name=1;
		else if(crrentPage.name<1) crrentPage.name=pages.length;
		crrentPage.innerHTML=crrentPage.name;
	}
	for(i=0; i<pages.length ; i++) pages[i].style.display = "none";
	pages[crrentPage.name-1].style.display = "";
	totalPage.innerHTML = pages.length;
}
function layerPaging(layerArea, selectTag){
	setPageing(layerArea, selectTag, 0);
	layerArea.down('img.before_page').onclick = function(){setPageing(layerArea, selectTag, -1);};
	layerArea.down('img.after_page').onclick = function(){setPageing(layerArea, selectTag, 1);};
}

/* 탭contents */
function tabContents(eventArea, tabArea, contArea){
	var tabs = tabArea.select("dfn");
	var content = $$('#'+eventArea+' '+contArea);
	for(i=0; i<tabs.length ; i++){
		tabs[i].onclick = setTabContents;
		if(tabs[i].className=="on") content[i].style.display = "block";
		else content[i].style.display = "none";
	}

	function setTabContents(){
		for(i=0; i<tabs.length ; i++){
			if(tabs[i]==this) {
				tabs[i].className="on";
				content[i].style.display = "block";
			} else {
				tabs[i].className="";
				content[i].style.display = "none";
			}
		}
	}
}

//091207 로그인존 내관심 아이템
function getMyItemCount(){
	new Ajax.Request('/serverzone/sz/store/getMyItemCount',
	{
		method:'post',
		encoding:'UTF-8',
		onComplete:function(request){
			if(request.responseText != "FAIL") {
				document.getElementById('myitem').innerHTML = eval(request.responseText) +"/20";
			}
		}
	}	);
}

//100503 showFlash
var isFlashInstalled=0;
function flashvalidator() {
	if (isFlashInstalled!==0) return isFlashInstalled;
	var agent=navigator.userAgent.toLowerCase();
	isFlashInstalled = true;
	if (agent.indexOf('msie')!=-1) {
		isFlashInstalled = true;
	} else {
		if (!(typeof !navigator.plugins && typeof navigator.plugins['Shockwave Flash'] == 'object'))
			isFlashInstalled = false;
	}
	return isFlashInstalled;
}
function showFlash() {
if (flashvalidator()===false) {
if (typeof arguments[1]=='object') {
if (arguments[1]['css']!='') {
var css = document.createElement('link');
css.setAttribute('rel', 'stylesheet')
css.setAttribute('type', 'text/css');
css.setAttribute('href', arguments[1]['css']);
document.getElementsByTagName('head')[0].appendChild(css);
}
if (arguments[1]['type'] == 'src') {
document.writeln('<div id=\"'+ arguments[1]['target'] +'\" class="' + arguments[1]['ch1'] + "_" + arguments[1]['ch2'] + '"></div>');
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', arguments[1]['content']);
document.getElementsByTagName('head')[0].appendChild(script);
} else {
document.write(arguments[1]['content']);
}
}
return false;
}
var Options=(arguments.length>0) ? arguments[0] : {};
var Default={
id:'ShockwaveFlash1',
movie:'',
menu:'false',
scale:'noscale',
allowFullScreen:'false',
allowScriptAccess:'always',
width:'0',
height:'0',
quality:'high',
wmode:'transparent',
bgcolor:'',
xml:false
};
for (var attr in Default) {
if (typeof Options[attr]=='undefined')
Options[attr]=Default[attr];
}
if (Options['xml']!==false)
Options['movie']=Options['movie'] + ((Options['movie'].match(/=/)) ? '&' : '?') + 'server=' + Options['xml'] + '&chkMovie=0';
var docProtocol=(location.href.indexOf('https')==0) ? 'https' : 'http';
var SwfMarkUp=[];
SwfMarkUp.push('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+docProtocol+'://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0" width="'+Options['width']+'" height="'+Options['height']+'" id="'+Options['id']+'" align="middle">');
for (var key in Options) {
if (key!='id'&&key!='xml')
SwfMarkUp.push('<param name=\"' + key + '\" value=\"' + Options[key] + '\" />');
}
SwfMarkUp.push('<param name="wmode" value=\"' + Options['wmode'] + '\" />');
SwfMarkUp.push('<param name="allowScriptAccess" value=\"always\" />');
SwfMarkUp.push('<param name="menu" value="false" />');
SwfMarkUp.push('<param name="quality" value="high" />');
SwfMarkUp.push('<embed src="'+Options['movie']+'" allowScriptAccess="always" menu="false" quality="high" bgcolor="'+Options['bgcolor']+'" wmode="'+Options['wmode']+'" width="'+Options['width']+'" height="'+Options['height']+'" name="'+Options['id']+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
SwfMarkUp.push('</object>');
document.write(SwfMarkUp.join(''));
}

//global.js
function showFlashObject(objID,objSource,objWidth,objHeight,objQuality,objWmode,objBgcolor,objXML){
if(objXML){
var chkMovie=0;
if(objSource.match(/=/))objSource=objSource+"&server="+objXML+"&chkMovie="+chkMovie;
else objSource=objSource+"?server="+objXML+"&chkMovie="+chkMovie;
}
var pageUrl=self.window.location.href;
if(pageUrl.substring(0,5)=="https")swfUrl="https";
else swfUrl="http";
if(!objID)objID="ShockwaveFlash1";
if(!objWidth)objWidth="0";
if(!objHeight)objHeight="0";
if(!objQuality)objQuality="high";
if(!objWmode)objWmode="transparent";
document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+swfUrl+'://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0" width="'+objWidth+'" height="'+objHeight+'" id="'+objID+'" align="middle">');
document.writeln('<param name="allowFullScreen" value="false" />');
document.writeln('<param name="scale" value="noscale" />');
document.writeln('<param name="movie" value="'+objSource+'" />');
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="'+objBgcolor+'" />');
document.writeln('<param name="wmode" value="'+objWmode+'" />');
document.writeln('<embed src="'+objSource+'" allowScriptAccess="always" menu="false" quality="high" bgcolor="'+objBgcolor+'" wmode="'+objWmode+'" width="'+objWidth+'" height="'+objHeight+'" name="'+objID+'" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
document.writeln('</object>');
}
function showMediaObject(objSource,objID,objWidth,objHeight,autostart,showcontrols){
if(!objID)objID="MovieClip1";
if(!objWidth)objWidth="400";
if(!objHeight)objHeight="345";
if(!autostart)autostart="0";
if(!showcontrols)showcontrols="0";
if(-1!=navigator.userAgent.indexOf("MSIE")){
document.writeln('<object classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" id="'+objID+'" width="'+objWidth+'" height="'+objHeight+'">');
document.writeln('<param name="AutoSize" value="1">');
document.writeln('<param name="AutoStart" value="'+autostart+'">');
document.writeln('<param name="AutoRewind" value="1">');
document.writeln('<param name="ClickToPlay" value="0">');
document.writeln('<param name="Enabled" value="1">');
document.writeln('<param name="EnableTracker" value="1">');
document.writeln('<param name="EnableContextMenu" value="0">');
document.writeln('<param name="ShowStatusBar" value="0">');
document.writeln('<param name="ShowControls" value="'+showcontrols+'">');
document.writeln('<param name="ShowAudioControls" value="'+showcontrols+'">');
document.writeln('<param name="ShowCaptioning" value="0">');
document.writeln('<param name="Mute" value="0">');
document.writeln('<param name="ShowDisplay" value="0">');
document.writeln('<param name="filename" value="'+objSource+'">');
document.writeln('</object>');
}
else{
document.writeln(' <object id="'+objID+'" type="video/x-ms-wmv" data="'+objSource+'" width="'+objWidth+'" height="'+objHeight+'">');
document.writeln(' <param name="AutoStart" value="'+autostart+'">');
document.writeln(' <param name="AutoRewind" value="1">');
document.writeln(' <param name="Enabled" value="1">');
document.writeln(' <param name="EnableTracker" value="1">');
document.writeln(' <param name="EnableContextMenu" value="0">');
document.writeln(' <param name="ShowStatusBar" value="0">');
document.writeln(' <param name="ShowControls" value="'+showcontrols+'">');
document.writeln(' <param name="ShowAudioControls" value="'+showcontrols+'">');
document.writeln(' <param name="ShowCaptioning" value="0">');
document.writeln(' <param name="ShowDisplay" value="0">');
document.writeln(' <param name="url" value="'+objSource+'">');
document.writeln(' <param name="src" value="'+objSource+'">');
document.writeln(' </object>');
}
}
function getCookie(cookieName){
var cookies=document.cookie;
if(cookies.indexOf(cookieName)==-1)return false;
cookie=cookies.substr(cookies.indexOf(cookieName));
cookie=cookie.split(';')[0];
cookie=cookie.substr(cookie.indexOf('=')+1);
return cookie;
}
function getStyleAtt(obj,stylePrp){
var att="";
if(obj.currentStyle){
stylePrp=stylePrp.replace(/\-(\w)/g,function(k,z){return z.toUpperCase();});
att=obj.currentStyle[stylePrp];
}
else if(document.defaultView&&document.defaultView.getComputedStyle){
att=document.defaultView.getComputedStyle(obj,null).getPropertyValue(stylePrp);
}
return att;
}

// Prototype.js Referenced(noneflash)
function insertAltContent(target, content) {
	if (!$(target)) return;
	$(target).insert({after:content});
	$(target).remove();
}

/* goItemSearch */
function goItemSearch(path){
	var serverId = 1;
	var myServerId = document.getElementById("myServerId").value;
	if ( myServerId != "" && myServerId != null  )
		serverId = myServerId;
	else
		serverId = (getCookie('l1ItemSearchServerId')) ? getCookie('l1ItemSearchServerId') : '1';
	document.location =path+"&serverId="+serverId;
}

function messageAndRedirect(message, url) {
	alert(message);
	location.href = url;
}
