/**
 * 통합문서관리  Javascript 클래스 목록
 * 	- DocumentManagerAtom
 *	- DocumentManagerDataItem
 *	- DocumentManagerBox
 *	- DocumentManagerBoxItemMenu
 *	- DocumentManagerBoxItemAction
 */

function DocumentManagerAtom (strVarName, // 1
							nScriptIndex, // 2
							strRefVarName, // 3
							strTableName, // 4
							strFieldName,
							nDBIndex) // 5
{
	this.m_strVarName = strVarName;
	this.m_nScriptIndex = nScriptIndex;
	this.m_strRefVarName = strRefVarName;
	this.m_strTableName = strTableName;
	this.m_strFieldName = strFieldName;
	this.m_nDBIndex = nDBIndex;
	
	this.m_strKeyCode = "";
	this.m_objDocumentManagerBox = null;
	this.m_heAtom = document.getElementById(this.m_strVarName);
	this.m_heAtom_ICON = document.getElementById(DocumentManagerAtom.ICON + this.m_strVarName);
}
	
DocumentManagerAtom.prototype.getVarName = function ()
{
	return this.m_strVarName;
}

DocumentManagerAtom.prototype.getRefVarName = function ()
{
	return this.m_strRefVarName;
}

DocumentManagerAtom.prototype.getHTML = function ()
{
	// 형만 맞춰놓았음.
}

/**
 * 아톰리스트에 추가
 */
DocumentManagerAtom.prototype.putAtom = function ()
{
	DocumentManagerAtom._atoms[this.m_strVarName] = this;
}

DocumentManagerAtom.prototype.setRefVarName = function (strRefVarName)
{
	this.m_strRefVarName = strRefVarName
}

DocumentManagerAtom.prototype.onClick = function ()
{
	this.m_objDocumentManagerBox.show();
	
	this._hide();
}

DocumentManagerAtom.prototype.onCloseClick = function ()
{
	/**
	 * event delegate
	 */
	this.m_objDocumentManagerBox.onCloseClick();
	
	// DocumentManagerBox에서 Flag를 확인해서 icon 바꿔야 하는지 확인하는 부분 추가해야합니다.
	
	this._show();
}

DocumentManagerAtom.prototype.onMouseDown = function (nIndex, objEvent)
{
	/**
	 * event delegate
	 */
	this.m_objDocumentManagerBox.onMouseDown(nIndex, objEvent);
}


////////////////////////////////////////
// public method

DocumentManagerAtom.prototype.init = function ()
{
	// 아이콘 위치를 가운데로 이동시킵니다.
	this._initIconPosition();
	
	this.m_objDocumentManagerBox = new DocumentManagerBox(this.m_strVarName);
	this.m_objDocumentManagerBox.init(this._getWidth(this.m_heAtom), this._getHeight(this.m_heAtom));
	
	this._changeIcon();
}

DocumentManagerAtom.prototype.setValue = function (strValue)
{
	this.m_objDocumentManagerBox.setValue(strValue);
	
	this._changeIcon();
}

DocumentManagerAtom.prototype.processInquiry = function()
{
	// S 플래그일 경우에는, 조회 요청을 한다.
	if (this.m_objDocumentManagerBox.hasFlag())
	{
		this._executeInquiryRequest();
	}	
}

/**
 * 문서의 유무를 나타내는 '_S_S_' 플래그를 저장하기 위한 요청 정보 생성 
 */
DocumentManagerAtom.prototype.makeRequest = function (xnRequest)
{
	var xnAtom = XmlLib.createChild(xnRequest, "DocumentManager");		

	xnAtom.setAttribute("VarName", this.m_strVarName);
	
	var strValue = this.m_objDocumentManagerBox.getValue();
	
	XmlLib.setTextValue(xnAtom, strValue);
}

/**
 * 폼을 저장할때, 통합문서 파일을 저장하기 위한 요청 정보를 생성한다.
 */
DocumentManagerAtom.prototype.makeUploadRequest = function (xnAtomRequest)
{
	if (this.m_objDocumentManagerBox.isUpdate())
	{
		var xnAtom = XmlLib.createChild(xnAtomRequest, "DocumentManager");		
		xnAtom.setAttribute("VarName", this.m_strVarName);
	
		var xnDBInfo = XmlLib.createChild(xnAtom, "DBInfo");
		xnDBInfo.setAttribute("Table", this.m_strTableName);
		xnDBInfo.setAttribute("Field", this.m_strRefVarName);
		xnDBInfo.setAttribute("InfoField", this.m_strFieldName);
		xnDBInfo.setAttribute("DBIndex", this.m_nDBIndex);
	
		var xnServiceInfo = XmlLib.createChild(xnAtom, "ServiceInfo");
		xnServiceInfo.setAttribute("ServiceType", "Update");
		xnServiceInfo.setAttribute("KeyCode", this._getKeyCode());
	
		this.m_objDocumentManagerBox.makeUploadRequest(xnAtom);
		
		return true;
	}
	return false;
}


////////////////////////////////////////
// private method

DocumentManagerAtom.prototype._initIconPosition = function ()
{
	var nWidth = this._getWidth(this.m_heAtom);
	var nHeight = this._getHeight(this.m_heAtom);
	
	var nIconWidth = this._getWidth(this.m_heAtom_ICON);
	var nIconHeight = this._getHeight(this.m_heAtom_ICON);
	
	var nLeft = nWidth / 2 - nIconWidth / 2;
	var nTop = nHeight / 2 - nIconHeight / 2;
	
	this.m_heAtom_ICON.style.left = nLeft + "px";
	this.m_heAtom_ICON.style.top = nTop + "px";
}

DocumentManagerAtom.prototype._show = function ()
{
	this.m_heAtom_ICON.style.display = "block";
}

DocumentManagerAtom.prototype._hide = function ()
{
	this.m_heAtom_ICON.style.display = "none";
}

DocumentManagerAtom.prototype._changeIcon = function ()
{
	if (this.m_objDocumentManagerBox.hasFlag())
	{
		this._setAtomIcon(true);
	}
	else
	{
		this._setAtomIcon(false);
	}
}

DocumentManagerAtom.prototype._setAtomIcon = function (bAttach)
{
	if (null != this.m_heAtom_ICON)
	{
		var strXpos = bAttach ? "-214px" : "-238px";
		this.m_heAtom_ICON.style.backgroundPositionX = strXpos;
	}
}

DocumentManagerAtom.prototype._getWidth = function (heHTML)
{
	return parseInt(heHTML.style.width);
}

DocumentManagerAtom.prototype._getHeight = function (heHTML)
{
	return parseInt(heHTML.style.height);
}

/**
 * 통합 문서 아톰은 참조 변수명인 아톰의 값을 기본키 값으로 사용하므로,
 * 참조 변수명인 아톰의 접두어가 포함된 value를 얻어온다.
 */
