﻿function Page_Exit() {

    if (self.screenTop > 9000) { // 브라우저 닫힘 
        // 창이 닫긴 후에 메시지가 뜨는 현상이 발생하므로 메시지를 먼저 띄운후 Process 처리

        if (getCookie("Usr_WinConf") != "")	//if(parent.frames["bottom"].document.forms.length > 0)
        {
            jAlert('로그아웃 되었습니다. 이용해주셔서 감사합니다.', "로그아웃", function () { User_LogOut(); });
        }
    }
    else {
        if (document.readyState == "complete") { } // 새로고침 
        else if (document.readyState == "loading") { }  // 다른 사이트로 이동 
    }
}
function browserCheck() {
    if (navigator.userAgent.indexOf('iPhone') != -1 || navigator.userAgent.indexOf('iPad') != -1 || navigator.userAgent.indexOf('iPod') != -1 || navigator.userAgent.indexOf('Android') != -1 || navigator.userAgent.indexOf('Windows CE') != -1 || navigator.userAgent.indexOf('Symbian') != -1) {
        window.top.location.href = "http://m.wisereport.co.kr";
    }
}
function CheckVal() {
    var flag = $("#login_flag").val();
    if (flag == "top") {
        if ($("input#UsrID").val().length == 0) {
            jAlert('아이디를 입력하세요.', "회원정보확인", function () { $("input#UsrID").focus(); });
            return false;
        }
        if ($("input#UsrPassWD").val().length == 0) {
            jAlert('비밀번호를 입력하세요.', "회원정보확인", function () { $("input#UsrPassWD").focus(); });
            return false;
        }
    }
    else {
        if ($("input#UsrID_Login").val().length == 0) {
            jAlert('아이디를 입력하세요.', "회원정보확인", function () { $("input#UsrID_Login").focus(); });
            return false;
        }
        if ($("input#UsrPassWD_Login").val().length == 0) {
            jAlert('비밀번호를 입력하세요.', "회원정보확인", function () { $("input#UsrPassWD_Login").focus(); });
            return false;
        }
    }

    if ($("#checker").attr("checked"))
        toMem();

    return true;
}
function openCookieWin() {
    if (getCookie("ncook20110427") != "done") {
        noticeWindow = window.open("/wiseSupport/popup/notice_q.html", "", "width=500, height=580, top=0,left=0", "scrollbars=0", "resizable=0", "menubar=0, toolbar=0, location=0, directories=0, status=0");
        try { noticeWindow.opener = self; } catch (e) { }
    }
}
function fn_membershipjoin() {
    //parent.location.href = "http://personal.wisereport.co.kr/wiseMain/CrossMembership.aspx?furl=join";
    parent.location.href = "/wiseMain/MembershipAgreement.aspx";
}

function fn_goEnglishSite() {
    parent.location.href = "http://en.wisereport.co.kr";
}

