﻿var DocParam = "test";
//Html Element 동작을 제어한다. (주)닷넷소프트 유승호
//text box에 입력값이 숫자일 경우에만 입력 받는다.
//		  text box의 onkeypress 이벤트 헨들러로 추가한다.
//		  ex) document.all.txtPrice.onkeypress = fn_CheckNumberBox
function fn_CheckNumberTextBox()
{
	try
	{
		// 허용키 : 8, 13, 27, 48 ~ 57
		if ( window.event.keyCode >= 48 && window.event.keyCode <= 57 )
		{
			window.event.returnValue = true;
			return;
		}
//		if ( window.event.keyCode == 8 && window.event.keyCode == 13 && window.event.keyCode == 27 && window.event.keyCode == 45 )
		if ( window.event.keyCode == 8 || window.event.keyCode == 13 && window.event.keyCode == 27)
		{
			window.event.returnValue = true;
			return;
		}
		window.event.returnValue = false;
	}
	catch ( exception ){}	
}
//숫자와 "-" 만 입력가능
//전화번호 체크할때 사용
function fn_CheckTelNoTextBox()
{
	try
	{
		// 허용키 : 8, 13, 27, 45, 48 ~ 57
		if ( window.event.keyCode >= 48 && window.event.keyCode <= 57 )
		{
			window.event.returnValue = true;
			return;
		}
//		if ( window.event.keyCode == 8 && window.event.keyCode == 13 && window.event.keyCode == 27 && window.event.keyCode == 45 )
		if ( window.event.keyCode == 8 || window.event.keyCode == 13 && window.event.keyCode == 27 || window.event.keyCode == 45 )
		{
			window.event.returnValue = true;
			return;
		}
		window.event.returnValue = false;
	}
	catch ( exception ){}	
}

//text box에 입력값이 소문자이면 대문자로 고친다.
//		  ex) document.all.txtPrice.onkeypress = fn_ConvertToUpperCase
function fn_ConvertToUpperCase()
{
	try
	{
		// 소문자이면 대문자로 변경한다. ( 97(122) -> 65(90) )
		if ( window.event.keyCode >= 97 && window.event.keyCode <= 122 )
			window.event.keyCode = window.event.keyCode - 32;
	}
	catch (exception){}	
}

//작성목적	: text box에 입력값이 소문자이면 대문자로 고친다.
//		  ex) document.all.txtPrice.onkeypress = fn_ConvertToLowerCase
function fn_ConvertToLowerCase()
{
	try
	{
		// 소문자이면 대문자로 변경한다. ( 97(122) <- 65(90) )
		if ( window.event.keyCode >= 65 && window.event.keyCode <= 90 )
			window.event.keyCode = window.event.keyCode + 32;
	}
	catch (exception){}	
}

//ListBox의 선택된 항목 값을 가져온다.
function fn_GetListBoxValue(oListBox)
{
	try
	{
		return oListBox[oListBox.selectedIndex].value;
	}
	catch (exception){}
}

//ListBox에 삽입한다.
function fn_AddListBoxItem(oListBox, sText, sValue)
{
	try
	{
		var oOption = document.createElement("option");
		oOption.text = sText;
		oOption.value = sValue;
		oListBox.add(oOption);
	}
	catch (exception){}
}

//Radion 컨트롤의 이름을 문자열로 전달하면 해당 컨트롤 그룹을 검색하여 checked = true인 컨트롤의 value를 리턴한다.
function fn_GetRadioValue(radioName)
{
	try
	{
		var iCount;
		var strValue;
		
		var oRGroup = document.all[radioName];
		iCount = oRGroup.length;
		for ( var i = 0 ; i < iCount ; i++ )
		{
			if ( oRGroup[i].checked)
			{
				strValue = oRGroup[i].value;
				break;
			}
		}
		return strValue;
	}
	catch ( exception ){}	
}

//Radion 컨트롤의 이름과 값을 문자열로 전달하면 해당 컨트롤 그룹을 검색하여 해당 값을 가진 컨트롤을 체크한다.
function fn_SetRadioValue(radioName, sValue)
{
	try
	{
		var iCount;
		var oRGroup = document.all[radioName];
		iCount = oRGroup.length;
		for ( var i = 0 ; i < iCount ; i++ )
		{
			if ( oRGroup[i].value == sValue )
			{
				oRGroup[i].checked = true;
				break;
			}
		}
	}
	catch (exception){}
}

//해당 이미지 Control을 disable시키고 마우스 모양을 default로 설정한다.
function fn_DisableImageButton(oImgBtn)
{
	try
	{
		oImgBtn.disabled = true;
		oImgBtn.style.cursor = "default";
		oImgBtn.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=30)";
	}
	catch ( exception ){}	
}

//해당 이미지 Control을 Enable시키고 마우스 모양을 hand로 설정한다.
function fn_EnableImageButton(oImgBtn)
{
	try
	{
		oImgBtn.disabled = false;
		oImgBtn.style.cursor = "hand";
		oImgBtn.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
	}
	catch ( exception ){}	
}

//해당 attrName를 갖는 모든 체크박스를 Check한다.
function fn_SetAllCheck(attrName)
{
	var oCheck;
	try
	{
		oCheck = document.all[attrName];
		if(oCheck == null) return;
		if(oCheck.length == null) 
		{
			oCheck.checked = true;
			return;
		}
		if(oCheck.length > 1)
		{
			for(var i = 0 ; i < oCheck.length ; i++)
			{
				if(oCheck[i].disabled == false)oCheck[i].checked = true;
			}
		}
		else
		{
			oCheck.checked = true;
		}
	}
	catch (exception){}
}

