var isIE = (window.navigator.appName.indexOf("Explorer") != -1) ? true : false; // ie ¿©ºÎ

var ezPopLayerID = 'divEzPop';
var ezPopUserNo = '0';
var ezPopUserID = '';
var ezPopIsBoard = false;

function ezOpenBlog() {
	ezAjax.execute("/common/ajax/exec_checkblog.php", "userno="+ezPopUserNo+"&userid="+ezPopUserID, ezExecOpenBlog);
}
function ezExecOpenBlog(req) {
	var value = req.responseText;
	if (value.replace(/ /g, "") != "") {
		window.open(value);
	}
	else {
		alert("ºí·Î±×¸¦ »ý¼ºÇÏÁö ¾Ê¾Ò°Å³ª Å»ÅðÇÑ È¸¿øÀÔ´Ï´Ù.");
	}
}

function ezOpenMemo() {
	ezAjax.execute("/common/ajax/exec_checkuser.php", "userno="+ezPopUserNo, ezExecOpenMemo);
}
function ezExecOpenMemo(req) {
	var value = req.responseText;
	if (value.replace(/ /g, "") != "") {
		window.open(SITE_URL+"/msg/pop_memo_reg.php?userno="+value, "EzMemo", "width=528, height=530, scrollbars=yes");
	}
	else {
		alert("Å»ÅðÇÑ È¸¿øÀÌ°Å³ª È¸¿øÁ¤º¸°¡ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù.");
	}
}

function ezOpenEmail() {
	ezAjax.execute("/common/ajax/exec_checkuser.php", "userno="+ezPopUserNo, ezExecOpenEmail);
}
function ezExecOpenEmail(req) {
	var value = req.responseText;
	if (value.replace(/ /g, "") != "") {
		window.open(SITE_URL+"/msg/pop_email_send.php?userno="+value, "EzEmail", "width=628, height=500");
	}
	else {
		alert("Å»ÅðÇÑ È¸¿øÀÌ°Å³ª È¸¿øÁ¤º¸°¡ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù.");
	}
}

function ezShowBoard() {
	// °Ô½ÃÆÇ¸ñ·Ï && °Ë»öÆû ÀÖ´Â °æ¿ì : ÇöÀç °Ô½ÃÆÇ °Ô½Ã±Û °Ë»ö(ÀÛ¼ºÀÚ¾ÆÀÌµð)
	if (ezPopIsBoard && document.sFrm) {
		document.sFrm.skey.value = 'id';
		document.sFrm.sword.value = ezPopUserID;
		document.sFrm.submit();
	}
	else {
		window.open(SITE_URL+"/search.php?skey=id&sword="+ezPopUserID);
	}
}

function ezGetOffset(obj) {
	var objOffset = { left : 0, top : 0 };
	var objOffsetParent = obj.offsetParent;

	objOffset.left = obj.offsetLeft;
	objOffset.top = obj.offsetTop;

	while (objOffsetParent) {
		objOffset.left += objOffsetParent.offsetLeft;
		objOffset.top += objOffsetParent.offsetTop;

		objOffsetParent = objOffsetParent.offsetParent;
	}

	return objOffset;
}

function ezRegistEvent() {
	if (isIE) {
		document.attachEvent('onclick', ezHidePop);
	}
	else if (document.addEventListener) {
		document.addEventListener('click', ezHidePop, false);
	}
	else if (document.attachEvent) {
		document.attachEvent('click', ezHidePop);
	}
}

function ezUnregistEvent() {
	if (isIE) {
		document.detachEvent('onclick', ezHidePop);
	}
	else if (document.removeEventListener) {
		document.removeEventListener('click', ezHidePop, false);
	}
	else if (document.detachEvent) {
		document.detachEvent('click', ezHidePop);
	}
}

function ezPop(e, userno, userid, isboard) {
	var e = window.event || e;

	ezPopUserNo = userno;
	ezPopUserID = userid;
	ezPopIsBoard = (isboard) ? true : false;

	var objElement = (e.srcElement) ? e.srcElement : e.target;

	setTimeout(function () { ezShowPop(objElement) }, 300);
}

