
//////////////////////////////////////////////////////////////////////
// js.ijji.cookie

var domainName = "ijji.com";
var serviceDomainName = document.domain;
// session cookie prefix. Cookies with this prefix will be deleted when logout
var sessionCookiePrefix = "NHN_S_";

function getFixDomain() {
	var s = document.domain;

	if ( s.indexOf(domainName) >= 0 ) {
		return domainName;
	}
	else {
		var n = s.indexOf(".");
		var test = s.split(".");
		if (test.length > 2)
		{
			return s.substring(n + 1, s.length);
		}else{
			return s;
		}
	}
}

function getServiceDomain(name) {
	if ( (location.host).indexOf("dev") == 0 || (location.host).indexOf("alpha") == 0 ) {
		return "alpha-" + name;
	}
	if ( (location.host).indexOf("beta") == 0 ) {
		return "beta-" + name;
	}
	return name;
}

function setDomain() {
	document.domain = getFixDomain();
}

function getCookie(name) {
	var aRec;
	var aCook = document.cookie.split("; ");

	for (var i=0; i<aCook.length; i++) {
		aRec = aCook[i].split("=");
		if (name.toLowerCase()==unescape(aRec[0].toLowerCase())) return aRec[1];
	}

	return "";
}

function setCookie(name, value) {
	var argv = setCookie.arguments;
   	var argc = setCookie.arguments.length;
   	var expires = (2 < argc) ? argv[2] : null;
   	var path = (3 < argc) ? argv[3] : null;
   	var domain = (4 < argc) ? argv[4] : null;
   	var secure = (5 < argc) ? argv[5] : false;
   	document.cookie = name + "=" + escape (value) +
      	((expires == null) ? "" :
        ("; expires=" + expires.toGMTString())) +
      	((path == null) ? "" : ("; path=" + path)) +
      	((domain == null) ? "" : ("; domain=" + getFixDomain())) +
      	((secure == true) ? "; secure" : "");
}

