﻿/**** Ajax 관련 함수 시작 ****/
var ajax = {};
ajax.xhr = {};

ajax.xhr.Request = function(url, params, callback, method, seq) {
    this.url = url;
    this.params = params;
    this.callback = callback;
    this.method = method;
    this.send();
    this.seq = seq
}
ajax.xhr.Request.prototype = {
    getXMLHttpRequest: function() {
        if (window.ActiveXObject) {
            try {
                return new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    return new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e1) { return null; }
            }
        } else if (window.XMLHttpRequest) {
            return new XMLHttpRequest();
        } else {
            return null;
        }
    },
    send: function() {
        this.req = this.getXMLHttpRequest();

        var httpMethod = this.method ? this.method : 'GET';
        if (httpMethod != 'GET' && httpMethod != 'POST') {
            httpMethod = 'GET';            
        }
        var httpParams = (this.params == null || this.params == '') ?
		                 "TimeStamp=" + new Date().getTime() : this.params + "&TimeStamp=" + new Date().getTime();

        var httpUrl = this.url;
        if (httpMethod == 'GET' && httpParams != null) {
            httpUrl = httpUrl + "?" + httpParams;
        }
        this.req.open(httpMethod, httpUrl, true);
        this.req.setRequestHeader(
			'Content-Type', 'application/x-www-form-urlencoded');
        var request = this;
        this.req.onreadystatechange = function() {
            request.onStateChange.call(request);
        }
        this.req.send(httpMethod == 'POST' ? httpParams : null);

    },
    onStateChange: function() {
        this.callback(this.req, this.seq);
    }
}
/**** Ajax 관련 함수 끝 ****/

/**** 문자열 공백 제거 ****/
String.prototype.trim = function() {
       return this.replace(/^\s+|\s+$/g,"");   
}

/**** 비로그인 & 로그인 박스 포커싱 ****/
function IsNotLoginBoard() {
    alert('로그인을 하셔야 게시물을 작성할 수 있습니다.');
    document.getElementById("txtUserID").focus();
}

function IsNotLoginComment() {
    alert('꼬릿글 작성을 위해 먼저 로그인을 해 주세요.');
    document.getElementById("txtUserID").focus();
}

/**** 한글 바이트 체크 하기 ****/
function fnByteLength(str){
    return str.replace(/[^\x00-\x7F]/g,"xx").replace(/([<\x0D])/g,function($0,$1){ return ($1 == "<")?"&lt;":"<br>"+$1;}).length;
}

String.prototype.bytes = function() {
    var str = this;
    var s = 0;
    for (var i = 0; i < str.length; i++) s += (str.charCodeAt(i) > 128) ? 2 : 1;
    return s;
}

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 SetCookie( name, value, expiredays )
{
	var todayDate = new Date();
	todayDate.setHours( todayDate.getHours() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

// 쿠키 불러오기
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));
}


