var NgbDebug = new function __NgbDebug()
{
	this.Print = function ( Message )
	{
		alert( Message );
	}
}

function NgbEVMDelegator( /*function*/ _fn )
{
	try
	{
		this.fn = _fn;
	}
	catch( e ) 
	{
		NgbDebug.Print ( 'EVMDelegator Error!' );
	}
}

function __NgbCommand( _Type, _Command, _ArgForCommand )
{
	this.Type = _Type;
	this.Command = _Command;
	this.nExecuteCount = 0;
	this.ArgForCommand = _ArgForCommand;
	this.IsExecute = false;
	
	this.Execute = function( arg )
	{
		if( !this.IsExecute )
		{
			this.IsExecute = true;
			this.nExecuteCount++;

			var argument = new Array();
			argument[ 0 ] = arg;
			argument[ 1 ] = this.ArgForCommand;

			this.Command.fn.apply( this.Command.fn, argument );
			this.IsExecute = false;
		}
		else
		{
			NgbDebug.Print( "Excute Error" );
		}
	}	
}

function __NgbEvent( _Name )
{
	// State
	this.k_nEventState_notRaised = 1;
	this.k_nEventState_raised = 2;
	this.k_nEventState_paused = 3;
	this.k_nEventState_canceled = 4;

	this.k_nEventHandlingType_Handler = 1;
	this.k_nEventHandlingType_Command = 2;

	this.State = this.k_nEventState_notRaised;
	this.Name = _Name;
	this.arg = null;
	this.Command = new Array();
	
	this.RaiseEvent = function( arg )
	{
		this.State = this.k_nEventState_raised;
		this.arg = arg;
		this.Execute();
	}

	this.AddHandler = function( _Command, arg )
	{
		this.Command[ this.Command.length ] = new __NgbCommand( this.k_nEventHandlingType_Handler, _Command, arg );
		this.Execute();
	}
	
	this.AddCommand = function( _Command, arg )
	{
		this.Command[ this.Command.length ] = new __NgbCommand( this.k_nEventHandlingType_Command, _Command, arg );
		this.Execute();
	}
	
	this.Execute = function()
	{
		if( this.State == this.k_nEventState_raised )
		{
			for( var i = 0 ; i < this.Command.length ; i++ )
			{
				if( this.Command[ i ].Type == this.k_nEventHandlingType_Handler ||
					( this.Command[ i ].Type == this.k_nEventHandlingType_Command && this.Command[ i ].nExecuteCount == 0 ) )
					this.Command[ i ].Execute( this.arg );
			}
		}
	}
}

var NgbEVM = new function __NgbEVM()
{
	// Type
	this.k_nEventType_immediately = 0;
	this.k_nEventType_onPageStart = 1;
	this.k_nEventType_onPageEnd = 2;
	this.k_nEventType_onLoad = 3;
	this.k_nEventType_onUnload = 4;
	this.k_nEventType_onSubmit = 5;

	// For Auth Syste
	this.k_nEventType_onRefreshNoteBox = 6;
	
	this.Event = new Array();
	this.Event[ this.k_nEventType_immediately ]				= new __NgbEvent( "k_nEventType_immediately" );
	this.Event[ this.k_nEventType_onPageStart ]				= new __NgbEvent( "k_nEventType_onPageStart" );
	this.Event[ this.k_nEventType_onPageEnd ]				= new __NgbEvent( "k_nEventType_onPageEnd" );
	this.Event[ this.k_nEventType_onLoad ]					= new __NgbEvent( "k_nEventType_onLoad" );
	this.Event[ this.k_nEventType_onUnload ]					= new __NgbEvent( "k_nEventType_onUnload" );
	this.Event[ this.k_nEventType_onSubmit ]					= new __NgbEvent( "k_nEventType_onSubmit" );
	this.Event[ this.k_nEventType_onRefreshNoteBox ]			= new __NgbEvent( "k_nEventType_onRefreshNoteBox" );
	
	this.AddHandler = function( nEventType, delegator /*, argument list... */ )
	{
		var arg = new Array();
		for( var i = 2 ; i < arguments.length ; i++ )
			arg [ i - 2 ] = arguments[ i ];

		if( !isNaN( nEventType ) )
			this.Event[ nEventType ].AddHandler( delegator, arg );
		else
			NgbDebug.Print( 'Invalid Event Type : Event.AddHandler - ' + nEventType );
	}
	
	this.AddCommand = function( nEventType, delegator /*, argument list... */ )
	{
		var arg = new Array();
		for( var i = 2 ; i < arguments.length ; i++ )
			arg [ i - 2 ] = arguments[ i ];

		if( !isNaN( nEventType ) )
			this.Event[ nEventType ].AddCommand( delegator, arg );
		else
			NgbDebug.Print( 'Invalid Event Type : Event.AddCommand - ' + nEventType );
	}
	
	this.ReplaceEventHandlerHelper = function( /*function*/ fnEventHandler, /*string*/ strPreJavascriptCode, /*string*/ strPostJavascriptCode )
	{
		var strEventHandlerJavascriptCode = "";
		if ( fnEventHandler )
		{
			strEventHandlerJavascriptCode = fnEventHandler.toString();
			strEventHandlerJavascriptCode = strEventHandlerJavascriptCode.slice( strEventHandlerJavascriptCode.indexOf( "{" ) + 1, -1 );
		}
		
		return new Function( strPreJavascriptCode + strEventHandlerJavascriptCode + strPostJavascriptCode );
	}
	
	this.ReplaceEventHandler = function()
	{
		document.body.onload = this.ReplaceEventHandlerHelper( document.body.onload, "", "return NgbEVM.RaiseEvent( NgbEVM.k_nEventType_onLoad );" );
		document.body.onunload = this.ReplaceEventHandlerHelper( document.body.onunload, "", "return NgbEVM.RaiseEvent( NgbEVM.k_nEventType_onUnload );" );
	}
	
	this.GetEventTypeName = function( nEventType )
	{
		return this.Event[ nEventType ].Name;
	}
	
	this.RaiseEvent = function( nEventType )
	{
		try
		{
			NgbDebug.print( this.GetEventTypeName( nEventType ) );
		}
		catch( e ) {}
		
		var arg = new Array();
		for( var i = 1 ; i < arguments.length ; i++ )
			arg [ i - 1 ] = arguments[ i ];

		if( !isNaN( nEventType ) )
			this.Event[ nEventType ].RaiseEvent( arg );
		else
			NgbDebug.Print( 'Invalid Event Type : Event.RaiseEvent - ' + nEventType );
	}
}

