/**
 * ChartAtom JS 클래스 리스트
 * ChartAtom
 * ChartAtomRuntimeAttrib
 * ChartAtomStyle
 * ChartItems
 * ExecuteChartForRuntime
 * ExecuteConnectionChart
 */

ChartAtom.PreName = "__CHARTATOM_";

/**
 * 검색단위 상수화
 */
ChartAtom.SECOND = 0;
ChartAtom.MINUTE = 1;
ChartAtom.HOUR = 2;
ChartAtom.DAY = 3;

function ChartAtom (strVarName, // 1
					nSQLIndex, // 2
					b2D, // 3
					nDirection, // 4
					nMulti, // 5
					strXAxisTitle, // 6
					nXAxisGrid, // 7
					nXAxisLayout, // 8
					strChartTitle, // 9
					nTitlePosition, // 10
					nTitleAlignment, // 11
					strYAxisTitle, // 12
					nYAxisGrid, // 13
					nYAxisLayout, // 14
					strRefVarName, // 15
					bDirectExecute, // 16
					nChartDataType, // 17
					bRunTime, // 18
					strChartItems, // 19
					objChartStyle, // 20
					bRealtime, // 21
					strRealtimePeriod, // 22
					nRealtimeType, // 23
					bVanish, // 24
					bLegend, // 25
					nLegendPosition, // 26
					nLegendAlignment, // 27
					nLegendBorder, // 28
					bToolBar, // 29
					bDataEditor, // 30
					bPointLabel, // 31
					nXAxisTickMark, // 32
					bXAxisScaleMin, // 33
					bXAxisScaleMax, // 34
					nXAxisScaleMin, // 35
					nXAxisScaleMax, // 36
					nYAxisTickMark, // 37
					bYAxisScaleMin, // 38
					bYAxisScaleMax, // 39
					nYAxisScaleMin, // 40
					nYAxisScaleMax, // 41
					nXAxisLabelAngle, // 42
					nYAxisLabelAngle, // 43
					bXAxisShowGridLine, // 44
					strXAxisGridLineColor, // 45
					nXAxisGridLineStyle, // 46
					nXAxisGridLineThick, // 47
					bYAxisShowGridLine, // 48
					strYAxisGridLineColor, // 49
					nYAxisGridLineStyle, // 50
					nYAxisGridLineThick) // 51
{
	
	
	this.m_strVarName = strVarName; // 아톰이름
	this.m_nSQLIndex = nSQLIndex
	this.m_b2D = b2D; // 3D 효과 여부
	this.m_nDirection = nDirection; // 표시 방향
	this.m_nMulti = nMulti; // 다중데이터 
	this.m_strXAxisTitle = strXAxisTitle; // X축 제목
	this.m_nXAxisGrid = nXAxisGrid; // X축 세로선 표시
	this.m_nXAxisLayout = nXAxisLayout; // X축 항목명 배치
	this.m_strChartTitle	= strChartTitle; // 챠트 제목
	this.m_nTitlePosition = nTitlePosition; // 챠트 제목 위치
	this.m_nTitleAlignment = nTitleAlignment; // 챠트 제목 정렬
	this.m_strYAxisTitle = strYAxisTitle; // Y축 제목
	this.m_nYAxisGrid = nYAxisGrid; // Y축 세로선 표시
	this.m_nYAxisLayout = nYAxisLayout; // Y축 항목명 배치
	this.m_strRefVarName = strRefVarName; // 참조 변수명
	this.m_bDirectExecute = bDirectExecute; // 즉시실행 여부
	this.m_nChartDataType = nChartDataType; // 챠트 데이터 원천
	this.m_bRunTime = bRunTime; // 실행시 지정
	this.m_alChartItems 	= null;
	this.m_objChartStyle = objChartStyle; // 챠트 스타일 속성 객체
	this.m_bRealtime = bRealtime; //실시간처리
	this.m_strRealtimePeriod = strRealtimePeriod; // 실시간 처리 단위
	this.m_nRealtimeType = nRealtimeType; //실시간 처리 폭	
	this.m_bVanish = bVanish;
	this.m_bLegend = bLegend;	// 범례 사용여부
	this.m_nLegendPosition = nLegendPosition;	// 범례 위치
	this.m_nLegendAlignment = nLegendAlignment;	// 범례 정렬
	this.m_nLegendBorder = nLegendBorder;		// 범례 테두리
	this.m_bToolBar = bToolBar;		// 도구바 사용여부
	this.m_bDataEditor = bDataEditor;	// 데이터편집기 사용여부
	this.m_bPointLabel = bPointLabel;	// 포인트라벨 사용여부
	this.m_nXAxisTickMark = nXAxisTickMark;	// X축 눈금 표시
	this.m_bXAxisScaleMin = bXAxisScaleMin; // X축 최소값 설정 여부
	this.m_bXAxisScaleMax = bXAxisScaleMax;	// X축 최대값 설정 여부
	this.m_nXAxisScaieMin = nXAxisScaleMin;	// X축 최소값
	this.m_nXAxisScaleMax = nXAxisScaleMax;	// X축 최대값
	this.m_nYAxisTickMark = nYAxisTickMark;	// Y축 눈금 표시
	this.m_bYAxisScaleMin = bYAxisScaleMin; // Y축 최소값 설정 여부
	this.m_bYAxisScaleMax = bYAxisScaleMax;	// Y축 최대값 설정 여부
	this.m_nYAxisScaleMin = nYAxisScaleMin;	// Y축 최소값
	this.m_nYAxisScaleMax = nYAxisScaleMax;	// Y축 최대값
	this.m_nXAxisLableAngle = nXAxisLabelAngle;	// X축 항목제목 각도
	this.m_nYAxisLableAngle = nYAxisLabelAngle;	// Y축 항목제목 각도
	this.m_bXAxisShowGridLine = bXAxisShowGridLine;	// X축 보조선 설정 여부
	this.m_strXAxisGridLineColor = strXAxisGridLineColor;	// X축 보조선 색상
	this.m_nXAxisGridLineStyle = nXAxisGridLineStyle;	// X축 보조선 종류
	this.m_nXAxisGridLineThick = nXAxisGridLineThick;	// X축 보조선 굵기
	this.m_bYAxisShowGridLine = bYAxisShowGridLine;	// Y축 보조선 설정 여부
	this.m_strYAxisGridLineColor = strYAxisGridLineColor;	// Y축 보조선 색상
	this.m_nYAxisGridLineStyle = nYAxisGridLineStyle;	// Y축 보조선 종류
	this.m_nYAxisGridLineThick = nYAxisGridLineThick;	// Y축 보조선 굵기
	
	this.m_heChartApplet = null;
	
	// XML작성시에 필요한 값만 가진 객체를 선언
	this.m_objRuntimeAttrib = new ChartAtomRuntimeAttrib(b2D, nMulti, strXAxisTitle, nXAxisGrid, 
							nXAxisLayout, strChartTitle, nTitlePosition, nTitleAlignment, strYAxisTitle, nYAxisGrid, 
							nYAxisLayout, bLegend, nLegendPosition, nLegendAlignment, nLegendBorder,bToolBar, 
							bDataEditor, bPointLabel, bDirectExecute, bRealtime, strRealtimePeriod, nRealtimeType,
							nXAxisTickMark, bXAxisScaleMin, bXAxisScaleMax, nXAxisScaleMin, nXAxisScaleMax,
							nYAxisTickMark, bYAxisScaleMin, bYAxisScaleMax, nYAxisScaleMin, nYAxisScaleMax,
							nXAxisLabelAngle, nYAxisLabelAngle, 
							bXAxisShowGridLine, strXAxisGridLineColor, nXAxisGridLineStyle, nXAxisGridLineThick,
							bYAxisShowGridLine, strYAxisGridLineColor, nYAxisGridLineStyle, nYAxisGridLineThick
		);
		
	/****************** ChartItemList 초기화  *******************/
	var arChartOrgItemList = strChartItems.split(",");
	
	var nLen = arChartOrgItemList.length;
	
	if (0 < nLen)
	{
		this.m_alChartItems = new Array();
	}
	
	for (var i = 0; i < nLen; i++)
	{
		var objChartItems = new ChartItems(arChartOrgItemList[i]);
		
		objChartItems.init();
		
		this.m_alChartItems.push(objChartItems);
	}
}

