$package('com.trs.wcm.infoview');
var IS_DEBUG = false;
var InfoViewConstants = {
	ResourceBase : './',
	FileUploadURL : 'file/file_upload.jsp',
	RichTextEditorURL : 'infoview_rich_text_editor.htm',
	ReadFileURL : '../file/read_file.jsp'	
}
InfoViewConstants.ReadFileURLPath = InfoViewConstants.ReadFileURL + '?FileName=';
InfoViewConstants.FileUploadDowithURL = null;
/*************************************************************/
var PageContext = {
	InitPage : function(_nChannelId, _nDocumentId) {
		if(_nChannelId == null || _nChannelId == 0 || _nDocumentId == null || _nDocumentId == 0)
			return;
		var sRequestUrl = "./infoview_document_get_data.jsp?ChannelId=" + _nChannelId + "&DocumentId=" + _nDocumentId;
		new Ajax.Request(sRequestUrl,{
			method : 'get',
			onSuccess : function(_transport){
				_XMLDATA_.initPageByData(_transport.responseText);
			},
			onFailure : function(_transport){
				alert("Problem retrieving XML data");
			}
		});
	},
	InitPageGateWay : function(_sGateWayInitUrl, _fOnSuccess) {
		if(!_sGateWayInitUrl)return;
		var sRequestUrl = "";
		if(_sGateWayInitUrl.indexOf('?')!=-1){
			sRequestUrl = _sGateWayInitUrl + "&" + location.search.substring(1);
		}
		else{
			sRequestUrl = _sGateWayInitUrl + location.search;
		}
		var oRequest = new Ajax.Request(sRequestUrl,{
			method : 'get',
			onSuccess : function(_transport, _json){
				var sGateWayMode = oRequest.header('GATEWAY_MODE');
				switch(sGateWayMode){
					case 'CACHED_DATA' :
						//\u9690\u85CF\u8DDF\u63D0\u4EA4\u76F8\u5173\u7684\u9875\u9762\u5143\u7D20
						PageContext.__hideActionsElements();
						if(_fOnSuccess){
							(_fOnSuccess)(_transport.responseText.trim());
						}
						break;
					case 'USERINFO'	:
						try{
							if(_fOnSuccess){
								(_fOnSuccess)(null, _json['USERINFO']);
							}
						}catch(err){
						}
						break;
					case 'NIL':
						if(_fOnSuccess){
							(_fOnSuccess)();
						}
						break;
					case 'NEED_LOGIN':
						try{
							//\u9690\u85CF\u8DDF\u63D0\u4EA4\u76F8\u5173\u7684\u9875\u9762\u5143\u7D20
							PageContext.__hideActionsElements();
							TRSCrashBoard.setMaskable(true);
							var sUrl = frmAction.GATEWAYLOGIN.value;	
							TRSDialogContainer.register('Trs_Gateway_Login', 
									'\u8BE5\u8868\u5355\u9700\u8981\u767B\u5F55', sUrl, 220, 230, true);		
							TRSDialogContainer.display('Trs_Gateway_Login');
						}catch(err){
							//just skip it
							alert('\u8BE5\u8868\u5355\u9700\u8981\u767B\u5F55\u540E\u624D\u80FD\u586B\u62A5\uFF01\u8BF7\u5148\u767B\u5F55\u3002');
						}
						break;
					case 'EXCEPTION' :
						//TODO
						break;
				}
			},
			onFailure : function(_transport){
				if(_fOnSuccess){
					(_fOnSuccess)();
				}
			}
		});
	},
	//ge gfc add @ 2008-1-16 \u9690\u85CF\u8DDF\u63D0\u4EA4\u76F8\u5173\u7684\u9875\u9762\u5143\u7D20(\u5305\u62EC\u63D0\u4EA4\u3001\u91CD\u7F6E\u3001\u53D6\u6D88\u7B49\u6309\u94AE\uFF0C\u5982\u679C\u6709\u7684\u8BDD)
	__hideActionsElements : function(){
		if($('Infoview_PubPage_Actions')) {
			Element.hide('Infoview_PubPage_Actions');
		}
		if($('SubmitButton')){
			Element.hide('SubmitButton');
		}
		if($('ResetButton')){
			Element.hide('ResetButton');
		}	
	},
	isReadable : function(_sTrsTempId, _nFieldType, _oElement){
		if(PageContext.isWorkFlowMode()){
			if(parent.window.WorkFlowHelper && parent.window.WorkFlowHelper.isReadable){
				return parent.window.WorkFlowHelper.isReadable(_sTrsTempId);
			}
			if(window.WorkFlowHelper && window.WorkFlowHelper.isReadable){
				return window.WorkFlowHelper.isReadable(_sTrsTempId);
			}
		}
		else if(PageContext.isNormalSettingMode()){
			if(parent.window.SettingHelper && parent.window.SettingHelper.isReadable){
				return parent.window.SettingHelper.isReadable(_sTrsTempId, _nFieldType, _oElement);
			}
			if(window.SettingHelper && window.SettingHelper.isReadable){
				return window.SettingHelper.isReadable(_sTrsTempId, _nFieldType, _oElement);
			}
		}
		return false;
	},
	isWriteable : function(_sTrsTempId, _nFieldType, _oElement){
		if(PageContext.isWorkFlowMode()){
			if(parent.window.WorkFlowHelper && parent.window.WorkFlowHelper.isWriteable){
				return parent.window.WorkFlowHelper.isWriteable(_sTrsTempId);
			}
			if(window.WorkFlowHelper && window.WorkFlowHelper.isWriteable){
				return window.WorkFlowHelper.isWriteable(_sTrsTempId);
			}
		}
		else if(PageContext.isNormalSettingMode()){
			if(parent.window.SettingHelper && parent.window.SettingHelper.isWriteable){
				return parent.window.SettingHelper.isWriteable(_sTrsTempId, _nFieldType, _oElement);
			}
			if(window.SettingHelper && window.SettingHelper.isWriteable){
				return window.SettingHelper.isWriteable(_sTrsTempId, _nFieldType, _oElement);
			}
		}
		return false;
	},
	toggleReadable : function(_sTrsTempId, _nFieldType, _oElement){
		var oWindow = parent.window;
		if(_nFieldType==2){
			oWindow = window;
		}
		if(PageContext.isWorkFlowMode()){
			if(oWindow.WorkFlowHelper){
				if(oWindow.WorkFlowHelper.toggleReadable){
					oWindow.WorkFlowHelper.toggleReadable(_sTrsTempId, _nFieldType);
				}
				if(oWindow.WorkFlowHelper._EffectPowerByView){
					oWindow.WorkFlowHelper._EffectPowerByView(_sTrsTempId, _nFieldType, 'read', this.isReadable(_sTrsTempId));
				}
			}
		}
		else if(PageContext.isNormalSettingMode()){
			if(oWindow.SettingHelper){
				if(oWindow.SettingHelper.toggleReadable){
					return oWindow.SettingHelper.toggleReadable(_sTrsTempId, _nFieldType, _oElement);
				}
				if(oWindow.SettingHelper._EffectPowerByView){
					oWindow.SettingHelper._EffectPowerByView(
						_sTrsTempId, _nFieldType, 'read', this.isReadable(_sTrsTempId, _nFieldType, _oElement), _oElement);
				}
			}
		}
		return true;
	},
	toggleWriteable : function(_sTrsTempId, _nFieldType, _oElement){
		var oWindow = parent.window;
		if(PageContext.isWorkFlowMode()){
			if(oWindow.WorkFlowHelper){
				if(oWindow.WorkFlowHelper.toggleWriteable){
					oWindow.WorkFlowHelper.toggleWriteable(_sTrsTempId, _nFieldType);
				}
				if(oWindow.WorkFlowHelper._EffectPowerByView){
					oWindow.WorkFlowHelper._EffectPowerByView(_sTrsTempId, _nFieldType, 'write', this.isWriteable(_sTrsTempId));
				}
			}
		}
		else if(PageContext.isNormalSettingMode()){
			if(oWindow.SettingHelper){
				if(oWindow.SettingHelper.toggleWriteable){
					return oWindow.SettingHelper.toggleWriteable(_sTrsTempId, _nFieldType, _oElement);
				}
				if(oWindow.SettingHelper._EffectPowerByView){
					oWindow.WorkFlowHelper._EffectPowerByView(
						_sTrsTempId, _nFieldType, 'write', this.isWriteable(_sTrsTempId, _nFieldType, _oElement), _oElement);
				}
			}
		}
		return true;
	},
	getInitValue : function(_sTrsTempId){
		if(parent.window.WorkFlowHelper && parent.window.WorkFlowHelper.getInitValue){
			return parent.window.WorkFlowHelper.getInitValue(_sTrsTempId);
		}
		if(window.WorkFlowHelper && window.WorkFlowHelper.getInitValue){
			return window.WorkFlowHelper.getInitValue(_sTrsTempId);
		}
		return null;
	},
	isReadOnly : function() {
		if((new com.trs.wcm.infoview.MyURL()).getParameter("ReadOnly") == 1)
			return true;
		return PageContext.isSettingMode()||PageContext.isShowMode();
	},
	isSettingMainPage : function() {
		return window.INFOVIEW_MODE == "Setting";
	},
	isWorkFlowMode : function(){
		return window.INFOVIEW_MODE == "WorkFlow_Setting" || window.parent.INFOVIEW_MODE == "WorkFlow_Setting";
	},
	isNormalSettingMode : function(){
		return window.INFOVIEW_MODE == "Setting" || window.parent.INFOVIEW_MODE == "Setting";
	},
	isSettingMode : function(){
		return this.isNormalSettingMode() || this.isWorkFlowMode();
	},
	isAddEditMode : function(){
		return window.INFOVIEW_MODE == "AddEdit" || parent.window.INFOVIEW_MODE == "AddEdit" || this.isPublicAddEditMode();
	},
	isPublicAddEditMode : function(){
		return window.INFOVIEW_MODE == "PublicAddEdit" || parent.window.INFOVIEW_MODE == "PublicAddEdit";
	},
	isShowMode : function(){
		return window.INFOVIEW_MODE == "Show" || parent.window.INFOVIEW_MODE == "Show";
	},
	isPreviewMode : function(){
		return window.INFOVIEW_MODE == "Preview" || parent.window.INFOVIEW_MODE == "Preview";
	},
	isEditableMode : function(){
		return !PageContext.isReadOnly();
//		return PageContext.isAddEditMode() || PageContext.isPreviewMode();
	},
	isMainPage : function(){
		return window.INFOVIEW_MODE != null;
	},
	isViewPage : function(){
		return window.INFOVIEW_MODE == null && parent.window.INFOVIEW_MODE != null;
	},
	isInfoViewViewPage : function(){
		if(window.IsViewPage == null){
			var bIsViewPage =  (window.INFOVIEW_MODE == null && parent.window.INFOVIEW_MODE != null);
			if(!bIsViewPage && window.INFOVIEW_MODE != null){
				var arrIframes = document.getElementsByTagName("iframe");
				bIsViewPage = true;
				for(var i=0; i<arrIframes.length; i++) {
					try{
						if(arrIframes[i].contentWindow.PageElementHelper){
							bIsViewPage = false;
							break;
						}
					}catch(err){
						//Just skip it.
					}
				}
			}
			window.IsViewPage = bIsViewPage;
		}
		return window.IsViewPage;
	},
	EventObsering4SettingMode : function() {
		var arrNodes = document.getElementsByTagName("DIV");
		for(var i=0; i<arrNodes.length; i++) {
			var oNode = arrNodes[i];
			if(!oNode.getAttribute("trs_obj_id", 2)
				|| !oNode.getAttribute("trs_obj_type", 2)
				|| !oNode.getAttribute("trs_obj_typename", 2))
				continue;
			oNode.style.cursor = 'pointer';
			PageElementHelper.EventObserveMe(oNode);
		}
		arrNodes = document.getElementsByTagName("INPUT");
		for(var i=0; i<arrNodes.length; i++) {
			var oNode = arrNodes[i];
			if(oNode.type != "text" || !oNode.getAttribute("xd:xctname", 2))
				continue;
			PageElementHelper.EventObserveMe(oNode);
			oNode.onclick = function() {
				return false;
			}
		}
	},
	//Create & Register ContextMenus of this page
	BuildContextMenu : function() {
		if(PageContext.isMainPage()){
			if(PageContext.isSettingMode()){
				PageContext._BuildCM4MainSetting();
			}
			if(PageContext.isPublicAddEditMode()){
				PageContext._BuildCM4Edit();
			}
			return;
		}
		if(PageContext.isNormalSettingMode()){
			PageContext._BuildCM4Setting();
		}
		else if(PageContext.isWorkFlowMode()){
			PageContext._BuildCM4WorkFlow();
		}
		else if(PageContext.isEditableMode()){
			PageContext._BuildCM4Edit();
		}
	},
	_BuildCM4WorkFlow : function() {
		_MenuContainer_.RegisterMenu(PageContext._CM_InfoViewGroup());
		_MenuContainer_.RegisterMenu(PageContext._CM_InfoViewField());
	},
	_BuildCM4Edit : function() {
		_MenuContainer_.RegisterMenu(PageContext._CM_RepeatTable());
		_MenuContainer_.RegisterMenu(PageContext._CM_FileAttachment());
	},
	_BuildCM4Setting : function() {
		_MenuContainer_.RegisterMenu(PageContext._CM_InfoViewGroup());
		_MenuContainer_.RegisterMenu(PageContext._CM_InfoViewField());
	},
	_BuildCM4MainSetting : function() {
		_MenuContainer_.RegisterMenu(PageContext._CM_InfoViewTitle());
		_MenuContainer_.RegisterMenu(PageContext._CM_InfoViewView());
	},
	_CM_RepeatTable : function(){
		//selectable section menu
		var oSelectableSectionMenu = new com.trs.wcm.infoview.ContextMenu("SelectableSectionMenu", "100px");
		oSelectableSectionMenu.addItem("trs_xCollection_insert", "\u63D2\u5165", 
			PageContext.Extend.GetRepeatInsertFunction(oSelectableSectionMenu, true), true);
		oSelectableSectionMenu.addItem("trs_xCollection_insertBefore", "\u5728\u4E0A\u65B9\u63D2\u5165", 
			PageContext.Extend.GetRepeatInsertFunction(oSelectableSectionMenu, true), true);
		oSelectableSectionMenu.addItem("trs_xCollection_insertAfter", "\u5728\u4E0B\u65B9\u63D2\u5165", 
			PageContext.Extend.GetRepeatInsertFunction(oSelectableSectionMenu, false), true);
		oSelectableSectionMenu.addItem("trs_xCollection_remove", "\u5220\u9664", function() {
			var oSrcElement = _MenuContainer_.GetSrcElement();
			var arrBrothers = _MenuContainer_.getBrothersOfSameXctName(oSrcElement);
			if(arrBrothers.length > 1)
				oSrcElement.parentNode.removeChild(oSrcElement);
			oSelectableSectionMenu.hide();
		});
		oSelectableSectionMenu.create();
		return oSelectableSectionMenu;
	},
	_CM_FileAttachment : function(){
		//file upload menu
		var oFileUploadMenu = new com.trs.wcm.infoview.ContextMenu("FileUploadMenu");
		oFileUploadMenu.addItem("attach", "\u9644\u52A0...", function() {
			var oSrcElement = _MenuContainer_.GetSrcElement();
			var oProps = {
				AllowExt : oSrcElement.getAttribute('allow_ext', 2),
				InlineImg: (oSrcElement.getAttribute('trs_file_upload_type', 2) == 'InlineImage')
			};
			if(InfoViewConstants.FileUploadDowithURL != null) {
				oProps['DowithUrl'] = InfoViewConstants.FileUploadDowithURL;
			}
			if(parent != self && parent.window.TRSDialogContainer 
					&& parent.window.TRSDialogContainer.DialogsMap['FileUploadDialog']){
				parent.window.TRSDialogContainer.DialogsMap['FileUploadDialog'].srcElement = oSrcElement;
				var positions = Position.getAbsolutePositionInTop(oSrcElement);
				var offsetX = document.body.scrollLeft;
				var offsetY = document.body.scrollTop;
				parent.window.TRSDialogContainer.display("FileUploadDialog", oProps, positions[0] + 20 - offsetX, positions[1] + 20 - offsetY);
			}else{
				TRSDialogContainer.DialogsMap['FileUploadDialog'].srcElement = oSrcElement;
				TRSDialogContainer.display("FileUploadDialog", oProps);
			}
			oFileUploadMenu.hide();
		});
		oFileUploadMenu.addItem("open", "\u6253\u5F00", function() {
			var oSrcElement = _MenuContainer_.GetSrcElement();
			var arrInputs = oSrcElement.getElementsByTagName("input");
			var sFileName = null;
			for(var i=0; i<arrInputs.length; i++) {
				if(arrInputs[i].type == "hidden") {
					sFileName = arrInputs[i].value;
					break;
				}
			}
			if(sFileName == null || sFileName == "")
				return;
			window.open(InfoViewConstants.ReadFileURLPath + sFileName);
			oFileUploadMenu.hide();
		});
		oFileUploadMenu.addItem("remove", "\u5220\u9664", function() {
			var oSrcElement = _MenuContainer_.GetSrcElement();
			var sFileUploadType = oSrcElement.getAttribute("trs_file_upload_type", 2);
			if(sFileUploadType == "InlineImage" || sFileUploadType == "LinkedImage") {
				var arrNodes = oSrcElement.childNodes;
				for(var i=0; i<arrNodes.length; i++) {
					if(!arrNodes[i].tagName
						||(arrNodes[i].tagName == "INPUT" && arrNodes[i].style == "hidden"))
						continue;
					if(arrNodes[i].getAttribute("image_body", 2) == "1") {
						arrNodes[i].style.display = "none";
						continue;
					}
					arrNodes[i].style.display = "inline";
				}
			}else{
				var arrTextSpan = oSrcElement.getElementsByTagName("span");
				for(var i=0; i<arrTextSpan.length; i++) {
					if(arrTextSpan[i].getAttribute("text_body", 2) == "1")
						arrTextSpan[i].style.display = "inline";
					if(arrTextSpan[i].getAttribute("text_file", 2) == "1")
						arrTextSpan[i].style.display = "none";
				}
			}
			var arrFileInputs = oSrcElement.getElementsByTagName("input");
			for(var i=0; i<arrFileInputs.length; i++) {
				if(arrFileInputs[i].getAttribute("xd:binding", 2) != null) {
					arrFileInputs[i].value = "";
					//arrFileInputs[i].removeAttribute("xd:xctname");
					//arrFileInputs[i].setAttribute("xd:xctname", "");
					break;
				}
			}
			oFileUploadMenu.hide();
		});
		oFileUploadMenu.addItem("attach_more", "\u9644\u52A0\u66F4\u591A\u9644\u4EF6", function() {
			var oSrcElement = _MenuContainer_.GetSrcElement();
			//var arrInputs = oSrcElement.getElementsByTagName("input");
			var oCloneNode = oSrcElement.cloneNode(true);
			//\u8D77\u4E00\u4E2A\u65B0\u7684id
			oCloneNode.id = oCloneNode.id + '_' + Math.random();
			PageElementHelper.CloneEventObserving(oSrcElement, oCloneNode);

			//\u6E05\u9664\u4E0D\u5FC5\u8981\u7684\u5C5E\u6027
			var arrTextSpan = oCloneNode.getElementsByTagName("span");
			for(var i=0; i<arrTextSpan.length; i++) {
				if(arrTextSpan[i].getAttribute("text_body", 2) == "1")
					arrTextSpan[i].style.display = "inline";
				if(arrTextSpan[i].getAttribute("text_file", 2) == "1")
					arrTextSpan[i].style.display = "none";
			}
			var arrFileInputs = oCloneNode.getElementsByTagName("input");
			for(var i=0; i<arrFileInputs.length; i++) {
				if(arrFileInputs[i].getAttribute("xd:binding", 2) != null) {
					arrFileInputs[i].value = "";
					//arrFileInputs[i].removeAttribute("xd:xctname");
					//arrFileInputs[i].setAttribute("xd:xctname", "");
					break;
				}
			}
			oSrcElement.parentNode.insertBefore(oCloneNode, oSrcElement);
			//alert(oCloneNode.outerHTML);

			oFileUploadMenu.hide();
		});
		oFileUploadMenu.create();
		return oFileUploadMenu;
	},
	_CM_InfoViewGroup : function(){
		//\u533A\u57DF\u8BBE\u7F6E
		var oAreaSettingMenu = new com.trs.wcm.infoview.ContextMenu("AreaSettingMenu", "100px");
		oAreaSettingMenu.addItem("publish_permission", "\u5141\u8BB8\u53D1\u5E03", 
			PageContext.Extend.GetPublishPermissionFunction(oAreaSettingMenu,'infoview-group'));
		oAreaSettingMenu.create();
		oAreaSettingMenu.addItem("readable_setting", "\u5141\u8BB8\u67E5\u770B", 
			PageContext.Extend.GetPowerSettingFunction(oAreaSettingMenu, 1, 1));
		oAreaSettingMenu.create();
//		oAreaSettingMenu.addItem("workflow_setting", "\u9AD8\u7EA7\u8BBE\u7F6E", 
//			PageContext.Extend.GetRightSetFunction(oAreaSettingMenu));
//		oAreaSettingMenu.create();
		return oAreaSettingMenu;
	},
	_CM_InfoViewField : function(){
		//\u5B57\u6BB5
		var oItemSettingMenu = new com.trs.wcm.infoview.ContextMenu("ItemSettingMenu", "100px");
		oItemSettingMenu.addItem("append_to_title", "\u6DFB\u52A0\u5230\u6807\u9898", 
			PageContext.Extend.GetTitlePatternFunction(oItemSettingMenu, '_INFOVIEW_FIELD_'));
		oItemSettingMenu.addItem("attr_setting", "\u5C5E\u6027\u8BBE\u7F6E", 
			PageContext.Extend.GetAttrSettingFunction(oItemSettingMenu));
		oItemSettingMenu.addItem("readable_setting", "\u5141\u8BB8\u67E5\u770B", 
			PageContext.Extend.GetPowerSettingFunction(oItemSettingMenu, 0, 1));
		oItemSettingMenu.create();
		oItemSettingMenu.addItem("writeable_setting", "\u5141\u8BB8\u7F16\u8F91", 
			PageContext.Extend.GetPowerSettingFunction(oItemSettingMenu, 0, 2));
		oItemSettingMenu.create();
		oItemSettingMenu.addItem("initvalue_setting", "\u6062\u590D\u9ED8\u8BA4\u503C", 
			PageContext.Extend.GetInitValueSettingFunction(oItemSettingMenu));
		oItemSettingMenu.create();
		oItemSettingMenu.addItem("workflow_setting", "\u9AD8\u7EA7\u8BBE\u7F6E", 
			PageContext.Extend.GetRightSetFunction(oItemSettingMenu, 0));
		oItemSettingMenu.create();
		return oItemSettingMenu;
	},
	_CM_InfoViewView : function(){
		//\u89C6\u56FE\u8BBE\u7F6E
		var oViewSettingMenu = new com.trs.wcm.infoview.ContextMenu("ViewSettingMenu", "100px");
		oViewSettingMenu.addItem("publish_permission", "\u5141\u8BB8\u53D1\u5E03", 
			PageContext.Extend.GetPublishPermissionFunction(oViewSettingMenu, 'infoview-view'));
		oViewSettingMenu.create();
		oViewSettingMenu.addItem("set_default_view", "\u9ED8\u8BA4\u89C6\u56FE", 
			PageContext.Extend.GetDefaultViewFunction(oViewSettingMenu));
		oViewSettingMenu.create();
		oViewSettingMenu.addItem("readable_setting", "\u5141\u8BB8\u67E5\u770B", 
			PageContext.Extend.GetPowerSettingFunction(oViewSettingMenu, 2, 1));
		oViewSettingMenu.create();
		return oViewSettingMenu;
	},
	_CM_InfoViewTitle : function(){
		var oTitleSystemMenu = new com.trs.wcm.infoview.ContextMenu("TitleSystemMenu", "100px");
		oTitleSystemMenu.addItem("user", "\u7528\u6237\u540D", 
			PageContext.Extend.GetTitlePatternFunction(oTitleSystemMenu, '${::user}'));
		oTitleSystemMenu.addItem("time_1", "\u65F6\u95F4:YYYY\u5E74MM\u6708DD\u65E5", 
			PageContext.Extend.GetTitlePatternFunction(oTitleSystemMenu, '${::time,yyyy\u5E74MM\u6708dd\u65E5}'));
		oTitleSystemMenu.addItem("time_2", "\u65F6\u95F4:YY\u5E74MM\u6708DD\u65E5", 
			PageContext.Extend.GetTitlePatternFunction(oTitleSystemMenu, '${::time,yy\u5E74MM\u6708dd\u65E5}'));
		oTitleSystemMenu.addItem("time_3", "\u65F6\u95F4:YYYY-MM-DD", 
			PageContext.Extend.GetTitlePatternFunction(oTitleSystemMenu, '${::time,yyyy-MM-dd}'));
		oTitleSystemMenu.addItem("time_4", "\u65F6\u95F4:YYYYMMDD", 
			PageContext.Extend.GetTitlePatternFunction(oTitleSystemMenu, '${::time,yyyyMMdd}'));
		oTitleSystemMenu.create();
		return oTitleSystemMenu;
	}
}
/*********************************************************************/
PageContext.Extend = {
	KeyDownOnListItem : function(_oElement) {
		if(_oElement == null)
			return;
		var oEvent = Event.findEvent();
		var nKeyCode = oEvent.keyCode;
		switch(nKeyCode) {
			case 13 ://Enter
				var oldElement = _oElement.parentNode;
				var newElement = oldElement.cloneNode(true);
				var arrChildNodes = newElement.getElementsByTagName("input");
				for(var i=0; i<arrChildNodes.length; i++) {
					var oInputNode = arrChildNodes[i];
					oInputNode.value = "";
				}
				PageElementHelper.CloneEventObserving(oldElement, newElement);
				oldElement.parentNode.insertBefore(newElement, oldElement.nextSibling);
				newElement.firstChild.focus();
				break;
			case 8 ://Backspace
				if(_oElement.value != "")
					break;
				var oCurrentNode = _oElement.parentNode;
				if(oCurrentNode == null)
					break;
				var oPreviousNode = oCurrentNode.previousSibling;
				if(oPreviousNode == null)
					break;
				var oParentNode = oCurrentNode.parentNode;
				if(oParentNode == null)
					break;
				oPreviousNode.firstChild.focus();
				oPreviousNode.firstChild.value = oPreviousNode.firstChild.value;
				oParentNode.removeChild(oCurrentNode);
				break;
		}
	},
	GetRepeatInsertFunction : function(_oSelectableSectionMenu,_bInsertBefore){
		return function() {
			var oSrcElement = _MenuContainer_.GetSrcElement();
			var oParentElement = oSrcElement.parentNode;
			if(oParentElement == null)
				return;
			var oCloneElement = oSrcElement.cloneNode(true);
			PageElementHelper.CloneEventObserving(oSrcElement, oCloneElement);
			var oRefElement = (_bInsertBefore)?oSrcElement:oSrcElement.nextSibling;
			oParentElement.insertBefore(oCloneElement, oRefElement);
			_XExpression_.setExpression(oCloneElement);
			_oSelectableSectionMenu.hide();
		}
	},
	GetRightSetFunction : function(_oContextMenu, _nFieldType){
		return function() {
			var oSrcElement = _MenuContainer_.GetSrcElement();
			var sTrsTempId = oSrcElement.getAttribute("trs_temp_id");
			if(parent.window.openFieldSetting){
				parent.window.openFieldSetting(sTrsTempId, _nFieldType || 0);
			}
			_oContextMenu.hide();
		}
	},
	GetTitlePatternFunction : function(_oContextMenu, _sTitlePattern){
		return function() {
			var oTitleNode = document.getElementById("TitlePattern");
			var sCurrTitlePattern = _sTitlePattern;
			if(_sTitlePattern=='_INFOVIEW_FIELD_'){
				if(window.parent)
					oTitleNode = window.parent.document.getElementById("TitlePattern");
				if(!oTitleNode)return;
				var oSrcElement = _MenuContainer_.GetSrcElement();
				sCurrTitlePattern = '${' + oSrcElement.name + '}';
			}
			PageElementHelper.AppendValue(oTitleNode, sCurrTitlePattern);
			_oContextMenu.hide();
		}
	},
	GetAttrSettingFunction : function(_oContextMenu){
		return function() {
			var oSrcElement = _MenuContainer_.GetSrcElement();
			//TODO
			if(parent.window && parent.window.openEditAttrs){
				parent.window.openEditAttrs(oSrcElement.getAttribute('trs_temp_id', 2));
			}
			_oContextMenu.hide();
		}
	},
	_SaveView_ : function(_sElementAttrName, _sWcmObjPropName){
		var oSrcElement = _MenuContainer_.GetSrcElement();
		var sCurrValue = oSrcElement.getAttribute(_sElementAttrName, 2);
		var nFlag = sCurrValue == "1" ? 0 : 1;
		oSrcElement.setAttribute(_sElementAttrName, nFlag);
		var oWCMObj = new CWCMObj();
		oWCMObj.setProperty(_sWcmObjPropName, nFlag);
		var sIVViewId = oSrcElement.getAttribute("trs_item_id", 2);
		oWCMObj.setProperty("IVViewId", sIVViewId);
		var sXMLString = WCMObjHelper.toXMLString(oWCMObj, "WCMObj");
		_XMLDATA_.submit("./infoview_save_view.jsp?DefaultView="+nFlag+"&IVViewId=" 
					+ sIVViewId + "&ObjectXML=" + sXMLString, null,
			function(_transport){
				var sIds = _transport.responseText;
				_MULTIVIEW_.UpdateNavigator(sIds, {trs_item_default_view:0});
			});
	},
	GetPublishPermissionFunction : function(_oContextMenu, _sType){
		return function() {
			var oSrcElement = _FlyButtonContainer_.GetSrcElement();
			if(_sType=='infoview-group'){
				var sObjPublish = oSrcElement.getAttribute("trs_obj_publish", 2);
				var nFlag = (sObjPublish == "0")?1:0;
				var oWCMObj = new CWCMObj();
				oWCMObj.setProperty("PublicFill", nFlag);
				var sXMLString = WCMObjHelper.toXMLString(oWCMObj, "WCMObj");
				var sIvGroupId = oSrcElement.getAttribute("trs_obj_id", 2);
				_XMLDATA_.submit("../infoview/infoview_save_group.jsp?IVGroupId="
						+ sIvGroupId + "&ObjectXML=" + sXMLString, null,
					function(_transport){
						if(parent.SettingHelper){
							parent.SettingHelper._EffectPublicFillByView(oSrcElement, nFlag);
						}
					});
			}
			else if(_sType=='infoview-view'){
				PageContext.Extend._SaveView_('trs_item_public_fill', 'PublicFill');
			}
			_oContextMenu.hide();
		}
	},
	GetDefaultViewFunction : function(_oContextMenu){
		return function() {
			PageContext.Extend._SaveView_('trs_item_default_view', 'DefaultView');
			_oContextMenu.hide();
		}
	},
	GetPowerSettingFunction : function(_oContextMenu, _nFieldType, _nPowerType){
		return function() {
			var oSrcElement = _FlyButtonContainer_.GetSrcElement();
			var sTrsTempId = oSrcElement.getAttribute('trs_temp_id', 2);
			var sPowerType = (_nPowerType==1)?'Readable':'Writeable';
			if(PageContext['toggle'+sPowerType]){
				if(_nFieldType==2){
					sTrsTempId = 'InfoViewView_' + oSrcElement.getAttribute('trs_item_id', 2);
				}
				PageContext['toggle'+sPowerType](sTrsTempId, _nFieldType, oSrcElement);
			}
			_oContextMenu.hide();
		}
	},
	GetInitValueSettingFunction : function(_oContextMenu){
		return function() {
			var oSrcElement = _FlyButtonContainer_.GetSrcElement();
			var sDefaultValue = oSrcElement.getAttribute('default_value', 2);
			//FIXME \u6682\u4E0D\u652F\u6301checkbox,radio,multi-select,date\u7B49\u63A7\u4EF6
			oSrcElement.value = sDefaultValue;
			_oContextMenu.hide();
		}
	},
	GetViewMenuFunction : function(_oElement){
		return function(){
			var oNavigatorTab = PageElementHelper.GetViewNavigatorTab(_oElement);
			if(oNavigatorTab!=null){
				var sPostfix = '&nbsp;<span style="font-family:Wingdings 2">P</span>';
				_MenuContainer_.OpenMenu("ViewSettingMenu", oNavigatorTab, {
						readable_setting : {
							display : PageContext.isWorkFlowMode(),
							postfix	: (PageContext.isWorkFlowMode() && 
								PageContext.isReadable("InfoViewView_"+oNavigatorTab.getAttribute('trs_item_id', 2)))
								? sPostfix : ""
						},
						workflow_setting : {
							display : PageContext.isWorkFlowMode(),
							postfix	: null
						},
						publish_permission : {
							display : PageContext.isNormalSettingMode(),
							postfix	: (oNavigatorTab.getAttribute("trs_item_public_fill", 2) == "1") 
								? sPostfix : ""
						},
						set_default_view : {
							display : PageContext.isNormalSettingMode(),
							postfix : (oNavigatorTab.getAttribute("trs_item_default_view", 2) == "1") 
								? sPostfix : ""
						}
					}
				);
			}
		}
	},
	GetRepeatMenuFunction: function(_oElement){
		return function(){
			var sInsert = _oElement.getAttribute("trs_xCollection_insert", 2)||'';
			sInsert = sInsert.replace(/^Insert\s*(.*?)\s*$/ig,'\u5728$1\u5F53\u524D\u884C\u63D2\u5165');
			var sInsertBefore = _oElement.getAttribute("trs_xCollection_insertBefore", 2)||'';
			sInsertBefore = sInsertBefore.replace(/^Insert\s*(.*?)\s*Above$/ig,'\u5728$1\u5F53\u524D\u884C\u524D\u63D2\u5165');
			var sInsertAfter = _oElement.getAttribute("trs_xCollection_insertAfter", 2)||'';
			sInsertAfter = sInsertAfter.replace(/^Insert\s*(.*?)\s*Below$/ig,'\u5728$1\u5F53\u524D\u884C\u540E\u63D2\u5165');
			var sRemove = _oElement.getAttribute("trs_xCollection_remove", 2)||'';
			sRemove = sRemove.replace(/^Remove\s*(.*?)\s*$/ig,'\u5220\u9664$1\u5F53\u524D\u884C');
			_MenuContainer_.OpenMenu("SelectableSectionMenu", _oElement,{
					trs_xCollection_insert : {
						display		: sInsert != '',
						description : sInsert
					},
					trs_xCollection_insertBefore : {
						display		: sInsertBefore != '',
						description : sInsertBefore
					},
					trs_xCollection_insertAfter : {
						display		: sInsertAfter != '',
						description : sInsertAfter
					},
					trs_xCollection_remove : {
						display		: sRemove != '',
						description : sRemove
					}
				});
		}
	},
	GetFileAttachmentMenuFunction : function(_oElement){
		return function() {
			var sUploadedFileName = null;
			var arrInputs = _oElement.getElementsByTagName("input");
			//TODO
			var oXctElement = PageElementHelper.GetMyXctContainer(_oElement);
			var bIsImage = oXctElement.getAttribute('xd:xctname', 2) != 'FileAttachment';
			for(var i=0; i<arrInputs.length; i++) {
				if(arrInputs[i].type == "hidden") {
					var sValue = arrInputs[i].value;
					var regExp = /^\w+.\w+$/g;
					sUploadedFileName = sValue.match(regExp);
					break;
				}
			}
			//sUploadedFileName = '';
			var menuParams = {
				attach : {
					display : true,
					description : (bIsImage)?'\u4E0A\u4F20\u56FE\u7247':'\u4E0A\u4F20\u9644\u4EF6'
				},
				open : {
					display : sUploadedFileName != null,
					description : (bIsImage)?'\u67E5\u770B\u56FE\u7247':'\u6253\u5F00\u9644\u4EF6'
				},
				remove : {
					display : sUploadedFileName != null,
					description : (bIsImage)?'\u79FB\u9664\u56FE\u7247':'\u79FB\u9664\u9644\u4EF6'
				}
			};
			if(!bIsImage) {
				menuParams['attach_more'] = {
					display : sUploadedFileName != null,
					description : '\u589E\u52A0\u9644\u4EF6'
				};
			}
			_MenuContainer_.OpenMenu("FileUploadMenu", _oElement, menuParams);
		}
	}
}
/*************************************************************/
var PageElementHelper = {
	AppendValue : function(_oElement, _oText) {
		if(_oElement == null || _oText == null)
			return;
		_oElement.value += _oText;
	},
	_IsXctContainer : function(oElement){
		if(!oElement || !oElement.tagName || !oElement.getAttribute("xd:xctname", 2))
			return false;
		var sTagName = oElement.tagName;
		var sXctName = oElement.getAttribute("xd:xctname", 2).toLowerCase();
		return (sTagName == "DIV" && sXctName == "repeatingsection")
			|| (sTagName == "TBODY" && sXctName == "repeatingtable")
			|| (sTagName == "SPAN" && sXctName == "fileattachment")
			|| (sTagName == "SPAN" && sXctName == "inlineimage")
			|| (sTagName == "SPAN" && sXctName == "linkedimage");
	},
	_XPath2Name : function(_sXPath){
		if(_sXPath==null)return'';
		var aXPaths = _sXPath.split('/');
		for(var i=0,n=aXPaths.length;i<n;i++){
			aXPaths[i] = aXPaths[i].replace(/^[^:]*?:/,'');
		}
		return aXPaths.join('_');
	},
	_XPath2FieldName : function(_sXPath){
		if(_sXPath==null)return'';
		var aXPaths = _sXPath.split('/');
		for(var i=0,n=aXPaths.length;i<n;i++){
			aXPaths[i] = aXPaths[i].replace(/^[^:]*?:/,'');
		}
		return aXPaths.pop();
	},
	_RebuildSelect : function(_eSelect, _aNewOptions){
		var oldChildNodes = _eSelect.childNodes;
		for (var i = _eSelect.childNodes.length-1; i>=0; i--){
			_eSelect.removeChild(_eSelect.childNodes[i]);
		}
		if(_aNewOptions){
			for (var i = 0; i < _aNewOptions.length; i++){
				var newOption = document.createElement('option');
				newOption.value = _aNewOptions[i]['value'];
				newOption.innerHTML = _aNewOptions[i]['display'] || _aNewOptions[i]['value'];
				_eSelect.appendChild(newOption);
			}
		}
	},
	GetViewNavigatorTab : function(_oElement){
		var elTmp = _oElement;
		while(elTmp){
			if(!elTmp.tagName || elTmp.tagName=='BODY')break;
			if(elTmp.tagName=='SPAN' && elTmp.getAttribute('infoview_navigator_tab', 2))
				return elTmp;
			elTmp = elTmp.parentNode;
		}
		return null;
	},
	$A : function(_sXPath){
		if(PageContext.isMainPage()){
			var arrIframes = document.getElementsByTagName("iframe");
			for(var i=0; i<arrIframes.length; i++) {
				try{
					if(!arrIframes[i].contentWindow.PageElementHelper)continue;
					var arrTmp = arrIframes[i].contentWindow.PageElementHelper.$A(_sXPath);
					if(arrTmp.length>0)return arrTmp;
				}catch(err){
					//Just skip it.
				}
			}
			return [];
		}
		var arrElements = document.getElementsByName(_sXPath);
		if(arrElements&&arrElements.length>0)
			return arrElements;
		var oElement = $(_sXPath);
		if(oElement)
			return [oElement];
		var arrNodes = document.getElementsByTagName('*');
		arrElements = [];
		for(var i=0,n=arrNodes.length;i<n;i++){
			oElement = arrNodes[i];
			if(oElement.tagName && oElement.getAttribute('trs_temp_id', 2)==_sXPath){
				arrElements.push(oElement);
			}
		}
		return arrElements;
	},
	GetMyXctContainer : function(_oElement, _nDeep) {
		var nDeep = _nDeep || 10;
		var oElement = _oElement;
		for(var i=0; oElement&&i<nDeep; i++) {
			if(!oElement.tagName || oElement.tagName=='BODY')break;
			if(PageElementHelper._IsXctContainer(oElement))
				return oElement;
			oElement = oElement.parentNode;
		}
		return null;
	},
	GetElementsByName : function(_oElement, _sName) {
		if(_sName == null || _sName == "")
			return [];
		var arrResult = [];
		if(_oElement == null){
			if(window.parent){//\u591A\u89C6\u56FE
				var arrIframes = window.parent.document.getElementsByTagName("iframe");
				for(var i=0,n=arrIframes.length;i<n;i++){
					try{
						if(!arrIframes[i].contentWindow._XMLDATA_)continue;
						var arrTmp = arrIframes[i].contentWindow.document.getElementsByName(_sName);
						if(arrTmp.length>0)return arrTmp;
					}catch(err){
						//TODO
					}
				}
			}
			return document.getElementsByName(_sName);
		}
		var arrElements = _oElement.getElementsByTagName('*');
		for(var i=0,n=arrElements.length; i<n; i++) {
			if(arrElements[i] == null || arrElements[i].name == null
				|| arrElements[i].name.toLowerCase() != _sName.toLowerCase())
				continue;
			arrResult.push(arrElements[i]);
		}
		return arrResult;
	},
	GetElementType : function(_oElement) {
		if(_oElement == null)
			return 0;
		var nElementType = _oElement.getAttribute("element-type", 2);
		if(nElementType != null)
			return nElementType;
		var sTrsObjType = _oElement.getAttribute("trs_obj_type", 2);
		if(sTrsObjType != null)
			return 6;
		return 0;
	},
	_ValidMe : function(_oElement){
		if(!PageContext.isEditableMode())return;
		//TODO
		if(_oElement.getAttribute("not_null", 2) == 1 && _oElement.value == ""){
			_oElement.style.borderColor = "red";
		}
	},
	_BasicFieldFeature_ : function(_oElement){
		if(!PageContext.isSettingMode())return;
		_FlyButtonContainer_.openButton("SettingButton", _oElement,function(){
				var sPostfix = '&nbsp;<span style="font-family:Wingdings 2">P</span>';
				_MenuContainer_.OpenMenu("ItemSettingMenu", _oElement,{
						readable_setting : {
							display     : PageContext.isWorkFlowMode(),
							postfix	: PageContext.isReadable(_oElement.getAttribute("trs_temp_id", 2), 0, _oElement)?sPostfix:""
						},
						writeable_setting : {
							display     : PageContext.isSettingMode(),
							postfix	: PageContext.isWriteable(_oElement.getAttribute("trs_temp_id", 2), 0, _oElement)?sPostfix:""
						},
						workflow_setting : {
							display     : PageContext.isWorkFlowMode()
						},
						attr_setting : {
							display		: PageContext.isNormalSettingMode()
						}
					});
			}, null, null, true);
		_FlyButtonContainer_.block = true;
	},
	_InputFeature_ : function(_oElement){
		if(!PageContext.isSettingMode())return;
		_FlyButtonContainer_.openButton("SettingButton", _oElement,function(){
				var sPostfix = '&nbsp;<span style="font-family:Wingdings 2">P</span>';
				_MenuContainer_.OpenMenu("ItemSettingMenu", _oElement,{
						append_to_title : {
							display     : PageContext.isNormalSettingMode()
						},
						readable_setting : {
							display     : PageContext.isWorkFlowMode(),
							postfix	: PageContext.isReadable(_oElement.getAttribute("trs_temp_id", 2), 0, _oElement)?sPostfix:""
						},
						writeable_setting : {
							display     : PageContext.isSettingMode(),
							postfix	: PageContext.isWriteable(_oElement.getAttribute("trs_temp_id", 2), 0, _oElement)?sPostfix:""
						},
						initvalue_setting : {
							display     : PageContext.isWorkFlowMode() && !!_oElement.getAttribute("default_value", 2),
							postfix	: "(" + _oElement.getAttribute("default_value", 2) + ")"
						},
						workflow_setting : {
							display     : PageContext.isWorkFlowMode()
						},
						attr_setting : {
							display		: PageContext.isNormalSettingMode()
						}
					});
			}, null, null, true);
		_FlyButtonContainer_.block = true;
	},
	_EffectInput : function(_oElement){
		var sEventType = _oElement.getAttribute("event-type", 2);
		switch(sEventType){
			case 'dblclick' :
				if(PageContext.isSettingMode()){
					if(parent.FieldsInIframe && parent.FieldsInIframe[sEventType]){
						return parent.FieldsInIframe[sEventType](_oElement.id, _oElement);
					}
				}
				break;
			case 'click' : 
				if(PageContext.isSettingMode())return false;
			case 'focus' :
				if(PageContext.isSettingMode()){
					if(parent.FieldsInIframe && parent.FieldsInIframe[sEventType]){
						return parent.FieldsInIframe[sEventType](_oElement.id, _oElement);
					}
				}
				BorderHelper.reserveBorder(_oElement);
				BorderHelper.standOutBorder(_oElement);
				PageElementHelper._InputFeature_(_oElement);
				break;
			case 'mouseover' :
				BorderHelper.reserveBorder(_oElement);
				BorderHelper.standOutBorder(_oElement);
				if(PageContext.isSettingMode())
					PageElementHelper._InputFeature_(_oElement);
				break;
			case 'blur' :
			case 'mouseout' :
				BorderHelper.recoverBorder(_oElement);
				if(PageContext.isSettingMode())
					_FlyButtonContainer_.CloseAll();
				if(sEventType=='blur')
					PageElementHelper._ValidMe(_oElement);
				break;
		}
	},
	_TextAreaFeature_ : function(_oElement){
		if(!PageContext.isSettingMode())return;
		_FlyButtonContainer_.openButton("SettingButton", _oElement,function(){
				var sPostfix = '&nbsp;<span style="font-family:Wingdings 2">P</span>';
				_MenuContainer_.OpenMenu("ItemSettingMenu", _oElement,{
						readable_setting : {
							display     : PageContext.isWorkFlowMode(),
							postfix	: PageContext.isReadable(_oElement.getAttribute("trs_temp_id", 2), 0, _oElement)?sPostfix:""
						},
						writeable_setting : {
							display     : PageContext.isSettingMode(),
							postfix	: PageContext.isWriteable(_oElement.getAttribute("trs_temp_id", 2), 0, _oElement)?sPostfix:""
						},
						initvalue_setting : {
							display     : PageContext.isWorkFlowMode() && !!_oElement.getAttribute("default_value", 2),
							postfix	: "(" + _oElement.getAttribute("default_value", 2) + ")"
						},
						workflow_setting : {
							display     : PageContext.isWorkFlowMode()
						},
						attr_setting : {
							display		: PageContext.isNormalSettingMode()
						}
					});
			}, null, null, true);
		_FlyButtonContainer_.block = true;
	},
	_EffectTextArea : function(_oElement){
		var sEventType = _oElement.getAttribute("event-type", 2);
		switch(sEventType){
			case 'dblclick' :
				if(PageContext.isSettingMode()){
					if(parent.FieldsInIframe && parent.FieldsInIframe[sEventType]){
						return parent.FieldsInIframe[sEventType](_oElement.id, _oElement);
					}
				}
				break;
			case 'click' : 
				if(PageContext.isSettingMode())return false;
			case 'focus' :
				if(PageContext.isSettingMode()){
					if(parent.FieldsInIframe && parent.FieldsInIframe[sEventType]){
						return parent.FieldsInIframe[sEventType](_oElement.id, _oElement);
					}
				}
				BorderHelper.reserveBorder(_oElement);
				BorderHelper.standOutBorder(_oElement);
				if(PageContext.isSettingMode())
					PageElementHelper._TextAreaFeature_(_oElement);
				break;
			case 'mouseover' :
				BorderHelper.reserveBorder(_oElement);
				BorderHelper.standOutBorder(_oElement);
				if(PageContext.isSettingMode())
					PageElementHelper._TextAreaFeature_(_oElement);
				break;
			case 'blur' :
			case 'mouseout' :
				BorderHelper.recoverBorder(_oElement);
				if(PageContext.isSettingMode())
					_FlyButtonContainer_.CloseAll();
				if(sEventType=='blur')
					PageElementHelper._ValidMe(_oElement);
				break;
		}
	},
	_RepeatSectionFeature_ : function(_oElement){
		if(!PageContext.isEditableMode())return;
		_FlyButtonContainer_.openButton("RepeatButton", _oElement, 
			PageContext.Extend.GetRepeatMenuFunction(_oElement));
	},
	_EffectRepeatSection : function(_oElement){
		var sEventType = _oElement.getAttribute("event-type", 2);
		switch(sEventType){
			case 'mouseover' :
				_oElement.style.borderWidth = "1px";
				_oElement.style.borderStyle = "dashed";
				_oElement.style.borderColor = "#404040";
				PageElementHelper._RepeatSectionFeature_(_oElement);
				PageElementHelper._SectionFeature_(_oElement);
				break;
			case 'mouseout' :
				_oElement.style.borderWidth = "0px";
				_FlyButtonContainer_.CloseAll();
				break;
			case 'dblclick' :
			case 'click' :
				if(PageContext.isSettingMode()){
					if(parent.FieldsInIframe && parent.FieldsInIframe[sEventType]){
						return parent.FieldsInIframe[sEventType](_oElement.getAttribute('trs_temp_id', 2), _oElement, true);
					}
				}
				break;
		}
	},
	_SectionFeature_ : function(_oElement){
		PageElementHelper._TrsObjectFeature_(_oElement);
	},
	_EffectSection : function(_oElement){
		if(!PageContext.isSettingMode())return;
		var sEventType = _oElement.getAttribute("event-type", 2);
		switch(sEventType){
			case 'mouseover' :
				_oElement.style.borderColor = "#006633";
				PageElementHelper._SectionFeature_(_oElement);
				break;
			case 'mouseout' :
				_oElement.style.borderColor = "gray";
				_FlyButtonContainer_.CloseAll();
				break;
			case 'dblclick' :
			case 'click' :
				if(PageContext.isSettingMode()){
					if(parent.FieldsInIframe && parent.FieldsInIframe[sEventType]){
						return parent.FieldsInIframe[sEventType](_oElement.getAttribute('trs_temp_id', 2), _oElement, true);
					}
				}
				break;
		}
	},
	_RepeatTableFeature_ : function(_oElement){
		PageElementHelper._RepeatSectionFeature_(_oElement);
	},
	_EffectRepeatTable_TBody : function(_oTBodyNode, _bIsNotice) {
		if(_oTBodyNode == null || _oTBodyNode.tagName != "TBODY")
			return;
		var oThisRow = _oTBodyNode.firstChild;
		if(oThisRow == null || oThisRow.tagName != "TR")
			return;
		var sBorderStyle = (_bIsNotice)?"1px dotted #404040":"1px solid #dcdcdc";
		for(var i=0; i<oThisRow.cells.length; i++) {
			var oCell = oThisRow.cells[i];
			oCell.style.border = sBorderStyle;
			if(i!=0)
				oCell.style.borderLeft = 0;
		}
		//\u53EA\u6709\u6807\u51FA\u4E0A\u4E00\u4E2ATBODY\u7684\u5E95\u8FB9\u624D\u80FD\u663E\u793A\u6210\u672CTBODY\u7684\u9876\u8FB9\u6548\u679C
		var oPreTBody = _oTBodyNode.previousSibling;
		if(oPreTBody == null || oPreTBody.tagName != "TBODY")
			return;
		var oPreRow = oPreTBody.firstChild;
		if(oPreRow == null || oPreRow.tagName != "TR")
			return;
		for(var i=0; i<oPreRow.cells.length; i++) {
			var oCell = oPreRow.cells[i];
			oCell.style.borderBottom = sBorderStyle;
		}
	},
	_EffectRepeatTable : function(_oElement){
		var sEventType = _oElement.getAttribute("event-type", 2);
		switch(sEventType){
			case 'mouseover' :
				PageElementHelper._EffectRepeatTable_TBody(_oElement, true);
				PageElementHelper._RepeatTableFeature_(_oElement);
				PageElementHelper._SectionFeature_(_oElement);
				break;
			case 'mouseout' :
				PageElementHelper._EffectRepeatTable_TBody(_oElement, false);
				_FlyButtonContainer_.CloseAll();
				break;
			case 'dblclick' :
			case 'click' :
				if(PageContext.isSettingMode()){
					if(parent.FieldsInIframe && parent.FieldsInIframe[sEventType]){
						return parent.FieldsInIframe[sEventType](_oElement.getAttribute('trs_temp_id', 2), _oElement, true);
					}
				}
				break;
		}
	},
	_FileAttachmentFeature_ : function(_oElement){
		if(!PageContext.isEditableMode())return;
		_FlyButtonContainer_.openButton("FileButton", _oElement, 
			PageContext.Extend.GetFileAttachmentMenuFunction(_oElement));
	},
	_EffectFileAttachment : function(_oElement){
		var sEventType = _oElement.getAttribute("event-type", 2);
		switch(sEventType){
			case 'dblclick' :
			case 'click' :
				if(PageContext.isSettingMode()){
					if(parent.FieldsInIframe && parent.FieldsInIframe[sEventType]){
						return parent.FieldsInIframe[sEventType](_oElement.id, _oElement);
					}
				}
				else if(PageContext.isAddEditMode() || PageContext.isShowMode()){
					var sXctName = _oElement.getAttribute("xd:xctname", 2);
					var arrInputs = _oElement.getElementsByTagName("input");
					var sFileName = null;
					for(var i=0; i<arrInputs.length; i++) {
						if(arrInputs[i].type == "hidden") {
							sFileName = arrInputs[i].value;
							break;
						}
					}
					if(sEventType=='click'){
						if(sFileName!=null && sFileName!=''){
							window.open(InfoViewConstants.ReadFileURLPath + sFileName);
							return;
						}
						if(PageContext.isShowMode())return;
						var bReadOnly = _oElement.getAttribute("trs_readonly_field", 2)=='1';
						if(bReadOnly)return;
						var oProps = {
							AllowExt : _oElement.getAttribute('allow_ext', 2),
							InlineImg: (_oElement.getAttribute('trs_file_upload_type', 2) == 'InlineImage')
						};
						if(InfoViewConstants.FileUploadDowithURL != null) {
							oProps['DowithUrl'] = InfoViewConstants.FileUploadDowithURL;
						}
						if(parent != self && parent.window.TRSDialogContainer 
								&& parent.window.TRSDialogContainer.DialogsMap['FileUploadDialog']){
							parent.window.TRSDialogContainer.DialogsMap['FileUploadDialog'].srcElement = _oElement;
							var positions = Position.getAbsolutePositionInTop(_oElement);
							var offsetX = document.body.scrollLeft;
							var offsetY = document.body.scrollTop;
							parent.window.TRSDialogContainer.display("FileUploadDialog", oProps, positions[0] + 20 - offsetX, positions[1] + 20 - offsetY);
//							parent.window.TRSDialogContainer.display("FileUploadDialog", oProps, positions[0]+20, positions[1]+20);
						}else{
							TRSDialogContainer.DialogsMap['FileUploadDialog'].srcElement = _oElement;
							TRSDialogContainer.display("FileUploadDialog", oProps);
						}
					}
				}
				break;
			case 'mouseover' :
				var bReadOnly = _oElement.getAttribute("trs_readonly_field", 2)=='1';
				if(!PageContext.isSettingMode() && bReadOnly)return;
				_oElement.style.borderStyle = "dashed";
				_oElement.style.borderColor = "silver";
				_oElement.style.visibility = 'visible';
				PageElementHelper._FileAttachmentFeature_(_oElement);
				PageElementHelper._BasicFieldFeature_(_oElement);
				break;
			case 'mouseout' :
				var bReadOnly = _oElement.getAttribute("trs_readonly_field", 2)=='1';
				if(!PageContext.isSettingMode() && bReadOnly)return;
				_oElement.style.borderStyle = "solid";
				_oElement.style.borderColor = "#dcdcdc";
				_oElement.style.visibility = 'visible';
				_FlyButtonContainer_.CloseAll();
				break;
		}
	},
	_TrsObjectFeature_ : function(_oElement){
		if(!PageContext.isSettingMode())return;
		_FlyButtonContainer_.openButton("SettingButton", _oElement, function() {
			var sPostfix = '';
			if((PageContext.isNormalSettingMode() && _oElement.getAttribute("trs_obj_publish", 2) == "1")
				|| (PageContext.isWorkFlowMode() && 
					PageContext.isReadable(_oElement.getAttribute("trs_temp_id", 2))) ){
				sPostfix = '&nbsp;<span style="font-family:Wingdings 2">P</span>';
			}
			_MenuContainer_.OpenMenu("AreaSettingMenu", _oElement,{
					readable_setting : {
						display : PageContext.isWorkFlowMode(),
						postfix	: sPostfix
					},
					workflow_setting : {
						display : PageContext.isWorkFlowMode()
					},
					publish_permission : {
						display : PageContext.isNormalSettingMode(),
						postfix	: sPostfix
					}
				});
		}, null, null, true);
	},
	_EffectTrsObject : function(_oElement){
		var sEventType = _oElement.getAttribute("event-type", 2);
		switch(sEventType){
			case 'mouseover' :
				_oElement.style.backgroundColor = "#C5CBDC";
				_oElement.style.borderWidth = "0px";
				_oElement.style.borderStyle = "dashed";
				_oElement.style.borderColor = "#404040";
				PageElementHelper._TrsObjectFeature_(_oElement);
				break;
			case 'mouseout' :
				_oElement.style.backgroundColor = "#FFFFFF";
				_oElement.style.borderWidth = "0px";
				_FlyButtonContainer_.CloseAll();
				break;
			case 'dblclick' :
			case 'click' :
				if(PageContext.isSettingMode()){
					if(parent.FieldsInIframe && parent.FieldsInIframe[sEventType]){
						return parent.FieldsInIframe[sEventType](_oElement.getAttribute('trs_temp_id', 2), _oElement, true);
					}
				}
				break;
		}
	},
	_EffectRichText : function(_oElement){
		var sEventType = _oElement.getAttribute("event-type", 2);
		switch(sEventType){
			case 'mouseover' :
				if(!PageContext.isSettingMode()){
					_oElement.style.backgroundColor = "#c5cbdc";
				}
				BorderHelper.reserveBorder(_oElement);
				BorderHelper.standOutBorder(_oElement);
				PageElementHelper._BasicFieldFeature_(_oElement);
				break;
			case 'mouseout' :
				if(!PageContext.isSettingMode()){
					_oElement.style.backgroundColor = "";
				}
				BorderHelper.recoverBorder(_oElement);
				_FlyButtonContainer_.CloseAll();
				break;
			case 'dblclick':
				if(PageContext.isSettingMode()){
					if(parent.FieldsInIframe && parent.FieldsInIframe[sEventType]){
						return parent.FieldsInIframe[sEventType](_oElement.id, _oElement);
					}
				}
				break;
			case 'click':
				if(PageContext.isSettingMode()){
					if(parent.FieldsInIframe && parent.FieldsInIframe[sEventType]){
						return parent.FieldsInIframe[sEventType](_oElement.id, _oElement);
					}
				}
				var oRichText = {
					element : _oElement,
					html    : _oElement.innerHTML
				}
				if(parent.window && parent.window.TRSDialogContainer 
					&& parent.window.TRSDialogContainer.DialogsMap['Trs_Simple_Editor']){
					TRSCrashBoard.setMaskable(false);
					parent.window.TRSDialogContainer.display("Trs_Simple_Editor", oRichText);
					TRSCrashBoard.setMaskable(true);
				}
				else{
					TRSCrashBoard.setMaskable(false);
					TRSDialogContainer.display("Trs_Simple_Editor", oRichText);
					TRSCrashBoard.setMaskable(true);
				}
				/*
				var oTRSAction = new CTRSAction(InfoViewConstants.RichTextEditorURL);
				if(InfoViewConstants.ResourceBase != ".") {
					CTRSAction_setRootPath(InfoViewConstants.ResourceBase);
				}
				var oResult = oTRSAction.doNoScrollDialogAction(700, 500, oRichText);
				if(!oResult || !oResult.element || oResult.html == null)
					return;
				oRichText.element.innerHTML = oResult.html;
				*/
				break;
		}
	},
	_BasicEffectInSetting : function(_oElement){
		var sEventType = _oElement.getAttribute("event-type", 2);
		switch(sEventType){
			case 'dblclick':
			case 'focus':
				if(PageContext.isSettingMode()){
					if(parent.FieldsInIframe && parent.FieldsInIframe[sEventType]){
						parent.FieldsInIframe[sEventType](_oElement.id, _oElement);
					}
				}
				return false;
		}
	},
	_EffectSelect : function(_oElement){
		PageElementHelper._BasicEffectInSetting(_oElement);
	},
	_EffectCheckBox : function(_oElement){
		PageElementHelper._BasicEffectInSetting(_oElement);
	},
	_EffectOptionButton : function(_oElement){
		PageElementHelper._BasicEffectInSetting(_oElement);
	},
	_EffectDTPicker_DTText : function(_oElement){
		PageElementHelper._EffectInput(_oElement);
		/*
		var sEventType = _oElement.getAttribute("event-type", 2);
		var oInput = _oElement.getElementsByTagName("input")[0];
		if(!oInput)return;
		switch(sEventType){
			case 'mouseover' :
			case 'mouseout' :
					oInput.style.border = (sEventType=='mouseover')?"1px solid #404040":"1px solid #dcdcdc";
				break;
			case 'dblclick':
			case 'click':
				if(PageContext.isSettingMode()){
					if(parent.FieldsInIframe && parent.FieldsInIframe[sEventType]){
						parent.FieldsInIframe[sEventType](oInput.id, oInput);
					}
				}
				break;
		}
		*/
	},
	_ViewNavTabFeature : function(_oElement){
		if(!PageContext.isSettingMode())return;
		_FlyButtonContainer_.openButton("ViewSettingButton", _oElement,
			PageContext.Extend.GetViewMenuFunction(_oElement), null, null, true);
		_FlyButtonContainer_.block = true;
	},
	_EffectViewNavTab : function(_oElement){
		if(!PageContext.isSettingMode())return;
		var sEventType = _oElement.getAttribute("event-type", 2);
		switch(sEventType){
			case 'mouseover' :
				PageElementHelper._ViewNavTabFeature(_oElement);
				break;
			case 'mouseout' :
				_FlyButtonContainer_.CloseAll();
				break;
			case 'click':
				break;
		}
	},
	EffectMe : function(_oElement) {
		var nElementType = PageElementHelper.GetElementType(_oElement);
		var bRetVal = true;
		switch(parseInt(nElementType,10)) {
			case  1  ://Input
				bRetVal = PageElementHelper._EffectInput(_oElement);
				break;
			case  2  ://TextArea
				bRetVal = PageElementHelper._EffectTextArea(_oElement);
				break;
			case  3  ://Repeat Section
				bRetVal = PageElementHelper._EffectRepeatSection(_oElement);
				break;
			case  4  ://Repeat Table
				bRetVal = PageElementHelper._EffectRepeatTable(_oElement);
				break;
			case  5  ://File AttachMent or InlineImage or LinkedImage
				bRetVal = PageElementHelper._EffectFileAttachment(_oElement);
				break;
			case  6  ://Trs Object
				bRetVal = PageElementHelper._EffectTrsObject(_oElement);
				break;
			case  7  ://RichText
				bRetVal = PageElementHelper._EffectRichText(_oElement);
				break;
			case  8  ://Select
				bRetVal = PageElementHelper._EffectSelect(_oElement);
				break;
			case  9  ://CheckBox
				bRetVal = PageElementHelper._EffectCheckBox(_oElement);
				break;
			case  10  ://OptionButton
				bRetVal = PageElementHelper._EffectOptionButton(_oElement);
				break;
			case  11  ://DTPicker_DTText
				bRetVal = PageElementHelper._EffectDTPicker_DTText(_oElement);
				break;
			case  12  ://ViewNavTab
				bRetVal = PageElementHelper._EffectViewNavTab(_oElement);
				break;
			case  13  ://Section
				bRetVal = PageElementHelper._EffectSection(_oElement);
				break;
			default :
		}
		return bRetVal;
	},
	EventObserveMe : function(_oElement, _arrExtraEvent) {
		if(_oElement == null)
			return;
		var sDataType = _oElement.getAttribute("trs_obj_typename", 2);
		if(sDataType == 'DataSection') {
			//Section
			//TODO
		}
		_oElement.lastEvents = {};
		var aEventTypes = ['mouseout', 'mouseover', 'focus', 'blur', 'dblclick', 'click'];
		for(var i=0;i<aEventTypes.length;i++){
			_oElement.lastEvents[aEventTypes[i]] = _oElement['on'+aEventTypes[i]];
		}
		_oElement.onmouseout = _oElement.onmouseover = 
				_oElement.onfocus = _oElement.onblur = 
		function(event) {
			event = event || window.event;
			if(event.type=='mouseover'){
				this.style.width = this.offsetWidth;
			}
			this.setAttribute("event-type", event.type);
			var retVal = PageElementHelper.EffectMe(this);
			if(_oElement.lastEvents[event.type]){
				_oElement.lastEvents[event.type].apply(this, arguments);
			}
			if(retVal===false)
				Event.stop(event);
			return retVal;
		}
		if(PageContext.isSettingMode()){
			_oElement.ondblclick = _oElement.onclick = _oElement.onmouseout;
		}
		for(var i=0;_arrExtraEvent&&i<_arrExtraEvent.length;i++){
			_oElement[_arrExtraEvent[i]] = _oElement.onmouseout;
		}
	},
	CloneEventObserving : function(_oFromNode, _oToNode) {
		if(!_oFromNode || !_oFromNode.tagName || !_oToNode)
			return;
		var arrAttributes = _oFromNode.attributes;
		for(var i=0,n=arrAttributes.length; i<n; i++) {
			var oAttribute = arrAttributes[i];
			var sAttrName = oAttribute.name;
			if(oAttribute.specified || !sAttrName.startsWith('on')
				|| !_oFromNode.getAttribute(sAttrName, 2)
				|| _oToNode.getAttribute(sAttrName, 2))
				continue;
			_oToNode.setAttribute(sAttrName, _oFromNode.getAttribute(sAttrName, 2));
		}
		//\u9012\u5F52\u590D\u5236\u5B50\u7684\u4E8B\u4EF6\u76D1\u542C
		var arrFromNodes = _oFromNode.childNodes;
		var arrToNodes = _oToNode.childNodes;
		for(var i=0,n=arrFromNodes.length; i<n; i++) {
			arguments.callee(arrFromNodes[i], arrToNodes[i]);
		}
	},
	GetDefaultValue : function(_oNode){
		if(PageContext.isWorkFlowMode()){
			var sTrsTempId = _oNode.getAttribute('trs_temp_id', 2);
			var sValue = PageContext.getInitValue(sTrsTempId);
			if(sValue!=null && sValue!=''){
				return sValue;
			}
		}
		var sDefault = _oNode.getAttribute('default_value', 2);
		if(sDefault!=null && sDefault!=''){
			var reVarName = /^\$\$(.*)\$\$$/;
			//ge gfc@2008-5-1 10:21 add the try..catch modual
			try{
				if(PageContext.isAddEditMode() && parent.window.com.trs.wcm.infoview.InitorValues){
					var arr = null;
					if(arr = reVarName.exec(sDefault)){
						var sVarValue = parent.window.com.trs.wcm.infoview.InitorValues[arr[1]];
						if(sVarValue!=null)
							return sVarValue;
					}
				}
				else if(!PageContext.isSettingMode() && reVarName.test(sDefault)){
					return '';
				}
			}catch(err){
				//just skip it
			}
		}
		return sDefault==null ? '' : sDefault;
	}
}


