/**
 * CheckRadioAtom JS 클래스 리스트
 * CheckAtom
 * RadioAtom
 */

function CheckAtom(strVarName, nScriptIndex, strDispType, 
	bScroll, strScrollName, bSureInputScroll, 
	strTableName, strFieldName, strFieldType, bVanish, bRelatedOperation,
	strHyperLinkName, strTabId)
{
	this.Atom (strVarName, "", strScrollName, -1, nScriptIndex);
	
	/*
	* 세단계 체크박스 여부
	*/
	this.m_bThreeState = false;
	/*
	* 체크상태, 체크안된상태->체크된상태->미결정상태.
	*/
	this.m_nState = CheckAtom.Unchecked;
	
	this.m_strDispType = strDispType;
	
	this.m_bScroll = bScroll;
	this.m_bSureInputScroll = bSureInputScroll;

	this.m_strUnCheckedValue = "";
	this.m_strCheckedValue = "";
	this.m_strPartialCheckedValue = "";
	
	this.m_strOldValue = ""; // onChange 이벤트를 강제로 발생시키기 위해 이전값을 저장합니다.
	this.m_strValue = "";
	
	this.m_strSaveType = ""; //check atom 저장속성
	this.m_nRowIndex = -1;
	
	this.m_strTableName = strTableName;
	this.m_strFieldName = strFieldName;
	this.m_strFieldType = strFieldType;
	
	this.m_bVanish = bVanish;
	
 	this.m_bOperation = true; // 연산식을 발생시킬것인가?
 	this.m_bRelatedOperation = bRelatedOperation;
 	this.m_strHyperLinkName = strHyperLinkName;
 	this.m_strTabId = strTabId;
 	
	// CheckAtom의 HTML은 Input이 아니라 Input를 감싸고 있는 DIV테그이다. 
	this.m_heAtom = document.getElementById(strVarName);
	
	if (null != strHyperLinkName && 0 < strHyperLinkName.length)
	{
		this.m_heAtom.style.cursor = "hand";
	}
}

CheckAtom.prototype = new Atom ();
CheckAtom.prototype.constructor = CheckAtom;

CheckAtom.prototype.getAtomType = function ()
{
	return "CheckAtom";
}

CheckAtom.prototype.getValue = function ()
{
	return this.m_strValue;
}

CheckAtom.prototype.isChecked = function ()
{
	return (Utils.trim(this.m_strCheckedValue) == Utils.trim(this.m_strValue))? true : false; 
}

CheckAtom.prototype.isUnChecked = function ()
{
	return (CheckAtom.Unchecked == this.m_nState);
}

/**
 * 아톰리스트에 추가
 */
CheckAtom.prototype.putAtom = function ()
{
	CheckAtom._atoms[this.m_strVarName] = this;
}

CheckAtom.prototype.setValue = function (strValue)
{
	strValue = Utils.trim(strValue);
	
	// 모두선택'과 '선택안함' 값이 없으면 토글동작
	if ("" == this.m_strCheckedValue && "" == this.m_strUnCheckedValue)
	{
		if ("toggle" == strValue)
		{
			this.m_nState = (CheckAtom.Checked == this.m_nState) ? CheckAtom.Unchecked : CheckAtom.Checked;
			this.displayValue();
		}
	}
	else
	{	
		switch (strValue)
		{
			case this.m_strCheckedValue:
				this.m_nState = CheckAtom.Checked;
				break;
			case this.m_strUnCheckedValue:
				this.m_nState = CheckAtom.Unchecked;
				break;
			case this.m_strPartialCheckedValue:
				this.m_nState = CheckAtom.Indeterminate;
				break;
			default:
				this.m_nState = CheckAtom.Unchecked;
		}
		
		if (strValue != this.m_strValue)
		{
			this.m_strValue = strValue;
			this.displayValue();
		}	
	}
}

CheckAtom.prototype.getHTML = function ()
{
	return this.m_heAtom;
}

CheckAtom.prototype.setHTML = function(heAtom)
{
	this.m_heAtom = heAtom;
}
		
CheckAtom.prototype.handleResult = function (xnAtom)
{
	var strValue = XmlLib.getTextValue(xnAtom);
	var nState = parseInt(XmlLib.getAttribute(xnAtom, "CheckState"));
	
	// 설정값이 있을 경우 결과 처리
	if (strValue)
	{
		this.setValue(strValue);
	}
	// 설정값이 없을 경우, state상태로 선택상태 변경
	else
	{
		this.m_nState = nState;
	
		if (CheckAtom.Unchecked == this.m_nState)
		{
			this.m_strValue = this.m_strUnCheckedValue;
		}
		else if (CheckAtom.Checked == this.m_nState)
		{
			this.m_strValue = this.m_strCheckedValue;
		}
		else if (true == this.m_bThreeState && CheckAtom.Indeterminate == this.m_nState)
		{
			this.m_strValue = this.m_strPartialCheckedValue;
		}
		else
		{
			this.m_strValue = this.m_strUnCheckedValue;
		}
		
		this.displayValue();
	}
}
 	
CheckAtom.prototype.getUnCheckedValue = function ()
{
	return this.m_strUnCheckedValue;
}

CheckAtom.prototype.getCheckedValue = function ()
{
	return this.m_strCheckedValue;
}

CheckAtom.prototype.getPartialCheckedValue = function ()
{
	return this.m_strPartialCheckedValue;
}

CheckAtom.prototype.getSaveType = function ()
{
	return this.m_strSaveType;
}
	