var NgbLogin = new function __NgbLogin()
{
	this.isLoginProcessing = false;
	
	var _codeRegSite = 0;
	var _strRedirect;
	var _isPhone = false;
	
	this.SubmitLogin = function()
	{
		var strDomain;
		var strEncData = arguments [ 1 ][ 0 ];
		var codeRegSite = arguments [ 1 ][ 1 ];
		var strRedirect = arguments [ 1 ][ 2 ];
		var isPhone = arguments [ 1 ][ 3 ];
		
		if ( this.isLoginProcessing )
		{
			alert( "·Î±×ÀÎ ÇÏ´Â ÁßÀÔ´Ï´Ù. Àá½Ã¸¸ ±â´Ù·ÁÁÖ¼¼¿ä." );
			return false;
		}
		this.isLoginProcessing = true;
		
		NgbClientForm.AddChildForSubform( 'strEncData', strEncData );
		NgbClientForm.AddChildForSubform( 'codeRegSite', codeRegSite );
		
		if ( typeof( strRedirect ) != 'undefined' )
			NgbClientForm.AddChildForSubform( 'strRedirect', strRedirect );
			
		if ( typeof( isPhone ) == 'undefined' )
			isPhone = false;

		try
		{
			strDomain = NgbUrl.GetDomainURL();
		}
		catch ( e )
		{
			strDomain = 'login.nexon.com';
		}
		
		if ( isPhone == false )
			NgbClientForm.SubmitForm( 'https://' + ( ( strDomain == 'df.nexon.com' || strDomain == 'dflogin.nexon.com' ) ? 'dflogin.nexon.com' : 'login.nexon.com' ) + '/login/page/loginproc.aspx' );
		else
			NgbClientForm.SubmitForm( 'https://' + ( ( strDomain == 'df.nexon.com' || strDomain == 'dflogin.nexon.com' ) ? 'dflogin.nexon.com' : 'login.nexon.com' ) + '/login/page/loginphone.aspx' );
	}

	this.Login = function( strNexonID, strPassword, codeRegSite, strRedirect, isPhone )
	{
		strNexonID = NgbString.Trim( strNexonID );
		strPassword = NgbString.Trim( strPassword );
		
		if ( typeof( codeRegSite ) == 'undefined' )
			codeRegSite = 0;
			
		if ( typeof( isPhone ) == 'undefined' )
			isPhone = false;
			
		if ( strNexonID == '' )
		{
			alert( '¾ÆÀÌµð¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä.' );
			return;
		}
		else if ( strPassword == '' )
		{
			alert( 'ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä.' );
			return;
		}
		
		_codeRegSite = codeRegSite;
		_strRedirect = strRedirect;
		_isPhone = isPhone;
		
		try
		{
			NgbSecurity.InitData();
			
			NgbSecurity.AddData( strNexonID );
			NgbSecurity.AddData( strPassword );
			
			try
			{
				strDomain = NgbUrl.GetDomainURL();
			}
			catch ( e )
			{
				strDomain = 'login.nexon.com';
			}
			
			NgbSecurity.SetURL( 'https://' + ( ( strDomain == 'df.nexon.com' || strDomain == 'dflogin.nexon.com' ) ? 'dflogin.nexon.com' : 'login.nexon.com' ) + '/login/page/encryptinfo.aspx', '·Î±×ÀÎ ÇÏ´Â ÁßÀÔ´Ï´Ù. Àá½Ã¸¸ ±â´Ù·ÁÁÖ¼¼¿ä.' );
			NgbSecurity.Encrypt( NgbLogin.EncryptHandler );
		}
		catch( e )
		{
			NgbEVM.AddCommand( NgbEVM.k_nEventType_onPageEnd, new NgbEVMDelegator( NgbLogin.SubmitLogin ), '', _codeRegSite, _strRedirect, _isPhone );
		}
	}
	
	this.EncryptHandler = function( encData )
	{
		NgbEVM.AddCommand( NgbEVM.k_nEventType_onPageEnd, new NgbEVMDelegator( NgbLogin.SubmitLogin ), encData, _codeRegSite, _strRedirect, _isPhone );
	}

	this.Logout = function( strURL )
	{
		if ( typeof( strURL ) == 'undefined' )
			strURL = document.location.href;
		
		document.location.href = 'http://' + ( ( NgbUrl.GetDomainURL() == 'df.nexon.com' || NgbUrl.GetDomainURL() == 'dflogin.nexon.com' )  ? 'dflogin.nexon.com' : 'login.nexon.com' ) + '/login/page/logout.aspx?redirect=' + escape( strURL );
	}
}

var NgbCookie = new function __NgbCookie()
{
	this.GetCookie = function ( nameVal )
	{
		var numCookie = document.cookie.length;
		var oven = document.cookie.split( '; ' );
	
		for ( var i = 0; i < oven.length; i++ )
		{
			if ( oven[i].indexOf( '=' ) != -1 )
			{
				cookieName = oven[i].substring( 0, oven[i].indexOf( '=' ) );
			} else {
				cookieName = oven[i];
			}
	
			if ( cookieName == nameVal )
			{
				if ( oven[i].indexOf( '=' ) != -1 )
				{
					cookieVal = oven[i].substr( oven[i].indexOf( '=' ) + 1 );
				} else {
					cookieVal = '';
				}
				return cookieVal;
			}
		}
		return '';
	}
	
	this.setCookie_Permanent = function (nameVal, value, nameDomain)
	{
		if ( nameDomain == null || typeof( nameDomain ) == 'undefined' )
			nameDomain = "nexon.com";
		
		// ÄíÅ° ÀúÀå : Permanent Cookie --> µÇµµ·ÏÀÌ¸é »ç¿ëÇÏÁö ¸¶¼¼¿ä. ÄíÅ° ²¿ÀÔ´Ï´Ù... -_-;;;
		document.cookie = nameVal + "=" + escape(value) + ";expires=Thu, 30 Aug 2030 10:02:13 UTC; path=/; domain=" + nameDomain + ";";
	}
}

