﻿var currentDepth = 0;

var GSR = "http://www.gsretail.com";
var GSS = "http://gssuper.gsretail.com";
var GS25 = "http://gs25.gsretail.com";
var MISTER = "http://misterdonut.gsretail.com";

var $Retail = {

    download: function(link) {
        // download handler 로 연결				
        location.href = "/common/handler/downloadHandler.ashx?path=" + link;
    },
    /********************************************************************************************************
    팝업창 오픈
    ********************************************************************************************************/
    openPopup: function(url) {
        var positionX = 0;
        var positionY = 0;
        window.open(url, "", "left=" + positionX + ",top=" + positionY + ",width=500,height=400,toolbar=no,scrollbars=no");
    },
    openPopup: function(url, width, height) {
        var positionX = 0;
        var positionY = 0;
        window.open(url, "", "left=" + positionX + ",top=" + positionY + ",width=" + width + ",height=" + height + ",toolbar=no,scrollbars=no");
    },
    openPopup: function(url, width, height, scrollbars) {
        var positionX = 0;
        var positionY = 0;
        window.open(url, "", "left=" + positionX + ",top=" + positionY + ",width=" + width + ",height=" + height + ",toolbar=no,scrollbars=" + scrollbars);
    },
    /****** 팝업창 리사이즈 **************************************************************/
    resizePopup: function() {
        var thisX = document.getElementById("offsetTable").offsetWidth;
        var thisY = document.getElementById("offsetTable").offsetHeight;
        var maxThisX = screen.width - 50;
        var maxThisY = screen.height - 80;
        if (window.navigator.userAgent.indexOf("SV1") != -1) {
            var marginY = 50; //마지막 수는 상황에따라 알맞게 넣으세요. (템플릿의 헤더높이 + 풋터 높이 + 알파)
        } else {
            var marginY = 29; //마지막 수는 상황에따라 알맞게 넣으세요. (템플릿의 헤더높이 + 풋터 높이 + 알파)
        }

        if (thisX > maxThisX) {
            window.document.body.scroll = "yes";
            thisX = maxThisX;
        }
        if (thisY > maxThisY - marginY) {
            window.document.body.scroll = "yes";
            thisX += 19;
            thisY = maxThisY - marginY;
        }

        var windowX = (screen.width - (thisX + 10)) / 2;
        var windowY = (screen.height - (thisY + marginY)) / 2 - 20;
        //	window.moveTo(windowX,windowY);
        window.resizeTo(thisX + 10, thisY + marginY + 40);
    },

    // keys = [] 
    moveFocus: function(controlId, keys) {
        if (!keys) {
            if (event.keyCode == 13) {
                $n(controlId).focus();
                return false;
            }
        } else {
            keys.each(function(key) {
                if (event.keyCode == 13) {
                    $n(controlId).focus();
                    return false;
                }
            })
        }
    },

    // disable fckeditor 
    disableEditor: function(editorInstance) {
        editorInstance.ToolbarSet.Disable();
        editorInstance.EditorDocument.body.disabled = true;
        editorInstance.EditorWindow.parent.document.getElementById("xExpanded").style.display = "none";
    }
     

}

// 로그인
function goLogin(arg) {
    if (arg == null || arg == "undignified") {
        location.replace("/Member/Login/Login.aspx?returnUrl=" + location.href);
    } else {
        location.replace("/Member/Login/Login.aspx?returnUrl=" + arg);
    }
}


// 트위터, 페이스북, plus 공유하기
function doSNS(btn) {

   var option = "toolbar=yes,directories=yes,status=yes,menubar=yes,resizable=yes,scrollbars=yes";
   if (btn == "tweet") 
   {
                window.open('http://twitter.com/home?status=GS Retail' + location.href, 'sharer', option)
   } else if (btn == "face") {
                window.open('http://www.facebook.com/share.php?u=' + location.href, 'sharer', option + ',width=626,height=436');
   }

/*
    var longUrl = escape("http://lyricsbird.net/");
    var reurl = "";
    var option = "toolbar=yes,directories=yes,status=yes,menubar=yes,resizable=yes,scrollbars=yes";
    var shortener = "http://udanax.org/";
    $.ajax({
        type: 'GET',
        url: shortener + "shorturl.jsp?mode=api&longurl=" + location.href + "&jsoncallback=?",
        dataType: 'json',
        timeout: 6000,
        success: function(data, status) {
            reurl = shortener + data.shorturl;
            if (btn == "tweet") {
                window.open('http://twitter.com/home?status=' + reurl, 'sharer', option)
            } else if (btn == "face") {
                window.open('http://www.facebook.com/share.php?u=' + reurl, 'sharer', option + ',width=626,height=436');
            }
        },
        error: function(request, status, error) {
            alert("Error status : " + status);
        }
    });
*/
}