DocumentManagerAtom.prototype._getKeyCode = function ()
{
	if (ContainsInputDataAtom())
	{
		// 참조변수명이 없을 경우 기본키, char 필드 타입, 화면에 보이고, 스크롤에 묶이지 않은 입력란을 사용한다.
		if (0 == this.m_strRefVarName.length)
		{
			var htInputDataAtomList = InputDataAtom.getInputDataList();
			for (var strVarName in htInputDataAtomList)
			{
				if ("" == strVarName)
					continue;
					
				var objAtom = Model.getAtom(strVarName);
				
				if (objAtom.isDefaultKey() && objAtom.isCharFieldType() && 
					objAtom.isVisible() && !objAtom.isScroll())
				{
					this.m_strRefVarName = objAtom.getVarName();
					
					break;
				}
			}
		}
		
		var objAtom = InputDataAtom.getAtom(this.m_strRefVarName);
		
		if (objAtom)
		{
			return objAtom.getValueWithPrefix();
		}
	}
	
	return "";
}

/**
 * DB (DOCUMENT 테이블)의 문서 정보를 조회한다
 */
DocumentManagerAtom.prototype._executeInquiryRequest = function ()
{
	GlobalField.setServiceName("SearchAction");
	GlobalField.setServiceEventName("DocumentManager");
	GlobalField.setEventVarName(this.m_strVarName);
	
	var xnInquiryRequest = MakeRequest.createRequestNode();
	
	this._makeInquiryRequest(xnInquiryRequest);
	
	var xnResultDoc = PQService.executeService(xnInquiryRequest.ownerDocument);
	
	this.m_objDocumentManagerBox.handleInquiryResult(xnResultDoc);
}

/**
 * DB에 문서 정보를 요청하는 정보 생성
 */ 
DocumentManagerAtom.prototype._makeInquiryRequest = function (xnRequest)
{
	MakeRequest.makeServiceRequest(xnRequest);
	
	var xnAtomRequest = MakeRequest.getAtomRequestNode(xnRequest);
	
	var xnAtom = XmlLib.createChild(xnAtomRequest, "DocumentManager");		
	xnAtom.setAttribute("VarName", this.m_strVarName);
	
	var strValue = this.m_objDocumentManagerBox.getValue();
	XmlLib.setTextValue(xnAtom, strValue);
	
	var xnServiceInfo = XmlLib.createChild(xnAtom, "ServiceInfo");		
	xnServiceInfo.setAttribute("ServiceType", "Inquiry");
	xnServiceInfo.setAttribute("Code", this._getKeyCode());
}

DocumentManagerAtom.ICON = "__DOC_MANAGER_ICON_";

/**
 * 아톰리스트
 */
DocumentManagerAtom._atoms = new Object();

DocumentManagerAtom.getAtom = function (strVarName)
{
	return DocumentManagerAtom._atoms[strVarName];
}

DocumentManagerAtom.init = function ()
{
	for (var strVarName in DocumentManagerAtom._atoms)
	{
		var objAtom = DocumentManagerAtom.getAtom(strVarName);
		if (null != objAtom)
		{
			objAtom.init();
		}
	}
}

DocumentManagerAtom.makeRequest = function (xnAtomRequest)
{
	for (var strVarName in DocumentManagerAtom._atoms)
	{
		var objAtom = DocumentManagerAtom.getAtom(strVarName);
		if (null != objAtom)
		{
			objAtom.makeRequest(xnAtomRequest);
		}
	}
}

DocumentManagerAtom.makeUploadRequest = function (xnAtomRequest)
{
	var bUpdate = false;
	
	for (var strVarName in DocumentManagerAtom._atoms)
	{
		var objAtom = DocumentManagerAtom.getAtom(strVarName);
		if (null != objAtom)
		{
			if (objAtom.makeUploadRequest(xnAtomRequest))
			{
				bUpdate = true;
			}
		}
	}
	
	return bUpdate;
}

DocumentManagerAtom.onClick = function (strVarName)
{
	var objAtom = DocumentManagerAtom.getAtom(strVarName);
	if (null != objAtom)
	{
		objAtom.onClick();
	}
}

DocumentManagerAtom.onCloseClick = function (strVarName)
{
	var objAtom = DocumentManagerAtom.getAtom(strVarName);
	if (null != objAtom)
	{
		objAtom.onCloseClick();
	}
}

DocumentManagerAtom.onMenuClick = function (strVarName, nMenuIndex)
{
	var objAtom = DocumentManagerAtom.getAtom(strVarName);
	if (null != objAtom)
	{
		objAtom.onMenuClick(nMenuIndex);
	}
}

DocumentManagerAtom.onMouseDown = function (strVarName, nIndex, objEvent)
{
	if (window.event)
	{
		objEvent = window.event;
	}
	
	var objAtom = DocumentManagerAtom.getAtom(strVarName);
	if (null != objAtom)
	{
		objAtom.onMouseDown(nIndex, objEvent);
	}
}


//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
/**
 * DOCUMENT 테이블의 문서 하나에 해당하는 정보를 가진 클래스
 */
function DocumentManagerDataItem (strCode, nSerial, nDataType, nDocType, strDocSubject, bFromDB)
{
	this.m_strCode = strCode;				// 기본키, 폼을 구별
	this.m_nSerial = nSerial;				// 기본키, 폼에 속하는 몇번재 문서인지를 나타냄
	this.m_nDataType = nDataType;			// 파일의 종류 (이미지, 문서)
	this.m_nDocType = nDocType;				// 문서의 종류 (거래, 증빙, 사양, 행정, 참고)
	this.m_strDocSubject = strDocSubject;	// 문서 제목
	
	this.m_bFromDB = bFromDB;				// DB에 현재 존재하는 데이터인지
	this.m_nOperationType = DocumentManagerDataItem.NOOPERATION;		// 없음(0), 삽입(1), 수정(2), 삭제(3)

	this.m_strWebPath = "";				// 웹문서일때 경로
	this.m_nInputIndex = -1;				// 새로 삽입 되는 데이터의 <input> 리스트 index 번호
	this.m_nMenuIndex = -1;			// 문서 제목 메뉴상의 위치
									// (-1 : 객체는 존재하나, 메뉴에는 표시 되지 않는 상태. DB에 있는 데이터를 삭제 하였을 경우)	
}

////////////////////////////////////////
// getter / setter

DocumentManagerDataItem.prototype.getCode = function ()
{
	return this.m_strCode;
}

DocumentManagerDataItem.prototype.getSerial = function ()
{
	return this.m_nSerial;
}

DocumentManagerDataItem.prototype.getDataType = function ()
{
	return this.m_nDataType;	
}

DocumentManagerDataItem.prototype.getDocType = function ()
{
	return this.m_nDocType;	
}

DocumentManagerDataItem.prototype.getSubject = function ()
{
	return this.m_strDocSubject;	
}

DocumentManagerDataItem.prototype.setSubject = function (strSubject)
{
	this.m_strDocSubject = strSubject;	
}

DocumentManagerDataItem.prototype.fromDB = function ()
{
	return this.m_bFromDB;
}

DocumentManagerDataItem.prototype.getInputIndex = function ()
{
	return this.m_nInputIndex;
}

DocumentManagerDataItem.prototype.setInputIndex = function (nIndex)
{
	this.m_nInputIndex = nIndex;
}

DocumentManagerDataItem.prototype.setOperationType = function (nType)
{
	this.m_nOperationType = nType;	
}

DocumentManagerDataItem.prototype.getWebPath = function ()
{
	return this.m_strWebPath;	
}

DocumentManagerDataItem.prototype.setWebPath = function (strPath)
{
	this.m_strWebPath = strPath;
}