var NgbString = new function __NgbString()
{
	this.TrimStart = function ( word ) 
	{
		var wordLeng = word.length;
		var i;
		var pos, first, last;
	
		for(i = 0; i < wordLeng; i++) {
			if(word.charAt(i) != ' ') break;
		}
		pos = i;
		first = pos;
		last = wordLeng;
		word = word.substring(first,last);
		return word;
	}

	this.TrimEnd = function ( word ) 
	{
		var wordLeng = word.length;
		var i;
		var pos, first, last;
	
		for(i = wordLeng-1; i >= 0; i--) {
			if(word.charAt(i) != ' ') break;
		}
		pos = i;
		first = 0;
		last = pos + 1;
		word = word.substring(first,last);
		return word;
	}

	this.Trim = function ( word ) 
	{
		word = this.TrimStart( word );
		word = this.TrimEnd( word );
		return word;
	}

	this.TrimAll = function ( word ) 
	{
		var wordLeng = word.length;
		var i;
	
		for(i=0; i<wordLeng; i++) {
			word = word.replace(' ','');
		}
		return word;
	}
	
	this.IsEmpty = function ( strParam )
	{
		if( strParam == null )
			return true;
		else if( strParam == 'undefined' )
			return true;
		else if( this.TrimAll( strParam ) == '' )
			return true;
		else
			return false;
	}
	
	this.GetLengthToByte = function ( word )
	{
		var nValue = 0;
		
		for ( var i = 0; i < word.length; i ++ )
		{
			if ( word.charCodeAt( i ) > 255 )
				nValue += 2;
			else
				nValue ++;
		}
		
		return nValue;
	}
	
	this.CheckSpecialCharacter = function ( strValue ) 
	{ 
		var bReturn = true;
		
		for ( var nLoop = 0; nLoop < strValue.length; nLoop ++ )
		{
			var charValue = strValue.charAt( nLoop );
			
			if (( charValue >= 'A' && charValue <= 'Z') || ( charValue >= 'a' && charValue <='z'))
			{
				continue;//'¿µ¾î';
			}
			else if ( charValue >= '0' && charValue <= '9')
			{
				continue;//'¼ýÀÚ';
			}
			else if ( charValue >= '\uAC00' && charValue <= '\uD7A3')
			{
				continue;//'ÇÑ±Û';
			}
			else if ( charValue == ' ')
			{
				continue; // ' ' (space)
			}
			else
			{
				bReturn = false;//'Áñ
				break;				
			}
		}
		
		return bReturn;
	}
	
	this.CheckNumberOnly = function ( strValue ) 
	{ 
		var bReturn = true;

		for ( var nLoop = 0; nLoop < strValue.length; nLoop ++ )
		{
			var charValue = strValue.charAt( nLoop );
			
			if ( charValue < '0' || charValue > '9' )
			{
				bReturn = false;// Áñ
				break;	
			}
		}

		return bReturn;
	}
	
	this.CheckNumberNAlphabetOnly = function ( strValue ) 
	{ 
		var bReturn = true;

		for ( var nLoop = 0; nLoop < strValue.length; nLoop ++ )
		{
			var charValue = strValue.charAt( nLoop );
			
			if (( charValue >= 'A' && charValue <= 'Z') || ( charValue >= 'a' && charValue <='z'))
			{
				continue;//'¿µ¾î';
			}
			else if ( charValue >= '0' && charValue <= '9')
			{
				continue;//'¼ýÀÚ';
			}
			else
			{
				bReturn = false;//'Áñ
				break;				
			}
		}
		return bReturn;
	}
}

var NgbClientForm = new function __NgbClientForm()
{
	this.AddChildForSubform = function ( strName, strValue )
	{
		var objForm = document.getElementById( 'formLogin' );
		var objInput;
		try
		{
			objInput = eval( 'document.getElementById( "formLogin" ).' + strName );
			objInput.value = strValue;
		}
		catch( e )
		{
			var objInput		= document.createElement( 'input' );
			objInput.type		= 'hidden';
			objInput.name		= strName;
			objInput.value		= strValue;
			objForm.appendChild( objInput );
		}
	}

	this.SubmitFormWithTarget = function ( strURL , strTarget )
	{
		var objForm = document.formLogin;
		
		if( NgbString.Trim(strTarget) == '' )
			objForm.target = '_self';
		else
			objForm.target = strTarget;
		
		objForm.action = strURL;
		objForm.submit();
	}
	
	this.SubmitForm = function ( strURL )
	{
		this.SubmitFormWithTarget( strURL, '_self' );
	}
}