//Implement ExpressionBox
var _XExpression_ = com.trs.wcm.infoview.XExpression = {
	parseExpression : function(_oElement) {
		var result = {
			expression : null,
			names      : []
		};
		if(_oElement == null)
			return result;
		var sExpression = _oElement.getAttribute("trs_calc_expression");
		var sBaseURL = _oElement.name;
		if(sExpression == null)
			return result;
		var oContainer = PageElementHelper.GetMyXctContainer(_oElement);
		var sContainerName = oContainer == null ? "" : oContainer.name;
		result.expression = sExpression.replace(/xdMath:Nz\(([^()]+)\)/g, "xdMath.Nz('$1','" + sBaseURL + "','" + sContainerName + "')");
		var src = sExpression;
		var regExp = /xdMath:Nz\(([^()]+)\)/g;
		var array = null;
		while ((array = regExp.exec(src)) != null) {
			if(array[1] == null)
				continue;
			result.names.push(_XExpression_.calculateXPath(sBaseURL, array[1]));
		}
		return result;
	},
	doExpression : function(_oElement, _bReplaceEvent) {
		if(_oElement ==  null)
			return;
		if(	(_oElement.getAttribute("xd:xctname") != null && 
				_oElement.getAttribute("xd:xctname").toLowerCase() == "expressionbox")
			|| (_oElement.getAttribute("xd:disableEditing") == "yes")) {
			_oElement.contentEditable = false;
		}
		var oContainer = PageElementHelper.GetMyXctContainer(_oElement);
		var oExpression = _XExpression_.parseExpression(_oElement);
		if(oExpression.expression == null || oExpression.names.length == 0)
			return;
		var fEvent = function(_element) {
			try {
				_oElement.value = eval(oExpression.expression);
				_oElement.onchange();
			} catch(e){
			};
		}
		if(!_bReplaceEvent)
			fEvent();
		//\u4E3A\u8868\u8FBE\u5F0F\u4F9D\u8D56\u7684\u63A7\u4EF6\u6CE8\u518Conchange\u65B9\u6CD5\uFF0C\u4EE5\u9A71\u52A8\u672C\u63A7\u4EF6\u7684\u66F4\u65B0
		if(_oElement.getAttribute("trs_calc_refresh") == null ||
				_oElement.getAttribute("trs_calc_refresh").toLowerCase() != "oninit") {
			for(var i=0; i<oExpression.names.length; i++) {
				var oElements = PageElementHelper.GetElementsByName(oContainer, oExpression.names[i]);
				if(oElements.length == 0) {
					if(oExpression.names[i].indexOf("/") > 0)
						continue;
					//?
					oElements = PageElementHelper.GetElementsByName(oContainer, oExpression.names[i]);
					if(oElements.length == 0)
						continue;
				}
				for(var j=0; j<oElements.length; j++) {
					if(_bReplaceEvent)
						oElements[j].onchange = fEvent;
					else{
						var fOnChange = oElements[j].onchange;
						oElements[j].onchange = function() {
							if(fOnChange)fOnChange();
							fEvent();
						}
					}
				}
			}
		}
	},
	setExpression : function(_oContainer) {
		if(_oContainer == null)
			return;
		var arrNodes = _oContainer.getElementsByTagName('*');
		for(var i=0; i<arrNodes.length; i++) {
			if(!arrNodes[i] || !arrNodes[i].tagName)
				continue;
			var sExpression = arrNodes[i].getAttribute("trs_calc_expression", 2);
			if(sExpression == null || sExpression == "")
				continue;
			_XExpression_.doExpression(arrNodes[i], true);
		}
	},
	calculateXPath : function(_sAbsoluteXPath, _sRelativeXPath) {
		if(_sRelativeXPath == null || _sRelativeXPath == "")
			return null;
		if(_sAbsoluteXPath == null || _sAbsoluteXPath == "")
			return _sRelativeXPath;
		if(_sRelativeXPath.indexOf(".") == -1)
			return _sRelativeXPath; 
		var arrRelative = _sRelativeXPath.split("/");
		var resRelative = [];
		var nIgnoreNum = 0;
		for(var i=0; i<arrRelative.length; i++) {
			if(arrRelative[i] == null || arrRelative[i] == "" || arrRelative[i] == ".")
				continue;
			//\u9004..\u82E5\u76F8\u5BF9\u8DEF\u5F84\u4E2D\u6709\u503C\u5C06\u76F8\u5BF9\u8DEF\u5F84\u79FB\u9664\u6700\u540E\u4E00\u4E2A\uFF0C\u5426\u5219\u5FFD\u7565\u7EDD\u5BF9\u8DEF\u5F84\u7684\u6700\u540E\u4E00\u4E2A
			if(arrRelative[i] == ".."){
				if(resRelative.length==0)
					nIgnoreNum ++;
				else
					resRelative.pop();
			}
			else
				resRelative.push(arrRelative[i]);
		}
		var arrAbsolute = _sAbsoluteXPath.split("/");
		var sResultXPath = '';
		for(var i=0; i<arrAbsolute.length-nIgnoreNum; i++) {
			sResultXPath += arrAbsolute[i] + "/";
		}
		sResultXPath += resRelative.join('/');
		return sResultXPath;
	}
};
//InfoPath\u5BF9\u5E94\u7684xdMath.Nz\u65B9\u6CD5
var xdMath = {
	Nz : function(_sName, _sBaseURL, _sContainerName) {
		if(_sName == null || _sName == "")
			return "";
		var oEvent = Event.findEvent();
		var oContainer = PageElementHelper.GetMyXctContainer((oEvent)?oEvent.srcElement:null);
		if(oContainer == null || _sContainerName == "" || oContainer.name != _sContainerName)
			oContainer = null;
		var sName = _XExpression_.calculateXPath(_sBaseURL, _sName);
		var arrElements = PageElementHelper.GetElementsByName(oContainer, sName);
		if(arrElements.length == 0)
			return "";
		if(arrElements.length == 1)
			return isNaN(arrElements[0].value)?arrElements[0].value:parseInt(arrElements[0].value,10);
		var arrValues = new Array();
		for(var i=0; i<arrElements.length; i++)
			arrValues.push(isNaN(arrElements[i].value)?arrElements[i].value:parseInt(arrElements[i].value,10));
		return arrValues;
	}
}

