﻿/**
* 파오인 뷰어 환경설정(공통)
*/

/* 상수 선언 */
var PAOIN_PAPER_SWF = 'http://www.paoin.com/Common/swf/PaperViewer.swf';
var PAOIN_PAPER_SWF_DEBUG = 'http://www.paoin.com/Common/swf/debug/PaperViewer.swf';

var PAOIN_ARTICLE_SWF = 'http://www.paoin.com/Common/swf/ArticleViewer.swf';
var PAOIN_ARTICLE_SWF_DEBUG = 'http://www.paoin.com/Common/swf/debug/ArticleViewer.swf';

var NEO_PAOIN_ARTICLE_SWF = 'http://thumb.paoin.com/paoweb/common/flash/ArticleViewer2.swf';
var NEO_PAOIN_ARTICLE_SWF_DEBUG = 'http://thumb.paoin.com/paoweb/common/flash/debug/ArticleViewer2.swf';


/// 파오인 지면 뷰어 URL
var PaoinPaperSWF = PAOIN_PAPER_SWF;
/// 파오인 기사 뷰어 URL
var PaoinArticleSWF = PAOIN_ARTICLE_SWF;
var isDebugMode = false;

/// 디버깅모드 구동 여부 체크
/// 디버깅모드 구동 방법 : javascript:setCookie('paoin_mode', 'debug'); 실행
if (document.cookie.indexOf("paoin_mode=debug") > -1) {
    isDebugMode = true;
    PaoinPaperSWF = PAOIN_PAPER_SWF_DEBUG;
    PaoinArticleSWF = PAOIN_ARTICLE_SWF_DEBUG;
    
}


/**
* 파오인 포털서비스로 업그레이드
*/

var flag_paoin = true;

if (flag_paoin) {
    // 파오인 서비스 코드
    var arrPaoin = new Array(
		"AA001", "AA005", "AA006", "AA010",
		"AA015", "AB007", "AB009", "AB006",
		"AB013", "AB020", "AC064", "AB019",
		"AG003", "AG007", "AG008", "AG010",
		"AH229", "AH404", "AH409", "AH603",
		"AH611", "AH701", "AJ001", "BA002", "AA002",
		"BA005", "AH224"

		, "AH402", "AH618"
		, "AH301", "AH302"
		, "AH510", "AA004"
		, "AH212", "BD009"
		,"AC131");


    var GCC = getPaoinParameter('GCC');  // 언론사 페이지
    var SCT = getPaoinParameter('SCT');  // 파오인 서비스에서 유입

    for (var i = 0; i < arrPaoin.length; i++) {
        if (GCC == (arrPaoin[i] + "99") || SCT == arrPaoin[i]) {
            if( isDebugMode )
            {
                PaoinArticleSWF =NEO_PAOIN_ARTICLE_SWF_DEBUG;
            }
            else{
                PaoinArticleSWF =NEO_PAOIN_ARTICLE_SWF;
            }
        }
    }

}

/***************
* 파오인 포탈 로그인체크
*****************/
/*
function loginPaotalCookies() {

    var value = getPaoinParameter('EYESCRAP_CUST_NO') ;
    if (getPaoinParameter('EYESCRAP_CUST_NO') != null) {
        setPaoinPotalCookie("PaoinNo", value) ;
    }

    value = getPaoinParameter('EYESCRAP_SESSID');    
    if (getPaoinParameter('EYESCRAP_SESSID') != null) {
        setPaoinPotalCookie("PaoinSessID", value);
    }
}
*/



/*
* 플렉스 기사 뷰어의에서 검색 버턴 클릭
*/
function searchButtonClick(keyword) {
    var searchURL = "http://www.paoin.com/paoweb/search/main.aspx?keyword=" + escape(keyword) + "&SCT=" + getSCT();
    var objWin = window.open(searchURL, "", "");
    objWin.focus();
}