//해당 attrName를 갖는 모든 체크박스를 UnCheck한다.
function fn_SetAllUnCheck(attrName)
{
	var oCheck;
	try
	{
		oCheck = document.all[attrName];
		if(oCheck == null) return;
		if(oCheck.length == null) 
		{
			oCheck.checked = false;
			return;
		}
		if(oCheck.length > 1)
		{
			for(var i = 0 ; i < oCheck.length ; i++)
			{
				oCheck[i].checked = false;
			}
		}
		else
		{
			oCheck.checked = false;
		}
	}
	catch (exception){}
}

//해당 Attribute를 갖는 모든 체크박스 중 Check된 항의 배열을 가져온다.
function fn_GetCheckedItems(attrValue)
{
	var oItem;
	var arrReturn;
	var iCnt = 0;
	var idx = 0;
	try
	{
		for ( var i = 0 ; i < document.all.length ; i++ )
		{
			oItem = document.all[i];
			if ( oItem.tagName.toUpperCase() == "INPUT")
				if ( oItem.getAttribute("type").toUpperCase() == "CHECKBOX" )
					if (oItem.getAttribute("chkgrpname") != null )
						if ( oItem.getAttribute("chkgrpname") == attrValue )
							if ( oItem.checked == true )
								iCnt++;
		}
		arrReturn = new Array(iCnt);
		for ( var i = 0 ; i < document.all.length ; i++ )
		{
			oItem = document.all[i];
			if ( oItem.tagName.toUpperCase() == "INPUT")
				if ( oItem.getAttribute("type").toUpperCase() == "CHECKBOX" )
					if (oItem.getAttribute("chkgrpname") != null )
						if ( oItem.getAttribute("chkgrpname") == attrValue )
							if ( oItem.checked == true )
								arrReturn[idx++] = oItem;
		}
		return arrReturn;
	}
	catch (exception){}
	return null;
}

//해당 Control을 절대 위치로 옴긴다.
function fn_MoveControl(oCtrl, posTop, posLeft)
{
	try
	{
		oCtrl.style.position = "absolute";
		oCtrl.style.top = posTop;
		oCtrl.style.left = posLeft;
	}
	catch (exception){}
}

//CheckBox List에서 Check될때 Highlight시킨다. Web Control의 Checkbox List Attribute에 onclick 이벤트로 정의한다.
function fn_HlightCheckboxList()
{
	var oTd = null;
	try
	{
		oTd = window.event.srcElement.parentNode;
		if ( window.event.srcElement.checked == true )
			oTd.style.backgroundColor = '#ffffcc';
		else
			oTd.style.backgroundColor = '#ffffff';
	}
	catch (exception)
	{
		return false;
	}
	return true;
}

//CheckBox List에서 Check될때 Highlight시킨다. Web Control의 Checkbox List Attribute에 onclick 이벤트로 정의한다.
function fn_CheckboxListLoad(checkboxList)
{
	var oTb = null;
	var oTr = null;
	var oTd = null;
	var oChk = null;
	try
	{
		oTb = checkboxList;
		for ( var i = 0 ; i < oTb.rows.length ; i++ )
		{
			oTr = oTb.rows(i);
			oTd = oTr.cells(0);
			oChk = oTd.childNodes(0);
			
			if ( oChk.checked == true )
				oTd.style.backgroundColor = '#ffffcc';
			else
				oTd.style.backgroundColor = '#ffffff';		
		}
	}
	catch (exception){}
}

//그리드확장function fn_GridExpand(oTd,expandUrl,tarGetTd,valueArray)
{
	var oImg = oTd.all[0];
	var strUrl = "";
	var strParams = "";
	var oParam;
	var oXmlDom;
	var oXmlElem;
	try
	{
		if(oTd.ViewFlag == "TRUE") //닫았을때
		{
			oTd.ViewFlag = "FALSE";	
			oImg.src = 	_ExpandPlusImg;	
			document.all[tarGetTd].parentElement.style.display = "none";
			document.all[tarGetTd].all[0].innerHTML = "Loading...Wait...";
		}
		else //확장일때
		{
			oTd.ViewFlag = "TRUE";
			oImg.src = _ExpandMinusImg;
			document.all[tarGetTd].parentElement.style.display = "";
			if(valueArray != null)
			{
				for(var i = 0 ; i < valueArray.length ; i++)
				{
					if(valueArray[i].indexOf('|') > -1)
					{
						oParam = valueArray[i].split('|');
						strParams += "&" + oParam[0] + "=" + escape(oParam[1]);
					}
					else
					{
						strParams += valueArray[i];
					}
				}
				strParams = "_YNAGRID=SUB_" + tarGetTd + strParams;
			}
			strUrl = expandUrl + "?" + strParams;
			fn_GetTreeGridXmlDom(strUrl,tarGetTd);
		}
	}
	catch(exception){}
}

//그리드 전부확장
function fn_GridAllExpand(oGrid)
{
	var oTrGrid;
	var oImg;
	var oGridTemp;
	var oTrItems;
	var oTr;
	var strTemp;
	try
	{
		fn_Progressbar(true);
		oGridTemp = document.all[oGrid];
		oTrItems = oGridTemp.getElementsByTagName("TR");
		oTrGrid = oGridTemp.all[oGrid + "_TR_HEADER"];
		oImg = oTrGrid.all[0].all[0];
		strTemp = oTrGrid.ViewFlag;
		if(oTrGrid.ViewFlag == "TRUE") //닫았을때
		{
			oTrGrid.ViewFlag = "FALSE";	
			oImg.src = 	_ExpandPlusImg;	
		}
		else //확장일때
		{
			oTrGrid.ViewFlag = "TRUE";
			oImg.src = _ExpandMinusImg;
		}
		for(var i = 0 ; i < oTrItems.length ; i++)
		{
			if(document.all[oGrid + "_TR_" + i] != null)
			{
				oTr = document.all[oGrid + "_TR_" + i];
				oTr.children[0].ViewFlag = strTemp;
				oTr.children[0].onclick();
			}
		}
	}
	catch(exception){}
	fn_Progressbar(false);
}

