﻿String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, '');
}

function OnFailed(error, userContext, methodName) {
    var log = '';
    var stackTrace = error.get_stackTrace();
    var message = error.get_message();
    var statusCode = error.get_statusCode();
    var exceptionType = error.get_exceptionType();
    var timedout = error.get_timedOut();

    log = message + "\r\n" + stackTrace + "\r\n" + statusCode + "\r\n" + exceptionType + "\r\n" + timedout;

    if (userContext != null) {
        log += "\r\n USERCONTEXT : " + userContext;
    }

    if (methodName != null) {
        log += "\r\n METHOD : " + methodName;
    }

    alert(log);
}

function confirmDel() {
    if (confirm('정말로 삭제 하시겠습니까?')) {
        return true;
    }
    else {
        return false;
    }
}

function download(path, or_name) {
    window.open('/web.admin/Common/download.ashx?path=' + path + '&on=' + or_name, 'download', 'scrollbars=0,width=200,height=100, top=10, left=10');
}

//3자리마다 컴마
function commify(n) {
    var reg = /(^[+-]?\d+)(\d{3})/;
    n += '';

    while (reg.test(n))
        n = n.replace(reg, '$1' + ',' + '$2');
    return n;
}

function popup(url, name, width, height) {
    var theURL = url;
    var winName = name
    var sizex = width;
    var sizey = height;
    var top = "";
    var left = "";
    var features = ", scrollbars=no";

    var atop, aleft;
    if (top == '') { atop = Math.floor((screen.availHeight - (sizey + 30)) / 2); } else { atop = top; }
    if (left == '') { aleft = Math.floor((screen.availWidth - (sizex + 12)) / 2); } else { aleft = left; }
    window.open(theURL, winName, "width=" + sizex + ", height=" + sizey + ", top=" + atop + ",left=" + aleft + features);
}



///////////////////////////////////////팝업관련 함수들
function onloadpop() {

 
    if (getCookie("20120202p") != "done") {
        Eventpopup('5', '');
    }  
       

    //if (getCookie("20120102p") != "done") {
    //    Eventpopup('7', '');
   // }
    
    //if (getCookie("20120127p") != "done") {
    //    Eventpopup('9', '');
    //}

    
    
}

function closeWin(index) {
    switch (index) {
        case 1:
            // 스키 메인 이용시간 변경 안내
            setCookie("20110119p", "done", 1);
            break;
        case 2:
        //스키메인 야간프로모션
         setCookie("20111223p", "done", 1);
            break;
        case 3:
        // 스노우도시 이용안내
            setCookie("20110428p", "done", 1);
            break;
        case 4:
       
            break;
        case 5:
          // 스페셜 이벤트
         setCookie("20120202p", "done", 1);
            break;
        case 6:
          // 골프메인팝업
          setCookie("20111130p", "done", 1);
            break;
        case 7:
          // 스노우 쏜다 이벤트 
             setCookie("20120102p", "done", 1);
            break;
        case 8:
            //골프 매인팝업 
            setCookie("20110712p", "done", 1);
            break;
        case 9:
             // 휴가지 선택 이벤트 
             setCookie("20120127p", "done", 1);
            break;
            //
            case 10:
             // 매장안내 이벤트 
             setCookie("20120120p", "done", 1);
            break;
            //
            
        default:
            break;
    }
    
}


function OpenLayer(objname, filepath, pwidth, pheight) {
    var obj = eval("document.getElementById('" + objname + "')");
   
    obj.href = filepath;
    hs.marginTop = 460;

    obj.onfocus = function() {
        return hs.htmlExpand(this, { objectType: 'iframe', width: pwidth, height: pheight, preserveContent: false });

    }
    obj.focus();
}

//    function OpenLayer2(objname, filepath, pwidth, pheight) {
//        var obj = eval("document.getElementById('" + objname + "')");
//        obj.href = filepath;
//        hs2.marginTop = 30;

