var attachObjList = {mask:"", imsg:""}

/*
 * ¸¶½ºÄ«, MsgÀÇ Node ÁöÁ¤ ÇÔ¼ö
 */
function getAppendNode(nid) {
	if (nid == null || nid == "") {
		return (document.compatMode=="CSS1Compat")?document.documentElement:document.body; //create reference to common "body" across doctypes
	} else {
		return document.getElementById(nid);
	}
}


/*
 * ¸¶½ºÅ© ÃÊ±â »ý¼º / Msg ÇÁ·¹ÀÓ »ý¼º ÇÔ¼ö
 */
function setMaskDiv() {
	var tmpMaskNode, tmpMsgNode;
	tmpMaskNode = getAppendNode(attachObjList.mask);
	tmpMsgNode = getAppendNode(attachObjList.imsg);
	var tmpForm  = document.createElement("form");
	var tmpDiv1 = document.createElement("div");
	var tmpDiv2 = document.createElement("div");
	var tmpDiv3 = document.createElement("div");
	try {
		if (tmpForm) {
			tmpForm.setAttribute("id","hfrm");
			tmpForm.setAttribute("name","hfrm");
			tmpForm.setAttribute("target","m2ifr");
		}
		if (tmpDiv1) {
			tmpDiv1.setAttribute("id","cmask");
			tmpDiv1.setAttribute("style","z-index:100");
		}
		if (tmpDiv2) {
			tmpDiv2.setAttribute("id","imsg");
			tmpDiv2.setAttribute("style","z-index:200");
			tmpDiv2.innerHTML = "<iframe name=\"m2ifr\" id=\"m2ifr\" src=\"about:blank\" width=\"300\" height=\"300\" frameborder=\"0\" frame=\"no\" allowTransparency=\"true\" onload=\"initIfraMsg(this.id)\" scrolling=\"no\"><\/iframe>";
		}
		if (tmpDiv3) {
			tmpDiv3.setAttribute("id","isubmsg");
			tmpDiv3.setAttribute("style","z-index:300");
			tmpDiv3.innerHTML = "<iframe name=\"m2ifrsub\" id=\"m2ifrsub\" src=\"about:blank\" width=\"300\" height=\"300\" frameborder=\"0\" frame=\"no\" allowTransparency=\"true\" onload=\"initIfraMsg(this.id)\" scrolling=\"no\"><\/iframe>";
		}
		tmpMaskNode.appendChild(tmpForm);
		tmpMaskNode.appendChild(tmpDiv1);
		tmpMsgNode.appendChild(tmpDiv2);
		tmpMsgNode.appendChild(tmpDiv3);

	} catch(e) {}
	initDiv();
//	initIfraMsg();
}


/*
 * ¸¶½ºÅ© À§Ä¡ ÇÔ¼ö
 */
function initMaskDiv() {
	var tmpBody = (document.compatMode=="CSS1Compat")?document.documentElement:document.body; //create reference to common "body" across doctypes
	var tmpDiv = document.getElementById("cmask");
	var minW = 300, minH = 300;//ÇÊÅÍ¸µ¿µ¿ª
	var maxW = 806, maxH = 800;
	var tmpW = (tmpBody.scrollWidth <= minW)?minW+"px":tmpBody.scrollWidth+"px";
	var tmpH = (tmpBody.scrollHeight <= minH)?minH+"px":tmpBody.scrollHeight+"px";
	if (maxW < tmpBody.clientWidth) tmpW = "100%";
	if (maxH < tmpBody.clientHeight) tmpH = "100%";

	if (tmpDiv) {
		tmpDiv.style.width = tmpW;
		tmpDiv.style.height = tmpH;
	}
}

function toggleMaskDiv() {
	var tmpDiv = document.getElementById("cmask");
	if (tmpDiv) {
		tmpDiv.style.display =(tmpDiv.style.display != "block")?"block":"none";
	}
}


/*
 * ÃÊ±â ·¹ÀÌ¾îÀ§Ä¡ Á¶Á¤ ÇÔ¼ö
 */
function initDiv() {
	initMaskDiv();
}


/*
 * ¸¶½ºÅ©¿Í ¸Þ¼¼Áö Ã¢ÀÇ Z-index °ª º¯°æ
 */
function swapIfraMsg() {
	var tmpDiv = document.getElementById("cmask");
	var tmpIfrDiv = document.getElementById("imsg");
	if (tmpDiv && tmpIfrDiv) {
		var tmpZIndex = tmpDiv.style.zIndex;
		tmpDiv.style.zIndex = tmpIfrDiv.style.zIndex;
		tmpIfrDiv.style.zIndex = tmpZIndex;
	}
}