DocumentManagerDataItem.prototype.getMenuIndex = function()
{
	return this.m_nMenuIndex;
}

DocumentManagerDataItem.prototype.setMenuIndex = function(nMenuIndex)
{
	this.m_nMenuIndex = nMenuIndex
}

////////////////////////////////////////
// public method

/**
 * DataItem 객체가 변경 되었으면, 저장 하기 위한 요청 정보를 생성한다.
 * 
 */
DocumentManagerDataItem.prototype.makeUploadRequestNode = function()
{
	if (DocumentManagerDataItem.NOOPERATION == this.m_nOperationType)
	{
		return null;
	}
	
	var xmlNode = XmlLib.createXML("Document");
	var xmlDoc = XmlLib.selectSingleNode(xmlNode, "./Document");
	
	xmlDoc.setAttribute("DocOperation", this.m_nOperationType);
	xmlDoc.setAttribute("DocSerial", this.m_nSerial);
	
	if (DocumentManagerDataItem.MODIFY == this.m_nOperationType)
	{
		xmlDoc.setAttribute("DocSubject", this.m_strDocSubject);
	}
	
	if (DocumentManagerDataItem.INSERT == this.m_nOperationType)
	{
		xmlDoc.setAttribute("DocDataType", this.m_nDataType);
		xmlDoc.setAttribute("DocumentType", this.m_nDocType);
		xmlDoc.setAttribute("DocSubject", this.m_strDocSubject);
		
		if (DocumentManagerDataItem.WEBDOCUMENT == this.m_nDataType)
		{
			xmlDoc.setAttribute("WebURL", this.m_strWebPath);
		}
		else
		{
			xmlDoc.setAttribute("InputIndex", this.m_nInputIndex);
		}
	}
	
	return xmlDoc;
}

// DATA_TYPE에 해당하는 값
DocumentManagerDataItem.SCANIMAGE = 0;
DocumentManagerDataItem.FILEIMAGE = 1;
DocumentManagerDataItem.FILEDOCUMENT = 2;
DocumentManagerDataItem.WEBDOCUMENT = 3;
DocumentManagerDataItem.NTOADOCUMENT = 4;

// Operation type에 해당하는 값
DocumentManagerDataItem.NOOPERATION = 0;
DocumentManagerDataItem.INSERT = 1;
DocumentManagerDataItem.MODIFY = 2;
DocumentManagerDataItem.DELETE = 3;



//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
function DocumentManagerBox (strVarName)
{
	this.m_strVarName = strVarName;
		
	this.m_arDocumentManagerBoxItemList = new Array();
	
	// Action Dialog의 화면 표시 여부
	this.m_bActionDialogOpen = false;
	
	/**
	 * 각 문서 객체가 메뉴와 버튼창은 하나만 만들어서 공유합니다.
	 * 선택된 각 문서의 아이콘에 대한 메뉴와 관리창을 인식하기 위한 참조입니다.
	 */
	this.m_objSelectDocumentManagerBoxItem = null;
	
	/**
	 * 메뉴와 버튼창은 하나만 만들어서 공유하기 위해 BOX에서 생성합니다.
	 */
	this.m_objDocumentManagerBoxItemMenu = null;
	this.m_objDocumentManagerBoxItemAction = null;
	this.m_objFileUploadComponent = null;
	
	this.m_heAtom_BOX = document.getElementById(DocumentManagerBox.BOX+ this.m_strVarName);
}	
	
////////////////////////////////////////
// event handler

DocumentManagerBox.prototype.onCloseClick = function ()
{
	this._hide();
}

DocumentManagerBox.prototype.onMouseDown = function (nIndex, objEvent)
{
	if (this.m_bActionDialogOpen)	// Action Dialog 가 열려 있으면, 이벤트 막음
	{
		return ;		
	}
	
	this.m_objSelectDocumentManagerBoxItem = this.m_arDocumentManagerBoxItemList[nIndex];
	
	// event delegate
	
	this.m_objSelectDocumentManagerBoxItem.onMouseDown(objEvent);
}

DocumentManagerBox.prototype.onChange = function (strValue)
{
	var strSrc = this._getFileExtension(strValue).toLowerCase();
	/*
	if ("" == strSrc)
	{
		alert('올바른 파일을 입력하세요');
		return;
	}
	else if ( !("gif" == strSrc || "jpg" == strSrc || "jpeg" == strSrc || "bmp" == strSrc))
	{
		alert('gif 와 jpg 파일만 지원합니다.');
		return;
	}
	*/

	this.m_objSelectDocumentManagerBoxItem.onChange();
}

DocumentManagerBox.prototype.onCancel = function ()
{
	this.m_objFileUploadComponent.hide();
}


////////////////////////////////////////
// public method

DocumentManagerBox.prototype.init = function (nWidth, nHeight)
{
	// 아이콘 위치를 가운데로 이동시킵니다.
	this._initIconPosition(nWidth, nHeight);
	
	this._createDialog();
	
	this._createDocumentManagerItem();
	
	this.setValue("");
}

DocumentManagerBox.prototype.setValue = function (strValue)
{
	this._clearAllSubjectMenuItem();
	
	// S 위치 확인해서 해당 위치의 DocumentManager icon 바꾸기
	if (null == strValue || 0 == strValue.length)
	{
		strValue = DocumentManagerBox.EMPTY_FLAG;
	}
	
	for (var i = 0; i < DocumentManagerBox.DOC_COUNT; i=i+1)
	{
		this.m_arDocumentManagerBoxItemList[i].setValue(strValue.charAt(i));
	}
}

DocumentManagerBox.prototype.getValue = function ()
{
	var strFlag = "";
	
	for (var i = 0; i < DocumentManagerBox.DOC_COUNT; i=i+1)
	{
		strFlag += this.m_arDocumentManagerBoxItemList[i].getValue();
	}
	return strFlag;
}

DocumentManagerBox.prototype.show = function ()
{
	this.m_heAtom_BOX.style.display = "block";
}

DocumentManagerBox.prototype.hasFlag = function ()
{
	for (var i = 0; i < DocumentManagerBox.DOC_COUNT; i=i+1)
	{
		if (this.m_arDocumentManagerBoxItemList[i].hasFlag())
		{
			return true;
		}
	}
	
	return false;
}

DocumentManagerBox.prototype.setActionDialogState = function (bState)
{
	this.m_bActionDialogOpen = bState;
}

DocumentManagerBox.prototype.isUpdate = function ()
{
	// TODO : 통합문서 저장 정보가 수정 되었는지를 리턴
	return true;
}

DocumentManagerBox.prototype.makeUploadRequest = function (xnAtom)
{
	for (var i = 0; i < DocumentManagerBox.DOC_COUNT; i=i+1)
	{
		this.m_arDocumentManagerBoxItemList[i].makeUploadRequest(xnAtom);
	}
}

/**
 * DB에서 받은 문서정보를 처리한다.
 */