CheckAtom.prototype.setSaveType = function (strSaveType)
{
	this.m_strSaveType = strSaveType;
}

CheckAtom.prototype.isSureInputScroll = function ()
{
	return this.m_bSureInputScroll;
}

CheckAtom.prototype.setRowIndex = function (nRowIndex)
{
	this.m_nRowIndex = nRowIndex;
}

CheckAtom.prototype.getRowIndex = function ()
{
	return this.m_nRowIndex;
}

/**
 * 체크 박스는 유효체크 및 필수 입력 속성을 사용하지 않는다. 
 * 항상 True를 반환한다. 
 * 배준배 
 */
CheckAtom.prototype.isSureInput = function ()
{
	return true;
}

CheckAtom.prototype.checkSureInput = function ()
{
	return true;
}

/**
 * 스크롤에 묶인 경우 유효행 체크를 합니다
 */
CheckAtom.prototype.checkSureInputScroll = function ()
{
	return true;
}

CheckAtom.prototype.getTableName = function ()
{
	return this.m_strTableName;
}

CheckAtom.prototype.getFieldName = function ()
{
	return this.m_strFieldName;
}

CheckAtom.prototype.getFieldType = function ()
{
	return this.m_strFieldType;
}

CheckAtom.prototype.setIsOperation = function (bOperation)
{
	this.m_bOperation = bOperation;
}

CheckAtom.prototype.isOperation = function ()
{
	return this.m_bOperation;
}

CheckAtom.prototype.isRelatedOperation = function ()
{
	return this.m_bRelatedOperation;
}

CheckAtom.prototype.isVisible = function ()
{
	var strVisibility = this.m_heAtom.style.visibility;
	if ("hidden" == strVisibility)
	{
		return false;
	}
	else if ("visible" == strVisibility)
	{
		return true;
	}
	else
	{
		// 탭뷰 안에 있는 경우
		var heTabView = this.m_heAtom.parentElement;
		if (this.m_bScroll)
		{
			heTabView = this.m_heAtom.parentElement.parentElement.parentElement;
		}
		
		if (null != heTabView && heTabView.tagName == "DIV")
		{
			if ("none" == heTabView.style.display)
			{
				return false;
			}
		}
	}
	return true;
}

CheckAtom.prototype.isFocusable = function ()
{
	if (this._isDisable() || false == this.isVisible())
	{
		return false;
	}
	
	//return true;
	return false;	// 일단 동작안하게 막음
}

CheckAtom.prototype.setFocus = function ()
{
	if (null != this.m_heAtom)
	{
		//return true;
	}
	return false;
}

////////////////////////////////////////////////////////////
// public method

CheckAtom.prototype.init = function ()
{
	this._initData();
}

/**
* 요청정보를 만든다.
* @param xnRequest
* @param isScroll 스크롤 아톰의 묶여있다면 true. 그 외에는 undefined
*/
CheckAtom.prototype.makeRequest = function (xnRequest, isScroll)
{
	var strVarName = this.getVarName();
	var strValue = this.getValue();

	var xnAtom = XmlLib.createChild(xnRequest, "CheckAtom");
	
	xnAtom.setAttribute("SaveType", this.m_strSaveType);//저장속성추가
	xnAtom.setAttribute("VarName", strVarName);
	xnAtom.setAttribute("CheckState", this.m_nState);
	
	// 체크 아톰은 설정값을 기본값으로 요청에 포함시킨다.
	xnAtom.setAttribute("DefaultString", this.m_strDispType);
	xnAtom.setAttribute("TabId", this.m_strTabId);
	XmlLib.setTextValue(xnAtom, strValue);
	
	xnAtom.setAttribute("TableName", this.getTableName()); 
	xnAtom.setAttribute("FieldName", this.getFieldName());
}

CheckAtom.prototype.clone = function(bIsHtml)
{
	var objNewAtom = new CheckAtom (this.m_strVarName, this.m_nScriptIndex, this.m_strDispType, 
		this.m_bScroll, this.m_strScrollName, this.m_bSureInputScroll, this.m_strTableName, 
		this.m_strFieldName, this.m_strFieldType, this.m_bVanish, this.m_bRelatedOperation, this.m_strHyperLinkName, this.m_strTabId);
		
	if (false != bIsHtml && null != this.m_heAtom)
	{
		objNewAtom.setHTML(this.m_heAtom.cloneNode(true));
	}
	else
	{
		objNewAtom.setHTML(null);
	}
	
 	return objNewAtom;
}

CheckAtom.prototype.displayValue = function ()
{
	if (null == this.m_heAtom)
		return;
	
	var heCheckbox = this._getImageBoxElement();
	
	switch (this.m_nState)
	{
		case CheckAtom.Unchecked:
			this._setUncheckedStyle();
			break;
		case CheckAtom.Checked:
			heCheckbox.style.backgroundPositionX = "-15px"; 
			break;
		case CheckAtom.Indeterminate:
			heCheckbox.style.backgroundPositionX = "-30px"; 
			break;
	}
}

/**
 * 선택표시 (f9 기능)
 */
CheckAtom.prototype.vanish = function ()
{
	if (this.m_bVanish)
	{
		// 현재 감춤 상태이면 표시한다.
		if ("hidden" == this.m_heAtom.style.visibility)
		{
			this.m_heAtom.style.visibility = "visible";
		}
		else	// 표시된 상태이면 감춘다.
		{
			this.m_heAtom.style.visibility = "hidden";
		} 
	}
}

/**
 * 체크 -> 연결검색 -> onChange 이벤트 -> _누름 스크립트 -> 스크롤_누름 이벤트
 */