ChartAtom.prototype.getVarName = function ()
{
	return this.m_strVarName;
}

ChartAtom.prototype.isDirectExec = function ()
{
	return this.m_bDirectExecute;
}
	
ChartAtom.prototype.getRefVarName = function ()
{
	return this.m_strRefVarName;
}

/**
 * 아톰리스트에 추가
 */
ChartAtom.prototype.putAtom = function ()
{
	ChartAtom._atoms[this.m_strVarName] = this;
}

ChartAtom.prototype.setValue = function (xnAtom)
{
	this._handleResult(xnAtom);
}

ChartAtom.prototype.getChartDataType = function ()
{
	return this.m_nChartDataType;
}

ChartAtom.prototype.init = function ()
{
	this.m_heChartApplet = document.getElementById(ChartAtom.PreName + this.m_strVarName);
	
	this._forceExecute();
	
	//this._setVisibility();	
}

ChartAtom.prototype.makeRequest = function (xnAtomRequest)
{
	var xnChartAtom = XmlLib.createChild(xnAtomRequest, "Chart");
	
	if (0 == this.m_nChartDataType)
	{
		xnChartAtom.setAttribute("VarName", this.m_strVarName);
		xnChartAtom.setAttribute("SQLIndex", this.m_nSQLIndex);
		
		// 일단은 속성을 모두 가지고 요청을 만듦니다
		// 차후 요청에 필요한 속성들이 모두 확인 되면 필요없는 속성은 요청에 포함시키지 않아야 합니다
		this._setChartAtomAttrib(xnChartAtom, this.m_alChartItems);
	}
}

ChartAtom.prototype.makeChartAttrib = function ()
{
	var xnChartAttrib = XmlLib.createChild(xnBrowseAtom, "ChartAttrib");
}

ChartAtom.prototype.executeFromSearchData = function (xnAtom)
{
	this._handleResult(xnAtom);
}
	
/**
 * 인자의 컬럼 이름이 챠트에 속하는 컬럼의 이름인가?
 * 
 * @param strColumn 컬럼이름
 * @return 속하면 true, 아니면 false
 */
ChartAtom.prototype.isChartColumn = function (strColumnName)
{
	for (var i = 0, nLen = this.m_alChartItems.length; i < nLen; i++)
	{
		if ((this.m_alChartItems[i].getItemName() == strColumnName) ||
      		(this.m_alChartItems[i].getItemTitle() == strColumnName))
		{
			return true;
		}
	}
	
	return false;
}

ChartAtom.prototype.searchFromRefBrowse = function ()
{
	if (null == this.m_strRefVarName || "" == this.m_strRefVarName)
	{
		return;
	}
	
	var objBrowseAtom = ReportBrowseAtom.getAtom(this.m_strRefVarName);
	
	if (null != objBrowseAtom)
	{
		var xnResult = objBrowseAtom.makeRequestForChart(this).documentElement
		
		this._handleResult(xnResult);
	}
}

// 실시간 처리에서 검색 서비스를 이용
ChartAtom.prototype.realtimeSearch = function ()
{
	GlobalField.setEventVarName(this.m_strVarName);
	GlobalField.setServiceName("SearchAction");
	
	GlobalField.setServiceEventName("Chart");
	
	var xnRequest = MakeRequest.createRequestNode();
	MakeRequest.makeServiceRequest(xnRequest);
	MakeRequest.makeAtomRequest(xnRequest, true);
	
	var xnResultDoc = null;
	
	try
	{
		MakeRequest.makeSearchAtomRequest(xnRequest, this.m_strVarName, "SearchAction");
		
		var xnRequestDoc = xnRequest.ownerDocument;
		
		if (null == xnRequestDoc)
		{
			return;
		}
		
		xnResultDoc = PQService.executeService(xnRequestDoc);
		
		if (null == xnResultDoc)
		{
			return;
		}
	}
	catch (e)
	{
		HandleException(e);
		return;
	}
	
	HandleResult.execute(xnResultDoc);
}

/**
 * 선택표시 (f9 기능)
 */
ChartAtom.prototype.vanish = function ()
{
	if (this.m_bVanish)
	{
		// 현재 감춤 상태이면 표시한다.
		if ("hidden" == this.m_heChartApplet.style.visibility)
		{
			this.m_heChartApplet.style.visibility = "visible";
		}
		else	// 표시된 상태이면 감춘다.
		{
			this.m_heChartApplet.style.visibility = "hidden";
		}
	}
}
	
///////////////////////////////////////////
// private method
//

ChartAtom.prototype._handleResult = function (xnAtom)
{
	if (null != this.m_heChartApplet)
	{
		var alTempItemList = null;
		
		// 실행시 지정인가?
		if (true == this.m_bRunTime)
		{
			var objExecuteChar = new ExecuteChartForRuntime();
			//var objOriXnAtom = xnAtom.cloneNode(true);
		
			if (null == alTempItemList)
			{
				alTempItemList = this.m_alChartItems;
			}

			// 애플릿은 챠트연결과 구분하기 위해서 보냄
			//var strResult = objExecuteChar.execute(xnAtom, false);
			
			var bSuccess = objExecuteChar.execute(xnAtom);
			
			if (false == bSuccess)
			{
				// 실행시 지정에서 취소하면 xnAtom을 공백으로 만든다.
				//xnAtom = objOriXnAtom;
				this._setAttribXML(xnAtom, this.m_objChartStyle, alTempItemList);
			}
			/*else
			{
				this._setAttribXML(xnAtom, this.m_objChartStyle, alTempItemList);
			}*/
		}
		else
		{
			// 모델 기본값을 사용해 챠트를 그릴때
			if (null == alTempItemList)
			{
				alTempItemList = this.m_alChartItems;
			}
			this._setAttribXML(xnAtom, this.m_objChartStyle, alTempItemList);
			
		}

		if (null != this.m_heChartApplet && null != xnAtom)
		{
			this.m_heChartApplet.createChartEmbedded(XmlLib.serializeToString(xnAtom));
		}
		
		// 차트를 생성한 뒤에 화면 감춤 처리를 한다.
		if (this.m_objChartStyle.isVisible())
		{
			this.m_heChartApplet.style.display = "none";
		}
	}
}

ChartAtom.prototype._setVisibility = function ()
{
	if (this.m_objChartStyle.isVisible())
	{
		this.m_heChartApplet.style.visibility = "";
	}
	else
	{
		this.m_heChartApplet.style.visibility = "hidden";
	}
}

ChartAtom.prototype._setAttribXML = function (xnAtom, objChartStyle, alTempItemList)
{
	this._setChartStyleAttrib(xnAtom, objChartStyle);
	
	// 기본값을 가지고 차트를 생성
	this._setChartAtomAttrib(xnAtom, alTempItemList);
	this._setChartItemAttrib(xnAtom, alTempItemList);
}

/**
 * ChartAtom 자체의속성을 Xml에 설정한다
 */