DocumentManagerBox.prototype.handleInquiryResult = function (xnResultDoc)
{
	var xnResult = HandleResult.getAtomResultNode(xnResultDoc);
	var xnDataRowList = XmlLib.selectNodeList(xnResult, "./DocumentManager/DataRow");
	
	if (null == xnDataRowList || 0 == xnDataRowList.length)
	{
		this.setValue("");
		return;
	}

	var nLen = xnDataRowList.length;
	for (var i = 0; i < nLen; i=i+1)
	{
		this._createDataItem(xnDataRowList[i]);
	}
	
	// 문서가 있을 경우에만 box item 표시를 하도록 한다.
	for (var j = 0; j < DocumentManagerBox.DOC_COUNT; j=j+1)
	{
		this.m_arDocumentManagerBoxItemList[j].refresh();
	}
	
	var strDocInfo = XmlLib.selectSingleNode(xnResult, "./DocumentManager").getAttribute("DocumentInfo")
	
	if (null != strDocInfo && 0 < strDocInfo.length)
	{
		var arInfo = strDocInfo.split(";");
		this.m_arDocumentManagerBoxItemList[1].setDocRegisterNumber(arInfo[2]);
	}
}

/**
 * 전체 5개의 boxitem에 속한 data item 중에서 가장 큰 serial 값 리턴
 */
DocumentManagerBox.prototype.getHighestSerial = function ()
{
	var nHighSerial = 0;
	var nSerial = 0;
	
	for (var i = 0; i < DocumentManagerBox.DOC_COUNT; i=i+1)
	{
		nSerial = this.m_arDocumentManagerBoxItemList[i].getHighestSerial();
		
		if (nSerial > nHighSerial)
		{
			nHighSerial = nSerial;
		}
	}
	
	return nHighSerial;
}

////////////////////////////////////////
// private method

DocumentManagerBox.prototype._initIconPosition = function (nWidth, nHeight)
{
	var nIconWidth = parseInt(this.m_heAtom_BOX.style.width);
	var nIconHeight = parseInt(this.m_heAtom_BOX.style.height);
	
	var nLeft = nWidth / 2 - nIconWidth / 2;
	var nTop = nHeight / 2 - nIconHeight / 2;
	
	this.m_heAtom_BOX.style.left = nLeft + "px";
	this.m_heAtom_BOX.style.top = nTop + "px";
}

DocumentManagerBox.prototype._createDialog = function ()
{
	this.m_objDocumentManagerBoxItemMenu = new DocumentManagerBoxItemMenu(this.m_strVarName);
	this.m_objDocumentManagerBoxItemAction = new DocumentManagerBoxItemAction(this.m_strVarName);
	
	this.m_objFileUploadComponent = new FileUploadComponent(this, this.m_strVarName);
	this.m_objFileUploadComponent.initMulti();
}

DocumentManagerBox.prototype._createDocumentManagerItem = function ()
{
	for (var i = 0; i < DocumentManagerBox.DOC_COUNT; i=i+1)
	{
		var objDocumentManagerBoxItem = new DocumentManagerBoxItem(this.m_strVarName, i, this,
				this.m_objDocumentManagerBoxItemMenu, this.m_objDocumentManagerBoxItemAction, this.m_objFileUploadComponent);
		
		this.m_arDocumentManagerBoxItemList.push(objDocumentManagerBoxItem);
	}
}

DocumentManagerBox.prototype._hide = function ()
{
	this.m_heAtom_BOX.style.display = "none";
}

/**
 * DOCUMENT 테이블의 row(문서 하나)에 해당하는 객체 생성
 */
DocumentManagerBox.prototype._createDataItem = function (xnDataRow)
{
	var xnColumns = xnDataRow.childNodes;
	var nLen = xnColumns.length;
	
	if (5 != nLen)
	{
		return ;
	}
	
	var strCode = XmlLib.getTextValue(xnColumns[0]);
	var nSerial = parseInt(XmlLib.getTextValue(xnColumns[1]));
	var nDataType = parseInt(XmlLib.getTextValue(xnColumns[2]));
	var nDocType = parseInt(XmlLib.getTextValue(xnColumns[3]));
	var strDocSubject = XmlLib.getTextValue(xnColumns[4]);
	
	var objDataItem = new DocumentManagerDataItem(strCode, nSerial, nDataType, nDocType, strDocSubject, true);
	
	this.m_arDocumentManagerBoxItemList[nDocType].addDataItem(objDataItem);
	
	this.m_arDocumentManagerBoxItemList[nDocType].setKeyCode(strCode);
	
	// 제목을 표시하도록 메뉴에 추가
	this.m_arDocumentManagerBoxItemList[nDocType].addSubject(strDocSubject);
}

/**
 * 제목 표시 메뉴 항목을 모두 삭제 한다.
 */
DocumentManagerBox.prototype._clearAllSubjectMenuItem = function ()
{
	for (var nIndex = 0; nIndex < DocumentManagerBox.DOC_COUNT; nIndex=nIndex+1)
	{
		var heAtom_BOX_ITEM_SUBJECT = document.getElementById(DocumentManagerBoxItem.ITEM_SUBJECT + '_' + nIndex + '_' + this.m_strVarName);
		var nLen = heAtom_BOX_ITEM_SUBJECT.childNodes[0].childNodes.length;
		
		for (var i = 0; i < nLen; i=i+1)
		{
			var objChild = heAtom_BOX_ITEM_SUBJECT.childNodes[0].childNodes[0];
			
			heAtom_BOX_ITEM_SUBJECT.childNodes[0].removeChild(objChild);
		}
		
		heAtom_BOX_ITEM_SUBJECT.style.visibility = "hidden";
	}
	
	for (var i = 0; i < this.m_arDocumentManagerBoxItemList.length; i=i+1)
	{
		this.m_arDocumentManagerBoxItemList[i]._clearItem();
	}
}

// 파일의 확장자를 가져옮	
DocumentManagerBox.prototype._getFileExtension = function (strFilePath)
{
	var nLastIndex = -1;
	nLastIndex = strFilePath.lastIndexOf('.');
	
	var strExtension = "";
	
	if (nLastIndex != -1)
	{
		strExtension = strFilePath.substring(nLastIndex + 1, strFilePath.length);
	}
	else
	{
		strExtension = "";
	}
	
	return strExtension;
}

DocumentManagerBox.BOX = "__DOC_MANAGER_BOX_";
DocumentManagerBox.DOC_COUNT = 5;

// empty flag 5byte space
DocumentManagerBox.EMPTY_FLAG = "     ";



function DocumentManagerBoxItem (strVarName, nIndex, objOwner,
		objDocumentManagerBoxItemMenu, objDocumentManagerBoxItemAction, objFileUploadComponent)
{
	this.m_strVarName = strVarName;
	this.m_strKeyCode = "";
	
	this.m_objOwner = objOwner;
	
	this.m_nIndex = nIndex;			// 몇번째 문서 종류 아이템 인지를 나타내는 index
	this.m_nMenuTypeIndex = -1;		// 이미지, 파일, 웹문서 메뉴중 어느것을 눌렀는가를 나타냄
	this.m_nSelectedMenuIndex = -1;	// 제목 메뉴에서 어떤 항목을 선택했는가를 나타냄
	this.m_nSubjectMenuLength = 0;	// 제목 메뉴의 항목 개수, 새로운 문서를 추가할때, 그 문서의 메뉴 index가 된다.
	
	this.m_heAtom_BOX_ITEM = document.getElementById(DocumentManagerBoxItem.ITEM + '_' + this.m_nIndex + '_' + strVarName);
	this.m_heAtom_BOX_ITEM_SUBJECT = document.getElementById(DocumentManagerBoxItem.ITEM_SUBJECT + '_' + this.m_nIndex + '_' + strVarName);

	/**
	 * 메뉴 하나를 공유해서 사용합니다.
	 */
	this.m_objDocumentManagerBoxItemMenu = objDocumentManagerBoxItemMenu;
	this.m_objDocumentManagerBoxItemAction = objDocumentManagerBoxItemAction;
	this.m_objFileUploadComponent = objFileUploadComponent;
	
	this.m_strFlag = "";
	this.m_strDocRegisterNumber = "";	
	
	this.m_arDataItemList = new Array();
	
	this.m_objDocViewWindow = null;		// 문서정보(이미지,웹)를 보여주는 modal 팝업창
}