var NgbMember = new function __NgbMember()
{
	this.GoLoginPage = function()
	{
		document.location.href = 'http://login.nexon.com/login/page/nx.aspx?url=login/login&redirect=' + escape( document.location.href );
		return false;
	}

	this.OpenUserProfile = function( oidUser )
	{
		var strURL = 'http://www.nexon.com/mypage/page/nxpop.aspx?url=member/profile&oidUser=' + oidUser ;
		window.open( strURL , 'UserProfile', 'scrollbars=no, resizable=no, width=488, height=570' ); 
		return false;
	}
		
	this.SearchNexonID = function( codeRegSite, strWiseLogParam )
	{
		if ( typeof( codeRegSite ) == 'undefined' )
			codeRegSite = 1;
			
		if ( typeof( strWiseLogParam ) == 'undefined' )
			strWiseLogParam = "";
			
		var strURL = 'https://www.nexon.com/member/page/nxpop.aspx?url=nexon/searchid&codeRegSite=' + codeRegSite + strWiseLogParam;
		window.open( strURL , 'SearchID', 'scrollbars=no, resizable=no, width=500, height=580' ); 
		
		return false;
	}
	
	this.SearchPassword = function( codeRegSite, strWiseLogParam )
	{
		if ( typeof( codeRegSite ) == 'undefined' )
			codeRegSite = 1;
			
		if ( typeof( strWiseLogParam ) == 'undefined' )
			strWiseLogParam = "";
			
		var strURL = 'https://www.nexon.com/member/page/nxpop.aspx?url=nexon/searchpassword&codeRegSite=' + codeRegSite + strWiseLogParam;
		window.open( strURL , 'SearchPass', 'scrollbars=no, resizable=no, width=500, height=580'); 
		
		return false;
	}
	
	this.GoRegisterPage = function( codeRegSite, strWiseLogParam )
	{
		if ( typeof( codeRegSite ) == 'undefined' )
			codeRegSite = 1;
		if ( typeof( strWiseLogParam ) == 'undefined' )
			strWiseLogParam = "";

		window.open( 'https://www.nexon.com/join/page/nx.aspx?URL=join/join&codeRegSite=' + codeRegSite + strWiseLogParam );
		
		return false;
	}
	
	this.GoCashReFillPage = function( )
	{
		if( NgbMember.IsLogin() )
		{
			var strURL = 'http://www.nexon.com/mypage/page/cashfill.aspx' ;
			window.open( strURL , 'UserProfile', 'scrollbars=no, resizable=no, width=480, height=600' ); 
		}
		else
		{
			NgbMember.GoLoginPage();
		}
		
		return false;
	}
	
	this.IsLogin = function()
	{
		if( NgbCookie.GetCookie( 'IL' ) == '1' )
			return true;
		else
			return false;
	}
	
	this.GoPersonalInfoPage = function( n4RenderType, strWiselogParam )
	{
		var strURL = 'https://www.nexon.com/mypage/page/nxsecure.aspx?url=myinfo/personalinfo' + strWiselogParam ;
		
		if ( n4RenderType == 0 )
			location.href = strURL; 
		else
			window.open( strURL , 'Privacy', 'scrollbars=no, resizable=no, width=600, height=575' ); 
	}
	
	this.GoPrivacyPage = function()
	{
		var strURL = 'http://www.nexon.com/etc/pop_privacy.html?ST=nexon&PS=footer' ;
		window.open( strURL , 'Privacy', 'scrollbars=no, resizable=no, width=600, height=575' ); 
	}
	
	this.GoStipulationPage = function()
	{
		var strURL = 'http://www.nexon.com/etc/pop_stipulation.html?ST=nexon&PS=footer' ;
		window.open( strURL , 'Stipulation', 'scrollbars=no, resizable=no, width=590, height=525' ); 
	}
	
	this.GoInfo_ChildProtect = function( target, wiselog ) 
	{
		if( typeof( target ) == "undefined" )
			target = "_self";
		
		if( typeof( wiselog ) == "undefined" )
			wiselog = "";
		
		if( target == "_blank" )
			window.open( "http://www.nexon.com/join/page/nx.aspx?url=info/guidechildprotect" + wiselog, "GoInfo_ChildProtect" );
		else
			location.href = "http://www.nexon.com/join/page/nx.aspx?url=info/guidechildprotect" + wiselog;
	}
	
	this.GoInfo_RealName = function( target )
	{
		if( typeof( target ) == "undefined" )
			target = "_self";
			
		if( target == "_blank" )
			window.open( "http://www.nexon.com/join/page/nx.aspx?url=info/guiderealname", "GoInfo_RealName" );
		else
			location.href = "http://www.nexon.com/join/page/nx.aspx?url=info/guiderealname";
	}
	
	this.GoInfo_UserInfo = function( target, wiselog )
	{
		if( typeof( target ) == "undefined" )
			target = "_self";
			
		if( typeof( wiselog ) == "undefined" )
			wiselog = "";
			
		if( target == "_blank" )
			window.open( "http://www.nexon.com/join/page/nx.aspx?url=info/guideuserinfo" + wiselog, "GoInfo_UserInfo" );
		else
			location.href = "http://www.nexon.com/join/page/nx.aspx?url=info/guideuserinfo" + wiselog;
	}
	
	this.GoInfo_Stipulation = function( target, wiselog )
	{
		if( typeof( target ) == "undefined" )
			target = "_self";
			
		if( typeof( wiselog ) == "undefined" )
			wiselog = "";
			
		if( target == "_blank" )
			window.open( "http://www.nexon.com/join/page/nx.aspx?url=info/stipulation" + wiselog, "GoInfo_Stipulation" );
		else
			location.href = "http://www.nexon.com/join/page/nx.aspx?url=info/stipulation" + wiselog;
	}
	
	this.GoInfo_SystemInfo = function( target )
	{
		if( typeof( target ) == "undefined" )
			target = "_self";
			
		if( target == "_blank" )
			window.open( "http://www.nexon.com/join/page/nx.aspx?url=info/systeminfo", "GoInfo_SystemInfo" );
		else
			location.href = "http://www.nexon.com/join/page/nx.aspx?url=info/systeminfo";
	}	
}

var NgbGameUser = new function __NgbGameUser()
{
	this.SearchGamePassword = function( maskGameCode )
	{
		var strURL = '';
		
		switch( maskGameCode )
		{
			case 131072: //baram
			case 196608: //lod 
			case 393216: //asgard
			case 262144: //elan 
			case 524288: //tales
				strURL = "https://www.nexon.com/doomvas/member/page/nxpop.aspx?url=game/changepassword&maskgamecode=" + maskGameCode;
				break; 
			case 589824: //maple
				strURL = "https://www.nexon.com/member/page/nxpop.aspx?url=game/changepassword_maple";
				break;
			case 720896: //ca
				strURL = "https://www.nexon.com/member/page/nxpop.aspx?url=game/changepassword_ca";
				break;
		}
		
		window.open( strURL , 'FindGamePwd_Popup', 'toolbar=no, location=no, scrollbars=no, resizable=no, width=488, height=500'); 
		
		return false;
		
	}
	
	this.ChangeGameNexonID = function( maskGameCode )
	{
		var strURL = '';
		var n4Height = 350;
		
		switch ( maskGameCode )
		{
			case 131072: //baram
			case 196608: //load 
			case 393216: //asgard
			case 262144: //elan 
				strURL = "https://www.nexon.com/doomvas/member/page/nxpop.aspx?url=game/changeid&maskgamecode=" + maskGameCode;
				break;
			case 589824: //maple
				strURL = "https://www.nexon.com/member/page/nxpop.aspx?url=game/changeid_maple";
				n4Height = 400;
				break;
			case 720896: //ca
				strURL = "https://www.nexon.com/member/page/nxpop.aspx?url=game/changeid_ca";
				break;
			case 786432: //qplay
				strURL = "https://www.nexon.com/member/page/nxpop.aspx?url=game/changeid_qplay";
				break;
		}
		
		window.open( strURL , 'ChangeNexonID_Popup', 'toolbar=no,location=no,scrollbars=no,resizable=no,width=488,height=' + n4Height ); 
		
		return false;
	}
}

