﻿/*******************************
* 서비스에 쓰이는 자바스크립트 변수 정의
********************************/
// 서비스 경로
var SERVICE_ROOT = "/paoweb/";

/// 웹 뷰어 URL
var PaoinArticleSWF = "/paoweb/common/flash/ArticleViewerLite.swf";             // 기사 뷰처
//var PaoinPaperSWF = "/paoweb/common/flash/PaperViewer.swf";                  // 지면 뷰어
var PaoinPaperSWF = "http://thumb.eyescrap.com/paoweb/common/swf/PaperViewerPaoin.swf";                  // 지면 뷰어

//var PaoinPrevSWF = "../common/flash/PreeViewer.swf";
var PaoinPrevSWF = "/paoweb/common/flash/PreeViewer.swf"; // 신문미리보기
var PaoinPrevMZSWF = "/paoweb/common/flash/PrevMagazine.swf"; // 신문미리보기

// 브라우져 종류 체크
function getNavigatorInfoStr()
{
    var name = navigator.appName, ver = navigator.appVersion,
        ver_int = parseInt(navigator.appVersion), ua = navigator.userAgent, infostr;
    if(name == "Microsoft Internet Explorer")
    {
        if(ver.indexOf("MSIE 3.0") != -1)
            return "Internet Explorer 3.0x";
        if(ver_int != 4)
            return "Internet Explorer " + ver.substring(0, ver.indexOf(" "));

        var real_ver = parseInt(ua.substring(ua.indexOf("MSIE ") + 5));
        if(real_ver >= 7)
            infostr = "Windows Internet Explorer ";
        else
            infostr = "Microsoft Internet Explorer ";

        if(ua.indexOf("MSIE 5.5") != -1)
            return infostr + "5.5";
        else
            return infostr + real_ver + ".x";

        return "Internet Explorer";
    }
    else if(name == "Netscape")
    {
        if(parseInt(ua.substring(8, 8)) <= 4)
          return "Netscape " + ver.substring(0, ver.indexOf(" "));
        else if(ua.lastIndexOf(" ") < ua.lastIndexOf("/"))
          return ua.substring(ua.lastIndexOf(" "));
        else
            return "Netscape";
    }
    else
        return name;
}

// OS 체크
function getOSInfoStr()
{
    var ua = navigator.userAgent;

    if(ua.indexOf("NT 6.0") != -1) return "Windows Vista/Server 2008";
    else if(ua.indexOf("NT 5.2") != -1) return "Windows Server 2003";
    else if(ua.indexOf("NT 5.1") != -1) return "Windows XP";
    else if(ua.indexOf("NT 5.0") != -1) return "Windows 2000";
    else if(ua.indexOf("NT") != -1) return "Windows NT";
    else if(ua.indexOf("9x 4.90") != -1) return "Windows Me";
    else if(ua.indexOf("98") != -1) return "Windows 98";
    else if(ua.indexOf("95") != -1) return "Windows 95";
    else if(ua.indexOf("Win16") != -1) return "Windows 3.x";
    else if(ua.indexOf("Windows") != -1) return "Windows";
    else if(ua.indexOf("Linux") != -1) return "Linux";
    else if(ua.indexOf("Macintosh") != -1) return "Macintosh";
    else return "";
}

/** 레이어 노출, 비노출 처리 **/
function layer_view(lname, flag) {

    alert(lname);
    if (document.layers) {
        layer = document.layers[lname];
    }
    else if (document.all) {
        layer = document.all[lname];
    }
    else {
        layer = document.getElementById(lname);
    }

    if (lname == '')
        return;

    if (document.layers) {
        layer.visibility = (flag == 0) ? 'show' : 'hide';
    }
    else if (document.all) {
        layer.style.visibility = (flag == 0) ? 'visible' : 'hidden';
    }
    else {
        layer.style.visibility = (flag == 0) ? 'visible' : 'hidden';
    }

    document.getElementById(lname).style.zIndex = 25000000000000000000;
}