/*****************************************************************************/
var _HASHMAP_ = com.trs.wcm.infoview.HashMap = Class.create('wcm.infoview.HashMap');
_HASHMAP_.prototype = {
	initialize : function(){
		this.m_arrKeys = [];
		this.m_arrValues = {};
	},
	get : function(_sKey) {
		if(_sKey == null)
			return null;
		return this.m_arrValues[_sKey];
	},
	put : function(_sKey, _oValue) {
		if(_sKey == null || _oValue == null)
			return null;
		var oPreviousValue = this.get(_sKey);
		if(oPreviousValue == null)
			this.m_arrKeys.push(_sKey);
		this.m_arrValues[_sKey] = _oValue;
		return oPreviousValue;
	},
	keyArray : function() {
		return this.m_arrKeys;
	}
};
/*****************************************************************************/
var _TransRule_ = com.trs.wcm.infoview.TransRule = {
	TransName : 'xd:xctname',
	Rules : new _HASHMAP_(),
	save : function(_sTagName, _sTransName, _fMethod) {
		if(_sTagName == null || _sTransName == null || _fMethod == null)
			return false;
		var sTagName = _sTagName.toLowerCase();
		var sTransName = _sTransName.toLowerCase();
		var nmMap = _TransRule_.Rules.get(sTagName);
		if(nmMap == null || nmMap instanceof Function) {
			nmMap = new _HASHMAP_();
			_TransRule_.Rules.put(sTagName, nmMap);
		}
		nmMap.put(sTransName, _fMethod);
		return true;
	},
	doTrans : function(_eleNode, _otherProp) {
		if(_eleNode == null)
			return false;
		var sTagName = _eleNode.tagName;
		if(sTagName == null)
			return false;
		var sTransName = null;
		sTransName = _eleNode.getAttribute(_TransRule_.TransName, 2);
		if(sTransName == null)
			return false;
		sTransName = sTransName.toLowerCase();
		var nmMap = _TransRule_.Rules.get(sTagName.toLowerCase());
		if(nmMap == null || (nmMap instanceof Function))
			return false;
		var arrKeys = nmMap.keyArray();
		for(var i=0; i<arrKeys.length; i++) {
			if(arrKeys[i] != sTransName)
				continue;
			var fMethod = nmMap.get(arrKeys[i]);
			if(fMethod == null)
				return false;
			fMethod(_eleNode, _otherProp);
			break;
		}
		return true;
	},
	_EffectWorkFlowPowerSetting : function(_eleNode){
		this._EffectPowerSetting(_eleNode);
	},
	_EffectPowerSetting : function(_eleNode){
		if(!PageContext.isSettingMode()&&!PageContext.isPreviewMode())return;
		if(PageContext.isWorkFlowMode()){
			var sTrsTempId = _eleNode.getAttribute('trs_temp_id', 2);
			if(!sTrsTempId)return;
			if(!PageContext.isReadable(sTrsTempId)){
				_eleNode.style.backgroundColor = '#FFECEC';
			}
			else if(!PageContext.isWriteable(sTrsTempId)){
				_eleNode.style.backgroundColor = '#e7f1f7';
			}
			else{
				_eleNode.style.backgroundColor = '';
			}
		}
		else{
			if(_eleNode.getAttribute('trs_obj_publish', 2)=='0'){
				_eleNode.style.backgroundColor = '#FFECEC';
			}
			else if(_eleNode.getAttribute('trs_readonly_field', 2)=='1'){
				_eleNode.style.backgroundColor = '#e7f1f7';
			}
			else{
				_eleNode.style.backgroundColor = '';
			}
		}
	},
	_ValidRule : function(_eleNode){
		if(!PageContext.isEditableMode() 
			|| !_eleNode.getAttribute('validation', 2)
			|| _eleNode.getAttribute('trs_readonly_field', 2)=='1')return;
		if(parent.window&&parent.window.ValidationHelper){
			_eleNode.setAttribute('desc', _eleNode.title);
			_eleNode.removeAttribute('title');
			_eleNode.setAttribute('validationId', parent.VALIDATIONID);
			parent.window.ValidationHelper.pushElements(_eleNode);
		}
		else if(window.ValidationHelper){
			_eleNode.setAttribute('desc', _eleNode.title);
			_eleNode.removeAttribute('title');
			_eleNode.setAttribute('validationId', window.VALIDATIONID);
			ValidationHelper.pushElements(_eleNode);
		}
	},
	copyAttributes : function(_oSrcElement, _oTgtElement) {
		var attributes = _oSrcElement.attributes;
		for(var i=0; i<attributes.length; i++) {
			if(!attributes[i].specified)
				continue;
			if(attributes[i].name == "style")
				continue;
			_oTgtElement.setAttribute(attributes[i].name, attributes[i].value);
		}
	},
	_MustDoSpan : function(_oDocument){
		//\u521B\u5EFA\u4E00\u4E2A\u7EA2\u661F\u8868\u793A\u5FC5\u586B\u9879
		var oMustSpan = (_oDocument||document).createElement("SPAN");
		oMustSpan.style.color = 'red';
		oMustSpan.style.fontWeight = 'bold';
		oMustSpan.style.width = '8px';
		oMustSpan.style.paddingLeft = 4;
		oMustSpan.style.position = 'absolute';
		oMustSpan.innerHTML = '*';
		return oMustSpan;
	},
	NotifyMustFill : function(_oNode, _oStyle, _bOuterWindow){
		var oDocument = (_bOuterWindow)?DomTools.GetElementDocument(_oNode):document;
		var oWindow = (_bOuterWindow)?DomTools.GetDocumentWindow(oDocument):window;
		var sSpanId = _oNode.getAttribute('trs_obj_id', 2) + "_mustfill";
		if(_oNode.getAttribute("not_null", 2) == "1"){
			if(oWindow.$(sSpanId)){
				oWindow.Element.show(sSpanId);
				return;
			}
			var oSpan = _TransRule_._MustDoSpan(oDocument);
			oSpan.id = sSpanId;
			oDocument.body.appendChild(oSpan);
			if(oWindow.frameElement && !Element.visible(oWindow.frameElement)){
				//Position clone\u65B9\u6CD5\u9700\u8981\u5728iframe\u5C55\u73B0\u65F6\u624D\u80FD\u8BA1\u7B97\u6B63\u786E
				Element.show(oWindow.frameElement);
				Position.clone(_oNode, oSpan, {
					setWidth : false,
					setHeight : false,
					offsetLeft : _oNode.offsetWidth,
					offsetTop : 5
				});
				Element.hide(oWindow.frameElement);
			}
			else{
				Position.clone(_oNode, oSpan, {
					setWidth : false,
					setHeight : false,
					offsetLeft : _oNode.offsetWidth,
					offsetTop : 5
				});
			}
			if(_oStyle){
				for(var name in _oStyle){
					oSpan.style[name] = _oStyle[name];
				}
			}
		}
		else if(oWindow.$(sSpanId)){
			oWindow.Element.hide(sSpanId);
		}
	},
	_GetInfoPathProp : function (_oNode) {
		if(_oNode == null)
			return null;
		var resProp = "";
		var PROPS = ["xd:innerCtrl", "xd:datafmt", "xd:boundProp", "xd:binding", "xd:xctname"];
		for(var i=0; i<PROPS.length; i++) {
			var sValue = _oNode.getAttribute(PROPS[i], 2);
			if(sValue == null)
				continue;
			resProp += PROPS[i] + '="' + sValue + '" ';
		}
		return resProp;
	}
};
_TransRule_.save("span", "PlainText", function(_oSpanNode, _bReadOnly) {
	var nHeight = 0;
	//\u6839\u636E\u9AD8\u5EA6\u6765\u533A\u5206\u751F\u6210textarea\u8FD8\u662Finput
	nHeight = parseInt(_oSpanNode.style.height, 10);
	if(isNaN(nHeight))
		nHeight = 0;
	var isTextArea = (nHeight > 30);
	var oInputNode = null;
	if(isTextArea) {
		oInputNode = document.createElement("textarea");
		oInputNode.style.whiteSpace = "normal";
		oInputNode.style.overflow = "auto";
	} else {
		oInputNode = document.createElement("input");
	}
	_TransRule_.copyAttributes(_oSpanNode, oInputNode);
	oInputNode.className = _oSpanNode.className;
	oInputNode.style.width = _oSpanNode.style.width;
	if(isTextArea) {
		oInputNode.style.height = _oSpanNode.style.height;
		oInputNode.setAttribute("element-type", "2");
	} else if(_oSpanNode.clientHeight < 16) {
		oInputNode.style.height = 16;
		oInputNode.setAttribute("element-type", "1");
	} else {
		oInputNode.style.height = _oSpanNode.clientHeight + 2;
		oInputNode.setAttribute("element-type", "1");
	}
	oInputNode.value = _oSpanNode.innerHTML.trim();
	BorderHelper.copyStyles(_oSpanNode, oInputNode, true);
	_oSpanNode.parentNode.replaceChild(oInputNode, _oSpanNode);
//	if(_oSpanNode.getAttribute("not_null", 2) == "1") {
//		oInputNode.style.borderColor = "red";
//		oInputNode.parentNode.insertBefore(_TransRule_._MustDoSpan(),_oSpanNode.nextSibling);
//	}
	if(!_bReadOnly||PageContext.isSettingMode()) {
		_TransRule_.NotifyMustFill(oInputNode, {marginLeft:'-15px'});
		PageElementHelper.EventObserveMe(oInputNode);
	}else{
		oInputNode.setAttribute("readOnly", true);
		oInputNode.setAttribute("contentEditable", false);
		oInputNode.style.cursor = "pointer";
	}
	_TransRule_._ValidRule(oInputNode);
	_TransRule_._EffectPowerSetting(oInputNode);
	try{
		oInputNode.value = PageElementHelper.GetDefaultValue(oInputNode);
	}catch(err){
		//Just Skip it.
//		alert(err.message);
	}
	_XExpression_.doExpression(oInputNode);
});
_TransRule_.save("span", "RichText", function(_oSpanNode, _bReadOnly) {
	_oSpanNode.style.overflow = "auto";
	_oSpanNode.setAttribute("element-type", "7");
	_oSpanNode.innerHTML = PageElementHelper.GetDefaultValue(_oSpanNode);
	if(!_bReadOnly || PageContext.isSettingMode()){
		PageElementHelper.EventObserveMe(_oSpanNode,!_bReadOnly&&PageContext.isEditableMode()?['onclick']:null);
		_TransRule_.NotifyMustFill(_oSpanNode, {marginLeft:'-15px'});
		_TransRule_._ValidRule(_oSpanNode);
	}
	_TransRule_._EffectPowerSetting(_oSpanNode);
	if(_bReadOnly)
		return;
	_oSpanNode.style.cursor = "pointer";
	_oSpanNode.title = "\u70B9\u51FB\u7F16\u8F91\u683C\u5F0F\u6587\u672C";
});
var _SelectsMap_ = {};
_TransRule_.save("select", "DropDown", function(_oNode, _bReadOnly) {
	_oNode.setAttribute("element-type", "8");
	var sTrsTmpId = _oNode.getAttribute("trs_temp_id", 2);
	var sFieldName = PageElementHelper._XPath2FieldName(sTrsTmpId);
	_SelectsMap_[sFieldName] = _oNode;
	var hsDymEnum = window.DymEnum || parent.window.DymEnum;
	/*
		hsDymEnum = {
			"\u9886\u517B\u610F\u5411_\u5E74\u9F84" : [
				{"value":"abc"},
				{"value":"bcd"},
				{"value":"efd"},
			]
		};
	*/
	if(hsDymEnum){
		var aEnumValues = hsDymEnum[sFieldName];
		if(aEnumValues && aEnumValues.length>0){
			PageElementHelper._RebuildSelect(_oNode, aEnumValues);
		}
	}
	PageElementHelper.EventObserveMe(_oNode);
	if(_bReadOnly&&!PageContext.isSettingMode()){
		_oNode.disabled = true;
	}
	else{
		_TransRule_.NotifyMustFill(_oNode);
		_TransRule_._ValidRule(_oNode);
		_TransRule_._EffectPowerSetting(_oNode);
	}
	_oNode.value = PageElementHelper.GetDefaultValue(_oNode);
});
_TransRule_.save("select", "ListBox", function(_oNode, _bReadOnly) {
	_oNode.setAttribute("element-type", "8");
	PageElementHelper.EventObserveMe(_oNode);
	if(_bReadOnly&&!PageContext.isSettingMode())
		_oNode.disabled = true;
	else
		_TransRule_.NotifyMustFill(_oNode);
	_TransRule_._ValidRule(_oNode);
	_TransRule_._EffectPowerSetting(_oNode);
	_oNode.value = PageElementHelper.GetDefaultValue(_oNode);
});
_TransRule_.save("input", "CheckBox", function(_oNode, _bReadOnly) {
	_oNode.setAttribute("element-type", "9");
	PageElementHelper.EventObserveMe(_oNode);
	if(_bReadOnly&&!PageContext.isSettingMode())
		_oNode.disabled = true;
	_TransRule_._EffectPowerSetting(_oNode);
});
_TransRule_.save("input", "OptionButton", function(_oNode, _bReadOnly) {
	_oNode.setAttribute("element-type", "10");
	PageElementHelper.EventObserveMe(_oNode);
	if(_bReadOnly&&!PageContext.isSettingMode())
		_oNode.disabled = true;
	_TransRule_._EffectPowerSetting(_oNode);
});
_TransRule_.save("div", "Section", function(_oDivNode) {
	_oDivNode.setAttribute("element-type", "13");
//	_oDivNode.style.height = _oDivNode.clientHeight + 2;
	if(PageContext.isSettingMode() || PageContext.isPreviewMode()){
		_oDivNode.style.border = '1px dotted gray';
		_TransRule_._EffectPowerSetting(_oDivNode);
	}
	if(PageContext.isSettingMode()){
		PageElementHelper.EventObserveMe(_oDivNode);
	}
});
_TransRule_.save("div", "RepeatingSection", function(_oDivNode) {
	_oDivNode.setAttribute("element-type", "3");
//	_oDivNode.style.height = _oDivNode.clientHeight + 2;
	if(PageContext.isSettingMode() || PageContext.isPreviewMode()){
		_oDivNode.style.border = '1px dotted gray';
	}
	PageElementHelper.EventObserveMe(_oDivNode);
	_TransRule_._EffectPowerSetting(_oDivNode);
});
_TransRule_.save("tbody", "RepeatingTable", function(_oNode) {
	_oNode.setAttribute("element-type", "4");
	PageElementHelper.EventObserveMe(_oNode);
	_TransRule_._EffectPowerSetting(_oNode);
});
_TransRule_.save("span", "ListItem_Plain", function(_oSpanNode, _bReadOnly) {
	var oInputNode = document.createElement("input");
	_TransRule_.copyAttributes(_oSpanNode, oInputNode);
	oInputNode.className = _oSpanNode.className;
	oInputNode.style.width = _oSpanNode.style.width;
	oInputNode.style.height = 18;
	oInputNode.value = _oSpanNode.innerHTML.trim();
	oInputNode.style.borderWidth = "0px";
	oInputNode.setAttribute("element-type", "1");
	if(PageContext.isEditableMode()){
		oInputNode.onkeydown = function() {
			PageContext.Extend.KeyDownOnListItem(this);
		};
	}
	if(!_bReadOnly||PageContext.isSettingMode()) {
		PageElementHelper.EventObserveMe(oInputNode);
	} else {
		oInputNode.setAttribute("readOnly", true);
		oInputNode.setAttribute("contentEditable", false);
	}
	_oSpanNode.parentNode.replaceChild(oInputNode, _oSpanNode);
	_TransRule_._EffectPowerSetting(oInputNode);
});
_TransRule_.save("span", "DTPicker_DTText", function(_oNode, _bReadOnly) {
	_bReadOnly = _bReadOnly && !PageContext.isSettingMode();
	var oParentNode = _oNode.parentNode;
	_oNode.setAttribute("element-type", "11");
	var sImgUrl = null;
	var childNodes = oParentNode.getElementsByTagName("img");
	for(var i=0; i<childNodes.length; i++) {
		if(childNodes[i] == null)
			continue;
		sImgUrl = childNodes[i].src;
		break;
	}
	var oTmpDiv = document.createElement('DIV');
	oTmpDiv.style.display = 'none';
	oParentNode.appendChild(oTmpDiv);
	var sInfoPathProp = _TransRule_._GetInfoPathProp(_oNode);
	var sName = _oNode.getAttribute("name", 2) || "default_calendar_name";
	var sDataFormat = _oNode.getAttribute("xd:datafmt", 2);
	var bWithoutTime = (sDataFormat == null || sDataFormat.indexOf("datetime") < 0);
	var sCalendarHTML = null;
	var sDefaultValue = PageElementHelper.GetDefaultValue(_oNode);
	if(bWithoutTime) {
		sCalendarHTML = TRSCalendar.getWithoutTime(sName, 
			sDefaultValue , true, sImgUrl, sInfoPathProp, true, _bReadOnly );
	} else {
		sCalendarHTML = TRSCalendar.getWithTime(sName, 
			sDefaultValue, true, sImgUrl, sInfoPathProp, true, _bReadOnly);
	}
	oTmpDiv.innerHTML = sCalendarHTML;
	var oInputNode = oTmpDiv.getElementsByTagName('INPUT')[0];
	var oImg = oTmpDiv.getElementsByTagName('IMG')[0];
	if(oInputNode){
		_TransRule_.copyAttributes(_oNode, oInputNode);
		oInputNode.style.borderWidth = "0px";
		if(_bReadOnly){
			oInputNode.readOnly = true;
			oInputNode.contentEditable = false;
			oInputNode.onblur = null;
			if(oImg){
				oImg.onclick = oImg.onmouseover = oImg.onmouseout = null;
				if(oImg.parentNode && oImg.parentNode.tagName == 'A'){
					oImg.parentNode.onclick = null;
				}
				if(!PageContext.isSettingMode()){
					oImg.style.filter = 'gray';
				}
			}
		}
		else if(!PageContext.isSettingMode()){
			oInputNode.onpropertychange = function(event){
				event = event || window.event;
				if(event.propertyName == 'value'){
					if(parent.ValidationHelper)
						parent.ValidationHelper.forceValid(this);
					else if(ValidationHelper)
						ValidationHelper.forceValid(this);
				}
			};
		}
		if(PageContext.isSettingMode()){
			if(oImg){
				oImg.onclick = oImg.onmouseover = oImg.onmouseout = null;
				if(oImg.parentNode && oImg.parentNode.tagName == 'A'){
					oImg.parentNode.onclick = null;
				}
			}
			oInputNode.onblur = null;
		}
		_TransRule_._ValidRule(oInputNode);
		_TransRule_._EffectPowerSetting(oInputNode);
		if(!_bReadOnly||PageContext.isSettingMode()) {
			PageElementHelper.EventObserveMe(oInputNode);
		}
	}
	oParentNode.removeChild(oTmpDiv);
	oParentNode.innerHTML = '';
	for(var n=oTmpDiv.childNodes.length-1;n>=0;n--){
		oParentNode.insertBefore(oTmpDiv.childNodes[n], oParentNode.firstChild);
	}
	if(oInputNode && !_bReadOnly){
		_TransRule_.NotifyMustFill(oInputNode, {marginLeft:'-15px'});
	}
});
_TransRule_.save("span", "FileAttachment", function(_oNode, _bReadOnly) {
	_oNode.setAttribute("element-type", "5");
	_oNode.style.paddingLeft = '4px';
	_oNode.style.paddingRight = '4px';
	_oNode.style.paddingTop = '4px';
	_oNode.style.paddingBottom = '4px';
	_oNode.style.cursor = 'pointer';
	var oImage = document.createElement("img");
	oImage.src = InfoViewConstants.ResourceBase + "FileAttachment.gif";
	oImage.style.width = "14px";
	oImage.style.height = "13px";
	oImage.align = 'absmiddle';
	_oNode.appendChild(oImage);
	var oText_body = document.createElement("span");
	oText_body.setAttribute("text_body", "1");
	oText_body.style.position = "relative";
	oText_body.style.paddingLeft = '1px';
	oText_body.innerHTML = "\u70B9\u51FB\u6B64\u5904\u4EE5\u6DFB\u52A0\u9644\u4EF6";
	_oNode.appendChild(oText_body);
	var oText_file = document.createElement("span");
	oText_file.setAttribute("text_file", "1");
	oText_file.style.display = "none";
	oText_file.innerHTML = "";
	_oNode.appendChild(oText_file);
	//\u521B\u5EFA\u9690\u85CF\u57DF\u4EE5\u8BB0\u5F55
	var oInput = document.createElement("input");
	oInput.type = "hidden";
	oInput.setAttribute("name", _oNode.name);
	oInput.setAttribute("xd:binding", _oNode.getAttribute("xd:binding", 2));
	oInput.setAttribute("trs_temp_id", _oNode.getAttribute("trs_temp_id", 2));
	oInput.setAttribute("trs_xctname_flag", "trs_is_inline_file");
	oInput.setAttribute("xd:xctname", "trs_is_inline_file");
	var sValidation = _oNode.getAttribute("validation", 2);
	oInput.setAttribute("validation", sValidation);
	oInput.value = "";
	_oNode.appendChild(oInput);
	//ge gfc modify @ 2008-3-3 \u4FEE\u6539\u6587\u4EF6\u4E0A\u4F20\u663E\u793A\u6837\u5F0F
	_oNode.style.border = "1px solid #dcdcdc";
	//_oNode.style.border = "0px solid #dcdcdc";
	_oNode.style.display = 'block';
	_oNode.style.whiteSpace = 'nowrap';
	_oNode.style.width = '160px';
	_oNode.style.backgroundColor = '#f6f6f6';

	_oNode.style.visibility = 'visible';
	if(sValidation!=null){
		try{
			eval('var ob = {' + sValidation + '}');
			if(ob.extvalid){
				_oNode.setAttribute("allow_ext", ob.extvalid);
			}
		}catch(err){
		}
	}
	PageElementHelper.EventObserveMe(_oNode, ['onclick', 'ondblclick']);
	_TransRule_._EffectPowerSetting(_oNode);
	if(PageContext.isSettingMode() || !_bReadOnly){
		_oNode.setAttribute("trs_context_menu_name", "FileUploadMenu");
		_TransRule_.NotifyMustFill(_oNode, {marginLeft:'-15px', marginTop:'7px'});
		_TransRule_._ValidRule(oInput);
	}
});
var GetImageAttachmentRule = function(_sXctNameFlag){
	return function(_oNode, _bReadOnly) {
		_oNode.setAttribute("element-type", "5");
		var sDefaultValue = PageElementHelper.GetDefaultValue(_oNode);
		var oSpanNode = document.createElement("span");
		_TransRule_.copyAttributes(_oNode, oSpanNode);
		oSpanNode.style.paddingLeft = '4px';
		oSpanNode.style.paddingRight = '4px';
		oSpanNode.style.paddingTop = '4px';
		oSpanNode.style.paddingBottom = '4px';
		oSpanNode.style.cursor = 'pointer';
		var oImage = document.createElement("img");
		oImage.src = InfoViewConstants.ResourceBase + "ImageAttachment.gif";
		oImage.style.width = "17px";
		oImage.style.height = "16px";
		oImage.style.display = (!sDefaultValue)?'':'none';
		oImage.align = 'absmiddle';
		oSpanNode.appendChild(oImage);
		var oText_body = document.createElement("span");
		oText_body.setAttribute("text_body", "1");
		oText_body.innerHTML = '&nbsp;\u70B9\u51FB\u6B64\u5904\u4EE5\u6DFB\u52A0\u56FE\u7247';
		oText_body.style.height = '16px';
		oText_body.style.lineHeight = '16px';
		oText_body.style.display = (!sDefaultValue)?'':'none';
		oSpanNode.appendChild(oText_body);
		var oImageUpload = document.createElement("img");
		oImageUpload.setAttribute("image_body", 1);
		oImageUpload.style.display = (!sDefaultValue) ? 'none' : '';
		if(sDefaultValue != null && sDefaultValue.length > 0){
			oImageUpload.src = InfoViewConstants.ReadFileURLPath + sDefaultValue;
		}
		oImageUpload.style.height = '100%';
		oImageUpload.style.width = '100%';
		oSpanNode.appendChild(oImageUpload);
		var oInput = document.createElement("input");
		oInput.type = "hidden";
		oInput.name = _oNode.name || _oNode.id;
		oInput.setAttribute("xd:binding", _oNode.getAttribute("xd:binding"));
		oInput.setAttribute("trs_xctname_flag", _sXctNameFlag);
		oInput.setAttribute("trs_temp_id", _oNode.getAttribute("trs_temp_id", 2));
		oInput.setAttribute("xd:xctname", _sXctNameFlag);
		var sValidation = _oNode.getAttribute("validation", 2);
		oInput.setAttribute("validation", sValidation);
		oInput.value = sDefaultValue || "";
		oSpanNode.appendChild(oInput);
		oSpanNode.style.height = _oNode.offsetHeight || '30px';
		oSpanNode.style.width = _oNode.offsetWidth || '30px';
		oSpanNode.style.border = "1px solid #dcdcdc";
		oSpanNode.style.visibility = 'visible';
		oSpanNode.setAttribute("trs_file_upload_type", _oNode.getAttribute("xd:xctname", 2));
		oSpanNode.setAttribute("allow_ext", 'jpg,gif,bmp,jpeg');
		if(sValidation!=null){
			try{
				eval('var ob = {' + sValidation + '}');
				if(ob.extvalid){
					oSpanNode.setAttribute("allow_ext", ob.extvalid);
				}
			}catch(err){
			}
		}
		PageElementHelper.EventObserveMe(oSpanNode, ['onclick']);
		_TransRule_._EffectPowerSetting(oSpanNode);
		_oNode.parentNode.replaceChild(oSpanNode, _oNode);
		if(PageContext.isSettingMode() || !_bReadOnly){
			oSpanNode.setAttribute("trs_context_menu_name", "FileUploadMenu");
			_TransRule_.NotifyMustFill(oSpanNode, {marginLeft:'-15px',marginTop:'7px'});
			_TransRule_._ValidRule(oInput);
		}
	};
}
_TransRule_.save("img", "InlineImage", GetImageAttachmentRule('trs_is_inline_image'));
_TransRule_.save("img", "LinkedImage", GetImageAttachmentRule('trs_is_linked_image'));
_TransRule_.save("span", "ExpressionBox", function(_oSpanNode, _bReadOnly) {
	var oInputNode = document.createElement("input");
	_TransRule_.copyAttributes(_oSpanNode, oInputNode);
	oInputNode.className = _oSpanNode.className;
	oInputNode.style.width = _oSpanNode.style.width;
	if(_oSpanNode.clientHeight < 16) {
		oInputNode.style.height = 16;
	} else {
		oInputNode.style.height = _oSpanNode.clientHeight + 2;
	}
	oInputNode.value = _oSpanNode.innerHTML.trim();
	oInputNode.style.borderWidth = "0px";
	oInputNode.setAttribute("element-type", "2");
	if(!_bReadOnly) {
		PageElementHelper.EventObserveMe(oInputNode);
	} else {
		oInputNode.setAttribute("readOnly", true);
		oInputNode.setAttribute("contentEditable", false);
	}
	_oSpanNode.parentNode.replaceChild(oInputNode, _oSpanNode);
	_TransRule_._EffectPowerSetting(oInputNode);
	_XExpression_.doExpression(oInputNode);
});