CheckAtom.prototype.onClick = function (heAtom, objEvent)
{
	if (true == this._isDisable())
	{
		return;
	}
	
	// 모두선택'과 '선택안함' 값이 없으면 토글동작
	if ("" == this.m_strCheckedValue && "" == this.m_strUnCheckedValue)
	{
		this.setValue("toggle");	
	}
	else
	{
		switch (this.m_nState)
		{
			case CheckAtom.Unchecked:
				strValue = this.m_strCheckedValue;
				break;
			case CheckAtom.Checked:
				if (false == this.m_bThreeState)
				{
					strValue = this.m_strUnCheckedValue;
				}
				else
				{
					strValue = this.m_strPartialCheckedValue;
				}
				break;
			case CheckAtom.Indeterminate:
				strValue = this.m_strUnCheckedValue;
				break;			
		}
		
		this.setValue(strValue);
	}
	
	// 연결검색
	PQConnectionSearch.execute(this.m_strVarName);
			
	this._occurOnChangeEvent();
	
	if (-1 == ScriptAtomEvent.onClick(this.m_nScriptIndex))
	{
		objEvent.returnValue = false;
		return;
	}
	else
	{
		ScriptAtomEvent.onClickAfter(this.m_nScriptIndex);
	}

	if (this.m_bScroll)
	{
		ScrollOnClick(this.m_strScrollName, this.m_strVarName, this.m_heAtom, objEvent);
	}
	
	// 하이퍼링크 동작, 가장 마지막에 수행해야 합니다. 다른 동작 추가시 위로 추가하세요
	if (null != this.m_strHyperLinkName && 0 != this.m_strHyperLinkName.length && ContainsWebHyperDataAtom())
	{
		var objHyperLinkAtom = Model.getAtom(this.m_strHyperLinkName, this.m_strScrollName, this.m_heAtom);
		if (null != objHyperLinkAtom)
		{
			// 먼저 하이퍼 링크의 링크 동작을 제외한 onClick을 수행한다. (스크립트동작)
			if (-1 != objHyperLinkAtom.onLinkClick())
			{
				objHyperLinkAtom.connectLink(this.m_heAtom);
			}
		}
	}
}

CheckAtom.prototype.onChange = function ()
{
	if (this.m_bScroll)
		{
			var objScrollAtom = null;
			if (ContainsScrollAtom())
			{
				objScrollAtom = ScrollAtom.getAtom(this.m_strScrollName);
				objScrollAtom.modifyRowExcludeOperation(this.m_nRowIndex);
			}
		}
}

/**
 * 인자로 받은 값만큼 높이를 변화시킨다
 * 
 * @param nResizeValue (높이 변경 값)
 */
CheckAtom.prototype.resizeHeight = function (nResizeValue)
{
	var nHeight = this.m_heAtom.offsetHeight;
	
	this.m_heAtom.style.height = (nHeight + nResizeValue) + "px";
}

/**
 * 인자로 받은 값만큼 넓이를 변화시킨다
 * 
 * @param nResizeValue (높이 변경 값)
 */
CheckAtom.prototype.resizeWidth = function (nResizeValue)
{
	var nWidth = this.m_heAtom.offsetWidth;
	
	this.m_heAtom.style.width = (nWidth + nResizeValue) + "px";
}

/**
 * 인자로 받은 값만큼 top을 변경시킨다
 * 
 * @param nRepositionValue (top 변경 값)
 */
CheckAtom.prototype.repositionYPos = function (nRepositionValue)
{
	var nTop = Number(this.m_heAtom.style.top.replace("px", ""));
	
	this.m_heAtom.style.top = (nTop + nRepositionValue) + "px";
}

/**
 * 인자로 받은 값만큼 left를 변경시킨다
 * 
 * @param nRepositionValue (left 변경 값)
 */
CheckAtom.prototype.repositionXPos = function (nRepositionValue)
{
	var nLeft = Number(this.m_heAtom.style.left.replace("px", ""));
	
	this.m_heAtom.style.left = (nLeft + nRepositionValue) + "px";
}


////////////////////////////////////////////////////////////
// private method

/**
 * 체크박스의 이름을 표현하는 table html이 disabled 되었는지에 기준하여
 * 아톰의 disabled 상태를 반환한다
 */
CheckAtom.prototype._isDisable = function ()
{
	return this.m_heAtom.getElementsByTagName("table")[0].disabled;
}

CheckAtom.prototype._occurOnChangeEvent = function ()
{
	if (this.m_strOldValue != this.m_strValue)
		{
		// 다음에 현재 값과 새로 입력된 값을 비교하기 위해 현재 값을 OldValue에 저장합니다.
			this.m_strOldValue = this.m_strValue;
			
			this.onChange();
		}
}

CheckAtom.prototype._initData = function ()
{
	//display 타입을 설정함 (체크되었을때 /안되었을때 /3가지 상태)
	var arDispTypeList = this.m_strDispType.split("$");
	if (null == arDispTypeList)
		return;
	
	if (2 <= arDispTypeList.length)
	{
		this.m_strUnCheckedValue = arDispTypeList[0];
		this.m_strCheckedValue = arDispTypeList[1];
		if (3 == arDispTypeList.length)
		{
			this.m_strPartialCheckedValue = arDispTypeList[2];
			this.m_bThreeState = true;
		}
	}
	
	// 새 번호를 채번하면 체크아톰을 선택안된 상태로 설정해 놓는다.
	this.m_strValue = this.m_strUnCheckedValue;
	
	// 현재 상태가 UnChecked이면 변경하지 않는다.
	if (CheckAtom.Unchecked != this.m_nState)
	{
		this._setUncheckedStyle();
	}
}