//메인그리드를 위한 페이징function fn_GotoMainPaging(oTemp)
{
	try
	{
		if(oTemp.tagName != "A")
		{
			document.location.href = oTemp.value;
		}
	}
	catch(exception){}
}

//Value값으로 Selected하기
function fn_SelectIndexByValue(oListBox, sValue) 
{
	try
	{		
		if (sValue == ""){return;}
		for (var i = 0; i < oListBox.options.length; i++)
		{
			if (oListBox.options[i].value == sValue)
			{							
				oListBox.selectedIndex = i;
				return;
			}
		} 
	}
	catch(exception){}
}

//트리그리드를 위한 페이징function fn_GotoSubPaging(oTemp)
{
	var strGoToUrl;
	var oParentGrid;
	var oTargetTd;
	try
	{
		if(oTemp.tagName != "A")
		{
			strGoToUrl = oTemp.value;
		}
		else
		{
			strGoToUrl = oTemp.href;
		}
		oTargetTd = oTemp.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
		fn_GetTreeGridXmlDom(strGoToUrl,oTargetTd.id);
		if(oTemp.tagName == "A") return false;
	}
	catch(exception){}
}
    
//그리드 TreeGrid에 뿌려줄 XmlDom생성
function fn_GetTreeGridXmlDom(expandUrl,tarGetTd)
{
	var strTemp = ""; 
	try
	{
		oXmlDom = new ActiveXObject("Microsoft.XMLDOM")
		oXmlDom = fn_GetXmlDomDocument(expandUrl);
		oXmlElem = oXmlDom.getElementsByTagName("HtmlData");
		strTemp = oXmlElem.item(0).text;
		document.all[tarGetTd].all[0].innerHTML = strTemp;
	}
	catch(exception){}
}		

//그리드해더에 이벤트를 주었을때, 이미지 토글
function fn_ColumnHeaderToggle(oHeader)
{
	try
	{
		if(oHeader.parentElement.AlignFlag == "Asc")
		{
			oHeader.parentElement.AlignFlag = "Desc";	
			oHeader.all["HeaderImg"].src = 	_HeaderDescImg;	
		}
		else if(oHeader.parentElement.AlignFlag == "Desc") //확장일때
		{
			oHeader.parentElement.AlignFlag = "Asc";	
			oHeader.all["HeaderImg"].src = _HeaderAscImg;
		}
	}
	catch(exception){}
}

function fn_TreeNodeCheck(node,nodename)
{
	var strTemp = "";
	try
	{
		for(var i = 0 ; i < node.childNodes.length ; i++)
		{
			if(node.childNodes[i].nodeName.toUpperCase() == nodename.toUpperCase())
			{
				strTemp = node.childNodes[i].text;
				break;
			}
		}
		return strTemp;
	}
	catch(exception){}
}

//해당경로의 XML가지고 오function fn_TreeLoadXml(xmlSrc)
{
	var oXmlDoc;
	try
	{
		oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		oXmlDoc = fn_GetXmlDomDocument(xmlSrc);
		oDiv = fn_TreeSubNodeLoad(oXmlDoc.childNodes[1]);
		oXmlDoc = null;
		return oDiv;
	}
	catch(exception){}
}

//트리XmlSrc경로 셋팅
function fn_SetXmlSrc(treeID,treeXmlSrc)
{
	try
	{
		document.all[treeID].XmlSrc = treeXmlSrc;
		fn_TreeOnLoad(treeID);
	}
	catch(exception){}
}

//트리가 처음으로 로딩이 되었을때 초기값 셋팅
function fn_TreeOnLoad(treeID)
{
	var oHtml = "";
	var oTree;
	var oXmlDoc;
	var oDiv;
	try
	{
		oTree = document.all[treeID];
		oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		
		if(oTree.XmlSrc == "")
		{
			if(document.all[treeID + "_XML"] != null)
			{
				oHtml = document.all[treeID + "_XML"].innerText;
				oXmlDoc.loadXML(oHtml);
			}
		}
		else
		{
			oXmlDoc = fn_GetXmlDomDocument(oTree.XmlSrc);
		}
		
		//jaeils 트리콘트롤 아이디를 아래에서 사용하기 위해 전역변수에 저장한다.
		tree_Control_ID = treeID;
		//jaeils 팝업메뉴 사용여부를 체크한다.
		fn_ChkUsePopupMenu(treeID);
		
		if(oXmlDoc.childNodes[1] != null)
		{
			oDiv = fn_TreeSubNodeLoad(oXmlDoc.childNodes[1]);
			oTree.innerHTML = oDiv;	
		}
		oXmlDoc = null;
	}
	catch(exception){}
}