var NgbNote = new function __NgbNote()
{
	this.OpenNotebox = function ( strNoteBoxURL, strWiseLogParam )
	{
		strNoteBoxURL = NgbString.IsEmpty( strNoteBoxURL ) ? 'http://message.nexon.com/nxcom/page/Gnx.aspx?URL=message/memo_box' : strNoteBoxURL;
		
		if ( !NgbString.IsEmpty( strWiseLogParam ) )
			strNoteBoxURL = strNoteBoxURL + strWiseLogParam;
		try
		{
			if( NgbMember.IsLogin() )
			{
				var memobox_target = 'memo_box_' + NgbCookie.GetCookie( 'NXCHOID' );
				window.open( strNoteBoxURL , memobox_target , 'width=640,height=480,toolbar=no,status=no,directories=no,scrollbars=no,location=no,resizable=no,menubar=no' );
			}
			else
			{
				NgbMember.GoLoginPage();
			}
		}
		catch( E )
		{
			window.open( strNoteBoxURL , memobox_target , 'width=640,height=480,toolbar=no,status=no,directories=no,scrollbars=no,location=no,resizable=no,menubar=no' );
		}
	}
	
	this.OpenNoteSend = function ( GameCode , ToCharacterName )
	{
		strNoteSendURL = 'http://message.nexon.com/nxcom/page/Gnx.aspx?URL=message/memo_send&maskGameCode=' + GameCode;
		if ( !NgbString.IsEmpty( ToCharacterName ) )
		{
			strNoteSendURL += '&strVirtualUserName=' + ToCharacterName;
		}
		
		if( NgbMember.IsLogin() )
		{
			window.open( strNoteSendURL , 'memo_send' , 'width=370,height=298,toolbar=no,status=no,directories=no,scrollbars=no,location=no,resizable=no,menubar=no' );
		}
		else
		{
			NgbMember.GoLoginPage();
		}
	}
}

var NgbReport = new function __NgbReport()
{
	this.OpenArticleReport = function ( GameCode, BoardSN, ArticleSN, BoardURL )
	{
		if( NgbMember.IsLogin() )
		{
			strReportURL = 'http://www.nexon.com/common/page/nxpop.aspx?url=report/article';
			strReportURL += '&maskGameCode=' + GameCode
			strReportURL += '&oidBoard=' + BoardSN
			strReportURL += '&oidArticle=' + ArticleSN
			strReportURL += '&strBoardUrl=' + BoardURL
			
			window.open( strReportURL , 'ReportArticle' , 'width=488,height=440,toolbar=no,status=no,directories=no,scrollbars=no,location=no,resizable=no,menubar=no' );
		}
		else
		{
			NgbMember.GoLoginPage();
		}
	}
}

var NgbBrowser = new __NgbBrowser();
function __NgbBrowser()
{
	this.agt = navigator.userAgent.toLowerCase();
	this.check = function(browserName) { return this.agt.indexOf(browserName) != -1 };
	this.msie = function() { return this.check("msie") };
	this.msie5 = function() { return this.check("msie 5") };
	this.msie55 = function() { return this.check("msie 5.5") };
	this.msie6 = function() { return this.check("msie 6") };
	this.msie7 = function() { return this.check("msie 7") };
	this.msie8 = function() { return this.check("msie 8") };
	this.chrome = function() { return this.check("chrome") };
	this.firefox = function() { return this.check("firefox") };
	this.netscape = function() { return this.check("netscape") };
	this.safari = function() { return this.check("safari") };
	this.opera = function() { return this.check("opera") };
	this.gecko = function() { return this.check("gecko") };
	this.khtml = function() { return this.check("khtml") };
	this.windows = function() { return this.check("windows") };
	this.windows2000 = function() { return this.check("windows nt 5.0") };
	this.windowsXP = function() { return this.check("windows nt 5.1") };
	this.windows98 = function() { return this.check("windows 98") };
	this.mac = function() { return this.check("mac") };
	this.linux = function() { return this.check("linux") };
}

var NgbUrl = new function __NgbUrl()
{
	this.GetQueryString = function ( strQuery ) 
	{
		var strQueryString;
		var strHref = document.location.href.toLowerCase();
		strQuery = strQuery.toLowerCase();
		
		strQueryString = strHref.substr(strHref.indexOf("?")+1);
		strQueryString = "&" + strQueryString + "&";

		var n4Index = strQueryString.indexOf("&" + strQuery + "=");
		var tempValue ;
		
		strUrlString = document.location.href.substr(strHref.indexOf("?")+1);
		strUrlString = "&" + strUrlString + "&";
		
		if(n4Index == -1)
		{
			return "";
		}
		else
		{
			tempValue = strUrlString.substr(n4Index+1);
			tempValue = tempValue.substring(tempValue.indexOf("=")+1, tempValue.indexOf("&"));
			if( tempValue == "undefined")
				tempValue = "";
				
			tempValue = tempValue.replace("#","");
			return tempValue;
		}
	};
	this.SetQueryString = function ( url, strParam, strValue )
	{
		var blParam = false;
		var strHref = url.toLowerCase();
		var strTempURL = "";		
				
		if (( strParam != "" ) && ( strValue.toString() != "" )) 
		{			
			var strTempParam = "&" + strParam.toLowerCase() + "=";
			
			// if strParam Exists...
			if ( strHref.indexOf( strTempParam ) != -1 ) 
			{	
				var strTempQueryString = strHref.split( strTempParam );
				var strBaseURL = strTempQueryString[0];
				var strLastURL = strTempQueryString[1].substr(strTempQueryString[1].indexOf("&")+1);
									
				strTempURL = strBaseURL + strTempParam + strValue;
											
				if ( strLastURL.indexOf( "=" ) != -1 )
					strTempURL += "&" + strLastURL;
			} 
			else 
			{
				strTempURL = strHref + strTempParam + strValue;
			}
		}
						
		return strTempURL.toString();
	};
	
	this.Redirect = function ( url )
	{
		if ( url != "" )
		{
			document.location.href = url.toString();
		}
	};
	
	this.GetDomainURL = function ()
	{
		var url = location.href;
		var reg = /(.)+:\/\/([^\/\s]+)/i;
		var data = url.match(reg);
		return data[2];
 	};
}