//    function na_pre_focus()	// 아이디 focus
//    {
//        $("input#UsrID").focus();
//    }
//family site
function na_JumpfamilyPage(sel, targetstr) {
    var index = sel.selectedIndex;
    if (sel.options[index].value != '') {
        if (targetstr == 'blank') {
            window.open(sel.options[index].value, 'win' + index);
        } else {
            var frameobj;
            if (targetstr == '') targetstr = 'self';
            if ((frameobj = eval(targetstr)) != null)
                frameobj.location = sel.options[index].value;
        }
    }
} //
//인기 검색어, My 검색어 List가져오기(top5)
function viewBanner(typ) {
    fn_Top5List(typ);
}
//bar의 Top5 리스트를 가지고온다.
function fn_Top5List(typ) {
    //data 로딩하는 이미지
    //	    $("#Top5").block({
    //	        message: '<h1><img src="/images/loading.gif"/></h1>',
    //	        css: { border: 'none', backgroundColor: '#fff', opacity: 0.5 },
    //	        overlayCSS: { backgroundColor: '#fff', opacity: 0.5 }
    //	    	    });
    if (typ == "1") {
        $.ajax({
            url: "/wiseReport/reports/Banner.aspx",
            type: 'post',
            dataType: 'text',
            data: {
                gubun: '1',
                index: $("#currentUrl").val()
            },
            async: false,
            success: function (data) {
                //$("#MyTop5").empty();
                $("#MyTop5").html(data);
                //$("#Top5").unblock();
            },
            error: function (xhr, textStatus) {
                fn_errorOccured();
            }
        });
    }
    else if (typ == "2")//종목
    {
        $.ajax({
            url: "/wiseReport/reports/Banner.aspx",
            type: 'post',
            dataType: 'text',
            data: {
                gubun: '2',
                index: $("#currentUrl").val()
            },
            async: false,
            success: function (data) {
                //$("#Top5").empty();
                $("#Top5").html(data);
                //$("#Top5").unblock();
            },
            error: function (xhr, textStatus) {
                fn_errorOccured();
            }
        });
    }
    else if (typ == "3")//산업
    {
        $.ajax({
            url: "/wiseReport/reports/Banner.aspx",
            type: 'post',
            dataType: 'text',
            data: {
                gubun: '3',
                index: $("#currentUrl").val()
            },
            async: false,
            success: function (data) {
                //$("#Top5").empty();
                $("#Top5").html(data);
                //$("#Top5").unblock();
            },
            error: function (xhr, textStatus) {
                fn_errorOccured();
            }
        });
    }
}
//Cookie를 생성하는 Function
function newCookie(name, value, days) { //쿠기를 생성하는 function

    var days = 10;   // 쿠키저장 일수
    if (days) {
        var date = new Date();  //날짜 객체 생성
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); //10일로 설정된 시간을 밀리세컨드로 변환
        var expires = "; expires=" + date.toGMTString(); //쿠키 만료일을 변수 expires에 설정함
    }
    else
        var expires = ""; //days 변수가 초기화 안될 경우 expires를 NULL로 초기화

    document.cookie = name + "=" + value + expires + "; path=/"; //쿠키생성 
}

//name의 Cookie값을 검색하여서 값을 가져오는데 없으면  NULL을 반환
function readCookie(name) {
    //name으로 Cookie의 값을 검색해서 반환한다 없으면 NULL을 반환
    var nameSG = name + "=";
    var nuller = '';
    if (document.cookie.indexOf(nameSG) == -1)  //Cookie를 검색
        return nuller;

    var ca = document.cookie.split(';');

    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameSG) == 0) return c.substring(nameSG.length, c.length);
    }
    return null;
}

//checkbox의 에 따라서 Cookie를 설정(체크이벤트를 잡아서 동작)
function changCB() {
    if (!$("#checker").attr("checked")) {
        delMem(1);
    }
    else {
        toMem(1);
    }
    if (!$("#checker_pwd").attr("checked")) {
        delMem(2);
    }
    else {
        toMem(2);
    }
}

//Cookie에 값을 넣는다.
function toMem(param) {
    if (param == 1 && $("#UsrID_Login").val() != "아이디") {
        newCookie('theName', $("#UsrID_Login").val());
    }
    else if (param == 2) {
        newCookie('thePass', $("#UsrPassWD_Login").val());
    }
}

//Cookie에 값을 ""로 초기화 한다.
function delMem(param) {
    if (param == 1) {
        newCookie('theName', "", 1);
        //if ($("#UsrID").val() == "") {
        //    $("#UsrID").val("아이디");
        //    $("#UsrID_Login").val("아이디");
        //}
    }
    else if (param == 2) {
        newCookie('thePass', "", 1);
        //$("#UsrPassWD").val("");
        //$("#UsrPassWD_Login").val("");
    }
}

//window.load 이벤트에 호출하는 function으로 페이지가 로딩 되면서 값을 세팅하는 부분
function remCookie(param) {
    if (readCookie("theName") == " " || readCookie("theName") == "") {
        $("#checker").removeAttr("checked");
    }
    else {
        $("#UsrID").val(readCookie("theName"));
        $("#UsrID_Login").val(readCookie("theName"));
        $("#checker").attr("checked", "checked");
    }
    if (readCookie("thePass") == " " || readCookie("thePass") == "") {
        $("#checker_pwd").removeAttr("checked");
    }
    else {
        $("#UsrPassWD").val(readCookie("thePass"));
        $("#UsrPassWD_Login").val(readCookie("thePass"));
        $("#checker_pwd").attr("checked", "checked");

        $("#UsrPassWD_Text").css("display", "none");
        $("#UsrPassWD").css("display", "inline");
        $("#UsrPassWD").css("borderColor", "#777");
        $("#btnLogin").focus();
    }
}

function login_BottomKeyPress(e) {
    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
        $("#btnLogin_Login").focus();
        changCB();
    }
}