//트리에 해당 XML에 맞는 처리
function fn_TreeSubNodeLoad(treeXmlNode)
{
	var oNode = null;
	var strReturnHtml = "";
	var strNodeId = "";
	var strTitle = "";
	var strHref = "";
	var strDbClick = "";
	var strDbClickScript = "";
    var strNodeXmlSrc = "";
	var strNodeCssText = "";
	var strImgPlus = "";
	var strImgMinus = "";
	var strImgDot = "";
	var strTitleHeadImg = "";
	var strImgPlusStyle = "";
	var strImgMinusStyle = "";
	var strImgDotStyle = "";
	var strTree = "";
	var strSubNodeHtml = "";
	var strZerg = "";
	var strPopupUseParam = "";
	var strCustomPopupParam = "";
	var strCustomPopupParamValue = "";

	try
	{
		for(var i = 0 ; i < treeXmlNode.childNodes.length ; i++)
		{
			oNode = treeXmlNode.childNodes[i];
			strNodeId			= fn_TreeNodeCheck(oNode,"NodeId");
			strTitle			= fn_TreeNodeCheck(oNode,"Title");
			strHref				= fn_TreeNodeCheck(oNode,"Href");
			strDbClick          = fn_TreeNodeCheck(oNode,"DbClick");
			strNodeXmlSrc		= fn_TreeNodeCheck(oNode,"NodeXmlSrc");
			strNodeCssText		= fn_TreeNodeCheck(oNode,"NodeCssText");
			strImgPlus			= fn_TreeNodeCheck(oNode,"ImgPlus");
			strImgMinus			= fn_TreeNodeCheck(oNode,"ImgMinus");
			strImgDot			= fn_TreeNodeCheck(oNode,"ImgDot");
			strTree				= fn_TreeNodeCheck(oNode,"Tree");
			strTitleHeadImg		= fn_TreeNodeCheck(oNode,"TitleHeadImg");
			strCustomPopupParam = fn_TreeNodeCheck(oNode,"CustomPopupParam");
			
			if(oNode.nodeName == "HorizontalLine") //수평라인 넣기
			{
				strReturnHtml += "<table cellpadding='0' cellspacing='0' border='0' width='100%'>";
				strReturnHtml += "	<tr>";
				strReturnHtml += "		<td height=8 valign='top' align=center><img src='/" + WEBROOT + "/" + "Images/ValueAdded/" + fn_GetDnTheme() + "/Mgmt/ig_treeTrans.gif' width='90%' height='1' style='background-color:#D0D0D0;'></td>";
				                                                                                                    
				strReturnHtml += "	</tr>";
				strReturnHtml += "</table>";
				continue;
			}
			
			strImgPlusStyle = "";
			strImgMinusStyle = "";

			if(strNodeXmlSrc == "") { //하위 트리가 없는 경우
				strImgPlusStyle = "STYLE='CURSOR:HAND;VISIBILITY:HIDDEN;DISPLAY:NONE;'";
				strImgMinusStyle = "STYLE='CURSOR:HAND;VISIBILITY:HIDDEN;DISPLAY:NONE;'";
				strImgDotStyle = "STYLE='CURSOR:HAND;DISPLAY:BLOCK;'";
			}
			else { //하위 트리가 있는 경우
				strImgPlusStyle = "STYLE='CURSOR:HAND;'";
				strImgMinusStyle = "STYLE='CURSOR:HAND;DISPLAY:NONE;'";
				strImgDotStyle = "STYLE='CURSOR:HAND;VISIBILITY:HIDDEN;DISPLAY:NONE;'";
			}

			if(strTree != "") {
				strImgPlusStyle = "STYLE='CURSOR:HAND;DISPLAY:BLOCK;'";
				strImgMinusStyle = "STYLE='CURSOR:HAND;DISPLAY:NONE;'";
			}

			strImgPlus = "/" + WEBROOT + "/" + (strImgPlus == "" ? "Images/ValueAdded/" + fn_GetDnTheme() + "/Mgmt/plus1.gif" : strImgPlus); 
			strImgMinus = "/" + WEBROOT + "/" + (strImgMinus == "" ? "Images/ValueAdded/" + fn_GetDnTheme() + "/Mgmt/minus1.gif" : strImgMinus);
			strImgDot =  "/" + WEBROOT + "/" + (strImgDot == "" ? "Images/ValueAdded/" + fn_GetDnTheme() + "/Mgmt/dot1.gif" : strImgDot);

			strImgPlus = "<IMG ID='PLUSIMG' NAME='PLUSIMG' NODEID='" + strNodeId + "' SRC='" + strImgPlus + "' BORDER=0 onclick=\"fn_TreeImgClick(new Array(this,true,'" + strNodeXmlSrc + "'))\" " + strImgPlusStyle + " >"; 
			strImgMinus = "<IMG ID='MINUSIMG' NAME='MINUSIMG' SRC='" + strImgMinus + "' BORDER=0 onclick=\"fn_TreeImgClick(new Array(this,false,'" + strNodeXmlSrc + "'))\" " + strImgMinusStyle + ">";
			strImgDot = "<IMG ID='DOTIMG' NAME='DOTIMG' SRC='" + strImgDot + "' BORDER=0  " + strImgDotStyle + ">";

			//스타일설정
			if(strNodeCssText != "")
			{
				strNodeCssText = " CLASS='" + strNodeCssText + "'";
			}
			else
			{
				strNodeCssText = " CLASS='Lmenu01'";
			}

			//타이틀설정
			if(strTitleHeadImg != "")
			{
				strTitleHeadImg = "<IMG SRC='/" + WEBROOT + "/" + strTitleHeadImg + "' BORDER=0>&nbsp;";
			}

			//Href설정
			strZerg = "";
			if(strHref != "")
			{
				if(strHref.toUpperCase().indexOf("JAVASCRIPT") > -1)
				{
					strZerg = strHref + ";";
				}
				else
				{
					strZerg = "fn_TreeNodeGotoUrl('" + strHref + "');";
				}
			}
			
			//더블클릭 이벤트
			strDbClickScript = "";
			if(strDbClick != "")
			{
				if(strDbClick.toUpperCase().indexOf("JAVASCRIPT") > -1)
				{
					strDbClickScript = " ondblclick=\"" + strDbClick + "\";";
				}
			}
			
			if(this.bUsePopupMenu == true) //jaeils 팝업메뉴 사용
			{
				strPopupUseParam = "NodeID='" + strNodeId + "' NodeTitle='" + strTitle + "' ";
	            
	            if(strCustomPopupParam.length > 0)
	                strCustomPopupParamValue = " CustomParam='" + strCustomPopupParam + "' ";

				strTitle = "<A ID='TITLELABLE' HREF='#' STYLE='CURSOR:HAND;' NAME='TITLELABLE' " + strDbClickScript + " onclick=\"" + strZerg + "fn_TreeNodeClick(this);\" onmousedown=\"javascript:fn_TreeNodeRightBottonClick(this);\">" + strTitleHeadImg + strTitle + "</A>\r\n";
				
			}
			else //jaeils 팝업메뉴 사용안함
			{
				strPopupUseParam = "";
				strCustomPopupParamValue = "";
				strTitle = "<A ID='TITLELABLE' HREF='#' STYLE='CURSOR:HAND;' NAME='TITLELABLE' " + strDbClickScript + " onclick=\"" + strZerg + "fn_TreeNodeClick(this);\">" + strTitleHeadImg + strTitle + "</A>\r\n";
			}
			
			strReturnHtml += "<DIV " + strNodeCssText + " style='width:100%;'>";
			strReturnHtml += "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 CLASS='tbBase'>";
			strReturnHtml += "<TR CLASS='menuBG'><TD width='17'>";
			strReturnHtml +=	strImgPlus;
			strReturnHtml +=	strImgMinus;
			strReturnHtml +=	strImgDot;
			strReturnHtml += "</td><td id='NodeTitle' UsrCss='menuTxt' class='menuTxt' ";
			strReturnHtml += strPopupUseParam; //jaeils 팝업메뉴에서 사용하기위해 추가
			strReturnHtml += strCustomPopupParamValue; //트리 노드마다 팝업메뉴의 아이템이 달라야 하는경우. 값은 트리 생성과정에서 넣어준다.
			strReturnHtml += ">";
			strReturnHtml +=	strTitle;
			strReturnHtml += "</TD></TR></TABLE>";

			//서브Tree가 있는 경우는 그넘의 애들을 셋팅해준다. 자기가 자기를 호출하는 재귀호출.. 앗싸.. -_-+
			strSubNodeHtml = "";
			if(strTree != "")
			{
				for(var j = 0 ; j < oNode.childNodes.length ; j++)
				{
					if(oNode.childNodes[j].nodeName.toUpperCase() == "TREE")
					{
						strSubNodeHtml = fn_TreeSubNodeLoad(oNode.childNodes[j]);
						break;
					}
				}
			}
			
			var strSubNodeStyle;
			if(strSubNodeHtml == "") strSubNodeStyle = " STYLE='DISPLAY:NONE;'";
			
			strReturnHtml += "<TABLE ID='CHILDNODE' NAME='CHILDNODE' " + strSubNodeStyle + " cellSpacing=0 cellPadding=0 border=0 width='100%'><TR><TD>";
			strReturnHtml += strSubNodeHtml;
			strReturnHtml += "</TD></TR></TABLE>";
			
			strReturnHtml += "</DIV>";
		}		
		return strReturnHtml;
	}
	catch(exception){}
}

