﻿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(GSR + "/Member/Login/Login.aspx?returnUrl=" + location.href);
    } else {
        location.replace(GSR + "/Member/Login/Login.aspx?returnUrl=" + MISTER + 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;
}



// GNB 레이어
function menu_open(str) {
    if (str == "true") {
        //alert('aa');
        document.getElementById("SWF_gnb_donut").style.height = "244px";
    } else {
        document.getElementById("SWF_gnb_donut").style.height = "74px";
    }
}


function popRegist(retailDomain) {
    modal(GSR + +"/member/card/card_membership.aspx?returnUrl=" + location.href, 500, 580, 0.4);
}

function popRegist() {
    modal(GSR + "/member/card/card_membership.aspx?returnUrl=" + location.href, 500, 580, 0.4);
}

// 멤버십카드
function popRegist2() {
    modal(GSR + "/member/card/card.aspx", 500, 518, 0.4);
}

// 나라사랑카드
function popRegist3() {
    modal(GSR + "/member/card/love.aspx", 500, 631, 0.4);
}

// 학생증체크카드
function popRegist4() {
    // 아직 미오픈이라서 임시로 주석
    modal(GSR + "/member/card/check.aspx", 500, 600, 0.4);
    //modal("/member/card/check_com.aspx", 360, 225, 0.4);
}

// 아이디 찾기 팝업
function idSearch(retailDomain) {
    modal(GSR + +"/Member/Id/find.aspx", 360, 400, 0.4);
}

// 아이디 찾기 팝업
function idSearch() {
    modal(GSR + "/Member/Id/find.aspx", 360, 370, 0.4);
}

// 비밀번호 찾기 팝업
function pwSearch() {
    modal(GSR + "/Member/Password/find.aspx", 360, 470, 0.4);
}

function popRegist2() {
    modal(GSR + "/member/card/card.aspx", 500, 550, 0.4);
}

function popLogin() {
    modal(GSR + "/member/card/card-nologin.aspx", 360, 230, 0.4);
}

function popIpin() {
    modal(GSR + "/member/card/card-ipin.aspx", 360, 300, 0.4);
}

function popMembership() {
    modal(GSR + "/member/join/join-total.aspx", 360, 225, 0.4);
}

function openIDSearch() {
    modal(GSR + "/Member/ID/find.aspx", 360, 400, 0.4);
}

function openPwSearch() {
    modal(GSR + "/Member/Password/find.aspx", 360, 470, 0.4);
}

function popLayer(ptype, msg) {
    modal(GSR + "/member/card/card-complete.aspx?pType=" + ptype + "&msg=" + escape(msg), 500, 450, 0.4);
}

// 멤버십카드
function popLayer(ptype, msg) {
    modal(GSR + "/member/card/card-complete.aspx?pType=" + ptype + "&msg=" + escape(msg), 500, 500, 0.4);
}
// 나라사랑카드
function popLayer1(ptype, msg) {
    modal(GSR + "/member/card/love-complete.aspx?pType=" + ptype + "&msg=" + escape(msg), 500, 408, 0.4);
}
// 학생증체크카드
function popLayer2(ptype, msg) {
    modal(GSR + "/member/card/check-complete.aspx?pType=" + ptype + "&msg=" + escape(msg), 500, 458, 0.4);
}
//실명인증
function popRealname(returnUrl) {
    modal(GSR + "/common/page/realname.aspx?returnurl=" + MISTER + returnUrl, 360, 600, 0.4);
}

// 회원가입팝업
function goRegistMember() {
    parent.location.href = GSR + "/Member/Join/Join.aspx";
}

function makeSiteHref(site, url){
    window.open(site+url, "", "");
    return false;
}
