/*****************************************************************************************************
 * File Name 	: SCSubmitAction.js
 * @author ATTO Information Technology Corp. eWork R&D Team 
 * @since 2008. 1. 2
 * @version 1.0
 * ---------------------------------------------------------------------------------------
 * Modification Information
 * Date           Developer           Content
 * -------        -------------       -------------------------
 * 2008.01.02     Kimks		          최초작업     
 * 2008.01.10     YongHanLee	      클래스 형대로 개선
 * 2008.02.21     KimKS	              Result Name별로 URL 추가 (다양한 형태의 Result가 가능)
 * 2008.05.21     KimKS	              SCAjaxControl 추가
 * 2008.06.15     KimKS	              CALL_ID 추가 (CALL_CLASS, CALL_FUN, CALL_TYPE를 서버에서 매핑하는 ID)
 * 2008.08.08     KimKS	              Ajax에서 JSON, XML형태로 데이터를 받을 수 있도록 기능 추가
 * 2008.10.17     KimKS	              SSL 기능 추가
 * 2009.01.22     KimKS	              Ajax 호출 시 정보 추가
 * ---------------------------------------------------------------------------------------
 * Copyright (C) 2007 by ATTO Information Technology Corp. eWork R&D Team  All rights reserved.
 *****************************************************************************************************/
var mRootWebSrcWebFileName = "";
var mRootWebContext = "";
var mServerName = "";
var mHttpPort = "8080";
var mHttpsPort = "8443";
var mSSLMode = false;

try{
	mRootWebSrcWebFileName = gRootWebSrcWebFileName;
	mRootWebContext = gRootWebContents;
	mServerName = gServerName;
	mHttpPort = gHttpPort;
	mHttpsPort = gHttpsPort;
	mSSLMode = gSSLMode;
} catch(ex){
	
}

