var popup_zIndex = 9999;
function popupWindow(no,w,h,x,y)
{
	/*** 위치선정 ***/
	var gap = ($('layout_exr')) ? get_objectLeft($('layout_exr')) : 0;
	popup_zIndex++;

	var obj = document.createElement("div");
	obj.setAttribute('id','popupWindow_' + no);
	with (obj.style){
		//border = "1px solid #000000";
		width = (w+2) + "px";
		height = (h+50) + "px";
		position = "absolute";
		top = y + "px";
		left = (x + gap) + "px";
		zIndex = popup_zIndex;
		background = "#ffffff";
		filter = "progid:DXImageTransform.Microsoft.Shadow(color='#505050', Direction=135, Strength=3);";
	}
	obj.onclick = function(){ 
		obj.style.zIndex = ++popup_zIndex;
	} 
	obj.onselectstart = function(){ return false; };
	document.body.appendChild(obj);
	
	var top = document.createElement("div");
	with (top.style){
		//borderBottom = "1px solid #000000";
		//background = "#333333";
		//background = "url('../skin/" + tplSkin + "/img/popup_bg.jpg')";
		background = "url('http://anderson.checkoutshop.co.kr/skin/_sample/img/popup_bg.jpg')";
		height = "17px";
		color = "#ffffff";
		font = "8pt 돋움";
		letterSpacing = "-1px";
		padding = "9px 0 0 8px";
		cursor = "pointer";
	}
	top.onmousedown = downPos;
	top.onmouseup = function(){ isMove = false; }
	//top.onmouseout = function(){ isMove = false; }
	obj.appendChild(top);

	var body = document.createElement("div");
	with (body.style){
		width = (w+2) + "px";
		height = h + "px";
		overflow = "hidden";
		borderLeft = "1px solid #545454";
		borderRight = "1px solid #545454";
		/*background = "#ffffff";*/
	}
	obj.appendChild(body);

	$j.ajax({
		type: "POST",
		url: "../ajax.php",
		data: "mode=ajaxPopup&no=" + no,
		success: function(msg){

			var ret = eval('(' + msg + ')');
			top.innerHTML = ret.title;
			body.innerHTML = ret.contents;

			var close = document.createElement("div");
			with (close.style){
				position = "absolute";
				top = "6px";
				right = "3px";
				color = "#ffffff";
				font = "bold 9px tahoma";
			}
			close.onclick = function(){
				obj.style.left = "-999px";
			}
			//close.innerHTML = "<img src='../skin/" + tplSkin + "/img/popup_close.gif'>";
			close.innerHTML = "<img src='http://anderson.checkoutshop.co.kr/skin/_sample/img/popup_close.gif'>";
			top.appendChild(close);

		}
	});

	var bot = document.createElement("div");
	with (bot.style){
		border = "1px solid #000000";
		background = "#555555";
		height = "23px";
		color = "#ffffff";
		padding = "0 8px 0 0";
		font = "8pt 돋움";
		letterSpacing = -1;
		textAlign= "right";
	}
	bot.innerHTML = "<div style='float:right;padding-top:6px'>팝업 그만보기</div><div style='float:right'><input type=checkbox onclick='popupWindow_close(" + obj.getAttribute('id') + "," + no + ")'></div>";
	obj.appendChild(bot);

	var posX, posY;
	var iciX, iciY;
	var isMove = false;

	function downPos(e){

		isMove = true;
		obj.style.zIndex = ++popup_zIndex;

		posX = event.clientX;
		posY = event.clientY;

		iciX = parseInt(obj.style.left);
		iciY = parseInt(obj.style.top);
		document.onmousemove = movePos;
	}

	function movePos(e){
		if (!isMove) return;
		obj.style.left = iciX + event.clientX - posX;
		obj.style.top = iciY + event.clientY - posY;
		return false;
	}

}

function popupWindow_close(obj,no)
{
	var pw = getCookie('popupWindow');
	var r_pw = pw.split(",");
	if (!r_pw[0]) r_pw = [];
	if (!in_array(no,r_pw)) r_pw.push(no);

	var now = new Date();
	//var expire = new Date(now.getTime() + 60*60*24*1000);
	var expire = new Date(now.getYear(),now.getMonth(),now.getDate(),24,0,0,0);
	setCookie('popupWindow',r_pw,expire);
	obj.parentNode.removeChild(obj);
}