DocumentManagerBoxItem.prototype.setDocRegisterNumber = function (strRegister)
{
	this.m_strDocRegisterNumber = strRegister;
}

////////////////////////////////////////
// event handler

DocumentManagerBoxItem.prototype.onMouseDown = function (objEvent)
{		
	// 오른쪽 클릭
	if (2 == objEvent.button)
	{
		this._openMenu();
	}
	// 왼쪽 클릭
	else
	{
		if ((is_ie && 1 == objEvent.button) || (is_nav && 0 == objEvent.button))
		{
			// if has doc 
			// then show dialog
			if (!this._emptyFlag())
			{
				this._showSubjectMenu();
			}
		}
	}
}	

DocumentManagerBoxItem.prototype.onMenuClick = function (nIndex)
{
	/**
	 * event delegate
	 */
	this.m_objDocumentManagerBoxItemMenu.hide();
	
	this.m_nMenuTypeIndex = nIndex;		// 메뉴의 index
	
	// 파일선택, 저장, 취소 모드로 연다.
	// nMenuIndex : 0:이미지, 1:문서, 2:웹문서
	this.m_objDocumentManagerBoxItemAction.init(this, nIndex, true);
	
	this.m_objDocumentManagerBoxItemAction.show();
	this.m_objOwner.setActionDialogState(true);
}

DocumentManagerBoxItem.prototype.onButtonOpenClick = function ()
{	
	this.m_objFileUploadComponent.show();
}

DocumentManagerBoxItem.prototype.onButtonSaveClick = function ()
{
	var strSubject = this.m_objDocumentManagerBoxItemAction.getSubject();
	var strPath = this.m_objDocumentManagerBoxItemAction.getPath();
	
	if (0 == strSubject.length)
	{
		alert ("제목을 입력 해야 합니다.");
		return;		
	}
	
	if (0 == strPath.length)
	{
		alert ("경로를 선택해야 합니다.");
		return;
	}
	
	// (input list의 길이 - 1)가 현재 저장할 파일의 index가 된다.
	var nInputIndex = this.m_objFileUploadComponent.getCount() - 1;
	
	this._addFile(strSubject, strPath, this.m_nMenuTypeIndex + 1, nInputIndex);
	
	this.m_objDocumentManagerBoxItemAction.hide();
	this.m_objOwner.setActionDialogState(false);
}

DocumentManagerBoxItem.prototype.onButtonCancelClick = function ()
{
	this.m_objDocumentManagerBoxItemAction.hide();
	this.m_objOwner.setActionDialogState(false);
	
	if (null != this.m_objDocViewWindow)
	{
		this.m_objDocViewWindow.close();
	}
}

DocumentManagerBoxItem.prototype.onButtonDeleteClick = function ()
{
	if (window.confirm("이 문서를 삭제하시겠습니까?"))
	{
		this._removeSubject(this.m_nSelectedMenuIndex);
		
		this.m_objDocumentManagerBoxItemAction.hide();
		this.m_objOwner.setActionDialogState(false);
		
		if (null != this.m_objDocViewWindow)
		{
			this.m_objDocViewWindow.close();
		}
	}
}

DocumentManagerBoxItem.prototype.onButtonModifyClick = function ()
{
	var strSubject = this.m_objDocumentManagerBoxItemAction.getSubject();
	
	if (0 == strSubject.length)
	{
		alert ("제목을 입력 해야 합니다.");
		return;
	}
	
	this._modifyDataItemTitle(this.m_nSelectedMenuIndex, strSubject);
	
	this.m_objDocumentManagerBoxItemAction.hide();
	this.m_objOwner.setActionDialogState(false);
}

DocumentManagerBoxItem.prototype.onChange = function ()
{
	var strPath = this.m_objFileUploadComponent.getPath();
	
	this.m_objDocumentManagerBoxItemAction.setPath(strPath);
	
	this.m_objFileUploadComponent.add();
	
	this.m_objFileUploadComponent.hide();
}

	
////////////////////////////////////////
// public method

DocumentManagerBoxItem.prototype.setValue = function (strFlag)
{
	this.m_strFlag = strFlag;
	
	this._changeIcon();
}

DocumentManagerBoxItem.prototype.getValue = function ()
{		
	return this.m_strFlag;
}

DocumentManagerBoxItem.prototype.hasFlag = function ()
{
	return !this._emptyFlag();
}

/**
 * DataItem이 있는지를 판별하여 아이콘 update
 */
DocumentManagerBoxItem.prototype.refresh = function ()
{
	if (0 == this.m_arDataItemList.length)
	{
		this.setValue(" ");
	}
	else
	{
		this.setValue("S");		
	}		
}

DocumentManagerBoxItem.prototype.setKeyCode = function(strKeyCode)
{
	this.m_strKeyCode = strKeyCode;
}
	
DocumentManagerBoxItem.prototype.addDataItem = function(objDataItem)
{
	objDataItem.setMenuIndex(this.m_nSubjectMenuLength);
	
	this.m_arDataItemList.push(objDataItem);
}

DocumentManagerBoxItem.prototype.addSubject = function (strTitle)
{
	var objThis = this;
	
	// add object
	var nIndex = this.m_heAtom_BOX_ITEM_SUBJECT.childNodes[0].childNodes.length;
	
	var heTR = document.createElement("tr");
	this.m_heAtom_BOX_ITEM_SUBJECT.childNodes[0].appendChild(heTR);
	
	// create html li
	var heTD = document.createElement("td");
	heTR.appendChild(heTD);
	
	heTD.innerText = strTitle;
	heTD.value = nIndex;		// 추가하는 항목의 메뉴에서의 index 위치
	
	// set style
	heTD.style.padding = "1px 10px 1px 10px;"
	
	// add event handler
	heTD.onmouseover = function ()
	{
		heTD.style.backgroundColor = "#191970";
		heTD.style.color = "#FFFFFF";
	}
	
	heTD.onmouseout = function ()
	{
		heTD.style.backgroundColor = "#ffffff";
		heTD.style.color = "#000000";
	}
	
	heTD.onmousedown = function ()
	{
		objThis.m_nSelectedMenuIndex = this.value;
		var objDataItem = objThis._getDataItemFromMenuIndex(objThis.m_nSelectedMenuIndex);
		
		if (null == objDataItem)
		{
			return;
		}
					
		objThis._hideSubjectMenu();
		
		if (objDataItem.fromDB())	// 디비에 저장된 문서 다운로드
		{
			objThis._executeDocumentDownload(objDataItem);
		}
		else	// 사용자가 추가한 문서 보여줌
		{
			objThis._showAddedDocument(objDataItem);			
		}
		
		// 삭제, 제목수정, 취소 모드로 연다.
		objThis.m_objDocumentManagerBoxItemAction.init(objThis, objDataItem.getDataType() - 1, false);
		objThis.m_objDocumentManagerBoxItemAction.setSubject(objDataItem.getSubject());
		
		objThis.m_objDocumentManagerBoxItemAction.show();
		objThis.m_objOwner.setActionDialogState(true);
	}
	
	objThis.m_nSubjectMenuLength = objThis.m_nSubjectMenuLength + 1;
}