var SCActionControl ={ 
	/**
	 * 상수 선언
	 */
	SYNERGY_STRUTS_ACTION 	: "SynergyStrutsChannel.action",						//시너지에서 공통으로 제공하는 Action명
	FILE_DOWNLOAD_ACTION 	: "SynergyStrutsFileDownload.action",					//시너지에서 공통으로 제공하는 File Download Action명
	CALL_ACTION 			: "",													//Action을 호출할 네임스페이스
	WEB_CONTEXT 			: "",													//웹컨텍스트명
	CALL_ID 				: "",													//Call Control Mapping ID
	CALL_TYPE 				: "",													//Call Type 기본:bean
	CALL_CLASS 				: "",													//호출할 클래스 팩키지 + 클래스명
	CALL_FUN 				: "",													//호출할 함수명
	SUCCESS_URL 			: "",													//정상처리시 호출될 화면명(전체경로)
	SUBMIT_METHOD 			: "",													//폼을 전송할 방법(get, post)	
	CHAR_SPLIT 				: "|",													//변경하지 말것
	CHAR_SPLIT1 			: ",",
	CHAR_SPLIT2 			: "__",
	CHAR_SPLIT3 			: "&",
	CHAR_SPLIT4 			: "?",
	RESULT_NAME : [],																//Result Name 정보
	RESULT_URL  : [],																//Result URL 정보

	SERVER_NAME				: mServerName,
	HTTP_PORT 				: mHttpPort,
	HTTPS_PORT				: mHttpsPort,
	SSL 					: false,												//SSL 적용여부

	/**
	 * 페이지 링크에 의한 액션 호출
	 */
	linkPage:function(strLinkPath, strAddedParams, strTarget, intWidth, intHeight, strOptions){
		try{
			return SCActionControl.linkPageBase(strLinkPath, strAddedParams, strTarget, intWidth, intHeight, strOptions, false);
		} catch(ex){
			throw SCErrorControl.raiseSysErr(ex, "SCActionControl.linkPage");						
		}
	},
	
	/**
	 * 바로 서비스 URL로 링크해서 처리함
	 */
	linkPageService:function(strLinkPath, strAddedParams, strTarget, intWidth, intHeight, strOptions){
		try{
			return SCActionControl.linkPageBase(strLinkPath, strAddedParams, strTarget, intWidth, intHeight, strOptions, true);
		} catch(ex){
			throw SCErrorControl.raiseSysErr(ex, "SCActionControl.linkPageService");						
		}
	},

	/**
	 * Action을 이용하여 링크처리를 한다.  blnService에 따라 링크 연결 URL이 상대적으로 처리할지 바로 이워크랜드 서비스로 처리할지 결정한다.
	 * @param {Object} strLinkPath					링크 경로
	 * @param {Object} strAddedParams				파라메터 
	 * @param {Object} strTarget					타겟
	 * @param {Object} intWidth						가로 크기
	 * @param {Object} intHeight					세로 크기
	 * @param {Object} strOptions					옵션
	 * @param {Object} blnService					서비스로 연결할지 여부
	 */
	linkPageBase:function(strLinkPath, strAddedParams, strTarget, intWidth, intHeight, strOptions, blnService){
		var strLinkURL = "";
		var blnOption = true;
		//intWidth, intHeight, strOptions가 동시에 없을 경우 일반 window.open 처리를 할 수 있게 속성적용를 하지 않는다.
		if(typeof(intWidth) === "undefined" && typeof(intHeight) === "undefined" && typeof(strOptions) === "undefined"){
			blnOption = false;
			strOptions = "";
		}

		//한글문제를 해결하기 위해 파라메터를 URI 엔코딩을 처리한다.
		strAddedParams = SCStringControl.getEncodingURI(strAddedParams, false);

		try{
			//파라메터 초기화 추가(Ajax를 통할 경우 초기화를 하지 않으면 같은 파라메터가 여러개 생김)
			//this.initAction();
			//중복체크 등록을 처리했으므로 this.initAction();호출하지 않아도 됨(20080616-LEEYH)
			strLinkURL = this.getLinkPage(strLinkPath, strAddedParams);
			if(blnService){strLinkURL = "http://www.eworkland.co.kr/eworklandweb/" + strLinkURL;}

			//페이지 옵셔 설정
			if(blnOption){
				if(typeof(strOptions) === "undefined"){strOptions = "";}
				if(typeof(intWidth) !== "undefined" && typeof(intHeight) !== "undefined" ){
					if (strOptions === ""){
						strOptions = "toolbar=no, location=no, menubar=no, scrollbars=no, status=yes, resizable=yes";	
					}
					var lngTop = (window.screen.height - intHeight) / 2;
					var lngLeft = (window.screen.width - intWidth) / 2;
					strOptions += ", width=" + intWidth + ", height=" + intHeight + ", top=" + lngTop + ", left=" + lngLeft;
				}
			}
			return window.open(strLinkURL,strTarget,strOptions);
		} catch(ex){
			throw SCErrorControl.raiseSysErr(ex, "SCActionControl.linkPageService");						
		}
	},

	/**
	 * 직접적인 위치를 지정해주는 LinkPage  (추가)
	 * @param {Object} strLinkPath					링크 경로
	 * @param {Object} strAddedParams				파라메터 
	 * @param {Object} strTarget					타겟
	 * @param {Object} intWidth						가로 크기
	 * @param {Object} intHeight					세로 크기
	 * @param {Object} lngTop						Top 위치
	 * @param {Object} lngLeft						Left 위치
	 * @param {Object} strOptions					옵션
	 * 
	 * 작성자 : 엄지훈
	 */
	linkPageAddPosition:function(strLinkPath, strAddedParams, strTarget, intWidth, intHeight, lngTop, lngLeft, strOptions){
		var strLinkURL = "";

		try{
			//파라메터 초기화 추가(Ajax를 통할 경우 초기화를 하지 않으면 같은 파라메터가 여러개 생김)
			//this.initAction();
			//중복체크 등록을 처리했으므로 this.initAction();호출하지 않아도 됨(20080616-LEEYH)
			strLinkURL = this.getLinkPage(strLinkPath, strAddedParams);

			//페이지 옵셔 설정
			if(typeof(strOptions) === "undefined"){strOptions = "";}
			if(typeof(intWidth) !== "undefined" && typeof(intHeight) !== "undefined" ){
				if (strOptions === ""){
					strOptions = "toolbar=no, location=no, menubar=no, scrollbars=no, status=yes, resizable=yes";	
				}
				strOptions += ", width=" + intWidth + ", height=" + intHeight + ", top=" + lngTop + ", left=" + lngLeft;
			}
			
			return window.open(strLinkURL,strTarget,strOptions);
		} catch(ex){
			throw SCErrorControl.raiseSysErr(ex, "SCActionControl.linkPageAddPosition");						
		}
	},
	
	getLinkPage:function(strLinkPath, strAddedParams){
		var strParams = "";
		var strAction = "";
		
		try{
			//액션 설정
			strAction = this.getActionName();

			//https 상태일 경우 http로 링크하기 위해 변경 by KimKS
			strAction = this.getServerBaseURL() + strAction;
			/* old
			if (this.WEB_CONTEXT === ""){this.WEB_CONTEXT = mRootWebContext;}
			
			//https 상태일 경우 http로 링크하기 위해 변경 by KimKS
			 
			//strAction = this.WEB_CONTEXT + "/" +strAction; //old
			strAction = "http://" + this.SERVER_NAME + ":" + this.HTTP_PORT + this.WEB_CONTEXT + "/" +strAction;
			*/
			
			if(!(strLinkPath === "")){this.SUCCESS_URL = strLinkPath;}

			//공통파라메터 설정
			strParams = this.getCommonGetParams();

			//Result Name정보를 설정한다.
			if (this.RESULT_NAME.toString() !== "")
				strParams =strParams +  "RESULT_NAME=" + this.RESULT_NAME.join(this.CHAR_SPLIT) + "&";	

			//Result URL정보를 설정한다.
			if (this.RESULT_URL.toString() !== "")
				strParams =strParams +  "RESULT_URL=" + this.RESULT_URL.join(this.CHAR_SPLIT) + "&";	
			
			//추가파라메터 설정
			if(strAddedParams !== ""){strParams += strAddedParams;}
			
			return strAction + this.CHAR_SPLIT4 + strParams;
		} catch(ex){
			throw SCErrorControl.raiseSysErr(ex, "SCActionControl.linkPage");						
		}
	},

	getCommonGetParams:function(){
		var strParams = "";	
		try{
			if (this.CALL_ID !== "") {strParams +=  "CALL_ID=" + this.CALL_ID + this.CHAR_SPLIT3;}
			if (this.CALL_TYPE !== "") {strParams +=  "CALL_TYPE=" + this.CALL_TYPE + this.CHAR_SPLIT3;}
			if (this.CALL_CLASS !== "") {strParams += "CALL_CLASS=" + this.CALL_CLASS + this.CHAR_SPLIT3;}
			if (this.CALL_FUN !== "") {strParams += "CALL_FUN=" + this.CALL_FUN + this.CHAR_SPLIT3;}
			if (this.SUCCESS_URL !== "") {
				// linkpage에서 addresult 했을 때 파라미터가 잘못 생성되는 오류가 있어서 수정
				// 2008-05-21 Lee Jinho
				// ----- 여기부터 -----
				this.RESULT_NAME.push("success");
				this.RESULT_URL.push(this.SUCCESS_URL);
				//strParams += "RESULT_NAME=success" + this.CHAR_SPLIT3 + "RESULT_URL=" + this.SUCCESS_URL + this.CHAR_SPLIT3;
				// ----- 여기까지 -----
			}
			return strParams;
		} catch(ex){
			throw SCErrorControl.raiseSysErr(ex, "SCActionControl.getCommonGetParams");		
		}
	},

	/**
	 * Action정보를 초기화한다.
	 * Action을 호출 후 초기화된다.
	 */
	initAction:function(){
		this.RESULT_NAME = [];
		this.RESULT_URL =[];
		this.SUCCESS_URL = "";
		this.CALL_ID = "";
		this.CALL_CLASS = "";
		this.CALL_FUN = "";
		this.SSL = false;
	},
	
	
	/**
	 * 서버에 정의한 Action을 호출하기에 앞서 팝업 윈도우를 띄운다.
	 * @param {Object} strForm			전송할 폼의 ID값
	 * @param {Object} strGroupID		전송할 폼 안에 그룹으로 묶인 ID 값으로 해당 값을 입력하면 해당 그룹만 전송한다.
	 * @param {Object} strTarget		팝업 윈도우 이름
	 * @param {Object} intWidth		팝업 윈도우 가로 사이즈
	 * @param {Object} intHeight		팝업 윈도우 세로 사이즈
	 * @param {Object} strOptions		팝업 윈도우 옵션 (default: scrollbars=yes, toolbar=no, resizable=no)
	 */
	submitActionPop:function(strForm, strGroupID, strTarget, intWidth, intHeight, strOptions){
		try{
			//팝업 윈도우 속성 초기화
			if(strOptions === null || strOptions === "") {
				strOptions = 'scrollbars=yes, toolbar=no, resizable=no';
			}
			
			//팝업 윈도우를 띄움
			window.open('', strTarget, strOptions + ', width=' + intWidth + ', height=' + intHeight);
			
			//새로 띄운 팝업 윈도우를 타겟으로 지정
			if(strTarget === null || strTarget === "") {
				$(strForm).target = "_self";
			} else {
				$(strForm).target = strTarget;
			}
			
			//submitAction 호출
			this.submitAction(strForm, strGroupID, strTarget);
			
		} catch(ex){
			throw SCErrorControl.raiseSysErr(ex, "SCActionControl.submitActionPop");
		}
	},
	
	/**
	 * 서버에 정의한 Action을 호출 상수값에 맞게 호출한다.
	 * CALL_ACTION을 정하지 않으면 시너지에서 제공하는 스트럿츠 채널을 자동으로 호출한다.
	 * @param {Stirng} strForm    전송할 폼의 ID값
	 * @param {String} strGroupID  전송할 폼 안에 그룹으로 묶인 ID 값으로 해당 값을 입력하면 해당 그룹만 전송한다.
	 */
	submitAction:function(strForm, strGroupID, strTarget){
		try{
			//새로 띄운 팝업 윈도우를 타겟으로 지정
			if(strTarget == null || strTarget == "") {
				$(strForm).target = "_self";
			} else {
				$(strForm).target = strTarget;
			}
			
			//액션명 설정
			var strAction = this.getActionName();
			
			//그룹만 전송할지 체크
			if(strGroupID === ""){
				this.setParam(strForm);								//파라미터 생성 
				if (this.SUBMIT_METHOD !== "")						//프로퍼티에 설정된 것이 우선으로 적용
					$(strForm).method = this.SUBMIT_METHOD;
				
				//https or http로 호출하기위해 변경 by KimKS 
				//$(strForm).action = strAction; //old; 
				$(strForm).action = this.getServerBaseURL() + strAction; 
					
				$(strForm).submit();
			} else {
				SCActionControl.submitPartAction(strForm, strGroupID, strAction);
			}
		} catch(ex){
			throw SCErrorControl.raiseSysErr(ex, "SCActionControl.submitAction");						
		} finally {
			//Action정보 초기화
			this.initAction();
		}
	},
	
	
	/**
	 * 서버에 정의한 Action을 간단한 방식으로 호출한다.
	 * 호출 전에 CALL_ACTION, CALL_ID, CALL_TYPE, CALL_CLASS, CALL_FUN, SUCCESS_URL을 설정하지 않으면 디폴트 값이 설정된다.
	 * @param {Stirng} strForm    전송할 폼의 ID값
	 * @param {String} strAddedParams  액션과 함께 전달할 파라메터.
	 */
	submitSimpleAction:function(strForm, strAddedParams){
		try{
			var strAction;
			var strParams = "";
			
			strAction = this.getActionName();
		
			strParams = this.getActionParams();
			
			if (strAddedParams !== "")
				strParams += strAddedParams;
			
			if (this.SUBMIT_METHOD !== "")			//프로퍼티에 설정된 것이 우선으로 적용
				$(strForm).method = this.SUBMIT_METHOD;
			
			//https or http로 호출하기위해 변경 by KimKS 
			//$(strForm).action = strAction + "?" + strParams; //old
			$(strForm).action = this.getServerBaseURL() + strAction + "?" + strParams;
			
			$(strForm).submit();

		} catch(ex){
			throw SCErrorControl.raiseSysErr(ex, "SCActionControl.submitSimpleAction");						
		} finally {
			//Action정보 초기화
			this.initAction();
		}
	},
	


	/**
	 * 서버에 정의한 Action을 호출 상수값에 맞게 호출한다.
	 * 그룹정보만 파라메터로 전송한다.
	 * @param {Stirng} strForm    전송할 폼의 ID값
	 * @param {String} strGroupID  전송할 폼 안에 그룹으로 묶인 ID 값으로 해당 값을 입력하면 해당 그룹만 전송한다.
	 */
	submitPartAction:function(strForm, strGroupID, strAction){
		try{
			
			//기존 폼에서 데이터를 전송할 수 있는 오브젝트만 추출 한다.
			var objGlobalForm = $("frmGlobal");
			//하위 엘리멘트 객체는 모두 삭제한다.									
			this.removeChild(objGlobalForm);
			objGlobalForm.style.display = "none";
			
			var objArrayId = new Object();
			var objArrayGroupID = strGroupID.split(this.CHAR_SPLIT);	//키그룹추출

			for(var i=0; i < objArrayGroupID.length; i++){
				var objElemnts = $(strForm).getElementsBySelector("INPUT, SELECT, TEXTAREA");
				var strName = "";
				var objCloneElement = null;
				for(var j=0; j<objElemnts.length; j++){
					//해당 엘리멘트로 처리할 경우 화면상에서 사라지다가 나타나는 현상이 발생 하여 Clone으로 복사하여 처리
					strName = objElemnts[j].name;
					if(strName !== ""){
						if(SCActionControl.getGroupID(strName) === objArrayGroupID[i]){
							objCloneElement = objElemnts[j].cloneNode(true);
							objCloneElement.value = objElemnts[j].value;

							//SELECT 태그가 멀티 선택일 경우 처리
							if(objElemnts[j].value !== ""){
								if(['SELECT'].include(objElemnts[j].tagName.toUpperCase())){
									for(var k=0; k<objElemnts[j].options.length; k++){
										if(objElemnts[j].options[k].selected){
											objCloneElement.options[k].selected = true;
										}
									}			
								}	
							}
							
							//FireFox는 값을 할당하고 appending을 해도 정상적으로 값이 설정되지만 IE에서는 check,radio  box가 
							//정상적으로 처리되지 않아 appending후에 check와 radio를 구분지어 각각 값을 설정해야 한다.(IE버그)
							if(['INPUT'].include(objElemnts[j].tagName.toUpperCase()) && ['checkbox'].include(objElemnts[j].type)){
								if(objElemnts[j].checked){
									objGlobalForm.appendChild(objCloneElement);	
									objGlobalForm.lastChild.checked = true;
								} else {
									objGlobalForm.appendChild(objCloneElement);
									objGlobalForm.lastChild.checked = false;	
								}
							} else if(['INPUT'].include(objElemnts[j].tagName.toUpperCase()) && ['radio'].include(objElemnts[j].type)){
								if(objElemnts[j].checked){
									//라디오 버튼은 그룹으로 처리됨으로 값에 대한 할당은 모든 복사가 끝난 후 처리하기 위해 
									//ID값을 취합하여 전송전에 처리한다.(IE버그)
									objArrayId[objElemnts[j].id] = objElemnts[j].id;
								}
								objGlobalForm.appendChild(objCloneElement);	
							} else {
								objGlobalForm.appendChild(objCloneElement);	
							}

						}
					}					
				}
				
			}
			
			//라디오 버튼은 마지막 처리
			for(var strRadioID in objArrayId){
				$(strRadioID).checked = true;
			}
			
			if(objGlobalForm.innerHTML !== ""){
				SCActionControl.setParam("frmGlobal");								//파라미터 생성 
				objGlobalForm.method = this.SUBMIT_METHOD;

				//https or http로 호출하기위해 변경 by KimKS 
				//objGlobalForm.action = strAction;	//old
				objGlobalForm.action = this.getServerBaseURL() + strAction; 
				
				objGlobalForm.submit();
			} else {
				alert(strGroupID + SCConst.SCMSG_CHECK_GROUP);
			}


		} catch(ex){
			throw SCErrorControl.raiseSysErr(ex, "SCActionControl.submitPartAction");			
		}
	},

	/**
	 * Action의 해당 Result 명에 대한 Result URL을 설정한다.
	 * @param {String} strResultName Result명
	 * @param {String} strResultURL Result URL
	 */
	addResultURL:function(strResultName, strResultURL){
		//중복이름으로 처리시 계속 동일 이름이 증가하는 것을 방지하기 위해 이름으로 찾아서 없을 경우 
		//push하고 있으면 해당 인넥스값을 이용하여 해당 strResultURL 값을  업데이트 한다.[20080616-LEEYH]
		var intFindIndex = SCActionControl.findResultName(strResultName); 

		if (intFindIndex >= 0){
			SCActionControl.RESULT_URL[intFindIndex] = strResultURL;
		} else {
			SCActionControl.RESULT_NAME.push(strResultName);
			SCActionControl.RESULT_URL.push (strResultURL);
		}
	},

	/**
	 * RESULT_NAME객체 안에 동일 이름이 있는지 체크하여 있을 경우 해당 인덱스값을 반환한다.
	 * @param {String} strResultName RESULT_NAME의 이름값
	 * @return {int} 찾은 인덱스값, 없을 경우 -1
	 */
	findResultName:function(strResultName){
		for (var i=0; i < SCActionControl.RESULT_NAME.size(); i++){
			if(SCActionControl.RESULT_NAME[i] === strResultName){
				return i;
			}
		}
		return -1;
	},

	/**
	 * 전송할 기본 액션 파라메터를 &로 연결하여 가져온다.
	 */	
	getActionParams:function(){
		var strParams = "";
		
		if (this.CALL_ID !== "")
			strParams += "CALL_ID=" + this.CALL_ID + "&";	
	
		if (this.CALL_TYPE !== "")
			strParams += "CALL_TYPE=" + this.CALL_TYPE + "&";	
	
		if (this.CALL_CLASS !== "")
			strParams += "CALL_CLASS=" + this.CALL_CLASS + "&";	
	
		if (this.CALL_FUN !== "")
			strParams += "CALL_FUN=" + this.CALL_FUN + "&";	
	
		//SUCCESS_URL을 설정한 경우
		//if (this.SUCCESS_URL !== "") --> 의미없음
		//	strParams = strParams +  "SUCCESS_URL=" + this.SUCCESS_URL  + "&";	
		if (this.SUCCESS_URL !== ""){
			this.addResultURL ("success", this.SUCCESS_URL);
		}	
		
		//Result Name정보를 설정한다.
		if (this.RESULT_NAME.toString() !== "")
			strParams += "RESULT_NAME=" + this.RESULT_NAME.join(this.CHAR_SPLIT) + "&";	

		//Result URL정보를 설정한다.
		if (this.RESULT_URL.toString() !== "")
			strParams += "RESULT_URL=" + this.RESULT_URL.join(this.CHAR_SPLIT) + "&";	

		return strParams;
	},

	/**
	 * 전송할 파라메터를 생성하고 해당 폼객체에 동적으로 삽입한다.
	 * @param {String} strForm 폼객체 ID
	 */
	setParam:function(strForm){
		//CALL_ID 생성
		if(this.CALL_ID !== ""){this.createElement(strForm, "INPUT", "txtCALL_ID", "CALL_ID",  this.CALL_ID);}
		//CALL_TYPE 생성
		if(this.CALL_TYPE !== ""){this.createElement(strForm, "INPUT", "txtCALL_TYPE", "CALL_TYPE",  this.CALL_TYPE);}
		//CALL_CLASS 생성
		if(this.CALL_CLASS !== ""){this.createElement(strForm, "INPUT", "txtCALL_CLASS", "CALL_CLASS",  this.CALL_CLASS);}
		//CALL_FUN 생성
		if(this.CALL_FUN !== ""){this.createElement(strForm, "INPUT", "txtCALL_FUN", "CALL_FUN",  this.CALL_FUN);}
		
		//SUCCESS_URL을 설정한 경우
		//if (this.SUCCESS_URL === ""){this.SUCCESS_URL = mRootWebSrcWebFileName;}
		//success가 두번가는 현상으로 아래와 같이 수정함
		if (this.SUCCESS_URL !== ""){
			this.addResultURL ("success", this.SUCCESS_URL);
		}else{
			if(this.RESULT_NAME.toString().indexOf("success") == -1 ){
				this.addResultURL ("success", mRootWebSrcWebFileName);
			} 
		}	

		//의미 없음 : by KimKS
		//if (this.SUCCESS_URL === ""){this.SUCCESS_URL = mRootWebSrcWebFileName;} 
		//this.createElement(strForm, "INPUT", "txtSUCCESS_URL", "SUCCESS_URL",  this.SUCCESS_URL);

		//Result Name정보를 설정한다.
		this.createElement(strForm, "INPUT", "txtRESULT_NAME", "RESULT_NAME",  this.RESULT_NAME.join(this.CHAR_SPLIT));
		//Result URL정보를 설정한다.
		this.createElement(strForm, "INPUT", "txtRESULT_URL", "RESULT_URL",  this.RESULT_URL.join(this.CHAR_SPLIT));
	}, 
		

	/**
	 * 호출할 Action명을 얻는다.
	 */
	getActionName:function(){
		var strActionName = "";

		if (this.CALL_ACTION !== "")
			strActionName = this.CALL_ACTION;
		else 
			strActionName = this.SYNERGY_STRUTS_ACTION;

		return strActionName ;
	}, 

	
	/**
	 * 호출할 서버 기본 주소를 얻는다.
	 */
	getServerBaseURL:function(){
		if (this.WEB_CONTEXT === ""){this.WEB_CONTEXT = mRootWebContext;}
		if (!mSSLMode)
			return "";
		else if (this.SSL)
			return "https://" + this.SERVER_NAME + ":" + this.HTTPS_PORT + this.WEB_CONTEXT + "/";
		else
			return "http://" + this.SERVER_NAME + ":" + this.HTTP_PORT + this.WEB_CONTEXT + "/";
	}, 
	
	/**
	 * 동적으로 Parent Element 하위에 자식 Element를 생성한다.
	 * @param {String} strParent Parent Element ID
	 * @param {String} strTagName 생성할 자식 Element의 태그 이름
	 * @param {String} strId ID값
	 * @param {String} strName Name값
	 * @param {String} strValue 값
	 */
	createElement:function(strParent, strTagName, strId, strName, strValue){
		//해당 태그이름의 엘리메트가 있는지 찾는다.
		var blnSetValue = false;
		var objElemnts = $(strParent).getElementsBySelector(strTagName);
		if(objElemnts.length !== 0){
			objElemnts.each(
				function(objElenment, index){
					if(objElenment.name === strName){
						objElenment.value = strValue; 
						blnSetValue = true;
					}
				}
			);			
		}

		//해당 Element의 동일한 이름이 없을 경우 새롭게 생성한다.
		if(objElemnts.length === 0 || ! blnSetValue) {
			var objElement = document.createElement(strTagName);
			objElement.id =strId;
			objElement.name = strName;
			objElement.value = strValue;
			objElement.style.display = "none";
			$(strParent).appendChild(objElement);
		}
	},
	
	/**
	 * 오브젝트 객체 이름에서 그룹 ID를 추출하여 반환한다.
	 * @param {Object} strName 오브젝트 객체 이름
	 */
	getGroupID:function(strName){
		if(strName.indexOf("__") >= 0){
			return strName.substring(0, strName.indexOf("__"));
		} else {
			return "";
		}
	},
	
	/**
	 * 하위 노드들을 삭제한다.
	 * @param {Object} objForm 부모 엘리메트 객체
	 */
	removeChild:function(objForm){
		var ChildNodes = objForm.childNodes;
		var intLength = ChildNodes.length;
		for (var i = intLength; i > 0; i--){
			objForm.removeChild(ChildNodes[i - 1]);
		}
	}

};