/**
 * 체크박스의 스타일을 체크되지 않은 상태로 한다
 */
CheckAtom.prototype._setUncheckedStyle = function ()
{
	this._getImageBoxElement().style.backgroundPositionX = "0px"; 
}

/**
 * 체크박스 아톰 요소중 이미지 요소를 반환합니다
 */
CheckAtom.prototype._getImageBoxElement = function ()
{
	return  this.m_heAtom.firstChild;
}

CheckAtom.prototype.getProperty = function (nNameID, arArgs, objRetVal)
{
	switch (nNameID)
	{
		case 21 :case 286 : return this.get_GdiProperty (286, arArgs, objRetVal);
		case 23 :case 253 : return this.get_GdiProperty (253, arArgs, objRetVal);
		case 33 :case 369 : return this.get_CheckProperty (369, arArgs, objRetVal);
		case 40 :case 375 : return this.get_CheckProperty (375, arArgs, objRetVal);
		default : return StdCore.E_NOT_DEF_PROPERTY;
	}
}

CheckAtom.prototype.setProperty = function(nNameID, arArgs, objRetVal)
{		
	switch (nNameID)
	{
		case 21 :case 286 : return this.set_GdiProperty (286, arArgs, objRetVal);
		case 23 :case 253 : return this.set_GdiProperty (253, arArgs, objRetVal);
		case 33 :case 369 : return this.set_CheckProperty (369, arArgs, objRetVal);
		case 40 :case 375 : return this.set_CheckProperty (375, arArgs, objRetVal);
		default : return StdCore.E_NOT_DEF_PROPERTY;	
	}
}

CheckAtom.prototype.get_CheckProperty = function (nNameID, arArgs, objRetVal)
{
	switch (nNameID)
	{
		case 375 : // 선택값
			objRetVal.setValueType(CVariantX._vtString, this.getValue());
			break; 
		case 369 : // 체크
		{
			switch (this.m_nState)
			{
				case CheckAtom.Unchecked : // #선택안함(1191)
					objRetVal.setValueType(CVariantX._vtInt, 1191);
					break;
				case CheckAtom.Checked : // #모두선택(1192)
					objRetVal.setValueType(CVariantX._vtInt, 1192);
					break;
				case CheckAtom.Indeterminate : // #부분선택(1193)
					objRetVal.setValueType(CVariantX._vtInt, 1193);
					break;
				default :
					break;
			}
			break;
		}
		default  : 
			return StdCore.E_NOT_DEF_PROPERTY;
	}
	
	return StdCore.S_OK;
}

CheckAtom.prototype.set_CheckProperty = function (nNameID, arArgs, objValue)
{
	switch (nNameID)
	{
		case 375 : // 선택값
			this.setValue(objValue.toStringX());
			break; 
		case 369 : // 체크
		{
			var strValue = "";
			
			switch (objValue.toInt())
			{
				case 1191 : // #선택안함(1191)
					strValue = this.m_strUnCheckedValue;
					break;
				case 1192 : // #모두선택(1192)
					strValue = this.m_strCheckedValue;
					break;
				case 1193 : // #부분선택(1193)
					strValue = this.m_strPartialCheckedValue;
					break;
				default :
					break;
			}
			
			this.setValue(strValue);
			break;
		}
		default  : 
			return StdCore.E_NOT_DEF_PROPERTY;
	}

	return StdCore.S_OK;
}

CheckAtom.prototype.action = function (nPropID, arArgs, objRetVal)
{
	switch (nPropID)
	{
		default : return this.getProperty (nPropID, arArgs, objRetVal);
	}
}


////////////////////////////////////////////////////////////
// static field

/*
* 체크 안 된 상태
*/
CheckAtom.Unchecked = 0;
/*
* 체크된 상태
*/
CheckAtom.Checked = 1;
/*
* 비결정 상태
*/
CheckAtom.Indeterminate = 2;

/**
 * 아톰리스트
 */
CheckAtom._atoms = new Object();

CheckAtom.init = function ()
{
	for (var strVarName in CheckAtom._atoms)
	{
		if ("" == strVarName)
			continue;
			
		var objAtom = CheckAtom._atoms[strVarName];
		
		objAtom.init();
	}
}

CheckAtom.getAtom = function (strVarName, strScrollName, heAtom)
{
	if (null != strScrollName && 0 < strScrollName.length)
	{
		var objScrollAtom = null;
		if (ContainsScrollAtom())
		{
			objScrollAtom = ScrollAtom.getAtom(strScrollName);
		}
		if (null != objScrollAtom)
		{
			var nRowIndex = objScrollAtom.getRowIndex(heAtom);
			if (0 <= nRowIndex)
				return objScrollAtom.getBindedAtom(strVarName, nRowIndex);
		}
	}
	else
	{
		return CheckAtom._atoms[strVarName];
	}
	
	return null;
}

CheckAtom.makeRequest = function (xnAtomRequest)
{
	for (var strVarName in CheckAtom._atoms)
	{
		var objAtom = CheckAtom._atoms[strVarName];
		
		objAtom.makeRequest(xnAtomRequest);
	}
}

////////////////////////////////////////////////////////////
// event handler

CheckAtom.onClick = function (strScrollName, heAtom, objEvent)
{
	objEvent = HTMLLib.getEvent(objEvent);
	
	var objAtom = CheckAtom.getAtom(heAtom.id, strScrollName, heAtom);
	if (objAtom)
	{
		objAtom.onClick(heAtom, objEvent);
	}
}