//        obj.onfocus = function() {
//            return hs2.htmlExpand(this, { objectType: 'iframe', width: pwidth, height: pheight, preserveContent: false });

//        }
//        obj.focus();
//    }


function goMainNews() {
    location.href = "/Service/Notice_list.aspx";
}

function introMovie() {
    location.href = "/Play/Movies.aspx";
}

function poplayer(type, code) {
    if (type == "open") {
        OpenLayer('GlobalLayerArea', '/popup/20100726/popup0726.html', '1010', '200');
    }
    else {
        switch (code) {
            case "1":
                // 스키강습 변경안내
                location.href = "";
                break;
            case "2":
            
                break;
            case "3":
               //  핫 섬머 산타 공연
                location.href = "http://www.playdoci.com/Service/Event_view.aspx?ai=16993";
                break;
            case "4":
                
                break;
            case "5":
                //스페셜이벤트
                location.href ="http://www.playdoci.com/Service/Event_view.aspx?ai=27312"; 
                break;
            case "6":
               // 골프메인팝업
                location.href = "http://www.playdoci.com/Service/Event_view.aspx?ai=24912";
                break;
            case "7":
              // 윈터스노우파티
                location.href = "http://www.playdoci.com/Service/Event_view.aspx?ai=26712";
                break;
            case "8":
                // 골프서브메인 팝업
                location.href = " http://www.playdoci.com/Golf/Infomation.aspx";
                break;
             case "9":
                // 휴가지 선택 이벤트
                location.href = "http://www.playdoci.com/Service/Event_view.aspx?ai=27072";
                break;
                
             case "10":
                 //매장안내   
                break;
               

        }
    }
}

function Eventpopup(type, code) {

    var left = (screen.availWidth - (screen.availWidth - 50));

    var top = (screen.availHeight - (screen.availHeight - 50));

    //특정시간 팝업내리기
   
    var to_day = new Date();
   
        
    switch (type) {
        case "1":
            // 스키 이용시간 변경안내
            window.open("/popup/2011/20110119/popup0119.html", "pop1", "scrollbars=no,toolbar=no,directories=no,menubar=no,status=no,top=" + top + ",left=" + left + ",width=330,height=414");
            break;
        case "2":
          // 스키 메인 팝ㅇㅓㅂ
            // var limit_end = new Date(2011, 10, 30, 18, 0, 0);
             //if (to_day.getTime() <= limit_end.getTime()) 
             //{
                left += 340;
                window.open("/popup/2011/20111223/popup1223.html", "pop21", "scrollbars=no,toolbar=no,directories=no,menubar=no,status=no,top=" + top + ",left=" + left + ",width=330,height=414");
             //}
            break;
        case "3":
        //스노우도시 이용안내
             
            var limit_end = new Date(2011, 4, 2, 0, 0, 0);
            
            if (to_day.getTime() <= limit_end.getTime()) {
                
            left += 340;
            window.open("/popup/2011/20110428/popup0428.html", "popf", "scrollbars=no,toolbar=no,directories=no,menubar=no,status=no,top=" + top + ",left=" + left + ",width=330,height=414");
           }
            
            break;
        case "4":
            //월은 index가 0부터 1월  (년,월,일,시,분,초)
            //var limit_start = new Date(2011, 1, 23, 10, 0, 0);
            //var limit_end = new Date(2010, 9, 13, 23, 0, 0);
            
            //if (to_day.getTime() >= limit_start.getTime()) {
                //온라인예매 이용안내
                //left += 680;
             //   window.open("/popup/2011/20110222/popup0222.html", "popCheck", "scrollbars=no,toolbar=no,directories=no,menubar=no,status=no,top=" + top + ",left=" + left + ",width=330,height=414");
             //}
            //left += 700;
             window.open("/popup/2012/20120110/popup0110.html", "popCheck", "scrollbars=no,toolbar=no,directories=no,menubar=no,status=no,top=" + top + ",left=" + left + ",width=500,height=317");
            break;
        case "5":
        //연간이용권
            // var limit_end = new Date(2012, 0, 30, 9, 0, 0);
            // if (to_day.getTime() <= limit_end.getTime()) {
            //left += 340;
            window.open("/popup/2012/20120202/popup0202.html", "popcm", "scrollbars=no,toolbar=no,directories=no,menubar=no,status=no,top=" + top + ",left=" + left + ",width=350,height=414");
            // }
            break;
        case "6":
            window.open("/popup/2011/20111130/popup1130.html", "pope", "scrollbars=no,toolbar=no,directories=no,menubar=no,status=no,top=" + top + ",left=" + left + ",width=350,height=414");
            break;
        case "7":
           // 2012 쏜다
            //left += 360;
            // var limit_end = new Date(2012, 0, 30, 9, 0, 0);
            // if (to_day.getTime() <= limit_end.getTime()) {
             
            window.open("/popup/2012/20120102/popup0102.html", "popw", "scrollbars=no,toolbar=no,directories=no,menubar=no,status=no,top=" + top + ",left=" + left + ",width=330,height=414");
            //}
            break;
        case "8":
            left += 360;
            // 골프서브메인 팝업
            window.open("/popup/2011/20110712/popup0712.html", "popg", "scrollbars=no,toolbar=no,directories=no,menubar=no,status=no,top=" + top + ",left=" + left + ",width=330,height=414");
            break;
        case "9":
        //새해 팝업
          
            window.open("/popup/2012/20120127/popup0127.html", "popg", "scrollbars=no,toolbar=no,directories=no,menubar=no,status=no,top=" + top + ",left=" + left + ",width=330,height=414");
            break;
       
        case "10":
        //매장안내
          //left -= 20;
            window.open("/popup/2012/20120120/popup0120.html", "popg", "scrollbars=no,toolbar=no,directories=no,menubar=no,status=no,top=" + top + ",left=" + left + ",width=350,height=414");
            break;

    }

}