//해당Url로 이동하기
function fn_TreeNodeGotoUrl(strHref)
{
	top.parent.frames["MiddleFrame"].location.href = strHref;
}

//선택한 노드의 depth구하기function fn_TreeNodeDepth(node)
{
	var nDepth = 0;
	var oNode;
	oNode = node.parentElement.parentElement;
	for(var i = 0 ; i < document.all.length ; i++)
	{
		if(oNode.XmlSrc != null)
		{
			nDepth = i+1;
			break;
		}
		else
		{
			oNode = oNode.parentElement.parentElement.parentElement.parentElement.parentElement;
		}
	}
	return nDepth;
}

//해당노드를 클릭했을때 이미지클릭이벤트 호출해주기function fn_TreeNodeClick(node)
{
	var strPlusImgStyle;
	var strMinusImgStyle;
	var oRootNode;
	var oTitleNodes;
	var strDepth;
	try
	{
		//이미지클릭호출해주기		strPlusImgStyle = node.parentElement.parentElement.childNodes[0].children['PLUSIMG'].style.display;
		strMinusImgStyle = node.parentElement.parentElement.childNodes[0].children['MINUSIMG'].style.display;
		if(strPlusImgStyle.toUpperCase() == "NONE")
		{
			node.parentElement.parentElement.childNodes[0].children['MINUSIMG'].onclick();
		}
		else if(strMinusImgStyle.toUpperCase() == "NONE")
		{
			node.parentElement.parentElement.childNodes[0].children['PLUSIMG'].onclick();
		}
		fn_ChangeTreeImgCss(node); //CSS교환
		return;
	}
	catch(exception){}
}

//이미지의 CSS교환
function fn_ChangeTreeImgCss(node)
{
	var oRootNode;
	try
	{
		//클릭된 노드의 css교환
		oRootNode = node;
		for(var i = 0 ; i < document.all.length ; i++)
		{
			if(oRootNode.parentElement != null)
			{
				oRootNode = oRootNode.parentElement;
				if(oRootNode.XmlSrc != null)
				{
					break;
				}
			}
		}
		oTitleNodes = oRootNode.all["NodeTitle"];
		for(var i = 0 ; i < oTitleNodes.length ; i++)
		{
			if(oTitleNodes[i] == node.parentElement)
			{
				strDepth = fn_TreeNodeDepth(node.parentElement.parentElement.parentElement.parentElement);
				switch(strDepth)
				{
//					case "1": oTitleNodes[i].className = "Selected";break;
//					case "2": oTitleNodes[i].className = "Selected";break;
					default : oTitleNodes[i].className = "Selected";break;
				}
			}
			else
			{
				oTitleNodes[i].className = oTitleNodes[i].UsrCss;
			}
		}			
	}
	catch(exception){}
}