/**
 * 라디오  Javascript 클래스 목록
 * 	- RadioAtom
 *	- RadioAtomGroup
 */


function RadioAtom (strVarName, strGroupName, strDisplay, IsGroupKey, nScriptIndex, bVanish, strHyperLinkName, strTabId, strTableName, strFieldName, strFieldType, bScroll, strScrollName, bSureInputScroll)
{
	this.Atom (strVarName, "", strScrollName, -1, nScriptIndex);
	
	this.m_strDisplay = strDisplay;
	this.m_IsGroupKey = IsGroupKey;
	this.m_strGroupName = strGroupName;
	this.m_strHyperLinkName = strHyperLinkName;
	this.m_strTabId = strTabId;
	this.m_strTableName = strTableName;
	this.m_strFieldName = strFieldName;
	this.m_strFieldType = strFieldType;
	
	this.m_heAtom = document.getElementById(this.m_strVarName);
	this.m_heAtomDiv = document.getElementById("__RADIO_" + this.m_strVarName);
	
	this.m_strSaveType = ""; //라디오 아톰 저장속성
	this.m_bVanish = bVanish;
	
	if (null != strHyperLinkName && 0 < strHyperLinkName.length)
	{
		this.m_heAtom.style.cursor = "hand";
	}
	
	this.m_nRowIndex = -1;
	this.m_bScroll = bScroll;
	this.m_bSureInputScroll = bSureInputScroll;
}

RadioAtom.prototype = new Atom ();
RadioAtom.prototype.constructor = RadioAtom;

RadioAtom.prototype.init = function ()
{
	
}

RadioAtom.prototype.clone = function (bIsHtml)
{
	var objNewAtom = new RadioAtom (this.m_strVarName, this.m_strGroupName, this.m_strDisplay, this.m_IsGroupKey,
	 								this.m_nScriptIndex, this.m_bVanish, this.m_strHyperLinkName, this.m_strTabId,
	 								this.m_strTableName, this.m_strFieldName, this.m_strFieldType, this.m_bScroll, this.m_strScrollName,
	 								this.m_bSureInputScroll);
		
	if (false != bIsHtml && null != this.m_heAtom)
	{
		objNewAtom.setHTML(this.m_heAtomDiv.cloneNode(true));
	}
	else
	{
		objNewAtom.setHTML(null);
	}
	
 	return objNewAtom;
}

RadioAtom.prototype.getAtomType = function ()
{
	return "Radio";
}

RadioAtom.prototype.getValue = function ()
{
	return this.m_strDisplay;
}

RadioAtom.prototype.getSelectValue = function ()
{
	var objGroup = RadioAtomGroup.getGroup(this.m_strGroupName);
	var objCheckedRadio = objGroup.getCheckedAtom();
	
	return objCheckedRadio.getValue();
}

RadioAtom.prototype.getHTML = function ()
{
	return this.m_heAtomDiv;
}

RadioAtom.prototype.setHTML = function (heAtom)
{
	this.m_heAtomDiv = heAtom;
	
	// 스크롤에서 보이지 않는 아톰은 HTML Element를 null로 설정해야 한다.
	if (null == heAtom)
	{
		this.m_heAtom = null;
	}
	else
	{
		this._resetMemberElement();
	}
}

RadioAtom.prototype._resetMemberElement = function ()
{
	if (null == this.m_strScrollName || "" == this.m_strScrollName) 
	{
		return;
	}

	var heFirstLayerChilds = this.m_heAtomDiv.childNodes;
	this._repointingElement(heFirstLayerChilds);
	
//	var objScrollAtom = null;
//	if (ContainsScrollAtom())
//	{
//		objScrollAtom = ScrollAtom.getAtom(this.m_strScrollName);
//	}
//	if (null != objScrollAtom)
//	{
//		var nRowIndex = objScrollAtom.getRowIndex(heAtom);
//		
//		this.m_heAtom.setAttribute("name", this.m_strGroupName + "_" + nRowIndex);
//	}
}

/**
 * 엘리먼트의 포인터를 다시 연결해 줍니다. 
 * 스크롤에 묶여 있을 경우, clone메서드를 실행하여 아톰(this.m_heAtom)이 복사되면
 * 아톰의 멤버 HTML들의 포인터가 기존의 아톰을 계속 가리키고 있는 문제 가 생깁니다.
 * 멤버HTML들이 새로운 아톰의 HTML멤버를 가리키게 하기위해
 * 아톰의 Element들을 가져와 하나씩 포인터를 이어 줍니다
 * @param heElement(현재 아톰의 엘리먼트)
 */
RadioAtom.prototype._repointingElement = function (heElement)
{	
	for (var i=0; i < heElement.length; i++)
	{
		this.m_heAtom = heElement[i]; 
	}
}

RadioAtom.prototype.getGroupName = function ()
{
	return this.m_strGroupName;
}

RadioAtom.prototype.getGroupKey = function ()
{
	return this.m_IsGroupKey;
}

/**
 *  날짜입력란 저장속성 getter,setter
 */
RadioAtom.prototype.getSaveType = function ()
{
	return this.m_strSaveType;
}

RadioAtom.prototype.setSaveType = function (strSaveType)
{
	this.m_strSaveType = strSaveType;
}

RadioAtom.prototype.setDisplayString = function (strDisplay)
{
	this.m_strDisplay = strDisplay;
}