function setCookie(name, value, expiredays) {
    var today = new Date();
    today.setDate(today.getDate() + expiredays);

    today.setHours(0);
    // 날짜를 설정하기 위해 setDate메소드를 사용하여 getDate의 "일"에 종료일 하루 "1" 을 더합니다.

    document.cookie = name + '=' + escape(value) + '; path=/; expires=' + today.toGMTString() + ';'
    //쿠키를 저장시 이름과 값을 쌍을 이루고 그리고 쿠키를 사용한 문서의 위치를 정하고 종료일은 GMT 시간으로 합니다

}

function getCookie(name) {
    var nameOfCookie = name + "=";
    var x = 0;
    while (x <= document.cookie.length) {
        var y = (x + nameOfCookie.length);
        if (document.cookie.substring(x, y) == nameOfCookie) {
            if ((endOfCookie = document.cookie.indexOf(";", y)) == -1)
                endOfCookie = document.cookie.length;
            return unescape(document.cookie.substring(y, endOfCookie));
        }
        x = document.cookie.indexOf(" ", x) + 1;
        if (x == 0) break;
    }
    return "";
}

///////////////////////////////////////팝업관련 함수들




function getWeb(strURL, strParam) {

    var objXMLHttp = getXMLHttpObject();
    var strText = "";
    var strMethod = strParam.length > 0 ? "POST" : "GET";
    if (objXMLHttp) {
        objXMLHttp.open(strMethod, strURL, false);
        objXMLHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        objXMLHttp.setRequestHeader("Content-length", strParam.length);
        //objXMLHttp.setRequestHeader("Connection", "close");
        objXMLHttp.send(strParam);
        strText = objXMLHttp.responseText;
    }

    return strText;
}

function getXMLHttpObject() {
    var obj = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    return obj;

}
