/*****************************************************************
* ajax용 alert : ajax 결과 값을 받아서 alert 처리 alert가 있으면 true 리턴
*****************************************************************/
function rbs_ajaxAlert(theVar) {
	var varStr = theVar.substring(0, 16);
	if(varStr == 'rbs_ajaxAlertStr') {
		eval(theVar);
		if(rbs_ajaxAlertStr) {
			alert(rbs_ajaxAlertStr);
			rbs_ajaxAlertStr = '';
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}

/*****************************************************************
* Cancel 처리함수 : open window, lightBox, self 자동 인식
*****************************************************************/
function rbs_cancelAction(theFlag) {
	try	{
		if(theFlag == 'reload') opener.location.reload();
		if(opener.location) window.top.close();
	} catch (e) {
		try	{
			if(theFlag == 'reload')
			{ 
		 		try {
		 			parent.contentsIFrame.location.reload();
		 		} catch(e) {
					parent.location.reload();
		 		}
	 		}
			rbs_lightBoxClose('in');
		} catch (e) {
			history.back();
		}
	}
}

/*****************************************************************
* 상위 이동 처리 처리함수 : open window, lightBox, self 자동 인식
*****************************************************************/
function rbs_closeRedirect(theURL) {
	try	{
		if(opener.location) window.top.close();
		opener.location.href=theURL;
	} catch (e) {
		try	{
			rbs_lightBoxClose('in');
			parent.location.href=theURL;
		} catch (e) {
			location.href=theURL;
		}
	}
}

/*****************************************************************
* 라이트박스 닫기 : 라이트박스 안에서 닫을 경우 theFlag 를 'in'으로 함
*****************************************************************/
function rbs_lightBoxClose(theFlag) {
	if(theFlag == 'in') {
		parent.myLightbox.end();
	} else {
		myLightbox.end();
	}
}

/*****************************************************************
* 스타일 변경 : style이 안먹는 브라우저에서 사용하고자 하나,
파이어폭스에서도 style이 사용되므로 현재로서는 사용할 필요없음
*****************************************************************/
function rbs_chStyle(theId, theAttr, theValue, theStyle) {
	if($(theId)) {
		try {
			eval('$(theId).style.' + theAttr + ' = \'' + theValue + '\';');
		} catch(e) {
			$(theId).setAttribute('style', theStyle);
		}
	}
}

/*****************************************************************
* Active Widget Grid 사용 함수
*****************************************************************
theCName : 컬럼명 배열명 String
theDName : 값 배열명 String
theCSName : 컬럼별 스타일 배열명 String
theCDWidth : 공통 컬럼 폭 넓이
*****************************************************************/
function rbs_setAWGrid(theCName, theDName, theCSName, theCDWidth) {
	var varCName, varDName, varCLength, varListSize, varCSName, varCSValue, i, varSources;

	eval('varCName = ' + theCName + ';');
	eval('varDName = ' + theDName + ';');
	//alert(varDName);

	varCLength = varCName.length;
	varListSize = varDName.length;

	var obj = new Active.Controls.Grid;
	obj.setId("grid");
	obj.setRowProperty("count", varListSize);
	obj.setColumnProperty("count", varCLength);
	obj.setDataProperty("text", function(i, j){return varDName[i][j]});
	obj.setColumnProperty("text", function(i){return varCName[i]});
	obj.setRowHeaderWidth("28px");
	obj.setColumnHeaderHeight("20px");
	obj.setAction("click", function(src){window.status = src.getItemProperty("text")});

	eval('varCSName = ' + theCSName + ';');

	varSources = '<style style="text/css">\n';
	varSources += '.active-controls-grid {height: 100%; font: menu;}\n';

	theCDWidth = (theCDWidth)?theCDWidth:100;
	
	for(i = 0; i < varCLength; i++) {
		varCSValue = varCSName[i];
		if(varCSValue) {
			varSources += '.active-column-' + i + ' {text-align:center;' + varCSValue + '}\n';
		} else {
			varSources += '.active-column-' + i + ' {width:' + theCDWidth + ';text-align:center;}\n';
		}
	}

	varSources += '.active-grid-column {border-right: 1px solid threedlightshadow;}\n';
	varSources += '.active-grid-row {border-bottom: 1px solid threedlightshadow; height:20px;}\n';
	varSources += '..active-box-normal {height:20px;}\n';
	varSources += '</style>\n';

	varSources += '<div style="width:100%;height:100%;border:solid 1px #ccc;"><div style="width:100%;height:100%;">\n';
	varSources += obj;
	varSources += '</div></div>\n';
	
	document.write(varSources);
}

/*****************************************************************
* 스타일 변경 : style이 안먹는 브라우저에서 사용하고자 하나,
파이어폭스에서도 style이 사용되므로 현재로서는 사용할 필요없음
*****************************************************************/
function fn_resetSelectCssJs(theObj) {
	if(theObj) {
		try {
			theObj.reInitializeSelectBox();
		} catch(e) {
		}
	}
}
/******************************
 이벤트가 일어난 element의 index
*******************************/
function fn_getIndex(elName)
{
   	var  el = event.srcElement
	var idx = 0;
	
	// input일 경우
   	if  (el.tagName == "INPUT")
   	{
		while(el != el.form.elements[idx]) 
		{
			if(el.form.elements[idx].name == elName)
				objIdx ++;
				
			idx ++;
		}
		
		var i = 0;
		var objIdx = 0;
		for(i = 0 ; i < idx ; i ++)
			if(el.form.elements[i].name == elName)
				objIdx ++;
		
		return objIdx;
	}
	
	// 이미지일 경우
   	if  (el.tagName == "IMG")
   	{
		while(el != document.getElementsByName(elName)[idx]) 
		{
			idx ++;
		}
		
		return idx;
	}
}
/******************************
 아이프레임 리사이즈
*******************************/
function fn_docResize() {
//	alert(document.body.scrollHeight);
	if (self != top){
		self.resizeTo(document.body.scrollWidth , document.body.scrollHeight + 10);
	}
}