DocumentManagerBoxItem.prototype.makeUploadRequest = function (xnAtom)
{
	for (var i = 0; i < this.m_arDataItemList.length; i=i+1)
	{
		var xnNode = this.m_arDataItemList[i].makeUploadRequestNode();
		
		if (null != xnNode)
		{
			XmlLib.importChildNode(xnAtom, xnNode, true);
		}
	}
}

/**
 * 현재 BoxItem에 속한 DataItem 개체의 serial 값 중에서 가장 큰 값을 리턴
 */
DocumentManagerBoxItem.prototype.getHighestSerial = function ()
{
	var nHighestSerial = 0;
	
	for (var i = 0; i < this.m_arDataItemList.length; i=i+1)
	{
		var nSerial = this.m_arDataItemList[i].getSerial();
		
		if (nSerial > nHighestSerial)
		{
			nHighestSerial = nSerial;
		}
	}
	return nHighestSerial;
}

////////////////////////////////////////
// private method

DocumentManagerBoxItem.prototype._clearItem = function ()
{
	this.m_arDataItemList = new Array();
	
	this.m_nSubjectMenuLength = 0;
}

DocumentManagerBoxItem.prototype._openMenu = function ()
{	
	this.m_objDocumentManagerBoxItemMenu.init(this);
	this.m_objDocumentManagerBoxItemMenu.show(this._getLeft(this.m_heAtom_BOX_ITEM));
}

/**
 * 문서파일을 새로 추가함
 */
DocumentManagerBoxItem.prototype._addFile = function (strSubject, strPath, nDataType, nInputIndex)
{
	var nSerial = this.m_objOwner.getHighestSerial() + 1;
	
	var objDataItem = new DocumentManagerDataItem(this.m_strKeyCode, nSerial, nDataType, this.m_nIndex, strSubject, false);
	
	objDataItem.setOperationType(DocumentManagerDataItem.INSERT);
	objDataItem.setInputIndex(nInputIndex);
	
	if (DocumentManagerDataItem.WEBDOCUMENT == nDataType)
	{
		objDataItem.setWebPath(strPath);
	}
	
	this.addDataItem(objDataItem);

	this.setValue("S");
	
	this.addSubject(strSubject);
}

DocumentManagerBoxItem.prototype._showSubjectMenu = function ()
{
	// TODO dialog
	if (null != this.m_heAtom_BOX_ITEM_SUBJECT)
	{
		this.m_heAtom_BOX_ITEM_SUBJECT.style.visibility = "visible";
		
		this.m_heAtom_BOX_ITEM_SUBJECT.focus();
	}
}

DocumentManagerBoxItem.prototype._hideSubjectMenu = function ()
{
	if (null != this.m_heAtom_BOX_ITEM_SUBJECT)
	{
		this.m_heAtom_BOX_ITEM_SUBJECT.style.visibility = "hidden";
	}
}

DocumentManagerBoxItem.prototype._changeIcon = function ()
{
	if (this._emptyFlag())
	{
		this._setItemIcon(false);
	}
	else
	{
		this._setItemIcon(true);
	}
}

DocumentManagerBoxItem.prototype._setItemIcon = function (bAttach)
{
	if (null != this.m_heAtom_BOX_ITEM)
	{
		var strYpos = bAttach ? "-15px" : "0px";
		this.m_heAtom_BOX_ITEM.style.backgroundPositionY = strYpos;
	}
}

DocumentManagerBoxItem.prototype._emptyFlag = function ()
{
	if (null == this.m_strFlag || 0 == this.m_strFlag.length || " " == this.m_strFlag)
	{
		return true;
	}
	
	return false;
}

DocumentManagerBoxItem.prototype._getLeft = function (heHTML)
{
	return parseInt(heHTML.style.left);
}

DocumentManagerBoxItem.prototype._getDataItemFromMenuIndex = function (nSubjectMenuIndex)
{
	for (var i = 0; i < this.m_arDataItemList.length; i=i+1)
	{
		if (nSubjectMenuIndex == this.m_arDataItemList[i].getMenuIndex())
		{
			return this.m_arDataItemList[i];
		}
	}
	return null;
}

/**
 * 문서의 제목 메뉴와 해당 객체 삭제
 */
DocumentManagerBoxItem.prototype._removeSubject = function (nSubjectMenuIndex)
{
	var objItem = this._getDataItemFromMenuIndex(nSubjectMenuIndex);	
	
	if (null != objItem)
	{
		this._removeSubjectMenu(nSubjectMenuIndex);
	
		this._removeDataItem(nSubjectMenuIndex);
	}
}

/**
 * 제목 메뉴의 tr 엘리멘트 삭제,
 * 나머지 메뉴 항목의 MenuIndex값 1씩 감소 (메뉴 항목은 0,1,2 ... 순서로 index값이 정렬 되어 있어야 함)
 */
DocumentManagerBoxItem.prototype._removeSubjectMenu = function (nSubjectMenuIndex)
{
	var heDelete = this.m_heAtom_BOX_ITEM_SUBJECT.childNodes[0].childNodes[nSubjectMenuIndex];
	
	if (null != heDelete)
	{
		this.m_heAtom_BOX_ITEM_SUBJECT.childNodes[0].removeChild(heDelete);
		
		this.m_nSubjectMenuLength = this.m_nSubjectMenuLength - 1;
		
		var nLen = this.m_heAtom_BOX_ITEM_SUBJECT.childNodes[0].childNodes.length;
		for (var i = nSubjectMenuIndex; i < nLen; i=i+1)
		{
			this.m_heAtom_BOX_ITEM_SUBJECT.childNodes[0].childNodes[i].childNodes[0].value = i;
		}
	}
	
	if (0 == this.m_heAtom_BOX_ITEM_SUBJECT.childNodes[0].childNodes.length)
	{
		this.setValue(" ");
	}
}

/**
 * 사용자가 추가한 DocumentManagerDataItem 객체는 삭제
 * DB에 있는 DocumentManagerDataItem 객체는 정보 수정
 */
DocumentManagerBoxItem.prototype._removeDataItem = function (nSubjectMenuIndex)
{
	var nCount = 0;
	for ( ; nCount < this.m_arDataItemList.length; nCount=nCount+1)
	{
		if (nSubjectMenuIndex == this.m_arDataItemList[nCount].getMenuIndex())
		{
			if (this.m_arDataItemList[nCount].fromDB())	// DB에 저장되어 있는 데이터
			{
				this.m_arDataItemList[nCount].setMenuIndex(-1);
				this.m_arDataItemList[nCount].setOperationType(DocumentManagerDataItem.DELETE);
				
				nCount = nCount + 1;
			}
			else		// 사용자가 추가한 데이터 삭제
			{
				this.m_arDataItemList.splice(nCount, 1);
			}
			break;
		}
	}
	
	// 나머지 객체의 menu index 값 감소 (0,1,2... 순서로 정렬 되어 있어야 함)
	for ( ; nCount < this.m_arDataItemList.length; nCount=nCount+1)
	{
		var nIndex = this.m_arDataItemList[nCount].getMenuIndex();
		
		if (-1 < nIndex)
		{
			this.m_arDataItemList[nCount].setMenuIndex(nIndex - 1);
		}			
	}
}