/************************************************************/
//Currency ContextMenu
com.trs.wcm.infoview.ContextMenu = Class.create('wcm.infoview.ContextMenu');
com.trs.wcm.infoview.ContextMenu.prototype = {
	initialize : function(_sId, _sWidth){
		if(_sId == null || _sId == "") {
			alert("Error : Parameter[_sId] is empty");
			return false;
		}
		this.m_sId = _sId;
		this.m_oMenu = document.getElementById(_sId);
		this.m_sWidth = _sWidth || "70px";
		this.m_arrItemNames = [];
		this.m_arrItemDescs = [];
		this.m_arrItemActions = [];
	},
	getId : function() {
		return this.m_sId;
	},
	addItem : function(_sItemName, _sItemDesc, _fItemAction) {
		if(_sItemName ==  null || _sItemDesc == null || _fItemAction == null)
			return;
		this.m_arrItemNames.push(_sItemName);
		this.m_arrItemDescs[_sItemName] = _sItemDesc;
		this.m_arrItemActions[_sItemName] = _fItemAction;
	},
	create : function() {
		if(this.m_oMenu == null) {
			this.m_oMenu = document.createElement("div");
			this.m_oMenu.id = this.m_sId;
			this.m_oMenu.style.zIndex = 100;
			this.m_oMenu.style.position = "absolute";
			this.m_oMenu.style.border = "1pt solid #666666";
			this.m_oMenu.style.width = "10px";
			this.m_oMenu.style.backgroundColor = '#f9f8f7';
			this.m_oMenu.style.height = "auto";
			this.m_oMenu.overflow = "visible";
			this.m_oMenu.style.display = "none";
			document.body.appendChild(this.m_oMenu);
		}
		if(this.m_oMenuMask == null){
			this.m_oMenuMask = document.createElement("iframe");
			if(location.protocol.toLowerCase().indexOf('https')!==1){
				this.m_oMenuMask.src = "javascript:void(0);";
			}
			this.m_oMenuMask.style.display = "none";
			this.m_oMenuMask.style.zIndex = 99;
			this.m_oMenuMask.style.position = "absolute";
			this.m_oMenuMask.frameBorder = "0";
			this.m_oMenuMask.scrolling = "no";
			document.body.appendChild(this.m_oMenuMask);
		}
	},
	display : function(_sTop, _sLeft, _arrMenuCtrl) {
		this.m_oMenu.innerHTML = "";
		for(var i=0; i<this.m_arrItemNames.length; i++) {
			var sItemName = this.m_arrItemNames[i];
			this._CreateItem(sItemName, _arrMenuCtrl);
		}
		this.m_oMenu.style.top = _sTop || "0";
		this.m_oMenu.style.left = _sLeft || "0";
		this.m_oMenu.style.display = "inline";
		this.m_oMenu.style.width = this.m_oMenu.offsetWidth;
		Position.clone(this.m_oMenu,this.m_oMenuMask);
		this.m_oMenuMask.style.display = "inline";
	},
	_CreateItem : function(sItemName, _arrMenuCtrl){
		var arrMenuCtrl = _arrMenuCtrl || {};
		var arrItemCtrl = arrMenuCtrl[sItemName];
		if(_arrMenuCtrl && (!arrItemCtrl || arrItemCtrl.display==false))
			return;
		arrItemCtrl = arrItemCtrl || {};
		var sPostfix = arrItemCtrl.postfix || "";
		var sItemDesc = arrItemCtrl.description || (this.m_arrItemDescs[sItemName] + sPostfix);
		var oItem = document.createElement("DIV");
		oItem.style.border = "1pt none #0a246a";
		oItem.style.cursor = "pointer";
		oItem.style.height = "22px";
		oItem.style.width = "100%";
		oItem.style.overflow = "visible";
		oItem.style.overflowY = "hidden";
		oItem.style.whiteSpace = "nowrap";
		oItem.style.backgroundColor = "#f9f8f7";
		this.m_oMenu.appendChild(oItem);
		this.EventObserveItem(oItem);
		oItem.onclick = this.m_arrItemActions[sItemName];
		//\u4E3A\u4E86\u8FBE\u5230\u6BD4\u8F83\u597D\u770B\u7684\u80CC\u666F\u6548\u679C\uFF0C\u91C7\u7528\u8FED\u52A0\u7684\u65B9\u5F0F\u5904\u7406
		//TODO \u76F4\u63A5\u4F7F\u7528\u80CC\u666F\u56FE\u624D\u5408\u7406
		var arrCloneSpans = [
			{backgroundColor:"#f6f4f3", width:"4px"},
			{backgroundColor:"#eeece9", width:"4px"},
			{backgroundColor:"#ebe9e5", width:"4px"},
			{backgroundColor:"#e4e2dc", width:"4px",innerHTML:'&nbsp;'},
			{backgroundColor:"#dddad3", width:"4px"},
			{backgroundColor:"#f9f8f7", width:"8px"},
			{backgroundColor:"#f9f8f7", paddingTop:'3px',width:this.m_sWidth, innerHTML:sItemDesc, fontSize:"12px", overflow:'visible'},
			{backgroundColor:"#f9f8f7", width:"8px"}
		];
		for(var j=0; j<arrCloneSpans.length; j++) {
			var oCloneSpan = document.createElement("SPAN");
			oCloneSpan.style.height = "22px";
			oCloneSpan.style.border = "0";
			oCloneSpan.style.overflow = "hidden";
			oCloneSpan.style.whiteSpace = "nowrap";
			for(var name in arrCloneSpans[j]){
				if(name=='innerHTML')
					oCloneSpan.innerHTML = arrCloneSpans[j][name]||'';
				else
					oCloneSpan.style[name] = arrCloneSpans[j][name];
			}
			oItem.appendChild(oCloneSpan);
		}
	},
	hide : function() {
		this.m_oMenu.style.display = "none";
		this.m_oMenuMask.style.display = "none";
	},
	EventObserveMe : function(_oElement) {
		if(_oElement == null)
			return;
		this.m_oMenu.onmouseout = this.m_oMenu.onmouseover = 
				this.m_oMenu.onfocus = this.m_oMenu.onblur = 
		function(event) {
			event = event || window.event;
			_oElement.setAttribute("event-type", event.type);
			PageElementHelper.EffectMe(_oElement);
		}
	},
	EventObserveItem : function(_oItemElement){
		if(_oItemElement == null)
			return;
		var caller = this;
		_oItemElement.onmouseover = _oItemElement.onmouseout = function(event) {
			event = event || window.event;
			this.setAttribute('event-type', event.type);
			caller._EffectItem(this);
		}
	},
	_EffectItem : function(_oItem) {
		if(!_oItem || !_oItem.tagName)
			return;
		var sEventType = _oItem.getAttribute('event-type', 2);
		var arrBgColors = null;
		switch(sEventType){
			case 'mouseover':
				arrBgColors = ["#b6bdd2", "#b6bdd2", "#b6bdd2", "#b6bdd2", "#b6bdd2", "#b6bdd2", "#b6bdd2", "#b6bdd2"];
				_oItem.style.backgroundColor = "#b6bdd2";
				break;
			case 'mouseout':
				arrBgColors = ["#f6f4f3", "#eeece9", "#ebe9e5", "#e4e2dc", "#dddad3", "#f9f8f7", "#f9f8f7", "#f9f8f7"];
				_oItem.style.backgroundColor = "#f9f8f7";
				break;
		}
		var arrChildNodes = _oItem.childNodes;
		for (var i = 0, n = arrChildNodes.length; i < n; i++){
			arrChildNodes[i].style.backgroundColor = arrBgColors[i];
		}
	}
};

