﻿g_SITELOCAL = "local.";
g_QASecureSitePort = "44305"; 
g_QAMemberSitePort = "44300";
g_SITEMEMBER = "gametree.co.kr";

getServiceDomain();

function getServiceDomain()
{
    var url = document.domain;
    url = url.toLowerCase();

    var arr = url.split('.');

    if (arr.length > 0) {
        g_SITEMEMBER = arr[0] + '.gametree.co.kr';
    } 
}
/*	--------------------------------------------------------------------------------------------
	@ Ntreevsoft menu control
	플래쉬 컨텐츠 메뉴이동 컨트롤
-------------------------------------------------------------------------------------------- */

// url 정보를 담은 JSON 객체
urls = {
	// default page
	m000 :  getServiceSite(),   //현재서비스사이트
	// 새소식
	m100 : '/News/List.aspx?tn=1',	// 새소식 메인
	m101 : '/News/List.aspx?tn=1',	// 공지사항
	m102 : '/News/List.aspx?tn=3',	// 이벤트
	m103 : '/News/List.aspx?tn=2',	// 업데이트
	// 게임소개
	m201 : '/Gameinfo/information.aspx',	// 게임특징
	m202 : '/Gameinfo/world.aspx',			// 세계관
	// 게임가이드
	m301 : '/Gameguide/gamestart.aspx',	// 시작하기
	m302 : '/Gameguide/control.aspx',		// 조작법
	m303 : '/Gameguide/job.aspx',			// 직업
	m304 : '/Gameguide/map.aspx',			// 맵정보
	m305 : '/Gameguide/quest.aspx',		// 퀘스트
	m306 : '/Gameguide/skill.aspx',		// 스킬
	m307 : '/Gameguide/item.aspx',			// 아이템
	m308 : '/Gameguide/monster.aspx',	// 몬스터/NPC
	// 커뮤니티
	m401 : '/Community/free.aspx',		// 자유게시판
	m402 : '/Community/strategy.aspx',		// 공략게시판
	m403 : '/Community/qna.aspx',		// QNA 게시판
	m404 : '/Community/screenshot.aspx',	// 스크린샷
	m405 : '/Community/fansite.aspx',			// 팬페이지
	m410 : '/Community/developer.aspx',			// 개발자게시판
	//상점 500
	m501 : '/Shop/shop.aspx',			// 상점
	// 랭킹
	m601 : '/Ranking/scorerank.aspx',		// 랭킹
	m602 : '/Ranking/history.aspx',		// 명예의 전당
	// 자료실
	m701 : '/Download/download.aspx',	// 게임 다운로드
	m702 : '/Download/movie.aspx',			// 동영상
	m703 : '/Download/paper.aspx',			// 월페이퍼
	// 고객센터
	m801 : '/Support/faq.aspx',			// FAQ 보기
	m802 : '/Support/ask.aspx',		// 1:1 문의
	m803: 'javascript:MyInfo()',         //내정보
	m804 : '/Support/operation.aspx',	// 운영정책
	//로그인박스
	m901: 'javascript:MyHistory()',
	m902: 'javascript:RechargeTreeCash(1)',
	// 팝업창 예제
	m1001 : 'window.open("/popup/2313.html","_blank","width=500,height=300")'
}

// 메뉴이동 실행
function m(c) {
	var go_url = c ? 'urls["m'+c+'"]' : 'urls["m000"]';
	var _url = eval(go_url);
    if (/window\.open/.test(_url)) {
		eval(_url); // url 정보가 window.open(###) 이면 팝업창으로 실행
	} else if (_url)	{
		window.location.href = _url; // 일반적인 url 이면 페이지 이동
	} else {
		alert('현재 서비스 준비 중입니다.'); // 정보가 없으면 alert 메세지
	}
}

// 내정보 바로가기
function MyInfo() {
    Ns.Content.info();
}

// 충전및사용내역 바로가기
function MyHistory() {
    Ns.Content.cashinfo();
}

// 트리캐쉬 충전하기
function MyCharge(method) {
    Ns.TreeCash.recharge(method);
}

// 트리캐쉬 충전하기(팝업)
function RechargeTreeCash(method) {
   Ns.TreeCash.recharge(method);
}

//로그인
function Login() {
    Ns.Login.get();
}

function CheckEnterForLogin(e){
	var key = window.event ? e.keyCode : e.which;
	if(key == 13){
		Login();
	}
}

// 로그아웃
function Logout() {
    Ns.Login.out();
}

// 회원가입
function SignUp() {
    Ns.Content.join();
}

//아이디,패스워드찾기
function FindId() {
   Ns.Content.find();
}