function deleteCookie(name) {
  document.cookie = name + "=dumy; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}

//////////////////////////////////////////////////////////////////////
// js.ijji.string

function defaultIfEmpty(obj, value) {
	if ( obj == null || obj == "" || obj == undefined || obj == "undefined") return value;
	if (typeof value == "boolean" || typeof value == "number") return eval(obj);
	return obj;
}

function isCp1252CharCode(charCode){
	var cp1252ExtCharCodes = new Array(338,339,352,353,376,381,382,402,710,732,8211,8212,8216,8217,8218,8220,8221,8222,8224,8225,8226,8230,8240,8249,8250,8364,8482);
	if(charCode > 0 && charCode <= 0xFF) return true; //Latin1
	for(var i=0; i < cp1252ExtCharCodes.length; i++)
		if(cp1252ExtCharCodes[i] == charCode) return true;
	return false;
}

function getInvalidCp1252Chars(str) {
	var arr = new Array();
	for(var i=0;i<str.length;i++)
		if(!isCp1252CharCode(str.charCodeAt(i))) arr.push( str.charAt(i) );
	if(arr.length == 0) return null;
	return arr;
}

function isCp1252Str(str) {
	for(var i=0;i<str.length;i++)
		if(!isCp1252CharCode(str.charCodeAt(i))) return false;
	return true;
}

//////////////////////////////////////////////////////////////////////
// js.ijji.browser.agent

function isXPSP2(){
    if (!isMSIE() ) return false;

	var agent = window.navigator.userAgent;
	if(agent.indexOf("SV1")) return true;
	if(isXP() && agent.indexOf("MSIE 7.") !=-1) return true;
	// todo : would be removed, if prepare to support Vista
	if (isVista()) return true;
	return false;
}

function isXP(){
	if (!isMSIE() ) return false;
	var agent = window.navigator.userAgent;
	if(agent.indexOf("NT 5.1") !=-1) return true;     //SP1

	return false;
}

function isVista(){
	if (!isMSIE() ) return false;
	var agent = window.navigator.userAgent;
	if(agent.indexOf("NT 6.") !=-1) return true;

    return false;
}

function isMSIE() {
	var agent = window.navigator.userAgent;
	if (agent.indexOf("MSIE") !=-1 ) return true;
	else return false;
}

function isFirefox() {
	var agent = window.navigator.userAgent;
	if (agent.toUpperCase().indexOf("FIREFOX") !=-1 ) return true;
	else return false;
}

function isGameSupportedBrowser() {
	return isMSIE() || isFirefox();
}

function isXPComEnabled(){
	if (isMSIE() ) return false;
	var agent = window.navigator.userAgent;
	if(agent.toUpperCase().indexOf("GECKO") !=-1) return true;     //FireFox, Netscape
	if(agent.toUpperCase().indexOf("OPERA") !=-1) return true;     //Opera
	return false;
}

function isWindows(){
	var agent = window.navigator.userAgent;
	if(agent.toUpperCase().indexOf("WINDOWS") !=-1) return true;
	return false;
}
//////////////////////////////////////////////////////////////////////
// js.ijji.activex

function viewActiveObject(html){
	document.write(html);
}

//////////////////////////////////////////////////////////////////////
// js.ijji.popup

function openSimpleFrameWindow(url, target, width, height) {
	return window.open(url, target, "scrollbars=no,statusbar=no,toolbar=no, menu=no,width=" + width + ",height=" + height);
}


//////////////////////////////////////////////////////////////////////
// js.ijji.html

function addEvent(ev, el) {
	if(ev.substring(0,2) == "on") ev = ev.substring(2);

	if (document.addEventListener) {
		document.addEventListener(ev, el, false);
	}
	else {
		attachEvent("on" + ev, el);
	}
}
function removeEvent(ev, el) {
	if(ev.substring(0,2) == "on") ev = ev.substring(2);

	if (document.addEventListener) {
		document.removeEventListener(ev, el, false);
	}
	else {
		detachEvent("on" + ev, el);
	}
}

function favor() {
	window.external.AddFavorite('http://www.ijji.com', 'ijji - Where Gamers Unite!');
}

//////////////////////////////////////////////////////////////////////
// js.ijji.prototype

String.prototype.trim = function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.cut = function(len, tail) {
    var str = this;
    var l = 0;
    for (var i=0; i<str.length; i++) {
        l += (str.charCodeAt(i) > 128) ? 2 : 1;
        if (l > len) return str.substring(0,i) + tail;
    }
    return str;
}


//////////////////////////////////////////////////////////////////////
// js.ijji.nds

var __loaded = false;
function runObject(objectid, callback) {
    var obj = document.getElementById(objectid);
	if( obj != null ) {
	  	__loaded = true;
		setTimeout(callback,1000);
	}else{
		setTimeout(runObject,1000);
	}
}

var __ndsFrame;
var __ndsURL = "http://lcs." + getFixDomain();

var __ndsURL_SSL_DEV = "https://dev-billing." + getFixDomain();
var __ndsURL_SSL_ALPHA = "https://alpha-billing." + getFixDomain();
var __ndsURL_SSL_BETA = "https://beta-billing." + getFixDomain();
var __ndsURL_SSL_RELEASE = "https://billing." + getFixDomain();
var __nds_SSL = false;

if (location.href.indexOf('https://dev-') == 0) {
	__ndsURL_SSL = __ndsURL_SSL_DEV;
} else if (location.href.indexOf('https://alpha-') == 0) {
	__ndsURL_SSL = __ndsURL_SSL_ALPHA;
} else if (location.href.indexOf('https://beta-') == 0) {
	__ndsURL_SSL = __ndsURL_SSL_BETA;
} else {
	__ndsURL_SSL = __ndsURL_SSL_RELEASE;
}

if ( location.href.indexOf('https') == 0 ) {
	__nds_SSL = true;
}

function setPageId() {
	if ( typeof(__ndsFrame)=="undefined" ) {
		if ( __nds_SSL ) {
			var s = "<iframe name='__ndsIframe' src='/common/blank.html' width=0 height=0 frameborder=0 style='display:none;'></iframe>";
		} else {
			var s = "<iframe name='__ndsIframe' width=0 height=0 frameborder=0 style='display:none;'></iframe>";
		}
		__ndsFrame = "set";
		document.write (s);
		setTimeout("__ndsLoadMain()",500);
	}
}

function __ndsLoadMain() {
	if ( typeof(__ndsIframe)=="object" ) {
		if ( location.href.indexOf('https://') == 0 ) {
			__ndsIframe.location.href = __ndsURL_SSL + "/nds/u{" + getNDSI18NAddedURL(document.URL) + "}";
		} else {
			__ndsIframe.location.href = __ndsURL + "/u{" + getNDSI18NAddedURL(document.URL) + "}";
		}
	} else {
		setTimeout("__ndsLoadMain()",500);
	}
}


//////////////////////////////////////////////////////////////////////
// js.ijji.misc

function toggleDisplay(id) {
  if ( document.getElementById(id).style.display == 'none' ) {
    document.getElementById(id).style.display = "";
  } else {
    document.getElementById(id).style.display = 'none';
  }
}

function parseCurrency(str) {
	var temp = new String(str);
	var SIZE = 3;
	var strings = new Array();

	if ( temp.length <= SIZE ) return temp;

	for (var i = 0; i < temp.length / SIZE; i++ ) {
		if ( temp.length < (i + 1) * SIZE) {
			strings[strings.length] = temp.substr(0,  temp.length - i * SIZE );
		} else {
			strings[strings.length] = temp.substr( temp.length - (i + 1) * SIZE, SIZE);
		}
	}

	var result = "";
	 for (var i = 0; i < strings.length; i++ ) {
	 		if ( result == "" ) result = strings[i];
	 		else result = strings[i] + "," + result;
	 }

	 return result;
}

//////////////////////////////////////////////////////////////////////
// play live
function goPlay(gameId, subId) {
	//alert(__mouse_pos_x + ',' + __mouse_pos_y);
	var startFrame = document.getElementById("startFrame");
	if (startFrame == null)	{
		var obj = document.createElement('iframe');
		obj.setAttribute('id','startFrame');
		obj.style.border = '0px';
		obj.style.width = '0px';
		obj.style.height = '0px';
		obj.style.visibility = 'hidden';
		startFrame = document.body.appendChild(obj);
	}
	startFrame.src="/common/prelaunch.nhn?gameId=" + gameId + "&subId=" + subId + "&posx=" + __mouse_pos_x + "&posy=" + __mouse_pos_y;
}

function showDownloadPopup(flag) {
	var alertLayer = document.getElementById('alertLayer');
	if (flag) {
		alertLayer.style.display = 'block';
	} else {
		alertLayer.style.display = 'none';
	}
}

function startDownloadAutoInstaller() {
	showDownloadPopup(false);
	var hgstartURL = "/nhnusa/dist/hansetup/ijjiAutoInstaller.exe";
	if ( (location.host).indexOf("dev") == 0 || (location.host).indexOf("alpha") == 0 ) {
		hgstartURL = "http://alpha.ijji.com" + hgstartURL;
	} else {
		hgstartURL = "http://cdn.ijjimax.com" + hgstartURL;
	}
	
	location.href = hgstartURL;
}

// AD
function showAd(categories, width, height) {
	var size = 2;
	var seed =  Math.floor(Math.random() * size);

	if (seed == 0) {
		getAdExpo9(categories, width, height);
	}
	else {
		getAdExpo9(categories, width, height);
	}

}

function getAdExpo9(categories, width, height) {
   var e9 = new expo9_ad();
   e9.addBlockingCategories=categories;
   e9.size =  width + "x" + height;
   e9.showAd();
}

// CRM 2 Functions
var _crmPopup = null;

function hasCrmAlert() {
	var checkURL = "services.ijji.com/crm/popupcheck";
	if ( (location.host).indexOf("dev") == 0 || (location.host).indexOf("alpha") == 0 ) {
		checkURL = "alpha-" + checkURL;
	} else if ( (location.host).indexOf("beta") == 0 ) {
		checkURL = "beta-" + checkURL;
	}

	checkURL = "http://" + checkURL;
	ajaxHttpRequest(checkURL, "showCrmLayer");
}

function showCrmLayer(json) {

	var crmLayer = document.getElementById("crm_layer");

	if ( !crmLayer || !json || json.popupyn != "Y") {
		return;
	}

	if ( json.popuptype == "POPUP" ) {
		popupCrm(json.popupURL);
		return;
	}

	var crmP = document.createElement("P");
	crmP.className = "txt";
	crmP.appendChild(document.createTextNode(json.message));
	crmP.appendChild(document.createElement("BR"));
	var crmA = document.createElement("A");
	crmA.appendChild(document.createTextNode("Click for details!"));
	crmA.href = "javascript:popupCrm('"+json.popupURL+"');";

	crmP.appendChild(crmA);
	crmLayer.appendChild(crmP);
	crmLayer.style.display = "block";
}

function popupCrm(url) {
	if ( !url ) { return ; }
	_crmPopup = window.open(url, 'CRM2', 'fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,width=200,height=200');
	document.getElementById("crm_layer").style.display = "none";
}

function closeCrmLayer() {
	document.getElementById("crm_layer").style.display = "none";
}
//////////////////////////////////////////////////////////////////////
// js.ijji.i18n
var __userSelectedLocale = "i18n_userSelectedLocale";
var __determinedLanguage = "i18n_lang";
var __defaultLanguageCode = "en";
var __ndsLangParam = "_lang";
var __langOrder = new Array("en","es");

function getLangCode() {
	var langCode = getCookie(__determinedLanguage);
	if ( langCode == null || langCode.length == 0 ) {
		return __defaultLanguageCode;
	}
	return langCode;
}

function getLangNum() {
	var code = getLangCode();
	for ( var i = 0 ; i < __langOrder.length ; i++ ) {
		if ( code == __langOrder[i] ) return i;
	}
	return 0;
}

function setLangCode(langCode) {
	var expires = 1000 * 60 * 60 * 24 * 365 * 10;
	var expires_date = new Date( (new Date()).getTime() + (expires) );
	setCookie(__userSelectedLocale, langCode, expires_date, null, domainName);
}

function setLangCodeNReload(langCode) {
	setLangCode(langCode);
	location.reload(true);
}

function getNDSI18NAddedURL(url) {
	if ( url == null || url.length <= 0 ) return url;
	
	// check service not in spanish
	var re = new Array(
		/^(http|https):\/\/[^\.]*luminary\.ijji\.com/,
		/^(http|https):\/\/[^\.]*rohan\.ijji\.com/,
		/^(http|https):\/\/[^\.]*channel\.ijji\.com/,
		/^(http|https):\/\/[^\.]*game\.ijji\.com/,
		/^(http|https):\/\/[^\.]*flash\.ijji\.com/,
		/^(http|https):\/\/[^\.]*miningboy\.ijji\.com/,
		/^(http|https):\/\/[^\.]*bbs\.ijji\.com/
	);
	for (var i = 0 ; i < re.length ; i++ ) {
		if ( re[i].test(url) ) {
			return url;
		}
	}
	
	url = url.replace(/[\?&]+$/,"");
	var n = url.indexOf("?");
	if ( n > 0 ) {
		return url + "&" + __ndsLangParam + "=" + getLangCode();
	}
	return url + "?" + __ndsLangParam + "=" + getLangCode();
}

function ialert() {
	var num = getLangNum();
	var msg = "";
	if ( num < arguments.length ) {
		msg = arguments[num];
	} else if ( arguments.length >= 1 ) {
		msg = arguments[0];
	}
	alert(msg);
}

//////////////////////////////////////////////////////////////////////
// ui
function findAbsPos(obj) {
	var curLeft = 0;
	var curTop = 0;
	var n = 0; // exit within 100 loops
	if (obj.offsetParent) {
		do {
			curLeft += obj.offsetLeft;
			curTop += obj.offsetTop;
			n++;
			obj = obj.offsetParent;
		} while ( obj && n < 100 );
	}
	return new Array(curLeft, curTop);
}


//////////////////////////////////////////////////////////////////////
// automatic initializers

// Premier Coupon
var cookieShowPrmrCoupon;
var cookieUsePrmrCoupon;

function hasPremierCoupon(service, useruid, ctype, pcode) {
	if (typeof(service) == 'undefined') service = '';
	if (typeof(useruid) == 'undefined') useruid = '';
	if (typeof(ctype) == 'undefined') ctype = '';
	if (typeof(pcode) == 'undefined') pcode = '';
	
	cookieShowPrmrCoupon = "showPremierCoupon"+useruid+service;
	cookieUsePrmrCoupon = "usePremierCoupon"+useruid;
	
	var prmrCoupon = getCookie(cookieShowPrmrCoupon);
	if ( prmrCoupon == null || prmrCoupon.length == 0 ) {
		var checkURL = "premier.ijji.com/coupon/chkCoupon.nhn";
		if ( (location.host).indexOf("dev") == 0 || (location.host).indexOf("alpha") == 0 ) {
			checkURL = "alpha-" + checkURL;
		} else if ( (location.host).indexOf("beta") == 0 ) {
			checkURL = "beta-" + checkURL;
		}
		checkURL = "http://" + checkURL + "?ctype="+ctype+"&pcode="+pcode;
		ajaxHttpRequest(checkURL, "showPremierCouponLayer");
	}
}

function showPremierCouponLayer(json) {
	var prmrLayer = document.getElementById("prmrCouponLayer");
	if ( !prmrLayer || !json || json.rtn != "0") {
//		closePremierCouponLayer();
		return;
	}
	
	var prmrPkg = document.getElementById("ajax_pcoupon");
	if(prmrPkg) {
		prmrPkg.innerHTML= json.pname;
	}
	
	var pgcoin = document.getElementById("ajax_pcoupon_pgcoin");
	if(pgcoin) {
		pgcoin.innerHTML= json.pgcoin;
	}
	
	prmrLayer.style.display = "block";
}

function closePremierCouponLayer() {
	document.getElementById('prmrCouponLayer').style.display = "none";
	// set cookie
	var validDays=1;
	var exp=new Date();
	exp.setDate(exp.getDate()+validDays);
	document.cookie = cookieShowPrmrCoupon+"=N; path=/; domain="+getFixDomain()+"; expires="+exp.toGMTString()+"; ";
}

function usePremierCoupon() {
	// set cookie
	var validDays=1;
	var exp=new Date();
	exp.setDate(exp.getDate()+validDays);
	document.cookie = cookieUsePrmrCoupon+"=Y; path=/; domain="+getFixDomain()+"; expires="+exp.toGMTString()+"; ";

	// redirect to registration page
	var prmrReg = "premier.ijji.com/premieroptions/ccart.nhn";
	if ( (location.host).indexOf("dev") == 0 || (location.host).indexOf("alpha") == 0 ) {
		prmrReg = "alpha-" + prmrReg;
	} else if ( (location.host).indexOf("beta") == 0 ) {
		prmrReg = "beta-" + prmrReg;
	}
	prmrReg = "http://" + prmrReg;
	document.location.href=prmrReg;
}

////////////////////////////////////////////////////////////////////////////////
// Codes related with Window Event

// mouse position
var __mouse_pos_x = 0;
var __mouse_pos_y = 0;
document.onmousemove=mtrack;
function mtrack(e) {
	var scrolledValue = getScrollXY();

	if ( typeof(window.screenLeft) == 'number' ) {
		__mouse_pos_x = event.screenX - window.screenLeft + scrolledValue[0];
		__mouse_pos_y = event.screenY - window.screenTop + scrolledValue[1];
	} else {
		if (typeof(event) != 'undefined'){
			__mouse_pos_x = event.clientX;
			__mouse_pos_y = event.clientY;
		} else {
			__mouse_pos_x = e.pageX;
			__mouse_pos_y = e.pageY;
		}
	}
}

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

// Codes related with Window Event
/////////////////////////////////////////////////////////////////////////////////

setDomain();
setPageId();

<!-- Start Quantcast tag -->
function quantCall() {
    var quant_src = "http://pixel.quantserve.com/pixel/p-bab2-LCsBITgs.gif"; 
	    
    if ("https:"==document.location.protocol) 
		quant_src = "https://secure.quantserve.com/pixel/p-bab2-LCsBITgs.gif"; //secure site

    var quant_img = document.createElement("img");
    quant_img.setAttribute("name","quantImg");
    quant_img.setAttribute("src",quant_src);
    quant_img.setAttribute("height",1);
    quant_img.setAttribute("width",1);
    quant_img.style.display = "none";
    document.body.appendChild(quant_img);
}

addEvent("onload",quantCall);
<!-- End Quantcast tag -->