/***
* 좌측 파오인 지수
*/

    // Major version of Flash required
    var requiredMajorVersion = 9;
    // Minor version of Flash required
    var requiredMinorVersion = 0;
    // Minor version of Flash required
    var requiredRevision = 0;

     

    function moveIFrame(x,y,w,h) {
       // alert("moveIFrame");
        var frameRef=document.getElementById("myFrame");
        if( frameRef )
        {
            frameRef.style.left=x + 5;
            frameRef.style.top=y + 5;
        }
        var iFrameRef=document.getElementById("myIFrame"); 
        
        if( iFrameRef )
        {
         iFrameRef.width=w;
         iFrameRef.height=h;
        }
    }

    function hideIFrame(){
        //alert("hideIFrame");
        if(  document.getElementById("myFrame") ) document.getElementById("myFrame").style.visibility="hidden";
    }
     
    function showIFrame(){
        //alert("showIFrame");
       if(  document.getElementById("myFrame") ) document.getElementById("myFrame").style.visibility="visible";
    }

    function loadIFrame(url){
       //alert("showIFrame");
	initFrame();
     if(  document.getElementById("myFrame") ) document.getElementById("myFrame").innerHTML = "<iframe id='myIFrame' src='" + url + "'frameborder='0' marginheight='0' marginwidth='0' scrolling='no'></iframe>";
    }

    function initFrame()
    {
	if(!document.getElementById("myFrame") ) {

	var formDiv = document.createElement("div");
            formDiv.id = 'myFrame';
            document.body.appendChild(formDiv);
            formDiv.style.position = 'absolute';
            formDiv.style.border ='0px';

            formDiv.style.backgroundColor  ='transparent';
//            formDiv.style.visibility = 'hidden';
            formDiv.style.zIndex = '500';

	}

    }

    function voteMessage(msg)
    {
        articleViewer.articleviewerAlert(msg);
    }


    // 파오인 포탈에서 넘어온 경우 파라메터 체크
    // stat=paoin
    function isLoginPaoinPortal() {
    /*
        if (getPaoinParameter('stat') == "paoin") {
            return true;
        }
        else
    */        
            return false;
    }

    function isPortalflow() {
        
        if (getPaoinParameter('stat') == "paoin") {
        return true;
        }
        else
        return false;
    }

	function goScrapBook(articleNo,op)
	{
		var url="http://www.paoin.com/paoweb/scrapbook/default.aspx?articleNo=" + articleNo + "&op=" + op;
		var objWin = window.open(url,"","");
		objWin.focus();
	}

	function goPaoinHome()
	{
		var url="http://www.paoin.com/";
		var objWin = window.open(url,"","");
		objWin.focus();
	}

    function isPaoinSource() {
        
        if (getPaoinParameter('stat') == "paoin") {
        return true;
        }
        else
        return false;
    }
    /**
    * 로그인 인증을 받을 페이지로 이동한다.
    * @path 절대주소  http://www.domain.com/service/index.html
    */
    function goLoginPortalPage(next_url) {

        var paoinLoginUrl = "http://www.paoin.com/paoweb/user/login.aspx";
        var paoinServiceUrl = "http://www.paoin.com/";
        
        location.href = (paoinLoginUrl + '?nexturl=' + encodeURIComponent(next_url));
    }


    /// 파라메터 구하기
    function getPaoinParameter(strParamName) {
        var strURL = location.search;
        var tmpParam = strURL.substring(1).split("&");
        if (strURL.substring(1).length > 0) {
            var Params = new Array;
            for (i = 0; i < tmpParam.length; i++) {
                Params = tmpParam[i].split("=");
                if (strParamName == Params[0]) {
                    return Params[1];
                }
            }
        }
        return "";
    }    
    
    
/**
 * 쿠키관련
 */
function getPaoinPotalCookie(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 setPaoinPotalCookie(name, value) 
{
    var argv = setPaoinPotalCookie.arguments;
    var argc = setPaoinPotalCookie.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();
	todayDate.setDate( todayDate.getDate() + expires );
		
	document.cookie = name + "=" + value +
		((expires == null) ? "" : ("; expires="+todayDate.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}


// 팝업 노출 컨트롤 -------------------

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() + ";"
}

// --//팝업 노출 컨트롤 -------------------