/**
* utf-8
*/
// 레이어 생성 및 컨트롤
function APM_runPOPUPDiv(id, w, h, x, y, mode, method, skinv, params)
{
	var x = (x) ? x : '';
	var y = (y) ? y : '';

	new elementz.ApmSoftNet.DIVZ(id, w, h, x, y, mode, method, skinv, params);
}

function hiddenPOPUPDiv(id){
	new elementz.ApmSoftNet.DIVZ(id, '', '', '', '', 'hidden', '','','');
}

function APM_runPOPUPProgramMode(mode,v)
{
	var method=APM_runPOPUPProgram;
	new ajax.ApmSoftNet.REQ(popupPhpPath+'/popup.php','',method,'POST','','','','');
}


function APM_runPOPUPProgram(reqs)
{
	var chkcode = 1;
	var today=new Date();
	var txpire= today.getTime();
	
	var _x = 30;
	var _y = 30;
	var _my= 30;
	var tmpwidth = document.body.clientWidth;
	
	var xmlDoc = '';
	var xmlDoc = reqs.responseXML;
	var popupList = xmlDoc.getElementsByTagName('item');
	var popupCount= popupList.length;

	for(var i=0; i<popupCount; i++)
	{
		var popup = popupList.item(i);
		
		var uid		= popup.getElementsByTagName('uid').item(0).firstChild.nodeValue;
		var popupID	= 'popup'+uid;
		
		if(popupOpenId){ //원하는 팝업아이디가 있을경우
			if(popupOpenId == popupID){ chkcode=1; }
			else{ chkcode=-1; }
		}
			
		if(chkcode==1){
			var sdate = popup.getElementsByTagName('sdate').item(0).firstChild.nodeValue;
			var edate = popup.getElementsByTagName('edate').item(0).firstChild.nodeValue;
			var foroneday = popup.getElementsByTagName('foroneday').item(0).firstChild.nodeValue;

			var sdatepire	=new Date("00:00:00 "+sdate);
			var sxpire		=sdatepire.getTime();
			var edatepire	=new Date("23:59:59 "+edate);
			var expire		=edatepire.getTime();
			
			if(sxpire<=txpire && expire>=txpire)
			{	
				
				var sizew	= parseInt(popup.getElementsByTagName('sizew').item(0).firstChild.nodeValue);
				var sizeh	= parseInt(popup.getElementsByTagName('sizeh').item(0).firstChild.nodeValue);			
				var description = popup.getElementsByTagName('description').item(0).firstChild.nodeValue;				
				
				sizeh = sizeh+20;
				
				if(_x+sizew>tmpwidth){
					_x = 100;
					_y = _my;
				}
	
				switch(foroneday){
					case 'n': // 항상출력
						APM_runPOPUPDiv(popupID,sizew,sizeh,_x,_y,'create','','default','');
						new mouse.dnd.SimpleDragSource(popupID);

						// print
						var closeBarHtml = getCloseSkin('n',popupID);
						document.getElementById(popupID).innerHTML = description+closeBarHtml;
						
						_x+= parseInt(sizew)+5;
					break;
					case 'y': // 하루에 한번만
						if (notice_getCookie(popupID) != 'done'){
							APM_runPOPUPDiv(popupID,sizew,sizeh,_x,_y,'create','','default','');
							new mouse.dnd.SimpleDragSource(popupID);
							
							// print
							var closeBarHtml = getCloseSkin('y',popupID);
							document.getElementById(popupID).innerHTML = description+closeBarHtml;
							
						_x+= parseInt(sizew)+5;
						}
					break;
				}
				
				if(sizeh>_my) _my = sizeh;
			}
		}
	}
}

function getCloseSkin(one,id){
	var outhtml = '';
	outhtml = '<div style="background-color:#333333; height:20px; color:#FFFFFF; text-align:right; font-size:12px; padding-right:5px;">'
	
	if(one=='y'){		
		outhtml+= '하루동안 감추기'
		outhtml+= '<input type="checkbox" id="chk'+id+'">'
		outhtml+= "&nbsp;&nbsp;&nbsp;<a href=\"javascript:notice_closeWin('"+id+"');\"><font color='#ffffff'>[닫기]</font></a>"		
	}else{
		outhtml+= "<a href=\"javascript:hiddenPOPUPDiv('"+id+"');\"><font color='#ffffff'>[닫기]</font></a>"
	}
	outhtml+= '</div>';
	
return outhtml;
}

function notice_getCookie( name )
{
	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 notice_setCookie( name, value, expiredays )
{
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

function notice_closeWin(id) 
{ 
	if ( document.getElementById('chk'+id).checked== true){
		notice_setCookie(id, "done" , 1); // 1=하룻동안 공지창 열지 않음
	}
	
	hiddenPOPUPDiv(id);
}