ChartAtom.prototype._setChartAtomAttrib = function (xnAtom, alChartItemAttrib)
{	
	var xnChartAtomAttrib = XmlLib.createChild(xnAtom, "ChartAtomAttrib");
	
	// 이속성은 ChartItemAttrib 로 옮겨가야 한다, 챠트의 타입은 아톰내 챠트별 속성이기 때문이다 현재는 1번째 챠트의 속성이 모든 챠트의 속성을 대표한다
	if (null != alChartItemAttrib)
	{
		xnChartAtomAttrib.setAttribute("Gallery", alChartItemAttrib[1].getChartType());
	}
	else
	{
		xnChartAtomAttrib.setAttribute("Gallery", 1);
	}
	
	xnChartAtomAttrib.setAttribute("TWODType", (this.m_b2D ? 1 : 0).toString());
	xnChartAtomAttrib.setAttribute("MultiType", this.m_nMulti);
	xnChartAtomAttrib.setAttribute("XAxisTitle", this.m_strXAxisTitle);
	xnChartAtomAttrib.setAttribute("YAxisTitle", this.m_strYAxisTitle);
	xnChartAtomAttrib.setAttribute("YAxisLayout", this.m_nYAxisLayout);
	xnChartAtomAttrib.setAttribute("XAxisGrid", this.m_nXAxisGrid.toString());
	xnChartAtomAttrib.setAttribute("YAxisGrid", this.m_nYAxisGrid.toString());
	xnChartAtomAttrib.setAttribute("XAxisLayout", this.m_nXAxisLayout.toString());
	xnChartAtomAttrib.setAttribute("YAxisLayout", this.m_nYAxisLayout.toString());
	xnChartAtomAttrib.setAttribute("ChartTitle", this.m_strChartTitle);
	xnChartAtomAttrib.setAttribute("TitlePosition", this.m_nTitlePosition.toString());
	xnChartAtomAttrib.setAttribute("TitleAlignment", this.m_nTitleAlignment.toString());
	
	xnChartAtomAttrib.setAttribute("Legend", (this.m_bLegend ? 1 : 0).toString());
	xnChartAtomAttrib.setAttribute("LegendPosition", this.m_nLegendPosition);
	xnChartAtomAttrib.setAttribute("LegendAlignment", this.m_nLegendAlignment);
	xnChartAtomAttrib.setAttribute("LegendBorder", this.m_nLegendBorder);
	xnChartAtomAttrib.setAttribute("ToolBar", (this.m_bToolBar? 1 : 0).toString());
	xnChartAtomAttrib.setAttribute("DataEditor", (this.m_bDataEditor? 1 : 0).toString());
	xnChartAtomAttrib.setAttribute("PointLabel", (this.m_bPointLabel? 1 : 0).toString());
	
	xnChartAtomAttrib.setAttribute("DirectExecute", (this.m_bDirectExecute? 1 : 0).toString());
	xnChartAtomAttrib.setAttribute("RealTime", (this.m_bRealtime? 1 : 0).toString());
	xnChartAtomAttrib.setAttribute("RealTimePeriod", this.m_strRealtimePeriod);
	xnChartAtomAttrib.setAttribute("RealTimeType", this.m_nRealtimeType);
	
	xnChartAtomAttrib.setAttribute("XAxisTickMark", this.m_nXAxisTickMark);
	xnChartAtomAttrib.setAttribute("XAxisScaleMin", (this.m_bXAxisScaleMin? 1 : 0).toString());
	xnChartAtomAttrib.setAttribute("XAxisScaleMax", (this.m_bXAxisScaleMax? 1 : 0).toString());
	xnChartAtomAttrib.setAttribute("XAxisScaleMinValue", this.m_nXAxisScaleMin);
	xnChartAtomAttrib.setAttribute("XAxisScaleMaxValue", this.m_nXAxisScaleMax);
	xnChartAtomAttrib.setAttribute("YAxisTickMark", this.m_nYAxisTickMark);
	xnChartAtomAttrib.setAttribute("YAxisScaleMin", (this.m_bYAxisScaleMin? 1 : 0).toString());
	xnChartAtomAttrib.setAttribute("YAxisScaleMax", (this.m_bYAxisScaleMax? 1 : 0).toString());
	xnChartAtomAttrib.setAttribute("YAxisScaleMinValue", this.m_nYAxisScaleMin);
	xnChartAtomAttrib.setAttribute("YAxisScaleMaxValue", this.m_nYAxisScaleMax);
	
	xnChartAtomAttrib.setAttribute("XAxisLabelAngle", this.m_nXAxisLableAngle);
	xnChartAtomAttrib.setAttribute("YAxisLabelAngle", this.m_nYAxisLableAngle);
	
	xnChartAtomAttrib.setAttribute("XAxisShowGridLine", (this.m_bXAxisShowGridLine? 1 : 0).toString());
	xnChartAtomAttrib.setAttribute("XAxisGridLineColor", this.m_strXAxisGridLineColor);
	xnChartAtomAttrib.setAttribute("XAxisGridLineStyle", this.m_nXAxisGridLineStyle);
	xnChartAtomAttrib.setAttribute("XAxisGridLineThick", this.m_nXAxisGridLineThick);
	xnChartAtomAttrib.setAttribute("YAxisShowGridLine", (this.m_bYAxisShowGridLine? 1 : 0).toString());
	xnChartAtomAttrib.setAttribute("YAxisGridLineColor", this.m_strYAxisGridLineColor);
	xnChartAtomAttrib.setAttribute("YAxisGridLineStyle", this.m_nYAxisGridLineStyle);
	xnChartAtomAttrib.setAttribute("YAxisGridLineThick", this.m_nYAxisGridLineThick);
}

/**
 * 각 챠트 아이템의 속성을 성정한다
 */
ChartAtom.prototype._setChartItemAttrib = function (xnAtom, alTempItemList)
{
	var xnChartItemAttrib = XmlLib.createChild(xnAtom, "ChartItemAttrib");
	
	ExecuteChartHelper.setXMLChartItem(xnChartItemAttrib, alTempItemList);
}

/**
 * 챠트의 Node에 속성을 설정한다
 * 이 메소드는 챠트가 모델에서 값을 가져올 경우에만 사용한다.
 */
ChartAtom.prototype._setChartStyleAttrib = function (xnAtom, objChartStyle)
{
	xnChartAttrib = XmlLib.createChild(xnAtom, "ChartStyleAttrib");
	
	xnChartAttrib.setAttribute("XPos", objChartStyle.getXPos());
	xnChartAttrib.setAttribute("YPos", objChartStyle.getYPos());
	xnChartAttrib.setAttribute("Width", objChartStyle.getWidth());
	xnChartAttrib.setAttribute("Height", objChartStyle.getHeight());
	xnChartAttrib.setAttribute("IsVisible", objChartStyle.isVisible());
	xnChartAttrib.setAttribute("IsVanish", objChartStyle.isVanish());
	xnChartAttrib.setAttribute("IsDisable", objChartStyle.isDisable());
	
	xnChartAttrib.setAttribute("ColorBackground", objChartStyle.getColorBackground());
	xnChartAttrib.setAttribute("ColorChartBackground", objChartStyle.getColorChartBackColor());
	
	xnChartAttrib.setAttribute("FontTitleName", objChartStyle.getFontTitleName());
	xnChartAttrib.setAttribute("FontTitleSize", objChartStyle.getFontTitleSize());
	xnChartAttrib.setAttribute("FontTitleStyle", objChartStyle.getFontTitleStyle());
	xnChartAttrib.setAttribute("FontTitleColor", objChartStyle.getColorTitle());
	
	xnChartAttrib.setAttribute("FontXAxisTitleName", objChartStyle.getFontXAxisTitleName());
	xnChartAttrib.setAttribute("FontXAxisTitleSize", objChartStyle.getFontXAxisTitleSize());
	xnChartAttrib.setAttribute("FontXAxisTitleStyle", objChartStyle.getFontXAxisTitleStyle());
	xnChartAttrib.setAttribute("ColorFontXAxisTitle", objChartStyle.getColorXAxisTitle());
	xnChartAttrib.setAttribute("FontYAxisTitleName", objChartStyle.getFontYAxisTitleName());
	xnChartAttrib.setAttribute("FontYAxisTitleSize", objChartStyle.getFontYAxisTitleSize());
	xnChartAttrib.setAttribute("FontYAxisTitleStyle", objChartStyle.getFontYAxisTitleStyle());
	xnChartAttrib.setAttribute("ColorFontYAxisTitle", objChartStyle.getColorYAxisTitle());
	
	xnChartAttrib.setAttribute("FontXAxisName", objChartStyle.getFontXAxisName());
	xnChartAttrib.setAttribute("FontXAxisSize", objChartStyle.getFontXAxisSize());
	xnChartAttrib.setAttribute("FontXAxisStyle", objChartStyle.getFontXAxisStyle());
	xnChartAttrib.setAttribute("ColorFontXAxis", objChartStyle.getColorXAxis());
	xnChartAttrib.setAttribute("FontYAxisName", objChartStyle.getFontYAxisName());
	xnChartAttrib.setAttribute("FontYAxisSize", objChartStyle.getFontYAxisSize());
	xnChartAttrib.setAttribute("FontYAxisStyle", objChartStyle.getFontYAxisStyle());
	xnChartAttrib.setAttribute("ColorFontYAxis", objChartStyle.getColorYAxis());
}

/**
 * 실행시 지정후 변경된 내용중, 챠트 검색값에서 삭제 되어야할 컬럼을 행으로 부터 삭제한다
 * @param nlRowData (기존 검색의 결과의 값의 행)
 * @param alRemoveIndex (삭제되어야 할 컬럼의 인덱스를 담은 리스트)
 */