//확장을 위해 이미지를 클릭했을때function fn_TreeImgClick(oNode)
{
	var oParent;
	var onode;
	var	bStatus;
	var strNodeXmlSrc;
	var oHead;
	var oBody;
	var nDepth;
	var oDoc;
	try
	{
		onode = oNode[0];
		bStatus = oNode[1];
		strNodeXmlSrc = oNode[2];
		oParent = onode.parentElement.parentElement.parentElement.parentElement.parentElement.children;
		oHead = oParent[0].children[0].children[0].children[0];
		oBody = oParent[1].children[0].children[0].children[0];
		//Layer교체
		if(oHead.children['DOTIMG'].style.display.toUpperCase() == "BLOCK") return;
		if(bStatus)
		{
			oHead.children['PLUSIMG'].style.display = 'none';
			oHead.children['MINUSIMG'].style.display = 'block';
			if(strNodeXmlSrc != '' && oBody.innerHTML == '') 
			{
				//현노드 depth구하기				nDepth = fn_TreeNodeDepth(oParent[0]);
				if(strNodeXmlSrc.indexOf('?') > 0)
				{
					oDoc = fn_TreeLoadXml(strNodeXmlSrc + '&TreeDepth=' + nDepth);
					oBody.innerHTML = oDoc;
				}
				else
				{
					oDoc = fn_TreeLoadXml(strNodeXmlSrc + '?TreeDepth=' + nDepth);
					oBody.innerHTML = oDoc;
				}
			}
			//하위 항목 보이기			if(oBody.innerHTML != "") oParent[1].style.display = 'block';
		}
		else
		{
			//Layer교체
			oHead.children['PLUSIMG'].style.display = 'block';
			oHead.children['MINUSIMG'].style.display = 'none';
			//하위항목 숨기기			oParent[1].style.display = 'none';
		}
	}
	catch(exception){}
	finally
	{
		oDoc = null;
	}
}

//현재 Row가 선택되었을때, 선택된 Row의 색깔을 바꿔준다.
var bCheckBox = true;
function fn_TrSelected(oTr)
{
	var oTrs;
	try
	{
		oTrs = oTr.parentElement;
		for(var i = 4 ; i < oTrs.children.length ; i = i + 2)
		{
			oTrs.children[i].onmouseout = fn_SetMouseOutClass;
			oTrs.children[i].className = 'trOutL';
		}
		oTr.onmouseout = fn_SetMouseOverClass;
		oTr.className = "trOverL";
	}
	catch(exception)
	{
		fn_OpenErrorMessage(exception.description);
	}
}

function fn_SetMouseOutClass()
{
	this.className = 'trOutL';
}

function fn_SetMouseOverClass()
{
	this.className = 'trOverL';
}

//현재 Row가 선택되었을때, 선택된 Row의 색깔을 바꿔준다.
function fn_SelectedTreeNode(selectedNodeID)
{
	try
	{
		top.parent.frames[1].GetSelectedNodeList(selectedNodeID);
	}
	catch(exception){}
}

function fn_SiteSelectedTreeNode(selectedNodeID)
{
	try
	{
		parent.leftMenu.GetSelectedNodeList(selectedNodeID);
	}
	catch(exception){}
}

//확장그리드에서 Td를 클릭했을때, 해당 Row를 자동으로 확장하도록 해준다.
function fn_TdClickTreeExpand(clickedTr)
{
	try
	{
		var oTr;
		oTr = document.all[clickedTr];
		oTr.childNodes[0].onclick();
	}
	catch(exception){}
}

//======================================================================
//트리 팝업메뉴를 위한 스크립트들... //jaeils
//======================================================================

//jaeils 전역변수
var tree_Control_ID = "";       //트리콘트롤 아이디
var menuPopup = window.createPopup();
var menuItems = new Array();	//메뉴항목이 담길 배열

var menuItemNum = 0;			//메뉴항목의 갯수
var menuWidth = 0;			    //메뉴상자의 가로크기
var menuHeight = 0;			    //메뉴상자의 높이
var menuDelay = 10;				//메뉴 딜레이 시간
var menuSpeed = 3;				//메뉴 로딩 속도
var menuOffset = 0;				//마우스 포인터로부터의 메뉴상자의 거리
var menuContent = "";			//메뉴의 innerHTML
var bUsePopupMenu = false;		//팝업사용여부 저장한 전역변수
function fn_ChkUsePopupMenu(treeID)
{
	var oTree;
	
	try
	{
		oTree = document.all[treeID];

		if(typeof(oTree.MenuXmlSrc) != "undefined")
		{
			if(oTree.MenuXmlSrc != "") //팝업메뉴 항목을 다른 페이지에서(aspx) 가져와야하는 경우 아마도 xmlhttp를 이용해서 메뉴의 XmlDom을 가져올 것이다.
			{
				this.bUsePopupMenu = true;	//팝업메뉴 사용함
			}
			else if(oTree.MenuXmlSrc == "" && document.all[treeID + "_MENU_XML"] != null) //팝업메뉴 항목이 xml파일일 경우 cs에서 textarea에 담아놓은 xml파일의 내용을 가져온다.
			{
				this.bUsePopupMenu = true;	//팝업메뉴 사용함
			}
			else //이도저도 아니면 팝업메뉴를 사용하지 않는것이다.
			{
				this.bUsePopupMenu = false;	//팝업메뉴 사용안함
			}
		}
	}
	catch(exception){}
}