/** 레이어 노출, 비노출 처리 **/
function layer_view_onoff(lname, flag) {
    
    if (document.layers) {
        layer = document.layers[lname];        
    }
    else if (document.all) {
        layer = document.all[lname];
    }
    else {
        layer = document.getElementById(lname);        
    }

    if (lname == '')
        return;

    if (layer != null) {

        if (document.layers) {
            layer.style.display = (flag == 0) ? 'block' : 'none';
        }
        else if (document.all) {
            layer.style.display = (flag == 0) ? 'block' : 'none';
        }
        else {
            layer.style.display = (flag == 0) ? 'block' : 'none';
        }
    }
    
}

/// 카테고리 Layer
function layerTabList(name, seq, count) {
    for (var i = 1; i <= count; i++) {
        layer_view_onoff(name + "" + i, 1);
    }

    layer_view_onoff(name + seq, 0);
}

/* 탭에서 onmousesover 하였을 때 스타일 변경되는 것 */
function onFocusMouse(lname, seq, count) {
    var layer;

    for (var i = 1; i <= count; i++) {
        layer = document.getElementById(lname + i);

        layer.className = "";
    }
    layer = document.getElementById(lname + seq);
    layer.className = "on";
}

function onFocusMouseInClass(lname, seq, count, className) {
    var layer;

    for (var i = 1; i <= count; i++) {
        layer = document.getElementById(lname + i);

        layer.className = "";
    }
    layer = document.getElementById(lname + seq);
    layer.className = className;
}

function onFocusMouse2(lname,  classname) {
    var layer;

    layer = document.getElementById(lname);
    layer.className = classname;
}


/* 스크랩 하기로 이동 */
function goNewsScrap(cno) {
    if(getCookie("USER_LOGIN_ID"))
    {
        var f = document.forms[0];
        var popWidth = 358;
        var popHeight = 520;
        var winLeftPost = (window.screen.availWidth - popWidth) / 2;
        var winTopPost = (window.screen.availHeight - popHeight) / 2;

        var RtnURL = encodeURI(document.location.href);
        var strUrl = SERVICE_ROOT +"scrap/scrap.aspx?cno="+ cno +"&RtnURL="+RtnURL;
        //window.open(strUrl, 'Scrap', 'width=222,height=300,scrollbar=no');
        window.open(strUrl, 'Scrap', 'width='+ popWidth +',height='+ popHeight +',scrollbar=no,left='+ winLeftPost +',top='+ winTopPost);        
    }
    else
    {
        try {
            var wind = window.open('/paoweb/user/login_popup.aspx?Page=Close', 'Close', 'width=' + 743 + ',height=' + 313 + ',scrollbars=no,resizable=no');
            wind.focus();
            if(wind)
            {}
            else
            {
                alert('팝업이 차단되었습니다. 팝업차단을 해제하신 후, 이용하세요.');
            }
        }
        catch(e)
        {
            alert('팝업이 차단되었습니다. 팝업차단을 해제하신 후, 이용하세요.');
        }  
    }
}


/// 기사 뷰어 페이지로 가기
function goViewer(cno) {
    //FORM으로 변경될 수 있음.

    var f = document.forms[0];
    var width = screen.width - 60;
    var height = screen.height - 100;

    window.open(f.articleURL.value + "?CNo=" + cno, 'paper', 'width='+width+',height='+height+',top=0,left=0,scrollbar=no,resizable=yes');
    //window.open(f.articleURL.value + "?CNo=" + cno, 'paper', 'width='+width+',height='+height+',top=0,left=0,scrollbar=no');
}


function goArticle(cno, sct) {

    // 현재페이지 쿠키로 저장 (파오인정액권)    
    setCookie("prevurl", location.href);
    
    
    //FORM으로 변경될 수 있음.
    var f = document.forms[0];

    document.location.href = f.articleURL.value + "?CNo=" + cno + "&SCT=" + sct;
}

function goMagazineArticle(cno, sct) {

    // 현재페이지 쿠키로 저장 (파오인정액권)    
    setCookie("prevurl", location.href);
    
    
    //FORM으로 변경될 수 있음.
    var f = document.forms[0];

    document.location.href = f.magazineURL.value + "?CNo=" + cno + "&SCT=" + sct;
}