ChartAtom.prototype._removeColDataFormRowData = function (xlRowData, alRemoveIndex)
{
	/*for (var i = 0, nLen = xlRowData.length; i < nLen; i++)
	{
		var xnRowData = xlRowData[i];
		
		var xlColData = XmlLib.selectNodeList(xlRowData[i], "ColData");
		
		for (var j = 0, nColLen = alRemoveIndex.length; j < nColLen; j++)
		{
			XmlLib.removeNode(xlRowData[i], xlColData[alRemoveIndex[j]]);
		}	
	}*/
	
	ExecuteChartHelper.removeColDataFormRowData(xlRowData, alRemoveIndex);
}

/**
 * 실행시 지정후 변경된 내용중, 챠트 검색값에서 삭제 되어야할 컬럼 이름을 삭제한다
 * @param xnColAttrib (기존 검색 결과중 컬럼 속성 xml)
 * @param nlRowData (기존 검색의 결과의 값의 행)
 * @param alRemoveIndex (삭제되어야 할 컬럼의 인덱스를 담은 리스트)
 */
ChartAtom.prototype._removeColNameFromColAttrib = function (xnColAttrib, xlColName, alRemoveIndex)
{
	/*for (var i = 0, nLen = alRemoveIndex.length; i < nLen; i++)
	{
		XmlLib.removeNode(xnColAttrib, xlColName[i]);
	}*/
	
	ExecuteChartHelper.removeColNameFromColAttrib(xnColAttrib, xlColName, alRemoveIndex);
}

/**
 * 실행시 지정의 결과에의해 기존 검색 결과중 삭제되어야할 컬럼 정보가 있는지 확인하고, 해당 컬럼의 인덱스리스트를 생성하여 반환한다
 * @param xnColName (기존 검색결과의 컬럼 이름 xml)
 * @param xlRowData (기전 검색결과의 값의 행 xml)
 * @param alTempItemList
 */
ChartAtom.prototype._getRemoveColIndexList = function (xlColName, xlRowData, alTempItemList)
{
	/*var alRemoveIndex = new Array();
	
	if (null == xlColName || null == xlRowData || null == alTempItemList)
	{
		return alRemoveIndex;
	}
	
	if (null != xlRowData && 0 < xlRowData.length)
	{
		var xlColData = XmlLib.selectNodeList(xlRowData[0], "./ColData");
		
		for (var i = 0, nColLen = xlColData.length; i < nColLen; i++)
		{
			if (false == isExistColData(xlColName[i], alTempItemList))
			{
				alRemoveIndex.push(i);
			}
		}
	}
	
	return alRemoveIndex;*/
	
	return ExecuteChartHelper.getRemoveColIndexList(xlColName, xlRowData, alTempItemList);
}

/**
 * 실행시 지정에 의해 바뀐 챠트 속성 중에 기존의 해당 컬럼이 존재 하는지의 여부를 체크한다.
 * 존재 하게 되면, 실행시 정에 의해 바뀐 챠트에도 존재하는 값이 된다 
 */
ChartAtom.prototype._isExistColData = function (xnColName, alTempItemList)
{
	/*if (null == alTempItemList)
	{
		return false;
	}
	
	for (var i = 0, nLen = alTempItemList.length; i < nLen; i++)
	{
		if (XmlLib.getTextValue(xnColName) == alTempItemList[i].getItemName())
		{
			return true;
		}
	}
	
	return false;*/
	
	return ExecuteChartHelper.isExistColData(xnColName, alTempItemList);
}

ChartAtom.prototype._getItemNameList = function (xnAtom)
{
	if (null == m_alChartItems)
	{
		return;
	}
	
	/*var xnColAttrib = XmlLib.selectSingleNode(xnAtom, "./ColAttrib");
	
	if (null == xnColAttrib)
	{
		return;
	}
	
	var arColNames = XmlLib.selectNodeList(xnColAttrib, "./ColName");
	
	var arItemNameList = new Array();


	for (var i = 0, nLen = arColNames.length; i < nLen; i++)
	{
		arItemNameList.push(XmlLib.getTextValue(arColNames[i]));
	}
	
	return arItemNameList;*/
	
	return ExecuteChartHelper.getItemNameList(xnAtom);
}
	
ChartAtom.prototype._forceExecute = function ()
{
	if (this.m_bRealtime)
	{
		var nDelayTime = parseInt(this.m_strRealtimePeriod);
		
		switch (this.m_nRealtimeType)
		{
			case ChartAtom.SECOND :
				// 초
				nDelayTime = nDelayTime * 1000;
				break;
			
			case ChartAtom.MINUTE :
				// 분
				nDelayTime = (nDelayTime * 1000) * 60;
				break;
				
			case ChartAtom.HOUR :
				// 시
				nDelayTime = (nDelayTime * 1000) * 360;
				break;
				
			case ChartAtom.DAY :
				// 일
				nDelayTime = ((nDelayTime * 1000) * 360) * 24;
				break;
		}
		
		window.setInterval("ChartAtom.realtimeSearch(\"" + this.m_strVarName + "\")", nDelayTime);
	}
}

/**
 * 아톰리스트
 */
ChartAtom._atoms = new Object();

ChartAtom.realtimeSearch = function (strVarName)
{
	var objAtom = ChartAtom._atoms[strVarName];
	
	objAtom.realtimeSearch();
}

ChartAtom.getAtom = function (strVarName)
{
	var objAtom = ChartAtom._atoms[strVarName];
	
	return objAtom;
}

ChartAtom.init = function ()
{
	for (var strVarName in ChartAtom._atoms)
	{
		var objAtom = ChartAtom._atoms[strVarName];
		
		if (null != objAtom)
		{
			objAtom.init();
		}
	}
}

/**
 * 모든 챠트 아톰의 요청정보를 만든다
 */
ChartAtom.makeRequest = function (xnAtomRequest)
{
	for (var strVarName in ChartAtom._atoms)
	{
		var objAtom = ChartAtom._atoms[strVarName];
		
		if (null != objAtom)
		{
			objAtom.makeRequest(xnAtomRequest);
		}
	}
}

/**
 * 즉시실행 요청 만들기
 */
ChartAtom.makeDireceExecRequest = function (xnAtomRequest)
{
	for (var strVarName in ChartAtom._atoms)
	{
		var objAtom = ChartAtom.getAtom(strVarName);
		
		if (objAtom.isDirectExec())
		{
			objAtom.makeRequest(xnAtomRequest);
		}
	}
}

/**
 * 챠트 아톰 리스트에서, 첫번째 챠트아톰을 찾아 반환한다
 */
ChartAtom.getFirstAtom = function ()
{
	var objChartAtom = null;
	
	for (var strVarName in ChartAtom._atoms)
	{
		objChartAtom = ChartAtom._atoms[strVarName];
		
		if (null != objChartAtom)
		{
			return objChartAtom;
		}
	}
	
	return objChartAtom;
}

ChartAtom.getRefAtom = function (strSearchAtomName)
{
	var objAtom = null;
	
	for (var strVarName in ChartAtom._atoms)
	{
		var objAtom = ChartAtom.getAtom(strVarName);
		
		if (objAtom.getRefVarName() == strSearchAtomName)
		{
			objAtom.makeRequest(xnAtomRequest);
		}
	}
	return objAtom;
}

ChartAtom.searchFromRefBrowse = function ()
{
	var objAtom = null;
	
	for (var strVarName in ChartAtom._atoms)
	{
		var objAtom = ChartAtom.getAtom(strVarName);
		
		// 데이터 원천이 검색창인가?
		if (1 == objAtom.getChartDataType())
		{
			objAtom.searchFromRefBrowse();
		}
	}
	
	return objAtom;
}

///////////////////////////////////////////
// 
// 런타임시에 변경되는 설정값만 변경이 가능