/*=======================================================================
Function명	: 팝업메뉴항목 가져와 세팅
작  성  자  : 김재일 (주)닷넷소프트최초작성일  : 2005년 06월 08일최종수정일  : 2005년 06월 08일========================================================================*/
function fn_GetPopupMenuItems(treeID, customMenuParam)
{
	var oMenuXmlDoc = null;		//팝업메뉴항목 담는 xmldom object
	var oTree;					
	var oMenuHtml = "";
	var oMenuNode = null;
	var strPopupImgUrl = "";
	var strPopupTitle = "";
	var strPopupHref = "";
	var strUserParam = "";
	var PopupMenuXmlNode = null;
	var strXmlUrl = "";
	
	try
	{
		oTree = document.all[treeID];
		oMenuXmlDoc = new ActiveXObject("Microsoft.XMLDOM");

		if(typeof(oTree.MenuXmlSrc) != "undefined")
		{
            //메뉴아이템 담는 변수 초기화
            menuItems = new Array();
            menuItemNum = 0;

			if(oTree.MenuXmlSrc != "") //팝업메뉴 항목을 다른 페이지에서(aspx) 가져와야하는 경우 아마도 xmlhttp를 이용해서 메뉴의 XmlDom을 가져올 것이다.
			{
			    if(oTree.MenuXmlSrc.indexOf("?") < 0)
			        strXmlUrl = oTree.MenuXmlSrc + "?CustomMenuParam=" + customMenuParam;
			    else
			        strXmlUrl = oTree.MenuXmlSrc + "&CustomMenuParam=" + customMenuParam;

				oMenuXmlDoc = fn_GetXmlDomDocument(strXmlUrl);
			}
			else if(oTree.MenuXmlSrc == "" && document.all[treeID + "_MENU_XML"] != null) //팝업메뉴 항목이 xml파일일 경우 cs에서 textarea에 담아놓은 xml파일의 내용을 가져온다.
			{
				oMenuHtml = document.all[treeID + "_MENU_XML"].innerText;
				oMenuXmlDoc.loadXML(oMenuHtml);
			}
			else //이도저도 아니면 팝업메뉴를 사용하지 않는것이다.
			{
				oMenuXmlDoc = null;
			}

			if(this.bUsePopupMenu == true)
			{
				PopupMenuXmlNode = oMenuXmlDoc.childNodes[1];
					
				//xml로 받아온 메뉴항목을 스크립트로 랜더링
				for(var i = 0 ; i < PopupMenuXmlNode.childNodes.length ; i++)
				{
					//Dom에서 팝업메뉴 데이터 추출
					oMenuNode = PopupMenuXmlNode.childNodes[i];

					if(oMenuNode.childNodes.length > 0)
					{
						strPopupImgUrl = fn_TreeNodeCheck(oMenuNode,"ImgUrl");
						strPopupTitle = fn_TreeNodeCheck(oMenuNode,"Title");
						strPopupHref = fn_TreeNodeCheck(oMenuNode,"Href");
						strUserParam = fn_TreeNodeCheck(oMenuNode,"UserParam");
						
						fn_AddPopupMenuItem(strPopupTitle, strPopupHref, strPopupImgUrl, strUserParam);
					}
					else //가로줄이다.
					{
						fn_AddPopupMenuItem("","","","","");
					}
				}
			}
		}
	}
	catch(exception){}
}

/*=======================================================================
Function명	: 팝업메뉴 항목추가
작  성  자  : 김재일 (주)닷넷소프트최초작성일  : 2005년 06월 07일최종수정일  : 2005년 06월 07일========================================================================*/
function fn_AddPopupMenuItem(text, url, img, param)
{
	try
	{
		if(text.length <= 0 && url.length <= 0 && img.length <= 0 && param.length <= 0)
			menuItems[menuItemNum] = new Array();
		else
			menuItems[menuItemNum] = new Array(text, url, img, param);

		menuItemNum++;
	}
	catch(exception){}
}

/*=======================================================================
Function명	: 팝업메뉴 Body
작  성  자  : 김재일 (주)닷넷소프트
최초작성일  : 2005년 06월 07일
최종수정일  : 2005년 06월 07일
========================================================================*/
function fn_CreatePopupMenuBody()
{
	var strTemp = "";
	var nPopupHeight = 0;
	var nPopupWidth = 0;
	
	var strMenuContent_Top = "";
	var strMenuContent_Bottom = "";
	var strThemeFolderName = "";
	
	try
	{
	    strThemeFolderName = fn_GetDnTheme();
	    
		menuContent = "";
		
		for(var m=0;m<menuItems.length;m++)
		{
			if(menuItems[m][1])
			{
				if(menuItems[m][1].indexOf("javascript:") > -1)
					strTemp = "javascript:parent." + menuItems[m][1].split("javascript:")[1];
				else
					strTemp = "javascript:parent." + menuItems[m][1];
			}
			
			if(menuItems[m][0])
			{
				if(nPopupWidth < menuItems[m][0].length * 12)
					nPopupWidth = menuItems[m][0].length * 12;
			}

			if(menuItems[m][0] && menuItems[m][2])
			{
				menuContent += '<tr onmouseover="this.style.background=\'#f1f3f3\'" onmouseout="this.style.background=\'\'" onClick="'+strTemp+'">';
				menuContent += '<a href="#"><td height="22"> </td><td height="22" class="menutxt" style="cursor:hand">' + menuItems[m][0] + '</td></a>';
				menuContent += '</tr>';
				nPopupHeight += 22;
			}
			else if(menuItems[m][0])
			{
				menuContent += '<tr onmouseover="this.style.background=\'#f1f3f3\'" onmouseout="this.style.background=\'\'" onClick="'+strTemp+'">';
				menuContent += '<a href="#"><td height="22"> &middot; </td><td height="22" class="menutxt" style="cursor:hand">' + menuItems[m][0] + '</td></a>';
				menuContent += '</tr>';
				nPopupHeight += 22;
			}
			else
			{
				menuContent += '<tr>';
				menuContent += '<td height="1" colspan="2" style="background:threedhighlight"></td>';
				menuContent += '</tr>';
				nPopupHeight += 1;
			}
		}
		
		this.menuWidth = nPopupWidth + 10;
		this.menuHeight = nPopupHeight + 6;
		
		strMenuContent_Top = '<html>';
		strMenuContent_Top += '<head>';
		strMenuContent_Top += '<title></title>';
		strMenuContent_Top += '</head>';
		strMenuContent_Top += '<body topmargin="0" leftmargin="0" bottommargin="0" rightmargin="0">';
		if(strThemeFolderName.length > 0)
		    strMenuContent_Top += '<link rel="STYLESHEET" type="text/css" href="/' + WEBROOT + '/Images/ValueAdded/' + fn_GetDnTheme() + '/Css/Mgmt/Menu.css">';
		else
		    strMenuContent_Top += '<link rel="STYLESHEET" type="text/css" href="/' + WEBROOT + '/Images/ValueAdded/Css/DomainAdmin/Menu.css">';
		strMenuContent_Top += '<div class="PopupMenu">';
		strMenuContent_Top += '<table class="tbbase" cellspacing="0" cellpadding="0" border="0" onmousedown="document.oncontextmenu=new Function(\'return false\');" ondragstart="return false" onselectstart="return false">';

		strMenuContent_Bottom = '</table>';
		strMenuContent_Bottom += '</div>';
		strMenuContent_Bottom += '</body>';
		strMenuContent_Bottom += '</html>';

		menuContent = strMenuContent_Top + menuContent + strMenuContent_Bottom;

		menuPopup.document.body.innerHTML = menuContent;
	}
	catch(exception){}
}

