/**
 * 검색창 헤더 클래스
 */
function BrowseColumn (strColumnName, // 1
					strFieldName, // 2
					strAlign, // 3
					strDisplay, // 4
					strType, // 5
					strBrowseVar, // 6
					strTable, // 7
					nWidth, // 8
					bReferencekey, // 9
					bSameDataHide, // 10
					bSumCheck, // 11
					bCheckField, // 12
					nPeriod, // 13
					nDbIndex, // 14
					bColumnVisible) // 15
{
	this.m_strColumnName = strColumnName;
	this.m_strFieldName = strFieldName;
	this.m_strAlign = strAlign;
	this.m_strDisplay = strDisplay;
	this.m_strType = strType;
	this.m_strBrowseVar = strBrowseVar;
	this.m_strTable = strTable;
	
	this.m_bReferenceKey = bReferencekey;
	this.m_bSameDataHide = bSameDataHide;
	this.m_bSumCheck = bSumCheck;
	this.m_bCheckField = bCheckField;
	this.m_nPeriod = nPeriod;
	this.m_nDbIndex = nDbIndex;
	this.m_bVisibility = bColumnVisible;
	
	this.m_nOriginWidth = nWidth;	// 원본 칼럼 넓이
	this.m_nWidth = nWidth;			// 현재 칼럼 넓이
}

BrowseColumn.prototype.isReferenceKey = function ()
{
	return this.m_bReferenceKey;
}

BrowseColumn.prototype.isCheckField = function ()
{
	return this.m_bCheckField;
}
// 컬럼 이름(항목명)
BrowseColumn.prototype.getItemName = function ()
{
	return this.m_strColumnName;
}
// 항목변수명
BrowseColumn.prototype.getItemVarName = function ()
{
	return this.m_strBrowseVar;
}

BrowseColumn.prototype.getCompleteFieldName = function ()
{
	// 필드명에 키워드가 포함되어 있다면, 테이블명을 붙이지 않는다.
	// 키워드 형태: [keyword]
	if (null != this.m_strFieldName.match(/\[\S+\]/))
	{
		return this.m_strFieldName;
	}
	else if (null == this.m_strTable || "" == this.m_strTable)
	{
		// 테이블 명이 없으면 필드명만 반환한다
		return this.m_strFieldName;
	}
	
	return this.m_strTable + "." + this.m_strFieldName;
}

BrowseColumn.prototype.getDbIndex = function ()
{
	return this.m_nDbIndex;
}

BrowseColumn.prototype.getTableName = function ()
{
	return this.m_strTable;
}

BrowseColumn.prototype.getFieldName = function ()
{
	return this.m_strFieldName;
}

BrowseColumn.prototype.getFieldType = function ()
{
	return this.m_strType;
}

BrowseColumn.prototype.getWidth = function ()
{
	return this.m_nWidth;
}

BrowseColumn.prototype.getOriginWidth = function ()
{
	return this.m_nOriginWidth;
}

BrowseColumn.prototype.setWidth = function (nWidth)
{
	this.m_nWidth = nWidth;
}

BrowseColumn.prototype.getVisibility = function ()
{
	return this.m_bVisibility;
}

BrowseColumn.prototype.setVisibility = function (bVisibility)
{
	this.m_bVisibility = bVisibility;
}

BrowseColumn.prototype.getAlign = function ()
{
	return this.m_strAlign;
}

BrowseColumn.prototype.getDisplay = function ()
{
	return this.m_strDisplay;
}

/**
 * 사용자정의 표현형식이 설정 되었을 경우, db에 저장된 값 (표현형식 변환하지 않은 값)을 리턴한다.
 * $USER:Y$접수, N$미접수
 */
BrowseColumn.prototype.getUserDisplayValueOrigin = function (strValue)
{
	var nIndex = this.m_strDisplay.indexOf("$USER:");
	if (0 <= nIndex)
	{
		var strUserDisplay = this.m_strDisplay.substring(nIndex + 6);
		var arDisplay = strUserDisplay.split(",");
		
		for (var i = 0; i < arDisplay.length; i++)
		{
			arDisplay[i] = Utils.trim(arDisplay[i]);
			
			var arSplit = arDisplay[i].split("$");
			
			if (2 == arSplit.length && strValue == arSplit[1])
			{
				return arSplit[0];
			}
		}
	}
	
	return strValue;
}

/**
 * 날짜 형식의 컬럼인지 아닌지를 반환합니다. 
 * @return boolean (날짜 형식이다, 아니다)
 */
BrowseColumn.prototype.isDateType = function ()
{
	if (0 > this.m_strDisplay.indexOf("DATE"))
	{
		return false;
	}

	return true;
}

BrowseColumn.prototype.makeColumnRequest = function (xnRequest)
{
	var xnColumnAttrib = XmlLib.createChild(xnRequest, "ColumnAttrib");
	 
	xnColumnAttrib.setAttribute("ColumnName", this.m_strColumnName);
	xnColumnAttrib.setAttribute("Field", this.m_strFieldName);
	xnColumnAttrib.setAttribute("Align", this.m_strAlign);
	xnColumnAttrib.setAttribute("Display", this.m_strDisplay);
	xnColumnAttrib.setAttribute("Type", this._checkUserDisplayType(this.m_strDisplay));
	xnColumnAttrib.setAttribute("BrowseVar", this.m_strBrowseVar);
	xnColumnAttrib.setAttribute("Table", this.m_strTable);
	xnColumnAttrib.setAttribute("IsReferenceKey", this.m_bReferenceKey ? "Y" : "N");
	xnColumnAttrib.setAttribute("IsSameDataHide", this.m_bSameDataHide ? "Y" : "N");
	xnColumnAttrib.setAttribute("IsSumCheck", this.m_bSumCheck ? "Y" : "N");
	xnColumnAttrib.setAttribute("IsCheckField", this.m_bCheckField ? "Y" : "N");
	
	xnColumnAttrib.setAttribute("Period", this.m_nPeriod);
	xnColumnAttrib.setAttribute("Width", this.m_nWidth);
	xnColumnAttrib.setAttribute("Visibility", this.m_bVisibility ? "Y" : "N");
}

/**
 * 항목변수 표현 형식이 사용자 정의 일 경우에는, 자료형을 string 으로 변환해서 전송한다.
 */
BrowseColumn.prototype._checkUserDisplayType = function (strDisplay)
{
	if (0 <= strDisplay.indexOf("$USER:"))
	{
		return "string";
	}
	return this.m_strType;
}


function BrowseRow (heRow)
{
	this.m_heRow = heRow;
	this.m_strFontColor = heRow.style.color;
}	
	
BrowseRow.prototype.getIndex = function ()
{
	return this.m_heRow.rowIndex;
}

BrowseRow.prototype.getRow = function ()
{
	return this.m_heRow;
}

BrowseRow.prototype.getFontColor = function ()
{
	return this.m_strFontColor;
}