function goOnlineArticle(cno, ct, param) {
    //FORM으로 변경될 수 있음.

    var f = document.forms[0];

    var url = SERVICE_ROOT + "news/article.aspx?CNo=" + cno;
    if (ct.length > 0 && ct !="" && ct !="null") { url += "&ct=" + ct; }
    if (param.length > 0) {url += param; }

    // 현재페이지 쿠키로 저장 (파오인정액권)
    setCookie("prevurl", location.href)
    location.href = url;
}

function OnlineArticle(cno, ct, param) {
    //FORM으로 변경될 수 있음.

    var f = document.forms[0];

    var url = SERVICE_ROOT + "news/article.aspx?CNo=" + cno;
    if (ct.length > 0 && ct !="" && ct !="null") { url += "&ct=" + ct; }
    if (param.length > 0) {url += param; }

    // 현재페이지 쿠키로 저장 (파오인정액권)
    setCookie("prevurl", location.href)
    location.href = url;
}

/// 기사 뷰어 페이지로 가기
function goPaper(sct, paper_date, page_no) {
    //FORM으로 변경될 수 있음.   
    var f = document.forms[0];    
    var width = screen.width - 10;
    var height = screen.height - 60;    
    var url = "";
    
    if(f.paperURL ) 
    {        
        url =f.paperURL.value;    
       
    }else{
        url = document.getElementById("paperURL").value;
    }
    
    if(getCookie("USER_LOGIN_ID"))
    {
        try
        {
            var wind = window.open(url + "?PaperDate=" + paper_date + "&SCT=" + sct + "&PageNo=" + page_no, 'paper', 'width=' + width + ',height=' + height + ',top=0,left=0,scrollbars=no,resizable=yes');
            if(wind)
            {
            }
            else
            {
                alert('팝업이 차단되었습니다. 팝업차단을 해제하신 후, 이용하세요.');
            }
        }
        catch(e)
        {
            alert('팝업이 차단되었습니다. 팝업차단을 해제하신 후, 이용하세요.');
        }
        
//        alert(wind.document.body.style.overflow);        
//        wind.document.body.style.overflow = "hidden";
    }
    else
    {    
        try
        {
            var wind = window.open('/paoweb/user/login_popup.aspx?Page=Paper&PaperDate=' + paper_date + '&SCT=' + sct + '&PageNo=' + page_no, 'loginpop', 'width=' + 743 + ',height=' + 313 + ',top='+(height-313)/2+',left='+(width-743)/2+',scrollbars=no,resizable=no');
            wind.focus();
            if(wind)
            {}
            else
            {
                alert('팝업이 차단되었습니다. 팝업차단을 해제하신 후, 이용하세요.');
            }
        }
        catch(e)
        {
            alert('팝업이 차단되었습니다. 팝업차단을 해제하신 후, 이용하세요.');
        }  
    }
}

// 지면뷰어 미리 보기 페이지로 이동 함
function goPaperPreview(paper_date, sct, page_no){
     var f = document.forms[0];
    var width = screen.width - 10;
    var height = screen.height - 60;
    var url = f.paperPreviewURL.value + "?PaperDate=" + paper_date + "&SCT=" + sct + "&PageNo=" + page_no;
    
    document.location.href = url;
    
}





function goNonLink()
{
    alert("준비중입니다");
}

/// 메인으로 이동 
function goHome() {
    document.location.href = SERVICE_ROOT;
}

/// 메인으로 이동
function goHomeFormPopup() {

    window.opener.document.location.href = "/";
    window.close();
}

function popAlert(msg)
{
    var popWidth = 270;
    var popHeight = 130;
    var winLeftPost = (window.screen.availWidth - popWidth) / 2;
    var winTopPost = (window.screen.availHeight - popHeight) / 2;

    var strUrl = "/paoweb/event/popmsg.aspx?Msg="+msg;
    try {
        var popAlert = open(strUrl, 'popAlert', 'left='+ winLeftPost +',top='+ winTopPost +',width='+ popWidth +',height='+ popHeight +',toolbars=no,scrollbars=no,resizable=no');
    } catch (e) {
        alert('팝업이 차단되었습니다. 팝업차단을 해제하신 후, 이용하세요.');
    }
}