/**
 * DocumentManagerDataItem 객체의 제목과, 메뉴 제목 변경
 */
DocumentManagerBoxItem.prototype._modifyDataItemTitle = function (nSubjectMenuIndex, strSubject)
{
	for (var i = 0; i < this.m_arDataItemList.length; i=i+1)
	{
		if (nSubjectMenuIndex == this.m_arDataItemList[i].getMenuIndex())
		{
			this.m_arDataItemList[i].setSubject(strSubject);
			
			// 사용자가 추가한 문서는 삽입 상태 이어야 문서가 추가된다. DB에서 가져온 문서만 수정 상태로 변경 한다.
			if (this.m_arDataItemList[i].fromDB)
			{
				this.m_arDataItemList[i].setOperationType(DocumentManagerDataItem.MODIFY);
			}
		}
	}
	
	// 메뉴 제목 변경
	var heTD = this.m_heAtom_BOX_ITEM_SUBJECT.childNodes[0].childNodes[nSubjectMenuIndex].childNodes[0];
	heTD.innerText = strSubject;
}

/**
 * DB에 있는 통합문서를 다운로드 하는 요청을 보낸다.
 * 일반 문서는 파일 저장 다이얼 로그가 뜬다.
 * 이미지, 웹문서는 별도의 창을 띄어 표시한다.
 */
DocumentManagerBoxItem.prototype._executeDocumentDownload = function (objDataItem)
{
	var strWhereClause = "S_CODE = '" + objDataItem.getCode() + "' AND S_DATA_SERI = " + objDataItem.getSerial();
	var strRequestURL = "/ups/Download.do?ServiceName=DocumentManager" + "&WhereClause=" + strWhereClause;
	
	var nDataType = objDataItem.getDataType();
	
	if (DocumentManagerDataItem.FILEDOCUMENT == nDataType)
	{
		var heFrame = document.getElementById("__FILE_DOWNLOAD_TARGET");
		heFrame.src = encodeURI(strRequestURL);
	}
	else
	{
		this._showDocumentDialog (nDataType, strRequestURL, objDataItem.getSubject());
	}
}

/**
 * 이미지, 웹문서의 내용을 보여주는 창을 띄운다.
 */
DocumentManagerBoxItem.prototype._showDocumentDialog = function (nDataType, strURL, strSubject)
{
	var arPopupInfo = new Array();
	arPopupInfo[0] = nDataType;
	arPopupInfo[1] = strURL;
	arPopupInfo[2] = strSubject;
	
	var nTop = window.screenTop + this.m_objDocumentManagerBoxItemAction.getBottomPosition();
	
	var strOption = "";
	strOption += "dialogLeft:300px; ";
	strOption += "dialogTop:" + nTop + "px; ";
	strOption += "dialogWidth:600px; ";
	strOption += "dialogHeight:500px; ";
	strOption += "resizable:yes;"
	
	if (DocumentManagerDataItem.WEBDOCUMENT == nDataType)
	{
		strOption += "scroll:no;status:yes;";
	}
	else
	{
		strOption += "scroll:no;status:no;";
	}
	
	if (DocumentManagerDataItem.NTOADOCUMENT == nDataType)
	{
		PQConnectionModel.executeNtoaModelWithRegisterNumber(this.m_strDocRegisterNumber, true);
	}
	else
	{
		this.m_objDocViewWindow = window.showModelessDialog("/ups/sys/html/support/DocumentView.html", arPopupInfo, strOption);
	}
}

/**
 * 사용자가 추가한 파일을 보여준다.
 */
DocumentManagerBoxItem.prototype._showAddedDocument = function (objDataItem)
{
	var nDataType = objDataItem.getDataType();
	
	if (DocumentManagerDataItem.FILEIMAGE == nDataType || DocumentManagerDataItem.SCANIMAGE == nDataType)
	{
		var nInputIndex = objDataItem.getInputIndex();		
		
		var strPath = this.m_objFileUploadComponent.getValue(nInputIndex);
		
		this._showDocumentDialog (nDataType, strPath, objDataItem.getSubject());
	}
	else if (DocumentManagerDataItem.WEBDOCUMENT == nDataType)
	{	
		var strPath = objDataItem.getWebPath();
		if (0 != strPath.indexOf("http://"))
		{
			strPath = "http://" + strPath;
		}
		
		window.open(strPath, "_blank");
	}
	else if (DocumentManagerDataItem.FILEDOCUMENT == nDataType)
	{
		// TODO : 구현 해야함, 로컬 파일 실행하기 어려움
	}
}

DocumentManagerBoxItem.ITEM = "__DOC_MANAGER_BOX_ITEM_";
DocumentManagerBoxItem.ITEM_SUBJECT = DocumentManagerBoxItem.ITEM + "SUBJECT_";


//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
/**
 * 메뉴 하나를 각 문서 아이콘(DocumentManager)에서 공유해서 사용합니다.
 */
function DocumentManagerBoxItemMenu (strVarName)
{
	this.m_objOwner = null;
	
	this.m_heAtom_BOX_ITEM_MENU = document.getElementById(DocumentManagerBoxItemMenu.MENU + strVarName);
	
}
////////////////////////////////////////
// public method

DocumentManagerBoxItemMenu.prototype.init = function (objOwner)
{	
	this.m_objOwner = objOwner;
	
	this._addEventHandler();
}

DocumentManagerBoxItemMenu.prototype.show = function (nLeft)
{
	/**
	 * TODO top은 23 고정, left는 위치 버그 : -25px
	 */
	if (null != this.m_heAtom_BOX_ITEM_MENU)
	{
		this.m_heAtom_BOX_ITEM_MENU.style.left = (nLeft - 25) + "px";
	
		this.m_heAtom_BOX_ITEM_MENU.style.visibility = "visible";
		this.m_heAtom_BOX_ITEM_MENU.focus();
	}
}

DocumentManagerBoxItemMenu.prototype.hide = function (nIndex)
{
	this.m_heAtom_BOX_ITEM_MENU.style.visibility = "hidden";
}


DocumentManagerBoxItemMenu.prototype._addEventHandler = function ()
{
	var objThis = this;
	var arTR = this.m_heAtom_BOX_ITEM_MENU.childNodes[0].childNodes;
	var nLen = arTR.length;
	
	for (var i = 0; i < nLen; i=i+1)
	{
		arTR[i].childNodes[0].value = i;
		
		arTR[i].childNodes[0].onmouseover = function ()
		{
			this.style.backgroundColor = "#191970"; // PQBLD에서 사용되는 색상 코드	
			this.style.color = "#FFFFFF";
		}
		
		arTR[i].childNodes[0].onmouseout = function ()
		{
			this.style.backgroundColor = "#ffffff";
			this.style.color = "#000000";
		}
		
		arTR[i].childNodes[0].onmousedown = function ()
		{
			objThis.m_objOwner.onMenuClick(this.value);
		}	
	}
}