RadioAtom.prototype.getTabId = function ()
{
	return this.m_strTabId;
}

RadioAtom.prototype.getTableName = function ()
{
	return this.m_strTableName;
}

RadioAtom.prototype.getFieldName = function ()
{
	return this.m_strFieldName;
}

RadioAtom.prototype.getFieldType = function ()
{
	return this.m_strFieldType;
}

RadioAtom.prototype.getRowIndex = function ()
{
	return this.m_nRowIndex;
}
 	
RadioAtom.prototype.setRowIndex = function (nIndex)
{
	this.m_nRowIndex = nIndex;
}

RadioAtom.prototype.isSureInput = function ()
{
	return this.m_bSureInput;
}
 	
RadioAtom.prototype.isSureInputScroll = function ()
{
	return this.m_bSureInputScroll;
}

/**
* 화면에 아톰의 값을 포맷대로 출력한다.
*/
RadioAtom.prototype.displayValue = function ()
{
}

/**
 * 선택표시 (f9 기능)
 */
RadioAtom.prototype.vanish = function ()
{
	if (this.m_bVanish)
	{
		// 현재 감춤 상태이면 표시한다.
		if ("hidden" == this.m_heAtomDiv.style.visibility)
		{
			this.m_heAtomDiv.style.visibility = "visible";
		}
		else	// 표시된 상태이면 감춘다.
		{
			this.m_heAtomDiv.style.visibility = "hidden";
		}
	}
}

RadioAtom.prototype.isChecked = function ()
{
	return this.m_heAtom.checked;
}

/**
 *	라디오 아톰의 필수입력 속성 반환
 */
RadioAtom.prototype.isSureInput = function ()
{
	return true;
}

RadioAtom.prototype.putAtom = function ()
{
	RadioAtom._atoms[this.getVarName()] = this;
}

/**
 *	아톰의 체크상태 설정
 */
RadioAtom.prototype.setCheck = function (bCheck)
{
	var objGroup = RadioAtomGroup.getGroup(this.m_strGroupName);
	
	if (bCheck)
	{
		if (objGroup)
		{
			objGroup.setChecked(this.m_strVarName);
		}
		this.m_heAtom.checked = true;
	}
	else
	{
		this.m_heAtom.checked = false;
		if (objGroup)
		{
			objGroup.uncheck(this.m_strVarName);
		}
	}
}

/**
 *	TODO : setValue할 것이 있을 때마다 추가해야 함.
 */
RadioAtom.prototype.setValue = function (strValue)
{
	if (this.m_strDisplay == strValue)
	{
		this.setCheck(true);
	}
	else
	{
		this.setCheck(false);
	}
}

RadioAtom.prototype.setSelectValue = function (strValue)
{
	var objGroup = RadioAtomGroup.getGroup(this.m_strGroupName);
	objGroup.setCheckValue(strValue);
}

/**
 *	라디오 버튼 클릭
 */
RadioAtom.prototype.onClick = function (objEvent)
{
	this.setCheck(true); // 눌려진 라디오를 체크상태로..
	
	// 연결검색
	PQConnectionSearch.execute(this.m_strVarName);
	
	// _누름
	if (-1 != ScriptAtomEvent.onClick(this.m_nScriptIndex))
	{
		ScriptAtomEvent.onClickAfter(this.m_nScriptIndex);
		
		// 하이퍼링크 동작, 가장 마지막에 수행해야 합니다. 다른 동작 추가시 위로 추가하세요
		if (null != this.m_strHyperLinkName && 0 != this.m_strHyperLinkName.length && ContainsWebHyperDataAtom())
		{
			var objHyperLinkAtom = Model.getAtom(this.m_strHyperLinkName);
			if (null != objHyperLinkAtom)
			{
				// 먼저 하이퍼 링크의 링크 동작을 제외한 onClick을 수행한다. (스크립트동작)
				if (-1 != objHyperLinkAtom.onLinkClick())
				{
					objHyperLinkAtom.connectLink(this.m_heAtom);
				}
			}
		}
	}
}

/**
 * 인자로 받은 값만큼 높이를 변화시킨다
 * 
 * @param nResizeValue (높이 변경 값)
 */
RadioAtom.prototype.resizeHeight = function (nResizeValue)
{
	var nHeight = this.m_heAtomDiv.offsetHeight;
	
	this.m_heAtomDiv.style.height = (nHeight + nResizeValue) + "px";
}

/**
 * 인자로 받은 값만큼 넓이를 변화시킨다
 * 
 * @param nResizeValue (높이 변경 값)
 */
RadioAtom.prototype.resizeWidth = function (nResizeValue)
{
	var nWidth = this.m_heAtomDiv.offsetWidth;
	
	this.m_heAtomDiv.style.width = (nWidth + nResizeValue) + "px";
}

/**
 * 인자로 받은 값만큼 top을 변경시킨다
 * 
 * @param nRepositionValue (top 변경 값)
 */
RadioAtom.prototype.repositionYPos = function (nRepositionValue)
{
	var nTop = Number(this.m_heAtomDiv.style.top.replace("px", ""));
	
	this.m_heAtomDiv.style.top = (nTop + nRepositionValue) + "px";
}

/**
 * 인자로 받은 값만큼 left를 변경시킨다
 * 
 * @param nRepositionValue (left 변경 값)
 */
RadioAtom.prototype.repositionXPos = function (nRepositionValue)
{
	var nLeft = Number(this.m_heAtomDiv.style.left.replace("px", ""));
	
	this.m_heAtomDiv.style.left = (nLeft + nRepositionValue) + "px";
}

