﻿g_SITELOCAL = "local.";

//////////////////////////////////////////////////
// Menu Link
//////////////////////////////////////////////////
function m(n)
{    
    var url = '';
    url = getServiceSite();
    
    n = parseInt(n);
    
    switch(n)
    {
        case 0 : // Logo
            url += '/Default.aspx';
            break;
        case 2 : // Game Start
            //alert("11월 6일 오후 2시부터 가능합니다");
            //url += '/';
            StartGame();
            return;
            break;
        case 100 : //공룡백과
            url += '/Dictionary/List.aspx';
            break; 
        case 200 : //게임소개
            url += '/GameInfo/Guide.aspx';
            break; 
        case 300 : // 다운로드
            url += '/Download/Download.aspx';
            break;   
        case 400 : // 놀이터
            url += '/Community/List.aspx';
            break;          
        case 500 : //이벤트
            url += '/News/EventList.aspx?flag=1';
            break;           
        case 501 : //업데이트
            url += '/News/List.aspx?Type=2';
            break;
        case 502 : //공지사항
            url += '/News/List.aspx?Type=1';
            break;            
        case 600 : // 자주묻는 질문
            url += '/support/FAQ.aspx';
            break;
        case 601 : // 1:1문의
            url += '/support/ask.aspx';
            break;            
        case 602 : // 운영정책
            url += '/support/Operation.aspx';
            break;       
        default :
            url += '/';
            break;
    }
    
    if (url == '') {
        alert('개발중입니다');
    }
    else {
        document.location = url;
    }
    
    return false;
}