function ChartAtomRuntimeAttrib(b2D, nMulti, strXAxisTitle, nXAxisGrid, nXAxisLayout,
					strChartTitle, nTitlePosition, nTitleAlignment,
					strYAxisTitle, nYAxisGrid, nYAxisLayout,
					bLegend, nLegendPosition, nLegendAlignment, nLegendBorder,bToolBar, bDataEditor, bPointLabel,
					bDirectExecute, bRealtime, strRealtimePeriod, nRealtimeType,
					nXaxisTickMark, bXaxisScaleMin, bXaxisScaleMax, nXaxisScaleMin, nXaxisScaleMax,
					nYaxisTickMark, bYaxisScaleMin, bYaxisScaleMax, nYaxisScaleMin, nYaxisScaleMax,
					nXaxisLabelAngle, nYaxisLabelAngle, 
					bXaxisShowGridLine, strXaxisGridLineColor, nXaxisGridLineStyle, nXaxisGridLineThick,
					bYaxisShowGridLine, strYaxisGridLineColor, nYaxisGridLineStyle, nYaxisGridLineThick
					)
{
	this.m_b2D 		 		= b2D; 				// 3D 효과 여부	c
	this.m_nMulti 			= nMulti;			// 다중데이터
	this.m_strXAxisTitle 	= strXAxisTitle; 	// X축 제목	c
	this.m_nXAxisGrid 		= nXAxisGrid; 		// X축 세로선 표시	c
	this.m_strChartTitle 	= strChartTitle; 	// 챠트 제목	c
	this.m_nXAxisLayout 		= nXAxisLayout;		// X축 항목명 배치	c
	this.m_nTitlePosition 	= nTitlePosition; 	// 챠트위치	c
	this.m_nTitleAlignment 	= nTitleAlignment; 	// 챠트 제목 정렬	c
	this.m_strYAxisTitle 	= strYAxisTitle; 	// Y축 제목	c
	this.m_nYAxisGrid 		= nYAxisGrid; 		// Y축 세로선 표시	c
	this.m_nYAxisLayout 		= nYAxisLayout; 	// Y축 항목명 배치	c	접두어 ?
	
	this.m_bLegend = bLegend;	// 범례 사용여부
	this.m_nLegendPosition = nLegendPosition;	// 범례 위치
	this.m_nLegendAlignment = nLegendAlignment;	// 범례 정렬
	this.m_nLegendBorder = nLegendBorder;		// 범례 테두리
	this.m_bToolBar = bToolBar;		// 도구바 사용여부
	this.m_bDataEditor = bDataEditor;	// 데이터편집기 사용여부
	this.m_bPointLabel = bPointLabel;	// 포인트라벨 사용여부
	
	this.m_bDirectExecute = bDirectExecute;	// 즉시 실행 여부
	this.m_bRealTim	= bRealtime;	// 실시간 처리 여부
	this.m_strRealtimePeriod = strRealtimePeriod;	// 실시간 처리 범위
	this.m_nRealtimeType	= nRealtimeType; // 실시간 처리 단위
	
	this.m_nXaxisTickMark = nXaxisTickMark;	// X축 눈금 표시
	this.m_bXaxisScaleMin = bXaxisScaleMin; // X축 최소값 설정 여부
	this.m_bXaxisScaleMax = bXaxisScaleMax;	// X축 최대값 설정 여부
	this.m_nXaxisScaieMin = nXaxisScaleMin;	// X축 최소값
	this.m_nXaxisScaleMax = nXaxisScaleMax;	// X축 최대값
	this.m_nYaxisTickMark = nYaxisTickMark;	// Y축 눈금 표시
	this.m_bYaxisScaleMin = bYaxisScaleMin; // Y축 최소값 설정 여부
	this.m_bYaxisScaleMax = bYaxisScaleMax;	// Y축 최대값 설정 여부
	this.m_nYaxisScaieMin = nYaxisScaleMin;	// Y축 최소값
	this.m_nYaxisScaleMax = nYaxisScaleMax;	// Y축 최대값
	
	this.m_nXaxisLableAngle = nXaxisLabelAngle;	// X축 항목제목 각도
	this.m_nYaxisLableAngle = nYaxisLabelAngle;	// Y축 항목제목 각도
	
	this.m_bXaxisShowGridLine = bXaxisShowGridLine;	// X축 보조선 설정 여부
	this.m_strXaxisGridLineColor = strXaxisGridLineColor;	// X축 보조선 색상
	this.m_nXaxisGridLineStyle = nXaxisGridLineStyle;	// X축 보조선 종류
	this.m_nXaxisGridLineThick = nXaxisGridLineThick;	// X축 보조선 굵기

	this.m_bYaxisShowGridLine = bYaxisShowGridLine;	// Y축 보조선 설정 여부
	this.m_strYaxisGridLineColor = strYaxisGridLineColor;	// Y축 보조선 색상
	this.m_nYaxisGridLineStyle = nYaxisGridLineStyle;	// Y축 보조선 종류
	this.m_nYaxisGridLineThick = nYaxisGridLineThick;	// Y축 보조선 굵기
}
	
////////////////////////////////////////////
// getter
//

ChartAtomRuntimeAttrib.prototype.get2D = function ()
{
	return m_b2D;
}

ChartAtomRuntimeAttrib.prototype.getMulti = function ()
{
	return nMulti;
}

ChartAtomRuntimeAttrib.prototype.getXAxisTitle = function ()
{
	return m_strXAxisTitle;
}

ChartAtomRuntimeAttrib.prototype.getXAxisGrid = function ()
{
	return m_nXAxisGrid;
}

ChartAtomRuntimeAttrib.prototype.getChartTitle = function ()
{
	return m_strChartTitle;
}

ChartAtomRuntimeAttrib.prototype.getXAxisLayout = function ()
{
	return m_nXAxisLayout;
}

ChartAtomRuntimeAttrib.prototype.getTitlePosition = function ()
{
	return m_nTitlePosition;
}

ChartAtomRuntimeAttrib.prototype.getTitleAlignment = function ()
{
	return m_nTitleAlignment;
}

ChartAtomRuntimeAttrib.prototype.getYAxisTitle = function ()
{
	return m_strYAxisTitle;
}

ChartAtomRuntimeAttrib.prototype.getYAxisGrid = function ()
{
	return m_nYAxisGrid;
}

ChartAtomRuntimeAttrib.prototype.getYAxisLayout = function ()
{
	return m_nYAxisLayout;
}

ChartAtomRuntimeAttrib.prototype.getLegend = function ()
{
	return m_bLegend;
}

ChartAtomRuntimeAttrib.prototype.getLegendPosition = function ()
{
	return m_nLegendPosition;
}

ChartAtomRuntimeAttrib.prototype.getLegendAlignment = function ()
{
	return m_nLegendAlignment;
}

ChartAtomRuntimeAttrib.prototype.getLegendOutline = function ()
{
	return m_nLegendOutline;
}

////////////////////////////////////////////
// setter
//

ChartAtomRuntimeAttrib.prototype.set2D = function (b2D)
{
	m_b2D = b2D;
}

ChartAtomRuntimeAttrib.prototype.setMulti = function (nMulti)
{
	m_nMulti = nMulti;
}

ChartAtomRuntimeAttrib.prototype.setXAxisTitle = function (strXAxisTitle)
{
	m_strXAxisTitle = strXAxisTitle;
}

ChartAtomRuntimeAttrib.prototype.setXAxisGrid = function (nXAxisGrid)
{
	m_nXAxisGrid = nXAxisGrid;
}

ChartAtomRuntimeAttrib.prototype.setChartTitle = function (strChartTitle)
{
	m_strChartTitle = strChartTitle;
}

ChartAtomRuntimeAttrib.prototype.setXAxisLayout = function (nXAxisLayout)
{
	m_nXAxisLayout = nXAxisLayout;
}

ChartAtomRuntimeAttrib.prototype.setTitlePosition = function (nTitlePosition)
{
	m_nTitlePosition = nTitlePosition;
}

ChartAtomRuntimeAttrib.prototype.setTitleAlignment = function (nTitleAlignment)
{
	m_nTitleAlignment = nTitleAlignment;
}

ChartAtomRuntimeAttrib.prototype.setYAxisTitle = function (strYAxisTitle)
{
	m_strYAxisTitle = strYAxisTitle;
}

ChartAtomRuntimeAttrib.prototype.setYAxisGrid = function (nYAxisGrid)
{
	m_nYAxisGrid = nYAxisGrid;
}

ChartAtomRuntimeAttrib.prototype.setYAxisLayout = function (nYAxisLayout)
{
	m_nYAxisLayout = nYAxisLayout;
}