/*
 * ¸Þ¼¼Áö Ã¢ È°¼ºÈ­ ÇÔ¼ö
 */
function initIfraMsg() {
	var tmpDiv = document.getElementById("cmask");
	var tmpIfrDiv = document.getElementById("imsg");
	var tmpIfrObj = document.getElementById("m2ifr");
	var tmpIfrSubDiv = document.getElementById("isubmsg");
	var tmpIfrSubObj = document.getElementById("m2ifrsub");
	if (tmpDiv && tmpDiv.style.display == "block") {
		if (tmpIfrSubDiv.style.display == "block") {
			posIfraMsg(tmpIfrSubDiv, tmpIfrSubObj);
		} else {
			tmpIfrDiv.style.display = "block";
			posIfraMsg(tmpIfrDiv, tmpIfrObj);
		}
	} else {
		posIfraMsg(tmpIfrDiv, tmpIfrObj);
		if (tmpIfrDiv) tmpIfrDiv.style.display = "none";
		if (tmpIfrSubDiv) tmpIfrSubDiv.style.display = "none";
	}
}


function rePosIfra() {
	var tmpDiv = document.getElementById("cmask");
	var tmpIfrDiv = document.getElementById("imsg");
	var tmpIfrObj = document.getElementById("m2ifr");
	if (tmpDiv && tmpDiv.style.display == "block") {
		posIfraMsg(tmpIfrDiv, tmpIfrObj);
	}
}

/*
 * ¸Þ¼¼Áö Ã¢ À§Ä¡ ¹× »çÀÌÁî Á¶Á¤ ÇÔ¼ö
 */
function posIfraMsg(tDiv, tIfra) {
	var initT = 0;
	var minH = 300, maxH = 800, minW = 300, maxW = 800, scrollT;
	var tmpH, tmpW;
	try {
		if (tIfra) {
			var tmpBody = (document.compatMode=="CSS1Compat")?tIfra.contentWindow.document.documentElement:tIfra.contentWindow.document.getElementsByTagName('body')[0]; //create reference to common "body" across doctypes
			var tmpParent = (document.compatMode=="CSS1Compat")?document.documentElement:document.body; //create reference to common "body" across doctypes
			tmpH = (tmpBody.scrollHeight < minH)?minH:((tmpBody.scrollHeight > maxH)?maxH:tmpBody.scrollHeight);
			tmpW = (tmpBody.scrollWidth < minW)?minW:((tmpBody.scrollWidth > maxW)?maxW:tmpBody.scrollWidth);
			tIfra.style.height = tmpH;
			tIfra.style.width = tmpW;

			maxW = (maxW < tmpParent.scrollWidth)?tmpParent.scrollWidth:maxW;
//			maxH = (maxH < tmpParent.scrollHeight)?tmpParent.scrollHeight:maxH;
			maxH = tmpParent.clientHeight;
			scrollT = tmpParent.scrollTop;
			if (tDiv) {
				tDiv.style.top = (maxH - tmpH < 0)?"0px":initT+((maxH - tmpH)/2)+scrollT+"px";
				tDiv.style.left = ((maxW - tmpW)/2)+"px";
			}
//			alert(tDiv.style.top+"\n"+tDiv.style.left);
//			if (tIfra.document.initFuc) tIfra.document.initFuc();
		}
	} catch(e) { } // about:blank ÀÏ°æ¿ì ÇØ´ç ¼Ó¼º ¾øÀ½ Ã³¸®
}


/*
 * ÆÄ¶ó¹ÌÅÍ Ãß°¡ ÇÔ¼ö
 */
function setFormParams(tFrm, fId, fVal) {
	try {
		if (tFrm) {
			var tmpInput = document.createElement("input");
			if (tmpInput) {
				tmpInput.setAttribute("id",fId);
				tmpInput.setAttribute("name",fId);
				tmpInput.setAttribute("type", "hidden");
				tmpInput.setAttribute("value",fVal);
			}
			tFrm.appendChild(tmpInput);
		}
	} catch(e) {alert(e);}
}


/*
 * ÆÄ¶ó¹ÌÅÍ ÃÊ±âÈ­ ÇÔ¼ö
 */
function clearFormParams(tFrm) {
	if (tFrm) {
		for (var i = 0, loopCount = tFrm.childNodes.length; i < loopCount; i++) {
			tFrm.removeChild(tFrm.childNodes[i]);
		}
	}
}


addLoadEvent(setMaskDiv);
addResizeEvent(initDiv);
addResizeEvent(rePosIfra);