//////////////////////////////////////////////////
// Footer
//////////////////////////////////////////////////
function popup(swc) {
    switch (swc){
        case "ntreev"  : window.open('http://www.ntreev.com'); break;
        case "policy"  : window.open('http://member.ntreev.com/policy/policy.aspx','ntreevpopup','width=589,height=554,statusbar=no,scrollbars=no,toolbar=no,resizable=no'); break;
        case "privacy" : window.open('http://member.ntreev.com/policy/privacy.aspx','ntreevpopup','width=589,height=554,statusbar=no,scrollbars=no,toolbar=no,resizable=no'); break;
        case "youth"   : window.open('http://member.ntreev.com/policy/youthhelp.aspx','ntreevpopup','width=589,height=554,statusbar=no,scrollbars=no,toolbar=no,resizable=no'); break;
        case "refusal" : window.open('http://member.ntreev.com/policy/refusal.aspx','ntreevpopup','width=459,height=254,statusbar=no,scrollbars=no,toolbar=no,resizable=no'); break;
    }
}

/////////////////
//URL Handle
/////////////////
String.prototype.trim = function()
{
  return this.replace(/(^\s*)|(\s*$)/gi, "");
}

String.prototype.replaceAll = function(str1, str2)
{
  var temp_str = "";

  if (this.trim() != "" && str1 != str2)
  {
	temp_str = this.trim();

	while (temp_str.indexOf(str1) > -1)
	{
	  temp_str = temp_str.replace(str1, str2);
	}
  }
  return temp_str;
}
////


//function getHTTPS(siteHost)
//{
//  return this.replace(/(^\s*)|(\s*$)/gi, "");
//}

function getHTTPS()
{
    var url = window.location;
    url = url.toString();
    
	var ret = "https://";
	if (typeof(g_SITELOCAL)=="string" && g_SITELOCAL != ""){
		var arr = g_SITELOCAL.split('|');
		for(var i=0; i < arr.length; i++){
			if ( url.indexOf( arr[i].trim() ) > -1 ){	
				ret = "http://";
				break;
			}
		}
	}

	return ret;
}

function getHTTPS(siteHost)
{
	var ret = "https://";
	if (typeof(g_SITELOCAL)=="string" && g_SITELOCAL != ""){
		var arr = g_SITELOCAL.split('|');
		for(var i=0; i < arr.length; i++){
			if ( siteHost.indexOf( arr[i].trim() ) > -1 ){	
				ret = "http://";
				break;
			}
		}
	}

	return ret;
}

function getSiteHost()
{
    var url = window.location;
    url = url.toString();
    
	var ret = "";
	var idx = url.indexOf("://");
	if (idx > -1){
		var idx2 = url.substring(idx+3, url.length).indexOf("/");
		if (idx2 > -1){
			ret = url.substring(idx+3, idx2 + (idx+3));
		}else{
			ret = url.substring(idx+3, url.length);
		}
		ret = ret.toLowerCase();
	}
	return ret;
	// (예)
	// 입력 : http://www.sinmadae.com/community/free.aspx
	// 출력 : www.sinmadae.com (소문자로 출력)
}

function getServiceSite()
{
	return ( "http://" + getSiteHost() );
	// (예)
	// 입력 : https://www.sinmadae.com/secure/info/updateinfo.aspx
	// 출력 : http://www.sinmadae.com 
}

function getSecureSite()
{

	return ( getHTTPS() + getSiteHost() + getSecureSitePort());  
	// (예1 - HTTPS For Service)
	// 입력 : http://www.sinmadae.com/notice/list.aspx
	// 출력 : https://www.sinmadae.com
	
	// (예2 - HTTP For Test : g_SITELOCAL에 정의)
	// 입력 : http://local.ob.sinmadae.com/notice/list.aspx
	// 출력 : http://local.ob.sinmadae.com
}

function getSecureSiteHTTP()
{
	return ( "http://" + getSiteHost() );
	
	// (예1 - HTTPS For Service)
	// 입력 : http://www.sinmadae.com/notice/list.aspx
	// 출력 : http://www.sinmadae.com
	
	// (예2 - HTTP For Test : g_SITELOCAL에 정의)
	// 입력 : http://local.ob.sinmadae.com/notice/list.aspx
	// 출력 : http://local.ob.sinmadae.com
}

function isQASite()
{
    return (getSiteHost().substring(0,3) == "qa.");
}

function getSecureSitePort()
{
    return ( (typeof(g_QASecureSitePort) != "undefined") && (g_QASecureSitePort != "") && isQASite() ) ? ":" + g_QASecureSitePort : "";
}

function getMemberSitePort()
{
    return ( (typeof(g_QAMemberSitePort) != "undefined") && (g_QAMemberSitePort != "") && isQASite() ) ? ":" + g_QAMemberSitePort : "";
}
//////////////////////////////////////////////////
// Neffy Download
//////////////////////////////////////////////////
function NeffyDownload() {
    var url = getServiceSite() + '/Download/Neffy/Neffy.aspx';
    window.open(url,'','width=418,height=789');
}

function SinmadaeDownload() {
    var url = getServiceSite() + '/Download/GSNeo/downloader.aspx';
	window.open(url,'','width=494,height=701');
}

// onload 이벤트 등록
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

function openNaverLinkPage() {
    var url = getServiceSite() + '/Events/NaverEvent.aspx';
    window.open(url, 'SinmadaeNaverLink');
}