DocumentManagerBoxItemMenu.MENU = "__DOC_MANAGER_BOX_ITEM_MENU_";

DocumentManagerBoxItemMenu.onBlur = function (heMenu)
{
	heMenu.style.visibility = "hidden";
}

function DocumentManagerBoxItemAction (strVarName)
{
	this.m_objOwner = null;
	
	this.m_heAtom_BOX_ACTION = document.getElementById(DocumentManagerBoxItemAction.ACTION + strVarName);
	
	this.m_heAtom_BOX_ACTION_SUBJECT = document.getElementById(DocumentManagerBoxItemAction.SUBJECT + strVarName);
	this.m_heAtom_BOX_ACTION_PATH = document.getElementById(DocumentManagerBoxItemAction.PATH + strVarName);
	
	this.m_heAtom_BOX_ACTION_OPEN = document.getElementById(DocumentManagerBoxItemAction.OPEN + strVarName);
	this.m_heAtom_BOX_ACTION_SAVE = document.getElementById(DocumentManagerBoxItemAction.SAVE + strVarName);
	this.m_heAtom_BOX_ACTION_CANCEL = document.getElementById(DocumentManagerBoxItemAction.CANCEL + strVarName);
	this.m_heAtom_BOX_ACTION_DELETE = document.getElementById(DocumentManagerBoxItemAction.DELETE + strVarName);
	this.m_heAtom_BOX_ACTION_MODIFY = document.getElementById(DocumentManagerBoxItemAction.MODIFY + strVarName);
	
	this.m_bSetDialogPosition = false;
	this.m_nDialogBottomPosition = 0;
}	
	
DocumentManagerBoxItemAction.prototype.init = function (objOwner, nIndex, bOpenAdd)
{
	this.m_objOwner = objOwner;
	
	this._addEventHandler();
		
	this._initOpenMode(bOpenAdd);
	
	this.setSubject("");
	this.setPath("");
	
	if (2 == nIndex && bOpenAdd)	// 웹문서 일 경우
	{
		this.m_heAtom_BOX_ACTION_OPEN.style.display = "none";
		this.m_heAtom_BOX_ACTION_PATH.disabled = false;
	}
	else
	{
		this.m_heAtom_BOX_ACTION_PATH.disabled = true;
	}
}

DocumentManagerBoxItemAction.prototype.show = function ()
{
	if (!this.m_bSetDialogPosition)
	{
		this._setPosition();
	}
	
	this.m_heAtom_BOX_ACTION.style.display = "block"
}

DocumentManagerBoxItemAction.prototype.hide = function ()
{
	this.m_heAtom_BOX_ACTION.style.display = "none";
}

DocumentManagerBoxItemAction.prototype.getSubject = function ()
{
	return this.m_heAtom_BOX_ACTION_SUBJECT.value;
}

DocumentManagerBoxItemAction.prototype.getPath = function ()
{
	return this.m_heAtom_BOX_ACTION_PATH.value;
}

DocumentManagerBoxItemAction.prototype.setPath = function (strPath)
{
	this.m_heAtom_BOX_ACTION_PATH.value = strPath;
}

DocumentManagerBoxItemAction.prototype.setSubject = function (strSubject)
{
	this.m_heAtom_BOX_ACTION_SUBJECT.value = strSubject;
}

DocumentManagerBoxItemAction.prototype.getBottomPosition = function ()
{
	return this.m_nDialogBottomPosition;
}

/**
 * (파일선택, 저장, 취소) / (삭제, 제목수정, 취소) 모드 변경
 */
DocumentManagerBoxItemAction.prototype._initOpenMode = function (bOpenAdd)
{
	if (bOpenAdd)
	{
		this.m_heAtom_BOX_ACTION_DELETE.style.display = "none";
		this.m_heAtom_BOX_ACTION_MODIFY.style.display = "none";
		
		this.m_heAtom_BOX_ACTION_OPEN.style.display = "block";
		this.m_heAtom_BOX_ACTION_SAVE.style.display = "block";
	}
	else
	{
		this.m_heAtom_BOX_ACTION_OPEN.style.display = "none";
		this.m_heAtom_BOX_ACTION_SAVE.style.display = "none";
		
		this.m_heAtom_BOX_ACTION_DELETE.style.display = "block";
		this.m_heAtom_BOX_ACTION_MODIFY.style.display = "block";
	}	
}

DocumentManagerBoxItemAction.prototype._setPosition = function ()
{
	var nModelWidth = GetWindowWidth();
	var nModelHeight = GetWindowHeight();
	
	var nLayoutWidth = parseInt(this.m_heAtom_BOX_ACTION.style.width);
	var nLayoutHeight = parseInt(this.m_heAtom_BOX_ACTION.style.height);
	
	var nLeft = nModelWidth / 2 - nLayoutWidth / 2;
	//var nTop = nModelHeight / 2 - nLayoutHeight / 2;
	var nTop = 0;
	
	this.m_heAtom_BOX_ACTION.style.top = nTop + "px";
	this.m_heAtom_BOX_ACTION.style.left = nLeft + "px";
	
	this.m_bSetDialogPosition = true;
	this.m_nDialogBottomPosition = nTop + nLayoutHeight;
}

DocumentManagerBoxItemAction.prototype._addEventHandler = function ()
{
	var objThis = this;
	this.m_heAtom_BOX_ACTION_OPEN.onclick = function ()
	{
		objThis.m_objOwner.onButtonOpenClick();
	}
	
	this.m_heAtom_BOX_ACTION_SAVE.onclick = function ()
	{
		objThis.m_objOwner.onButtonSaveClick();
	}
	
	this.m_heAtom_BOX_ACTION_CANCEL.onclick = function ()
	{
		objThis.m_objOwner.onButtonCancelClick();
	}
	
	this.m_heAtom_BOX_ACTION_DELETE.onclick = function ()
	{
		objThis.m_objOwner.onButtonDeleteClick();
	}
	
	this.m_heAtom_BOX_ACTION_MODIFY.onclick = function ()
	{
		objThis.m_objOwner.onButtonModifyClick();
	}
}

DocumentManagerBoxItemAction.ACTION = "__DOC_MANAGER_BOX_ITEM_ACTION_";

DocumentManagerBoxItemAction.SUBJECT = DocumentManagerBoxItemAction.ACTION + "SUBJECT_";
DocumentManagerBoxItemAction.PATH = DocumentManagerBoxItemAction.ACTION + "PATH_";

DocumentManagerBoxItemAction.OPEN = DocumentManagerBoxItemAction.ACTION + "OPEN_";
DocumentManagerBoxItemAction.SAVE = DocumentManagerBoxItemAction.ACTION + "SAVE_";
DocumentManagerBoxItemAction.CANCEL = DocumentManagerBoxItemAction.ACTION + "CANCEL_";
DocumentManagerBoxItemAction.DELETE = DocumentManagerBoxItemAction.ACTION + "DELETE_";
DocumentManagerBoxItemAction.MODIFY = DocumentManagerBoxItemAction.ACTION + "MODIFY_";