ChartAtomRuntimeAttrib.prototype.setLegend = function (bLegend)
{
	m_bLegend = bLegend;
}

ChartAtomRuntimeAttrib.prototype.setLegendPosition = function (nLegendPosition)
{
	m_nLegendPosition = nLegendPosition;
}

ChartAtomRuntimeAttrib.prototype.setLegendAlignment = function (nLegendAlignment)
{
	m_nLegendAlignment = nLegendAlignment;
}

ChartAtomRuntimeAttrib.prototype.setLegendOutline = function (nLegendOutline)
{
	m_nLegendOutline = nLegendOutline;
}


function ChartAtomStyle (nXPos, nYPos, nWidth, nHeight
						, bVisible, bVanish, bDisable
						, strColorBackground, strColorChartBackground
						, strFontTitleName, nFontTitleSize, nFontTitleStyle, strColorTitle
						, strFontXAxisTitleName, nFontXAxisTitleSize, nFontXAxisTitleStyle, strColorXAxisTitle
						, strFontYAxisTitleName, nFontYAxisTitleSize, nFontYAxisTitleStyle, strColorYAxisTitle
						, strFontXAxisName, nFontXAxisSize, nFontXAxisStyle, strColorXAxis
						, strFontYAxisName, nFontYAxisSize, nFontYAxisStyle, strColorYAxis
						)
{
	this.m_nXPos = nXPos; 
	this.m_nYPos = nYPos; 
	this.m_nWidth = nWidth; 
	this.m_nHeight = nHeight; 
	this.m_bVisible = bVisible;					// 보이기
	this.m_bVanish = bVanish;					// 선택
	this.m_bDisable = bDisable;					// 비활성화	
	
	this.m_strColorBackground		= strColorBackground; 		// 전체배경 색상
	this.m_strColorChartBackground	= strColorChartBackground;	// 차트배경 색상
	this.m_strFontTitleName			= strFontTitleName;			// 제목글꼴 종류
	this.m_nFontTitleSize			= nFontTitleSize;			// 제목글꼴 크기
	this.m_nFontTitleStyle			= nFontTitleStyle;			// 제목글꼴 스타일
	this.m_strColorTitle			= strColorTitle;			// 제목글꼴 색상
	this.m_strFontXAxisTitleName	= strFontXAxisTitleName;	// X축 제목글꼴 종류
	this.m_nFontXAxisTitleSize		= nFontXAxisTitleSize;		// X축 제목글꼴 크기
	this.m_nFontXAxisTitleStyle		= nFontXAxisTitleStyle;		// X축 제목글꼴 스타일
	this.m_strColorXAxisTitle		= strColorXAxisTitle;		// X축 제목글꼴 색상
	this.m_strFontYAxisTitleName	= strFontYAxisTitleName;	// Y축 제목글꼴 종류
	this.m_nFontYAxisTitleSize		= nFontYAxisTitleSize;		// Y축 제목글꼴 크기
	this.m_nFontYAxisTitleStyle		= nFontYAxisTitleStyle;		// Y축 제목글꼴 스타일
	this.m_strColorYAxisTitle		= strColorYAxisTitle;		// Y축 제목글꼴 색상
	this.m_strFontXAxisName			= strFontXAxisName;			// X축 글꼴 종류
	this.m_nFontXAxisSize			= nFontXAxisSize;			// X축 글꼴 크기
	this.m_nFontXAxisStyle			= nFontXAxisStyle;			// X축 글꼴 스타일
	this.m_strColorXAxis			= strColorXAxis;			// X축 글꼴 색상
	this.m_strFontYAxisName			= strFontYAxisName;			// X축 글꼴 종류
	this.m_nFontYAxisSize			= nFontYAxisSize;			// X축 글꼴 크기
	this.m_nFontYAxisStyle			= nFontYAxisStyle;			// X축 글꼴 스타일
	this.m_strColorYAxis			= strColorYAxis;			// X축 글꼴 색상
}

///////////////////////////////////
// getter
//

ChartAtomStyle.prototype.getXPos = function ()
{
	return this.m_nXPos;
}

ChartAtomStyle.prototype.getYPos = function ()
{
	return this.m_nYPos;
}

ChartAtomStyle.prototype.getWidth = function ()
{
	return this.m_nWidth;
}

ChartAtomStyle.prototype.getHeight = function ()
{
	return this.m_nHeight;
}

ChartAtomStyle.prototype.isVisible = function ()
{
	return this.m_bVisible;
}

ChartAtomStyle.prototype.isVanish = function ()
{
	return this.m_bVanish;
}

ChartAtomStyle.prototype.isDisable = function ()
{
	return this.m_bDisable;
}

ChartAtomStyle.prototype.getColorBackground = function ()
{
	return this.m_strColorBackground;
}
ChartAtomStyle.prototype.getColorChartBackColor = function ()
{
	return this.m_strColorChartBackground;
}
ChartAtomStyle.prototype.getFontTitleName = function()
{
	return this.m_strFontTitleName;
}
ChartAtomStyle.prototype.getFontTitleSize = function()
{
	return this.m_nFontTitleSize;
}
ChartAtomStyle.prototype.getFontTitleStyle = function()
{
	return this.m_nFontTitleStyle;
}
ChartAtomStyle.prototype.getColorTitle = function()
{
	return this.m_strColorTitle;
}
ChartAtomStyle.prototype.getFontXAxisTitleName = function ()
{
	return this.m_strFontXAxisTitleName;
}
ChartAtomStyle.prototype.getFontXAxisTitleSize = function ()
{
	return this.m_nFontXAxisTitleSize;
}
ChartAtomStyle.prototype.getFontXAxisTitleStyle = function ()
{
	return this.m_nFontXAxisTitleStyle;
}
ChartAtomStyle.prototype.getColorXAxisTitle = function ()
{
	return this.m_strColorXAxisTitle;
}
ChartAtomStyle.prototype.getFontYAxisTitleName = function ()
{
	return this.m_strFontYAxisTitleName;
}
ChartAtomStyle.prototype.getFontYAxisTitleSize = function ()
{
	return this.m_nFontYAxisTitleSize;
}
ChartAtomStyle.prototype.getFontYAxisTitleStyle = function ()
{
	return this.m_nFontYAxisTitleStyle;
}
ChartAtomStyle.prototype.getColorYAxisTitle = function ()
{
	return this.m_strColorYAxisTitle;
}
ChartAtomStyle.prototype.getFontXAxisName = function ()
{
	return this.m_strFontXAxisName;
}
ChartAtomStyle.prototype.getFontXAxisSize = function ()
{
	return this.m_nFontXAxisSize;
}
ChartAtomStyle.prototype.getFontXAxisStyle = function ()
{
	return this.m_nFontXAxisStyle;
}
ChartAtomStyle.prototype.getColorXAxis = function ()
{
	return this.m_strColorXAxis;
}
ChartAtomStyle.prototype.getFontYAxisName = function ()
{
	return this.m_strFontYAxisName;
}
ChartAtomStyle.prototype.getFontYAxisSize = function ()
{
	return this.m_nFontYAxisSize;
}
ChartAtomStyle.prototype.getFontYAxisStyle = function ()
{
	return this.m_nFontYAxisStyle;
}
ChartAtomStyle.prototype.getColorYAxis = function ()
{
	return this.m_strColorYAxis;
}

// 형만 맞춰놓았음.
ChartAtomStyle.prototype.getFontFamily = function ()
{
	
}

ChartAtomStyle.prototype.getFontSize = function ()
{
	
}

ChartAtomStyle.prototype.getFontColor = function ()
{
	
}

ChartAtomStyle.prototype.getIsBold = function ()
{
	
}

ChartAtomStyle.prototype.getIsItalic = function ()
{
	
}

ChartAtomStyle.prototype.getIsUnderline = function ()
{
	
}

ChartAtomStyle.prototype.getIsStrikeout = function ()
{
	
}

///////////////////////////////////
// setter
//

ChartAtomStyle.prototype.setXPos = function (nXPos)
{
	this.m_nXPos = nXPos;
}

ChartAtomStyle.prototype.setYPos = function (nYPos)
{
	this.m_nYPos = xYPos;
}

ChartAtomStyle.prototype.setWidth = function (nWidth)
{
	this.m_nWidth = nWidth;
}

ChartAtomStyle.prototype.setHeight = function (nHeight)
{
	this.m_nHeight = nHeight
}