/*=======================================================================
Function명	: 팝업메뉴 위치 설정
작  성  자  : 김재일 (주)닷넷소프트최초작성일  : 2005년 06월 07일최종수정일  : 2005년 06월 07일========================================================================*/
function fn_ShowMenu()
{
	try
	{
		menuXPos = event.clientX + menuOffset;
		menuYPos = event.clientY + menuOffset;

		menuXIncrement = menuWidth / menuSpeed;
		menuYIncrement = menuHeight / menuSpeed;

		menuTimer = setTimeout("fn_OpenMenu(0,0)", menuDelay);

		return false;
	}
	catch(exception){}
}

/*=======================================================================
Function명	: 팝업메뉴 뛰우기작  성  자  : 김재일 (주)닷넷소프트최초작성일  : 2005년 06월 07일최종수정일  : 2005년 06월 07일========================================================================*/
function fn_OpenMenu(height, width)
{
	try
	{
		iHeight = height;
		iWidth = width;
		
		menuPopup.show(menuXPos, menuYPos, iWidth, iHeight, document.body);

		if(iHeight < menuHeight)
			menuTimer = setTimeout("fn_OpenMenu(iHeight + menuYIncrement, iWidth + menuXIncrement)", 1);
		else
			clearTimeout(menuTimer);
	}
	catch(exception){}
}

/*=======================================================================
Function명	: 트리에서 마우스 오른쪽버튼 클릭 처리
작  성  자  : 김재일 (주)닷넷소프트
최초작성일  : 2005년 06월 07일
최종수정일  : 2005년 06월 07일
========================================================================*/
function fn_TreeNodeRightBottonClick(obj)
{
	var arrMenuItem = new Array();
	var strFunctionName = "";
	var strFunctoinUserParam = "";
	var strNodeID = "";
	var strNodeTitle = "";
	var strCustomMenuParam = "";

	try
	{
		if(event.button==2)
		{
			//트리 바인딩시 넣어주는 노드정보를 가져온다. [팝업메뉴를 위해 넣었다.]
			strNodeID = obj.parentNode.NodeID;
			strNodeTitle = obj.parentNode.NodeTitle;
			strCustomMenuParam = obj.parentNode.CustomParam;

            //메뉴아이템을 가져와 저장한다.
		    fn_GetPopupMenuItems(tree_Control_ID, strCustomMenuParam);

			for(var menuIdx=0; menuIdx<menuItems.length; menuIdx++)
			{
				arrMenuItem = menuItems[menuIdx];
 
				if(arrMenuItem.length >= 2)
				{
					if(arrMenuItem[1].length > 0 && arrMenuItem[1].indexOf("(") > -1)
					{
						strFunctionName = arrMenuItem[1];
						strFunctionName = strFunctionName.split("(")[0]; //함수 이름만 짤라냄 (노드아이디와, 사용자파라미터 넣기위해)
					}
					else if(arrMenuItem[1].length > 0 && arrMenuItem[1].indexOf("(") == -1)
					{
						strFunctionName = arrMenuItem[1];
					}

					strFunctoinUserParam = arrMenuItem[3];	//사용자 파라미터

					//사용자 함수에 파라미터를 더한다.
					strFunctionName += "(new Array('";
					strFunctionName += strNodeID;
					strFunctionName += "','";
					strFunctionName += strNodeTitle;
					strFunctionName += "','";
					strFunctionName += strFunctoinUserParam;
					strFunctionName += "'))";

					//팝업메뉴의 사용자 함수를 재설정한다. (파라미터 포함한 함수) + 메뉴를 안보이게 하는 parent쪽 함수(fn_CloseMenu) 호출
					menuItems[menuIdx][1] = strFunctionName + ";parent.fn_CloseMenu()";
					
					//alert(menuItems[menuIdx][1]);
				}
				strFunctionName = "";
				strFunctoinUserParam = "";
			}

			//배열에 저장된 메뉴항목 데이터에 살을 붙여 메뉴화한다. [팝업메뉴 Body의 HTML구성]
			//메뉴의 항목을 변경해야하기 때문에 처음에 만들어 둘 수 없다. 오른쪽 버튼이 클릭될때마다 만들어야한다.
			fn_CreatePopupMenuBody();
			
			//컨텍스트메뉴 재정의
			obj.oncontextmenu = fn_ShowMenu;
		}
	}
	catch(exception){}
}

/*=======================================================================
Function명	: 팝업메뉴 닫기
작  성  자  : 김재일 (주)닷넷소프트최초작성일  : 2005년 06월 29일최종수정일  : 2005년 06월 29일========================================================================*/
function fn_CloseMenu()
{
	try
	{
		menuPopup.hide();
	}
	catch(exception){}
}