function ezShowPop(objElement) {
	if (!document.getElementById(ezPopLayerID)) ezPopMake();

	var objPos = ezGetOffset(objElement);

	var objEzPop = document.getElementById(ezPopLayerID);
	objEzPop.style.left = objPos.left+"px";
	objEzPop.style.top = objPos.top + objElement.offsetHeight+"px";
	objEzPop.style.display = "block";

	ezRegistEvent();
}

function ezHidePop() {
	ezUnregistEvent();

	var objEzPop = document.getElementById(ezPopLayerID);
	if (objEzPop) objEzPop.style.display = "none";
}

function ezPopOver(objElement) {
	objElement.style.backgroundColor = "#EBF4F6";
}

function ezPopOut(objElement) {
	objElement.style.backgroundColor = "";
}

function ezPopMake() {
	var objDiv = document.createElement('DIV');
	objDiv.id = ezPopLayerID;
	objDiv.style.position = "absolute";
	objDiv.style.left = objDiv.style.top = "0px";
	objDiv.style.zIndex = 100;
	objDiv.style.display = "none";
	objDiv.innerHTML = ezPopGetTable();
	document.body.appendChild(objDiv);
}

function ezPopGetTable() {
	return "\
<table width='110' border='0' cellpadding='3' cellspacing='1' bgcolor='#F29871'><tr><td bgcolor='#FFFFFF'>\
<table width='100%' border='0' cellpadding='0' cellspacing='0'>\
<tr height='18'><td class='board_title_txt' onClick=\"ezOpenMemo()\" onMouseOver='ezPopOver(this)' onMouseOut='ezPopOut(this)' style='cursor:pointer;'>ÂÊÁö º¸³»±â</a></td></tr>\
<tr height='18'><td class='board_title_txt' onClick=\"ezShowBoard()\" onMouseOver='ezPopOver(this)' onMouseOut='ezPopOut(this)' style='cursor:pointer;'>°Ô½Ã±Û º¸±â</a></td></tr>\
</table>\
</td></tr></table>";
}
//<tr height='18'><td class='board_title_txt' onClick=\"ezOpenEmail()\" onMouseOver='ezPopOver(this)' onMouseOut='ezPopOut(this)' style='cursor:pointer;'>¸ÞÀÏ º¸³»±â</a></td></tr>\
//<tr height='18'><td class='board_title_txt' onClick=\"ezOpenBlog()\" onMouseOver='ezPopOver(this)' onMouseOut='ezPopOut(this)' style='cursor:pointer;'>¸¾½ººí·Î±× °¡±â</td></tr>\
/* AJAX Request */
var ezAjax = new Object();
ezAjax.xmlHttpReq = null;

ezAjax.execute = function(url, params, returnExec) {
	ezAjax.xmlHttpReq = ezGetXmlHttpRequest();
	if (ezAjax.xmlHttpReq) {
		url += ((url.indexOf('?') >= 0) ? '&' : '?') + "rnd="+Math.random();

		ezAjax.xmlHttpReq.onreadystatechange = function() {
			if (ezAjax.xmlHttpReq.readyState == 4) {
				returnExec(ezAjax.xmlHttpReq);
				ezAjax.xmlHttpReq = null;
			}
		}

		ezAjax.xmlHttpReq.open("POST", url, true);
		ezAjax.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

		ezAjax.xmlHttpReq.send(params);
	}
}

function ezGetXmlHttpRequest() {
	if (window.XMLHttpRequest) {
		// Create XMLHttpRequest object in non-Microsoft browsers
		return new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		// Create XMLHttpRequest via MS ActiveX
		try {
			// Try to create XMLHttpRequest in later versions
			// of Internet Explorer
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			// Failed to create required ActiveXObject
			try {
				// Try version supported by older versions
				// of Internet Explorer
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				// Unable to create an XMLHttpRequest with ActiveX
			}
		}
	}
	else {
		return null;
	}
}