function popViewerGuide() {

    var url = "/paoweb/guide/viewer.aspx";
    var popWidth = 780;
    var popHeight = 600;
    var winLeftPost = (window.screen.availWidth - popWidth) / 2;
    var winTopPost = (window.screen.availHeight - popHeight) / 2;

    window.open(url, 'guide', 'width=' + popWidth + ',height=' + popHeight + ',top=0,left=0,scrollbar=no,resizable=yes');
}


function popChargeGuide() {

    var url = "/paoweb/guide/media_charge.aspx";
    var popWidth = 780;
    var popHeight = 600;
    var winLeftPost = (window.screen.availWidth - popWidth) / 2;
    var winTopPost = (window.screen.availHeight - popHeight) / 2;

    window.open(url, 'guide', 'width=' + popWidth + ',height=' + popHeight + ',top=0,left=0,scrollbar=no,resizable=yes');
}

//****************************** 스크랩북 관련 start ******************************//

// 마이스크랩으로 이동
function goMyScrap() {
    var RtnURL = encodeURI(document.location.href);
    document.location.href = SERVICE_ROOT + "scrapbook/default.aspx?RtnURL="+RtnURL;
}

// 마이스크랩으로 이동(팝업일때)
function goMyScrapFormPopup() {
    var RtnURL = encodeURI(document.location.href);

    var url = SERVICE_ROOT + "scrapbook/default.aspx?RtnURL=" + RtnURL;
    var objWin = window.open(url, "paoin", "");
    objWin.focus();
    
    //window.opener.document.location.href = SERVICE_ROOT + "scrapbook/default.aspx?RtnURL=" + RtnURL;
    //opener.window.focus();
    	
    //window.close();
}

/// 편집출력 히든 호출
function loadhiddenEyePrint(al) {

    var hiddenPrint = document.getElementById("hiddenPrint");
    var RtnURL = encodeURI(document.location.href);
    
    if (al == "")
    {
        alert('저장&인쇄 할 기사를 선택해 주세요.');
    }
    else
    {
        hiddenPrint.src = "";
        //hiddenPrint.src = "/paoweb/scrapbook/hidden_editprint.aspx?ArticleList="+ al +"&RtnURL="+RtnURL;
        hiddenPrint.src = "/paoweb/scrapbook/hidden_editprint.aspx?ArticleList="+ al;
    }
}


/// 편집출력가이드 호출
function loadEyePrintInfo() {

    var strUrl = "/paoweb/scrapbook/info/info.aspx";
    try {
        var editprint = open(strUrl, 'editprintinfo', 'left=0,top=0,width=600,height=700,toolbars=no,scrollbars=yes,resizable=no');
    } catch (e) {
        alert('편집출력가이드팝업이 차단되었습니다. 팝업차단을 해제하신 후, 이용하세요.');
    }    
}

// 저장&인쇄 팝업 호출
function goSavePrintPopup(al)
{
    var RtnURL = encodeURI(document.location.href);
    var strUrl = "/paoweb/scrapbook/pop_savenprint.aspx?ArticleList="+ al +"&RtnURL="+RtnURL;

    if (al == "")
    {
        alert('저장&인쇄 할 기사를 선택해 주세요.');
    }
    else
    {
        try {
            var saveprint = open(strUrl, 'saveprint', 'left=0,top=0,width=570,height=670,toolbars=no,scrollbars=no,resizable=no');
        } catch (e) {
            alert('저장인쇄 팝업이 차단되었습니다. 팝업차단을 해제하신 후, 이용하세요.');
        }
    }
}

//  저장&인쇄 팝업 호출 (flex호출)
function doSavePrintPopupUrl(strUrl) {

    try {
        var saveprint = open(strUrl, 'saveprint', 'left=0,top=0,width=570,height=670,toolbars=no,scrollbars=no,resizable=no');
    } catch (e) {
        alert('저장인쇄 팝업이 차단되었습니다. 팝업차단을 해제하신 후, 이용하세요.');
    }
}