function checkNumber(val) {
    var filter = /^\d+$/;
    if (filter.test(val))
        return true;
    else
        return false;
}


// 아이디 찾기 팝업
function idSearch() {
    modal("/Member/Id/find.aspx", 360, 400, 0.4);
}

// 비밀번호 찾기 팝업
function pwSearch() {
    modal("/Member/Password/find.aspx", 360, 470, 0.4);
}


function getParameter(name) {
    var rtnval = '';
    var nowAddress = unescape(location.href);
    var parameters = (nowAddress.slice(nowAddress.indexOf('?') + 1, nowAddress.length)).split('&');

    for (var i = 0; i < parameters.length; i++) {
        var varName = parameters[i].split('=')[0];
        if (varName.toUpperCase() == name.toUpperCase()) {
            rtnval = parameters[i].split('=')[1];
            break;
        }
    }
    return rtnval;
}


/*
사용법 : $.cookie(키, 값, 옵션);
옵션은 {expires:'',domain:'', path:'', secure:''}
예 : $.cookie('key', 'ok', {expires:7,domain:'.myhost.com', path:'/', secure:0});
expires는 日단위..
뽑아오기 : alert($.cookie('happy_new_expire'));
*/
(function($) {
    $.cookie = function(key, value, options) {
        if (arguments.length > 1) {
            var o = $.extend({}, $.cookie.defaults, options);
            if (value === null || value === undefined) {
                value = '';
                o.expires = -1;
            }
            if (o.expires.constructor != Date) {
                var today = new Date();
                today.setDate(today.getDate() + o.expires);
                o.expires = today;
            }
            // Create the cookie string
            document.cookie =
    key + '=' + value +
    '; expires=' + o.expires.toUTCString() +
    (o.path ? '; path=' + (o.path) : '') +
    (o.domain ? '; domain=' + (o.domain) : '') +
    (o.secure ? '; secure' : '');
        } else {
            if (result = new RegExp(key + "=(.*?)(?:;|$)").exec(document.cookie))
                return decodeURIComponent(result[1]);
            return false;
        }
    };
    $.cookie.defaults = {
        expires: 365,
        path: '/'
    }
})(jQuery);


// GNB 레이어
function menu_open(str) {
    if (str=="true") {
        //alert('aa');
        document.getElementById("SWF_gnb_retail").style.height = "244px";
    } else {
        document.getElementById("SWF_gnb_retail").style.height = "64px";
    }
}

//나눔기부하기
function donation(args) {
    var point, n_type;
    point = args[0];
    n_type = args[1];
    
    $.cookie('nanum_point', point, { expires: 1, domain: '.gsretail.com', path: '/', secure: 0 });
    modal('/contribution/share/l-charity1.aspx?point=' + point + '&n_type=' + n_type, '360', '330', '0.4');
}


function popRegist() {
    modal("/member/card/card_membership.aspx?returnUrl=" + location.href, 500, 580, 0.4);
}

// 멤버십카드
function popRegist2() {
    modal("/member/card/card.aspx", 500, 550, 0.4);
}

// 나라사랑카드
function popRegist3() {
    modal("/member/card/love.aspx", 500, 631, 0.4);
}

// 학생증체크카드
function popRegist4() {
    // 아직 미오픈이라서 임시로 주석
    modal("/member/card/check.aspx", 500, 600, 0.4);
    //modal("/member/card/check_com.aspx", 360, 225, 0.4);
}

function popLogin() {
    modal("/member/card/card-nologin.aspx", 360, 230, 0.4);
}

function popIpin() {
    modal("/member/card/card-ipin.aspx", 360, 300, 0.4);
}

function popMembership() {
    modal("/member/join/join-total.aspx", 360, 225, 0.4);
}

function openIDSearch() {
    modal("/Member/ID/find.aspx", 360, 400, 0.4);
}

function openPwSearch() {
    modal("/Member/Password/find.aspx", 360, 470, 0.4);
}
// 멤버십카드
function popLayer(ptype, msg) {
    modal("/member/card/card-complete.aspx?pType=" + ptype + "&msg=" + escape(msg), 500, 500, 0.4);
}
// 나라사랑카드
function popLayer1(ptype, msg) {
    modal("/member/card/love-complete.aspx?pType=" + ptype + "&msg=" + escape(msg), 500, 408, 0.4);
}
// 학생증체크카드
function popLayer2(ptype, msg) {
    modal("/member/card/check-complete.aspx?pType=" + ptype + "&msg=" + escape(msg), 500, 458, 0.4);
}

// 회원가입팝업
function goRegistMember() {
    parent.location.href = "/Member/Join/Join.aspx";
}