//Currency MenuContainer
com.trs.wcm.infoview.MenuContainer = Class.create('wcm.infoview.ContextMenu');
com.trs.wcm.infoview.MenuContainer.prototype = {
	initialize : function(){
		this.m_arrId = [];
		this.m_arrMenu = [];
		this.m_oSrcElement = null;
	},
	GetSrcElement : function() {
		return this.m_oSrcElement;
	},
	RegisterMenu : function(_oContextMenu) {
		if(!_oContextMenu || !_oContextMenu.getId)//\u5224\u65AD\u662F\u5426\u4E3AContextMenu\u5BF9\u8C61
			return;
		var sMenuId = _oContextMenu.getId();
		if(sMenuId == null || sMenuId == "")
			return;
		if(!this.m_arrMenu[sMenuId]) {
			this.m_arrId.push(sMenuId);
		}
		this.m_arrMenu[sMenuId] = _oContextMenu;
	},
	OpenMenu : function(_sMenuId, _oElement, _arrMenuCtrl) {
		this.CloseAll();
		if(window.parent&&window.parent._MenuContainer_)
			window.parent._MenuContainer_.CloseAll();
		PageContext.bClickFlag = !PageContext.bClickFlag;
		this.m_oSrcElement = _oElement;
		if(_sMenuId == null)
			return;
		var oMenu = this.m_arrMenu[_sMenuId];
		if(oMenu == null || !oMenu.display)//\u5224\u65AD\u662F\u5426\u4E3AContextMenu\u5BF9\u8C61
			return;
		var oEvent = Event.findEvent();
		if(oEvent == null)
			return;
		var sTop = Event.pointerY(oEvent);
		var sLeft = Event.pointerX(oEvent);
		oMenu.display(sTop, sLeft, _arrMenuCtrl);
		oMenu.EventObserveMe(_oElement);
	},
	CloseMenu : function(_sMenuId) {
		if(_sMenuId == null)
			return;
		var oMenu = this.m_arrMenu[_sMenuId];
		if(oMenu && oMenu.hide)
			oMenu.hide();

		this.m_oSrcElement = null;
	},
	CloseAll : function() {
		for(var i=0,n=this.m_arrId.length; i<n; i++) {
			this.CloseMenu(this.m_arrId[i]);
		}
	},
	getBrothersOfSameXctName : function(_oElement) {
		if(!_oElement || !_oElement.tagName || !_oElement.parentNode)
			return [];
		var result = [];
		var sTagName = _oElement.tagName;
		var sXctName = _oElement.getAttribute("xd:xctname", 2);
		if(!sXctName)
			return [];
		var arrNodes = _oElement.parentNode.childNodes;
		for(var i=0; i<arrNodes.length; i++) {
			if(arrNodes[i].tagName == sTagName
					&& arrNodes[i].getAttribute("xd:xctname", 2) == sXctName)
				result.push(arrNodes[i]);
		}
		return result;
	},
	openTitleSystemMenu : function() {
		var oTitleNode = document.getElementById("TitlePattern");
		_MenuContainer_.OpenMenu("TitleSystemMenu", oTitleNode);
	}
}
var _MenuContainer_ = new com.trs.wcm.infoview.MenuContainer();
/*************************************************************/
com.trs.wcm.infoview.FlyButton = Class.create('wcm.infoview.FlyButton');
com.trs.wcm.infoview.FlyButton.prototype = {
	initialize : function(_sId, _sHtml, _sContextMenuName){
		if(_sId == null || _sId == "") {
			alert("Error : Parameter[_sId] is empty");
			return false;
		}
		if(_sHtml == null || _sHtml == "") {
			alert("Error : Parameter[_sHtml] is empty");
			return false;
		}
		this.m_sId = _sId;
		this.m_sHtml = _sHtml;
		//this.m_sStyle = _sStyle || "width:100%;height=100%";
		this.m_oButton = document.getElementById(_sId);
		this.m_ContextMenuName = _sContextMenuName;
	},
	getId : function() {
		return this.m_sId;
	},
	create : function() {
		if(this.m_oButton != null)
			return;
		this.m_oButton = document.createElement("div");
		this.m_oButton.id = this.m_sId;
		this.m_oButton.style.zIndex = 99;
		this.m_oButton.style.cursor = 'pointer';
		this.m_oButton.style.position = "absolute";
		this.m_oButton.style.borderWidth = "0px";
		this.m_oButton.style.borderStyle = "solid";
		this.m_oButton.style.borderColor = "#9a9a9a";
		this.m_oButton.setAttribute("xd:xctname", "FlyButton");
		if(this.m_ContextMenuName) {
			this.m_oButton.setAttribute("trs_context_menu_name", this.m_ContextMenuName);
		}
		this.m_oButton.style.display = "none";
		this.m_oButton.innerHTML = this.m_sHtml;
		document.body.appendChild(this.m_oButton);
	},
	display : function(_sTop, _sLeft) {
		var sTop = _sTop || "0";
		var sLeft = _sLeft || "0";
		this.m_oButton.style.top = sTop;
		this.m_oButton.style.left = sLeft;
		this.m_oButton.style.display = "inline";
	},
	hide : function() {
		this.m_oButton.style.display = "none";
	},
	getWidth : function() {
		var arrImages = this.m_oButton.getElementsByTagName("img");
		if(arrImages.length == 0)
			return 0;
		return arrImages[0].style.width;
	},
	setWidth : function(_sWidth) {
		var arrImages = this.m_oButton.getElementsByTagName("img");
		if(arrImages.length == 0 || !_sWidth)
			return;
		arrImages[0].style.width = _sWidth;
	},
	getHeight : function() {
		var arrImages = this.m_oButton.getElementsByTagName("img");
		if(arrImages.length == 0)
			return;
		return arrImages[0].style.height;
	},
	setHeight : function(_sHeight) {
		var arrImages = this.m_oButton.getElementsByTagName("img");
		if(arrImages.length == 0 || !_sHeight)
			return;
		arrImages[0].style.height = _sHeight;
	},
	extendEvent : function(_oElement) {
		if(_oElement == null)
			return;
		this.m_oButton.onmouseout = this.m_oButton.onmouseover = 
				this.m_oButton.onfocus = this.m_oButton.onblur = 
		function(event) {
			event = event || window.event;
			_oElement.setAttribute("event-type", event.type);
			PageElementHelper.EffectMe(_oElement);
		}
	},
	attachEvent : function(_sEventName, _fEventMethod) {
		if(_sEventName == null || _sEventName == "" || _fEventMethod == null)
			return;
		eval("this.m_oButton." + _sEventName + " = _fEventMethod");
	}
};