var NgbAjax = new function __NgbAjax()
{
	this.NxRequest = new Array();
	this.nRequestCount = 0;

	this.GetAjaxObject = function ( nIndex ) 
	{
		if( window.ActiveXObject )
		{
			try 
			{
				this.NxRequest[ nIndex ] = new ActiveXObject( 'Msxml12.XMLHTTP' );
			} 
			catch( e ) 
			{
				try 
				{
					this.NxRequest[ nIndex ]= new ActiveXObject( 'Microsoft.XMLHTTP' );
				} 
				catch (e2) 
				{
					this.NxRequest[ nIndex ] = new XMLHttpRequest();	// IE 7.0
				}
			}
		} 
		else 
		{
			this.NxRequest[ nIndex ] = new XMLHttpRequest();
		}
	}
	
	this.AddRequest = function( objAjaxRequest )
	{
		var nIndex = this.nRequestCount;
		this.nRequestCount++;
		this.GetAjaxObject( nIndex );

		if( this.NxRequest[ nIndex ] )
		{
			this.NxRequest[ nIndex ].open( 'Post', objAjaxRequest.strURL + '?' + objAjaxRequest.GetQueryString(), true );
			this.NxRequest[ nIndex ].setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded; charset=ks_c_5601-1987' );
			this.NxRequest[ nIndex ].onreadystatechange = function() { objAjaxRequest.HandleReponse( nIndex ); } ;
			this.NxRequest[ nIndex ].send( objAjaxRequest.GetPostData() );
		}
	}
	
	
	this.AddAmlRequest = function( objAjaxRequest )
	{
		var nIndex = this.nRequestCount;
		this.nRequestCount++;
		this.GetAjaxObject( nIndex );

		if( this.NxRequest[ nIndex ] )
		{
			this.NxRequest[ nIndex ].open( 'Post', objAjaxRequest.strURL + '?' + objAjaxRequest.GetQueryString(), true );
			this.NxRequest[ nIndex ].setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded; charset=ks_c_5601-1987' );
			this.NxRequest[ nIndex ].onreadystatechange = function() { objAjaxRequest.HandleAmlReponse( nIndex ); } ;
			this.NxRequest[ nIndex ].send( objAjaxRequest.GetPostData() );
		}
	}
	
	this.RemoveRequest = function( nIndex )
	{
		this.NxRequest[ nIndex ] = null;
	}
}

function __NgbAjaxRequest( url )
{
	this.strURL = url;
	this.arrQueryString = new Array();
	this.arrPostData = new Array();
	this.Handler = null;
	
	this.HandleReponse = function( nIndex )
	{
		var xmlRequest =NgbAjax.NxRequest[ nIndex ];
		if( xmlRequest && xmlRequest.readyState == 4 && xmlRequest.status == 200 ) 
		{
			NgbAjax.RemoveRequest( nIndex );

			var responseText = xmlRequest.responseText;
			this.Handler( responseText );
		}
	}
	
	this.HandleAmlReponse = function( nIndex )
	{
		var xmlRequest =NgbAjax.NxRequest[ nIndex ];

		if( xmlRequest && xmlRequest.readyState == 4 && xmlRequest.status == 200 ) 
		{
			NgbAjax.RemoveRequest( nIndex );
                        try 
			{
			   var responseXML = xmlRequest.responseText;
			   var resultObject = NxamlParser.ParseXmlText( responseXML );
                        } 
			catch (e)
			{
				alert( '[XMLDoc Parse Error] ' + e.description );
			}
			this.Handler( responseXML, resultObject  );
		}
	}
	
	this.GetQueryString = function()
	{
		var strQueryString = '';
		if( this.strURL.indexOf( '?' ) != -1 )
			strQueryString = this.strURL.substr( this.strURL.indexOf( '?' ) );
			
		for( var i = 0 ; i < this.arrQueryString.length ; i++ )
		{
			if( strQueryString != '' )
				strQueryString += '&';
			
			strQueryString += this.arrQueryString[ i ].key + '=' +  this.arrQueryString[ i ].value;
		}
		
		return strQueryString;	
	}
	
	this.GetPostData = function()
	{
		var strPostData = '';

		for( var i = 0 ; i < this.arrPostData.length ; i++ )
		{
			if( strPostData != '' )
				strPostData += '&';
			
			strPostData += this.arrPostData[ i ].key + '=' +  this.arrPostData[ i ].value;
		}
		
		return strPostData;	
	}
	
	this.AddQueryString = function( key, value )
	{
		this.arrQueryString[ this.arrQueryString.length ] = { key:key, value:value };
	}
	
	this.AddPostData = function( key, value )
	{
		this.arrPostData[ this.arrPostData.length ] = { key:key, value:value };
	}
	
	this.AddHandler = function( handler )
	{
		this.Handler = handler;
	}
	
	this.Execute = function()
	{
		NgbAjax.AddRequest( this );
	}
	
	this.ExecuteAml = function()
	{
		NgbAjax.AddAmlRequest( this );
	}
}

var NgbUserEvent = new __NgbUserEvent();
function __NgbUserEvent()
{
	this.MousePositionX = function(evnt)
	{
		var LeftValue;
		if ( window.pageYOffset ) { LeftValue = window.pageXOffset; }
		else if ( document.documentElement && document.documentElement.scrollTop ) { LeftValue = document.documentElement.scrollLeft; }
		else if ( document.body ) { LeftValue = document.body.scrollLeft; }

		if(NgbBrowser.msie()) { return LeftValue + event.clientX; }
		else { return evnt.pageX; }
	};
	this.MousePositionY = function(evnt)
	{
		var TopValue;
		if ( window.pageYOffset ) { TopValue = window.pageYOffset;	}
		else if ( document.documentElement && document.documentElement.scrollTop ) { TopValue = document.documentElement.scrollTop; }
		else if ( document.body ) { TopValue = document.body.scrollTop; }

		if(NgbBrowser.msie()) { return TopValue + event.clientY; }
		else { return evnt.pageY;}
	};
	this.DetectKey = function( evnt )
	{
		if( NgbBrowser.msie() )
		{
			if( event.ctrlKey == true )
				return false;
			
			if ( event.keyCode == 27 )
				return false;
			
			if ( event.keyCode == 116 || ( event.ctrlKey && (event.keyCode == 78 || event.keyCode == 82) ) )
			{
        		event.keyCode= 1;
				return false;
			}
		}
		else
		{
			if( evnt.keyCode == 17 )	// ctrl key
				return false;
			
			if ( evnt.keyCode == 27 )
				return false;
			
			if ( evnt.keyCode == 116 || ( evnt.keyCode == 17 && ( evnt.keyCode == 78 || evnt.keyCode == 82 ) ) )
			{
        		evnt.keyCode = 1;
				return false;
			}
		}
	}
}