/**** 메뉴 링크 ****/
function flash_link(link_value)
{
	switch( link_value.toString() )
	{
	    case "10": location.href = "/Main/HomeMain.aspx";           // 홈
	        break;
	    case "50": RunGameStart();                                        // 게임시작버튼
	        break;
	    case "60": location.href = "/Download/Download.aspx";      // 게임 다운로드
	        break;
	    case "70": location.href = "/Guide/Default.aspx";               // 게임 가이드
            break;

        case "100":
        case "110": location.href = "/News/NewsList.aspx";                      // 새소식
            break;
        case "120": location.href = "/News/NewsList.aspx?noticetype=1";     // 공지사항
            break;
        case "130": location.href = "/News/NewsList.aspx?noticetype=2";     // 업데이트
            break;
        case "140": location.href = "/News/NewsList.aspx?noticetype=4";     // 점검
            break;
        case "150": location.href = "/News/Event/EventList.aspx";               // 이벤트
            break;

        case "200":
        case "210":
            location.href = "/Ranking/RankingMemberStyle.aspx";                     // 개인 랭킹
            break;
        case "220":
            alert("현재 열심히 작업중입니다. 곧 찾아뵙겠습니다.");               // 클랜 랭킹
            break;

        case "300":
        case "310":
            location.href = "/Clan/Default.aspx";                                     // 클랜 메인
            break;
        case "320":
            alert("현재 열심히 작업중입니다. 곧 찾아뵙겠습니다.");
            //location.href = "/Clan/ClanBattle/ClanBattleList.aspx";                 // 클랜전 상황실
            break;
        case "330":
            location.href = "/Clan/ClanBoard/ClanBoardList.aspx";                 // 클랜 게시판
            break;
        case "340":
            location.href = "/Clan/ClanSearch.aspx";                                 // 클랜 검색
            break;
        case "350":
            location.href = "/Clan/MakeClan/MakeClan.aspx";                     // 클랜 개설
            break;            

        case "400":
        case "410": location.href = "/Community/FreeBoard/FreeBoardList.aspx";          // 자유게시판 
            break;
        case "420": location.href = "/Community/MediaBoard/MediaBoardList.aspx";     // 미디어 보드
            break;
        case "430": location.href = "/Community/Strategy/StrategyBoardList.aspx";        // 공략게시판
            break;
        case "440": location.href = "/KinBoard/Default.aspx";                                 // 지식가이드
            break;
        case "450": location.href = "/Community/GMBoard/GMBoardList.aspx";            // GM통신소
            break;
        case "460": location.href = "/Community/Poll/PollList.aspx";                          // 설문조사
            break;	   


        case "500": location.href = "/Guide/Default.aspx";                                                                     // 가이드 메인
            break;
        case "510": window.open("/NewbieGuide/GuideMain.aspx", 'nguide', 'width=900,height=650');          // 초보자 가이드
            break;
        case "520": window.open("/Guide/Feature/GuideSynopsis.aspx", "feature", "width=900,height=650");    // 게임특징
            break;
        case "530": window.open("/Guide/Interface/GameStart.aspx", "feature", "width=900,height=650");           // 인터페이스
            break;
        case "540": window.open("/Guide/GameMode/Challenge.aspx", "feature", "width=900,height=650");          // 게임모드
            break;
        case "550": window.open("/Guide/Mission/GuideExplode.aspx", "feature", "width=900,height=650");           // 임무타입
            break;
        case "560": window.open("/Guide/Control/GuideControl.aspx?ttype=1", "feature", "width=900,height=650");           // 조작방법
            break;            

        case "600": location.href = "/Download/Download.aspx";       // 다운로드
            break;
        case "610": location.href = "/Download/Download.aspx";       // 다운로드
            break;
        case "620": location.href = "/Download/Media.aspx";            // 동영상
            break;
        case "630": location.href = "/Download/Wallpaper.aspx";       // 월페이퍼
            break;	
        
        case "700"	:
        case "710": location.href = "/Support/Faq/FaqList.aspx";        // FAQ
            break;
        case "720": location.href = "/Support/Inquiry/InquiryWrite.aspx";    // 1:1문의
            break;
        case "730": location.href = "/Support/Inquiry/InquiryWrite.aspx?section=bug"; // 버그신고 / 건의
            break;
        case "740": location.href = "/Support/Policy/Policy.aspx";           // 운영정책
            break;

        case "1010": window.open("/Guide/Feature/GuideCharacter.aspx?clan=2&branch=1", "feature", "width=900,height=650");
            break;
        case "1020": window.open("/Guide/Feature/GuideCharacter.aspx?clan=2&branch=2", "feature", "width=900,height=650");
            break;
        case "1030": window.open("/Guide/Feature/GuideCharacter.aspx?clan=2&branch=3", "feature", "width=900,height=650");
            break;
        case "1040": window.open("/Guide/Feature/GuideCharacter.aspx?clan=2&branch=4", "feature", "width=900,height=650");
            break;
        case "1050": window.open("/Guide/Feature/GuideCharacter.aspx?clan=2&branch=5", "feature", "width=900,height=650");
            break;
        case "1060": window.open("/Guide/Feature/GuideCharacter.aspx?clan=1&branch=1", "feature", "width=900,height=650");
            break;
        case "1070": window.open("/Guide/Feature/GuideCharacter.aspx?clan=1&branch=2", "feature", "width=900,height=650");
            break;
        case "1080": window.open("/Guide/Feature/GuideCharacter.aspx?clan=1&branch=3", "feature", "width=900,height=650");
            break;
        case "1090": window.open("/Guide/Feature/GuideCharacter.aspx?clan=1&branch=4", "feature", "width=900,height=650");
            break;
        case "1100": window.open("/Guide/Feature/GuideCharacter.aspx?clan=1&branch=5", "feature", "width=900,height=650");
            break;                                                                                                                       
				    					
		default : alert(link_value);		
	}
}

function RunGameStart() {
    var isLogin = GetCookie("DAUTH");
    var isTester = GetCookie("isTester");
    var isPCB = GetCookie("isPCB");
    if (isLogin == "" || isLogin == null) {
        alert('로그인 후 이용 가능합니다.');
        document.getElementById("txtUserID").focus();
        return false;
    }
    else 
    {    
        var Installed = false;
        try {
            var xObj = new ActiveXObject("DragonflyControl.DragonflyCtrl.1");
            if (xObj)
                Installed = true;
        }
        catch (ex) {
        }

        if (Installed) { // 설치된경우
            try {
                frames['ifrmGame'].location.href = "/Main/GameOn/GameStart.aspx";
            }
            catch (ex) {
            }
        }
        else {
            top.location.href = "/Main/GameOn/ActiveXGuide.aspx";
        }
    }
}