//////////////////////////////////////////////////
// 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)
{
	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(url)
{
	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.gongbak.com/community/free.aspx
	// 출력 : www.gongbak.com
}

function getServiceSite()
{
    var url = window.location;
    url = url.toString();
	return ( "http://" + getSiteHost(url) );
	// (예)
	// 입력 : https://www.dinomachia.co.kr/secure/info/updateinfo.aspx
	// 출력 : http://www.dinomachia.co.kr
}

function getSecureSite()
{
    var url = window.location;
    url = url.toString();
	return ( getHTTPS(url) + getSiteHost(url) );
	
	// (예1 - HTTPS For Service)
	// 입력 : http://www.dinomachia.co.kr/notice/list.aspx
	// 출력 : https://www.dinomachia.co.kr
	
	// (예2 - HTTP For Test : g_SITELOCAL에 정의)
	// 입력 : http://local.ob.dinomachia.co.kr/notice/list.aspx
	// 출력 : http://local.ob.dinomachia.co.kr
}
function getSecureSiteHTTP()
{
    var url = window.location;
    url = url.toString();
	return ( "http://" + getSiteHost(url) );
	
	// (예1 - HTTPS For Service)
	// 입력 : http://www.dinomachia.co.kr/notice/list.aspx
	// 출력 : http://www.dinomachia.co.kr
	
	// (예2 - HTTP For Test : g_SITELOCAL에 정의)
	// 입력 : http://local.ob.dinomachia.co.kr/notice/list.aspx
	// 출력 : http://local.ob.dinomachia.co.kr
}

//////////////////////////////////////////////////
// Login
//////////////////////////////////////////////////
function Login() {
    Ns.Login.get();
}

function Logout() {
    Ns.Login.out();
}

function LogoutReturn(r_url) {
	location.href = getSecureSite() + '/secure/login/processlogout.aspx?r_url='+ r_url;
}

function FindId() {
    Ns.Content.find(); 
}

function SignUp()
{
    Ns.Content.join();   
}

function MyInfo()
{
    Ns.Content.info();   
}

function CheckEnterForLogin(e){
	var key = window.event ? event.keyCode : e.which;
	if(key == 13){
		Login();
	}
}

function goRecharge(method) {
    Ns.TreeCash.recharge();
}

function __getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

onload = function() {
	var rememberId = __getCookie('remember_id');
	if (rememberId != null && rememberId != '') {
		document.getElementById('remember_id').checked = true;
		document.getElementById('login_id').value = rememberId;
	}
}

//////////////////////////////////////////////////
// Footer
//////////////////////////////////////////////////
function ShowWallet() {
    var url = getSecureSite() + '/secure/Common/AccountWallet.aspx';
    window.open(url,'','width=330,height=330');
}

function popup(swc) {
    switch (swc){
        case "ntreev": Ns.Content.company(); break;
        case "policy": Ns.Content.policy(); break;
        case "privacy": Ns.Content.privacy(); break;
        case "youth": Ns.Content.youth(); break;
        case "refusal": Ns.Content.refusal(); break;        
    }
}

function ShowRefundPolicy() {
    //var url = getSecureSiteHTTP() + '/Policy/RefundPolicy.aspx';
	//var url = "http://member.ntreev.com/policy/refund.aspx";
    //window.open(url,'ntreevpopup','width=589,height=554,statusbar=no,scrollbars=no,toolbar=no,resizable=no');
    Ns.Content.refund();
}
function DisplayRunningInfo() {
    var url = getServiceSite() + '/Common/Running/Play.aspx';
    document.location = url;
}
//////////////////////////////////////////////////
// Flash 관련
//////////////////////////////////////////////////
function FlashBanner(fid, fn, wd, ht, para, bannerImg, bannerLink)
{
	var flashval = 'bannerImg=' + bannerImg + '&bannerLink=' + bannerLink;

    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + wd + '" height="' + ht + '" id="' + fid + '" align="middle">');
	document.write('<param name="allowScriptAccess" value="Always">');
	document.write('<param name="movie" value="' + fn + para + '">');
	document.write('<param name="menu" value="false">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<param name="base" value=".">');
	document.write('<param name="FlashVars" value="' + flashval + '">');
	document.write('<embed base="." src="' + fn + para + '" menu="false" quality="high" wmode="transparent" width="' + wd + '" height="' + ht + '" name="' + fid + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" ');
	document.write(' FlashVars="' + flashval + '" />');
	document.write('</object>');
}

function NeffyDownload() {
    //alert("죄송합니다. 지금은 게임을 다운로드 받을 수 없습니다.");
    //return;
   
    var url = getServiceSite() + '/Download/Neffy/Neffy.aspx';
    window.open(url,'','width=418,height=789');
}

function SetInfoMessage(obj, gotFocus) {
    obj.className = (!gotFocus && obj.value.split(' ').join('') == '') ? 'showInfo' : '';
}

function popCoupon(){
    var sHeigth = window.screen.availHeight;
    var sWidth = window.screen.availWidth;

    var left = (sWidth - 350) / 2;
    var top =  (sHeigth - 260) / 2;    var url = '/Common/Coupon.aspx';
    var name = 'popCoupon';
    var features = 'width=350px,height=260px,scrollbars=no,status=no,menubar=no,toolbar=no,resizable=no,top=' + top + ',left = ' + left;

    var win_popEvent = window.open(url, name, features);	if(win_popEvent == null){
		alert("현재 팝업 차단이 설정되어 있습니다.\n\n팝업 차단을 해제하시면 새창이 열립니다.");
	}    }

/*
    description : 내 공룡방 팝업
    author      : 이세형
    date        : 2008-08-04
    comment     : 내 공룡방 팝업 변경 (파라미터 추가 : CharacterID)
    parameter   :  CharacterID (캐릭터ID) 
*/
function popMyDino(characterID) {
    var url = "/MyDino/Main.aspx?CharacterID=" + characterID;
	var winObj = window.open(url,'ntreevpopup','width=750,height=675,statusbar=no,scrollbars=no,toolbar=no,resizable=no');
	
	if (winObj) winObj.focus();
    return false;
} 

// onload 이벤트 등록
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
        end = dc.length;

    return unescape(dc.substring(begin + prefix.length, end));
}