ChartAtomStyle.prototype.setIsVisible = function (bVisible)
{
	this.m_bVisible = bVisible;
}

ChartAtomStyle.prototype.setIsVanish = function (bVanish)
{
	this.m_bVanish = bVanish;
}

ChartAtomStyle.prototype.setIsDisable = function (bDisable)
{
	this.m_bDisable = bDisable;
}

ChartAtomStyle.prototype.setColorChartBackColor = function (objColor)
{
	this.m_strColorChartBackground = objColor;
}

ChartAtomStyle.prototype.setFontFamily = function (objColor)
{
	
}

ChartAtomStyle.prototype.setFontSize = function (objColor)
{
	
}


/**
 * 계열설정	X 축 0
 * 			Y 축 1
 *
 * 챠트함수	실제값 0 
 *			합계    1
 *			빈도수 2
 *			평균값 3
 *			최대값 4
 *			최소값 5
 *
 * 챠트종류	세로막대 0
 *			가로막대 1
 *			영역 2
 *			꺾은선 3
 *			물방울 4
 *			원형 5
 *			도우넛 6
 *			분산 7
 *			주식형 8
 *			곡선 9
 *			영역곡선 10
 *			계단 11
 *			큐브 12
 *			파레토 13
 */


function ChartItems (strItems)
{
	this.m_strItems = strItems;
	
	this.m_strDBName = "";	// 디비명
	this.m_strTableName = ""; // 테이블명
	this.m_strFieldName = ""; // 필드명
	this.m_nDBIndex = 1; // DBIndex
	this.m_strItemTitle = ""; // 항목제목
	this.m_strItemName = ""; // 항목명
	this.m_strChartCategory = ""; // 챠트계열 (X, Y 축)
	this.m_strChartFunction = ""; // 챠트함수
	this.m_strChartType = ""; // 챠트종류
	this.m_bHidden = false; // 표시안함
	
	this.m_strDataType = ""; // 자료형
	this.m_nDataSize = 0; // 최대자릿수
}
	
///////////////////////////////////////////
// getter / setter
//

ChartItems.prototype.getDBName = function ()
{
	return this.m_strDBName;
}

ChartItems.prototype.getTableName = function ()
{
	return this.m_strTableName;
}

ChartItems.prototype.getFieldName = function ()
{
	return this.m_strFieldName;
}

ChartItems.prototype.getDBIndex = function ()
{
	return this.m_nDBIndex;	
}
ChartItems.prototype.getItemTitle = function ()
{
	return this.m_strItemTitle;
}

ChartItems.prototype.getItemName = function ()
{
	return this.m_strItemName;
}

ChartItems.prototype.getChartCategory = function ()
{
	return this.m_strChartCategory;
}

ChartItems.prototype.getChartFunction = function ()
{
	return this.m_strChartFunction;
}

ChartItems.prototype.getChartType = function ()
{
	return this.m_strChartType;
}

ChartItems.prototype.isHidden = function ()
{
	return this.m_bHidden;
}	

ChartItems.prototype.getDataType = function ()
{
	return this.m_strDataType;
}

ChartItems.prototype.getDataSize = function ()
{
	return this.m_nDataSize;
}

///////////////////////////////////////////
// public method
//

ChartItems.prototype.init = function ()
{
	var arItems = this.m_strItems.split(";");
	
	// 내용이 12개이면 DB로부터 가져온 경우이고
	// 그렇지 않으면 검색창으로 부터온 경우 이다
	if (12 == arItems.length)
	{
		this.m_strTableName = arItems[0];
		this.m_strFieldName = arItems[1];
		this.m_nDBIndex = parseInt(arItems[2]);
		this.m_strItemTitle = arItems[3];
		this.m_strItemName = arItems[4];
		this.m_strChartCategory = arItems[5];
		this.m_strChartFunction = arItems[6];
		this.m_strChartType = arItems[7];
		this.m_bHidden = this.getHiddenToBooleanType(arItems[8]);
		this.m_strDBName = arItems[9];
		this.m_strDataType = arItems[10];
		this.m_nDataSize = parseInt(arItems[11]);
	}
	else
	{
		// DBIndex, 항목명, XY 축, 함수, 챠트종류, 표시안함 상태는 확인 하였으나
		// 그외의 내용은 불명확 한 상태이다
		//m_nDBIndex = parseInt(arItems[2]);
		this.m_strItemTitle = arItems[3];
		this.m_strItemName = arItems[3];
		this.m_strChartCategory = arItems[5];
		this.m_strChartFunction = arItems[6];
		this.m_strChartType = arItems[7];
		this.m_bHidden = this.getHiddenToBooleanType(arItems[8]);
	}
}

///////////////////////////////////////////
// private method
//

ChartItems.prototype.getHiddenToBooleanType = function (strHidden)
{
	if (null == strHidden)
	{
		return false;
	}
	else
	{
		strHidden = strHidden.toUpperCase();
			
		if ("TRUE" == strHidden)
		{
			return true;
		}
		return false;
	}
}


function ExecuteChartForRuntime ()
{
	this.m_alChartItems = null;
}

ExecuteChartForRuntime.prototype.execute = function (xnAtom)
{
	var xnOrgAtom = xnAtom.cloneNode(true);
	
	var objAttrib = null;
	var objStyle = null;
	var objChartStyle = new ChartAtomStyle (370, 240, 440, 410, false, 0, 0, 0, "-4144960", "굴림체", 9, "-16777216", "N", "N", "N", "N", false, false, false);
	
	var alItemList = ExecuteChartHelper.showChartAttribDialog(ExecuteChartHelper.getItemNameList(xnAtom));
	
	if (null != alItemList)
	{
		alTempItemList = new Array();

		for (var i = 0, nLen = alItemList.length; i < nLen - 2; i++)
		{
			var objItem = alItemList[i];
			
			var objNewChartItem = new ChartItems(new Array("", "", ""
			, objItem.ItemTitle, "", objItem.Category
			, objItem.ChartFunction, objItem.ChartType, objItem.Hide).join(";"))

			objNewChartItem.init();

			alTempItemList.push(objNewChartItem);
		}
		
		// 차트 속성 추출
		objAttrib = alItemList[alItemList.length - 2];
		
		// 차트 스타일 추출
		objStyle = alItemList[alItemList.length - 1];
		
		var xnColAttrib = XmlLib.selectSingleNode(xnAtom, "./ColAttrib")
		var xlColName = XmlLib.selectNodeList(xnColAttrib, "./ColName")
		var xlRowData = XmlLib.selectNodeList(xnAtom, "./Value/RowData");
		
		var alRemoveIndex = ExecuteChartHelper.getRemoveColIndexList(xlColName, xlRowData, alTempItemList);
		
		ExecuteChartHelper.removeColDataFormRowData(xlRowData, alRemoveIndex);
		
		ExecuteChartHelper.removeColNameFromColAttrib(xnColAttrib, xlColName, alRemoveIndex);
		
		if (null == alTempItemList)
		{
			alTempItemList = this.m_alChartItems;
		}
		
		// 차트 설정을 XML에 저장
		this.setChartAtomRuntimeAttrib(xnAtom, alTempItemList, objAttrib);
	
		// 아이템 설정을 XML에 저장
		this.setChartItemAttrib(xnAtom, alTempItemList);
		
		// 스타일 객체의값을 바꾼다
		this.setChartRuntimeStyleAttrib(objStyle, objChartStyle);	//스타일객체의 값만 바꾼다
		
		// 스타일 객체의 값을 XML에 저장
		this.setChartStyleAttrib(xnAtom, objChartStyle, objAttrib);
		
		return true;
	}
	else
	{
		xnAtom = xnOrgAtom;
		
		return false;
	}
}

// 차트 출력 - 실행시 지정
ExecuteChartForRuntime.prototype.setChartAtomRuntimeAttrib = function (xnAtom, alTempItemList, objAttrib)
{
	var xnChartAtomAttrib = XmlLib.createChild(xnAtom, "ChartAtomAttrib");
	
	xnChartAtomAttrib.setAttribute("Gallery", alTempItemList[1].getChartType());
	
	ExecuteChartHelper.setXMLChartAtom(xnChartAtomAttrib, alTempItemList, objAttrib);
}