//Currency Static FlyButtonContainer
var _FlyButtonContainer_ = com.trs.wcm.infoview.FlyButtonContainer = {
	m_arrId : [],
	m_arrFlyButton : [],
	m_oSrcElement : null,
	block : false,
	DefaultImageWidth : "15px",
	DefaultImageHeight : "15px",
	registerButton : function(_oFlyButton) {
		if(_oFlyButton == null)
			return;
		var sButtonId = _oFlyButton.getId();
		if(!_FlyButtonContainer_.m_arrFlyButton[sButtonId]) {
			_FlyButtonContainer_.m_arrId.push(sButtonId);
		}
		_FlyButtonContainer_.m_arrFlyButton[sButtonId] = _oFlyButton;
	},
	openButton : function(_sButtonId, _oElement, _fMethod, _sWidth, _sHeight, _isInElement) {
		if(_FlyButtonContainer_.block)
			return;
		_FlyButtonContainer_.CloseAll();
		_FlyButtonContainer_.m_oSrcElement = _oElement;
		if(_sButtonId == null || _oElement == null)
			return;
		var oButton = _FlyButtonContainer_.m_arrFlyButton[_sButtonId];
		if(oButton == null)
			return;
		if(!oButton.display)
			return;
		var sWidth = _sWidth || _FlyButtonContainer_.DefaultImageWidth;
		var sHeight = _sHeight || _FlyButtonContainer_.DefaultImageHeight;
		oButton.setWidth(sWidth);
		oButton.setHeight(sHeight);
		var oPos = Position.positionedOffset(_oElement);
		var sTop = oPos[1];
		var sLeft = oPos[0];
		if(!_isInElement) {
//			var sWidth = oButton.getWidth() || _FlyButtonContainer_.DefaultImageWidth;
//			sLeft -= parseInt(sWidth);
			sTop += 2;
		} else {
			sTop += 1;
			sLeft += 1;
		}
		oButton.display(sTop, sLeft);
		oButton.extendEvent(_oElement);
		oButton.attachEvent('onclick', _fMethod);
	},
	closeButton : function(_sButtonId) {
		if(_sButtonId == null)
			return;
		var oButton = _FlyButtonContainer_.m_arrFlyButton[_sButtonId];
		if(oButton == null)
			return;
		if(!oButton.hide)
			return;
		oButton.hide();
	},
	CloseAll : function() {
		for(var i=0; i<_FlyButtonContainer_.m_arrId.length; i++) {
			var sButtonId = _FlyButtonContainer_.m_arrId [i];
			_FlyButtonContainer_.closeButton(sButtonId);
		}
		_FlyButtonContainer_.block = false;
	},
	GetSrcElement : function() {
		return _FlyButtonContainer_.m_oSrcElement;
	},
	//Create & Register FlyButtons of this page
	loadFlyButton : function() {
		if(PageContext.isSettingMode()){
			if(PageContext.isMainPage()){
				_FlyButtonContainer_.loadFlyButton4MainSetting();
			}
			else{
				_FlyButtonContainer_.loadFlyButton4Setting();
			}
		}
		else if(PageContext.isEditableMode()){
			if(!PageContext.isMainPage() || PageContext.isPublicAddEditMode()){
				_FlyButtonContainer_.loadFlyButton4Edit();
			}
		}
	},
	loadFlyButton4Edit : function() {
		//selectable section menu
		var oRepeatButton = new com.trs.wcm.infoview.FlyButton("RepeatButton", "<img src='" + InfoViewConstants.ResourceBase + "DownButton.gif' border='0'>");
		oRepeatButton.create();
		_FlyButtonContainer_.registerButton(oRepeatButton);
		var oFileButton = new com.trs.wcm.infoview.FlyButton("FileButton", '<img src="' + InfoViewConstants.ResourceBase + 'FileButton.gif" border="0">', "FileUploadMenu");
		oFileButton.create();
		_FlyButtonContainer_.registerButton(oFileButton);
	},
	loadFlyButton4Setting : function() {
		var oSettingButton = new com.trs.wcm.infoview.FlyButton("SettingButton", "<img src='" + InfoViewConstants.ResourceBase + "DownButton.gif' border='0'>");
		oSettingButton.create();
		_FlyButtonContainer_.registerButton(oSettingButton);
	},
	loadFlyButton4MainSetting : function(){
		var oSettingButton = new com.trs.wcm.infoview.FlyButton("SettingButton", "<img src='" + InfoViewConstants.ResourceBase + "DownButton.gif' border='0'>");
		oSettingButton.create();
		_FlyButtonContainer_.registerButton(oSettingButton);
		var oViewSettingButton = new com.trs.wcm.infoview.FlyButton("ViewSettingButton", "<img src='" + InfoViewConstants.ResourceBase + "DownButton.gif' border='0'>");
		oViewSettingButton.create();
		_FlyButtonContainer_.registerButton(oViewSettingButton);
	}
}
/*************************************************************/
com.trs.wcm.infoview.MyURL = function(_sURL) {
	//set url
	var sURL = null;
	if(_sURL ==  null || _sURL == "") {
		sURL = window.location.href;
	} else {
		sURL = _sURL;
	}
	this.m_sURL = sURL.replace(/#*$/, "");

	//set query string
	var nPos = this.m_sURL.indexOf("?");
	if(nPos < 0) {
		this.m_sQueryString = "";
	} else {
		this.m_sQueryString = this.m_sURL.substring(nPos + 1);
	}

	//set parameters
	this.m_arrParameters = new Array();
	var arrPairs = this.m_sQueryString.split("&");
	for(var i=0; i<arrPairs.length; i++) {
		var arrPair = arrPairs[i].split("=");
		if(arrPair.length != 2) {
			continue;
		}
		if(arrPair[0] == null || arrPair[0] == "" || arrPair[1] == null || arrPair[1] == "") {
			continue;
		}
		this.m_arrParameters[arrPair[0].toLowerCase()] = arrPair[1];
	}

	//function getParameter
	this.getParameter = function(_sName) {
		return this.m_arrParameters[_sName.toLowerCase()];
	}
}
/*****************************************************/
var _XMLDATA_ = com.trs.wcm.infoview.XMLData = {
	createXMLData : function() {
		var sRootName = "my:myFields";
		var oXMLDoc = com.trs.util.XML.createXMLDoc(sRootName);
		if(oXMLDoc == null) {
			return null;
		}
		var oXMLNode = oXMLDoc.documentElement;
		oXMLNode.setAttribute("xmlns:my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-16T07:01:44");
		var oHTMLNode = document.documentElement;
		_XMLDATA_.recurXMLData(oXMLNode, oHTMLNode);
		if( IS_DEBUG) {
			prompt("_XMLDATA_.createXMLData", com.trs.util.XML.serializeToString(oXMLDoc));
		}
		return oXMLDoc;
	},
	CreateMultiXMLData : function(){
		var sRootName = "my:myFields";
		var oXMLDoc = com.trs.util.XML.createXMLDoc(sRootName);
		if(oXMLDoc == null) {
			return null;
		}
		var oXMLNode = oXMLDoc.documentElement;
		oXMLNode.setAttribute("xmlns:my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-16T07:01:44");
		var arrIframes = document.getElementsByTagName("iframe");
		for(var i=0; i<arrIframes.length; i++) {
			try{
				if(!arrIframes[i].contentWindow._XMLDATA_)continue;
				//alert(arrIframes[i].contentWindow._XMLDATA_.createXMLData);
				var oContentWindow = arrIframes[i].contentWindow;
				var oHTMLNode = oContentWindow.document.documentElement;
				_XMLDATA_.recurXMLData(oXMLNode, oHTMLNode, oContentWindow.document);
			}catch(err){
				//Just skip it.
			}
		}
		return oXMLDoc;
	},
	_renderXMLDataByProperty : function(oXMLNode, oNodeProperty){
		if(oNodeProperty != null) {
			var sPathName = oNodeProperty.xpath;
			var sXMLPathName = _XMLDATA_.getNodeXPath(oXMLNode);
			var nInciseIndex = (sXMLPathName)?(sXMLPathName.length+1):0;
			if(nInciseIndex >= sPathName.length)
				return;
			sPathName = sPathName.substring(nInciseIndex);
			var arrPathName = sPathName.split("/");
			for(var i=0,n=arrPathName.length; i<n; i++) {
				if(arrPathName[i] == null || arrPathName[i] == "")
					continue;
				//\u6700\u540E\u4E00\u7EA7\u8DEF\u5F84\u624D\u652F\u6301repeat
				var isRepeatable = (i == arrPathName.length-1 && oNodeProperty.repeatable);
				
				//\u628A\u9644\u4EF6\u5F53\u4F5C\u4E00\u4E2Arepeat\u7C7B\u578B\u7684\u5B57\u6BB5\uFF0C\u8FD9\u6837\u624D\u53EF\u652F\u6301\u591A\u4E2A\u9644\u4EF6
				if(oNodeProperty['trs_xctname_flag'] == 'trs_is_inline_file') {
					isRepeatable = true;
				}
				var oNode = _XMLDATA_.appendChild(oXMLNode, arrPathName[i], isRepeatable);
				oXMLNode = oNode;
			}
			if(oNodeProperty.type == "value_node") {
				if(oNodeProperty.trs_xctname_flag != null) {
					oXMLNode.setAttribute(oNodeProperty.trs_xctname_flag, "1");
				}
				if(oNodeProperty.value != null) {
					var txtNode = oXMLNode.ownerDocument.createCDATASection(oNodeProperty.value);
					oXMLNode.appendChild(txtNode);

					if(oNodeProperty['file-desc'] != null) {
						oXMLNode.setAttribute('file-desc', oNodeProperty['file-desc']);
					}
					/*
					if(oXMLNode.childNodes.length>0){
						var oCloneNode = oXMLNode.cloneNode(true);
						for(var n=oCloneNode.childNodes.length-1;n>=0;n--){
							oCloneNode.removeChild(oCloneNode.childNodes[n]);
						}
						oCloneNode.appendChild(txtNode);
						oXMLNode.parentNode.insertBefore(oCloneNode, oXMLNode.nextSibling);
					}
					else{
						oXMLNode.appendChild(txtNode);
					}
					*/
				}
			}
		}
		return oXMLNode;
	},
	recurXMLData : function(_oXMLNode, _oHTMLNode, _oDocument) {
		if(_oXMLNode == null || _oHTMLNode == null)
			return;
		var oXMLNode = _oXMLNode;
		var oHTMLNode = _oHTMLNode;
		var oNodeProperty = _XMLDATA_.getNodeProperty(oHTMLNode, _oDocument);
		oXMLNode = _XMLDATA_._renderXMLDataByProperty(oXMLNode, oNodeProperty);
		//\u9012\u5F52\u904D\u5386\u5B50
		var arrNodes = oHTMLNode.childNodes;
		for(var i=0,n=arrNodes.length; i<n; i++) {
			_XMLDATA_.recurXMLData(oXMLNode, arrNodes[i], _oDocument);
		}
	},
	validateData : function() {
//		try {
			if(window.ValidationHelper){
				var arrValidInfos = ValidationHelper.validSet(window.VALIDATIONID);
				var bIsValid = true;
				var sHTML = '<ul>';
				for(var i=0;arrValidInfos&&i<arrValidInfos.length;i++){
					if(arrValidInfos[i].isValid())continue;
					bIsValid = false;
					sHTML += '<li>'+arrValidInfos[i].getWarning();
				}
				sHTML += '</ul>';
				if(!bIsValid){
					if($(window.VALIDATION_MESSAGE_CONTAINER)){
						$(window.VALIDATION_MESSAGE_CONTAINER).innerHTML = sHTML;
					}
					else{
						alert(sHTML);
					}
				}
				else{
					if($(window.VALIDATION_MESSAGE_CONTAINER)){
						$(window.VALIDATION_MESSAGE_CONTAINER).innerHTML = '';
					}
				}
				return bIsValid;
			}
			return true;
//		}catch(e){
//			alert("Exception in _XMLDATA_.validateData : " + e.description);
//		}
	},
	getNodeXPath : function(_oXMLNode) {
		var arrPaths = [];
		var oTmpNode = _oXMLNode;
		while(oTmpNode) {
			if(oTmpNode.parentNode == null || oTmpNode.parentNode.nodeType == 9)
				break;
			var sNodeName = oTmpNode.nodeName;
			if( sNodeName== null || sNodeName == "")
				break;
			arrPaths.push(sNodeName);
			oTmpNode = oTmpNode.parentNode;
		}
		return arrPaths.join('/');
	},
	_IsElementNode : function(sTagName, sXctName, _oHTMLNode){
		return (sTagName == "DIV" || 
				(sTagName == "SPAN" && sXctName != "richtext") || sTagName == "TBODY");
	},
	_GetInputSelectorValue : function(_oHTMLNode, _oDocument){
		var sInputType = _oHTMLNode.type;
		if(sInputType!='radio' && sInputType!='checkbox')throw 'not input selector node.';
		var arrElements = (_oDocument||document).getElementsByName(_oHTMLNode.name);
		var arrValues = [];
		for(var i=0,n=arrElements.length; i<n; i++) {
			if(arrElements[i] == null 
				|| arrElements[i].tagName != "INPUT" 
				|| arrElements[i].type != sInputType)
				continue;
			arrElements[i].setAttribute("trs_temp_flag_ignore", 1);
			var sValue = (arrElements[i].checked)? 
				arrElements[i].getAttribute("xd:onValue", 2)
				: ((sInputType=="radio")?null:arrElements[i].getAttribute("xd:offValue", 2));
			if(sValue != null)
				arrValues.push(sValue);
		}
		return arrValues.join(',');
	},
	getNodeProperty : function(_oHTMLNode, _oDocument) {
		if(_oHTMLNode == null || _oHTMLNode.tagName == null)
			return null;
		//Ignore
		var sTempIgnore = _oHTMLNode.getAttribute("trs_temp_flag_ignore", 2);
		if(sTempIgnore != null) {
			_oHTMLNode.removeAttribute("trs_temp_flag_ignore");
			return null;
		}
		var sTagName = _oHTMLNode.tagName;
		//Ignore IMG
		if(sTagName == "IMG")
			return null;
		var sXctName = _oHTMLNode.getAttribute("xd:xctname", 2);
		if(sXctName == null || sXctName == "")
			return null;
		if(_oHTMLNode.getAttribute("trs_readonly_field", 2) == '1' && !this._GetElementValue(_oHTMLNode, _oDocument)){
			return null;
		}
		sXctName = sXctName.toLowerCase().trim();
		//Ignore fileattachment,inlineimage,linkedimage
		if(sTagName == "SPAN" && 
			( sXctName== "fileattachment" || sXctName == "inlineimage" || sXctName == "linkedimage"))
			return null;
		var sXPath = _oHTMLNode.getAttribute('trs_temp_id', 2);
		if(sXPath == null || sXPath == "")
			return null;
		var isRepeatable = false;
		//Judge is Element Node
		if(_XMLDATA_._IsElementNode(sTagName, sXctName, _oHTMLNode)) {
			isRepeatable = (sXctName == "repeatingsection" || sXctName == "repeatingtable");
			return {
				type : "element_node",
				xpath : sXPath,
				repeatable : isRepeatable
			};
		}
		//Input
		if(sTagName == "INPUT") {
			var sInputType = _oHTMLNode.type;
			var sValue = null;
			var sTrsXctName = null;
			if(sInputType == "hidden" || sInputType == "password" || sInputType == "text") {
				sValue = _oHTMLNode.value;
				sTrsXctName = _oHTMLNode.getAttribute("trs_xctname_flag", 2);
				isRepeatable = (sXctName == "listitem_plain");
			} else if(sInputType == "checkbox" || sInputType == "radio") {
				sValue = _XMLDATA_._GetInputSelectorValue(_oHTMLNode, _oDocument);
			} else {
				return null;
			}
			var result = {
				'file-desc': _oHTMLNode.getAttribute('file-desc', 2),
				type : "value_node",
				xpath : sXPath,
				value : sValue,
				repeatable : isRepeatable,
				trs_xctname_flag : sTrsXctName
			};
			return result;
		}
		if(sTagName == "TEXTAREA" || sTagName == "SELECT") {
			return {
				type : "value_node",
				xpath : sXPath,
				value : _oHTMLNode.value
			};
		}
		if(sTagName == "SPAN" && sXctName == "richtext") {
			return {
				type : "value_node",
				xpath : sXPath,
				value : _oHTMLNode.innerHTML
			};
		}

		return null;
	},
	_GetElementValue : function(_oHTMLNode, _oDocument){
		var sTagName = _oHTMLNode.tagName;
		var sXctName = _oHTMLNode.getAttribute("xd:xctname", 2);
		var sType = null;
		switch(sTagName){
			case 'INPUT':
				sType = _oHTMLNode.type.toLowerCase();
				if(sType == "checkbox" || sType == "radio") {
					return ''+_XMLDATA_._GetInputSelectorValue(_oHTMLNode, _oDocument);
				}
				return _oHTMLNode.value;
			case 'TEXTAREA':
			case 'SELECT':
				return _oHTMLNode.value;
			case 'SPAN':
				if(sXctName == "richtext")
				return _oHTMLNode.innerHTML;
			default:
			return '';
		}
	},
	appendChild : function(_oXMLNode, _sNodeName, _isRepeatable) {
		if(_oXMLNode == null || _sNodeName == null)
			return null;
		if(!_isRepeatable) {
			//\u82E5\u5DF2\u7ECF\u5B58\u5728\u8BE5\u5B50\u8282\u70B9\uFF0C\u5219\u4E0D\u521B\u5EFA\uFF0C\u76F4\u63A5\u8FD4\u56DE
			var arrNodes = _oXMLNode.childNodes;
			for(var i=0,n=arrNodes.length; i<n; i++) {
				if(arrNodes[i].nodeName == _sNodeName)
					return arrNodes[i];
			}
		}
		var oNode = _oXMLNode.ownerDocument.createElement(_sNodeName);
		_oXMLNode.appendChild(oNode);
		return oNode;
	},
	findChildrenByName : function(_oXMLNode, _sName) {
		if(_oXMLNode == null || _sName == null || _sName == "")
			return [];
		var retVal = [];
		var arrNodes = _oXMLNode.childNodes;
		for(var i=0,n=arrNodes.length; i<n; i++) {
			if(arrNodes[i] && arrNodes[i].nodeName == _sName)
				retVal.push(arrNodes[i]);
		}
		return retVal;
	},
	trimXMLDataByTemplate : function(_oXMLData, _oXMLTemplate) {
		if(_oXMLData == null || _oXMLTemplate == null)
			return null;
		_XMLDATA_.recurTrimXMLData(_oXMLData.documentElement, _oXMLTemplate.documentElement);
		return _oXMLTemplate;
	},
	_ClearNode : function(_oNode) {
		if(_oNode == null)
			return;
		var arrNodes = _oNode.childNodes;
		//\u5220\u9664\u5B50\u7684\u65F6\u5019\u5FC5\u987B\u5012\u7740\u5220\uFF0C\u5426\u5219\u5F88\u53EF\u80FD\u5BFC\u81F4index\u9519\u4F4D
		for(var i=arrNodes.length - 1; i>=0; i--) {
			if(arrNodes[i].nodeType == 3 || arrNodes[i].nodeType == 4) {
				_oNode.removeChild(arrNodes[i]);
			}
		}
	},
	_GetTextValue : function(_oNode) {
		if(_oNode == null)
			return null;
		var arrNodes = _oNode.childNodes;
		for(var i=0,n=arrNodes.length; i<n; i++) {
			if(arrNodes[i].nodeType == 3 || arrNodes[i].nodeType == 4) {
				var sValue = arrNodes[i].nodeValue;
				if(sValue!=null&&sValue.trim()!='')
					return sValue.trim();
			}
		}
		return null;
	},
	_ExtendFileFlag : function(_oFromNode, _oToNode) {
		if(_oFromNode == null || _oToNode == null)
			return;
		var FLAGS = ["trs_is_inline_file", "trs_is_inline_image", "trs_is_linked_image"];
		for(var i=0; i<FLAGS.length; i++) {
			var sValue = _oFromNode.getAttribute(FLAGS[i]);
			if(sValue == "1") {
				_oToNode.setAttribute(FLAGS[i], sValue);
			}
		}
		var sFileDesc = _oFromNode.getAttribute('file-desc');
		//alert([_oFromNode.xml, sFileDesc]);
		if(sFileDesc != null) {
			_oToNode.setAttribute('FileName', sFileDesc);
		}
	},
	recurTrimXMLData : function(_oDataNode, _oTemplateNode) {
		var oDataNode = _oDataNode;
		var oTemplateNode = _oTemplateNode;
		var arrNodes = oTemplateNode.childNodes;
		var arrClonedNodes = [];
		for(var i=arrNodes.length; i>0; i--) {
			var oNode = arrNodes[i-1];
			if(oNode == null)
				continue;
			if(oNode.nodeType==1){
				oNode.removeAttribute('trs_unreadable_field');
			}
			var arrFoundNodes = _XMLDATA_.findChildrenByName(oDataNode, oNode.nodeName);
			if(arrFoundNodes.length == 0){
				if(oNode.nodeType==1){
					oNode.setAttribute('trs_unreadable_field', 1);
				}
				continue;
			}
			for(var j=0; j<arrFoundNodes.length; j++) {
				var sNodeValue = _XMLDATA_._GetTextValue(arrFoundNodes[j]);
				var oClonedNode = null;
				//\u907F\u514D\u91CD\u590D\u6DFB\u52A0oNode\u7684\u8282\u70B9
				if(j == 0) {
					oClonedNode = oNode;
				} else {
					oClonedNode = oNode.cloneNode(true);
					arrClonedNodes.push(oClonedNode);
				}
				if(sNodeValue == null || sNodeValue == "") {
					_XMLDATA_.recurTrimXMLData(arrFoundNodes[j], oClonedNode);
				} else {
					_XMLDATA_._ClearNode(oClonedNode);
					var txtNode = oNode.ownerDocument.createCDATASection(sNodeValue);
					oClonedNode.appendChild(txtNode);
					_XMLDATA_._ExtendFileFlag(arrFoundNodes[j], oClonedNode);
				}
			}
		}
		//?\u9006\u7740\u52A0,\u65E0\u6240\u8C13\u987A\u5E8F
		for(var i=0; i<arrClonedNodes.length; i++) {
			oTemplateNode.appendChild(arrClonedNodes[i]);
		}
	},
	//ge gfc add @ 2007-10-9 13:51
	renderSubmit : function(_bJustCached){
		if(!_XMLDATA_.validateData())
			return;

		//\u8BB0\u5F55\u4E00\u4E0B_bJustCached\u53C2\u6570\uFF0C\u56E0\u4E3A\u5982\u679C\u8981\u663E\u793A\u9A8C\u8BC1\u540E\u56DE\u8C03\u7684\u8BDD\uFF0C_bJustCached\u53C2\u6570\u65E0\u6CD5\u76F4\u63A5\u4F20\u5165doSubmit
		PageContext['JustCachedToInfogate'] = _bJustCached;

		if(frmAction) {
			//\u9A8C\u8BC1\u7801\u903B\u8F91
			if(frmAction.JustCached != null) {
				frmAction.JustCached.value = (_bJustCached == true) ? 1 : 0;
			}
			if(frmAction.verifycode != null) {
				var oVerifyURL = frmAction.verifycodeurl;
				if(oVerifyURL != null && oVerifyURL.value != null) {
					_XMLDATA_.displayVerify(oVerifyURL.value);
					return;
				}
			}
			//else
			_XMLDATA_.doSubmit(null, _bJustCached);
		}	
	},
	doSubmit : function(_sVerifyCode) {
		//\u65E2\u662Fmainpage\u53C8\u662Fviewpage\u5373\u4E3A\u5355\u9875\u5F62\u5F0F,\u5426\u5219\u4E3A\u591A\u9875\u5F62\u5F0F
		var bMultiView = !(PageContext.isMainPage() && PageContext.isInfoViewViewPage());
		if(bMultiView){
			if(frmAction && frmAction.verifycode != null) {
				frmAction.verifycode.value = _sVerifyCode;
			}
			//ge gfc add @ 2008-1-16 21:18 
			var nCachedInfoviewId = parseInt(getParameter('cachedinfoviewid'), 10);
			if(nCachedInfoviewId > 0 && frmAction.CachedInfoviewId) {
				var eCachedInfoviewId = frmAction.CachedInfoviewId;
				if(eCachedInfoviewId.length > 1) {//\u6709\u591A\u9875\u8868\u5355
					eCachedInfoviewId = frmAction.CachedInfoviewId[0];
				}
				eCachedInfoviewId.value = nCachedInfoviewId;
			}
			//ge gfc add @ 2008-1-24 15:00  \u7528\u4E8E\u533A\u522B\u662F\u5C06\u6682\u5B58\u4FE1\u606F\u63D0\u4EA4\u8FD8\u662F\u6682\u5B58/\u7EE7\u7EED\u6682\u5B58
			if(frmAction.JustCached != null) {
				frmAction.JustCached.value = (PageContext['JustCachedToInfogate'] == true) ? 1 : 0;
			}

			_XMLDATA_.collectMultiViewData();
			return;
		}
		//\u5355\u9875\u7684\u5904\u7406\u903B\u8F91
		if(!_XMLDATA_.validateData())
			return;
		if(!frmAction || !frmAction.ObjectXML){
			return;
		}
		if(frmAction.verifycode != null) {
			frmAction.verifycode.value = _sVerifyCode;
		}
		var oObjectXML = frmAction.ObjectXML;
		var oTemplateDoc = com.trs.util.XML.loadXML(oObjectXML.value);
		var oDataDoc = _XMLDATA_.createXMLData();
		oDataDoc = _XMLDATA_.trimXMLDataByTemplate(oDataDoc, oTemplateDoc);
		if(IS_DEBUG) {
			prompt("_XMLDATA_.doSubmit : oDataDoc", com.trs.util.XML.serializeToString(oDataDoc));
			return;
		}
		oObjectXML.value = com.trs.util.XML.serializeToString(oDataDoc);
		if(frmAction.DocumentId){
			frmAction.DocumentId.value = (new com.trs.wcm.infoview.MyURL()).getParameter("DocumentId") || "";
		}
		frmAction.method = "post";

		if(frmAction.InfoviewTitle && frmAction.InfoviewTitle.value == '') {
			frmAction.InfoviewTitle.value = document.title;
		}
		var nCachedInfoviewId = parseInt(getParameter('cachedinfoviewid'), 10);
		if(nCachedInfoviewId > 0 && frmAction.CachedInfoviewId) {
			frmAction.CachedInfoviewId.value = nCachedInfoviewId;
		}

		try{
			PageContext.__hideActionsElements();
			if($('loading_bar')) {
				Element.show('loading_bar');
			}
		}catch(err){
			//just skip it
		}

		frmAction.submit();
	},
	doReset : function() {
		_XMLDATA_.DoReset_removeRepeated();
		if(window.parent && window.parent.document 
				&& window.parent.document.getElementById("frmAction")) {
			var elObjectXML = window.parent.document.getElementById("frmAction").ObjectXML;
			if(elObjectXML && elObjectXML.value) {
				_XMLDATA_.initPageByData(elObjectXML.value);
			}
			else{
				var elDataXML = window.parent.document.getElementById("frmAction").DataXML;
				if(elDataXML && elDataXML.value) {
					_XMLDATA_.initPageByData(elDataXML.value);
				}
			}
		} else {
			//fetch xml data & init page
			if(frmAction) {
				if(frmAction.ObjectXML && frmAction.ObjectXML.value) {
					_XMLDATA_.initPageByData(frmAction.ObjectXML.value);
				}
				var nChannelId = frmAction.ChannelId.value;
				var nDocumentId = (new com.trs.wcm.infoview.MyURL()).getParameter("DocumentId") || "";
				PageContext.InitPage(nChannelId, nDocumentId);
			}
		}
	},
	doReset4MultiView : function() {
		var frmAction = document.getElementById("frmAction");
		frmAction.reset();
		var arrIframes = document.getElementsByTagName("iframe");
		for(var i=0; i<arrIframes.length; i++) {
			try{
				if(!arrIframes[i].contentWindow._XMLDATA_)continue;
				var oDataDoc = arrIframes[i].contentWindow._XMLDATA_.doReset();
			}catch(err){
				//Just skip it.
			}
		}
	},
	collectMultiViewData : function(_bSkipValidating) {
		if(_bSkipValidating != true) {
			if(!_XMLDATA_.validateData()) {
				return false;
			}
		}

		var frmAction = document.getElementById("frmAction");
		var oTemplateDoc = com.trs.util.XML.loadXML(frmAction.ObjectXML.value);
		var oDataDoc = _XMLDATA_.CreateMultiXMLData();
		oTemplateDoc = _XMLDATA_.trimXMLDataByTemplate(oDataDoc, oTemplateDoc);
		/*
		var arrIframes = document.getElementsByTagName("iframe");
		for(var i=0; i<arrIframes.length; i++) {
			try{
				if(!arrIframes[i].contentWindow._XMLDATA_)continue;
				//alert(arrIframes[i].contentWindow._XMLDATA_.createXMLData);
				var oContentWindow = arrIframes[i].contentWindow;
				var oDataDoc = oContentWindow._XMLDATA_.createXMLData();
				oTemplateDoc = _XMLDATA_.trimXMLDataByTemplate(oDataDoc, oTemplateDoc);
				//prompt("oTemplateDoc : ", com.trs.util.XML.serializeToString(oTemplateDoc));
			}catch(err){
				//Just skip it.
			}
		}
		if(IS_DEBUG) {
			prompt("_XMLDATA_.collectMultiViewData : ", com.trs.util.XML.serializeToString(oTemplateDoc));
			return;
		}
		*/
		try{
			//RunningProcessBar.start();
		}catch(e){
		}
		frmAction.ObjectXML.value = com.trs.util.XML.serializeToString(oTemplateDoc);
		//alert(frmAction.ObjectXML.value);
		//return false;
		frmAction.method = "post";
		frmAction.submit();

		return true;
	},
	displayVerify : function(_sVerifyURL) {
		TRSDialogContainer.display("VerifyCodeDialog", _sVerifyURL);
	},
	initPageByData : function(_sResponseText) {
		var oXMLDoc = com.trs.util.XML.loadXML(_sResponseText);
		if(oXMLDoc == null) {
			return null;
		}
		var oXMLRoot = oXMLDoc.documentElement;
		var oHTMLRoot = document.body;
		_XMLDATA_.recurInitPageByData(oHTMLRoot, oXMLRoot);
		if(parent.window&&parent.window.ValidationHelper){
			parent.window.ValidationHelper.forceValidSet(parent.window.VALIDATIONID, true);
		}
	},
	//\u8BBE\u7F6E\u8282\u70B9\u7684\u503C\uFF08\u5305\u62EC\u4E00\u4E9B\u7279\u5B9A\u5C5E\u6027\uFF09
	_SetElementValue : function(_oHTMLNode, _oXMLNode, _bInitFromGateInfo) {
		var sValue = _oXMLNode;
		if(!String.isString(_oXMLNode)){
			sValue = _XMLDATA_._GetNodeText(_oXMLNode);
		}
		if(sValue == null || sValue.trim().length == 0)
			return false;
		var sName = _oHTMLNode.name;
		if(!sName)
			return false;
		var oElement = _oHTMLNode;
		var sXctName = oElement.getAttribute("xd:xctname", 2);
		sXctName = (sXctName)?sXctName.toLowerCase():sXctName;
		var sTagName = oElement.tagName;
		if( sTagName == "INPUT"){ 
			if(oElement.type == "radio"){
				oElement.checked = (oElement.getAttribute("xd:onValue") == sValue);
				return true;
			}
			else if(oElement.type == "checkbox") {
				oElement.checked = (','+sValue.trim()+',').indexOf(','+(oElement.getAttribute("xd:onValue")||'')+',')!=-1;
				return true;
			}
		}
		if(sTagName == "SPAN" &&  sXctName== "richtext") {
			oElement.innerHTML = sValue;
			return true;
		}
		//\u5355\u72EC\u5904\u7406\u6587\u4EF6\u9644\u4EF6\u548C\u56FE\u7247\u5B57\u6BB5
		if(sTagName == "SPAN" 
			&& (sXctName == "fileattachment" || sXctName == "inlineimage" || sXctName == "linkedimage")) {
			var arrElements = oElement.childNodes;
			var sPreFileDesc = null;
			for(var i=0; i<arrElements.length; i++) {
				if(!arrElements[i].tagName)continue;
				//\u6587\u4EF6\u9644\u4EF6
				if(sXctName == "fileattachment"){
					if(arrElements[i].getAttribute("text_body") == "1") {
						arrElements[i].style.display = sValue ? "none" : "inline";
						continue;
					}
					if(arrElements[i].getAttribute("text_file") == "1") {
						arrElements[i].style.display = sValue ? "inline" : "none";
						var sFileDesc = null;
						try{
							sFileDesc = _oXMLNode.getAttribute('FileName');	
						}catch(err){
							//just skip it
						}
						sPreFileDesc = sFileDesc;
						arrElements[i].innerHTML = sFileDesc || sValue;
						continue;
					}
					if(arrElements[i].tagName == "INPUT" && arrElements[i].type == "hidden") {
						arrElements[i].value = sValue;
						if(sPreFileDesc != null) {
							arrElements[i].setAttribute("file-desc", sPreFileDesc);
						}
						continue;
					}					
				//\u56FE\u7247
				}
				else{
					if(arrElements[i].getAttribute("image_body") == "1") {
						if(_bInitFromGateInfo){
							arrElements[i].src = InfoViewConstants.ReadFileURLPath + sValue + '&FromInit=1';
						}
						else{
							arrElements[i].src = InfoViewConstants.ReadFileURLPath + sValue;
						}
						arrElements[i].style.display = sValue ? "inline" : "none";
						continue;
					}
					arrElements[i].style.display = sValue ? "none" : "inline";
					if(arrElements[i].tagName == "INPUT" && arrElements[i].type == "hidden") {
						arrElements[i].value = sValue;
						if(sPreFileDesc != null) {
							arrElements[i].setAttribute("file-desc", sPreFileDesc);
						}
						continue;
					}
				}
				
			}
			return true;
		}
		oElement.value = sValue;
		if(sValue!='' && sTagName=='SELECT' && oElement.disabled && oElement.value==''){
			var newOption = document.createElement('OPTION');
			oElement.appendChild(newOption);
			newOption.value = newOption.innerHTML = sValue;
			newOption.selected = true;
		}
		return true;
	},
	_GetNodeText : function(eNode) {
		if(eNode == null)
			return null;
		var sText = eNode.nodeValue;
		if(sText != null)
			return sText;
		var childNodes = eNode.childNodes;
		if(childNodes.length == 0)
			return "";
		for(var i=0; i<childNodes.length; i++) {
			if(childNodes[i].nodeName == "#text" && childNodes[i].nodeValue)
				return childNodes[i].nodeValue;
			else if(childNodes[i].nodeName == "#cdata-section")
				return childNodes[i].nodeValue;
		}
		return null;
	},
	recurInitPageByData : function(_oHTMLNode, _oXMLNode) {
		if(_oHTMLNode == null || _oXMLNode == null)
			return;
		var arrHTMLNodes = _oHTMLNode.childNodes;
		var arrSourceHTMLNodes = [];
		var arrClonedHTMLNodes = [];
		for(var i=0; i<arrHTMLNodes.length; i++) {
			var oHTMLNode = arrHTMLNodes[i];
			var isSpecialRepeat = false;
			if(!oHTMLNode.tagName) continue;
			if(oHTMLNode.tagName == "LI") {
				var oLiInput = oHTMLNode.firstChild;
				var sLiXctName = oLiInput.getAttribute("xd:xctname", 2);
				if(oLiInput != null && sLiXctName != null && sLiXctName.toLowerCase() == "listitem_plain") {
					oHTMLNode = oHTMLNode.firstChild;
					isSpecialRepeat = true;
				}
			}
			var sXctName = oHTMLNode.getAttribute("xd:xctname", 2);
			if(sXctName == null || sXctName == "") {
				_XMLDATA_.recurInitPageByData(oHTMLNode, _oXMLNode);
				continue;
			}
			var sXPath = oHTMLNode.name;
			if(sXPath == null || sXPath == "") {
				_XMLDATA_.recurInitPageByData(oHTMLNode, _oXMLNode);
				continue;
			}
			var arrXMLNodes = _XMLDATA_.findNodesByXPath(_oXMLNode, sXPath);
			if(arrXMLNodes.length == 0) {
				_XMLDATA_.recurInitPageByData(oHTMLNode, _oXMLNode);
				continue;
			}
			for(var j=0; j<arrXMLNodes.length; j++) {
				var oCloneNode = null;
				var oValueNode = null;
				if(j == 0) {
					oCloneNode = oHTMLNode;
					oValueNode = oHTMLNode;
				} else {
					if(isSpecialRepeat) {
						oCloneNode = oHTMLNode.parentNode.cloneNode(true);
						PageElementHelper.CloneEventObserving(oHTMLNode.parentNode, oCloneNode);
						oValueNode = oCloneNode.firstChild;
						arrSourceHTMLNodes.push(oHTMLNode.parentNode.nextSibling);
						arrClonedHTMLNodes.push(oCloneNode);
					} else {
						//\u591A\u4E2A\u76F8\u540C\u5B57\u6BB5\uFF0C\u4F8B\u5982\u591A\u4E2A\u9644\u4EF6
						oCloneNode = oHTMLNode.cloneNode(true);
						//\u8D77\u4E00\u4E2A\u65B0\u7684id
						oCloneNode.id = oCloneNode.id + '_' + (j+1);
						PageElementHelper.CloneEventObserving(oHTMLNode, oCloneNode);
						arrSourceHTMLNodes.push(oHTMLNode.nextSibling);
						arrClonedHTMLNodes.push(oCloneNode);
						oValueNode = oCloneNode;
					}
				}
				var isSuccess = _XMLDATA_._SetElementValue(oValueNode, arrXMLNodes[j]);
				if(!isSuccess) {
					_XMLDATA_.recurInitPageByData(oCloneNode, arrXMLNodes[j]);
				}
			}
		}
		for(var i=0; i<arrClonedHTMLNodes.length; i++) {
			_oHTMLNode.insertBefore(arrClonedHTMLNodes[i], arrSourceHTMLNodes[i]);
		}
	},
	findNodesByXPath : function(_oXMLNode, _sXPath) {
		if(_oXMLNode == null || _sXPath == null)
			return [];
		var resNodes = [];
		var sXPath = _sXPath;
		var sNodeXPath = _XMLDATA_.getNodeXPath(_oXMLNode);
		var nInciseIndex = (sNodeXPath)?(sNodeXPath.length+1):0;
		if(nInciseIndex >= sXPath.length)
			return resNodes;
		sXPath = sXPath.substring(nInciseIndex);
		var arrPath = sXPath.split("/");
		var oNode = _oXMLNode;
		//\u5BFB\u627E\u6700\u540E\u4E00\u4E2A\u7236\u8282\u70B9
		for(var i=0; i<arrPath.length-1; i++) {
			var arrNodes = oNode.childNodes;
			var tmpNode = null;
			for(var j=0,n=arrNodes.length; j<n; j++) {
				if(arrNodes[j].nodeName == arrPath[i]) {
					tmpNode = arrNodes[j];
					break;
				}
			}
			oNode = tmpNode;
			if(oNode == null)
				break;
		}
		if(oNode == null)
			return resNodes;
		var arrBtmNodes = oNode.childNodes;
		for(var i=0,n=arrBtmNodes.length; i<n; i++) {
			if(arrBtmNodes[i].nodeName == arrPath[arrPath.length-1]) {
				resNodes.push(arrBtmNodes[i]);
			}
		}
		return resNodes;
	},
	submit : function(_sURL, _sData, _fOnSuccess) {
		new Ajax.Request(_sURL,{
			method : 'post',
			postBody : _sData,
			asynchronous : true,
			onFailure : function(_transport){
				alert("Problem submit XML data");
			},
			onSuccess : _fOnSuccess
		});
	},
	DoReset_recurRemoveRepeated : function(_oElement) {
		if(!_oElement) return;
		var oElement = _oElement;
		var bIsSuccess = false;
		if(oElement.tagName == "OL") {
			var oFirstLi = oElement.firstChild;
			if(oFirstLi && oFirstLi.tagName == "LI") {
				var oFirstInput = oFirstLi.firstChild;
				if(oFirstInput && oFirstInput.tagName == "INPUT") {
					var sXctName = oFirstInput.getAttribute("xd:xctname", 2);
					if(sXctName != null &&  sXctName.toLowerCase() == "listitem_plain") {
						var arrNodes = oElement.childNodes;
						for(var i=arrNodes.length; i>1; i--) {
							oElement.removeChild(arrNodes[i-1]);
						}
						bIsSuccess = true;
					}
				}
			}
		}
		else if(oElement.tagName == "TABLE") {
			var arrTBodies = oElement.childNodes;
			var isHold = true;
			for(var i=arrTBodies.length; i>0; i--) {
				var oTBody = arrTBodies[i-1];
				var sXctName = oTBody.getAttribute("xd:xctname", 2);
				if(sXctName != null &&  sXctName.toLowerCase() == "repeatingtable") {
					if(isHold)
						isHold = false;
					else
						oElement.removeChild(oTBody);
				}
			}
			bIsSuccess = !isHold;
		}
		else if(oElement.tagName == "DIV") {
			var oFirstDiv = oElement.firstChild;
			if(oFirstDiv && oFirstDiv.tagName == "DIV") {
				var sXctName = oFirstDiv.getAttribute("xd:xctname", 2);
				if(sXctName != null && sXctName.toLowerCase() == "repeatingsection") {
					var arrNodes = oElement.childNodes;
					for(var i=arrNodes.length; i>1; i--) {
						oElement.removeChild(arrNodes[i-1]);
					}
					bIsSuccess = true;
				}
			}
		}
		//\u5F53\u524D\u8282\u70B9\u5DF2\u7ECF\u5B8C\u6210
		if(bIsSuccess)return;
		//\u9012\u5F52\u8C03\u7528
		var arrNodes = oElement.childNodes;
		for(var i=0; i<arrNodes.length; i++) {
			_XMLDATA_.DoReset_recurRemoveRepeated(arrNodes[i]);
		}
	},
	DoReset_removeRepeated : function() {
		var oRoot = document.documentElement;
		_XMLDATA_.DoReset_recurRemoveRepeated(oRoot);
	}
}

/*************************************************************/
Object.extend(PageContext, {
	CollectConstants : function(frmAction){
		//\u5916\u90E8\u8D44\u6E90\uFF08\u56FE\u7247\u7B49\uFF09\u7684\u6839\u8DEF\u5F84
		if(frmAction.resourcebase && frmAction.resourcebase.value){
			InfoViewConstants.ResourceBase = frmAction.resourcebase.value;
		}
		//\u4E0A\u4F20\u6587\u4EF6\u9875\u9762\u7684URL
		if(frmAction.fileuploadurl && frmAction.fileuploadurl.value){
			InfoViewConstants.FileUploadURL = InfoViewConstants.ResourceBase + 'file_upload.html';
			InfoViewConstants.FileUploadDowithURL = frmAction.fileuploadurl.value;
		}
		//\u8BFB\u53D6\u6587\u4EF6\u9875\u9762\u7684URL
		if(frmAction.readfileurl && frmAction.readfileurl.value){
			InfoViewConstants.ReadFileURL = frmAction.readfileurl.value;
			InfoViewConstants.ReadFileURLPath = InfoViewConstants.ReadFileURL + '?FileName=';
		}
	},
	_DoWithFrmAction : function(){
		var frmAction = $("frmAction");
		if(!frmAction){
			if(parent.window && parent.window!=window && parent.window.document.getElementById("frmAction")){
				PageContext.CollectConstants(parent.window.document.getElementById("frmAction"));
			}
			return;
		}
		PageContext.CollectConstants(frmAction);
		//submit button filter
		var isSubmitDisabled = (frmAction.action == null || frmAction.action == "");
		var oSubmitButton = $("SubmitButton");
		if(oSubmitButton&&!isSubmitDisabled){
			oSubmitButton.disabled = false;
			oSubmitButton.onclick = function(){
				_XMLDATA_.renderSubmit();
			};
			if(window.ValidationHelper){
				ValidationHelper.addValidListener(function(){
					var oSubmitButton = $("SubmitButton");
					oSubmitButton.disabled = false;
				}, window.VALIDATIONID);

				ValidationHelper.addInvalidListener(function(){
					var oSubmitButton = $("SubmitButton");
					oSubmitButton.disabled = true;
				}, window.VALIDATIONID);
			}
		}
		else if(oSubmitButton){
			oSubmitButton.disabled = true;
		}
		var oResetButton = $("ResetButton");
		if(oResetButton)
			oResetButton.onclick = _XMLDATA_.doReset;
		return frmAction;
	},
	_TransElements : function(){
		var bIsReadOnly = !PageContext.isEditableMode();
		var arrElements = document.getElementsByTagName("*");
		for(var i=0; i<arrElements.length; i++) {
			var aElement = arrElements[i];
			_TransRule_.doTrans(aElement, bIsReadOnly || aElement.getAttribute('trs_readonly_field', 2)=='1');
		}
		PageContext._DoAfterTrans();
	},
	_FindLinkedEnumWithCondition : function(_oDataArray, _sCValue, _sCName){
		for (var i = 0; i < _oDataArray.length; i++){
			if(_oDataArray[i].value == _sCValue){
				return (!!_oDataArray[i] && _oDataArray[i][_sCName]) || [];
			}
		}
		return [];
	},
	_DoAfterTrans : function(){
		//\u7EA7\u8054\u83DC\u5355
		var oLinkedEnums = window.m_oLinkedEnums || parent.window.m_oLinkedEnums;
		if(oLinkedEnums && oLinkedEnums.ChainItems){
			for (var i = 0; i < oLinkedEnums.ChainItems.length; i++){
				var sChain = oLinkedEnums.ChainItems[i];
				var arrChainItems = sChain.split(',');
				for(var j = 0; j < arrChainItems.length ; j++){
					var sUpLevelName = arrChainItems[j];//\u4E0A\u4E00\u7EA7\u83DC\u5355
					var elSelectUpLevel = _SelectsMap_[sUpLevelName];
					if(!elSelectUpLevel)continue;
					elSelectUpLevel.ChainName = sUpLevelName;
					elSelectUpLevel.ChainItems = arrChainItems;
					elSelectUpLevel.ChainIndex = j;//\u7EA7\u8054index
					if(j!=arrChainItems.length-1){
						Event.observe(elSelectUpLevel, 'change', function(){
							if(!this.LinkedEnums)return;
							if(this.ChainIndex+1 >= this.ChainItems.length)return;
							var sNextChainName = this.ChainItems[this.ChainIndex+1];
							var aEnumValues = PageContext._FindLinkedEnumWithCondition(this.LinkedEnums, this.value, sNextChainName);
							var eNextChain = _SelectsMap_[sNextChainName];
							if(eNextChain){
								eNextChain.LinkedEnums = aEnumValues;
								var sValue = eNextChain.value;
								PageElementHelper._RebuildSelect(eNextChain, aEnumValues);
								eNextChain.value = sValue;
							}
							for(var k=this.ChainIndex+2;k<this.ChainItems.length;k++){
								eTmpChain = _SelectsMap_[this.ChainItems[k]];
								if(!eTmpChain)continue;
								sValue = eTmpChain.value;
								PageElementHelper._RebuildSelect(eTmpChain, []);
								eTmpChain.value = sValue;
							}
						}.bind(elSelectUpLevel));
					}
					if(j==0 ){
						var aEnumValues = oLinkedEnums.Data[sUpLevelName];
						var sValue = elSelectUpLevel.value;
						elSelectUpLevel.LinkedEnums = aEnumValues;
						if(aEnumValues && aEnumValues.length>0){
							PageElementHelper._RebuildSelect(elSelectUpLevel, aEnumValues);
						}
						elSelectUpLevel.value = sValue;
					}
					else{
						var sValue = elSelectUpLevel.value;
						PageElementHelper._RebuildSelect(elSelectUpLevel, []);
						elSelectUpLevel.value = sValue;
					}
				}
			}
		}
	},
	PageLoaded : function(){
		if(PageContext.isMainPage()){
			PageContext._MainPageLoaded();
			return;
		}
		PageContext._ViewPageLoaded();
	},
	_InitPageByData : function(sDataXml){
		if(sDataXml != null) {
			_XMLDATA_.initPageByData(sDataXml);
		}
		if(window.ValidationHelper){
			window.ValidationHelper.forceValidSet(window.VALIDATIONID, true);
		}
	},
	_InitAllPagesByData : function(sDataXml){
		if(PageContext.isInfoViewViewPage()){
			PageContext._InitPageByData(sDataXml);
		}
		else{
			var arrIframes = document.getElementsByTagName("iframe");
			for(var i=0; i<arrIframes.length; i++) {
				try{
					if(!arrIframes[i].contentWindow.PageElementHelper)continue;
					arrIframes[i].contentWindow.PageContext._InitPageByData(sDataXml);
				}catch(err){
					//Just skip it.
				}
			}
		}
	},
	_InitAllPages : function(frmAction){
		var oDataXml = frmAction.DataXML || frmAction.ObjectXML;
		var oGateWayInit = frmAction.GateWayInit;
		if(oDataXml != null) {
			PageContext._InitAllPagesByData(oDataXml.value);
		}
		else if(oGateWayInit && oGateWayInit.value){
			PageContext.InitPageGateWay(oGateWayInit.value, function(_sDataXml, _oUserInfo){
				if(_sDataXml){
					PageContext._InitAllPagesByData(_sDataXml);
				}
				if(_oUserInfo){
					PageContext._InitAllPagesByUserInfo(_oUserInfo);
				}
			});
		}
	},
	_GetInfoGateBinding : function(_oNode, _oUserInfo){
		var sInfoGateBinding = _oNode.getAttribute('gateway_binding', 2);
		if( sInfoGateBinding != null && sInfoGateBinding != '' ){
			if(_oUserInfo){
				var sVarValue = $v(_oUserInfo, sInfoGateBinding);
				if(sVarValue != null)return sVarValue;
			}
		}
		return '';
	},
	_InitPageByUserInfo : function(_oUserInfo, _oDocument){
		if(_oUserInfo != null) {
			var bIsReadOnly = !PageContext.isEditableMode();
			var arrElements = (_oDocument||document).getElementsByTagName("*");
			for(var i=0; i<arrElements.length; i++) {
				var oElement = arrElements[i];
				if(!(oElement.tagName && oElement.getAttribute('trs_temp_id', 2)))continue;
				var sBindingValue = PageContext._GetInfoGateBinding(oElement, _oUserInfo);
				if( sBindingValue != null && !_XMLDATA_._GetElementValue(oElement, _oDocument)){
					_XMLDATA_._SetElementValue(oElement, sBindingValue, true);
				}
			}
			if(window.ValidationHelper){
				window.ValidationHelper.forceValidSet(window.VALIDATIONID, true);
			}
		}
	},
	_InitAllPagesByUserInfo : function(_oUserInfo){
		if(PageContext.isInfoViewViewPage()){
			PageContext._InitPageByUserInfo(_oUserInfo);
		}
		else{
			var arrIframes = document.getElementsByTagName("iframe");
			for(var i=0; i<arrIframes.length; i++) {
				try{
					if(!arrIframes[i].contentWindow.PageElementHelper)continue;
					arrIframes[i].contentWindow.PageContext._InitPageByUserInfo(_oUserInfo, arrIframes[i].contentWindow.document);
				}catch(err){
					//Just skip it.
				}
			}
		}
	},
	_ViewPageLoaded : function(){
		var frmAction = PageContext._DoWithFrmAction();
		//infopath element filter
		if(window.$ValidatorConfigs){
			$ValidatorConfigs.setMouseMode(true);
			$ValidatorConfigs.setFocusMode(false);
		}
		PageContext._TransElements();
		if(!PageContext.isPublicAddEditMode()){
			if(parent.frmAction && parent.frmAction.DataXML){
				PageContext._InitPageByData(parent.frmAction.DataXML.value);
			}
		}
//		PageContext._InitPageByData(frmAction);
		//loading contextmenu & flybutton
		PageContext.BuildContextMenu();
		PageContext._RegisterDialogs(false);
		PageContext._LoadFlyButtons();
		if(Function.isFunction(window.CustomOnload))CustomOnload();
	},
	_MainPageLoaded : function(){
		if(window.$ValidatorConfigs){
			$ValidatorConfigs.setMouseMode(true);
			$ValidatorConfigs.setFocusMode(false);
		}
		var frmAction = PageContext._DoWithFrmAction();
		if(!PageContext.isPublicAddEditMode()){
			_MULTIVIEW_.FetchMultiViewData();
		}
		else{
			if(PageContext.isInfoViewViewPage()){
				PageContext._TransElements();
			}
			PageContext._InitAllPages(frmAction);
		}
		PageContext.BuildContextMenu();
		PageContext._RegisterDialogs(true);
		PageContext._LoadFlyButtons();
	},
	_RegisterDialogs : function(_bMainPage){
		TRSCrashBoard.setMaskable(true);
		if(_bMainPage){
			if(PageContext.isSettingMainPage())
				PageContext._RegisterDialog4MainSetting();
			else if(PageContext.isEditableMode())
				PageContext._RegisterDialog4MainEdit();
		}
		else if(PageContext.isSettingMode()){
			PageContext._RegisterDialog4Setting();
		}
		else if(PageContext.isEditableMode()){
			PageContext._RegisterDialog4Edit();
		}
	},
	_LoadFlyButtons : function(){
		_FlyButtonContainer_.loadFlyButton();
	},
	_RegisterDialog4MainEdit : function(){
		//\u6587\u4EF6\u4E0A\u4F20
		var dialogFileUpload = TRSDialogContainer.register("FileUploadDialog", '\u4E0A\u4F20\u6587\u4EF6', InfoViewConstants.FileUploadURL, '280px', '90px', true);
		dialogFileUpload.onFinished = function(_args){
			//_args\u6570\u7EC4\uFF1A_args[0] file-name, _args[1] file-desc, _args[2] input-name(\u672A\u7528\u5230)
			var sFileName = _args[0];
			var sFileDesc = _args[1] || sFileName;
			var oSrcElement = _MenuContainer_.GetSrcElement() || dialogFileUpload.srcElement;
			var sFileUploadType = oSrcElement.getAttribute("trs_file_upload_type", 2);
			if(sFileUploadType == "InlineImage" || sFileUploadType == "LinkedImage") {
				var arrNodes = oSrcElement.getElementsByTagName("*");
				for(var i=0; i<arrNodes.length; i++) {
					if(arrNodes[i].getAttribute("image_body", 2) == "1") {
						arrNodes[i].src = InfoViewConstants.ReadFileURLPath + sFileName;
						arrNodes[i].style.display = "";
					}
					else if(!(arrNodes[i].tagName == "INPUT" && arrNodes[i].type == "hidden")){
						arrNodes[i].style.display = "none";
					}
				}
			}else{
				var arrTextSpan = oSrcElement.getElementsByTagName("span");
				for(var i=0; i<arrTextSpan.length; i++) {
					if(arrTextSpan[i].getAttribute("text_body", 2) == "1") {
						arrTextSpan[i].style.display = "none";
					}
					if(arrTextSpan[i].getAttribute("text_file", 2) == "1") {
						arrTextSpan[i].style.whiteSpace = "nowrap";
						arrTextSpan[i].style.display = "";
						arrTextSpan[i].innerHTML = sFileDesc;
					}
				}
			}
			var arrFileInputs = oSrcElement.getElementsByTagName("input");
			for(var i=0; i<arrFileInputs.length; i++) {
				if(arrFileInputs[i].getAttribute("xd:binding", 2) != null && (arrFileInputs[i].type == "hidden")) {
					arrFileInputs[i].value = sFileName;
					arrFileInputs[i].setAttribute("file-desc", sFileDesc);
					arrFileInputs[i].setAttribute("xd:xctname", arrFileInputs[i].getAttribute("trs_xctname_flag", 2));
					break;
				}
			}
			dialogFileUpload.srcElement = null;
		};
		//\u683C\u5F0F\u6587\u672C\u7F16\u8F91\u5668
		var sUrl = InfoViewConstants.ResourceBase + 'editor/simpleeditor/index.html';
		var oSimpleEditorDialog = TRSDialogContainer.register('Trs_Simple_Editor', 
				'\u683C\u5F0F\u6587\u672C\u7F16\u8F91\u5668', sUrl, 600, 500, true);
		oSimpleEditorDialog.onFinished = function(_oArgs){
			if(_oArgs.element == null)
				return;
			_oArgs.element.innerHTML = _oArgs.html || '';
		}
		//\u6821\u9A8C\u7801
		var sVerifyCodeURL = InfoViewConstants.ResourceBase + "infoview_verify_code.htm";
		var dialogVerifyCode = TRSDialogContainer.register("VerifyCodeDialog", '\u8BF7\u586B\u5199\u6821\u9A8C\u7801', sVerifyCodeURL, '180px', '130px', true);
		dialogVerifyCode.onFinished = function(_args){
			var sVerifyCode = _args || "";
			_XMLDATA_.doSubmit(sVerifyCode);
		};
	},
	_RegisterDialog4Edit : function(){
		if(!(parent.window && parent.window.TRSDialogContainer 
			&& parent.window.TRSDialogContainer.DialogsMap['FileUploadDialog'])){
			//\u6587\u4EF6\u4E0A\u4F20
			var dialogFileUpload = TRSDialogContainer.register("FileUploadDialog", '\u4E0A\u4F20\u6587\u4EF6', InfoViewConstants.FileUploadURL, '280px', '90px', true);
			dialogFileUpload.onFinished = function(_args){
				var sFileName = _args[0];
				var oSrcElement = _MenuContainer_.GetSrcElement() || dialogFileUpload.srcElement;
				var sFileUploadType = oSrcElement.getAttribute("trs_file_upload_type", 2);
				if(sFileUploadType == "InlineImage" || sFileUploadType == "LinkedImage") {
					var arrNodes = oSrcElement.getElementsByTagName("*");
					for(var i=0; i<arrNodes.length; i++) {
						if(arrNodes[i].getAttribute("image_body", 2) == "1") {
							arrNodes[i].src = InfoViewConstants.ReadFileURLPath + sFileName;
							arrNodes[i].style.display = "";
						}
						else if(!(arrNodes[i].tagName == "INPUT" && arrNodes[i].type == "hidden")){
							arrNodes[i].style.display = "none";
						}
					}
				}else{
					var arrTextSpan = oSrcElement.getElementsByTagName("span");
					for(var i=0; i<arrTextSpan.length; i++) {
						if(arrTextSpan[i].getAttribute("text_body", 2) == "1") {
							arrTextSpan[i].style.display = "none";
						}
						if(arrTextSpan[i].getAttribute("text_file", 2) == "1") {
							arrTextSpan[i].style.whiteSpace = "nowrap";
							arrTextSpan[i].style.display = "";
							arrTextSpan[i].innerHTML = sFileName;
						}
					}
				}
				var arrFileInputs = oSrcElement.getElementsByTagName("input");
				for(var i=0; i<arrFileInputs.length; i++) {
					if(arrFileInputs[i].getAttribute("xd:binding", 2) != null && (arrFileInputs[i].type == "hidden")) {
						arrFileInputs[i].value = sFileName;
						arrFileInputs[i].setAttribute("xd:xctname", arrFileInputs[i].getAttribute("trs_xctname_flag", 2));
						break;
					}
				}
			};
		}
		if(!(parent.window && parent.window.TRSDialogContainer 
			&& parent.window.TRSDialogContainer.DialogsMap['Trs_Simple_Editor'])){
			//\u683C\u5F0F\u6587\u672C\u7F16\u8F91\u5668
			var sUrl = InfoViewConstants.ResourceBase + 'editor/simpleeditor/index.html';
			var oSimpleEditorDialog = TRSDialogContainer.register('Trs_Simple_Editor', 
					'\u683C\u5F0F\u6587\u672C\u7F16\u8F91\u5668', sUrl, 600, 500, true);
			oSimpleEditorDialog.onFinished = function(_oArgs){
				if(_oArgs.element == null)
					return;
				_oArgs.element.innerHTML = _oArgs.html || '';
			}
		}
		if(!(parent.window && parent.window.TRSDialogContainer 
			&& parent.window.TRSDialogContainer.DialogsMap['VerifyCodeDialog'])){
			//\u6821\u9A8C\u7801
			var sVerifyCodeURL = InfoViewConstants.ResourceBase + "infoview_verify_code.htm";
			var dialogVerifyCode = TRSDialogContainer.register("VerifyCodeDialog", '\u8BF7\u586B\u5199\u6821\u9A8C\u7801', sVerifyCodeURL, '180px', '130px', true);
			dialogVerifyCode.onFinished = function(_args){
				var sVerifyCode = _args || "";
				_XMLDATA_.doSubmit(sVerifyCode);
			};
		}
	},
	_RegisterDialog4Setting : function(){
		var sRightSettingURL = "http://localhost:8080/wcm/auth/right_set.jsp?ObjType=103&ObjId=56";
		var dialogRightSetting = TRSDialogContainer.register("RightSettingDialog", "\u6743\u9650\u8BBE\u7F6E", sRightSettingURL, "700px", "600px", true, true, true);
		dialogRightSetting.onFinished = function(_args) {
			alert("dialogRightSetting.onFinished : _args = " + _args);
		}
	},
	_RegisterDialog4MainSetting : function(){
		var sRightSettingURL = "http://localhost:8080/wcm/auth/right_set.jsp?ObjType=103&ObjId=56";
		var dialogRightSetting = TRSDialogContainer.register("RightSettingDialog", "\u6743\u9650\u8BBE\u7F6E", sRightSettingURL, "700px", "600px", true, true, true);
		dialogRightSetting.onFinished = function(_args) {
			alert("dialogRightSetting.onFinished : _args = " + _args);
		}
		var sSerialCodeURL = "infoview_serial_code.htm";
		var dialogSerialCode = TRSDialogContainer.register("SerialCodeDialog", "\u7F16\u53F7\u8BBE\u7F6E", sSerialCodeURL, "650px", "450px", true, true, true);
		dialogSerialCode.onFinished = function(_args) {
			//alert(_args.HasDocSerial + " | " + _args.SerialPattern + " | " + _args.SerialPeriod + " | " + _args.SerialField);
			document.getElementById("HasDocSerial").value = _args.HasDocSerial || "0";
			document.getElementById("SerialPattern").value = _args.SerialPattern || "";
			document.getElementById("SerialPeriod").value = _args.SerialPeriod || "";
			document.getElementById("SerialField").value = _args.SerialField || "";
		}
		var sReplyNoticeURL = "infoview_reply_notice.htm";
		var dialogReplyNotice = TRSDialogContainer.register("ReplyNoticeDialog", "\u90AE\u4EF6\u56DE\u590D\u8BBE\u7F6E", sReplyNoticeURL, "500px", "450px", true, true, true);
		dialogReplyNotice.onFinished = function(_args) {
			//alert(_args.ReplyNoticeRequired + " | " + _args.NoticeRelatedField + " | " + _args.NoticeSubjectPattern + " | " + _args.NoticeContentPattern);
			document.getElementById("ReplyNoticeRequired").value = _args.ReplyNoticeRequired || "0";
			document.getElementById("NoticeRelatedField").value = _args.NoticeRelatedField || "";
			document.getElementById("NoticeSubjectPattern").value = _args.NoticeSubjectPattern || "-1";
			document.getElementById("NoticeContentPattern").value = _args.NoticeContentPattern || "";
		}
	},
	DocumentClicked : function(){
		if(PageContext.bClickFlag) {
			PageContext.bClickFlag = false;
			return;
		}
		_MenuContainer_.CloseAll();
		if(window.parent && window.parent._MenuContainer_)
			window.parent._MenuContainer_.CloseAll();
	},
	OnContextMenu : function(){
		if(PageContext.bContextMenuFlag) {
			PageContext.bContextMenuFlag = false;
			return false;
		}
		var oEvent = Event.findEvent();
		var oSrcElement = Event.element(oEvent);
		if(PageContext.isSettingMode()){
			if(PageContext.isMainPage()){
				(PageContext.Extend.GetViewMenuFunction(oSrcElement))();
			}
			return false;
		}
		if(PageContext.isEditableMode()){
			var oContainerElement = PageElementHelper.GetMyXctContainer(oSrcElement);
			if(oContainerElement != null) {
				var sContextMenuName = oContainerElement.getAttribute("trs_context_menu_name", 2);
				if(sContextMenuName == "FileUploadMenu") {
					var sUploadedFileName = null;
					var arrInputs = oContainerElement.getElementsByTagName("input");
					for(var i=0; i<arrInputs.length; i++) {
						if(arrInputs[i].type = "hidden") {
							var sValue = arrInputs[i].value;
							var regExp = /^\w\d+.\w+$/g;
							sUploadedFileName = sValue.match(regExp);
							break;
						}
					}
					PageContext.bClickFlag = true;
					_MenuContainer_.OpenMenu("FileUploadMenu", oContainerElement,
						{
							attach : {
								display : true,
								postfix	: null
							},
							open : {
								display : sUploadedFileName != null && sUploadedFileName != "",
								postfix	: null
							},
							remove : {
								display : sUploadedFileName != null && sUploadedFileName != "",
								postfix	: null
							}
						}
					);
				} else if(sContextMenuName != null){
					PageContext.bClickFlag = true;
					(PageContext.Extend.GetRepeatMenuFunction(oContainerElement))();
				}
				return false;
			}
		}
		_MenuContainer_.CloseAll();
		try {
			window.parent._MenuContainer_.CloseAll();
		} catch(error) {
		}
		return false;
	}
});
window.onload = PageContext.PageLoaded;
PageContext.bClickFlag = false;
document.onclick = PageContext.DocumentClicked;
PageContext.bContextMenuFlag = false;
document.oncontextmenu = PageContext.OnContextMenu;


TRSDialogContainer.getPageDimisions = function () {
	var oParent = document.body;
	var scroll = TRSDialogContainer.getScroll();
	return{
		width : scroll.width   == 0 ? oParent.clientWidth  : oParent.scrollWidth,
		height: $MOZ() ? oParent.scrollHeight : Math.max(oParent.scrollHeight, oParent.clientHeight),
		visibleWidth : oParent.clientWidth,
		visibleHeight: oParent.clientHeight
	}
}