var NgbCache = new __NgbCache();
function __NgbCache() 
{
	//¹è¿­Á¤ÀÇ
	this.cacheObjArray = new Array();
	
	//Key Value(Cache array first value)Á¤ÇØÁÖ´Â ÇÔ¼ö
	this.cacheObjNaming = function() {
		var cacheObjName = "";
		for( var i = 0 ; i < arguments.length ; i++ )
		{
			if( i != 0 )
				cacheObjName += "_";
			cacheObjName += arguments [ i ];
		}
		return cacheObjName;
	}
	
	//Å° °ª¿¡ µû¶ó ±× Ç×¸ñÀÌ ¹è¿­¿¡ ÀÖ´ÂÁö °Ë»ç
	this.isCacheObj = function( tempObjNaming ) {
		if( this.cacheObjArray.length>0 )
		{
			for( var i = 0; i < this.ArrayCount; i++ )
			{
				if(this.cacheObjArray[i][0] == tempObjNaming )
				{
					isCacheObjArrayValue = this.cacheObjArray[i];
					return isCacheObjArrayValue;
				}
			}
		}
		else
		{
			return false;
		}
	}

	this.cacheObjInsert = function() {
		if(NgbCache.isCacheObj(arguments[0])) {
			if( this.cacheObjArray.length>0 )
			{
				for( var i = 0; i < this.ArrayCount; i++ )
				{
					if(this.cacheObjArray[i][0] == tempObjNaming )
					{
						for( var j = 0 ; j < arguments.length ; j++ )
						{
							this.cacheObjArray[i][j] = arguments[ j ];
						}
					}
				}
			}
			else
			{
				return false;
			}
		} else {
			this.cacheObjArray[this.ArrayCount] = new Array();
			for( var i = 0 ; i < arguments.length ; i++ )
			{
				this.cacheObjArray[this.ArrayCount][i] = arguments[ i ];
			}
			this.ArrayCount = this.cacheObjArray.length;
		}
	}
	
	this.cacheObjDel = function() {
		if(NgbCache.isCacheObj(arguments[0])) {
			if( this.cacheObjArray.length>0 )
			{
				for( var i = 0; i < this.ArrayCount; i++ )
				{
					if(this.cacheObjArray[i][0] == tempObjNaming )
					{
						isCacheObjArrayValue = this.cacheObjArray[i];
						this.cacheObjArray[i] = "";
					}
				}
			this.ArrayCount = this.cacheObjArray.length;
			}
			else
			{
				return false;
			}
		}
	}
	
	this.ArrayCount = 0;
}

var NgbSearchUtil = new function __NgbSearchUtil()
{
	this._MakeURL = function ( strSectionName, strSearchText )
	{
		if( this._IsValidSection( strSectionName ) == false )
		{
			strSectionName = 'total';
		}
			
		if( this._IsValidSearchText( strSearchText) == true)
		{
			var strURL = "http://search.nexon.com/search/page/nx.aspx?url=search/";
			strURL += strSectionName.toLowerCase();
			strURL += "&strSearchText=";
			strURL += escape(strSearchText);
			return strURL;
		}
		else
			return '';
	}

	this._IsValidSection = function ( strSectionName )
	{
		switch( strSectionName.toLowerCase() )
		{
			case 'total':
			case 'kplus':
			case 'gameweb':
			case 'gameweb_game':
			case 'channelfun':
			case 'guild':
			case 'guildweb':
			case 'image':
			case 'webzine':
				return true;
			default:
				return false;
		}
	}

	this._IsValidSearchText = function ( strSearchText )
	{
		if( strSearchText.length < 2 )
		{
			alert('°Ë»ö¾î¸¦ 2±ÛÀÚ ÀÌ»ó ÀÔ·ÂÇÏ¼¼¿ä');
			return false;
		}

		return true;
	}

	this.OnSearch = function( strSectionName, strSearchText , strTargetFrame, strWiseLog)
	{
		var strURL = this._MakeURL( strSectionName, strSearchText );
		if( strURL != '' )
		{
			if( strWiseLog != null && typeof(strWiseLog) != "undefined" && strWiseLog != '' )
			{
				strURL = strURL + strWiseLog;	
			}
			
			if( strTargetFrame != null && typeof(strTargetFrame) != "undefined" && strTargetFrame != '' )
			{
				try
				{
					eval( strTargetFrame.toLowerCase().replace(/_/g, "") ).location.href = strURL;
					return;
				}
				catch(err) { }
			}
			
			window.open( strURL );
		}
	}
}


var NgbBannerManager = new function __NgbBannerManager()
{
	this.AddBanner = function ( divID, ID, width, height, domain )
	{
		NgbEVM.AddCommand( NgbEVM.k_nEventType_onPageEnd, new NgbEVMDelegator( NgbBannerManager.WriteBanner ), divID, ID, width, height, domain );
	}
	
	this.WriteBanner = function()
	{
		var divID = arguments [ 1 ][ 0 ];
		var ID = arguments [ 1 ][ 1 ];
		var width = arguments [ 1 ][ 2 ];
		var height = arguments [ 1 ][ 3 ];
		var domain = arguments [ 1 ][ 4 ];
		
		new __NgbBanner( divID, ID, width, height, domain ).Write();
	}
}