RadioAtom.prototype.getProperty = function (nNameID, arArgs, objRetVal)
{
	switch (nNameID)
	{
		case 21 :case 286 : return this.get_GdiProperty (286, arArgs, objRetVal);
		case 23 :case 253 : return this.get_GdiProperty (253, arArgs, objRetVal);
		case 14 :case 436 : return this.get_RadioProperty (436, arArgs, objRetVal);
		case 33 :case 369 : return this.get_RadioProperty (369, arArgs, objRetVal);
		case 39 :case 375 : return this.get_RadioProperty (375, arArgs, objRetVal);
		default : return StdCore.E_NOT_DEF_PROPERTY;
	}
}

RadioAtom.prototype.setProperty = function(nNameID, arArgs, objRetVal)
{		
	switch (nNameID)
	{
		case 21 :case 286 : return this.set_GdiProperty (286, arArgs, objRetVal);
		case 23 :case 253 : return this.set_GdiProperty (253, arArgs, objRetVal);
		case 14 :case 436 : return this.set_RadioProperty (436, arArgs, objRetVal);
		case 33 :case 369 : return this.set_RadioProperty (369, arArgs, objRetVal);
		case 39 :case 375 : return this.set_RadioProperty (375, arArgs, objRetVal);
		default : return StdCore.E_NOT_DEF_PROPERTY;	
	}
}

RadioAtom.prototype.get_RadioProperty = function (nNameID, arArgs, objRetVal)
{
	switch (nNameID)
	{
		case 375 : // 선택값
			var objGroup = RadioAtomGroup.getGroup(this.m_strGroupName);
			var objCheckedRadio = objGroup.getCheckedAtom();
			
			objRetVal.setValueType(CVariantX._vtString, objCheckedRadio.getValue());
			break;
		case 436 :// 설정값
			objRetVal.setValueType(CVariantX._vtString, this.getValue());
			break; 
		case 369 : // 체크
			var nValue = this.isChecked() ? 1 : 0;
			objRetVal.setValueType(CVariantX._vtInt, nValue);
			break; 
		default  : 
			return StdCore.E_NOT_DEF_PROPERTY;
	}
	return StdCore.S_OK;
}

RadioAtom.prototype.set_RadioProperty = function (nNameID, arArgs, objRetVal)
{
	switch (nNameID)
	{					
		case 375 : // 선택값
			var objGroup = RadioAtomGroup.getGroup(this.m_strGroupName);
			objGroup.setCheckValue(objValue.toStringX());
			break;
		case 436 : // 설정값
			this.setDisplayString(objValue.toStringX());
			break; 
		case 369 : // 체크
			var bChecked = objValue.toBoolean();
			
			if (bChecked)
			{
				var objGroup = RadioAtomGroup.getGroup(this.m_strGroupName);
				objGroup.setCheckValue(this.getValue());
			}
			break; 
		default  : 
			return StdCore.E_NOT_DEF_PROPERTY;
	}

	return StdCore.S_OK;
}

RadioAtom.prototype.action = function (nPropID, arArgs, objRetVal)
{
	switch (nPropID)
	{
		default : return this.getProperty (nPropID, arArgs, objRetVal);
	}
}


/**
 * 아톰 리스트
 */
RadioAtom._atoms = new Object();

RadioAtom.getAtom = function (strVarName, strScrollName, heAtom)
{
	if (null != strScrollName && 0 < strScrollName.length)
	{
		var objScrollAtom = null;
		if (ContainsScrollAtom())
		{
			objScrollAtom = ScrollAtom.getAtom(strScrollName);
		}
		if (null != objScrollAtom)
		{
			var nRowIndex = objScrollAtom.getRowIndex(heAtom);
			if (0 <= nRowIndex)
				return objScrollAtom.getBindedAtom(strVarName, nRowIndex);
		}
	}
	else
	{
		return RadioAtom._atoms[strVarName];
	}
	
	return null;
}

RadioAtom.onClick = function (strVarName, strScrollName, heAtom, objEvent)
{
	objEvent = HTMLLib.getEvent(objEvent);
	var objRadioAtom = RadioAtom.getAtom(strVarName, strScrollName, heAtom);

	objRadioAtom.onClick(objEvent);
}

/**
 * RadioAtom을 관리하는 그룹
 */
function RadioAtomGroup (strGroupName)
{
	this.m_htRadioAtomList = new Object();
	this.m_strGroupName = strGroupName;
	this.m_strCheckName = "";
	
	// 그룹키로 설정된 아톰의 VarName
	this.m_strGroupAtomName = "";
}

RadioAtomGroup.prototype.getAtomList = function ()
{
	return this.m_htRadioAtomList;
}

/**
 * 체크된 아톰을 반환한다.
 */
RadioAtomGroup.prototype.getCheckedAtom = function ()
{
	return this.m_htRadioAtomList[this.m_strCheckName];
}

RadioAtomGroup.prototype.getGroupName = function ()
{
	return this.m_strGroupName;
}

/**
 *	라디오 그룹을 초기화 한다.
 *	체크된 라디오가 없으면, '그룹'으로 설정된 라디오아톰을 '체크'상태로 만든다.
 */
RadioAtomGroup.prototype.init = function ()
{
	for (var strVarName in this.m_htRadioAtomList)
	{
		var objAtom = this.m_htRadioAtomList[strVarName];

		if (objAtom.isChecked())
		{
			this.m_strCheckName = strVarName;
			return;
		}
	}
	
	var objAtom = this.m_htRadioAtomList[this.m_strGroupAtomName];
	
	objAtom.setCheck(true);
}