var SCAjaxControl ={ 

	/*---------------------------------
	 * 상수 및 전역 변수 선언
	 *---------------------------------*/
	resultConsts : {
		CODE_KEY	: '@resultCode',	//처리결과 코드
		MSG_KEY		: '@resultMsg',		//오류 시 메시지 키
		CODE_OK		: '0'				//정상처리결과 값
	},

	resultTypes : {
		PAGE	: '',		//(default) Result Page로 결과를 받음
		JSON	: 'JSON',	//JSON 데이타 포맷
		XML		: 'XML'		//XML 데이타 포맷 : 미완
	},

	RESULT_TYPE		: "",	//결과 값 형태 (주의)ajaxActionRequest에만 적용 됨
	
	/**
	 * Ajax 환경 옵션 오브젝트
	 * ajaxRequest 또는 ajaxActionRequest를 호출하기 전에 설정되어야 한다. 
	 */
	options : { method			: 'post',
				asynchronous	: true,
				contentType		: 'application/x-www-form-urlencoded',
				encoding		: 'utf-8',
				parameters		: '',
				postBody		: '',
				onSuccess		: '',
				onFailure		: '',
				onException		: ''
			  },
	
	/**
	 * Ajax 통신으로 Request를 처리한다.
	 * @param {Object} strRequestURL Request를 보낼 URL
	 */
	ajaxRequest:function(strRequestURL){
		//기본 callBack 함수 정의
		if (this.options.onFailure == '') {this.options.onFailure =  this.defaultFailure; }
		if (this.options.onException == '') {this.options.onException =  this.defaultException; }
		
		//Ajax Reauest 객체를 생성하여 요청을 보낸다.
		//처리 결과는 options의 onSuccess callBack 함수를 호출하여 전달된다.
		var ajaxReq = new Ajax.Request( strRequestURL, this.options);
		
		//(중요)파라메터 클리어
		this.options.parameters = "";
		this.options.postBody = "";
	},
	
	/**
	 * Ajax 통신으로 Request를 Synergy Struts Action으로 보내 처리한다.
	 * @param {Object} strAddedParams 추가로 전달할 파라메터 
	 */
	ajaxActionRequest:function(strAddedParams){
		//Synergy Struts Action의 파라메터를 얻는다.
		var strParams = SCActionControl.getActionParams() + "&scajax=true&";
		
		if (typeof(strAddedParams) !== "undefined" && strAddedParams !== null) {
			strParams +=  "&" + strAddedParams;
		}

		//RESULT_TYPE 생성
		if (this.RESULT_TYPE !== "")
			strParams += "RESULT_TYPE=" + this.RESULT_TYPE;	
		
		//Ajax 옵션에 파라메터를 설정한다.
		if (this.options.method.toLowercase == 'get') {
			typeof(this.options.parameters) == 'string' ? 
				this.options.parameters += "&" + strParams	:
				this.options.parameters = this.options.parameters.toQueryString() + "&" + strParams;			
		}else {
			if (this.options.parameters != "" && this.options.postBody == "") { this.options.postBody = this.options.parameters; }
			typeof(this.options.postBody) == 'string' ? 
				this.options.postBody += "&" + strParams :
				this.options.postBody = this.options.postBody.toQueryString() + "&" + strParams;	
		}
		 
		//Synergy Struts Action으로 Request를 보낸다. 
		
		this.ajaxRequest (SCActionControl.getActionName());
		
		//예) Form 파라메터 파싱 방법
		//var strParams = Form.serialize (strForm, "NE"); //Not Encoding
		//for (var prop in strParams) {
		//	alert (prop + ':' + strParams[prop]);
		//}
		
	},
	
	/**
	 * Ajax Request 처리에서 발생한 오류의 기본 callBack 함수 (onFailure)
	 * @param {Object} xmlHttp XMLHttpRequest
	 */
	defaultFailure:function(xmlHttp){
		alert ("AJAX failed : Error No="  + xmlHttp.status + "; [" + xmlHttp.statusText + "]");
	},
	
	/**
	 * Ajax Request 처리에서 발생한 Exception의 기본 callBack 함수 (onException)
	 * @param {Object} xmlHttp XMLHttpRequest
	 */
	defaultException:function(xmlHttp, exception){
		alert ("AJAX Exception : " + exception);
	},
	
	/**
	 * 결과 데이터를 JSON 객체로 변환한다.
	 * @param {Object} xmlHttp XMLHttpRequest
	 */
	responseJson:function(xmlHttp){
		//JSON 포맷인지를 검사하고, JSON 객체로 변환
		var returnData = xmlHttp.responseText.evalJSON(true);
		
		//오류 처리
		if (returnData.resultSet[this.resultConsts.CODE_KEY] !== undefined && returnData.resultSet[this.resultConsts.CODE_KEY] !== this.resultConsts.CODE_OK){
			throw new Error(returnData.resultSet[this.resultConsts.MSG_KEY]);
		}
		
		//결과반환
		return returnData;
	}	
};