/**
 * 각 챠트 아이템의 속성을 설정한다
 * 챠트 연결에서 사용
 */
ExecuteChartForRuntime.prototype.setChartItemAttribForConnect = function (xnAtom, alTempItemList)
{
	var xnTempChartItem = XmlLib.createXML("ChartItemAttrib");
	var xnChartItemAttrib = xnTempChartItem.documentElement;
	
	ExecuteChartHelper.setXMLChartItem(xnChartItemAttrib, alTempItemList);
	
	XmlLib.importChildNode(xnAtom, xnChartItemAttrib, true);
}

/**
 * 각 챠트 아이템의 속성을 설정한다
 * 차트 출력에서 사용
 */
ExecuteChartForRuntime.prototype.setChartItemAttrib = function (xnAtom, alTempItemList)
{
	var xnChartItemAttrib = XmlLib.createChild(xnAtom, "ChartItemAttrib");
	
	ExecuteChartHelper.setXMLChartItem(xnChartItemAttrib, alTempItemList);
}	

/**
 * 챠트의 Node에 속성을 설정한다
 * 이 메소드는 챠트가 모델에서 값을 가져올 경우에만 사용한다.
 */
ExecuteChartForRuntime.prototype.setChartStyleAttrib = function (xnAtom, objChartStyle, objAttrib)
{
	xnChartAttrib = XmlLib.createChild(xnAtom, "ChartStyleAttrib");
	ExecuteChartHelper.setXMLChartStyle(xnChartAttrib, objChartStyle, objAttrib);
}

/**
 * 실행시 지정된 챠트 스타일값을 설정한다
 * 그리기 속성은차후에 추가 됨
 */
ExecuteChartForRuntime.prototype.setChartRuntimeStyleAttrib = function (objStyle, objChartStyle)
{
	objChartStyle.setColorChartBackColor(objStyle.BackColor);
	objChartStyle.setFontFamily(objStyle.FontFamily);
	objChartStyle.setFontSize(objStyle.FontSize);
}


function ExecuteConnectionChart ()
{
	this.m_alChartItems = null;
}

/**
 *	@return 챠트를 실행할지 여부
 */
ExecuteConnectionChart.prototype.execute = function (xnAtom)
{
	// 속성 지정이 실패할 경우를 대비해 오리지날을 복사해 둔다
	var xnOrgAtom = xnAtom.cloneNode(true);
	
	var objAttrib = null;
	var objStyle = null;
	var objChartStyle = new ChartAtomStyle (370, 240, 440, 410, false, false, false, "-4144960", "-460545", 
											"굴림체", 9, 0, "-16777216", "굴림체", 9, 0, "-16777216", "굴림체", 9, 0, "-16777216",
											"굴림체", 9, 0, "-16777216","굴림체", 9, 0, "-16777216");
	
	var alItemList = ExecuteChartHelper.showChartAttribDialog(ExecuteChartHelper.getItemNameList(xnAtom));
	
	if (null == alItemList)
	{
		return false;
	}
	
	alTempItemList = new Array();

	for (var i = 0, nLen = alItemList.length; i < nLen - 2; i++)
	{
		var objItem = alItemList[i];
		
		var objNewChartItem = new ChartItems(new Array("", "", ""
		, objItem.ItemTitle, "", objItem.Category
		, objItem.ChartFunction, objItem.ChartType, objItem.Hide).join(";"))

		objNewChartItem.init();

		alTempItemList.push(objNewChartItem);
	}
	
	// 차트 속성 추출
	objAttrib = alItemList[alItemList.length - 2];
	
	// 차트 스타일 추출
	objStyle = alItemList[alItemList.length - 1];
	
	var xnColAttrib = XmlLib.selectSingleNode(xnAtom, "./ColAttrib")
	var xlColName = XmlLib.selectNodeList(xnColAttrib, "./ColName")
	var xlRowData = XmlLib.selectNodeList(xnAtom, "./Value/RowData");
	
	var alRemoveIndex = ExecuteChartHelper.getRemoveColIndexList(xlColName, xlRowData, alTempItemList);
	
	ExecuteChartHelper.removeColDataFormRowData(xlRowData, alRemoveIndex);
	
	ExecuteChartHelper.removeColNameFromColAttrib(xnColAttrib, xlColName, alRemoveIndex);
	
	if (null == alTempItemList)
	{
		alTempItemList = this.m_alChartItems;
	}
	
	// 차트 설정을 XML에 저장
	this.setChartAtomRuntimeAttribForConnect(xnAtom, alTempItemList, objAttrib);

	// 아이템 설정을 XML에 저장
	this.setChartItemAttribForConnect(xnAtom, alTempItemList);
	
	// 스타일 객체의값을 바꾼다
	this.setChartRuntimeStyleAttrib(objStyle, objChartStyle);	//스타일객체의 값만 바꾼다
	
	// 스타일 객체의 값을 XML에 저장
	this.setChartStyleAttribForConnect(xnAtom, objChartStyle, objAttrib);
	
	return true;
}

// 챠트 연결
ExecuteConnectionChart.prototype.setChartAtomRuntimeAttribForConnect = function (xnAtom, alTempItemList, objAttrib)
{
	var xnTempChartAtom = XmlLib.createXML("ChartAtomAttrib");
	var xnChartAtomAttrib = xnTempChartAtom.documentElement;
	
	ExecuteChartHelper.setXMLChartAtom(xnChartAtomAttrib, alTempItemList, objAttrib);
	
	// 차트연결로 사용할 경우 첫번째는 노드가 이니기 때문에 XmlLib.createChild로 노드를 추가할 수 없다
	// 그래서 챠트 애트리뷰트 XML을 생성하고 XmlLib.importChildNode를 사용해서 원래 XML에 집어놓는다
	XmlLib.importChildNode(xnAtom, xnChartAtomAttrib, true);
}

/**
 * 각 챠트 아이템의 속성을 설정한다
 * 챠트 연결에서 사용
 */
ExecuteConnectionChart.prototype.setChartItemAttribForConnect = function (xnAtom, alTempItemList)
{
	var xnTempChartItem = XmlLib.createXML("ChartItemAttrib");
	var xnChartItemAttrib = xnTempChartItem.documentElement;
	
	ExecuteChartHelper.setXMLChartItem(xnChartItemAttrib, alTempItemList);
	
	XmlLib.importChildNode(xnAtom, xnChartItemAttrib, true);
}

/**
 * 각 챠트 아이템의 속성을 설정한다
 * 차트 출력에서 사용
 */
ExecuteConnectionChart.prototype.setChartItemAttrib = function (xnAtom, alTempItemList)
{
	var xnChartItemAttrib = XmlLib.createChild(xnAtom, "ChartItemAttrib");
	
	ExecuteChartHelper.setXMLChartItem(xnChartItemAttrib, alTempItemList);
}	

/**
 * 챠트의 Node에 속성을 설정한다
 * 이 메소드는 챠트가 모델에서 값을 가져올 경우에만 사용한다.
 */
ExecuteConnectionChart.prototype.setChartStyleAttrib = function (xnAtom, objChartStyle, objAttrib)
{
	xnChartAttrib = XmlLib.createChild(xnAtom, "ChartStyleAttrib");
	ExecuteChartHelper.setXMLChartStyle(xnChartAttrib, objChartStyle, objAttrib);
}

/**
 * 챠트의 Node에 속성을 설정한다
 * 챠트 연결에서 사용
 */
ExecuteConnectionChart.prototype.setChartStyleAttribForConnect = function (xnAtom, objChartStyle, objAttrib)
{
	var xnTempStyle = XmlLib.createXML("ChartStyleAttrib");
	var xnChartAttrib = xnTempStyle.documentElement;
	
	ExecuteChartHelper.setXMLChartStyle(xnChartAttrib, objChartStyle, objAttrib);
	
	XmlLib.importChildNode(xnAtom, xnChartAttrib, true);
}

/**
 * 실행시 지정된 챠트 스타일값을 설정한다
 * 그리기 속성은차후에 추가 됨
 */
ExecuteConnectionChart.prototype.setChartRuntimeStyleAttrib = function (objStyle, objChartStyle)
{
	objChartStyle.setColorChartBackColor(objStyle.BackColor);
	objChartStyle.setFontFamily(objStyle.FontFamily);
	objChartStyle.setFontSize(objStyle.FontSize);
}