RadioAtomGroup.prototype.makeRequest = function (xnRequest)
{
	var objRadio = this.getCheckedAtom();
	
	if (!objRadio)
	{
		return;
	}
	
	var strCheckValue = objRadio.getValue();
	
	for (var strAtomName in this.m_htRadioAtomList)
	{
		var objAtom = this.m_htRadioAtomList[strAtomName];
		var xnAtom = XmlLib.createChild(xnRequest, "Radio");
		
		xnAtom.setAttribute("VarName", strAtomName);
		
		// 라디오 아톰은 기본값에, 아톰의 설정값을 전달한다.
		xnAtom.setAttribute("DefaultString", objAtom.getValue());
		xnAtom.setAttribute("TabId", objAtom.getTabId());
		
		// 아톰의 현재값은 그룹에서 선택된 아톰의 설정값을 전달한다.
		XmlLib.setTextValue(xnAtom, strCheckValue);
		
		xnAtom.setAttribute("TableName", objAtom.getTableName());
		xnAtom.setAttribute("FieldName", objAtom.getFieldName());
	}
}

RadioAtomGroup.prototype.add = function (strVarName, objRadioAtom)
{
	this.m_htRadioAtomList[strVarName] = objRadioAtom;
}

RadioAtomGroup.prototype.getAtom = function (strVarName)
{
	var objAtom = this.m_htRadioAtomList[strVarName];
	
	if (null == objAtom)
		return null;
		
	return objAtom;
}

RadioAtomGroup.prototype.setCheckValue = function (strCheckValue)
{
	for (var strRadioVarName in this.m_htRadioAtomList)
	{
		var objRadio = this.m_htRadioAtomList[strRadioVarName];
		
		objRadio.setValue(strCheckValue);
	}
}

/**
 * 그룹내에서 아톰명에 해당되는 아톰만 체크상태로 설정
 * 애플릿에도 속성값 전송 (상태유지를 위해)
 * @strVarName - 아톰명, 아톰명이 공백("")이면 모두 '체크안함' 상태로 설정
 */
RadioAtomGroup.prototype.setChecked = function (strVarName)
{
	// 일치되는 값이 없으면 Default로 GroupAtomName대입
	this.m_strCheckName = this.m_strGroupAtomName;
	
	for (var strRadioVarName in this.m_htRadioAtomList)
	{
		var objRadio = this.m_htRadioAtomList[strRadioVarName];
		var strChecked = "N";
		
		if (strRadioVarName == strVarName)
		{
			this.m_strCheckName = strRadioVarName;
			strChecked = "Y";
		}
		
		// 필요 없다고 예상되므로, 이상없으면 주석 삭제해도됨
		//"라디오아톰.체크" 동작을 위해서 라디오아톰의 체크 여부가 변경될 때마다 , 그 상태를 스크립트 속성에서 갱신한다.
		//PQScript.setScriptAttribute(strRadioVarName, "Checked", strChecked);			
	}
}

/**
 * 그룹내에서 해당 라디오를 체크 해제하고
 * '그룹설정'된 라디오를 체크 설정 해준다.
 */
RadioAtomGroup.prototype.uncheck = function (strVarName)
{
	if (strVarName == this.m_strCheckName)
	{
		this.m_htRadioAtomList[this.m_strGroupAtomName].setCheck(true);
	}
}

/**
 *	라디오 그룹에서 '그룹'으로 설정된 라디오아톰의 아톰명을 정한다.
 */
RadioAtomGroup.prototype.setGroupAtomName = function ()
{
	for (var strVarName in this.m_htRadioAtomList)
	{
		var objAtom = this.m_htRadioAtomList[strVarName];
		
		if ("Y" == objAtom.getGroupKey())
		{
			this.m_strGroupAtomName = objAtom.getVarName();
			
			return;
		}
	}
}

/**
 * 라디오그룹 리스트
 */
RadioAtomGroup._groups = new Object();

RadioAtomGroup.addGroup = function (strKey, objGroup)
{
	RadioAtomGroup._groups[strKey] = objGroup;
}

RadioAtomGroup.getGroup = function (strGroupName)
{
	if (0 == RadioAtomGroup._groups.length)
		return null;
		
	return RadioAtomGroup._groups[strGroupName];
}

RadioAtomGroup.init = function ()
{
	for (var strGroupName in RadioAtomGroup._groups)
	{
		if ("" == strGroupName)
			continue;
			
		var objRadioAtomGroup = RadioAtomGroup._groups[strGroupName];
		objRadioAtomGroup.setGroupAtomName();
		objRadioAtomGroup.init();
	}
}

RadioAtomGroup.makeRequest = function (xnAtomRequest)
{
	for (var strGroupName in RadioAtomGroup._groups)
	{
		var objRadioAtomGroup = RadioAtomGroup._groups[strGroupName];
		objRadioAtomGroup.makeRequest(xnAtomRequest);
	}
}

/*
 * 라디오 아톰의 필수입력처리
 */
RadioAtomGroup.checkSureInput = function ()
{
	for (var strGroupName in RadioAtomGroup._groups)
	{
		var objRadioAtomGroup = RadioAtomGroup._groups[strGroupName];
		var htAtomList = objRadioAtomGroup.getAtomList();

		for (var strVarName in htAtomList)
		{
			var objAtom = RadioAtomGroup._groups[strVarName];

			if (null != objAtom)
			{
				//return objAtom;
				objAtom.checkSureInput();
			}
		}
	}
}