﻿// JScript File
    /*=======================================================================
    Function명  : getCookie
    내      용  : 쿠키를 가져오는 함수
    작  성  자  : 라석[ENET]
    최초작성일  : 2005년 12월 22일
    설명: 쿠키값 전체에서 쿠키 key값으로 나눠 값을 찾는 함수
    ========================================================================*/
	function getCookie(NameOfCookie)
	{
		if (document.cookie.length > 0) 
		{              
			begin = document.cookie.indexOf(NameOfCookie+"=");       
			if (begin != -1) 
			{           
				begin += NameOfCookie.length+1;       
				end = document.cookie.indexOf(";", begin);
				if (end == -1) end = document.cookie.length;
				return unescape(document.cookie.substring(begin, end));
			} 
		}
		return null;
	}

	// 
	/*=======================================================================
    Function명  : setCookie
    내      용  : 쿠키를 설정하는 함수
    작  성  자  : 라석[ENET]
    최초작성일  : 2005년 12월 22일
    설명: 쿠키를 날짜(일)을 첨부하여 값을 저장 - expiredays가 없을 경우 현재 날짜
    ========================================================================*/
	function setCookie(NameOfCookie, value, expiredays) 
	{
		var ExpireDate = new Date ();
		ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
		document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
	}
	
    /*=======================================================================
    Function명  : Preview
    내      용  : Photo클릭 시 미리보기 화면 띄움. 
    작  성  자  : 박소영[ENET]
    최초작성일  : 2005년 10월 02일

    설명:
    ========================================================================*/
    function Preview(contentsID, code,ContentsArr)
    {   
        var url = "";
        var menuId = " ";
        
        if(document.getElementById('hhdMenuId') != null)
            menuId = document.getElementById('hhdMenuId').value;
        
        switch(code.toLowerCase())
        {
            case "mpic":        //영상
            case "divmpic":
            case "mpic_best":
                url = '/YNA/ContentsSales/ContentsData/YISW_MpicPreview.aspx?ContentsID=' + contentsID + '&MenuId=' + menuId;
                window.open(url,'Preview','width=737,height=693;resizeble=no,scrollbars=yes, toolbar=no, status=yes, menubar=no');
                break;
            case "graphic":     //그래픽
            case "divgraphic":
            case "graphic_best":
                url = '/YNA/ContentsSales/ContentsData/YISW_GraphicPreview.aspx?ContentsID=' + contentsID  + '&MenuId=' + menuId;
                window.open(url,'Preview','width=737,height=693;resizeble=no,scrollbars=yes, toolbar=no, status=yes, menubar=no');
                break;
            case "artist":      //갤러리
                url='./YISW_photoPreview.aspx?ContentsID=' + contentsID + '&IsGallery=Y&'  + 'MenuId=' + 'MenuId=' + menuId+'&ContentsArr='+ContentsArr;
                window.open(url,'Preview','width=737,height=693;resizeble=no,scrollbars=yes, toolbar=no, status=yes, menubar=no');
                break;
            case "active":      //액티브
            case "divactive":
            case "active_best":
            case "activenews":
                url='/YNA/ContentsSales/ContentsData/YISW_activePreview.aspx?ContentsID=' + contentsID + '&MenuId=' + menuId;    
                window.open(url,'Preview','width=737,height=693;resizeble=no,scrollbars=yes, toolbar=no, status=yes, menubar=no');
                break;
            case "inter":       //내신속보
            case "photo":       //사진
                url='/YNA/ContentsSales/ContentsData/YISW_photoPreview.aspx?ContentsID=' + contentsID + '&IsGallery=I&'  + 'MenuId=' + menuId+'&ContentsArr='+ContentsArr;
                window.open(url,'Preview','width=737,height=693;resizeble=no,scrollbars=yes, toolbar=no, status=yes, menubar=no');
                break;
            case "outer":  //외신사진
            case "outer2":  //외신속보
                url='/YNA/ContentsSales/ContentsData/YISW_photoPreview.aspx?ContentsID=' + contentsID + '&IsGallery=O&'  + 'MenuId=' + menuId+'&ContentsArr='+ContentsArr;
                window.open(url,'Preview','width=737,height=693;resizeble=no,scrollbars=yes, toolbar=no, status=yes, menubar=no');
                break;
            case "photo_best":
            case "directory":   //디렉토리검색
            case "section":     //섹션뉴스
            case "photonews":
            case "best":
                url='/YNA/ContentsSales/ContentsData/YISW_photoPreview.aspx?ContentsID=' + contentsID + '&IsGallery=A&'  + 'MenuId=' + menuId+'&ContentsArr='+ContentsArr;
                window.open(url,'Preview','width=737,height=693;resizeble=no,scrollbars=yes, toolbar=no, status=yes, menubar=no');
                break;
            case "world":  //월드토픽
                url='/YNA/ContentsSales/ContentsData/YISW_photoPreview.aspx?ContentsID=' + contentsID + '&IsGallery=W&'  + 'MenuId=' + menuId+'&ContentsArr='+ContentsArr;
                window.open(url,'Preview','width=737,height=693;resizeble=no,scrollbars=yes, toolbar=no, status=yes, menubar=no');
                break;
            case "repere":  //르페르
                url='/YNA/ContentsSales/ContentsData/YISW_photoPreview.aspx?ContentsID=' + contentsID + '&IsGallery=R&'  + 'MenuId=' + menuId+'&ContentsArr='+ContentsArr;
                window.open(url,'Preview','width=737,height=693;resizeble=no,scrollbars=yes, toolbar=no, status=yes, menubar=no');
                break;
            case "people":
                url="/YNA/ContentsSales/ContentsData/YISW_PeopleView.aspx?PeopleId=" + contentsID  + '&MenuId=' + menuId;
                window.open(url,'Preview','width=720,height=650;resizeble=no,scrollbars=no, toolbar=no, status=yes, menubar=no');
                break;
            case "article":
                window.open("/YNA/ContentsSales/ContentsData/YISW_articlePreviewPurchase.aspx?contentsid="+contentsID + '&MenuId=32',"Preview",'width=737, height=693, menubar=no, scrollbars=yes, status=yes, help=no');
                break;
        }
    }
    
    /*=======================================================================
    Function명  : CheckSelContents
    내      용  : 장바구니 담기/마이앨범 담기 버튼을 눌렀을 경우 선택한 Photo 체크 및 담기.
    작  성  자  : 박소영[ENET]
    수  정  자  : 이대욱[ENET]
    최초작성일  : 2005년 10월 02일
    ========================================================================*/
    function CheckSelContents(div, id)
    {
        //로그인체크 
        if(!CheckLogin(''))
            return false;
            
        if(id.length == 0)
            id = "hchkSelContent";
            
        var tagInput = document.getElementsByTagName("input");
        var strSelId = "";
        
        for(var i=0; i<tagInput.length; i++)
        {
            if(tagInput[i].type == "checkbox" && tagInput[i].checked  && tagInput[i].id==id)
            {
                if(strSelId.length > 0)
                    strSelId += ",";
                strSelId += tagInput[i].title;
            }   
        }

        if(strSelId.length == 0)
        {
            fn_OpenInformation( '콘텐츠를 선택하세요');
            return false;
        }
        else
        {
            if(div == "0")
            {
                var url='../Order/YISW_conCartAdd.aspx?ContentsID=' + strSelId;
                window.open(url, 'AddCart', 'width=800,height=600,scrollbars=no,resizable=no');
            }
            else if(div == "1")
            {
                var url = "../Order/YISW_conAlbumAdd.aspx?ContentsId=" + strSelId;
                window.open(url, 'AddCart', 'width=800,height=600, resizeble=no,scrollbars=no, toolbar=no, status=no, menubar=no');
            }
            else
            {
                document.getElementById('hfId').value = strSelId;                
                return true;
            }
        }
        
        return false;
    }
    
    /*=======================================================================
    Function명  : ClickHbtnKit
    내      용  : Photo의 장바구니 담기 버튼을 누른 경우 입력 메시지 출력.
    작  성  자  : 박소영[ENET]
    최초작성일  : 2005년 10월 02일


    ========================================================================*/
    function ClickHbtnKit(contentsID)
    {
       if(!CheckLogin(''))
            return false;
            
       var url='../Order/YISW_conCartAdd.aspx?ContentsID=' + contentsID;
       window.open(url, 'AddCart', 'width=800,height=600, resizeble=no,scrollbars=no, toolbar=no, status=no, menubar=no');
    }
    
    /*=======================================================================
    Function명  : ClickHbtnMyAlbum
    내      용  : Photo의 마이앨범 담기 버튼을 누른 경우 입력 메시지 출력.
    작  성  자  : 박소영[ENET]
    최초작성일  : 2005년 10월 02일


    ========================================================================*/
    function ClickHbtnMyAlbum(contentsID)
    {
       if(!CheckLogin(''))
            return false;
       
       var url = "../Order/YISW_conAlbumAdd.aspx?ContentsId=" + contentsID;
       window.open(url, 'AddCart', 'width=800,height=600, resizeble=no,scrollbars=no, toolbar=no, status=no, menubar=no');
    }
    
    /*=======================================================================
    Function명  : BuyImmediately
    내      용  : 프리뷰에서 즉시구매 
    작  성  자  : 이대욱[ENET]
    최초작성일  : 2005년 10월 02일


    ========================================================================*/
    function BuyImmediately(contentsID)
    {
        var menuId = " ";
        
        if(document.getElementById('hhdMenuId') != null)
            menuId = document.getElementById('hhdMenuId').value;
            
        var url="../MyPage/YISW_ImmediatelyBuy.aspx?contentsid=" + contentsID + "&memberid=" + getCookie("YNA_MEMBER_ID") + "&MenuId=" + menuId;
        window.open(url, 'Buy', 'width=800,height=600,resizeble=no, scrollbars=yes, toolbar=no, status=no, menubar=no');
    }
    
    /*=======================================================================
    Function명  : CheckPageRange
    내      용  : 입력한 페이지 번호의 유효성검사 및 메시지 출력.
    작  성  자  : 박소영[ENET]
    최초작성일  : 2005년 10월 03일

    ========================================================================*/
    function CheckPageRange(objName)
    {
        var totalPage = document.getElementById(objName + "_lblTotalPage");
        var selPage = document.getElementById(objName + "_txtSelPage");

        if(selPage.value.length == 0)
        {
            fn_OpenErrorMessage('이동할 페이지를 입력하세요');
            selPage.value = "";
            selPage.focus();        
            return false;
        }
            
        else if (!(/^[1-9][0-9]*$/g.test(selPage.value)) || eval(selPage.value) > eval(totalPage.innerText))
        {
            fn_OpenErrorMessage('페이지를 잘못 입력하셨습니다');
            selPage.value = "";
            selPage.focus();        
            return false;
        }

        return true;    
    }
    
    function CheckPageRangeAndGo(objName)
    {
        var totalPage = document.getElementById(objName + "_lblTotalPage");
        var selPage = document.getElementById(objName + "_txtSelPage");
        
        var keyWord = document.getElementById("ucSearchCtr_txtKeyword");
        var cID = document.getElementById("ucSearchCtr_txtContentsID");
        var sDate = document.getElementById("ucSearchCtr_txtStartDate");
        var eDate = document.getElementById("ucSearchCtr_txtEndDate");

        if(selPage.value.length == 0)
        {
            fn_OpenErrorMessage('이동할 페이지를 입력하세요');
            selPage.value = "";
            selPage.focus();        
            return false;
        }
            
        else if (!(/^[1-9][0-9]*$/g.test(selPage.value)) || eval(selPage.value) > eval(totalPage.innerText))
        {
            fn_OpenErrorMessage('페이지를 잘못 입력하셨습니다');
            selPage.value = "";
            selPage.focus();        
            return false;
        }

        var tURL = "/YNA/ContentsSales/ContentsData/YISW_SearchResult2.aspx?ContentsAttribute=photo&Keyword=" + keyWord.value + "&ContentsID=" + cID.value + "&StartDate=" + sDate.value + "&EndDate=" + eDate.value + "&ContentsType=all&Div=&nDate=0&Research=False&SearchKey=12246616313351&PAGINGTOTALCOUNT=" + totalPage.innerText + "&PAGINGCURRENTPAGE=" + selPage.value + "&PAGINGPAGESIZE=20";
        alert (tURL);
        this.document.URL = tURL;
        
        return true;    
    }
    
       
    
    /*=======================================================================
        Function명  : SetSize
        내      용  : 이미지의 사이즈를 맞춘다. (비율 고정)
        작  성  자  : 박소영[ENET]
        최초작성일  : 2005년 10월 28일

    ========================================================================*/
    function SetSize(originImg, w, h)
    {
        var contents;

        if(originImg != null)
        {
            var newImg = new Image();
            
//            alert(originImg.src.charAt(30));
            
            //잘못 들어온 경로 수정해준다. 
//            if(originImg.src.charAt(30) == '/')
                newImg.src = originImg.src;
//            else
//                newImg.src = 'http://img.contentssales.co.kr/' + originImg.src.substring(30, originImg.src.length-1);
                
//            alert(newImg.src);    
//            alert(w + ' - ' + newImg.width);
//            alert(h + ' - ' + newImg.height);

            if((w / h) < (newImg.width / newImg.height))
            {
                // 원본 너비가 지정한 너비보다 클경우 비율에 맞게 사이즈 조정
                if(w < newImg.width)
                {
                    originImg.style.width = w;
                    originImg.style.height = newImg.height * (w / newImg.width);
                }
                
                // 지정한 너비를 기준으로 강제 사이즈 조정
//                originImg.style.width = w;
//                originImg.style.height = newImg.height * (w / newImg.width);
            }
            else
            {
                // 원본 높이가 지정한 높이보다 클경우 비율에 맞게 사이즈 조정
                if(h < newImg.height)
                {
                    originImg.style.width = newImg.width * (h / newImg.height);
                    originImg.style.height = h;
                }
                
                // 지정한 높이를 기준으로 강제 사이즈 조정
//                originImg.style.width = newImg.width * (h / newImg.height);
//                originImg.style.height = h;
            }
        }
    }
     
    function SetSizeAs(originImg, w, h)
    {
        var contents;
        var tempW, tempH;

        if(originImg != null)
        {
            var newImg = new Image();
            newImg.src = originImg.src;

		    tempW = w;
		    tempH = newImg.height * (w / newImg.width);

            if(h < tempH)
            {
		        tempW = tempW * (h / tempH);
		        tempH = h;
            }

            originImg.style.width = tempW;
            originImg.style.height = tempH;
        }
    } 
     
        
    
    /*=======================================================================
    Function명  : NewWindow
    내      용  : 팝업창을 화면 한가운데 위치시킨다.
    작  성  자  : 홍세진[ENET]
    최초작성일  : 2005년 10월 28일

    ========================================================================*/
    var win=null;
    function NewWindow(mypage,myname,w,h)
    {
	    LeftPosition = (screen.width)?(screen.width-w)/2:100;
	    TopPosition = (screen.height)?(screen.height-h)/2:100;
	    
	    settings = 'width='+w+',height='+h + ',top='+TopPosition+',left='+LeftPosition +',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	    
	    win = window.open(mypage,myname, settings);
	    if(win.focus)
	    {
		    win.focus();
	    }
    }
    
    /*=======================================================================
    Function명  : ClickBtnPage
    내      용  : 페이지 번호를 눌렀을 경우 해당 페이지를 찾는다.
    작  성  자  : 박소영[ENET]
    최초작성일  : 2005년 11월 07일
    ========================================================================*/
    function ClickBtnPage(obj)
    {
        var tmp;
        var pageno = document.getElementById("PageNo");
        
        for (var i = 0; i < 10; i++)
        {
            tmp = "ucContentsListCtr$ctl0" + i;
          
            if (obj == tmp)
            {
                pageno.value = i;        
            }
        }
    }
    
   /*=======================================================================
    Function명  : SetAllCheckBox
    내      용  : 글 목록의 전체 체크박스를 체크한다.  
    작  성  자  : 박소영[ENET]
    최초작성일  : 2005년 11월 09일
    설명:
    ========================================================================*/
   function SetAllCheckBox(obj)
   {
        var tagInput = document.getElementsByTagName("input");
        
        for(var i=0; i<tagInput.length; i++)
        {
            if(tagInput[i].id == obj.id && tagInput[i].type =="checkbox" && tagInput[i].disabled == false)
                tagInput[i].checked = obj.checked;
        }
   }
   
   /*=======================================================================
        Function명  : ArticlePreview
        내      용  : 무료기사 미리보기 
        작  성  자  : 박소영[ENET]
        최초작성일  : 2005년 12월 12일
        설명:
    ========================================================================*/
   function ArticlePreview(contentsid)
   {
        window.open("/YNA/ContentsSales/ContentsData/YISW_articlePreviewPurchase.aspx?contentsid="+contentsid + '&MenuId=32',"Priview",'width=737, height=693, menubar=no, scrollbars=yes, status=yes, help=no');
   }
    
	/*=======================================================================
	Function명	: 페이지 닫기
	작  성  자  : 박소영 이네트
	최초작성일  : 2006년 01월 06일
	최종수정일  : 2006년 01월 06일
	========================================================================*/
	function Close()
	{
		this.close();
	}
	
    /*=======================================================================
	Function명	: 프린트
	작  성  자  : 박소영 이네트
	최초작성일  : 2006년 01월 06일
	최종수정일  : 2006년 01월 06일
	========================================================================*/
	function Print()
	{
		this.print();
	}
		
    /*=======================================================================
    Function명  : SetDefaultImg
    내      용  : 이미지가 없을 때 기본이미지 설정
    작  성  자  : 박소영[ENET]
    최초작성일  : 2006년 01월 05일
    ========================================================================*/
    function SetDefaultImg(originImg, attribute, w, h)
    {
        if(originImg != null)
        {
            if(attribute == "C")
                originImg.src = "/YNA/ContentsSales/Images/prsnNoImg.gif";
            else
                originImg.src = "/YNA/ContentsSales/Images/noimage.gif";
                
            SetSize(originImg, w, h);
        }
    }
    
    
    