/**
* 지면 저장 (플렉스 뷰어)  (플렉스 뷰어에서 ActivX구동)
*/
function activeXPageSave(pageNos, isJpg) {

    try {
        var strUrl = '/paoweb/scrapbook/pop_savepapers.aspx?PageList=' + pageNos + '&isJpg=' + isJpg;
        var saveprint = open(strUrl, 'saveprint', 'left=0,top=0,width=570,height=517,toolbars=no,scrollbars=no,resizable=no');
    } catch (e) {
        alert('저장인쇄 팝업이 차단되었습니다. 팝업차단을 해제하신 후, 이용하세요.');
    }
}
/**
* 기사 저장 인쇄 (플렉스 뷰어에서 ActivX구동)
*/
function activeXArticleSavePrint(articleNos) {
    goSavePrintPopup(articleNos)
}


//****************************** 스크랩북 관련 start ******************************//

// 팝업 노출 컨트롤 -------------------

function popupCheck( popupKey )
{
    var name = popupKey;
    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 isPopupEnable( popupKey )
{
    if( popupCheck(popupKey) != "done" )
        return true;
    else
        return false;    
}

function popupClosed(popupKey, expiredays )
{
	var name = popupKey;
	var value = "done";
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

// --//팝업 노출 컨트롤 -------------------



function goArticleScrap(cno, fno) {

    var f = document.forms[0];
    var frm = document.getElementById("f");

    frm.action = f.paperURL.value;
    frm.CNo.value = cno;
    frm.listType.value = "Scrap";
    frm.searchData.value = fno;
    frm.searchData2.value = "";
    //frm.mediaIdList.value = "";
    //frm.startDate.value = "";
    //frm.endDate.value = "";
    frm.startRowIndex.value = "1";
    frm.maximumRows.value = "10";

    frm.submit();
}

/*
PV 기사보기
*/
function goArticlePVCategory(cno, pvct, list){
    
    var goUrl;
    if( list == "magazine" )
    {
         goUrl="/paoweb/magazine/article.aspx?CNo=" + cno + "&ct=" + pvct +"&startRowIndex=0&mediaType=2&pv=1";
    }
    else if( list == "paper" )
    {
        goUrl="/paoweb/paper/article.aspx?CNo=" + cno +"&ct=" + pvct +"&startRowIndex=0&mediaType=1&pv=1";
    }
    else if( list == "photo" )
    {
        goUrl="/paoweb/paper/article.aspx?CNo=" + cno +"&ct=" + pvct +"&startRowIndex=0&mediaType=3&pv=1";
    }
    
    document.location.href = goUrl;

}

function goArticleCategory(cno, ct, list,startRowIndex,sct) {


    // 현재페이지 쿠키로 저장 (파오인정액권)
    setCookie("prevurl", location.href);

    var f = document.forms[0];
    var param = ""
    if (ct != "") param = "&ct=" + ct;
    
    if (startRowIndex != "" && startRowIndex != "undefined") param = param + "&startRowIndex=" + startRowIndex;
    if (sct != "" && sct != "undefined") param = param +"&sct=" + sct;



    if (list == "magazine")
        document.location.href = "/paoweb/magazine/article.aspx" + "?CNo=" + cno + param + "&mediaType=2";
    else if (list == "news")
        document.location.href = "/paoweb/news/article.aspx" + "?CNo=" + cno + param + "&mediaType=1";
    else
        document.location.href = f.articleURL.value + "?CNo=" + cno + param;
    
}

function goArticlePVNew(cno, ct, max) {
    var f = document.forms[0];
    var frm = document.getElementById("f");


    // 현재페이지 쿠키로 저장 (파오인정액권)
    setCookie("prevurl", location.href, null);

    frm.action = f.articleURL.value;
    frm.CNo.value = cno;
    frm.listType.value = "PVNews";
    frm.searchData.value = ct;
    frm.searchData2.value = "";
    //frm.mediaIdList.value = "";
    //frm.startDate.value = "";
    //frm.endDate.value = "";
    frm.startRowIndex.value = "1";
    frm.maximumRows.value = max;

    frm.target = "";

    frm.submit();

}

function goArticleSearch(cno, param) {
    var f = document.forms[0];
    var frm = document.getElementById("f");

    if (param == "online")
        frm.action = "/paoweb/news/article.aspx";
    else if (param == "magazine")
        frm.action = "/paoweb/magazine/article.aspx";
    else 
        frm.action = f.articleURL.value;
    frm.CNo.value = cno;
    frm.listType.value = "Search";
    frm.searchData.value = f.keyword.value;
    frm.searchData2.value = f.ct == null ? "" : f.ct.value;            //카테고리 리스트
    frm.mediaIdList.value = f.SCT == null ? "" : f.SCT.value;
    frm.startDate.value = f.startdate.value;
    frm.endDate.value = f.enddate.value;
    
    frm.page.value = f.listpageno == null ? "1" : f.listpageno.value;  //"1";
    frm.page_size.value = f.pagesize == null ? "12" : f.pagesize.value;  //"10";
    frm.searchparam.value = f.searchparam == null ? "" : f.searchparam.value;

    frm.submit();
}

// --// 기사 통합뷰어 호출 -------------------




/**
* 쿠키관련
*/
function getCookie(name) {
    var cname = name + "=";
    var dc = document.cookie;
    if (dc.length > 0) {
        begin = dc.indexOf(cname);

        if (begin != -1) {
            begin += cname.length;
            end = dc.indexOf(";", begin);
            if (end == -1) end = dc.length;
            return unescape(dc.substring(begin, end));
        }
    }
    return null;
}

function setCookie(name, value) {
    var argv = setCookie.arguments;
    var argc = setCookie.arguments.length;
    var expires = (2 < argc) ? argv[2] : null;
    var path = (3 < argc) ? argv[3] : null;
    var domain = (4 < argc) ? argv[4] : null;
    var secure = (5 < argc) ? argv[5] : false;

    var todayDate = new Date();
    //기본적으로 다음날 0시0분까지로 설정
    //todayDate = new Date(todayDate.getFullYear(), todayDate.getMonth(), todayDate.getDate()+1);
    todayDate.setDate(todayDate.getDate() + expires);

    document.cookie = name + "=" ;

    document.cookie = name + "=" + value +
		((expires == null) ? "" : ("; expires=" + todayDate.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}

/**
* 공백제거
*/
function trim(str) {
    var count = str.length;
    var len = count;
    var st = 0;
    while ((st < len) && (str.charAt(st) <= ' ')) st++;
    while ((st < len) && (str.charAt(len - 1) <= ' ')) len--;
    return ((st > 0) || (len < count)) ? str.substring(st, len) : str;
}



/***************************************
ASYNCHRONOUS IMAGE LOADING CODE
****************************************/

// For all object with class "asyncImaLoad" (loader), function read
// image path from title attribute, create new Image object,
// next assign image from path to Image object and 
// append it to loader
function setupLoadingAsynchronousImages() {
    // for each object with class "asyncImgLoad"
    $('.asyncImgLoad').each(
        function() {
            // save handle to loader - caintainer which we gona insert loaded image
            var loader = $(this);
            // get image path from loader title attribute
            var imagePath = loader.attr('title');
            // create new image object
            var img = new Image();
            // set opacity for image to maximum
            // value 0.0 means completly transparent
            $(img).css("opacity", "0.0")
            // next we set function wich gona be caled then
            // image load is finished  
                .load(
                    function() {
                        // insert loaded image to loader object 
                        // and remove unnecessary title attribute
                        loader.append(this).removeAttr('title');
                        // for inserted image we set margin to zero
                        // opacity to max and fire up 500ms opacity animation
                        $(this)
                            .css("margin", "0px")
                            .css("opacity", "0.0")
                            .animate({ opacity: 1.0 }, 500,
                                function() {
                                    // after animation we remove loader background image 
                                    loader.css("background-image", "none");
                                }
                            );
                    }
            // set new value for attribute src - this means: load image from imagePath    
                ).attr('src', imagePath);
        }
    );
} // end of function setupLoadingAsynchronousImages


function calEventGoLocation(ref){
 location.href = "/paoweb/user/login.aspx?nexturl=" + ref;
}

function eventGoLocation(ref)
{
    location.href = ref;
}
