
//parent
function getCookie(strName)
{
	var strArg = new String(strName + "=");	
	var nArgLen, nCookieLen, nEnd;
	var i = 0, j;

	nArgLen    = strArg.length;
	nCookieLen = document.cookie.length;

	
	if(nCookieLen > 0) {
	
		while(i < nCookieLen) {
		
			j = i + nArgLen;
			
			if(document.cookie.substring(i, j) == strArg) {
				nEnd = document.cookie.indexOf (";", j);
				if(nEnd == -1) nEnd = document.cookie.length;
				return unescape(document.cookie.substring(j, nEnd));
			 
			}
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) break;
		}
	}
	
	return("");
}

function OpenPopup()
{	

	var commonLib = new CommonLibary;
	var url = "../process/ajax/popup.php";
	var myAjax = new Ajax.Request(
	url, 
	{
		method: 'post', 
		parameters: {'mode' : "getNowPopup"} ,
		asynchronous: false,
		contentType: 'application/x-www-form-urlencoded',
		encoding:	'UTF-8',
		onSuccess: function(xmlHttp) 
		{
			var resultResponseText = decodeURIComponent(xmlHttp.responseText);	
			
			
			var list = eval('({\"cateList\" :[' +  resultResponseText + ']})');	
			var listRange = new ObjectRange(0,list.cateList.length,true);
			
			listRange.each(function(cnt){
				
				var popup_no		= list.cateList[cnt].popup_no;
				var width			= list.cateList[cnt].popup_width;
				var height			= list.cateList[cnt].popup_height;		
				var top_pos			= list.cateList[cnt].popup_top_position;		
				var left_pos		= list.cateList[cnt].popup_left_position;	
				var popup_type		= list.cateList[cnt].popup_type;	
				var popup_scroll	= list.cateList[cnt].popup_scroll;
				var popup_stop_type = list.cateList[cnt].popup_stop_type;

				var param = {
					"popup_no" : popup_no,
					"width" : width ,
					"height": height ,
					"top"	: top_pos ,
					"left"	: left_pos
					};

				

				var popupUrl = "../program/popup.html?popupNo="+popup_no ;
				
				
				if ( getCookie( "pop_"+ popup_no) != "checked" ) 
				{
					if(popup_type == "window")
						OpenWindowPopup(param,popupUrl, "pop" + cnt);
					else if(popup_type == "layer")
					{
						OpenLayerPopup(param,popupUrl);
					}
				}
			});
		}
	});

	myAjax = null;
}

function OpenWindowPopup(param,popupUrl,name)
{
	var commonLib = new CommonLibary;
	commonLib.WinOpenWithName(param,popupUrl,name);
}

var iframeId = "";
var zIndexStr = 3;

function OpenLayerPopup(param,popupUrl)
{
	 var newDiv =document.createElement('div');
	 var newIframe =document.createElement('iframe');
	 newDiv.id = "popupDiv_" + param['popup_no'];
	 newDiv.name = "popupDiv_" + param['popup_no'];

	 newDiv.style.position='absolute';
	 newDiv.style.width	= param['width'] +  'px';
	 newDiv.style.height = param['height']  +  'px';

	 newDiv.style.top	= param['top'] + 'px';
	 newDiv.style.left	= param['left'] + 'px';
	 newDiv.style.display	= '';
	 newDiv.style.zIndex = zIndexStr;

	 newIframe.id = "popupIframe_" + param['popup_no'];
	 newIframe.name = "popupIframe_" + param['popup_no'];

 	 newIframe.width = '100%';
	 newIframe.height = '100%';
	 newIframe.scrolling = 'no';

   newIframe.src = popupUrl;
	 newDiv.appendChild(newIframe);
	 document.body.appendChild(newDiv);
 	 Event.observe(newIframe,'load',IframeResize);
	 
 	 zIndexStr++;	 
}

function IframeResize()
{	
	try
	{
		
		var commonLib = new CommonLibary;
		var targetObj = commonLib.GetEventTargetObj(event);

		var iframeObj = targetObj; 


		if(iframeObj.readyState == "complete")
		{
			var docu = iframeObj.contentWindow.document;
			var docBody = docu.body;
			
			var div_length = docBody.offsetHeight; 
			var div_width = docBody.offsetWidth;
				
			iframeObj.height =  div_length  + 'px';
			iframeObj.width = div_width  + 'px'; 
		}
	}
	catch (ee)
	{
		alert('잠시후에 다시 접속하여 주십시오. \n\n 감사합니다.');
	}
	

	return false;
}



Event.observe(window,'load',function() {
	OpenPopup();
});

