﻿// 쿠키 가져오기
function GetCookieValue( gckName )
{
	var nameOfCookie = gckName + "=";
	var t = 0;

	while ( t <= document.cookie.length )
	{
		var locd = (t+nameOfCookie.length);
		if ( document.cookie.substring( t, locd ) == nameOfCookie )
		{
			if ( (endOfCookie=document.cookie.indexOf( ";", locd )) == -1 )
			endOfCookie = document.cookie.length;
			return unescape( document.cookie.substring( locd, endOfCookie ) );
		}
		t = document.cookie.indexOf( " ", t ) + 1;
		if ( t == 0 )
			break;
	}
	return "";
}


//메인 팝업 위치 조절 띄우기 // name, width, height, scrolling, resizable, top, left
function OpenPopupEx(url, n, w, h, s, r, top, left) 
{
	winprops = 'height='+h+',width='+w+ ',scrollbars='+s+',resizable=' + r+ ',top='+top+',left='+left 
	win = window.open(url, n, winprops)
	
	if (win != null && parseInt(navigator.appVersion) >= 4) { 
		//win.window.focus(); 
	}
}

// 쿠기저장
function CheckPopChk_SetCookie( name, value, expiredays ) 
{ 
    var todayDate = new Date(); 
    todayDate.setDate( todayDate.getDate() + expiredays ); 
    document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";" 
}

var arrlayer = new Array(10);

function Close(seqno, nCnt, bLayer, bPreview)
{
    if(!bPreview)
        CheckPopChk_SetCookie( "popup"+seqno, "1", 1); 
    
    if(bLayer)
    {
    	document.body.removeChild(arrlayer[nCnt]);
    }
    else
    {
        self.close();
    }
}

function DisplayLayerPopup(strImagefn, nTop, nLeft, nWidth, nHeight, nSeqno, nCnt, strPopupType, strLinkUrl, bLayer, bPreView)
{
    arrlayer[nCnt] = document.createElement('div');    
   
    var strCSS = 'position: absolute;'
			    + 'height: ' + nHeight + 'px;'
			    + 'z-index: 1;'
			    + 'border:solid 1px #000;'
			    + 'background-color:#fff;';
    
    if (bLayer == true && !bPreView)
        strCSS += 'top:' + nTop + 'px;left:' + nLeft + 'px;';
    
    if (!bLayer) 
        strCSS += 'width:100%;';
    else 
        strCSS += 'width: '+ nWidth + 'px;';

    if(strPopupType == 'i')
    {
        if(strLinkUrl == '')
        {
		    strCSS += ' background:url(http://www.iquest.co.kr/_Pop_up/img/' + strImagefn + ');background-repeat:no-repeat;';
		}
		else
		{
		    var image = document.createElement('div'); 
		    var imageCSS = 'margin-top:0px;margin-left:0px;height:' + (parseInt(nHeight,10) - 20) + 'px;overflow:hidden';
		    if (!bLayer) 
                imageCSS += 'width:100%;';
            else 
                imageCSS += 'width: '+ nWidth + 'px;';

            image.style.cssText = imageCSS;
           
            if (bLayer)
            {
                image.innerHTML = '<a href="' + strLinkUrl + '" target="_parent"><img src="http://www.iquest.co.kr/_Pop_up/img/' + strImagefn + '" border="0"></a>';
            }
            else
            {
                image.innerHTML = '<img src="http://www.iquest.co.kr/_Pop_up/img/' + strImagefn + '" border="0" onclick="ImageLink(\'' + strLinkUrl + '\');" style="cursor:pointer;">';
            }
                
            arrlayer[nCnt].appendChild(image);
            
		}
    }
   		
    arrlayer[nCnt].style.cssText = strCSS;
    
    var layerin = document.createElement('div'); 
    var nTopmargin = (parseInt(nHeight,10) - 20);
    if(strPopupType == 'i' && strLinkUrl != '') nTopmargin = 0;
    
    var layerinCSS = 'margin-top:' + nTopmargin + 'px; margin-left:0px;display:block;'
                            + 'margin-bottom:0px;background-color:#000;height:20px; text-align:right;';
    if (!bLayer) 
        layerinCSS += 'width:100%;';
    else 
        layerinCSS += 'width: '+ nWidth + 'px;';
                        
    layerin.style.cssText = layerinCSS; 
                            
                            
    layerin.innerHTML = '<img src="http://www.iquest.co.kr/_Pop_up/img/201004_event_popup_close.jpg" border="0" onClick="javascript:Close(' + nSeqno  + ' , ' + nCnt + ',' + bLayer + ', ' + bPreView + ');" style="cursor:pointer;">';
    
    if(strPopupType == 't')
    {     
		/*var returnValue = new Ajax.Request(
			"/admin/popup/popup_contents_view.asp",
			{method: 'get', parameters: strParams, onSuccess: registResult, onFailure: serverError}
		);
		*/
        
        $.ajax({
			type:"GET",
			data:{"gbn":"getPopupContents",
        	"seqNo":nSeqno},
			dataType:"json",
			url:"/popupInfo.do",
			success:function(data, status) {
	        	var Contents = document.createElement('div'); 
	            var ContentsCSS = 'margin-top:0px;margin-left:0px;height:' + (parseInt(nHeight,10) - 20) + 'px;overflow:hidden;';
	            
	            if (!bLayer) 
	                ContentsCSS += 'width:100%;';
	            else 
	                ContentsCSS += 'width: '+ nWidth + 'px;';
	                
	            Contents.style.cssText = ContentsCSS;
	      
	            Contents.innerHTML = data.contents;
	            
	            layerin.style.margin = 0;
	          
	            arrlayer[nCnt].appendChild(Contents);
	            arrlayer[nCnt].appendChild(layerin);
	            document.body.appendChild(arrlayer[nCnt]);
	        	},
	        	error:function(request, status) {
	        		
	        		//alert(request);
	        		//alert(status);
	        		
	        		//alert('서버에 연결 실패!');
	        		
				}
			});
    }
    else
    {
        arrlayer[nCnt].appendChild(layerin);
        document.body.appendChild(arrlayer[nCnt]);
    }
    
    function serverError(){ alert('서버에 연결 실패!'); }
    function registResult(request)
    {
        var Contents = document.createElement('div'); 
        var ContentsCSS = 'margin-top:0px;margin-left:0px;height:' + (parseInt(nHeight,10) - 20) + 'px;overflow:hidden;';
        
        if (!bLayer) 
            ContentsCSS += 'width:100%;';
        else 
            ContentsCSS += 'width: '+ nWidth + 'px;';
            
        Contents.style.cssText = ContentsCSS;
  
        Contents.innerHTML = request.responseText;   
        
        layerin.style.margin = 0;
      
        arrlayer[nCnt].appendChild(Contents);
        arrlayer[nCnt].appendChild(layerin);
        document.body.appendChild(arrlayer[nCnt]);
        
    }
}

function ImageLink(strLinkUrl)
{
    parent.opener.location.href = strLinkUrl;
    self.close();
}
