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 setDomain() {
	document.domain = getFixDomain();
}


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;
}

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;";
}

function isXPSP2(){
    tmp_MSIE = window.navigator.userAgent.indexOf("MSIE");
    if(tmp_MSIE && window.navigator.userAgent.indexOf("SV1") > tmp_MSIE){
        return true;     //SP2
    }else{
        return false;
    }
}


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

function isMSIE() {
	if (window.navigator.userAgent.indexOf("MSIE") >=0 ) return true;
	else return false;
}

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

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

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

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);
	}
}

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;
}


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;
}

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;
function setPageId() {
	if ( typeof(__ndsFrame)=="undefined") {
		var s = "<iframe name='__ndsIframe' width=0 height=0 frameborder=0 style='display:none;'></iframe>";
		//var s = "<img src='' id='__ndsImg' width='0' height='0'>";
		__ndsFrame = "set";
		document.write (s);
		setTimeout("__ndsLoadMain()",500);
	}

}

function __ndsLoadMain() {
/*
	var o = document.getElementById("__ndsImg");
	if ( typeof(o)=="object" ) {
		o.src = "http://lcs.ijji.com/u{" + document.URL + "}";
	} else {
		setTimeout("__ndsLoadMain()",500);
	}
	return;
*/
	if ( typeof(__ndsIframe)=="object" ) {
		__ndsIframe.location.href = "http://lcs.ijji.com/u{" + document.URL + "}";
	} else {
		setTimeout("__ndsLoadMain()",500);
	}
}

function favor() {
	window.external.AddFavorite('http://www.ijji.com', 'ijji - Live Games Online');
}

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



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

setDomain();
setPageId();