function __NgbBanner( divID, ID, width, height, domain )
{
	this.divID = divID;
	this.ID = ID;
	this.width = width;
	this.height = height;
	this.domain = domain;
	
	this.Write = function()
	{
		//alert(  this.GetIframeString() );
		document.getElementById( this.divID ).innerHTML = this.GetIframeString();
	}

	this.GetIframeString = function()
	{
		return '<IFRAME id="' + this.divID + '_iframe" name="' + this.divID + '_iframe" tabindex=0 SRC="' + this.GetIframeSrc() + '" WIDTH=' + this.width + ' HEIGHT=' + this.height + ' NORESIZE SCROLLING="No" FRAMEBORDER="0" MARGINHEIGHT="0" MARGINWIDTH="0" allowTransparency="true"></IFRAME>';
	}
	
	this.GetIframeSrc = function()
	{
		var strIframeBaseURL = 'http://ad.nexon.com';
		if( document.location.href.toLowerCase().indexOf( "https://" ) == 0 ) 
		{
			strIframeBaseURL = 'https://ad.nexon.com';
		}
		
		if( this.ID == 'test' )
			return strIframeBaseURL + '/NetInsight/html/test/test/test@test';
		else if( this.ID == 'test2' )
			return strIframeBaseURL + '/NetInsight/html/test/test/test@ti';
		else if( this.domain != null && this.domain != '' )
			return strIframeBaseURL + '/NetInsight/html/nexon/' + this.domain + '/' + this.ID;
		else
			return strIframeBaseURL + '/NetInsight/html/nexon/www.nexon.com/' + this.ID;
	}
	
	this.AppendScript = function()
	{
		/*
		var script		= document.createElement( 'script' );
		
		script.src		= this.GetIframeString();
		script.type	= 'text/javascript';
		script.charset	= 'ks_c_5601-1987';
		
		document.getElementById( this.divID ).appendChild( script );
		*/
	}
}

var NgbGnbBanner = new function __NgbGnbBanner()
{
	this.strQueryString = '';
	this.Handler = null;
	
	this.GetBanner = function( n4CMSSN, n1PageSize, handler )
	{
		var strBannerPageURL = 'http://www.nexon.com/ajax/banner.aspx';
		if( document.location.href.toLowerCase().indexOf( "https://" ) == 0 )
			strBannerPageURL = 'https://www.nexon.com/ajax/banner.aspx';
			
		this.AddQueryString( 'n4CMSSN', n4CMSSN );
		this.AddQueryString( 'n1PageSize', n1PageSize );
		this.AddHandler( handler );
		this.AppendScript( strBannerPageURL + this.strQueryString );
	}
	
	this.AddQueryString = function( key, value )
	{
		if( this.strQueryString == '' )
		{
			this.strQueryString += '?' + key + '=' + value;
		}
		else
		{
			this.strQueryString += '&' + key + '=' + value;
		}
	}
	
	this.AddHandler = function( handler )
	{
		this.Handler = handler;
	}
	
	this.AppendScript = function( src )
	{
		var script		= document.createElement( 'script' );
		
		script.src		= src;
		script.type		= 'text/javascript';
		script.charset	= 'ks_c_5601-1987';
		
		document.getElementsByTagName( 'head' )[ 0 ].appendChild( script );
	}
	
	this.HandleResponse = function( responseXML )
	{
		var resultObject	= NxamlParser.ParseXmlText( responseXML );
		
		this.Handler( responseXML, resultObject );
	}
}

//±âÁ¸ÆÄÀÏ º¸Á¸
var NgbSearchBar = new function __NgbSearchBar() 
{
	this._MakeURL = function ( strSectionName, strSearchText )
	{
		if( this._IsValidSection( strSectionName ) == false )
		{
			strSectionName = 'total';
		}
			
		if( this._IsValidSearchText( strSearchText) == true)
		{
			var strURL = "http://search.nexon.com/search/page/nx.aspx?url=search/";
			strURL += strSectionName.toLowerCase();
			strURL += "&strSearchText=";
			strURL += escape(strSearchText);
			return strURL;
		}
		else
			return '';
	}

	this._IsValidSection = function ( strSectionName )
	{
		switch( strSectionName.toLowerCase() )
		{
			case 'total':
			case 'kplus':
			case 'gameweb':
			case 'gameweb_game':
			case 'channelfun':
			case 'guild':
			case 'guildweb':
			case 'image':
			case 'webzine':
				return true;
			default:
				return false;
		}
	}

	this._IsValidSearchText = function ( strSearchText )
	{
		if( strSearchText.length < 2 )
		{
			alert('°Ë»ö¾î¸¦ 2±ÛÀÚ ÀÌ»ó ÀÔ·ÂÇÏ¼¼¿ä');
			return false;
		}

		return true;
	}

	this.OnSearch = function( strSectionName, strSearchText , strTargetFrame, strWiseLog)
	{
		var strURL = this._MakeURL( strSectionName, strSearchText );
		if( strURL != '' )
		{
			if( strWiseLog != null && typeof(strWiseLog) != "undefined" && strWiseLog != '' )
			{
				strURL = strURL + strWiseLog;	
			}
			
			if( strTargetFrame != null && typeof(strTargetFrame) != "undefined" && strTargetFrame != '' )
			{
				try
				{
					eval( strTargetFrame.toLowerCase().replace(/_/g, "") ).location.href = strURL;
					return;
				}
				catch(err) { }
			}
			
			window.open( strURL );
		}
	}
}


var NptEventKeyCode = new function __NptEventKeyCode()
{
	this.CheckNumeric = function ( nkeyCode )
	{
		if ( ( nkeyCode >= 48 && nkeyCode <= 57 )		// ¼ýÀÚÅ°
			|| ( nkeyCode >= 96 && nkeyCode <= 105 )	// ¼ýÀÚÅ°ÆÐµå
			)
		{
			return true;
		}
		
		return false;
	}
	
	this.CheckAlphabet = function ( nkeyCode )
	{
		if ( nkeyCode >= 65 && nkeyCode <= 90 )
		{
			return true;
		}
		
		return false;
	}
	
	this.CheckSpecialCharacter = function ( nkeyCode )
	{
		if ( ( nkeyCode >= 186 && nkeyCode <= 192 )		// Æ¯¼ö¹®ÀÚ
			|| ( nkeyCode >= 219 && nkeyCode <= 222 )	// Æ¯¼ö¹®ÀÚ
			)
		{
			return true;
		}
		
		return false;
	}
	
}

var NgbDisplay = new function __NgbDisplay()
{
	this.ShowElement = function( objID )
	{
		if( document.getElementById( objID ) != null )
			document.getElementById( objID ).style.display = "block";
	}

	this.HideElement = function( objID )
	{
		if( document.getElementById( objID ) != null )
			document.getElementById( objID ).style.display = "none";
	}	
}
