document.write("<script src='/icons/icons/bevariables.js'></script>");//import public avariable js file
//Public Functions---------------------------------------------------------------

String.prototype.trim = function() {
	var x=this;
	x=x.replace(/^\s*(.*)/, "$1");
	x=x.replace(/(.?)\s*$/, "$1");
	return x;
}
Array.prototype.indexOf = function(psValue,pbCase){
	var lbCase = (pbCase==null)?false:pbCase;
	for(var i=0;i<this.length;i++){
		if(pbCase){
			if(this[i]==psValue) return i;
		}else{
			if(this[i].toLowerCase()==psValue.toLowerCase()) return i;
		}
	}
	return -1;
}
Array.prototype.remove = function(index){ 
	if(isNaN(index)||index>this.length){return false;} 
	this.splice(index,1); 
}
Array.prototype.returnIndex = function(psValue){ 
	for (var i=0;i<this.length;i++) if(psValue.trim().toUpperCase()==this[i].trim().toUpperCase()) return i;
	return -1;
}
function bIsNewDoc(){
	var lsSearch=window.location.search.toLowerCase();
	if (lsSearch.search(/openform/)!=-1)
		return true;
	else
		return false;
}
function sRepeatTime(psSource,piTime){
	var rsTmp="";
	for (i=0;i<piTime;i++)
		rsTmp += psSource;
	return rsTmp;
}

function sReplaceSubstring(psSource,psFrom,psTo){
	if (psFrom==null || psFrom=="" || psFrom==psTo) return psSource;
	var lpos=0;
	var lsReturn="";
	while (psSource.indexOf(psFrom)>-1){
		lpos= psSource.indexOf(psFrom);
		lsReturn += psSource.substring(0,lpos)+psTo;
		psSource=psSource.substring((lpos+psFrom.length), psSource.length);
	}
	lsReturn += psSource;
	if(lsReturn.substring(lsReturn.length-psFrom.length,lsReturn.length)==" "+psFrom.substring(0,psFrom.length-1))
		lsReturn=""+lsReturn.substring(0,lsReturn.length-psFrom.length+1)+psTo.substring(0,psTo.length-1);
	return lsReturn;
}

/*
bConfirm(psPrompt,piBtnType,psTitle,piWidth,piHeight)
piBtnType:1-OK,2-Cancel,4-Yes,8-No,example:Yes,No,Cancel£¬2+4+8=14
piWidth: default-300
piHeight:default-150
*/
var MB_OK=1,MB_CANCEL=2,MB_YES=4,MB_NO=8;
var MB_ICONSTOP=16,MB_ICONQUESTION=32,MB_ICONEXCLAMATION=64,MB_ICONINFORMATION=128;
function bConfirm(){
	var lvArguments=bConfirm.arguments;
	var laArg = new Array();
	laArg["Prompt"]=(lvArguments.length>0)?lvArguments[0]:"";
	laArg["BtnType"]=(lvArguments.length>1)?lvArguments[1]:12;
	laArg["Title"]=(lvArguments.length>2)?lvArguments[2]:"";
	var liWidth = (lvArguments.length>3 && lvArguments[3] != null && lvArguments[3] != "")?lvArguments[3]:300;
	var liHeight = (lvArguments.length>4 && lvArguments[4] != null && lvArguments[4] != "")?lvArguments[4]:150;
	return vOpenModal('/icons/icons/getConfirm.htm',laArg,liWidth,liHeight);
}

function OpenWindow(psURL,psTarget,piWidth,piHeight,psReSize,psScroll,psMenu,psStatus){
	if (psReSize==null) psReSize="yes";
	if (psScroll==null) psScroll="no";
	if (psMenu==null) psMenu="no";
	if (psStatus==null) psStatus="no";
	var liWidth=(piWidth<=1)?screen.width*piWidth:piWidth;
	var liHeight=(piHeight<=1)?screen.height*piHeight:piHeight;
	var liLeft=(screen.width-liWidth)/2;
	var liTop=(screen.height-liHeight)/2;
	if (liWidth==screen.width) liWidth=liWidth-9/800*liWidth;
	if (liHeight==screen.height) liHeight=liHeight-52/600*liHeight;

	var lmode = 'menubar='+psMenu+',resizable='+psReSize+',scrollbars='+psScroll+',';
	lmode += 'status='+psStatus+',toolbar=no,location=no,directories=no,';
	var lsize = 'left='+liLeft+',top='+liTop+',width='+liWidth+',height='+liHeight;
	var rnw = window.open(psURL,psTarget,lmode+lsize);
	return rnw;
}

function vOpenModal(psURL,pvArg,piWidth,piHeight,psStyle){
	var liWidth=(piWidth<=1)?screen.width*piWidth:piWidth;
	var liHeight=(piHeight<=1)?screen.height*piHeight:piHeight;
	if (psStyle==null) psStyle="";
	var lsModal = psStyle + " dialogWidth:"+liWidth+"px;dialogHeight:"+liHeight+"px;center:yes;status:no;help:no";
	var rvArg = showModalDialog( psURL,pvArg,lsModal);
	return rvArg;
}

function sSelectArray(psStyle,psTitle,psInfo,psArg,pbLimit,pbEmpty){
/*
psStyle£ºMultiple/Single/CheckBox/Radio
*/
	var laArg = new Array();
	laArg["Title"] = psTitle;
	laArg["PromptInfo"] = psInfo;
	laArg["ArgPara"] = sReplaceSubstring(psArg,",",";");
	var lbLimit = (pbLimit==null)?true:false;
	laArg["Limit"]=(lbLimit)?"1":"0";
	laArg["Empty"]=(pbEmpty==true)?"1":"0";
	var raArr = null;
	if (psStyle.toLowerCase()=="single") psStyle="Radio";
	if (psStyle.toLowerCase()=="multiple") psStyle="Checkbox";
	raArr = vOpenModal("/icons/icons/" + psStyle.toLowerCase() + "select.htm", laArg , 400 , 270);
	return raArr;
}

function sGetComment(psTitle,psInfo){
	var laArg = new Array();
	laArg["Title"] = (psTitle==null?"":psTitle);
	laArg["PromptInfo"] = (psInfo==null?"":psInfo);
	return vOpenModal('/icons/icons/getComment.htm',laArg,400,220);
}

function sGetInput(psTitle,psInfo,psInitValue,psInputType){
	var laArg = new Array();
	laArg["Title"] = (psTitle==null?"":psTitle);
	laArg["PromptInfo"] = (psInfo==null?"":psInfo);
	laArg["InitValue"] = (psInitValue==null?"":psInitValue);
	laArg["InputType"] = (psInputType==null?"":psInputType);
	return vOpenModal('/icons/icons/getInput.htm',laArg,400,150);
}

function sGetDateTime(psStyle,psTitle,psArg,psInfo){
/*
psStyle£º1/2/3/4
*/
	var laArg = new Array();
	laArg["Style"] = (psStyle==null?"":psStyle);
	laArg["Title"] = (psTitle==null?"":psTitle);
	laArg["PromptInfo"] = (psInfo==null?"":psInfo);
	laArg["ArgPara"] = (psArg==null?"":psArg);
	var raArr = null;
	if (psStyle!=null && (psStyle.indexOf("2")!=-1 || psStyle.indexOf("4")!=-1))
		raArr = vOpenModal("/icons/icons/getDateTime.htm", laArg , 220 , 280);
	else
		raArr = vOpenModal("/icons/icons/getDateTime.htm", laArg , 220 , 240);
	return raArr;
}

function bShowTable(psTitle,psInfo,pvValue){
	var laArg = new Array();
	laArg["Title"] = (psTitle==null?"":psTitle);
	laArg["PromptInfo"] = (psInfo==null?"":psInfo);
	laArg["Value"] = (pvValue==null?"":pvValue);
	//return vOpenModal('/icons/icons/showTable.htm',laArg,600,350);
	var loWin = OpenWindow('/icons/icons/showTable.htm','',600,350);
	loWin.dialogArguments = laArg;
}

function sGetParameter(psParaName,psQueryString,psSeparator){
	var lsQueryString=(psQueryString!=null)?psQueryString : (window.location.href);
	var lsSeparator=(psSeparator!=null)?psSeparator:"&";
	lsQueryString = lsSeparator+lsQueryString+lsSeparator+psParaName + "=" + lsSeparator;
	psParaName = lsSeparator+ psParaName + "=";
	var lsTemp=lsQueryString.toLowerCase();
	var lsName=psParaName.toLowerCase();
	var lsTmp=lsQueryString.substr(lsTemp.indexOf(lsName)+lsName.length);
	return lsTmp.substr(0,lsTmp.indexOf(lsSeparator));
}

function sSetParameter(psParaName,psParaValue,psQueryString,psSeparator){
	var lsSeparator1=(psSeparator!=null)?psSeparator:"&";
	var lsSeparator=lsSeparator1.toLowerCase();
	var lsQueryString1=(psQueryString!=null)?psQueryString: (window.location.href);
	var lsQueryString = lsSeparator + lsQueryString1.toLowerCase() + lsSeparator;
	var lsParaName = lsSeparator+ psParaName.toLowerCase() + "=";
	var liStartPos = lsQueryString.indexOf(lsParaName);
	var liEndPos = lsQueryString.indexOf(lsSeparator,liStartPos+lsSeparator.length);
	if (liStartPos==-1){
		if (psQueryString==null || psQueryString=="")
			var lsTemp=psParaName+"="+psParaValue;
		else
			var lsTemp=psQueryString+lsSeparator1+psParaName+"="+psParaValue;
		return lsTemp;
	}else{
		if (liStartPos<lsSeparator.length) liStartPos +=lsSeparator.length;
		var lsTemp=lsSeparator + lsQueryString1;
		if (lsQueryString1.toLowerCase().indexOf(lsParaName)!=-1){
			lsTemp= lsTemp.substr(lsSeparator.length,liStartPos-lsSeparator.length)+lsSeparator1+psParaName+"="+psParaValue + lsTemp.substr(liEndPos);
		}else{
			lsTemp= lsTemp.substr(lsSeparator.length,liStartPos-lsSeparator.length)+psParaName+"="+psParaValue + lsTemp.substr(liEndPos);
		}
		return lsTemp;
	}
}

function bOpenDatabase(psNav,psView){
	if (psNav!=null){
		if (psNav.trim().charAt(0)!="/" && psNav.indexOf("://")==-1) psNav = gsCurURL + psNav;
		top.NavIFrame.location.replace(psNav);
	}
	if (psView!=null){
		if (psView.trim().charAt(0)!="/" && psView.indexOf("://")==-1) psView = gsCurURL + psView;
		if (psView.toLowerCase().search("count=")==-1) psView += "&Count=" + giPCount;
		top.DefaultView=psView;
		if (typeof(top.PromptViewLoading)=="function" && (psView.trim().charAt(0)=="/" || psView.indexOf("://")==-1)) 
			top.PromptViewLoading();
		top.ViewIFrame.location.replace(psView);
	}
}

function CreateMenuBar(psBtnID,psImgID){//Create Form Bar or View Bar
	if (typeof document.all.MenuBar !="object") return false;
	var liFlag = (typeof top.ViewIFrame =="object" && typeof top.ViewIFrame.parent=="object") ? true:false;
	if (liFlag && typeof top.document=="object" && typeof top.document.all.ID_View_MenuBar !="object" && typeof top.ViewIFrame.parent.document.all.ID_View_MenuBar !="object") return false;
	if (!liFlag && typeof top.document=="object" && typeof top.document.all.ID_Form_MenuBar !="object") return false;
	if (liFlag==false && document.title!="" && document.title!=null) top.document.title = document.title;
	lsHead = (liFlag)?"top.ViewIFrame.":"top.ContentBody.";
	if (typeof top.document=="unknown") lsHead="window.MailIframe.";
	var lsHTML = "<table border='0' cellpadding='0' cellspacing='0' class=MenuBar><tr id=ID_MenuBar>\n";
	var lsBtnID = (psBtnID!=null && psBtnID!="")?psBtnID:"MenuBtn";
	var lsImgID = (psImgID!=null && psImgID!="")?psImgID:"MenuImg";
	var oMenus = document.getElementsByName(lsBtnID);
	var oMenuImgs = document.getElementsByName(lsImgID);
	var lsEvent='',lsWidth='null',lsTD='';
	if (oMenus!=null){
		for (i=0; i<oMenus.length;i++){
			lsHTML += "<td class=MenuInterval nowrap>&nbsp;</td>";
			lsHTML += "<td class=MenuBtn nowrap onMouseDown='this.className=\"MenuBtnInset\"' onMouseUp='this.className=\"MenuBtn\"' onMouseOver='this.className=\"MenuBtnOutset\"' onMouseOut='this.className=\"MenuBtn\"' onclick=\"";
			lsEvent = lsHead + "document.getElementsByName('" + lsBtnID + "')[" + i + "].click();";
			lsTD = oMenus[i].innerText;
			if (oMenus[i].PopMenuID!=null && oMenus[i].PopMenuID!=""){
				lsWidth='null'
				if (oMenus[i].PopMenuWidth!=null && oMenus[i].PopMenuWidth!="") lsWidth=oMenus[i].PopMenuWidth;
				lsEvent = "showMenu('"+oMenus[i].PopMenuID+"',"+lsWidth+",'"+lsHead.substr(0,lsHead.length-1)+"');";
				lsTD = oMenus[i].innerText + "<img src='"+gsImgURL+"bg_Interval.gif' align='absmiddle' width=5 height=1><img src='"+gsImgURL+"ico_Menu_Popup.gif' align='absmiddle'>";
			}
			lsHTML += lsEvent + "\" title='"+oMenus[i].title+"'><img src='"+gsImgURL+oMenuImgs[i].innerText+"' align='absmiddle'>"+ lsTD + "</td>\n";
		}
	}
	lsHTML += "<td width=100% class=MenuInterval>&nbsp;</td>\n";
	if (typeof document.all.ID_PromptMsg=="object")
		lsHTML += "<td width=10% nowrap class=MenuInterval>"+document.all.ID_PromptMsg.innerHTML+"</td>\n";
	lsHTML += "</tr></table>\n";
	if (liFlag == true ) {
		window.parent.document.all.ID_View_MenuBar.innerHTML = lsHTML;
		if(typeof  window.parent.document.all.SelectAll == "object"){
			if (typeof document.all.$$SelectDoc=="object"){
				window.parent.document.all.SelectAll.style.display = "block";
				window.parent.document.all.SelectAll.checked = false;
			}else
				window.parent.document.all.SelectAll.style.display="none";
		}
		if (typeof window.parent.document.all.hMenuTable=="object")
			window.parent.document.all.hMenuTable.style.display = "block";
	}else{
		top.document.all.ID_Form_MenuBar.innerHTML = lsHTML;
		window.focus();
	}
}

//Form Functions--------------------------------------------------
/*
PromptUnit(pbModal,psTargetFieldName,psViewName,psWindowTitle,pbShowCategoryBox,pbMultiChoice, piShowOnly,psShowType,pbParentValue,pbSelPrvGroup)
*/
function PromptUnit(){
	var lvArguments=PromptUnit.arguments;
	if (lvArguments.length<2) return false;

	var lbModal=lvArguments[0];
	var lsTarget="&ReturnTarget="+escape(lvArguments[1]);	
	var lsViewName=(lvArguments.length>=3)?lvArguments[2]:"";
	var lsDBName = "";
	if(lsViewName != ""){
		if(lsViewName.indexOf("|") != -1){
			lsDBName = "&DBName=" + lsViewName.substr(0,lsViewName.indexOf("|"));
			lsViewName = lsViewName.substr(lsViewName.indexOf("|") + 1);
		}
		lsViewName = "&ViewName=" + lsViewName;
	}
	
	var lsWinTitle=(lvArguments.length>=4)?("&WindowTitle="+escape(lvArguments[3])):"";
	var lsShowCategoryBox = "&SearchBar=1&Unit=1";
	if(lvArguments.length>=5){
		if(lvArguments[4] == -1){
			lsShowCategoryBox = lsShowCategoryBox.replace("&SearchBar=1&Unit=1","");
		}else if(lvArguments[4] == true){
			lsShowCategoryBox += "&CategoryBox=1";
		}else if(lvArguments[4] != false){
			if((lvArguments[4] & 2) != 2) lsShowCategoryBox = lsShowCategoryBox.replace("&Unit=1","");
			if((lvArguments[4] & 4) == 4) lsShowCategoryBox += "&CategoryBox=1";
			if((lvArguments[4] & 8) != 8) lsShowCategoryBox = lsShowCategoryBox.replace("&SearchBar=1","");
			//if((lvArguments[4] & 16) != 16) lsShowCategoryBox = lsShowCategoryBox.replace("&Private=1","");
			//if((lvArguments[4] & 32) == 32) lsShowCategoryBox += "&Address=1";
		}
	}
	var lsMultiChoice=(lvArguments.length>=6 && lvArguments[5]==true)?"&MultiChoice=1":"";
	var lsShowOnly = "";
	if(lvArguments.length>=7){
		if(lvArguments[6] == true){
			lsShowOnly += "&RoleOnly=1";
		}else{
			if((lvArguments[6] & 2) == 2){
				lsShowOnly += "&RoleOnly=1";
			}
			if((lvArguments[6] & 4) == 4){
				lsShowOnly += "&UserOnly=1";
			}
			if((lvArguments[6] & 8) == 8){
				lsShowOnly += "&ExDeptOnly=1";
			}
		}
	}
	var lsShowType=(lvArguments.length>=8 && lvArguments[7]!="")?("&ShowType="+escape(lvArguments[7])):"";
	var lsParentValue=(lvArguments.length>=9 && lvArguments[8]==true)?"&ParentValue=1":"";
	var lsSelPrvGroup = (lvArguments.length>=10 && lvArguments[9]==false)?"&SelPrvGroup=0":"";
	var liWidth=550;
	var liHeight=500;
	var lsMode="Directory=no,Menu=no,Status=no,ScrollBars=no,Resizable=yes,";
	var lsSize="left="+(screen.width-liWidth)/2+",top="+(screen.Height-liHeight-50)/2 + ",width="+liWidth+",height="+liHeight;
	var lsWinName="SelectUnit";
	var lsURL=encodeURI(gsOAURL)+sGetLang("DB_NAME_UNITADM")+"/frmSelectUnit?OpenForm"
	var lsURLArguments=lsTarget+lsWinTitle+lsShowCategoryBox+lsMultiChoice+lsShowOnly+lsShowType+lsParentValue+lsDBName+lsSelPrvGroup;
	if(lbModal){
		if(lvArguments.length>=1 && lvArguments[1]!=""){
			var lsTemp = lvArguments[1];
		}else{
			var lsTemp = sGetLang("UNIT_DEFAULTCATE");
		}
		lsTemp=lsTemp.replace(/,/g,";");		
		var laCategory = lsTemp.split(";");		
		var laTarget = lvArguments[1].replace(/,/g,";").split(";");
		var laArg = new Array();
		var laValue = new Array();
		for(var i = 0; i < laCategory.length;i++){
			var lsTarget = (laTarget[i].indexOf("|")==-1)?laTarget[i]:laTarget[i].substr(0,laTarget[i].indexOf("|"));
			if(typeof goForm=="object" && typeof goForm.elements[lsTarget] == "object"){
				laValue[i] = goForm.elements[lsTarget].value;
			}else{
				laValue[i] = "";
			}
		}
		laArg["InitValue"] = laValue;
		laArg["ViewName"] = lsViewName;
		return vOpenModal(lsURL+lsURLArguments,laArg,liWidth,liHeight);
	}else{
		window.UnitViewName = lsViewName;
		window.open(lsURL+lsURLArguments,lsWinName,lsMode+lsSize);
	}
}

/*
PromptDiction(psFieldName,psCategory,pbMultiChoice)
*/

function PromptDiction(){
	var lvArguments = PromptDiction.arguments;
	if (lvArguments.length<1) return false;
	var lsTarget="&ReturnTarget="+lvArguments[0];
	var lsCategory = "&Category="
	lsCategory += (lvArguments.length>=2)?escape(lvArguments[1]):"";
	var lsMultiChoice=(lvArguments.length>=3 && lvArguments[2]==true)?"&MultiChoice=1":"";
	var lsURL = encodeURI(gsOAURL) + gsDCDBName +"/frmSelectDiction?Openform"+lsTarget+lsCategory + lsMultiChoice;
	OpenWindow(lsURL,"SelectDiction",300,500,"no")
}

/*
PromptThemes(psFieldName,pbMultiChoice,pbModel)
*/
function PromptThemes(){
	var lvArguments = PromptThemes.arguments;
	if (lvArguments.length<1) return false;
	var lsTarget=lvArguments[0];
	var lbMultiChoice=(lvArguments.length>=2)?lvArguments[1]:false;
	var lbModel = (lvArguments.length>=3)?lvArguments[2]:false;
	var lsURL = encodeURI(gsOAURL) + gsDCDBName +"/frmWThemeTree?Openform";
	PromptView(lbModel,lvArguments[0],lsURL,sGetLang("DICTION_SELECTTHEME"),lbMultiChoice);
}

/*
PromptPrintTemplate(psFieldName,psCategory,pbMultiChoice)
*/

function PromptPrintTemplate(pbModal,psFieldName,psCategory,pbMultiChoice){
	var lsCategory = "&Category="
	lsCategory += (psCategory!=null)?escape(psCategory):"";
	var lsURL = encodeURI(gsOAURL) + gsDCDBName +"/agtTemplateTree?OpenAgent&Type=Print"+lsCategory;
	return PromptTree(pbModal,psFieldName,lsURL,sGetLang("DICTION_PRINTTEMPLATE"),pbMultiChoice);
}

/*
PromptFileTemplate(psFieldName,psCategory,pbMultiChoice)
*/

function PromptFileTemplate(pbModal,psFieldName,psCategory,pbMultiChoice){
	var lsCategory = "&Category="
	lsCategory += (psCategory!=null)?escape(psCategory):"";
	var lsURL = encodeURI(gsOAURL) + gsDCDBName +"/agtTemplateTree?OpenAgent&Type=File"+lsCategory;
	return PromptTree(pbModal,psFieldName,lsURL,sGetLang("DICTION_FILETEMPLATE"),pbMultiChoice);
}

/*
PromptNameBook(pbModal,psViewName,psWindowTitle,pbShowCategoryBox)
*/
function PromptNameBook(){
	var lvArguments=PromptNameBook.arguments;
	if (lvArguments.length<2) return false;
	var lbModal=lvArguments[0];
	var lsViewName=(lvArguments.length>=2)?("&ViewName="+lvArguments[1]):"";
	var lsWinTitle=(lvArguments.length>=3)?("&WindowTitle="+escape(lvArguments[2])):"";
	var lsShowCategoryBox=(lvArguments.length>=4 && lvArguments[3]==true)?"&ShowCategoryBox=1":"";
	var liWidth=screen.width/2,liHeight=screen.height*5/6;
	var lsMode="Directory=no,Menu=no,Status=no,ScrollBars=no,Resizable=yes,";
	var lsSize="left="+(screen.width-liWidth-10)+",top="+(screen.Height-liHeight-70) + ",width="+liWidth+",height="+liHeight;
	var lsWinName="NameBook";
	var lsURL=encodeURI(gsOAURL)+sGetLang("DB_NAME_UNITADM")+"/frmNameBook?OpenForm"

	var lsURLArguments=lsViewName+lsWinTitle+lsShowCategoryBox;
	if(lbModal)
		return vOpenModal(lsURL+lsURLArguments,lvArguments[1],liWidth,liHeight);
	else
		window.open(lsURL+lsURLArguments,lsWinName,lsMode+lsSize);
}


function PrnByTemplate(psDBPath,psUNID,psTemplate){
	var lbFlag = (typeof top.ViewIFrame =="object") ? true:false;
	if (lbFlag==true){
		if (typeof top.document!="unknown"){
			var loframe= top.ViewIFrame;
		}else{
			var loframe= window.MailIframe;
		}
		var lsIDs = sGetSelected(sGetLang("P_PRNBYTEMPLATE_DOCNOTFOUND"));
		if(lsIDs=="") return false;
		if(window.confirm(sGetLang("P_PRNBYTEMPLATE_CONTINUE"))==false) return false;
		lsIDs = sReplaceSubstring(lsIDs.substring(0,lsIDs.length-1),"|",";");
		loframe.docIDs = lsIDs;
		var lsTemplate = "";
		if (typeof (loframe.document.all.hPrintTemplate)=="object")
			lsTemplate = loframe.document.all.hPrintTemplate.innerText;
		var lsURL=encodeURI(gsOAURL)+gsSRDBName+"/agtPrintByTemplate?Openagent&Template="+lsTemplate;
		loframe.RunAgent.location.replace(lsURL);
	}else{
		if (psDBPath!=null && psDBPath!="") window.argDBName = psDBPath;
		if (psUNID!=null && psUNID!="")
			window.docIDs = psUNID;
		else
			window.docIDs = gsCurUNID;
		if (psTemplate!=null && psTemplate!="") window.argTemplate = psTemplate;
		var lsURL=encodeURI(gsOAURL)+gsSRDBName+"/frmPrnByTemplate?Openform";
		top.RunAgent.location.replace(lsURL);
	}
}

//View Functions----------------------------------------

function BeginPage(){ShowPage(0);}

function PriorPage(){ShowPage(1);}

function NextPage(){ShowPage(2);}

function EndPage(){ShowPage(3);}

function Ascend(piIndex){ShowPage(9,piIndex);event.cancelBubble=true;}

function Descend(piIndex){ShowPage(-9,piIndex);event.cancelBubble=true;}

function ColumnSort(piIndex){
	if (typeof top.document!="unknown"){
		var loframe= top.ViewIFrame;
	}else{
		var loframe= top.ViewIFrame.MailIframe;
	}
	var lshref = (loframe.location.href);
	var lsDescend = sGetParameter("ResortDescending",lshref);
	var lsAscend = sGetParameter("ResortAscending",lshref);
	if (lsDescend=="" && lsAscend=="" || lsAscend!="" && lsAscend-0!=piIndex || lsDescend!="" && lsDescend-0!=piIndex)
		ShowPage(9,piIndex);
	else if(lsAscend!="" && lsAscend-0==piIndex)
		ShowPage(-9,piIndex);
	else if(lsDescend!="" && lsDescend-0==piIndex)
		ShowPage(-10,piIndex);
}

function CollapseView(){
	if (typeof top.document!="unknown"){
		var loframe= top.ViewIFrame;
	}else{
		var loframe= top.ViewIFrame.MailIframe;
	}
	if (typeof loframe.document.all.hViewName != "object" || typeof loframe.FTObject=="object") return false;
	var lsURL=(loframe.location.href);
	var lsDescend = sGetParameter("ResortDescending",lsURL);
	var lsAscend = sGetParameter("ResortAscending",lsURL);
	if (lsDescend!="" || lsAscend!="") return false;
	var lsTemp = sGetParameter("Collapse",lsURL);
	if (lsTemp!="") lsURL = sReplaceSubstring(lsURL,"&Collapse="+lsTemp,"");
	lsTemp = sGetParameter("Expand",lsURL);
	if (lsTemp!="") lsURL = sReplaceSubstring(lsURL,"&Expand="+lsTemp,"");
	lsURL=sReplaceSubstring(lsURL,"&ExpandView","");
	if (lsURL.search("CollapseView")==-1){
		if (lsURL.indexOf("&")!=-1)
			lsURL=lsURL.substring(0,lsURL.indexOf("&"))+"&CollapseView"+lsURL.substring(lsURL.indexOf("&"),lsURL.length);
		else
			lsURL=lsURL+"&CollapseView";
	}
	PromptViewLoading();
	if (lsURL.toLowerCase()==loframe.location.href.toLowerCase()){
		loframe.location.reload(true);
		if(top.SelectView == "1" && top.dialogArguments!=null)
			HideViewLoading();
	}else{
		loframe.location.replace(lsURL);
	}
}

function ExpandView(){
	if (typeof top.document!="unknown"){
		var loframe= top.ViewIFrame;
	}else{
		var loframe= top.ViewIFrame.MailIframe;
	}
	if (typeof loframe.document.all.hViewName != "object" || typeof loframe.FTObject=="object") return false;
	var lsURL=(loframe.location.href);
	var lsDescend = sGetParameter("ResortDescending",lsURL);
	var lsAscend = sGetParameter("ResortAscending",lsURL);
	if (lsDescend!="" || lsAscend!="") return false;
	var lsTemp = sGetParameter("Collapse",lsURL);
	if (lsTemp!="") lsURL = sReplaceSubstring(lsURL,"&Collapse="+lsTemp,"");
	lsTemp = sGetParameter("Expand",lsURL);
	if (lsTemp!="") lsURL = sReplaceSubstring(lsURL,"&Expand="+lsTemp,"");
	lsURL = sReplaceSubstring(lsURL,"&CollapseView","");
	if (lsURL.search("ExpandView")==-1){
		if (lsURL.indexOf("&")!=-1)
			lsURL=lsURL.substring(0,lsURL.indexOf("&"))+"&ExpandView"+lsURL.substring(lsURL.indexOf("&"),lsURL.length);
		else
			lsURL=lsURL+"&ExpandView";
	}
	PromptViewLoading();
	if (lsURL.toLowerCase()==loframe.location.href.toLowerCase()){
		loframe.location.reload(true);
		if(top.SelectView == "1" && top.dialogArguments!=null)
			HideViewLoading();
	}else{
		loframe.location.replace(lsURL);
	}
}

function bCollapse(psURL){
	var liPage = document.all.dPage.innerText-0;
	var lsURL = sSetParameter("dPage",liPage,psURL);
	var lsStart1 = sGetParameter("Start");
	if (lsStart1=="") lsStart1="1";
	var lsStart2 = sGetParameter("Start",psURL);
	if (lsStart1!=lsStart2){
		if (sReplaceSubstring(lsStart1,".","")-0<sReplaceSubstring(lsStart2,".","")-0)
			liPage++;
		else
			liPage--;
		lsURL = sSetParameter("dPage",liPage,lsURL);
	}
	var lsValue = sGetParameter("Collapse",lsURL);
	var lodoc=window.document;
	var liType = lodoc.all.hViewType.innerText - 0;
	var lsCategory = lodoc.all.hCategory.innerText.trim();
	if (liType > 2 && lsCategory!=""){
		var lsTemp = sGetParameter("RestrictToCategory",lsURL);
		if (lsTemp!=null && lsTemp!=""){
			lsURL = sReplaceSubstring(lsURL,"&RestrictToCategory="+lsTemp,"");
			lsCategory = lsTemp;
		}
		lsURL=sReplaceSubstring(lsURL,"&Collapse="+lsValue,"&RestrictToCategory="+lsCategory+"&Collapse="+lsValue);
	}
	lsURL += "#"+lsValue;
	var lsArgViewName = sGetParameter("argView");
	if (lsArgViewName!=null && lsArgViewName!="")
		lsURL=sReplaceSubstring(lsURL,"&Collapse="+lsValue,"&Collapse="+lsValue+"&argView="+lsArgViewName);
	PromptViewLoading();
	window.location.replace(lsURL);
	event.cancelBubble=true;
}

function bExpand(psURL){
	var liPage = document.all.dPage.innerText-0;
	var lsURL = sSetParameter("dPage",liPage,psURL);
	var lsStart1 = sGetParameter("Start");
	if (lsStart1=="") lsStart1="1";
	var lsStart2 = sGetParameter("Start",psURL);
	if (lsStart1!=lsStart2){
		if (sReplaceSubstring(lsStart1,".","")-0<sReplaceSubstring(lsStart2,".","")-0)
			liPage++;
		else
			liPage--;
		lsURL = sSetParameter("dPage",liPage,lsURL);
	}
	var lsValue = sGetParameter("Expand",lsURL);
	var lodoc=window.document;
	var liType = lodoc.all.hViewType.innerText - 0;
	var lsCategory = lodoc.all.hCategory.innerText.trim();
	if (liType > 2 && lsCategory!=""){
		var lsTemp = sGetParameter("RestrictToCategory",lsURL);
		if (lsTemp!=null && lsTemp!=""){
			lsURL = sReplaceSubstring(lsURL,"&RestrictToCategory="+lsTemp,"");
			lsCategory = lsTemp;
		}
		lsURL=sReplaceSubstring(lsURL,"&Expand="+lsValue,"&RestrictToCategory="+lsCategory+"&Expand="+lsValue);
	}
	lsURL += "#"+lsValue;
	var lsArgViewName = sGetParameter("argView");
	if (lsArgViewName!=null && lsArgViewName!="")
		lsURL=sReplaceSubstring(lsURL,"&Expand="+lsValue,"&Expand="+lsValue+"&argView="+lsArgViewName);
	PromptViewLoading();
	window.location.replace(lsURL);
	event.cancelBubble=true;
}

function ViewRefresh(){
	if (typeof top.document!="unknown"){
		var loframe= top.ViewIFrame;
	}else{
		var loframe= top.ViewIFrame.MailIframe;
	}
	PromptViewLoading();
	if(top.SelectView == "1" && top.dialogArguments!=null) {
		if((loframe.location.href.indexOf("Expand=")!=-1 || loframe.location.href.indexOf("Collapse=")!=-1))
			HideViewLoading();
		else
			loframe.location.replace(loframe.location.href);
	}
	else loframe.location.reload();
}

function bViewSearch(pbMultipleView){
	if (hFTSTable.style.display!='none') return false;
	if (typeof top.document!="unknown"){
		var loframe= top.ViewIFrame;
	}else{
		var loframe= top.ViewIFrame.MailIframe;
	}
	var lodoc = loframe.document;
	if (typeof lodoc.all.FTSViewName != "object") return false;
	if (typeof lodoc.all.hViewBody != "object") return false;
	var liType = lodoc.all.hViewType.innerText - 0;
	if ((liType==2 || liType==4) && typeof lodoc.all.ID_ViewCommand=="object")
		window.categoryPageIndex = document.all.dPage.innerText;
	hFTSCount.innerText="0";
	hFTSKeyWords.innerText="";
	hFTSTable.style.display='';
	if (document.all.KeyWord.offsetHeight>0) document.all.KeyWord.focus();
	document.all.ID_FTSearch.style.display=(pbMultipleView==true)?'none':"";
	document.all.ID_FTSearch.parentElement.style.display=(pbMultipleView==true)?'none':"";
	if (typeof document.all.ID_FTAnonymous=="object") document.all.ID_FTAnonymous.parentElement.style.display=(pbMultipleView==true)?'none':"";
	document.all.ID_FTClearSearch.parentElement.style.display=(pbMultipleView==true)?'none':"";
	return false;
}

function bClearSearch(){
	hButtonTable.style.display='';
	hFTSTable.style.display='none';
	if (document.all.hFTSKeyWords.innerText.trim()!=""){
		if (typeof top.document!="unknown"){
			var loframe= top.ViewIFrame;
		}else{
			var loframe= top.ViewIFrame.MailIframe;
		}
		var lodoc = loframe.document;
		var lsURL = loframe.location.href;
		var liType = lodoc.all.hViewType.innerText - 0;
		if ((liType==2 || liType==4) && typeof lodoc.all.ID_ViewCommand=="object" && loframe.FTObject!=null && loframe.FTObject.categoryPageIndex!=null && loframe.FTObject.categoryPageIndex-0>1 && sGetParameter("dPage",lsURL)==""){
			lsURL = sSetParameter("dPage",loframe.FTObject.categoryPageIndex,lsURL);
			loframe.location.replace(lsURL);
		}else{
			if(top.SelectView == "1") loframe.location.replace(lsURL);
			else loframe.location.reload(true);
		}
	}
	hFTSCount.innerText="0";
	hFTSKeyWords.innerText="";
	document.all.KeyWord.value="";
	return false;
}

function bSiteFTSearch(psQueryName,paDBView,psQueryString,psQueryTitle){
	window.SiteQueryName = psQueryName;
	if (paDBView!=null && psQueryString!=null){
		if (psQueryTitle!=null){
			var loObject = new Object();
			loObject.sQueryUniqueName = psQueryTitle;
		}
		parent.bMultipleFTSearch(paDBView,psQueryString,loObject);
	}else{
		parent.FTSearch(false,true,false,psQueryName);
	}
}

function FTSearch(pbSecond,pbExtension,pbShowAnonymous,psQueryName){
	if (typeof top.document!="unknown"){
		var loframe= top.ViewIFrame;
	}else{
		var loframe= top.ViewIFrame.MailIframe;
	}
	var lodoc = loframe.document;
	if (pbShowAnonymous!=null && pbShowAnonymous==true){
		document.all.KeyWord.value = "<Anonymous>";
	}
	if (pbExtension && loframe.SiteQueryName!=null && psQueryName==null) psQueryName = loframe.SiteQueryName;
	var lsDB = (typeof lodoc.all.FTSDBPath=="object")?lodoc.all.FTSDBPath.innerText:loframe.gsCurURL.substr(1) + loframe.gsCurDBName;
	var lsViewName = (typeof lodoc.all.FTSViewName=="object")?lodoc.all.FTSViewName.innerText:"";
	var lsKeyWord = document.all.KeyWord.value;
	if (pbExtension==true){
		var loObject = (loframe.FTObject!=null)?loframe.FTObject:new Object();
		if (psQueryName==null){
			if (lsKeyWord!="" && (loObject.KeyWords==null || loObject.KeyWords=="")) loObject.KeyWords = lsKeyWord;
		}else{
			//document.all.KeyWord.value="";
		}
		var lsQueryName = (psQueryName!=null)?psQueryName:((loObject.sQueryName!=null)?loObject.sQueryName:((typeof lodoc.all.FTSQueryName=="object")?lodoc.all.FTSQueryName.innerText:""));
		if(loObject.sStatus == null){if(lsQueryName == "") loObject.sStatus = "1";else loObject.sStatus="2"};
		loObject.DB = lsDB;
		if(loObject.sStatus == "1"){
			var lsTempURL = gsOAURL+sGetLang("DB_NAME_SCHSTAT")+"/agtFTSQuery?OpenAgent&DBName="+lsDB+"&ViewName="+lsViewName;
			loframe.RunAgent.location.replace(lsTempURL);
			return true;
		}else if(loObject.sStatus == "2"){
			var lsReturnDB = (psQueryName==null)?"":((typeof lodoc.all.ID_FTSearchDBView=="object" && lodoc.all.ID_FTSearchDBView.innerText !="")?"":"&ReturnDB=1");
			var lsTempURL = gsOAURL+sGetLang("DB_NAME_SCHSTAT")+"/agtFTSQuery?OpenAgent&QueryName="+escape(lsQueryName)+lsReturnDB;
			loframe.RunAgent.location.replace(lsTempURL);
			return true;
		}
		loObject.Second = null;
		loObject.sStatus = null;
		loObject.sQueryName = null;
		loObject.extension = true;
		loObject.QueryName = psQueryName;
		loObject.OldQueryName = lsQueryName;
	}else{
		var loObject = (loframe.FTObject!=null && pbSecond==true)?loframe.FTObject:new Object();
		loObject.DB = lsDB;
		if (pbSecond==true && loObject.View==null && loObject.MultipleViews==null) return false;
		//document.all.KeyWord.value = "";
		if (lsKeyWord.trim()=="") {alert(sGetLang('P_NOKEYWORD'));return false;}
		if (pbSecond==true && loObject.extension==true)
			loObject.extension = true;
		else
			loObject.extension = false;
		if (pbSecond==true){
			loObject.Second = lsKeyWord;
		}else{
			loObject.Second = null;
			loObject.KeyWords = lsKeyWord;
		}
	}
	if (typeof lodoc.all.ID_FTSearchDBView=="object" && lodoc.all.ID_FTSearchDBView.innerText!=null && lodoc.all.ID_FTSearchDBView.innerText!="")
		loObject.aSearchView=lodoc.all.ID_FTSearchDBView.innerText.split(";");
	if (loObject.extension == true || loObject.aSearchView!=null){
		lsKeyWord = sGetLang('P_FTS_EXTENSION');
	}else{
		lsKeyWord = loObject.KeyWords;
	}
	if (loObject.Second!=null){lsKeyWord += " " + loObject.Second;}
	document.all.hFTSKeyWords.innerText=lsKeyWord;

	bMultipleFTSearch(loObject.aSearchView,null,loObject);
}

function FTSaveSearch(){
	var lsName = sGetInput(sGetLang("P_FTS_SAVEQUERYTITLE"),"","");
	if (lsName==null || lsName=="") return false;
	if (typeof top.document!="unknown") var loframe= top.ViewIFrame;
	else var loframe= top.ViewIFrame.MailIframe;
	if (loframe.FTObject==null) return false;
	var lsURL=encodeURI(gsOAURL) + gsSRDBName + "/frmFTSearch?OpenForm&IsSave=1";
	if (typeof loframe.RunAgent=="object"){
		loframe.FTObject.SaveName = lsName;
		loframe.RunAgent.location.replace(lsURL);
	}else if (typeof top.RunAgent=="object"){
		top.FTObject.SaveName = lsName;
		top.RunAgent.location.replace(lsURL);
	}
	return true;
}

function FTShowSearch(poObject){
	if (poObject!=null){
		parent.document.all.hFTSKeyWords.innerText=poObject.name;
		var loObject = new Object();
		loObject.DB = poObject.db;
		loObject.View = poObject.view;
		loObject.aSearchView = poObject.multipleviews;
		loObject.MultipleViews = (poObject.multipleviews!=null)?poObject.multipleviews.join("\n"):null;
		loObject.Count = poObject.count;
		loObject.Category = poObject.category;
		loObject.QueryName = poObject.queryname;
		loObject.sQueryUniqueName = poObject.squeryname;
		loObject.Type=poObject.type;
		loObject.DataType=poObject.datatype;
		loObject.ExtQueryString = poObject.querystring;
		loObject.SearchWV=sGetParameter("SearchWV",poObject.queryarg);
		loObject.SearchOrder=sGetParameter("SearchOrder",poObject.queryarg);
		loObject.SearchMax=sGetParameter("SearchMax",poObject.queryarg);
		if (poObject.type=="1"){//old agent model
			parent.bMultipleFTSearch(null,null,loObject,true);
		}else{
			if (poObject.dbviews==null || poObject.exequerystring==null){
				window.parent.HideViewLoading();
				alert(sGetLang("P_FTS_QUERYSTRINGERROR"));
				return false;
			}
			window.FTObject = loObject;
			parent.bMultipleFTSearch(null,null,loObject,true,true);
			bExecuteFTSearch(poObject.dbtitles,poObject.dbviews,poObject.exequerystring);
		}
		return true;
	}
	if (typeof top.document!="unknown") var loframe= top.ViewIFrame;
	else var loframe= top.ViewIFrame.MailIframe;
	if (typeof loframe.RunAgent=="object") var loObject = loframe.FTObject;
	else if (typeof top.RunAgent=="object")var loObject = top.FTObject;
	var lsQueryName="",lsDB="",lsViewName="";
	if (loObject!=null){
		if (loObject.QueryName!=null && loObject.QueryName!="") lsQueryName = loObject.QueryName;
		if (loObject.DB!=null && loObject.DB!="") lsDB = loObject.DB;
		if (loObject.View!=null && loObject.View!="") lsViewName = loObject.View;
	}else{
		if(loframe.SiteQueryName!=null && loframe.SiteQueryName!="") lsQueryName = loframe.SiteQueryName;
		if(typeof loframe.document.all.FTSViewName=="object") lsViewName = loframe.document.all.FTSViewName.innerText;
		lsDB = (typeof loframe.document.all.FTSDBPath=="object")?loframe.document.all.FTSDBPath.innerText:loframe.gsCurURL.substr(1) + loframe.gsCurDBName;
	}
	var lsURL=encodeURI(gsOAURL) + gsSRDBName + "/agtShowSearch?OpenAgent&QueryName="+lsQueryName+"&DB="+encodeURI(lsDB)+"&View="+lsViewName;
	if (typeof loframe.RunAgent=="object"){
		loframe.RunAgent.location.replace(lsURL);
	}else if (typeof top.RunAgent=="object"){
		top.RunAgent.location.replace(lsURL);
	}
}

function bMultipleFTSearch(paMultipleDBView,psQueryString,poObject,pbNotSetProperty,pbNotOpenURL){
	if (typeof top.document!="unknown") var loframe= top.ViewIFrame;
	else var loframe= top.ViewIFrame.MailIframe;
	var lodoc = loframe.document;
	var loObject = (poObject!=null)?poObject:new Object();
	
	if (pbNotSetProperty!=true){
		if (paMultipleDBView!=null){
			if (typeof paMultipleDBView == "string")
				loObject.MultipleViews = paMultipleDBView;
			else
				loObject.MultipleViews = paMultipleDBView.join("\n");
		}else{
			loObject.MultipleViews = null;
		}
		if (psQueryString!=null) loObject.ExtQueryString = psQueryString;
		
		loObject.DB = (typeof lodoc.all.FTSDBPath=="object")?lodoc.all.FTSDBPath.innerText:loframe.gsCurURL.substr(1) + loframe.gsCurDBName;	
		loObject.View = (typeof lodoc.all.FTSViewName=="object")?lodoc.all.FTSViewName.innerText:"";
		loObject.QueryString=(typeof lodoc.all.FTSQuery=="object")?lodoc.all.FTSQuery.innerText.trim():"";
		loObject.Type = (typeof lodoc.all.FTSType=="object")?lodoc.all.FTSType.innerText.trim():"";
		var lsDataType = "1";//new view format
		if (typeof lodoc.all.hViewType=="object" && (lodoc.all.hViewType.innerText=="2" || lodoc.all.hViewType.innerText=="4") && (typeof lodoc.all.hViewBody!="object" || lodoc.all.hViewBody.NewFormat!="1"))
			lsDataType = "0";//old view format
		if (typeof lodoc.all.hCabID=="object" && lodoc.all.hCabID.innerText!=""){
			var lsTemp = "/"+sReplaceSubstring(loObject.DB.toLowerCase(),"\\","/");
			lsTemp = lsTemp.substring(lsTemp.lastIndexOf("/")+1,lsTemp.length);
			if (lsTemp == "zc"+lodoc.all.hCabID.innerText.toLowerCase()+".nsf") lsDataType = "2";//kmcab view format
		}
		loObject.DataType = lsDataType;
		loObject.Category=(typeof lodoc.all.hCategory=="object")?lodoc.all.hCategory.innerText.trim():"";
	}
	
	if (window.categoryPageIndex!=null){
		loObject.categoryPageIndex = window.categoryPageIndex;
		window.categoryPageIndex = null;
	}
	if (loObject.Count!=null && typeof document.all.ID_PageCount=="object") document.all.ID_PageCount.innerText=loObject.Count;
	if (typeof document.all.tPage=="object")document.all.tPage.innerText="1";
	if (typeof document.all.dPage=="object")document.all.dPage.innerText="1";
	if (typeof lodoc.all.dPage=="object") lodoc.all.dPage.innerText = "1";
	PromptViewLoading(sGetLang("P_CONST_SEARCH"));
	if (pbNotOpenURL!=true){
		var lsURL=encodeURI(gsOAURL) + gsSRDBName + "/frmFTSearch?OpenForm";
		if (typeof loframe.RunAgent=="object"){
			loframe.FTObject = loObject;
			loframe.RunAgent.location.replace(lsURL);
		}else if (typeof top.RunAgent=="object"){
			top.FTObject = loObject;
			top.RunAgent.location.replace(lsURL);
		}
	}
	return true;
}

function bExecuteFTSearch(paDBTitle,paDBView,psQueryString,piPage){
	if (window.FTObject==null) return false;
	if (paDBView!=null && psQueryString!=null){
		var xmlhttp = oGetXmlHttpRequest();
		if (xmlhttp!=null){
			var laTitle = new Array();
			var laView = new Array();
			for(var i=0;i<paDBView.length;i++){
				var lsURL = paDBView[i] + "&Count=1&Query="+psQueryString;
				xmlhttp.open("HEAD",lsURL, false);
				xmlhttp.send();
				if (xmlhttp.status-0<400){
					laTitle[laTitle.length] = paDBTitle[i];
					laView[laView.length] = paDBView[i];
				}
			}
			paDBTitle = laTitle;
			paDBView = laView;
			if (laView.length==0){
				window.parent.HideViewLoading();
				alert(sGetLang("P_FTS_QUERYSTRINGERROR"));
				return false;
			}
		}
		var loObject = window.FTObject;
		loObject.ExeObject = new Object();
		loObject.ExeObject.DBTitles = paDBTitle;
		loObject.ExeObject.DBViews = paDBView;
		loObject.ExeObject.QueryString = psQueryString;
	
		var liCount = (loObject.Count!=null)?loObject.Count-0:giPCount;
		var loParent=window.parent.document;
		if (typeof loParent=="object" && typeof loParent.all.ID_PageCount=="object"){
			liCount = loParent.all.ID_PageCount.innerText-0;
		}
		loObject.ExeObject.Count = liCount;
		loObject.ExeObject.DataType = (loObject.DataType!=null)?loObject.DataType:"1";
		
		var lsURLCmd = "&SearchWV=" + ((loObject.SearchWV!=null)?loObject.SearchWV:"0");
		//lsURLCmd += "&SearchFuzzy=" + ((loObject.SearchFuzzy!=null)?loObject.SearchFuzzy:"0");
		lsURLCmd += "&SearchOrder=" + ((loObject.SearchOrder!=null)?loObject.SearchOrder:"3");
		lsURLCmd += "&SearchMax=" + ((loObject.SearchMax!=null)?loObject.SearchMax:"0");
		lsURLCmd += "&Type=" + ((loObject.MultipleViews!=null)?"":loObject.ExeObject.DataType);
		loObject.ExeObject.URLCmd = lsURLCmd;
		
		loObject.ExeObject.URLIndex = 0;
		loObject.ExeObject.TotalHits = new Array();
		loObject.ExeObject.showHTML="";
		loObject.ExeObject.showCount=0;
		loObject.ExeObject.showIndex=0;
		loObject.ExeObject.showOldType=false;
		var lsURL = loObject.ExeObject.DBViews[loObject.ExeObject.URLIndex]+ ((liCount!=0)?"&Count="+liCount:"") + loObject.ExeObject.URLCmd + "&Query=" + loObject.ExeObject.QueryString;
	}else if(piPage!=null){
		var loObject = window.FTObject.ExeObject;
		var liStart = (piPage-1) * loObject.Count+1;
		for(var i=0;i<loObject.TotalHits.length;i++){
			if (liStart>loObject.TotalHits[i]){
				liStart -= loObject.TotalHits[i];
			}else{
				loObject.URLIndex = i;
				break;
			}
		}
		if (i>=loObject.TotalHits.length) return false;
		var lsURL = loObject.DBViews[loObject.URLIndex]+ ((loObject.Count!=0)?"&Count="+loObject.Count:"") + loObject.URLCmd + "&Query=" + loObject.QueryString;
		if (liStart>1) lsURL = sSetParameter("Start",liStart,lsURL);
		loObject.showHTML="";
		loObject.showCount=0;
		loObject.showIndex=0;
		loObject.showOldType=false;
	}
	window.RunAgent.location.replace(lsURL);
	
	return true;
}

function bShowAnonymous(){
	if (typeof top.document!="unknown"){
		var loframe= top.ViewIFrame;
	}else{
		var loframe= top.ViewIFrame.MailIframe;
	}
	var lsURL=encodeURI(gsCurURL) + gsSRDBName + "/agtShowAnonymous?openagent&DBPath=" + encodeURI(loframe.gsCurURL.substr(1) + loframe.gsCurDBName) + "&ViewName=" + loframe.document.all.FTSViewName.innerText + "&RestrictToCategory=" + escape((typeof loframe.document.all.hCategory=="object")?loframe.document.all.hCategory.innerText.trim():"");
	if (typeof loframe.RunAgent=="object"){
		loframe.RunAgent.location.replace(lsURL);
	}else if (typeof top.RunAgent=="object"){
		top.RunAgent.location.replace(lsURL);
	}
}

function bRemind(){
	var lbView=(typeof top.ViewIFrame =="object") ? true:false;
	if (lbView==true){
		if (typeof top.document!="unknown"){
			var loframe= top.ViewIFrame;
		}else{
			return false;
			var loframe= top.ViewIFrame.MailIframe;
		}
		if (typeof loframe!="object") return false;
		var lsIDs =sGetSelected(sGetLang('MESSAGE_NODOCTOREMIND'));
		if (lsIDs=="") return false;
		var lsDB = loframe.gsCurURL.substr(1)+loframe.gsCurDBName;
	}else{
		if (typeof top.opener.top.document=="unknown") return false;
		if (gsCurUNID==null) return false;
		var lsIDs=gsCurUNID+"|";
		var lsDB = gsCurURL.substr(1)+gsCurDBName;
	}
	if (typeof goForm=="object" && typeof goForm.e_Input=="object")
		var lsArg = sGetParameter("LinkUNID",goForm.e_Input.value);
	SendMsg(gsCurUser,"remind",lsDB,lsIDs,lsArg);
}

function bSendToApprove(psDocs,psContent){
	//psDocs:DBPath1|DocUNID1;DBPath2|DocUNID2
	if (typeof top.document=="unknown") return false;
	if (psDocs!=null && psDocs!=""){
		var lsDocs = psDocs;
	}else{
		var loframe= top.ViewIFrame;
		if (typeof loframe!="object") return false;
		var lsIDs =sGetSelected(sGetLang('ENGINE_NODOCTOAPPROVE'));
		if (lsIDs=="") return false;
		var lsDB = loframe.gsCurURL.substr(1)+loframe.gsCurDBName;
		lsIDs = lsIDs.substring(0,lsIDs.lastIndexOf("|"));
		var laID = lsIDs.split("|");
		for (var i=0;i<laID.length;i++) laID[i] = lsDB + "|" + laID[i];
		var lsDocs = laID.join(";");
	}
	if (psContent!=null && psContent!=""){
		var lsContent = psContent;
	}else{
		var lsContent = sSelectArray("Multiple",sGetLang("ENGINE_SENDTOAPPROVE"),"",sGetLang("ENGINE_APPROVECONTENT"));
		if (lsContent == null) return false;
		lsContent = sReplaceSubstring(lsContent,";","");
	}
	var laDoc = lsDocs.split(";");
	for (var i=0;i<laDoc.length;i++) laDoc[i] += "|" + lsContent;
	if (laDoc.length>1 && lsContent!="5"){
		alert(sGetLang("ENGINE_MOREDOCTOAPPROVE"));
		return false;
	}
	if (i>=10) return false;
	bNewWork(null,null,null,laDoc.join(";"));
}


//function ViewAction(lsAction as string,lsActionName as string,lsVal as string,psPrompt as string,pbNoSelected)
function ViewAction(psAction,psActionName,psVal,psPrompt,pbNoSelected){
	if (pbNoSelected!=true){
		var lsSelectMsg = sGetLang("P_VIEWACTION_NODOC1")+psActionName+sGetLang("P_VIEWACTION_NODOC2");
		if (psPrompt==null || psPrompt=="")
			var lsPromptmsg = sGetLang("P_VIEWACTION_CONFIRM1")+psActionName+sGetLang("P_VIEWACTION_CONFIRM2");
		else
			var lsPromptmsg = psPrompt;
		return WebAction(null,psAction,"",psVal,lsSelectMsg,lsPromptmsg);
	}else{
		return WebAction(null,psAction,null,psVal,null,null);
	}
	
}
//function WebAction(psActionURL as string,psAction as string,psIDs as string,psVal as string,psSelectMsg as string,psConfirmMsg as string,poWindow)
function WebAction(psActionURL,psAction,psIDs,psVal,psSelectMsg,psConfirmMsg,poWindow){
	var lsAct = psAction;
	var lsIDs = psIDs;
	var lsArgVal = psVal;
	if(psIDs!=null && psIDs==""){
		lsIDs = sGetSelected(psSelectMsg,poWindow);
		if(lsIDs=="") return false;
	}
	if(psConfirmMsg!=null){
		if(window.confirm(psConfirmMsg)==false)	return false;
	}
	if (lsAct.toLowerCase()=="arch"){
		var laTemp=vGetArchive(true,"s_DArchDB","s_ArchDB","s_DArchFolder","s_ArchFolder");
		if(laTemp==null)return false;
		window.s_ArchDB=laTemp["CabID"];
		window.s_ArchFolder=laTemp["FolderID"];
	}
	if(psActionURL==null || psActionURL==""){
		var lsDBName = (gsCurDBName.toLowerCase()==gsCurUser.toLowerCase()+".nsf")?gsCurEncodeName+".nsf":gsCurDBName;
		var lsTdb = (lsAct.toLowerCase()=='del' || lsAct.toLowerCase()=='lock' || lsAct.toLowerCase()=='markread' || lsAct.toLowerCase()=='markunread' || lsAct.toLowerCase()=="arch")?encodeURI(gsOAURL) + gsSRDBName:encodeURI(gsCurURL) +lsDBName;
	}else{
		var lsTdb = psActionURL;
	}
	var lsURL=lsTdb;
	if(lsTdb.indexOf("?")==-1)
		lsURL+="/frmAutoClose?Openform";
	if (lsAct.toLowerCase()=='del' || lsAct.toLowerCase()=='lock' || lsAct.toLowerCase()=="arch")
		lsArgVal = (lsArgVal)?"yes":"no";
	window.Action=lsAct;
	window.docIDs=lsIDs;
	window.argVal=lsArgVal;
	var loWindow=null;
	if(typeof(window.RunAgent)=="object"){
		loWindow=window;
	}else if(typeof(parent.RunAgent)=="object"){
		loWindow=parent;
	}else if(typeof(top.RunAgent)=="object"){
		loWindow=top;
	}
	if(loWindow!=null){
		loWindow.RunAgent.location.replace(lsURL);
		return true;
	}
}


function sGetSelected(psPrompt,poWindow){
	var lsIDs ="";
	if(typeof(poWindow)=="object"){
		var loframe=poWindow;
	}else{
		if (typeof top.document!="unknown"){
			var loframe= top.ViewIFrame;
		}else{
			var loframe= top.ViewIFrame.MailIframe;
		}
	}
	var loForm = loframe.document.forms[0];
	for (var i = 0; i < loForm.elements.length; i++){
		if (loForm.elements[i].type != "checkbox") continue;
		if (loForm.elements[i].name != "$$SelectDoc") continue;
		if (loForm.elements[i].checked != true) continue;
		lsIDs=lsIDs+loForm.elements[i].value+"|";
	}
	for (var i=0;i<loframe.document.all.length;i++){
		if (loframe.document.all[i].id!=null && loframe.document.all[i].id.indexOf("DivisionalIframe")!=-1){
			loForm=eval("loframe."+loframe.document.all[i].id+".document.forms[0]");
			for (var k = 0; k < loForm.elements.length; k++){
				if (loForm.elements[k].type != "checkbox") continue;
				if (loForm.elements[k].name != "$$SelectDoc") continue;
				if (loForm.elements[k].checked != true) continue;
				lsIDs=lsIDs+loForm.elements[k].value+"|"
			}
		}
	}

	if (lsIDs.trim().charAt(0)=="|") lsIDs=lsIDs.trim().substr(1);
	if (lsIDs=="" && psPrompt != "") alert(psPrompt);

	return lsIDs;
}

function SelectAll(pbSelect,psIDs){
	if (typeof top.document!="unknown"){
		var loframe= top.ViewIFrame;
		var loForm = loframe.document.forms[0];
	}else{
		var loframe= top.ViewIFrame.MailIframe;
		var loForm = loframe.document.forms[0];
	}
	for (var i = 0; i < loForm.elements.length; i++)
		if (loForm.elements[i].type == "checkbox" && loForm.elements[i].name == "$$SelectDoc"){
			if (psIDs==null)
				loForm.elements[i].checked = pbSelect;
			else if(psIDs.indexOf(loForm.elements[i].value)!=-1)
				loForm.elements[i].checked = pbSelect;
			else
				loForm.elements[i].checked = !pbSelect;
		}
	for (var i=0;i<loframe.document.all.length;i++){
		if (loframe.document.all[i].id!=null && loframe.document.all[i].id.indexOf("DivisionalIframe")!=-1){
			loForm=eval("loframe."+loframe.document.all[i].id+".document.forms[0]");
			for (var k = 0; k < loForm.elements.length; k++){
				if (loForm.elements[k].type == "checkbox" && loForm.elements[k].name == "$$SelectDoc"){ 
					if (psIDs==null)
						loForm.elements[k].checked = pbSelect;
					else if(psIDs.indexOf(loForm.elements[k].value)!=-1)
						loForm.elements[k].checked = pbSelect;
					else
						loForm.elements[k].checked = !pbSelect;
				}
			}
		}
	}
}

function sGetOpenDocumentURL(psURL){
	var lsTmp=gsCurURL+gsCurDBName;
	var lsDBName = (gsCurDBName.toLowerCase()==gsCurUser.toLowerCase()+".nsf")?gsCurEncodeName+".nsf":gsCurDBName;
	lsTmp=lsTmp.toLowerCase();
	var lsURL=(psURL.toLowerCase().indexOf(lsTmp)>=0)?psURL:encodeURI(gsCurURL)+lsDBName+psURL;
	if (psURL.trim().charAt(0)!="/"){
		//OA Directory database use model
		if (psURL.toLowerCase().indexOf("z")==0 && psURL.toLowerCase().indexOf(".nsf")>0) lsURL=encodeURI(gsOAURL) + psURL;
		//kmcab use model
		if (psURL.toLowerCase().indexOf("zckm")==0 && psURL.toLowerCase().indexOf(".nsf")>0) lsURL=encodeURI(gsOAURL) + psURL;
	}else{
		if (psURL.toLowerCase().indexOf(".nsf")>0) lsURL=psURL;
	}
	var lsDBName = (typeof document.all.ID_ViewDBName=="object" && document.all.ID_ViewDBName.innerText!="")?document.all.ID_ViewDBName.innerText:gsCurDBName;
	var lsViewName = "";
	if (typeof document.all.hViewName=="object" && document.all.hViewName.innerText!="")
		lsViewName = document.all.hViewName.innerText;
	else if (typeof document.all.ID_ViewName=="object" && document.all.ID_ViewName.innerText!="")
		lsViewName = document.all.ID_ViewName.innerText;
	else if (typeof document.all.ID_SCROLLVIEWNAME=="object" && document.all.ID_SCROLLVIEWNAME.innerText!="")
		lsViewName = document.all.ID_SCROLLVIEWNAME.innerText;
	if (lsViewName!="") lsURL += "&FromView=" + encodeURIComponent(lsDBName+"|"+lsViewName);
	return lsURL;
}

function OpenDocument(psURL,psTarget,psNTID,piWidth,piHeight){
	var lsURL=sGetOpenDocumentURL(psURL);
	var liWidth=(piWidth!=null)?piWidth:1;
	var liHeight=(piHeight!=null)?piHeight:1;
	var sBaseUrl = document.location.protocol + '//' + document.location.host;
	var tmpHTML='<html><title></title><head>		\n'+
	'<base href="' + sBaseUrl + gsImgURL + '">		\n' +
	'<link rel="stylesheet" href="Form.css">		\n' +
	'<script src="/icons/icons/Functions.js"></script>	\n' +
	'<SCRIPT Language=JScript.Encode src="/icons/icons/PopMenu.js"></SCRIPT>	\n' +
	'<script>gsImgURL = "' + gsImgURL + '";			\n'+
	'document.cookie="gsCurUser="+escape("'+gsCurUser+'")+"; path=/";		\n'+
	'document.cookie="gsCurEncodeName="+escape("'+gsCurEncodeName+'")+"; path=/";	\n'+
	'document.cookie="gsCurDept="+escape("'+gsCurDept+'")+"; path=/";		\n'+
	'document.cookie="gsOAURL="+escape("'+gsOAURL+'")+"; path=/";			\n'+
	'document.cookie="gsImgURL="+escape("'+gsImgURL+'")+"; path=/";			\n'+
	'</script></head>					\n'+
	'<body leftmargin=0 topmargin=0 onbeforeunload="QueryCloseIE()" oncontextmenu="return false;">	\n' +
	"<table border='0' cellpadding='0' cellspacing='0' style='width:100%;height:100%'>\n" + 
	"<tr><td id='ID_Form_MenuBar' class='TD_MENUBAR' style='width:100%;height:35;background-image:url(bg_Form_MenuBar.jpg)'>&nbsp;</td></tr>\n" +
	"<tr><td height=100%>				\n" +
	'<iframe src="'+lsURL+'" id="ContentBody" width=100% height=100%  Frameborder=No Border=0 Marginwidth=0 Marginheight=0 Scrolling=auto></iframe>					\n' + 
	"</td></tr></table>						\n" + 
	"<font id=hPromptDoing></font>					\n" +
	"<iframe src='/icons/icons/BeforeUnload.htm' style='display:none' width=0 height=0  Frameborder=No Border=0 Marginwidth=0 Marginheight=0 Scrolling=no></iframe>			\n" +
	"<iframe id='RunAgent' src='' style='display:none' width=0 height=0  Frameborder=No Border=0 Marginwidth=0 Marginheight=0 Scrolling=no></iframe>					\n" +
	"<iframe id='FlowEngine' src='' style='display:none' width=0 height=0  Frameborder=No Border=0 Marginwidth=0 Marginheight=0 Scrolling=no></iframe>					\n" +
	'</body></html>';

	//make read
	var lsRead="";
	if (psNTID!=null){
		var loURM=document.getElementsByName(psNTID);
		if (loURM!=null && loURM.length>0 && loURM[0].innerHTML.length>8){
			var lsReadURL = gsOAURL + gsSRDBName + "/agtMarkRead?OpenAgent&DBPath=" + gsCurURL.substr(1) + escape(gsCurDBName) + "&NTID=" + psNTID;
			if (loURM[0].FieldName!=null && loURM[0].FieldName!="")
				lsReadURL += "&FieldName="+loURM[0].FieldName;
			if (loURM[0].FieldValue!=null && loURM[0].FieldValue!="")
				lsReadURL += "&FieldValue="+loURM[0].FieldValue;
			if (typeof window.RunAgent=="object"){
				window.RunAgent.location.replace(lsReadURL);
			}else if (typeof top.document!="unknown" && typeof top.RunAgent=="object"){
				top.RunAgent.location.replace(lsReadURL);
			}else {
				lsRead=lsReadURL;
			}
			if (typeof document.all.ID_SCROLLMSGCOUNTID=="object" && document.all.ID_SCROLLMSGCOUNTID.innerText!="" && typeof top.document!="unknown"){
				loMsgCount = eval("top.document.all."+document.all.ID_SCROLLMSGCOUNTID.innerText);
				if (typeof loMsgCount =="object")
					loMsgCount.innerText = (loMsgCount.innerText-0>0)?loMsgCount.innerText-0-1:0;
			}
			for(var k=0;k<loURM.length;k++) loURM[k].innerHTML="&nbsp;"
		}
	}
	if (psURL.toLowerCase().indexOf("http://")>=0 || psURL.toLowerCase().indexOf("https://")>=0){//open other domain page
		var lsDomain=psURL.substr(psURL.toLowerCase().indexOf("http://")+7);
		lsDomain=lsDomain.substr(0,lsDomain.indexOf("/"));
		if (psURL.toLowerCase().indexOf("http://")>=0)
			var lonw = OpenWindow("http://"+lsDomain+"/icons/icons/openDocument.htm?Open&URL=" + psURL,psTarget,liWidth,liHeight,"yes");
		else
			var lonw = OpenWindow("https://"+lsDomain+"/icons/icons/openDocument.htm?Open&URL=" + psURL,psTarget,liWidth,liHeight,"yes");
		return false;
	}
	if (lsRead==""){
		var lonw = OpenWindow("",psTarget,liWidth,liHeight,"yes");
		lonw.document.write(tmpHTML);
		lonw.gsImgURL = gsImgURL;
	}else{
		var lonw = OpenWindow("/icons/icons/openDocument.htm?Open&URL=" + lsURL,psTarget,liWidth,liHeight,"yes");
		lonw.MakeReadURL=lsRead;
	}
	lonw.setInterval('bSetDelimiterTime()',1*60000);
	if (typeof top.document!="unknown"){lonw.openerTop=top;}
	return lonw;
}

function bOpenViewEntry(poObj){
	if (poObj==null) return false;
	var lsAction = "0",lsURL,lsWidth,lsHeight,lsArg="";
	if (typeof ID_OpenAction=="object" && ID_OpenAction.innerText!="") lsAction = ID_OpenAction.innerText;
	if (typeof ID_OpenArgument=="object" && ID_OpenArgument.innerText!="") lsArg = ID_OpenArgument.innerText;
	var lsDBURL = "";
	if (typeof document.all.hViewBody=="object" && document.all.hViewBody.ISFTSearch=="1"){
		var loObj = poObj.parentElement.parentElement;
		while(loObj=loObj.parentElement){
			if (loObj.tagName=="TABLE"){
				if (loObj.CurDBURL!=null && loObj.CurDBURL!='')
					lsDBURL = loObj.CurDBURL;
				break;
			}
		}
		if (poObj.DataType=="1" && poObj.eBody!=null && poObj.eBody!="" && poObj.eBody.substring(0,poObj.eBody.indexOf("-"))!="CURDB"){
			lsDBURL = "zc" + poObj.eBody.substring(0,poObj.eBody.indexOf("-")) + ".nsf";
		}
	}else{
		if (poObj.DataType=="1" && poObj.eBody!=null && poObj.eBody!="")
			lsDBURL = "zc" + poObj.eBody.substring(0,poObj.eBody.indexOf("-")) + ".nsf";
	}
	switch(lsAction){
		case "0"://open document
		case "10"://open documen in view content
			if (poObj.DataType!=null && poObj.DataType=="1"){//open two database model
				lsURL = lsDBURL+"/0/" + poObj.eBody.substring(poObj.eBody.indexOf("-")+1,poObj.eBody.length)+"?OpenDocument";
				lsURL += "&LinkUNID="+poObj.eFileID.substring(0,poObj.eFileID.indexOf("-"))+"-"+poObj.UNID;
			}else if (poObj.DataType=="2"){//open my Favorites model
				lsURL = (poObj.eDB.substring(0,1)!="z")?"/"+poObj.eDB:poObj.eDB;
				lsURL += "/0/"+poObj.eUNID+"?OpenDocument";
				if (poObj.eLinkUNID!=null && poObj.eLinkUNID!="") lsURL += "&LinkUNID="+poObj.eLinkUNID;
			}else if (poObj.DataType=="3"){//open schedule model
				lsURL = lsDBURL+"/0/"+poObj.UNID + "?OpenDocument";
				if (poObj.eArgUNID!=null && poObj.eArgUNID!="") lsURL +="&ID="+poObj.eArgUNID;
				if (poObj.eWidth!=null && poObj.eWidth!="") lsWidth = poObj.eWidth;
				if (poObj.eHeight!=null && poObj.eHeight!="") lsHeight = poObj.eHeight;
			}else if (poObj.DataType=="4"){//alert message
				if(null != poObj.e_Message){
					alert(poObj.e_Message);
					return true;
				}else if(null != poObj.eMessage){
					alert(poObj.eMessage);
					return true;
				}
			}else if (poObj.DataType=="5"){//open search result
				lsURL = lsDBURL+"/0/"+poObj.UNID + "?OpenDocument";
				if (poObj.eDB!=null && poObj.eDB!="") lsURL = "/" + poObj.eDB + lsURL;
				if (poObj.eWidth!=null && poObj.eWidth!="") lsWidth = poObj.eWidth;
				if (poObj.eHeight!=null && poObj.eHeight!="") lsHeight = poObj.eHeight;
			}else if (poObj.DataType=="-1"){//default editdocument model
				lsURL = lsDBURL+"/0/"+poObj.UNID + "?EditDocument";
				if (poObj.eWidth!=null && poObj.eWidth!="") lsWidth = poObj.eWidth;
				if (poObj.eHeight!=null && poObj.eHeight!="") lsHeight = poObj.eHeight;
			}else{
				lsURL = lsDBURL+"/0/"+poObj.UNID + "?OpenDocument";
				if (poObj.eWidth!=null && poObj.eWidth!="") lsWidth = poObj.eWidth;
				if (poObj.eHeight!=null && poObj.eHeight!="") lsHeight = poObj.eHeight;
			}

			if (lsAction=="0")
				OpenDocument(lsURL,poObj.UNID,poObj.NTID,lsWidth,lsHeight);
			else
				window.location.replace(sGetOpenDocumentURL(lsURL));
			break;
		case "1"://edit document
		case "11"://
			lsURL = lsDBURL+"/0/"+poObj.UNID + "?EditDocument";
			if (poObj.eWidth!=null && poObj.eWidth!="") lsWidth = poObj.eWidth;
			if (poObj.eHeight!=null && poObj.eHeight!="") lsHeight = poObj.eHeight;
			if (lsAction=="1")
				OpenDocument(lsURL,poObj.UNID,poObj.NTID,lsWidth,lsHeight);
			else
				window.location.replace(sGetOpenDocumentURL(lsURL));
			break;
		case "2"://open rtf
		case "12":
			if (poObj.DataType!=null && poObj.DataType=="1"){//open two database model
				lsURL = '/servlet/ShowRtf?open&DB='+((lsDBURL.charAt(0)=='/')?lsDBURL.substr(1):gsCurURL.substr(1)+lsDBURL)+"&UNID="+poObj.eBody.substring(poObj.eBody.indexOf("-")+1,poObj.eBody.length)+"&Rtf="+lsArg;
			}else if (poObj.DataType=="2"){//open my Favorites model
				lsURL = '/servlet/ShowRtf?open&DB='+((poObj.eDB.substring(0,1)!="z")?poObj.eDB:gsOAURL.substr(1)+poObj.eDB)+"&UNID="+poObj.eUNID+"&Rtf="+lsArg;
			}else{
				lsURL = "/servlet/ShowRtf?open&DB="+((lsDBURL!='')?lsDBURL.substr(1):gsCurURL.substr(1)+gsCurDBName)+"&UNID="+poObj.UNID+"&Rtf="+lsArg;
			}
			if (lsAction=="2")
				OpenWindow(lsURL,'',1,1);
			else
				window.location.replace(sGetOpenDocumentURL(lsURL));
			break;
		case "3"://open primary text
		case "4"://open first attachment
			lsURL = encodeURI(gsOAURL)+gsSRDBName+"/agtOpenAttach?openagent&Action="+lsAction;
			if (poObj.DataType!=null && poObj.DataType=="1"){//open two database model
				lsURL += "&DB=" + encodeURI((lsDBURL.charAt(0)=='/')?lsDBURL.substr(1):gsCurURL.substr(1)+lsDBURL)+"&UNID="+poObj.eBody.substring(poObj.eBody.indexOf("-")+1,poObj.eBody.length);
			}else if (poObj.DataType=="2"){//open my Favorites model
				lsURL += '&DB='+encodeURI((poObj.eDB.substring(0,1)!="z")?poObj.eDB:gsOAURL.substr(1)+poObj.eDB)+"&UNID="+poObj.eUNID;
			}else{
				lsURL += "&DB="+encodeURI((lsDBURL!='')?lsDBURL.substr(1):gsCurURL.substr(1)+gsCurDBName)+"&UNID="+poObj.UNID;
			}
			WebAction(lsURL,"openattach");
			break;
		case "5"://view link file for zSCAB.ntf
			lsURL = encodeURI(gsOAURL)+gsSRDBName+"/agtOpenAttach?openagent&Action="+lsAction;
			lsURL += "&DB="+encodeURI((lsDBURL!='')?lsDBURL.substr(1):gsCurURL.substr(1)+gsCurDBName)+"&UNID="+poObj.UNID;
			WebAction(lsURL,"openlinkfile");
			break;
		case "6"://Open Issue
			if (poObj.DataType=="4"){//alert message
				if(null != poObj.e_Message){
					alert(poObj.e_Message);
					return true;
				}else if(null != poObj.eMessage){
					alert(poObj.eMessage);
					return true;
				}
			}else{
				lsURL = gsCurURL+"zMagazine.nsf/ArticleFrame?openpage&PCategory="+poObj.UNID;
				OpenWindow(lsURL,'',4/5,4/5,'yes');
			}
			break;
		case "7":
		case "17":
			lsURL = gsCurURL+"zVote.nsf/frmVoteResult?OpenForm&RealUNID="+poObj.UNID;
			if (lsAction=="7")
				OpenWindow(lsURL,'',poObj.eWidth,poObj.eHeight,'yes','yes');
			else
				window.location.replace(lsURL);
			break;
		case "8":
			window.popEMail = poObj.eMail;
			window.popEUser = poObj.eUser;
			window.popUNID = poObj.UNID;
			showMenu(poObj.eMenuID,(poObj.eWidth!=null)?poObj.eWidth:100);
			break;
		default:break;
	}
}


function GotoPage(){
	if (typeof top.document!="unknown"){
		var lodoc=top.ViewIFrame.document;
	}else{
		var lodoc=top.ViewIFrame.MailIframe.document;
	}
	if (typeof lodoc.all.tPage!="object") return false;
	var ltPage = lodoc.all.tPage.innerText - 0;
	var lsPage = sGetInput(sGetLang("P_GOPAGE_TITLE"),sGetLang("P_GOPAGE_INFO"),document.all.dPage.innerText);
	if (lsPage==null) return false;
	if(lsPage==""||lsPage=="0"){alert(sGetLang("P_NOPAGENUMBER"));return false;}
	if(lsPage-0>ltPage){alert(sGetLang("P_OVERPAGECOUNT"));return false;}
	ShowPage(-1,lsPage-0-1);
}

function EditPageCount(){
	if (typeof top.document!="unknown"){
		var loframe=top.ViewIFrame;
	}else{
		var loframe=top.ViewIFrame.MailIframe;
	}
	var lsCount = sGetInput(sGetLang("P_EDITPAGECOUNT_TITLE"),sGetLang("P_EDITPAGECOUNT_INFO"),sGetParameter("Count",loframe.location.href));
	if (lsCount!=null && lsCount!=""){
		var lsURL = sSetParameter("Count",lsCount,loframe.location.href);
		lsURL = sSetParameter("Start","1",lsURL);
		lsURL = sReplaceSubstring(lsURL,"&Start=1","");
		lsURL = sSetParameter("dPage","1",lsURL);
		lsURL = sReplaceSubstring(lsURL,"&dPage=1","");
		loframe.location.replace(lsURL);
	}
}

/*
ViewType£º
1-no category and no response;
2-category or response but not one category;
3-after show one category,no category and no response;
4-after show one category, category or response;
5-for kmcab (the same to type four)
*/
function ShowPage(piAction,piIndex){
	if (typeof top.document!="unknown") var loframe= top.ViewIFrame;
	else var loframe= top.ViewIFrame.MailIframe;
	var lodoc = loframe.document;
	var loCurdoc = window.document;
	
	var lshref = (loframe.location.href);
	var lsDescend = sGetParameter("ResortDescending",lshref);
	var lsAscend = sGetParameter("ResortAscending",lshref);
	
	var liType = lodoc.all.hViewType.innerText - 0;
	if (liType==5) liType=4;
	if ((liType==2 || liType==4) && (lsDescend!="" || lsAscend)) liType--;
	var liTPage = (typeof lodoc.all.tPage!="object")?0:lodoc.all.tPage.innerText - 0;
	var liPage = (piAction==-1) ? piIndex:lodoc.all.dPage.innerText-0;
	var liCount = (typeof lodoc.all.PCount=="object" && lodoc.all.PCount.innerText!="")?(lodoc.all.PCount.innerText-0):giPCount;
	

	var liUseStatus = 1;//view default nextpage or prevpage
	if (piAction==9 || piAction==-9 || piAction==-10){
		if (loCurdoc.all.hFTSTable.style.display!="none") return false;
		liUseStatus = 2;//Sort ViewColumn;
	}else if(loCurdoc.all.hFTSTable.style.display!="none" && typeof loframe.FTObject=="object"){
		liUseStatus = 3;//View FTSearch status
	}else if ((liType==2 || liType==4) && typeof lodoc.all.ID_ViewCommand=="object" && loCurdoc.all.hFTSTable.style.display=="none"){//Domino action model
		var lsDefault = lodoc.all.ID_ViewCommand.Default;//View default show type
		if (!(lshref.indexOf("&ExpandView")!=-1 || lsDefault=="Expand" && (lshref.indexOf("&CollapseView")==-1 || lshref.indexOf("&Collapse=")==-1 || lshref.indexOf("&Expand=")==-1)))
			liUseStatus = 4;//default Collapse or action Collapse/Expand/CollapseView and not ExpandView;
	}

	switch(liUseStatus){
		case 1://default view page action
			if ((piAction==0 || piAction==1) && liPage<2) return false;
			if ((piAction==2 || piAction==3) && liPage==liTPage) return false;
			var liACount = lodoc.all.ACount.innerText - 0;
			var lsViewName = loframe.document.all.hViewName.innerText;
			var lsArgView = sGetParameter("argView",lshref);
			var lsCurDB = (typeof lodoc.all.ID_ViewDBName=="object" && lodoc.all.ID_ViewDBName.innerText!="")?lodoc.all.ID_ViewDBName.innerText:loframe.gsCurDBName;
			var lsCurURL = encodeURI(loframe.gsCurURL);
			var lsCategory = lodoc.all.hCategory.innerText.trim();
			var lsForm = (lsViewName.substr(0,4).toLowerCase()=="view")?("frm"+lsViewName.substr(4)):lsViewName;
			if (lsArgView.trim()!=""){
				lsForm=lshref.substr(0,lshref.indexOf("?"));
				lsForm=lsForm.substr(lsForm.lastIndexOf("/")+1);
			}
			//get url
			if (piAction==0){
				var lsURL = lsCurURL + lsCurDB + "/"+ lsForm +"?openform&Count=" + liCount
			}else{
				if ((liType==1) || (liType==3)){			//direct url
					if (piAction==1) liPage = (liPage>2) ? liPage-2:0;
					if (piAction==3) liPage = liTPage - 1;
					liPage = liPage + 1;
					if (liPage > liTPage) liPage = liPage - 1;
					var liStart = (liPage-1) * liCount + 1 ;
					var lsURL=lsCurURL + lsCurDB + "/" + lsForm + "?OpenForm&Start=" + liStart + "&Count=" + liCount + "&dPage="+liPage;
				}else{							//use agent to get url
					var liArrow = 3;
					if (piAction==1) liArrow = 2
					if (piAction==3) liArrow = 4
					var lsStart = sGetParameter("Start",lshref);
					if (lsStart=="" || lsStart==null)  lsStart = "0";
					if (piAction==-1) lsStart=-1;
					var lsURL= gsOAURL + gsSRDBName + "/agtGotoPage?OpenAgent&Start=" + lsStart + "&Arrow=" + liArrow  + "&dPage=" + liPage + "&tPage=" + liTPage + "&PCount=" + liCount + "&ACount=" + liACount + "&dbpath=" + lsCurURL.substr(1) +escape(lsCurDB) + "&viewname=" + lsViewName + "&viewtype=" + liType;
					if (lsArgView.trim()!="") lsURL += "&formname=" + lsForm ;
					var lsCollapse = sGetParameter("Collapse",lshref);
					if (lsCollapse!="") lsURL += "&Collapse=" + lsCollapse ;
					var lsExpand = sGetParameter("Expand",lshref);
					if (lsExpand!="") lsURL += "&Expand="+lsExpand ;
				}
			}
			//add parameter
			if ( lsCategory!="" && liType>2) lsURL = lsURL+"&RestrictToCategory=" + escape(lsCategory) ;
			if (lsArgView.trim()!="") lsURL = lsURL+"&argView=" + lsArgView ;
			if (lshref.indexOf("&ExpandView")>0) lsURL = lsURL+"&ExpandView";
			if (lshref.indexOf("&CollapseView")>0) lsURL = lsURL+"&CollapseView";
			if (lsDescend!="") lsURL = lsURL + "&ResortDescending="+lsDescend;
			if (lsAscend!="") lsURL = lsURL + "&ResortAscending="+lsAscend;
			PromptViewLoading();
			loframe.location.replace(lsURL);
			break;
		case 2://sort viewcolumn
			var lsURL = sSetParameter("Start","1",lshref);
			var lsDPage = sGetParameter("dPage",lshref);
			if (lsDPage!="") lsURL = sReplaceSubstring(lsURL,"&dPage="+lsDPage,"");
			if (lsDescend!="") lsURL = sReplaceSubstring(lsURL,"&ResortDescending="+lsDescend,"");
			if (lsAscend!="") lsURL = sReplaceSubstring(lsURL,"&ResortAscending="+lsAscend,"");
			var lsTemp = sGetParameter("Seq",lshref);
			if (lsTemp!="") lsURL = sReplaceSubstring(lsURL,"&Seq="+lsTemp,"");
			lsTemp = sGetParameter("Collapse",lshref);
			if (lsTemp!="") lsURL = sReplaceSubstring(lsURL,"&Collapse="+lsTemp,"");
			lsTemp = sGetParameter("Expand",lshref);
			if (lsTemp!="") lsURL = sReplaceSubstring(lsURL,"&Expand="+lsTemp,"");
			lsURL = sReplaceSubstring(lsURL,"&CollapseView","");
			lsURL = sReplaceSubstring(lsURL,"&ExpandView","");
			if (piAction==9)
				lsURL += "&ResortAscending=" + piIndex;
			else if (piAction==-9)
				lsURL += "&ResortDescending=" + piIndex;
			PromptViewLoading();
			loframe.location.replace(lsURL);
			break;
		case 3://view FTSearch
			if ((piAction==0 || piAction==1) && liPage<2) return false;
			if ((piAction==2 || piAction==3) && liPage==liTPage) return false;
			if (piAction==0) liPage = 0;
			if (piAction==1) liPage = (liPage>2) ? liPage-2:0;
			if (piAction==3) liPage = liTPage - 1;
			liPage = liPage + 1;
			if (liPage > liTPage) liPage = liPage - 1;
			loCurdoc.all.dPage.innerText = liPage;
			lodoc.all.dPage.innerText = liPage;
			PromptViewLoading();
			loframe.bExecuteFTSearch(null,null,null,liPage);
			/*
			var loForm = loframe.RunAgent.document.forms[0];
			loForm.action = loForm.action.substring(0,loForm.action.toLowerCase().indexOf("?searchview")+11);
			loForm.Start.value = (liStart==1)?0:liStart;
			for (var i = 0; i < loForm.elements.length; i++){
				if(loForm.elements[i].type=="hidden" && loForm.elements[i].name.indexOf("__")==0)
					loForm.elements[i].outerHTML="";
			}
			loForm.submit();
			*/
			break;
		case 4://Domino view action model
			var lsStart = sGetParameter("Start",lshref);
			if (piAction==0){
				if (lsStart=="" || lsStart=="0" || lsStart=="1") return false;
				PromptViewLoading();
				loframe.location.replace(sSetParameter("Start","1",lshref));
				window.categoryPageIndex = 1;
			}else if (piAction==1){
				if (lsStart=="" || lsStart=="0" || lsStart=="1") return false;
				PromptViewLoading();
				lodoc.all.ID_PrevPage.click();
				window.categoryPageIndex = loCurdoc.all.dPage.innerText-0-1;
			}else if (piAction==2){
				var oEntries = lodoc.getElementsByName('ViewEntry');
				if (oEntries.length<liCount) return false;
				window.categoryPageIndex = loCurdoc.all.dPage.innerText-0+1;
				PromptViewLoading();
				lodoc.all.ID_NextPage.click();
			}else if (piAction==3){
				
			}
			break;
		default:break;
	}
	return true;
}

function ShowSelectInput(){
	var lbMultiple = (top.SingleChoice == "1")?false:true;
	if (typeof top.document!="unknown"){
		var loframe= top.ViewIFrame;
		var loForm = loframe.document.forms[0];
	}else{
		var loframe= top.ViewIFrame.MailIframe;
		var loForm = loframe.document.forms[0];
	}
	if(typeof top.goReturnField == "object")
		var lsReturnValue = top.goReturnField.value;
	if(!lbMultiple){
		if(typeof window.parent.document.all.SelectAll == "object")
			window.parent.document.all.SelectAll.style.display="none";
		var loEntrys = loframe.document.getElementsByName('ViewEntry');
		for (var i = 0; i < loForm.elements.length; i++){
			if (loForm.elements[i].type == "checkbox" && loForm.elements[i].name == "$$SelectDoc"){
				loForm.elements[i].outerHTML ='<input type="radio" name="$$SelectDoc" value="'+loForm.elements[i].value+'">';
				var lsEntryValue = loForm.elements[i].value;
				for(var j=0; j < loEntrys.length; j++){
					if(loEntrys[j].UNID == lsEntryValue && typeof loEntrys[j].Entry_Value!="undefined"){
						loForm.elements[i].value = loEntrys[j].Entry_Value;
						break;
					}
				}
				loForm.elements[i].attachEvent("onclick",SelectViewEntry);
				loForm.elements[i].attachEvent("ondblclick",SelectViewEntryOK);
				//loForm.elements[i].onclick = "SelectViewEntry(this);";
				//loForm.elements[i].ondblclick = "SelectViewEntryOK(this);";
				var lsEntryValueCompare = (loForm.elements[i].value.indexOf("|")==-1)?loForm.elements[i].value:loForm.elements[i].value.substr(loForm.elements[i].value.indexOf("|")+1);
				if((";"+lsReturnValue).indexOf(";"+lsEntryValueCompare+";")!=-1) SelectViewEntry(loForm.elements[i]);
			}else if (loForm.elements[i].type == "radio" && loForm.elements[i].name == "$$SelectDoc"){
				var lsEntryValueCompare = (loForm.elements[i].value.indexOf("|")==-1)?loForm.elements[i].value:loForm.elements[i].value.substr(loForm.elements[i].value.indexOf("|")+1);
				if((";"+lsReturnValue).indexOf(";"+lsEntryValueCompare+";")!=-1) SelectViewEntry(loForm.elements[i]);
			}
		}
	}else{
		var loEntrys = loframe.document.getElementsByName('ViewEntry');
		for (var i = 0; i < loForm.elements.length; i++){
			if (loForm.elements[i].type == "checkbox" && loForm.elements[i].name == "$$SelectDoc"){
				var lsEntryValue = loForm.elements[i].value;
				for(var j=0; j < loEntrys.length; j++){
					if(loEntrys[j].UNID == lsEntryValue && typeof loEntrys[j].Entry_Value!="undefined"){
						loForm.elements[i].value = loEntrys[j].Entry_Value;
						break;
					}
				}
				loForm.elements[i].attachEvent("onclick",SelectViewEntry);
				loForm.elements[i].attachEvent("ondblclick",SelectViewEntryOK);
				//loForm.elements[i].onclick = "SelectViewEntry(this);";
				//loForm.elements[i].ondblclick = "SelectViewEntryOK(this);";
				var lsEntryValueCompare = (loForm.elements[i].value.indexOf("|")==-1)?loForm.elements[i].value:loForm.elements[i].value.substr(loForm.elements[i].value.indexOf("|")+1);
				if((";"+lsReturnValue).indexOf(";"+lsEntryValueCompare+";")!=-1) SelectViewEntry(loForm.elements[i]);
			}
		}
	}
	//DisplayValue();
}

function SelectAllViewEntry(pbChecked){
	var loSrc = event.srcElement;
	if (typeof top.document!="unknown"){
		var loframe= top.ViewIFrame;
		var loForm = loframe.document.forms[0];
	}else{
		var loframe= top.ViewIFrame.MailIframe;
		var loForm = loframe.document.forms[0];
	}
	var lbCheck = (pbChecked==null)?loSrc.checked:pbChecked;
	for (var i = 0; i < loForm.elements.length; i++)
		if (loForm.elements[i].type == "checkbox" && loForm.elements[i].name == "$$SelectDoc"){
			if(lbCheck != loForm.elements[i].checked){
				SelectViewEntry(loForm.elements[i]);
			}
		}
	
	for (var i=0;i<loframe.document.all.length;i++){
		if (loframe.document.all[i].id!=null && loframe.document.all[i].id.indexOf("DivisionalIframe")!=-1){
			loForm=eval("loframe."+loframe.document.all[i].id+".document.forms[0]");
			for (var k = 0; k < loForm.elements.length; k++){
				if (loForm.elements[k].type == "checkbox" && loForm.elements[k].name == "$$SelectDoc"){ 
					if(lbCheck != loForm.elements[k].checked){
						SelectViewEntry(loForm.elements[i]);
					}
				}
			}
		}
	}
}

function SelectViewEntryOK(poElement){
	SelectViewEntry(poElement);
	parent.document.all.btnOK.click();
}

function SelectViewEntry(poElement){
	if (typeof top.document!="unknown"){
		var loframe= top.ViewIFrame;
		var loForm = loframe.document.forms[0];
	}else{
		var loframe= top.ViewIFrame.MailIframe;
		var loForm = loframe.document.forms[0];
	}
	var lbRadio = false;
	var lsNodeValue = "",lsNodeDisplay="";
	var lbChecked = false;
	if(typeof poElement != "undefined" && (poElement.tagName == "TR" || poElement.tagName == "INPUT")){
		for (var i = 0; i < loForm.elements.length; i++){
			var lsEntryValue = (poElement.tagName == "TR")?poElement.Entry_Value:poElement.value;
			//alert(lsEntryValue);
			if (loForm.elements[i].type != "checkbox" && loForm.elements[i].type != "radio") continue;
			if (loForm.elements[i].name != "$$SelectDoc") continue;
			if (loForm.elements[i].value != lsEntryValue) continue;
			if(loForm.elements[i].type == "radio"){
				lbRadio = true;
				loForm.elements[i].checked = true;
			}else{
				if(event != null && event.type == "dblclick") loForm.elements[i].checked = true;
				else loForm.elements[i].checked = !loForm.elements[i].checked;
			}
			lsNodeValue = loForm.elements[i].value;
			lsNodeDisplay = lsNodeValue;
			if(lsNodeValue.indexOf("|")!=-1){
				lsNodeDisplay=lsNodeValue.substr(0,lsNodeValue.indexOf("|"));
				lsNodeValue=lsNodeValue.substr(lsNodeValue.indexOf("|")+1);
			}
			lbChecked = loForm.elements[i].checked;
		}
	}else{
		if(event == null) return false;
		var loSrc = event.srcElement;
		lsNodeValue = loSrc.value;
		lsNodeDisplay = lsNodeValue;
		if(lsNodeValue.indexOf("|")!=-1){
			lsNodeDisplay=lsNodeValue.substr(0,lsNodeValue.indexOf("|"));
			lsNodeValue=lsNodeValue.substr(lsNodeValue.indexOf("|")+1);
		}
		lbChecked = loSrc.checked;
		if(loSrc.type == "radio") lbRadio = true;
	}
	if(parent.goReturnField && parent.goDisplayField){
		var lsTemp="";
		if(event != null){
			if(lbRadio){
				parent.goReturnField.value = lsNodeValue+";";
			}else{
				if(lbChecked){
					lsTemp=";"+parent.goReturnField.value+";";
					if(lsTemp.indexOf(";"+lsNodeValue+";")==-1)
						parent.goReturnField.value=parent.goReturnField.value+lsNodeValue+";";
				}else{
					parent.goReturnField.value=(";"+parent.goReturnField.value).replace(";"+lsNodeValue+";",";");
					parent.goReturnField.value = parent.goReturnField.value.substr(1);	
				}
			}
		}
	}
	//var lsTotalDisplay = (parent.goDisplayField.value=="")?lsNodeDisplay:sReplaceSubstring(parent.goDisplayField.value,"\r",";")+";"+lsNodeDisplay;
	DisplayValue(lsNodeDisplay,lbChecked);
}



function DisplayValue(psNodeDisplay,pbChecked){
	if(psNodeDisplay==null){
		if(parent.goReturnField && parent.goDisplayField){
			lsTemp=parent.goReturnField.value;
			var laTemp=lsTemp.split(";");
			for (var i=0; i<laTemp.length; i++) 
				if (laTemp[i].indexOf("|")>0)
					laTemp[i] = laTemp[i].substr(0,laTemp[i].indexOf("|"));
			lsTemp=laTemp.join("\r");
			parent.goDisplayField.value=lsTemp+(lsTemp=="")?"":"\r";
		}
	}else{
		lsTemp=psNodeDisplay;
		var laTemp=lsTemp.split(";");
			for (var i=0; i<laTemp.length; i++) 
				if (laTemp[i].indexOf("|")>0)
					laTemp[i] = laTemp[i].substr(0,laTemp[i].indexOf("|"));
		lsTemp=laTemp.join("\r")+"\r";
		if(pbChecked){	
			if(("\n"+parent.goDisplayField.value+"\n").indexOf("\n"+lsTemp+"\n")==-1)		
				parent.goDisplayField.value += lsTemp;
		}else{
			parent.goDisplayField.value = sReplaceSubstring("\n"+parent.goDisplayField.value,"\n"+lsTemp+"\n","\n");
			parent.goDisplayField.value = parent.goDisplayField.value.substr(2);
		}
	}
}

function ShowPageInfo(pbFTSearch){
	var oEntries = document.getElementsByName('ViewEntry');
	if (oEntries!=null && oEntries.length>0){
		//change view's Table.outerHTML
		var loViewTable=oEntries[0];
		while(loViewTable=loViewTable.parentElement){
			if (loViewTable.tagName=="TABLE" && (loViewTable.parentElement==null || loViewTable.parentElement.tagName=="FORM" || loViewTable.parentElement.parentElement.tagName=="FORM")) break;
		}
		if (loViewTable.tagName=="TABLE"){
			loViewTable.outerHTML="<table cellspacing=0 cellpadding=0 border=0 width=100%>" + loViewTable.outerHTML.substr(loViewTable.outerHTML.indexOf(">")+1);
		}
		//change row style
		var liRowWeight=screen.width - 152 -5 - 50;
		if (screen.width>800) screen.width - 169 -5 -50;
		if(top.SelectView == "1"){
			var liRowWeight=document.body.offsetWidth+10 -5 - 50;
			if (document.body.offsetWidth>800) document.body.offsetWidth+10 -5 -50;
		}
		var lsOverClass,lsOutClass,lbFlag;
		if (typeof window.hViewTitle=="object" && hViewTitle.offsetWidth>0) liRowWeight=hViewTitle.offsetWidth-32;
		var laUNID = new Array();
		var lbLink = (typeof document.all.ID_ViewDBName=="object" && document.all.ID_ViewDBName.innerText!="")?true:false;
		for (i=0; i<oEntries.length;i++){
			var loTr = oEntries[i];
			if (lbLink && oEntries[i].UNID!=null && oEntries[i].UNID!="") laUNID[laUNID.length] = oEntries[i].UNID;
			lsOverClass = "Entry_MouseOver";
			lsOutClass = "Entry_MouseOut";
			if (loTr.MouseOverClass!=null && loTr.MouseOverClass!="") lsOverClass = loTr.MouseOverClass;
			if (loTr.MouseOutClass!=null && loTr.MouseOutClass!="") lsOutClass = loTr.MouseOutClass;

			var loTmp=loTr.parentElement.parentElement.parentElement;
			while(loTmp!=null && loTr!=null ){
				if ((loTmp.tagName=="FORM" || (loTmp.parentElement!=null && loTmp.parentElement.tagName=="FORM"))  && loTr.tagName=="TR") break;
				loTr=loTr.parentElement;
				loTmp=loTmp.parentElement;
			}

			loTr.className="Bg_Row";
			lbFlag=true;
			for(var k=loTr.children.length-1;k>=0;k--){
				if (loTr.children[k].innerHTML.toLowerCase().indexOf("viewentry")!=-1) lbFlag = false;
				if (lbFlag==true && oEntries[i].tagName!="SPAN") loTr.children[k].style.display="none";
				if (loTr.children[k].innerHTML=="")
					loTr.children[k].innerHTML='<img src="'+gsImgURL+'bg_Interval.gif">';
				loTr.children[k].className="Entry_TD";
			}
			if (oEntries[i].tagName!="SPAN"){
				var loEntryTable=oEntries[i];
				while(loEntryTable=loEntryTable.parentElement) if (loEntryTable.tagName=="TABLE") break;
				loEntryTable.outerHTML="<table cellspacing=0 cellpadding=0 border=0 width="+liRowWeight+" onmouseover='this.className=\""+lsOverClass+"\";' onmouseout='this.className=\""+lsOutClass+"\";' class='"+lsOutClass+"'>" + loEntryTable.outerHTML.substr(loEntryTable.outerHTML.indexOf(">")+1);
			}else{
				loTr.className=lsOutClass;
				loTr.onmouseover=new Function("this.className='"+lsOverClass+"';");
				loTr.onmouseout=new Function("this.className='"+lsOutClass+"';");
				oEntries[i].style.fontWeight="bold";
			}
		}
	}
	//change selelct checkbox of TD width
	var oFormElements = goForm.elements;
	var liIndex = 0;
	for (var i = 0; i < oFormElements.length; i++){
		if (oFormElements[i].type == "checkbox" && oFormElements[i].name == "$$SelectDoc"){
			oFormElements[i].parentElement.style.width="14";
			if (lbLink && liIndex<laUNID.length){
				oFormElements[i].value = laUNID[liIndex];
				liIndex++;
			}
		}
	}

	var oImgs = document.images;
	for (var i=0;i<oImgs.length;i++){
		if (oImgs[i].src.indexOf("/icons/ecblank.gif")!=-1 && oImgs[i].width -0 ==16){
			//delete the images that it's height is equal of one
			if (oImgs[i].height -0 ==1){
				var loTD = oImgs[i].parentElement;
				if (loTD.innerHTML.indexOf("/icons/collapse.gif")==-1 && loTD.innerHTML.indexOf("/icons/expand.gif")==-1) oImgs[i].style.display="none"; 
			//chage the images width before the selected input
			} else if (oImgs[i].height -0 ==16 && oImgs[i].name!=null && oImgs[i].name.toLowerCase().indexOf("_selectimg")==0){
				oImgs[i].outerHTML="<img valign=top src=/icons/ecblank.gif height=16 width=3 border=0>"; 
			}
		} else if (oImgs[i].src.indexOf("/icons/vwicn")!=-1 && oImgs[i].width -0 ==13){
			if (oImgs[i].src.indexOf("/icons/vwicn999.gif")!=-1) oImgs[i].style.display="none";
			if (oImgs[i].parentElement.innerHTML == oImgs[i].outerHTML){
				oImgs[i].parentElement.style.width="13";
				oImgs[i].parentElement.style.verticalAlign="middle";
			}
		} else if (oImgs[i].src.indexOf("/icons/collapse.gif")!=-1){
			var loHref = oImgs[i].parentElement;
			var lsValue = sGetParameter("Collapse",loHref.href);
			var lsTemp = sReplaceSubstring(loHref.outerHTML,"<A ","<A name='"+lsValue+"' ");
			var lsHTML = lsTemp.substring(0,lsTemp.indexOf('href="')+6);
			lsTemp = lsTemp.substring(lsTemp.indexOf('href="')+6,lsTemp.length);
			var lsURL = lsTemp.substring(0,lsTemp.indexOf('"'));
			lsHTML += '#" onclick="bCollapse(\''+lsURL+'\');return false;" ';
			lsHTML += lsTemp.substring(lsTemp.indexOf('"')+1,lsTemp.length)
			loHref.outerHTML = lsHTML;
			var loTR = oImgs[i];
			var loTD = null,lbCategory=false;
			while(loTR=loTR.parentElement){
				if (loTD == null && loTR.tagName=="TD") loTD = loTR;
				if (loTR.tagName=="TR") break;
			}
			loTR.style.verticalAlign = "middle";
			if (!(loTR.innerHTML.indexOf("ViewEntry")!=-1 && (loTR.innerHTML.indexOf("OpenDocument(")!=-1 || loTR.innerHTML.indexOf("bOpenViewEntry(")!=-1))){
				loTR.onclick=new Function("bCollapse('" + sReplaceSubstring(lsURL,"&amp;","&") + "');return false;");
				loTR.style.cursor="hand";
				lbCategory = true;
			}
			oImgs[i].outerHTML = "<img align=absmiddle src='" + gsImgURL + "ico_collapse.gif' border=0>&nbsp;&nbsp;";
			if (loTD!=null && lsValue.indexOf(".")!=-1 && lbCategory==true && loTD.innerHTML.toLowerCase().indexOf("/icons/ecblank.gif")==-1){
				var liCount = lsValue.split(".").length-1;
				lsHTML = ""
				for(var i=0;i<liCount;i++)
					lsHTML += '<img src="/icons/ecblank.gif" border="0" height="9" width="16">';
				loTD.innerHTML =  lsHTML+ loTD.innerHTML;
			}
		} else if (oImgs[i].src.indexOf("/icons/expand.gif")!=-1){
			var loHref = oImgs[i].parentElement;
			var lsValue = sGetParameter("Expand",loHref.href);
			var lsTemp = sReplaceSubstring(loHref.outerHTML,"<A ","<A name='"+lsValue+"' ");
			var lsHTML = lsTemp.substring(0,lsTemp.indexOf('href="')+6);
			lsTemp = lsTemp.substring(lsTemp.indexOf('href="')+6,lsTemp.length);
			var lsURL = lsTemp.substring(0,lsTemp.indexOf('"'));
			lsHTML += '#" onclick="bExpand(\''+lsURL+'\');return false;" ';
			lsHTML += lsTemp.substring(lsTemp.indexOf('"')+1,lsTemp.length)
			loHref.outerHTML = lsHTML;
			var loTR = oImgs[i];
			var loTD = null,lbCategory=false;
			while(loTR=loTR.parentElement){
				if (loTD == null && loTR.tagName=="TD") loTD = loTR;
				if (loTR.tagName=="TR") break;
			}
			loTR.style.verticalAlign = "middle";
			if (!(loTR.innerHTML.indexOf("ViewEntry")!=-1 && (loTR.innerHTML.indexOf("OpenDocument(")!=-1 || loTR.innerHTML.indexOf("bOpenViewEntry(")!=-1))){
				loTR.onclick=new Function("bExpand('" + sReplaceSubstring(lsURL,"&amp;","&") + "');return false;");
				loTR.style.cursor="hand";
				lbCategory = true;
			}
			oImgs[i].outerHTML = "<img align=absmiddle src='" + gsImgURL + "ico_expand.gif' border=0>&nbsp;&nbsp;";
			if (loTD!=null && lsValue.indexOf(".")!=-1 && lbCategory==true && loTD.innerHTML.toLowerCase().indexOf("/icons/ecblank.gif")==-1){
				var liCount = lsValue.split(".").length-1;
				lsHTML = ""
				for(var i=0;i<liCount;i++)
					lsHTML += '<img src="/icons/ecblank.gif" border="0" height="9" width="16">';
				loTD.innerHTML =  lsHTML + loTD.innerHTML;
			}
		}
	}

	if (pbFTSearch==true) return;

	ShowViewCount();
	ShowViewTitle();
	if (top.SelectView == "1") ShowSelectInput();
	HideViewLoading();
}

function ShowPageForHTML(){
	document.all.hViewBody.NewFormat="1";//mark new view format
	CreateMenuBar();
	ShowViewCount();
	ShowViewTitle();
	if (top.SelectView == "1") ShowSelectInput();
	HideViewLoading();
}

function ShowViewCount(){
	var lodoc=window.document;
	if (typeof lodoc.all.tPage!="object") return false;
	var liType = lodoc.all.hViewType.innerText - 0;
	var lsTemp = sGetParameter("dPage");
	if (lsTemp=="" && window.parent.categoryPageIndex!=null){
		lodoc.all.dPage.innerText = window.parent.categoryPageIndex;
		window.parent.categoryPageIndex = null;
	}
	var liPage = lodoc.all.dPage.innerText - 0;
	var lsCategory = lodoc.all.hCategory.innerText.trim();
	var lsView = lodoc.all.hViewName.innerText;
	var liCount = (typeof lodoc.all.PCount=="object" && lodoc.all.PCount.innerText!="")?(lodoc.all.PCount.innerText-0):giPCount;

	if (typeof window.parent.document.all.dPage=="object") window.parent.document.all.dPage.innerText = liPage;
	//get unread marks
	var lsCurDB = (typeof lodoc.all.ID_ViewDBName=="object" && lodoc.all.ID_ViewDBName.innerText!="")?lodoc.all.ID_ViewDBName.innerText:gsCurDBName;
	var lsURL = encodeURI(gsOAURL) + gsSRDBName + "/agtCountPage?OpenAgent&DBPath=" + encodeURI(gsCurURL.substr(1)) + escape(lsCurDB) + "&ViewName=" + escape(lsView) + "&ViewType=" + liType + "&PCount=" + liCount + "&RestrictToCategory=" + escape(lsCategory);
	var lbUnReadSign = false;
	if (typeof lodoc.all.hUnReadSign=="object" && lodoc.all.hUnReadSign.innerText-0==1){
		lbUnReadSign = true;
		lsURL +="&UnReadSign=" + lodoc.all.hUnReadSign.innerText;//add require for mark unread
		if (typeof lodoc.all.ID_UnReadSignDB=="object" && lodoc.all.ID_UnReadSignDB.innerText!="")
			lsURL +="&UnReadDB="+lodoc.all.ID_UnReadSignDB.innerText;
	}
	if (typeof lodoc.all.ID_SCROLLMSGCOUNTID=="object" && lodoc.all.ID_SCROLLMSGCOUNTID.innerText!="" && typeof top.document!="unknown"){
		loMsgCount = eval("top.document.all."+lodoc.all.ID_SCROLLMSGCOUNTID.innerText);
		if (typeof loMsgCount =="object"){//add require for get scrollmsg count
			lsURL +="&ScrollView=" + lodoc.all.ID_SCROLLVIEWNAME.innerText+"&MsgCountID=" + lodoc.all.ID_SCROLLMSGCOUNTID.innerText;
			if (typeof lodoc.all.ID_SCROLLFORMULA=="object")
				lsURL +="&ScrollFormula=" + lodoc.all.ID_SCROLLFORMULA.innerText;
		}
	}

	document.write('<iframe id="RunAgent" src="" style="display:none" width=0 height=0  Frameborder=No Border=0 Marginwidth=0 Marginheight=0 Scrolling=no></iframe>');

	var lsOldURL = ((window.parent.prevViewURL!=null)?window.parent.prevViewURL:"&");
	var lsNewURL = window.location.href+"&";
	window.parent.prevViewURL = lsNewURL.toLowerCase();
	var lbCountPage = false;
	if (lsOldURL==lsNewURL.toLowerCase() || lsOldURL.substring(0,lsOldURL.indexOf("&"))!=lsNewURL.substring(0,lsNewURL.indexOf("&")).toLowerCase())
		lbCountPage = true;
	else if (sGetParameter("argView",lsOldURL)!=sGetParameter("argView",lsNewURL))
		lbCountPage = true;

	if (typeof window.parent.document.all.tPage=="object"){
		if (lbCountPage == true){
			document.write('<iframe src='+lsURL+' style="display:none" width=0 height=0  Frameborder=No Border=0 Marginwidth=0 Marginheight=0 Scrolling=no></iframe>');
		}else{
			ShowViewCountInfo(parent.document.all.ID_ACount.innerText-0,liCount,false,window);
			if (lbUnReadSign == true) MarkUNRead();
		}
	}
	
	if (typeof window.parent.document.all.ID_PageCount=="object")
		window.parent.document.all.ID_PageCount.innerText = liCount;
	//show view bottom button bar	
	if (typeof window.parent.document.all.hButtonTable=="object")
		window.parent.document.all.hButtonTable.style.display = "block";
	if (typeof window.parent.document.all.hFTSTable=="object")
		window.parent.document.all.hFTSTable.style.display = "none";
}

function ShowViewCountInfo(piTotal,piCount,pbAgent,poWindow){
	var lodoc=(poWindow!=null)?poWindow.document:window.parent.document;
	var loParent=(poWindow!=null)?poWindow.parent.document:window.parent.parent.document;
	var liTotalPage = 1;
	if (piTotal>0 && piCount>0){
		liTotalPage = parseInt((piTotal/piCount));
		if (liTotalPage*piCount<piTotal) liTotalPage++;
	}
	if (typeof lodoc.all.ACount=="object") lodoc.all.ACount.innerText = piTotal;
	if (typeof lodoc.all.tPage=="object") lodoc.all.tPage.innerText = liTotalPage;
	if (typeof loParent!="object") return false;
	if (typeof loParent.all.ID_ACount=="object") loParent.all.ID_ACount.innerText = piTotal;
	if (typeof loParent.all.hFTSCount=="object" && loParent.all.hFTSTable.style.display!="none")
		loParent.all.hFTSCount.innerText = piTotal;
	if (typeof loParent.all.tPage=="object") loParent.all.tPage.innerText = liTotalPage;
	if (piCount==piTotal && (pbAgent==true || loParent.all.hFTSTable.style.display!="none"))
		loParent.all.ID_PageCount.innerText = piCount;
	if (typeof loParent.all.SelectAll=="object"){
		if (typeof lodoc.all.$$SelectDoc=="object"){
			loParent.all.SelectAll.style.display = "block";
			loParent.all.SelectAll.checked = false;
		}else
			loParent.all.SelectAll.style.display="none";
	}
	if (typeof loParent.all.ID_FirstPage=="object"){
		var liTotal = liTotalPage;
		var liIndex = loParent.all.dPage.innerText-0;
		if (liIndex>1){
			loParent.all.ID_FirstPage.disabled=false;
			loParent.all.ID_PrevPage.disabled=false;
		}else{
			loParent.all.ID_FirstPage.disabled=true;
			loParent.all.ID_PrevPage.disabled=true;
		}
		if (liIndex<liTotal){
			loParent.all.ID_NextPage.disabled=false;
			loParent.all.ID_LastPage.disabled=false;
		}else{
			loParent.all.ID_NextPage.disabled=true;
			loParent.all.ID_LastPage.disabled=true;
		}
		if (typeof loParent.all.hFTSCount=="object" && loParent.all.hFTSTable.style.display!="none") return false;
		var liType = lodoc.all.hViewType.innerText - 0;
		if ((liType==2 || liType==4) && typeof lodoc.all.ID_ViewCommand=="object"){//Domino action model
			var lsDefault = lodoc.all.ID_ViewCommand.Default;//View default show type
			var lsURL = (poWindow!=null)?poWindow.location.href:window.parent.location.href;
			if (!(lsURL.indexOf("&ExpandView")!=-1 || lsDefault=="Expand" && (lsURL.indexOf("&CollapseView")==-1 || lsURL.indexOf("&Collapse=")==-1 || lsURL.indexOf("&Expand=")==-1))){//default Collapse or action Collapse/Expand/CollapseView and not ExpandView;
				var lsStart = sGetParameter("Start",lsURL);
				if (lsStart=="" || lsStart=="0" || lsStart=="1"){
					loParent.all.ID_FirstPage.disabled=true;
					loParent.all.ID_PrevPage.disabled=true;
				}
				var oEntries = lodoc.getElementsByName('ViewEntry');
				if (oEntries.length<piCount){
					loParent.all.ID_NextPage.disabled=true;
				}
				loParent.all.ID_LastPage.disabled=true;
			}
		}
	}
}

function ShowViewTitle(psTableID){
	var loTable=null;
	if (psTableID!=null && typeof document.all[psTableID]=="object"){
		loTable = document.all[psTableID];
	}else if (typeof document.all.hViewTitle=="object"){
		loTable = document.all.hViewTitle;
	}else{
		for (i=0; i<document.all.length;i++){
			if (document.all[i].tagName=="TH") break;
		}
		if (i<document.all.length){
			loTable = document.all[i];
			while(loTable = loTable.parentElement){
				if (loTable.tagName=="TABLE") break;
			}
		}
	}
	var loTitle=null;
	if (typeof parent.document.all.ID_View_Title=="object"){
		loTitle = parent.document.all.ID_View_Title;
	}
	if (loTitle!=null){
		if (loTable==null){
			loTitle.innerHTML="&nbsp;"
			parent.document.all.hViewTitleTable.style.display = "none";
		}else{
			loTable.style.display="none";
			var lsHTML = sReplaceSubstring(loTable.innerHTML,"TH","td class=ViewTitle");
			var loObject = loTable;
			if (loObject.children[0].tagName=="TBODY") loObject = loObject.children[0].children[0];
			var lsDescend = sGetParameter("ResortDescending");
			var lsAscend = sGetParameter("ResortAscending");
			var lsTemp = sGetLang("P_CONST_COLUMNSORT");
			for (var i=0;i<loObject.children.length;i++){
				var lsIndex = loObject.children[i].columnIndex;
				var lsInner = loObject.children[i].innerHTML;
				if (loObject.children[i].tagName=="TH" && lsIndex!=null && lsIndex!=""){
					var lsOne = '<table title="'+lsTemp+'" width="100%" height="50%" border="0" cellspacing="0" cellpadding="0" onclick="ColumnSort('+lsIndex+');" style="cursor:hand" onMouseOver="this.children[0].children[0].style.textDecoration=\'underline\';" onMouseOut="this.children[0].children[0].style.textDecoration=\'none\';"><tr><td rowspan="3" class=ViewTitle width=1% nowrap>'+lsInner+'&nbsp;</td><td style="vertical-align:bottom"><img src="'+gsImgURL+((lsIndex==lsAscend)?'ico_ascend.gif':'ico_sortup.gif')+'" style="cursor:default" onclick="Ascend('+lsIndex+');"></td></tr><tr><td style="height:1px"></td></tr><tr><td style="vertical-align:top"><img src="'+gsImgURL+((lsIndex==lsDescend)?'ico_descend.gif':'ico_sortdown.gif')+'" style="cursor:default" onclick="Descend('+lsIndex+');"></td></tr></table>';
					lsHTML = sReplaceSubstring(lsHTML,">"+lsInner+"<",">"+lsOne+"<");
				}
			}
			loTitle.innerHTML='<table width="100%" border="0" cellspacing="0" cellpadding="0">'+lsHTML+"</table>";
			parent.document.all.hViewTitleTable.style.display = "block";
		}
	}
}

function ShowFTSearchPage(){
	var lsOne,lsUNID,lsTemp,laID,laLink,lsFolder="",loTr,lsHTML="";
	var lsDataType = document.all.ID_FTSearchType.value.trim();
	if (lsDataType=="" && document.all.Hits.value-0>0){
		lsDataType="1";
		var oEntries = document.getElementsByName('ViewEntry');
		if (oEntries!=null && oEntries.length>0){
			lsDataType="0";
		}else{
			oEntries = document.getElementsByName('ID_MultipleLink');
			if (oEntries!=null && oEntries.length>0) lsDataType="2";
		}
	}
	var lsDBName = (gsCurDBName.toLowerCase()==gsCurUser.toLowerCase()+".nsf")?gsCurEncodeName+".nsf":gsCurDBName;
	switch(lsDataType){
	case "0"://old view format
		lsHTML="<table border='0' width='100%' cellpadding='0' cellspacing='0' id='ID_SearchResult' CurDBURL='"+gsCurURL+lsDBName+"'>";
		var oEntries = document.getElementsByName('ViewEntry');
		if (oEntries!=null && oEntries.length>0){
			for (i=0; i<oEntries.length;i++){
				lsUNID="";
				if (oEntries[i].UNID!=null && oEntries[i].UNID!=""){
					lsUNID = oEntries[i].UNID;
				}else{
					lsTemp = oEntries[i].onclick.toString();
					if (lsTemp.indexOf("OpenDocument(")!=-1){
						lsTemp = lsTemp.substring(0,lsTemp.indexOf("?"));
						lsUNID = lsTemp.substring(lsTemp.lastIndexOf("/")+1,lsTemp.length);
					}
				}
				lsOne = '<tr valign="top"><TD><IMG ALIGN=top NAME="_SelectImg'+lsUNID+'" SRC="/icons/ecblank.gif" BORDER=0 HEIGHT=16 WIDTH=16></TD><TD><INPUT TYPE=checkbox NAME="$$SelectDoc" VALUE="'+lsUNID+'"></TD><td>';
				lsOne += oEntries[i].parentElement.parentElement.outerHTML;
				lsOne += '</td></tr>';
				lsHTML += lsOne;
			}
		}
		lsHTML += '</table>';
		break;
	case "1"://new view format
		if (typeof document.all.ID_SearchResult=="object"){
			document.all.ID_SearchResult.CurDBURL=gsCurURL+lsDBName;
			lsHTML = document.all.ID_SearchResult.outerHTML;
		}
		break;
	case "2"://kmcab view format
		if (typeof window.parent.ID_TerminalFolderID=="object")
			lsFolder = window.parent.ID_TerminalFolderID.innerText;
		var oEntries = document.getElementsByName('ID_MultipleLink');
		if (oEntries!=null && oEntries.length>0){
			for (i=0; i<oEntries.length;i++){
				laID = oEntries[i].eFileIDs.split(";");
				laLink = oEntries[i].eLinks.split(";");
				for(var k=0;k<laID.length;k++){
					if (lsFolder.indexOf(laID[k].substring(0,laID[k].lastIndexOf("-")))!=-1) break;
				}
				if (k>=laID.length) k=0;
				oEntries[i].eFileIDs='';
				oEntries[i].eLinks='';
				oEntries[i].eBody=laID[k].substring(0,laID[k].indexOf("-"))+"-"+oEntries[i].UNID;
				oEntries[i].eFileID=laID[k];
				oEntries[i].UNID = laLink[k].substring(laLink[k].indexOf("-")+1,laLink[k].length);
				loTr = oEntries[i].parentElement.parentElement.parentElement.parentElement;
				if(typeof loTr.children[0].children[0]=="object" && loTr.children[0].children[0].tagName=="INPUT"){
					loTr.children[0].children[0].value = oEntries[i].UNID;
				}
			}
		}
		if (typeof document.all.ID_SearchResult=="object"){
			document.all.ID_SearchResult.CurDBURL=gsCurURL+lsDBName;
			lsHTML = document.all.ID_SearchResult.outerHTML;
		}
		break;
	case "3"://old view use agent print mode
		if (typeof document.all.ID_SearchResult=="object"){
			document.all.ID_SearchResult.CurDBURL=gsCurURL+lsDBName;
			lsHTML = document.all.ID_SearchResult.outerHTML;
		}
		break;
	}
	
	var loObject = window.parent.FTObject.ExeObject;
	var liTotal=0,liCount=0,lbOldType=false;
	if (loObject==null){
		liTotal = document.all.TotalHits.value-0;
		liCount = document.all.Count.value-0;
		if (lsDataType=="0" || lsDataType=="3") var lbOldType = true;
	}else{
		loObject.TotalHits[loObject.URLIndex] = document.all.TotalHits.value-0;
		if ((loObject.Count==0 || loObject.showCount<loObject.Count) && document.all.Hits.value-0>0){
			loObject.showCount += document.all.Hits.value-0;
			if (loObject.DBTitles.length>1){
				loObject.showHTML  += "<table cellpadding=0 cellspacing=0 border='0' width='100%'><tr><td class=Entry_Category onclick='bShowFTSearchCategory("+loObject.showIndex+");'><img src='"+gsImgURL+"ico_desktopcollapse.gif' id='ID_Image_"+loObject.showIndex+"'>&nbsp;"+loObject.DBTitles[loObject.URLIndex]+"<font style='font-weight:normal;'>&nbsp;( "+document.all.Hits.value+" )</font></td></tr></table>";
			}
			loObject.showIndex++;
			loObject.showHTML  += lsHTML;
		}
		if ((lsDataType=="0" || lsDataType=="3") && document.all.Hits.value-0>0) loObject.showOldType = true;
		if(loObject.TotalHits.length<loObject.DBViews.length || (loObject.Count==0 || loObject.showCount<loObject.Count) && loObject.URLIndex<loObject.DBViews.length-1){//execute after url request
			loObject.URLIndex++;
			liCount = (loObject.Count>loObject.showCount)?loObject.Count-loObject.showCount:((loObject.Count>0)?1:0);
			var lsURL = loObject.DBViews[loObject.URLIndex] + "&Count=" + liCount + loObject.URLCmd + "&Query=" + loObject.QueryString;
			window.location.replace(lsURL);
			return;
		}
		for(var i=0;i<loObject.TotalHits.length;i++) liTotal += loObject.TotalHits[i];
		liCount = loObject.Count;
		lsHTML = loObject.showHTML;
		var lbOldType = loObject.showOldType;
	}

	var lodoc=window.parent.document;
	if (typeof lodoc=="object" && typeof lodoc.all.hViewBody=="object"){
		lodoc.all.hViewBody.ISFTSearch="1";
		lodoc.all.hViewBody.innerHTML=lsHTML;
	}

	ShowViewCountInfo(liTotal,liCount);

	if (lbOldType == true) window.parent.ShowPageInfo(true);
	if (top.SelectView == "1") ShowSelectInput();
	window.parent.HideViewLoading();
}


function bShowFTSearchCategory(piIndex){
	var oTables = document.getElementsByName("ID_SearchResult");
	var loSpan=oTables[piIndex];
	if(typeof loSpan=="object"){
		if(loSpan.style.display!="none")
			loSpan.style.display="none";
		else
			loSpan.style.display="";
	}
	var loSpanImage=eval("document.all.ID_Image_"+piIndex);
	if(typeof loSpanImage=="object" && typeof loSpan=="object"){
		if(loSpan.style.display!="none")
			loSpanImage.src=gsImgURL+"ico_desktopcollapse.gif";
		else
			loSpanImage.src=gsImgURL+"ico_desktopexpand.gif";
	}
	return true;
}



function MarkUNRead(psIDs){
	if (psIDs==null){
		var lodoc=window.document;
		if (!(typeof lodoc.all.hUnReadSign=="object" && lodoc.all.hUnReadSign.innerText-0==1)) return false;
		var lsDBName = (typeof lodoc.all.ID_UnReadSignDB=="object" && lodoc.all.ID_UnReadSignDB.innerText!="")?lodoc.all.ID_UnReadSignDB.innerText:gsCurDBName;
		var lsURL = encodeURI(gsOAURL) + gsSRDBName + "/agtCountPage?OpenAgent&DBPath=" + encodeURI(gsCurURL.substr(1) + lsDBName)+"&UnReadSign=1";
		if (typeof lodoc.all.ID_SCROLLMSGCOUNTID=="object" && lodoc.all.ID_SCROLLMSGCOUNTID.innerText!="" && typeof top.document!="unknown"){
			loMsgCount = eval("top.document.all."+lodoc.all.ID_SCROLLMSGCOUNTID.innerText);
			if (typeof loMsgCount =="object"){//add require for get scrollmsg count
				lsURL +="&ScrollView=" + lodoc.all.ID_SCROLLVIEWNAME.innerText+"&MsgCountID=" + lodoc.all.ID_SCROLLMSGCOUNTID.innerText;
			if (typeof lodoc.all.ID_SCROLLFORMULA=="object")
				lsURL +="&ScrollFormula=" + lodoc.all.ID_SCROLLFORMULA.innerText;
			}
		}
		document.write('<iframe src='+lsURL+' style="display:none" width=0 height=0  Frameborder=No Border=0 Marginwidth=0 Marginheight=0 Scrolling=no></iframe>');
	}else{
		var lodoc=window.document;
		if (typeof lodoc.all.hUnReadSign!="object" || lodoc.all.hUnReadSign.innerText-0!=1 || psIDs=="")return false;
		var laID = psIDs.split(";");
		var lsID,loURM,lsMark=sGetLang("P_CONST_UNREADMARK");
		for(i=0;i<laID.length;i++){
			lsID= new String("00000000");
			lsID = "NT" + lsID.substr(0,8-laID[i].length).concat(laID[i]);
			loURM=lodoc.getElementsByName(lsID);
			if (loURM==null || loURM.length==0) continue;
			for(var k=0;k<loURM.length;k++) loURM[k].innerHTML=lsMark;
		}
	}
}


function CheckInput(obj){
	var code=window.event.keyCode-0;
	if (!((code>95 && code<106) || (code>47 && code<59) || code==8 || code==46 || code==37 || code==39 || code==13)){alert(sGetLang("P_NOTNUMBER"));obj.value="";return false;}
}

/*
var laTemp=vGetKMCab(true,false,"ProjectAdmin","ZECAB.NTF");
if (laTemp!=null) goForm.CabName.value=laTemp["CabName"];
laTemp["CabID"];
*/
function vGetKMCab(pbMultiChoice,pbLimit,psCategory,psTemplate,psInitValue){
	var lsLimit = "&Limit=";
	var lsCategory = "&Category=";
	var lsTemplate = "&Template=";
	lsLimit += (pbLimit)?1:0;
	lsCategory += (psCategory!=null)?escape(psCategory):"";
	lsTemplate += (psTemplate!=null)?psTemplate:"";
	var lsURL=encodeURI(gsOAURL)+sGetLang('DB_NAME_KM')+"/agtKMCabTree?OpenAgent"+lsLimit+lsCategory+lsTemplate;
	if (psInitValue==null) psInitValue="";
	var rsTemp=PromptTree(true,psInitValue,lsURL,sGetLang("KM_PROMPTKMCAB"),pbMultiChoice);
	if (rsTemp==null) return null;
	var laTemp=rsTemp.split(";");
	var raValue = new Array();
	raValue['CabName']="";
	raValue['CabID']="";
	if (rsTemp.trim()=="") return raValue;
	for (var i=0; i<laTemp.length; i++){
		if (raValue['CabName']=="")
			raValue['CabName'] =  laTemp[i].substr(0,laTemp[i].indexOf("|"));
		else
			raValue['CabName'] += ";"+laTemp[i].substr(0,laTemp[i].indexOf("|"));
		if (raValue['CabID']=="")
			raValue['CabID'] = laTemp[i].substr(laTemp[i].indexOf("|")+1);
		else
			raValue['CabID'] += ";"+laTemp[i].substr(laTemp[i].indexOf("|")+1);
	}
	return raValue;
}
/*
var laTemp=vGetKMFolder(gsCurDBName.substr(1,5),"Admin",false,false,true);
if (laTemp!=null) goForm.ParentFolder.value=laTemp["FolderName"];
psRole:All/Admin/Author/User;
laTemp["FolderID"];
*/
function vGetKMFolder(psCabID,psRole,pbMultiChoice,pbTerminal,pbNoFile,psInitValue){
	var lsRole = "&Role=" + psRole;
	var lsTerminal = "&Terminal=";
	var lsNoFile = "&NoFile=";
	lsTerminal += (pbTerminal)?1:0;
	lsNoFile += (pbNoFile)?1:0;
	var lsCabID = (psCabID.indexOf("-")!=-1)?psCabID.substring(0,psCabID.indexOf("-")):psCabID;
	if (lsCabID.trim().toLowerCase()!=gsCurUser.trim().toLowerCase()){
		var lsURL=encodeURI(gsOAURL)+"z"+lsCabID+".nsf/agtFolderTree?OpenAgent"+lsRole+lsTerminal+lsNoFile;
	}else{
		var lsURL=encodeURI(gsOAURL)+sGetLang("P_CONST_PFOLDERDIR")+"/"+gsCurEncodeName+".nsf/agtFolderTree?OpenAgent"+lsRole+lsTerminal+lsNoFile;
	}
	if (psCabID.indexOf("-")!=-1) lsURL += "&FolderID=" + escape(psCabID);

	if (psInitValue==null) psInitValue="";
	var rsTemp=PromptTree(true,psInitValue,lsURL,sGetLang("KMCAB_PROMPTFOLDER"),pbMultiChoice);
	if (rsTemp==null) return null;
	var laTemp=rsTemp.split(";");
	var raValue = new Array();
	raValue['FolderName']="";
	raValue['FolderID']="";
	if (rsTemp.trim()=="") return raValue;
	for (var i=0; i<laTemp.length; i++){
		if (raValue['FolderName']=="")
			raValue['FolderName'] =  laTemp[i].substr(0,laTemp[i].indexOf("|"));
		else
			raValue['FolderName'] += ";"+laTemp[i].substr(0,laTemp[i].indexOf("|"));
		if (raValue['FolderID']=="")
			raValue['FolderID'] = laTemp[i].substr(laTemp[i].indexOf("|")+1);
		else
			raValue['FolderID'] += ";"+laTemp[i].substr(laTemp[i].indexOf("|")+1);
	}
	return raValue;
}

/*
var laTemp=vSetArchive("ProjectAdmin");
laTemp["CabName"]
laTemp["CabID"]
laTemp["FolderName"]
laTemp["FolderID"]
*/

function vSetArchive(psCategory,pbLimit){
	var laCab,laFolder;
	var raValue = new Array();
	raValue['CabName']="";
	raValue['CabID']="";
	raValue['FolderName']="";
	raValue['FolderID']="";
	var lbLimit=(pbLimit==null)?false:pbLimit;
	laCab=vGetKMCab(true,lbLimit,psCategory);
	if (laCab==null) return null;
	if (laCab["CabID"].trim()=="") return raValue;
	var laCabID=laCab["CabID"].split(";");
	var laCabName=laCab["CabName"].split(";");
	for (var i=0; i<laCabID.length; i++){
		laFolder=vGetKMFolder(laCabID[i],'All',true,true,false);
		if (laFolder==null || laFolder['FolderName']=='') continue;
		
		if (raValue['CabID']=="")
			raValue['CabID'] = "z" + laCabID[i] + ".nsf";
		else
			raValue['CabID'] += ";z" + laCabID[i] + ".nsf";

		if (raValue['CabName']=="")
			raValue['CabName'] = laCabName[i];
		else
			raValue['CabName'] += ";" + laCabName[i];

		if (raValue['FolderID']=="")
			raValue['FolderID'] = laFolder['FolderID'];
		else
			raValue['FolderID'] += ";" + laFolder['FolderID'];

		if (raValue['FolderName']=="")
			raValue['FolderName'] = laFolder['FolderName'];
		else
			raValue['FolderName'] += ";" + laFolder['FolderName'];
	}	

	return raValue;

}

/*
PromptTree(pbModal,psTargetFieldName,psURL,psWindowTitle,pbMultiChoice,pbShowCategoryBox,psCategories,piWidth,piHeight)
*/
function PromptTree(){
	var lvArguments=PromptTree.arguments;
	if (lvArguments.length<2) return false;

	var lbModal=lvArguments[0];
	var lsTarget="&ReturnTarget="+lvArguments[1];
	var lsViewName=(lvArguments.length>=3)?("&URL="+lvArguments[2]):"";
	var lsWinTitle=(lvArguments.length>=4)?("&WindowTitle="+escape(lvArguments[3])):"";
	var lsMultiChoice=(lvArguments.length>=5 && lvArguments[4]==true)?"&MultiChoice=1":"";
	var lsShowCategoryBox=(lvArguments.length>=6 && lvArguments[5]==true)?"&ShowCategoryBox=1":"";
	var lsCategories=(lvArguments.length>=7)?"&Categories="+lvArguments[6]:"";
	var liWidth=(lvArguments.length>=8 && lvArguments[7]!=null)?lvArguments[7]:300;
	var liHeight=(lvArguments.length>=9 && lvArguments[8]!=null)?lvArguments[8]:500;
	var lsMode="Directory=no,Menu=no,Status=no,ScrollBars=no,Resizable=no,";
	var lsSize="left="+(screen.width-liWidth)/2+",top="+(screen.Height-liHeight-50)/2 + ",width="+liWidth+",height="+liHeight;
	var lsWinName="SelectUnit";
	var lsURL=encodeURI(gsOAURL)+gsSRDBName+"/frmShowTree?OpenForm"
	var lsURLArguments=lsTarget+lsWinTitle+lsShowCategoryBox+lsMultiChoice+lsCategories+lsViewName;

	if(lbModal)
		return vOpenModal(lsURL+lsURLArguments,lvArguments[1],liWidth,liHeight);
	else
		window.open(lsURL+lsURLArguments,lsWinName,lsMode+lsSize);
}


/*
PromptView(pbModal,psTargetFieldName,psURL,psWindowTitle,pbMultiChoice,piWidth,piHeight,pbShowCategoryBox,psCategories)
*/
function PromptView(){
	var lvArguments=PromptView.arguments;
	if (lvArguments.length<3) return false;

	var lbModal=lvArguments[0];
	var lsTarget="&ReturnTarget="+lvArguments[1];
	var lsViewName=(lvArguments.length>=3)?("&URL="+lvArguments[2]):"";
	if(lsViewName.toLowerCase().indexOf("&count=")==-1) lsViewName += "&Count="+giPCount;
	//lsViewName+=(lvArguments.length>=3)?("&ViewURL="+lvArguments[2]):"";
	var lsWinTitle=(lvArguments.length>=4)?("&WindowTitle="+escape(lvArguments[3])):"";
	var lsMultiChoice=(lvArguments.length>=5 && lvArguments[4]==true)?"&MultiChoice=1":"";
	var liWidth=(lvArguments.length>=6 && lvArguments[5]!=null)?lvArguments[5]:310;
	var liHeight=(lvArguments.length>=7 && lvArguments[6]!=null)?lvArguments[6]:550;
	var lsShowCategoryBox=(lvArguments.length>=8 && lvArguments[7]==true)?"&ShowCategoryBox=1":"";
	var lsCategories=(lvArguments.length>=9)?"&Categories="+lvArguments[8]:"";
	//var liWidth=700,liHeight=500;
	var lsMode="Directory=no,Menu=no,Status=no,ScrollBars=no,Resizable=no,";
	var lsSize="left="+(screen.width-liWidth)/2+",top="+(screen.Height-liHeight-50)/2 + ",width="+liWidth+",height="+liHeight;
	var lsWinName="SelectUnit";
	var lsURL=encodeURI(gsOAURL)+gsSRDBName+"/frmSelectView?OpenForm";
	var lsURLArguments=lsTarget+lsWinTitle+lsShowCategoryBox+lsMultiChoice+lsCategories+lsViewName;
	if(lbModal){
		var laArguments = new Array();
		laArguments["ReturnTarget"] = lvArguments[1];
		if(lvArguments[1] != "" && eval("typeof goForm."+lvArguments[1]) == "object"){
			laArguments["InitValue"] = eval("goForm."+lvArguments[1]+".value");
		}
		return vOpenModal(lsURL+lsURLArguments,laArguments,liWidth,liHeight);
	}else{
		window.open(lsURL+lsURLArguments,lsWinName,lsMode+lsSize);
	}
}

function bNewWork(psFlowType,psFlowName,psApplyID,psDocs,psArgument){
	var lsDBName = sGetLang("DB_NAME_ENGINE");
	var lsURL = encodeURI(gsOAURL) + lsDBName + "/agtNewWork?OpenAgent";
	if (psFlowName!=null && psFlowName!=""){
		lsURL += "&Flow="+escape(((psFlowType!=null && psFlowType!="")?psFlowType+"/":"")+psFlowName);
	}else{
		if (psApplyID!=null && psApplyID!=""){
			lsURL += "&Apply="+psApplyID;
		}else{
			lsURL += "&FlowType="+escape((psFlowType==null)?"":psFlowType);
		}
		var loRet=PromptTree(true,"Name",lsURL,sGetLang("ENGINE_NEWWORK"),false,false,"");
		if(loRet==null || loRet=="") return false;
		var liIndex=loRet.indexOf("|");
		var lsFlow=loRet.substr(0,liIndex);
		var lsFormName=loRet.substr(liIndex+1);
		var lvForms=lsFormName.split(";");
		if(lvForms.length>1){
			var lsReturn=sSelectArray("Single",sGetLang("FLOW_SELECTCATEGORY"),"",lsFormName);
			if(lsReturn==null)return false;
			lsFormName=lsReturn;
		}else{
			liIndex=lsFormName.indexOf("|");
			if(liIndex>-1)	lsFormName=lsFormName.substr(liIndex+1);
		}
		lsURL = encodeURI(gsOAURL)+lsDBName+"/"+lsFormName+"?OpenForm&Flow="+escape(lsFlow);
	}
	if (psDocs!=null && psDocs!="") lsURL += "&From=" + psDocs;
	if (psArgument!=null && psArgument!="") lsURL += "&Argument=" + psArgument;
	OpenDocument(lsURL,"");
	return true;
}


function bStow(pbStowFile,psFolderID,psComment){
	var lbView=(typeof top.ViewIFrame =="object") ? true:false;
	if (lbView==true){
		if (typeof top.document!="unknown"){
			var loframe= top.ViewIFrame;
		}else{
			return false;
			var loframe= top.ViewIFrame.MailIframe;
		}
		if (typeof loframe!="object") return false;
		if (typeof loframe.hStowSign=="object" && loframe.hStowSign.innerText-0!=1) return false;
		var lsIDs =sGetSelected(sGetLang('FOLDER_STOWFILE'));
		if (lsIDs=="") return false;
	}else{
		if (typeof top.opener.top.document=="unknown"){
			alert (sGetLang("MAIL_STOWCANNOTUSE"))	
			return false;
		}
		if (gsCurUNID==null) return false;
		var lsIDs=gsCurUNID+"|";
	}
	var lbStowFile = (pbStowFile!=null)?pbStowFile:window.confirm(sGetLang('FOLDER_ISSTOWFILE'));
	var lsApply = (lbStowFile==false)?"StowLink":"StowFile";
	if (psFolderID!=null && psFolderID!=""){
		var lsFolderID = psFolderID;
	}else{
		var laTemp=vGetKMFolder(gsCurUser.trim(),"ALL",(lbStowFile==false)?true:false,true,false);
		if (laTemp==null) return false;
		var lsFolderID=laTemp["FolderID"];
		if (lsFolderID=="") return false;
	}
	var lsComment=(psComment!=null)?psComment:sGetComment(sGetLang("FOLDER_STOWMSGTITLE"),sGetLang("FOLDER_STOWMSGINFO"));
	var lsArgs = "&FolderIDs=" + lsFolderID;
	if (typeof goForm=="object" && typeof goForm.e_Input=="object")
		lsArgs += "&LinkUNID=" + sGetParameter("LinkUNID",goForm.e_Input.value);
	var lsURL=encodeURI(gsOAURL) + gsSRDBName + "/frmAutoClose?Openform";
	if (lbView==true) window.argDBName=loframe.gsCurURL.substr(1)+loframe.gsCurDBName;
	window.argComment = lsComment;
	WebAction(lsURL,lsApply,lsIDs,lsArgs);
}

function bRecommend(psUsers,psComment){
	var lbView=(typeof top.ViewIFrame =="object") ? true:false;
	if (lbView==true){
		if (typeof top.document!="unknown"){
			var loframe= top.ViewIFrame;
		}else{
			return false;
			var loframe= top.ViewIFrame.MailIframe;
		}
		if (typeof loframe!="object") return false;
		if (typeof loframe.hStowSign=="object" && loframe.hStowSign.innerText-0!=1) return false;
		var lsIDs =sGetSelected(sGetLang('FOLDER_RECOMMENDFILE'));
		if (lsIDs=="") return false;
	}else{
		if (typeof top.opener.top.document=="unknown") return false;
		if (gsCurUNID==null) return false;
		var lsIDs=gsCurUNID+"|";
	}
	if (psUsers!=null && psUsers!=""){
		var lsUsers = psUsers;
	}else{
		var lsUsers=PromptUnit(true,"","All",sGetLang("FOLDER_PROMPTFRIEND"),true,true);
		if(lsUsers==null || lsUsers=="") return false;
	}
	var lsComment=(psComment!=null)?psComment:sGetComment(sGetLang("FOLDER_RECOMMENDMSGTITLE"),sGetLang("FOLDER_RECOMMENDMSGINFO"));
	var lsArgs = "&Users=" + lsUsers;
	if (typeof goForm=="object" && typeof goForm.e_Input=="object")
		lsArgs += "&LinkUNID=" + sGetParameter("LinkUNID",goForm.e_Input.value);
	var lsURL=encodeURI(gsOAURL) + gsSRDBName + "/frmAutoClose?Openform";
	if (lbView==true) window.argDBName=loframe.gsCurURL.substr(1)+loframe.gsCurDBName;
	window.argComment = lsComment;
	WebAction(lsURL,"Recommend",lsIDs,lsArgs);
}

function vPromptAddress(){
	//if (psFieldName=)
	var lvArguments=vPromptAddress.arguments;
	if (lvArguments.length<3) return false;
	var pbMultiChoice=lvArguments[0];
	var psFieldName=lvArguments[1];
	if (psFieldName==null) psFieldName="EMail";
	var psInitValue=lvArguments[2];	
	var psAddressType=(lvArguments.length>=4)?lvArguments[3]:"";
	var psReturnTarget=(lvArguments.length>=5 && psFieldName!="")?lvArguments[4]:"";	
	var lsFieldName = "&FieldName=";
	lsFieldName += (psFieldName!=null)?psFieldName:"EMail";
	var lsAddressType="&AddressType=";
	lsAddressType+=(psAddressType!=null && psAddressType!="")?psAddressType:"All"
	var lsURL=encodeURI(gsOAURL)+sGetLang('DB_NAME_ADDRESS')+"/agtAddressTree?OpenAgent"+lsFieldName+lsAddressType;
	if (psInitValue==null) psInitValue="";
	var rsTemp=PromptTree(true,psInitValue,lsURL,sGetLang("ADDRESS_PROMPTADDRESS"),pbMultiChoice);
	if (rsTemp==null) return null;
	var laTemp=rsTemp.split(";");
	var raValue = new Array();
	raValue['Name']="";
	raValue['Field']="";
	if (rsTemp.trim()=="") return raValue;
	for (var i=0; i<laTemp.length; i++){
		if (raValue['Name']=="")
			raValue['Name'] =  laTemp[i].substr(0,laTemp[i].indexOf("|"));
		else
			raValue['Name'] += ";"+laTemp[i].substr(0,laTemp[i].indexOf("|"));
		if (raValue['Field']=="")
			raValue['Field'] = laTemp[i].substr(laTemp[i].indexOf("|")+1);
		else
			raValue['Field'] += ";"+laTemp[i].substr(laTemp[i].indexOf("|")+1);
	}
	if (psReturnTarget.trim()=="")
		return raValue;
	else{	
		var xmlhttp = oGetXmlHttpRequest();
		if (xmlhttp!=null){
			var lsURL = encodeURI(gsOAURL)+sGetLang('DB_NAME_ADDRESS')+"/agtExplainAddress?openagent" +lsFieldName+lsAddressType+"&Print=1&ParentSN="+raValue['Field'] + "&t="+((new Date()).valueOf());
			xmlhttp.onreadystatechange = bSetExplainValue;
			xmlhttp.open("GET",lsURL, false);
			xmlhttp.send('');
		}
		return raValue;
	}
	
	function bSetExplainValue(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200 ) {
    			var lsText = xmlhttp.responseText;
    			var lsReturn="";
    			if (lsText.indexOf("<ReturnValue>")!=-1 && lsText.indexOf("</ReturnValue>")!=-1){
				 lsReturn = lsText.substring(lsText.indexOf("<ReturnValue>")+13,lsText.indexOf("</ReturnValue>"));
			}
			if (lsReturn=="") return false;			
			var loReturnTarget=eval("goForm."+psReturnTarget);
			if (typeof loReturnTarget=="object"){
				loReturnTarget.value=lsReturn;
				//opener.document.all(loReturnTarget).value=lsReturn;
			}	
  		}
	}
}

function SendMsg(psSendTo,psApply,psDB,psIDs,psArg,poMsg,pbSendAtTime){
	//var lsSendTo=(psSendTo!=null && psSendTo!=null)?("&SendTo="+escape(psSendTo)):"";
	var lsApply=(psApply!=null && psApply!="")?("&Apply="+psApply):"";
	var lsSendAtTime = "&SendAtTime="+((pbSendAtTime==true)?"1":"0");
	var liWidth=410,liHeight=550;
	var lsMode="Directory=no,Menu=no,Status=no,ScrollBars=no,Resizable=yes,";
	var lsSize="left="+(screen.width-liWidth)/2+",top="+(screen.Height-liHeight-50)/2+",width="+liWidth+",height="+liHeight;
	var lsWinName="SendMsg";
	var lsURL=encodeURI(gsOAURL)+sGetLang("DB_NAME_MESSAGE")+"/frmSendMsg?OpenForm"+lsApply+lsSendAtTime;
	var loWindow = window;
	if (typeof top.opener=="object" && typeof top.opener.top.RunAgent=="object") loWindow = top.opener;
	loWindow.objDB = psDB;
	loWindow.objIDs= psIDs;
	loWindow.objArg= psArg;
	loWindow.objSendTo = psSendTo;
	if (poMsg!=null){
		if(typeof poMsg=="object"){
			var lsMsg = "======= "+poMsg.eTime+"  "+poMsg.eFrom+" =======\r\n";
			var lsTemp = poMsg.innerHTML;
			/*
			var lsTemp = poMsg.innerText;
			if (lsTemp.lastIndexOf("]")==lsTemp.length-1 && lsTemp.lastIndexOf("[")==lsTemp.length-6)
				lsTemp = lsTemp.substring(0,lsTemp.length-6);
			*/
			lsMsg += lsTemp + "\r\n";
			
			lsMsg +="=====================================";
			loWindow.objContent=lsMsg;
		}else if(typeof poMsg == "string"){
			lsURL+="&UNID="+poMsg;
		}
	}
	var loNewWin=window.open(lsURL,lsWinName,lsMode+lsSize);
	loNewWin.opener=loWindow;
	return loNewWin;
}

function SendMail(psSendTo){
	var xmlhttp = oGetXmlHttpRequest();
	if (xmlhttp==null) return "";
	var lsURL = encodeURI(gsOAURL)+sGetLang("DB_NAME_UNITADM")+"/agtGetUserMail?openagent&UserName="+escape(gsCurUser);
	xmlhttp.open("GET",lsURL, false);
	xmlhttp.send();
	var lsText = xmlhttp.responseText;
	var lsMailServer = "";
	if (lsText.indexOf("<MailServer>")!=-1 && lsText.indexOf("</MailServer>")!=-1){
		 lsMailServer = lsText.substring(lsText.indexOf("<MailServer>")+12,lsText.indexOf("</MailServer>"));
	}

	var lsMailFile = "";
	if (lsText.indexOf("<MailFile>")!=-1 && lsText.indexOf("</MailFile>")!=-1){
		 lsMailFile = lsText.substring(lsText.indexOf("<MailFile>")+10,lsText.indexOf("</MailFile>"));
	}
	if(lsMailFile == "") return;
	var lsWinName = "SendMail";
	var lsSendTo=(psSendTo!=null && psSendTo!=null)?("&SendTo="+escape(psSendTo)):"";
	var lsMailURL = ((lsMailServer=="")?"":lsMailServer)+"/"+sReplaceSubstring(lsMailFile,"\\","/")+"/Memo?OpenForm"+lsSendTo;
	var loNewWin=OpenDocument(lsMailURL,lsWinName);
	return loNewWin;
}

function ShowSchedule(psUsers,psDate){
	if (psUsers==null || psUsers=="") return null;
	var lsDate=(psDate!=null)?"&Date="+psDate:"";
	var lsURL=encodeURI(gsOAURL)+sGetLang("DB_NAME_SCHEDULE")+"/frmGroupCalendar?OpenForm&Users="+escape(psUsers)+lsDate;
	var loNewWin=OpenDocument(lsURL,"");
	return loNewWin;
}


/*
var laTemp=vSetArchive2();
laTemp["CabName"]
laTemp["CabID"]
*/
function vSetArchive2(){
	var lsDBName = sGetLang("DB_NAME_ENGINE");//in modal,it return null
	lsDBName="zEngine.nsf";
	var laCab;

	laCab=PromptTree(true,"Name",gsOAURL + lsDBName + "/agtSetArchive?OpenAgent",sGetLang("SYSRES_PROMPTARCHIVEDB"),true,false,"");
	if (laCab==null) return null;

	var laTemp=laCab.split(";");
	var raValue = new Array();
	raValue['CabName']="";
	raValue['CabID']="";
	for (var i=0; i<laTemp.length; i++){
		if (raValue['CabName']=="")
			raValue['CabName'] =  laTemp[i].substr(0,laTemp[i].indexOf("|"));
		else
			raValue['CabName'] += ";"+laTemp[i].substr(0,laTemp[i].indexOf("|"));
		if (raValue['CabID']=="")
			raValue['CabID'] = laTemp[i].substr(laTemp[i].indexOf("|")+1);
		else
			raValue['CabID'] += ";"+laTemp[i].substr(laTemp[i].indexOf("|")+1);
	}
	return raValue;
}

/*
var laTemp=vGetArchive(true/false,"s_DArchDB","s_ArchDB","s_DArchFolder","s_ArchFolder");
laTemp["CabName"]
laTemp["CabID"]
laTemp["FolderName"]
laTemp["FolderID"]
*/
function vGetArchive(pbModal,psDArchDB,psArchDB,psDArchFolder,psArchFolder,pbLimit){
	var lsCabName="&CabName="+psDArchDB;
	var lsCabID="&CabID="+psArchDB;
	var lsFolderName="&FolderName="+psDArchFolder;
	var lsFolderID="&FolderID="+psArchFolder;
	var lsDBName=sGetLang("DB_NAME_ENGINE");
	var lsLimit=(pbLimit==null)?"":"&Limit=1";
	var lsURL=encodeURI(gsOAURL) + gsSRDBName + "/frmSetArchive?OpenForm"+lsCabName+lsCabID+lsFolderName+lsFolderID+lsLimit;
	var liWidth=500,liHeight=250;
	var lsMode="Directory=no,Menu=no,Status=no,ScrollBars=no,Resizable=no,";
	var lsSize="left="+(screen.width-liWidth)/2+",top="+(screen.Height-liHeight-50)/2+",width="+liWidth+",height="+liHeight;
	
	if(pbModal)
		return vOpenModal(lsURL,"",liWidth,liHeight,"scroll:no;");
	else
		window.open(lsURL,"",lsMode+lsSize);
}

function vSelectFlow(pbMultiChoice,psType){
	//psType:all/creator/user/admin;
	var lsDBName = sGetLang("DB_NAME_FLOW");
	var lsType="";
	if(psType!=null && psType!="") lsType="&Type="+escape(psType);
	var loRet=PromptTree(true,"",gsOAURL + lsDBName + "/agtFlowTree?OpenAgent"+lsType,sGetLang("ENGINE_SELECTFLOW"),pbMultiChoice,false,"");
	return loRet;
}

function vSelectFields(psFlowType,psFlowName,pbMultiChoice,psFormName){
	var lsDBName = sGetLang("DB_NAME_FLOW");
	var lsFlowType="&FlowType="+escape(psFlowType);
	var lsFlowName="&FlowName="+escape(psFlowName);
	var lsFormName="";
	lsFormName=(psFormName==null)?"":"&FormName="+escape(psFormName);
	var lbMultiChoice=(pbMultiChoice==null)?true:pbMultiChoice;
	var loRet=PromptTree(true,"",gsOAURL + lsDBName + "/agtSelectFields?OpenAgent"+lsFlowType+lsFlowName+lsFormName,sGetLang("FLOW_SELECTFIELD"),lbMultiChoice,false,"");
	return loRet;
}

function vSelectForm(psFlowType,psFlowName){
	var lsDBName = sGetLang("DB_NAME_FLOW");
	var loRet=PromptTree(true,"",gsOAURL + lsDBName + "/agtSelectForm?OpenAgent","",false,false,"");
	return loRet;
}

//-----------UploadControl start----------------------------------------------------------------
function UploadFiles(poUploadControl){	//called by save event
	for (var i = 0; i < goForm.elements.length; i++){
		if(typeof(goForm.elements[i].type)=="string" && goForm.elements[i].type.toLowerCase() == "file" && goForm.elements[i].value!=""){
			poUploadControl.DelAll();
			lsAddList = goForm.elements[i].value.substr(goForm.elements[i].value.lastIndexOf('\\')+1);
			if(iGetStringByte(lsAddList) > 128){
				alert(sGetLang("P_CONST_FILENAMETOOLONG"));
				return false;
			}
			poUploadControl.AddLocalFile(goForm.elements[i].value);
		}
	}
	if(typeof goAttachManager!="undefined")
		if(!goAttachManager.UploadAttachment()) return false;
	return true;
}

function UploadLocalFile(psFilePath,poUploadControl,pbCallForRTF){
	var loUploadControl = (poUploadControl==null)?goForm.UploadControl:poUploadControl;
	if((typeof(loUploadControl)!="object") || (gbIsEdit==false))return false;
	var lsFileName = psFilePath.substr(psFilePath.lastIndexOf("\\")+1);
	if(iGetStringByte(lsFileName) > 128){
			alert(sGetLang("P_CONST_FILENAMETOOLONG"));
			return false;
	}
	if(pbCallForRTF=true && goForm.s_RTFFiles){
		if (goForm.s_RTFFiles.value==""){
			goForm.s_RTFFiles.value = lsFileName;
		}else{
			goForm.s_RTFFiles.value += "|" + lsFileName;
		}
	}
	if(!loUploadControl.UploadFile2(psFilePath)) return false;
	if(goForm.s_AddList){
		if (goForm.s_AddList.value==""){
			goForm.s_AddList.value = lsFileName;
		}else{
			goForm.s_AddList.value += "|" + lsFileName;
		}
	}
	return true;
}

function bAttachmentsModified(poUploadControl){
	if(typeof goAttachManager!="undefined")
		return goAttachManager.IsModified();
	return false;
}

function AttachManager(psAttachList,poUploadControl){
	var loUploadControl = (poUploadControl!=null)?poUploadControl:goForm.UploadControl;
	var lsAttachList = (psAttachList!=null)?psAttachList:((window.ID_SpanAttachList==null)?"":window.ID_SpanAttachList.innerText);
	var lsSplit = ":";
	var gaAttachList = new Array();
	this.RIGHT_SHOW = "ShowAttach";
	this.RIGHT_ADD	=	"AddAttach";
	this.RIGHT_DEL = "DelAttach";
	this.RIGHT_SAVE = "SaveAttach";
	this.RIGHT_EDIT = "EditAttach";
	this.RIGHT_HIDE = "HideAttach";
	
	this.CreateAttachList = function(psName,piType,psRights){
		var lsName = (psName==null)?"":psName;
		var liType = (piType==null)?0:piType;
		var lsRights = (psRights==null)?"":psRights;
		var loAttachList = GetAttachList(lsName);
		if(null == loAttachList){
			if(lsAttachList!=""){
				var laAttachList = lsAttachList.split(lsSplit);
				for(var i=0;i<laAttachList.length;i++){
					if(laAttachList[i].indexOf(lsName+"|")==0){
						lsName = laAttachList[i];break;
					}
				}
			}
			if(liType==0){
				var loAttachList = new AttachmentView(lsName,lsRights);
			}else{
				var loAttachList = new AttachmentList(lsName,lsRights);
			}
			gaAttachList.push(loAttachList);
		}
		return loAttachList;
	}
	
	this.initAttachList = function(){
		var loSpanList = document.getElementsByName("_SPANATTACH");
		for(var i=0;i<loSpanList.length;i++){
			this.CreateAttachList(loSpanList[i].name,0,loSpanList[i].Rights);
		}
	}
	
	this.AddAttachment = function(psName,psFileName){
		var loAttachList = this.CreateAttachList(psName);
		return loAttachList.AddAttachment(psFileName);
	}
	
	this.DelAttachment = function(psName,psFileName){
		var loAttachList = this.CreateAttachList(psName);
		return loAttachList.DelAttachment(psFileName);
	}
	
	this.EmptyAttachment = function(psName){
		var loAttachList = this.CreateAttachList(psName);
		return loAttachList.EmptyAttachment();
	}
	
	this.UploadAttachment = function(){
		if(!this.IsModified()) return true;
		if(!this.GetModifiedFiles()) return false;
		goForm.s_AttachList.value = "";
		for(var i=0;i<gaAttachList.length;i++){
			var loAttachList = gaAttachList[i];

			//all attach list
			var lsAttachList = loAttachList.GetAttachString();
			if(lsAttachList!=""){
				if(goForm.s_AttachList.value!="") goForm.s_AttachList.value += lsSplit;
				goForm.s_AttachList.value += lsAttachList;
			}
			
			//del file list
			var lsDelList = loAttachList.GetDelString();
			if(lsDelList!=""){
				if(goForm.s_DelList.value.trim()!="") goForm.s_DelList.value+="|";
				goForm.s_DelList.value += lsDelList;
				
				//domino detachfile html
				var lsDetach="";
				var laDelList = lsDelList.split("|");
				for (var j=0; j<laDelList.length; j++){
					if (laDelList[j].trim()!="")
						lsDetach = lsDetach + "<input type='text' name='%%Detach' value='"+laDelList[j]+"'>";
				}
				hDetachFile.innerHTML += lsDetach;
			}
			
			//add file list
			var lsAddList = loAttachList.UploadAttachment();
			if(lsAddList!=""){
				if(goForm.s_AddList.value!="") goForm.s_AddList.value += "|";
				goForm.s_AddList.value += lsAddList;
			}
		}
		return true;
	}
	
	this.GetModifiedFiles = function(){
		var laEditedFiles = new Array();
		for(var i=0;i<gaAttachList.length;i++){
			if(gaAttachList[i].aGetEditedFiles()!=null){
				if(gaAttachList[i].aGetEditedFiles().join(";")!="")
					laEditedFiles = laEditedFiles.concat(gaAttachList[i].aGetEditedFiles());
			}
		}
		if(laEditedFiles.join(";")!=""){
			var lsUploaded = sSelectArray("Multiple",sGetLang("UPLOAD_TITLEFILESELECT"),sGetLang("UPLOAD_PROMPTSAVEMODIFIED"),laEditedFiles.join(";"),false);
			if(typeof lsUploaded!="undefined"){
				var laModifiedFiles = lsUploaded.split(";");
				for(var j=0;j<gaAttachList.length;j++){
					if(gaAttachList[j].aGetEditedFiles()!=null){
						for(var i=0;i<laModifiedFiles.length;i++){
							if(gaAttachList[j].aGetEditedFiles().indexOf(laModifiedFiles[i])!=-1){
								gaAttachList[j].SetModifiedFile(laModifiedFiles[i]);
							}
						}
					}
					if(i==laModifiedFiles.length){
						if(gaAttachList[j].aModifiedFiles == null){
							gaAttachList[j].SetModifiedFile("");
						}
					}
				}
			}else{
				return false;
			}
		}
		return true;
	}
	
	this.OpenAttachment = function(psName){
		var loAttachList = this.CreateAttachList(psName);
		return loAttachList.OpenAttachment();
	}
	
	this.GetAttachCount = function(psName){
		var loAttachList = this.CreateAttachList(psName);
		return loAttachList.GetAttachCount();
	}
	
	function GetAttachList(psName){
		for(var i=0;i<gaAttachList.length;i++){
			if(gaAttachList[i].Name.toLowerCase() == psName.toLowerCase()){
				return gaAttachList[i];
			}
		}
		return null;
	}
	
	this.IsExistAttach = function(psFileName){
		for(var i=0;i<gaAttachList.length;i++){
			var loAttachList = gaAttachList[i];
			if(loAttachList.IsExistAttach(psFileName)) return true;
		}
		return false;
	}
	
	this.IsModified = function(){
		for(var i=0;i<gaAttachList.length;i++){
			var loAttachList = gaAttachList[i];
			if(loAttachList.IsModified()) return true;
		}
		return false;
	}
}

function AttachmentList(psName){
	this.Name = (psName.indexOf("|")==-1)?psName:psName.substr(0,psName.indexOf("|"));
	this.UploadControl = goForm.UploadControl;
	this.aAttachment = new Array();
	this.aAttachmentDel = new Array();
	this.type = 1;
	
	if(psName.indexOf("|")!=-1){
		laAttachTemp = psName.substr(psName.indexOf("|")+1).split("|");
		for(var j=0;j<laAttachTemp.length;j++){
			var loAttachment = new Object();
			loAttachment.FileName = laAttachTemp[j];
			loAttachment.IsLocal = false;
			this.aAttachment.push(loAttachment);
		}
	}
	
	this.AddAttachment = function(psFileName){
		if(psFileName==null || psFileName==""){
			var lsAddFiles = this.UploadControl.SelectFiles(true,"");
		}else{
			var lsAddFiles = psFileName;
		}
		if(lsAddFiles=="") return false;
		var laAdd = lsAddFiles.split("|");
		for(var i=0;i<laAdd.length;i++){
			if(bIsExistAttach(laAdd[i].substr(laAdd[i].lastIndexOf("\\")+1))){
				alert(sGetLang("UPLOAD_ATTACHEXIST",laAdd[i].substr(laAdd[i].lastIndexOf("\\")+1)));
				continue;
			}
			if(iGetStringByte(laAdd[i].substr(laAdd[i].lastIndexOf("\\")+1)) > 128){
				alert(sGetLang("P_CONST_FILENAMETOOLONG"));
				return false;
			}
			var loAttachment = new Object();
			loAttachment.FileName = laAdd[i];
			loAttachment.IsLocal = true;
			if(this.aAttachment == null) this.aAttachment = new Array(loAttachment);
			else this.aAttachment.push(loAttachment);
		}
		return true;
	}
	
	this.DelAttachment = function(psFileName){
		if(this.aAttachment!=null){
			var lsFileName = (psFileName==null)?"":psFileName;
			var lbFound = true;
			if(lsFileName==""){
				lbFound = false;
			}else{
				for(var j=0;j<this.aAttachment.length;j++)
					if(this.aAttachment[j].FileName.substr(this.aAttachment[j].FileName.indexOf("\\")+1).toLowerCase() == lsFileName.toLowerCase()) break;
				if(j==this.aAttachment.length) lbFound = false;
			}
			if(!lbFound){
				var lsFileSel = "";
				for(var i=0;i<this.aAttachment.length;i++){
					var lsFileName = (this.aAttachment[i].IsLocal)?this.aAttachment[i].FileName.substr(this.aAttachment[i].FileName.lastIndexOf("\\")+1):this.aAttachment[i].FileName;
					var lsIsLocal = (this.aAttachment[i].IsLocal)?"1":"0";
					if(lsFileSel!="") lsFileSel += ";";
					lsFileSel += lsFileName+"|"+this.aAttachment[i].FileName+"|"+lsIsLocal;
				}
				var lsFileReturn = sSelectArray("Multiple",sGetLang("UPLOAD_TITLEFILESELECT"),sGetLang("UPLOAD_PROMPTFILEDELETE"),lsFileSel);
				if(lsFileReturn!=null && lsFileReturn!=""){
					lsFileName = lsFileReturn;
				}else{
					lsFileName = "";
				}
			}
			if(lsFileName!=""){
				var laFileDel = lsFileName.split(";");
				for(var i=0;i<laFileDel.length;i++){
					var lsFileDel = (laFileDel[i].indexOf("|")!=-1)?laFileDel[i].substr(0,laFileDel[i].indexOf("|")):laFileDel[i];
					for(var j=0;j<this.aAttachment.length;j++){
						if(this.aAttachment[j].FileName.toLowerCase() == lsFileDel.toLowerCase()){
							if(!this.aAttachment[j].IsLocal){
								this.aAttachmentDel[this.aAttachmentDel.length] = lsFileDel;
							}
							this.aAttachment.splice(j,1);
						}
					}
				}
				if(this.aAttachment.length==0) this.aAttachment = null;
			}
		}else{
			alert(sGetLang("UPLOAD_NOATTACHMENT"));
		}
		return true;
	}
	
	this.EmptyAttachment = function(){
		if(this.aAttachment!=null){
			for(var j=0;j<this.aAttachment.length;j++){
				if(!this.aAttachment[j].IsLocal){
					this.aAttachmentDel[this.aAttachmentDel.length] = this.aAttachment[j].FileName;
				}
			}
			this.aAttachment = null;
		}
		return true;
	}
	
	this.GetAttachCount = function(){
		return (this.aAttachment==null)?0:this.aAttachment.length;
	}
	
	this.OpenAttachment = function(){
		if(this.aAttachment == null || this.aAttachment.length==0){
			alert(sGetLang("UPLOAD_NOATTACHMENT"));
			return false;
		}else{
			var laAttach = this.aAttachment;
			if(laAttach.length==1){
				if(laAttach[0].IsLocal) this.UploadControl.OpenLocalFile(laAttach[0].FileName);
				else this.UploadControl.OpenNetFile(this.UploadControl.urlpath+laAttach[0].FileName);
			}else{
				var lsFileSel = "";
				for(var i=0;i<laAttach.length;i++){
					var lsFileName = (laAttach[i].IsLocal)?laAttach[i].FileName.substr(laAttach[i].FileName.lastIndexOf("\\")+1):laAttach[i].FileName;
					var lsIsLocal = (laAttach[i].IsLocal)?"1":"0";
					if(lsFileSel!="") lsFileSel += ";";
					lsFileSel += lsFileName+"|"+laAttach[i].FileName+"|"+lsIsLocal;
				}
				var lsFileOpen = sSelectArray("Single",sGetLang("UPLOAD_TITLEFILESELECT"),sGetLang("UPLOAD_PROMPTFILEOPEN"),lsFileSel);
				if(lsFileOpen!=null){
					var lsFileName = lsFileOpen.substr(0,lsFileOpen.indexOf("|"));
					if(lsFileOpen.substr(lsFileOpen.indexOf("|")+1)=="1") this.UploadControl.OpenLocalFile(lsFileName);
					else this.UploadControl.OpenNetFile(this.UploadControl.urlpath+lsFileName);
				}
			}
		}
		return true;
	}
	
	this.UploadAttachment = function(){
		if(this.aAttachment==null) return "";
		var lsAddList = "";
		for(var i=0;i<this.aAttachment.length;i++){
			if(this.aAttachment[i].IsLocal){
				if(this.UploadControl.UploadFile2(this.aAttachment[i].FileName)){
					if(lsAddList!="") lsAddList += "|";
					lsAddList += "|"+this.aAttachment[i].FileName.substr(this.aAttachment[i].FileName.lastIndexOf("\\")+1);
				}
			}
		}
		return lsAddList;
	}
	
	this.GetAttachString = function(){
		if(this.aAttachment==null) return "";
		var lsAttachList = this.Name;
		for(var i=0;i<this.aAttachment.length;i++){
			if(this.aAttachment[i].IsLocal){
				lsAttachList += "|"+this.aAttachment[i].FileName.substr(this.aAttachment[i].FileName.lastIndexOf("\\")+1);
			}else{
				lsAttachList += "|"+this.aAttachment[i].FileName;
			}
		}
		return lsAttachList;
	}
	
	this.GetDelString = function(){
		return this.aAttachmentDel.join("|");
	}

	this.IsExistAttach = function(psFileName){
		if(this.aAttachment==null) return false;
		for(var i=0;i<this.aAttachment.length;i++){
			if(this.aAttachment[i].IsLocal){
				var lsFileName = this.aAttachment[i].FileName.substr(this.aAttachment[i].FileName.lastIndexOf("\\")+1);
			}else{
				var lsFileName = this.aAttachment[i].FileName;
			}
			if(lsFileName.toLowerCase() == psFileName.toLowerCase()) return true;
		}
		return false;
	}
	
	this.aGetEditedFiles = function(){
		return null;
	}
	
	this.SetModifiedFile = function(psFileName){
		return true;
	}
	
	this.IsModified = function(){
		if(null!=this.aAttachment){
			for(var i=0;i<this.aAttachment.length;i++){
				if(this.aAttachment[i].IsLocal) return true;
			}
		}
		if(null!=this.aAttachmentDel){
			if(this.aAttachmentDel.join(";")!="") return true;
		}
		return false;
	}
}
function AttachmentView(psName,psRights){
	this.UploadControl = null;
	this.type = 1;
	this.Name = psName;
	this.aAttachment = new Array();
	this.sSplit = "|";
	this.aRights = (psRights==null || psRights=="")?null:(psRights.split(this.sSplit));
	this.aEditedFiles = null;
	this.aModifiedFiles = null;
	
	this.parseXML = function(){
		if(this.Name.indexOf("|")!=-1){
			this.aAttachment = this.Name.substr(this.Name.indexOf("|")+1).split("|");
			this.Name = this.Name.substr(0,this.Name.indexOf("|"))
		}
		return true;
	}
	
	this.init = function(){
		if(!this.parseXML()) return false;
		//alert(this.Name);
		if(this.Name == null) return false;
		if(this.Name == ""){
			this.UploadControl = goForm.UploadControl;
			return true;
		}
		if(!goForm.UploadControl) return false;
		var loNode = document.createElement("<Span>");
		loNode.CLASSID = goForm.UploadControl.classid;
		loNode.CODEBASE = goForm.UploadControl.codebase;
		loNode.width = goForm.UploadControl.width;
		loNode.height = goForm.UploadControl.height;
		
		var laIndex = new Array();
		for(var i=0;i<goForm.UploadControl.childNodes.length;i++){
			var loNodeChild = document.createElement(goForm.UploadControl.childNodes[i].outerHTML);
			if(loNodeChild.name.toLowerCase() == "uploadedfile"){
				var lsUploadFiles = "";
				var laUploadFiles = window.ID_SpanAttachNames.innerText.split(this.sSplit);
				for(var j=0;j<laUploadFiles.length;j++){
					if(laUploadFiles[j]=="") continue;
					for(var k=0;k<this.aAttachment.length;k++){
						if(laUploadFiles[j].toLowerCase() == this.aAttachment[k].toLowerCase()){
							laIndex.push(j);
							lsUploadFiles += laUploadFiles[j] + "|";
						}
					}
				}
				loNodeChild.value = lsUploadFiles;
			}else if(loNodeChild.name.toLowerCase() == "datetime"){
				var laModified = window.ID_SpanAttachModified.innerText.split(this.sSplit);
				var lsModified = "";
				for(var j=0;j<laIndex.length;j++){
					lsModified += laModified[laIndex[j]] + "|";
				}
				loNodeChild.value = lsModified;
			}else if(loNodeChild.name.toLowerCase() == "filesize"){
				var laSize = window.ID_SpanAttachSize.innerText.split(this.sSplit);
				var lsSize = "";
				for(var j=0;j<laIndex.length;j++){
					lsSize += laSize[laIndex[j]] + "|";
				}
				loNodeChild.value = lsSize;
			}else if(loNodeChild.name.toLowerCase() == "addscript"){
				loNodeChild.value = "AttachRunFunc|"+this.Name+"|AddAttachment";
			}else if(loNodeChild.name.toLowerCase() == "pastescript"){
				loNodeChild.value = "AttachRunFunc|"+this.Name+"|PasteAttachment";
			}else if(loNodeChild.name.toLowerCase() == "enableoledit"){
				if(this.aRights!=null && gbIsEdit){
					if(this.aRights.indexOf(goAttachManager.RIGHT_EDIT)==-1){
						loNodeChild.value = "0";
					}else{
						loNodeChild.value = "1";
					}
				}else{
					loNodeChild.value = (gbIsEdit)?"1":"0";
				}
			}else if(loNodeChild.name.toLowerCase() == "enablesaveas"){
				if(this.aRights!=null){
					if(this.aRights.indexOf(goAttachManager.RIGHT_SAVE)==-1){
						loNodeChild.value = "0";
					}else{
						loNodeChild.value = "1";
					}
				}else{
					loNodeChild.value = "1";
				}
			}else if(loNodeChild.name.toLowerCase() == "enableadd" || loNodeChild.name.toLowerCase() == "enablepaste"){
				if(this.aRights!=null && gbIsEdit){
					if(this.aRights.indexOf(goAttachManager.RIGHT_ADD)==-1){
						loNodeChild.value = "0";
					}else{
						loNodeChild.value = "1";
					}
				}else{
					loNodeChild.value = (gbIsEdit)?"1":"0";
				}
			}else if(loNodeChild.name.toLowerCase() == "enabledelitem" || loNodeChild.name.toLowerCase() == "enabledelall"){
				if(this.aRights!=null && gbIsEdit){
					if(this.aRights.indexOf(goAttachManager.RIGHT_DEL)==-1){
						loNodeChild.value = "0"
					}else{
						loNodeChild.value = "1"
					}
				}else{
					loNodeChild.value = (gbIsEdit)?"1":"0";
				}
			}
			//alert(loNodeChild.Right);
			loNode.appendChild(loNodeChild);
		}	
		//alert(loNode.innerHTML);
		if(!window._UploadToolBar) return false;
		var loNodeToolBar = document.createElement("<Span>");
		loNodeToolBar.innerHTML = window._UploadToolBar.innerHTML;
		//alert(loNodeToolBar.innerHTML);
		var lsDisplay = "";
		if(this.aRights!=null){
			if(this.aRights.length==0) lsDisplay = "none";
			if(this.aRights.indexOf(goAttachManager.RIGHT_HIDE)!=-1) lsDisplay = "none";
		}
		var lsCtrlHTML = "<table id='Table_"+this.Name+"' border=1 height=100px cellpadding='0' cellspacing='1' style='width:100%;background-color:#555555;display:"+lsDisplay+"'>";
		lsCtrlHTML += "<tr><td width=100% height=20px>";
		lsCtrlHTML += loNodeToolBar.innerHTML;
		lsCtrlHTML += "</td></tr>";
		lsCtrlHTML += "<tr><td width=100% height=70px>";
		lsCtrlHTML += "<OBJECT name='obj_" + this.Name + "' CLASSID=" + loNode.CLASSID + " CODEBASE=" + loNode.CODEBASE + " width=100% height=100%>";	
		lsCtrlHTML += loNode.innerHTML;
		lsCtrlHTML += "</OBJECT>"
		lsCtrlHTML += "</td></tr>";
		lsCtrlHTML += "</table>";
		
		var loSpanList = document.getElementsByName("_SPANATTACH");
		for(var i=0;i<loSpanList.length;i++){
			if(loSpanList[i].name.toLowerCase()==this.Name.toLowerCase()){
				loSpanList[i].innerHTML = lsCtrlHTML;
				break;
			}
		}
		//document.write(lsCtrlHTML);
		var loCtrlTable = eval("window.Table_"+this.Name);
		var loToolBarTable = loCtrlTable.rows[0].cells[0].children[0];
		var lbCellDisplay = true;
		var lbCellButton = false;
		for(var i=0;i<loToolBarTable.rows[0].cells.length;i++){
			var loCell = loToolBarTable.rows[0].cells[i];
			if(loCell.type == "button"){
				loCell.onclick = new Function("AttachRunFunc('"+this.Name+"','"+loCell.onclickevent+"')");
			}else if(loCell.type == "menu"){
				loCell.attachEvent("onclick",new Function("showMenu('ID_"+this.Name+"_SHOWTYPE')"));
			}
			if(this.aRights!=null && loCell.Right!=null){
				if(this.aRights.indexOf(loCell.Right)==-1){
					loCell.style.display = "none";
				}else{
					loCell.style.display = "";
				}
			}else{
				loCell.style.display = "";
			}
		}
		
		var loTableToolBar = loCtrlTable.rows[0].cells[0].childNodes[0];
		for(var i=0;i<loTableToolBar.rows[0].cells.length;i++){
			if(loTableToolBar.rows[0].cells[i].id=="_UploadMenuBar"){
				var loMenuBar = loTableToolBar.rows[0].cells[i];
				for(var j=0;j<loMenuBar.children.length;j++){
					var loA = loMenuBar.children[j];
					loA.onclick = new Function("AttachRunFunc('"+this.Name+"','"+loA.onclickevent+"');return false;");
					loA.id = "ID_"+this.Name+"_SHOWTYPE";
				}
				break;
			}
		}
		var loMenuBar = eval("window.TR_"+this.Name);
		
		this.UploadControl = eval("goForm.obj_"+this.Name);
	}
	
	this.bValidFile = function(psFileName){
		if(goAttachManager.IsExistAttach(psFileName)){
			alert(sGetLang("UPLOAD_ATTACHEXIST",psFileName));
			return false;
		}
		if(iGetStringByte(psFileName) > 128){
			alert(sGetLang("P_CONST_FILENAMETOOLONG"));
			return false;
		}
		return true;
	}
	
	this.AddAttachment = function(){
		if(this.UploadControl == null) return false;
		var lsAddFiles = this.UploadControl.SelectFiles(true,"");
		if(lsAddFiles=="") return false;
		var laAdd = lsAddFiles.split("|");
		for(var i=0;i<laAdd.length;i++){
			if(!this.bValidFile(laAdd[i].substr(laAdd[i].lastIndexOf("\\")+1))) continue;
			this.UploadControl.AddLocalFile(laAdd[i]);
		}
	}
	
	this.OpenAttachment = function(){
		if(this.UploadControl == null) return false;
		this.UploadControl.OpenFile();
		return true;
	}
	
	this.EditAttachment = function(){
		if(this.UploadControl == null) return false;
		this.UploadControl.OnlineEdit();
		return true;
	}
	
	this.DelAttachment = function(){
		if(this.UploadControl == null) return false;
		this.UploadControl.DelItem();
		this.UploadControl.focus();
		return true;
	}
	
	this.SaveAttachment = function(){
		if(this.UploadControl == null) return false;
		this.UploadControl.SaveAs();
		this.UploadControl.focus();
		return true;
	}
	
	this.SaveAllAttachment = function(){
		if(this.UploadControl == null) return false;
		this.UploadControl.SaveAllAs();
		this.UploadControl.focus();
		return true;
	}
	
	this.PasteAttachment = function(){
		if(this.UploadControl == null) return false;
		var lsFileList = this.UploadControl.GetFileNameFromClip();
		if(lsFileList!=""){
			var laFileList = lsFileList.split(this.sSplit);
			for(var i=0;i<laFileList.length;i++){
				var lsFileName = laFileList[i].substr(laFileList[i].lastIndexOf("\\")+1);
				if(!this.bValidFile(lsFileName)) continue;
				this.UploadControl.AddLocalFile(laFileList[i]);
			}
		}
		this.UploadControl.focus();
		return true;
	}
	
	this.DelAllAttachment = function(){
		if(this.UploadControl == null) return false;
		this.UploadControl.DelAll();
		this.UploadControl.focus();
		return true;
	}
	
	this.ChangeView = function(piType){
		if(this.UploadControl == null) return false;
		this.UploadControl.ChangeView(piType);
		this.UploadControl.focus();
		return true;
	}
	
	this.RefreshView = function(){
		if(this.UploadControl == null) return false;
		this.UploadControl.RefreshView();
		this.UploadControl.focus();
		return true;
	}
	
	this.aGetModifiedFiles = function(){
		this.aModifiedFiles = new Array();
		this.aEditedFiles = new Array();
		if(this.UploadControl.GetModifiedFiles()!=""){
			this.aEditedFiles = this.UploadControl.GetModifiedFiles().split("|");
		}
		if(this.aEditedFiles.join(";")!=""){
			var lsUploaded = sSelectArray("Multiple",sGetLang("UPLOAD_TITLEFILESELECT"),sGetLang("UPLOAD_PROMPTSAVEMODIFIED"),this.aEditedFiles.join(";"),false);
			if(typeof lsUploaded!="undefined"){
				this.aModifiedFiles = lsUploaded.split(";");
			}
		}
		return this.aModifiedFiles;
	}

	//public function
	this.IsExistAttach = function(psFileName){
		for(var i=0;i<this.UploadControl.GetFileCount();i++){
			if(this.UploadControl.GetFileName(i)){
				if(this.UploadControl.GetFileName(i).toLowerCase() == psFileName.toLowerCase()) return true;
			}
		}
	}
	
	this.aGetEditedFiles = function(){
		return this.UploadControl.GetModifiedFiles().split(this.sSplit);
	}
	
	this.SetModifiedFile = function(psFileName){
		if(this.aModifiedFiles==null) this.aModifiedFiles = new Array();
		this.aModifiedFiles.push(psFileName);
	}
	
	this.UploadAttachment = function(){
		if(this.UploadControl==null) return "";
		var laFileToUpload = new Array();
		
		//1.1 file new
		for(var i=0;i<this.UploadControl.GetFileCount();i++){
			if(!this.UploadControl.IsUploadFile(i)){	
				laFileToUpload[laFileToUpload.length] = this.UploadControl.GetFileNameExt(i);
			}
		}
		//1.2 file modified
		var laModifiedFiles = (this.aModifiedFiles == null)?this.aGetModifiedFiles():this.aModifiedFiles;
		if(null!=laModifiedFiles){
			for(var i=0;i<laModifiedFiles.length;i++){
				if(laModifiedFiles[i]=="") continue;
				laFileToUpload[laFileToUpload.length] = this.UploadControl.GetTempDir() + laModifiedFiles[i];
			}
		}
		
		//1.2 file uploading....
		var lsAddList = "";
		for(var i=0;i<laFileToUpload.length;i++){
			lbValid = this.UploadControl.UploadFile(laFileToUpload[i]);
			if(!lbValid){
				if(!confirm(sGetLang("UPLOAD_FILEUPLOADFAIL",laFileToUpload[i].substr(laFileToUpload[i].lastIndexOf("\\")+1)))){
					return false;
				}
			}else{
				if(lsAddList!="") lsAddList += "|";
				lsAddList += "|" + laFileToUpload[i].substr(laFileToUpload[i].lastIndexOf("\\")+1)+"|";
			}
		}
		return lsAddList;
	}
	
	this.GetAttachString = function(){
		if(this.UploadControl==null) return "";
		if(this.Name == "") return "";
		var lsAttachList = this.Name;
		for(var i=0;i<this.UploadControl.GetFileCount();i++){
			if(!this.UploadControl.IsUploadFile(i)){
				lsAttachList += "|"+this.UploadControl.GetFileName(i).substr(this.UploadControl.GetFileName(i).lastIndexOf("\\")+1);
			}else{
				lsAttachList += "|"+this.UploadControl.GetFileName(i);
			}
		}
		return lsAttachList;
	}
	
	this.GetDelString = function(){
		if(this.UploadControl==null) return "";
		var lsDelList = this.UploadControl.GetDelList();
		var laModifiedFiles = (this.aModifiedFiles == null)?this.aGetModifiedFiles():this.aModifiedFiles;
		if(null!=laModifiedFiles){
			if(laModifiedFiles.join("|")!=""){
				if(lsDelList!="") lsDelList+="|";
				lsDelList += laModifiedFiles.join("|");
			}
		}
		return lsDelList;
	}
	
	this.IsModified = function(){
		if(this.UploadControl==null) return false;
		if(this.UploadControl.GetDelList()!="") return true;
		if(this.UploadControl.GetOnlineEdited()!="") return true;
		for(var i=0;i<this.UploadControl.GetFileCount();i++){
			if(!this.UploadControl.IsUploadFile(i))
				return true;
		}
		return false;
	}
	
	this.init();
}
function AttachRunFunc(psName,psFunc){
	var lsFunc = (psFunc.lastIndexOf(")")!=(psFunc.length-1))?psFunc+"()":psFunc;
	var lsFunction = "var loAttachList = goAttachManager.CreateAttachList('"+psName+"');loAttachList."+lsFunc+";"
	eval(lsFunction);
}
//-----------UploadControl end----------------------------------------------------------------

//-----------WordControl start----------------------------------------------------------------
function NewOfficeDocument(poOffice,psFileURL,pbPrompt){
	if(typeof(poOffice)!="object") return false;
	var lsFileURL=gsOAURL+gsDCDBName+"/viewWordTemplate/0/$file/$WTemplate.doc";
	var lbPrompt = (pbPrompt==null)?false:pbPrompt;	
	var lsRevisionCanAccept = s_AcceptRevision.innerText;
	if(psFileURL==null || psFileURL == ""){
		if((window.s_DWordTemplate && s_DWordTemplate.innerText.trim() != "NULL")&&(lbPrompt==false)){
				var lsURL=encodeURI(gsOAURL)+gsSRDBName+"/agtNewOffice?OpenAgent&ObjectID="+poOffice.id+"&Template=" + escape(s_DWordTemplate.innerText);
				top.RunAgent.location.replace(lsURL);
		}else{
			if(s_DWordTemplate.innerText!="NULL"){
				var lsURL=encodeURI(gsOAURL) + gsSRDBName + "/agtFileTemplate?OpenAgent&Category="+escape(s_DWordTemplate.innerText);
				var lvRet=PromptTree(true,"",lsURL,sGetLang("P_SELECTTEMPLATE"),false);
				if(lvRet==null || lvRet==""){
					return false;
				}
				var lsNO=lvRet.substring(0,lvRet.indexOf("|"));
				var lsName=lvRet.substring(lvRet.indexOf("|")+1);
				lsFileURL=gsOAURL+gsDCDBName+"/viewFileTemplateByID/"+lsNO+"/$file/"+lsName;
			}
			poOffice.SetIni(lsFileURL,"",1);
			top.LastModify = poOffice.getLastModify();
			poOffice.OpenFile(gsCurUser,"0","0",false,"1");
			if(lsRevisionCanAccept=="1"){
				BodySignRevisionCanAccept(poOffice);
			}	
			if(goForm.s_BodySaved)		//clear bodysaved flag
				goForm.s_BodySaved.value="";
			return true;
		}
	}else{
		lsFileURL = psFileURL;		
		poOffice.SetIni(lsFileURL,"",1);
		top.LastModify = poOffice.getLastModify();
		poOffice.OpenFile(gsCurUser,"0","0",false,"1");
		if(lsRevisionCanAccept=="1"){
				BodySignRevisionCanAccept(poOffice);
		}
		if(goForm.s_BodySaved)		//clear bodysaved flag
			goForm.s_BodySaved.value="";
		return true;
	}
}

function QuerySaveBody(poOffice,pbForce){
	if(typeof(poOffice)!="object" || goForm.s_ReadOnly.value=="1") return true;
	var lbForce = (pbForce == null)?false:pbForce;
	var lsAcceptRevisions = goForm.s_RevisionAccept.value;
	var liConfirm;
	if(poOffice.WordIsOpen()){
		if(!poOffice.IsSaved()){
			if(goForm.s_BodySaved.value=="1"){
				liConfirm = 4;
			}else{
				liConfirm = bConfirm(sGetLang("P_OFFICE_PROMPTQUERYSAVE"),MB_YES+MB_NO+MB_CANCEL+MB_ICONQUESTION,sGetLang("P_OFFICE_TITLE"));
			}
			if(liConfirm == 4){
				if(lsAcceptRevisions != "0"){
					BodyAcceptRevision(poOffice);
				}
				poOffice.SaveWord();
				poOffice.CloseWord(2);
				goForm.s_BodySaved.value="1";
				return true;
			}else if(liConfirm == 8){
				poOffice.CloseWord(3);
				return false;	
			}else{
				return -1;
			}
		}else{
			poOffice.CloseWord(2);
		}
	}
	if(typeof top.LastModify!="undefined" && poOffice.GetLocalFile()!="" && (top.LastModify=="" || poOffice.getLastModify()=="" || top.LastModify < poOffice.getLastModify())){
		if(goForm.s_BodySaved.value=="1"){
			liConfirm = 4;
		}else{
			if(!lbForce)	liConfirm = bConfirm(sGetLang("P_OFFICE_PROMPTQUERYSAVE"),MB_YES+MB_NO+MB_CANCEL+MB_ICONQUESTION,sGetLang("P_OFFICE_TITLE"));
			else liConfirm = 4;
		}
		if(liConfirm == 4){
			goForm.s_BodySaved.value="1";
			return true;
		}else if(liConfirm == 8){
			return false;
		}else{
			return -1;
		}
	}else{
		return false;
	}
}

function EditBody(poOffice){
	if(typeof(poOffice)!="object") return false;
	var lsFileURL;
	var lsFileName = "";
	var lsLocalPath = "";
	var lsRevision=goForm.s_Revision.value;
	var lsReadOnly=goForm.s_ReadOnly.value;
	var lsAcceptRevisions = goForm.s_RevisionAccept.value;
	var lsRevisionCanAccept = s_AcceptRevision.innerText;
	var lsRevisionEdit = (typeof(s_IsSubmit)!="object"||goForm.s_BodyName.value=="")?"0":(s_IsSubmit.innerText);
	if(poOffice.GetLocalFile().trim()==""){
		if(goForm.s_BodyName.value==""){
			NewOfficeDocument(poOffice);
		}else{
			lsFileName=goForm.s_BodyName.value;
			//var lsDBName = (gsCurDBName.toLowerCase()==gsCurUser.toLowerCase()+".nsf")?gsCurEncodeName+".nsf":gsCurDBName;
			lsFileURL= gsCurURL+gsCurDBName+"/all/"+gsCurUNID+"/$file/"+lsFileName;
			if (typeof ID_CopyURLPath=="object" && ID_CopyURLPath.innerText!="")
				lsFileURL= ID_CopyURLPath.innerText+lsFileName;
			if(!poOffice.SetIni(lsFileURL,lsFileName,1)){
				alert(sGetLang("P_OFFICE_PROMPTFILEEXIST"));
				return false;
			}
			if(!poOffice.WordIsOpen()){
				poOffice.OpenFile(gsCurUser,lsRevisionEdit,lsRevision,lsReadOnly,"1");
				if(lsAcceptRevisions != "0"){
					BodySignAccept(poOffice);
				}
				if(lsRevisionCanAccept=="1"){
					BodySignRevisionCanAccept(poOffice);
				}
			}else{
				poOffice.SetWordFocus();
			}
			top.LastModify = poOffice.getLastModify();
		}
	}else{
		if(!poOffice.WordIsOpen()){			
			poOffice.OpenFile(gsCurUser,lsRevisionEdit,lsRevision,lsReadOnly,"1");
			if(lsAcceptRevisions != "0"){
					BodySignAccept(poOffice);
			}
			if(lsRevisionCanAccept=="1"){
					BodySignRevisionCanAccept(poOffice);
			}	
		}else{
				poOffice.SetWordFocus();
		}
	}
	//bAutoCloseWPS(poOffice,true);
	top.IsOpenOffice = "1";//For PrintByTemplate Variable;
}

function SaveBody(poOffice,pbSaveBody){
	if(typeof(poOffice)!="object" || goForm.s_ReadOnly.value=="1") return true;
	if (bValidServerSession()==false) return false;
	var lbQuery = (pbSaveBody==null)?QuerySaveBody(poOffice):pbSaveBody;
	//var lsAcceptRevisions = goForm.s_RevisionAccept.value;
	//var lbQuery = QuerySaveBody(poOffice);
	if(lbQuery == -1){
		return false;
	}else if(lbQuery == true){
		if(poOffice.Upload("")!=""){
			goForm.s_BodySaved.value="1";
			var lsFilePath = poOffice.GetFileName("");
			if(goForm.s_BodyName){
				goForm.s_BodyName.value=lsFilePath;
				if (goForm.s_BodyName.value.trim()!="" && typeof window.hBodyDetachFile=="object"){
					var lsDetach="<input type='text' name='%%Detach' value='"+goForm.s_BodyName.value+"'>";
					hBodyDetachFile.innerHTML+=lsDetach;
				}
			}			
		}else{
			goForm.s_BodySaved.value="0";
			return false;
		}
	}
	return true;
}

function EditWordBody(poOffice){
	//goForm.s_Revision.value=(goForm.s_BodyCreator.value==""||goForm.s_BodyCreator.value==gsCurUser)?"0":"1";
	goForm.s_Revision.value="1";

	if(goForm.s_RevisionAccept.value=="" && goForm.s_BodyCreator.value!="" && goForm.s_BodyCreator.value!=gsCurUser){
		goForm.s_RevisionAccept.value="0";
	}
	if(goForm.s_RevisionAccept.value!="0"){
		goForm.s_Revision.value="0";
	}
	goForm.s_ReadOnly.value="0";
	EditBody(poOffice);
}

function ReadWordBody(poOffice){
	if(goForm.s_BodyName.value=="")return false;
	goForm.s_Revision.value="0";
	goForm.s_ReadOnly.value="1";
	EditBody(poOffice);
}

function BodyAcceptRevision(poOffice){
	BodyRunMacro(poOffice,"OAAcceptAllRevisions");
}

function BodySignAccept(poOffice){
	BodyRunMacro(poOffice,"OASignAccept");
}

function BodySignRevisionCanAccept(poOffice){
	BodyRunMacro(poOffice,"OASignRevisionCanAccept");
}

function BodyInvalidButton(poOffice,piInvalid){
	BodyRunMacro(poOffice,"OAInvalidButton",(piInvalid+""));
}

function BodyInvalidCommandBars(poOffice,piInvalid){
	BodyRunMacro(poOffice,"OAInvalidCommandBars",(piInvalid+""));
}

function BodyRunMacro(poOffice,psMacroName,psArg0,psArg1,psArg2,psArg3,psArg4,psArg5,psArg6,psArg7,psArg8,psArg9){
	var lsArg0 = (psArg0==null)?"":psArg0;
	var lsArg1 = (psArg1==null)?"":psArg1;
	var lsArg2 = (psArg2==null)?"":psArg2;
	var lsArg3 = (psArg3==null)?"":psArg3;
	var lsArg4 = (psArg4==null)?"":psArg4;
	var lsArg5 = (psArg5==null)?"":psArg5;
	var lsArg6 = (psArg6==null)?"":psArg6;
	var lsArg7 = (psArg7==null)?"":psArg7;
	var lsArg8 = (psArg8==null)?"":psArg8;
	var lsArg9 = (psArg9==null)?"":psArg9;
	poOffice.RunVBA(psMacroName,lsArg0,lsArg1,lsArg2,lsArg3,lsArg4,lsArg5,lsArg6,lsArg7,lsArg8,lsArg9);
}

function bWordBodyModified(poOffice){
	if (poOffice==null && goForm && goForm.MSOffice) poOffice = goForm.MSOffice;
	if(typeof(poOffice)!= "object") return false;
	if(poOffice.WordIsOpen()){
		if(!poOffice.IsSaved()){
			return true;
		}else{
			if(top.LastModify < poOffice.getLastModify()){
				return true;
			}else{
				return false;
			}
		}
	}else{
		poOffice.CloseWord(3);
		if(typeof top.LastModify!="undefined" && top.LastModify < poOffice.getLastModify()){
				return true;
		}
	}
	return false;
}

var goTimer;
function bAutoCloseWPS(poOffice,pbFirst){
	if(poOffice.GetClientType()!=1) return true;
	if (pbFirst==true){
		if (goTimer!=null) window.clearInterval(goTimer);
		goTimer=setInterval('bAutoCloseWPS(goForm.MSOffice)',300);
	}else{
		if (typeof poOffice!="object" && goTimer!=null) window.clearInterval(goTimer);
		if (typeof poOffice=="object"){
			if (!poOffice.WordIsOpen()){
				poOffice.CloseWord(2);
				if (goTimer!=null) window.clearInterval(goTimer);
			}
		}
	}
}
//-----------WordControl end----------------------------------------------------------------

//-----------WebSignature Start-------------------------------------------------------------
function bSaveSignature(){
	if(typeof gaSignCtrl == "object"){
		for(i=0;i<gaSignCtrl.length;i++){
			if (gaSignCtrl[i].Modify){
				gaSignCtrl[i].SaveSignature();
				goForm.s_WebSigned.value="1";
			}
		}
	}
	return true;
}

function bWebSignatureModified(){
	if(typeof gaSignCtrl == "object"){
		for(i=0;i<gaSignCtrl.length;i++){
			if (gaSignCtrl[i].Modify){
				return true;
			}
		}
	}
	return false;
}
//-----------WebSignature End---------------------------------------------------------------


function EditDocSN(psSNField,psSNName){
	var lsEditMode=gbIsEdit?"1":"0";
	var lsArg="";
	psSNName=psSNName==null?"":psSNName;
	lsArg=sSetParameter("DBName",escape(gsCurDBName),lsArg);
	lsArg=sSetParameter("UNID",gsCurUNID,lsArg);
	lsArg=sSetParameter("EditMode",lsEditMode,lsArg);
	lsArg=sSetParameter("SNField",psSNField,lsArg);
	lsArg=sSetParameter("SNName",escape(psSNName),lsArg);

	var lsURL=encodeURI(gsOAURL) + gsDCDBName + "/frmDocSN?OpenForm&" + lsArg;

	OpenWindow(lsURL,"",400,150,"no","no","no","no");
}

/*
SelectOpinion(psFieldName as string)
*/

function SelectOpinion(psFieldName){
	var lvArguments = SelectOpinion.arguments;
	if (lvArguments.length<1) return false;
	var lsTarget="&ReturnTarget="+lvArguments[0];
	var lsURL = encodeURI(gsOAURL) + gsDCDBName +"/frmSelectOpinion?Openform"+lsTarget;
	var lsRet=vOpenModal(lsURL,"",screen.width*3/5,screen.height*3/5,"");
	if(lsRet!=null)
		if(goForm.elements[psFieldName]) goForm.elements[psFieldName].value += lsRet;
}

function PromptDoing(psMessage) {
	if (typeof top.hPromptDoing!="object" && typeof top.hPromptDoingExt!="object") return false;
	var lsTop="100",lsLeft="0";
	if (typeof top.hPromptDoingExt=="object"){
		lsTop="200";
		lsLeft="100";
	}
	if (psMessage==null) psMessage = sGetLang("P_CONST_DOING");

	var lsHTML='<div id=hPromptDoingDiv style="position:absolute; top:'+lsTop+'; left:'+lsLeft+'; z-index:10; visibility:visible;width:100%;"><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 style="width:100%;background-color: transparent; "><TR><TD align=center style="background-color: transparent;"><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=0 style="width:300;height:60;background-color: #333333;"><TR><TD><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0  style="width:300;height:60;FONT-SIZE: 9pt;"><TR><TD width=100 align=center style="background-color:#eeeeee"><img src="'+gsImgURL+'ico_loading.gif"></TD><TD id=hPromptDoingText style="background-color:#eeeeee" nowrap>' + psMessage + '</td></tr></table></TD></TR></TABLE></td></tr></table></div>	\n' +
	'<div id="hCover" style="position:absolute; top:0; left:0; z-index:9; visibility:visible;"><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 style="width:100%;height:1000;background-color: transparent; "><TR><TD style="background-color: transparent; "></td></tr></table></div>		\n';
	if (typeof top.hPromptDoing=="object") top.hPromptDoing.innerHTML=lsHTML;
	if (typeof top.hPromptDoingExt=="object") top.hPromptDoingExt.innerHTML=lsHTML;
}

function HideDoing() {
	if (typeof top.hPromptDoing=="object") top.hPromptDoing.innerHTML="";
	if (typeof top.hPromptDoingExt=="object") top.hPromptDoingExt.innerHTML="";
}

function PromptViewLoading(psMessage) {
	if (typeof top.document=="unknown" || typeof top.hPromptDoingExt!="object") return false;
	var liHeight = top.ID_DIV_VIEWBODY.offsetHeight;
	var liWidth = top.ID_DIV_VIEWBODY.offsetWidth;
	var liLeft = iGetLeftPosition(top.ID_DIV_VIEWBODY);
	var liTop = iGetTopPosition(top.ID_DIV_VIEWBODY);
	if (psMessage==null) psMessage = sGetLang("P_CONST_URLOPENING");
	
	var lsHTML='<div id=hPromptDoingDiv style="position:absolute; top:230; left:100; z-index:10; visibility:visible;width:100%;"><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 style="width:100%;background-color: transparent; "><TR><TD align=center style="background-color: transparent;"><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=0 style="width:300;height:60;background-color: #333333;"><TR><TD><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0  style="width:300;height:60;FONT-SIZE: 9pt;"><TR><TD width=100 align=center style="background-color:#eeeeee"><img src="'+gsImgURL+'ico_loading.gif"></TD><TD id=hPromptDoingText style="background-color:#eeeeee" nowrap>' + psMessage + '</td></tr></table></td></tr></table></TD></TR></TABLE></div>	\n';
	if (top.SelectView == "1") lsHTML='<div id=hPromptDoingDiv style="position:absolute; top:130; left:5; z-index:10; visibility:visible;width:100%;"><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 style="width:100%;background-color: transparent; "><TR><TD align=center style="background-color: transparent;"><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0  style="width:265;height:60;FONT-SIZE: 9pt;background-color:#eeeeee"><TR><TD width=100 align=center><img src="'+gsImgURL+'ico_loading.gif"></TD><TD id=hPromptDoingText nowrap>' + psMessage + '</td></tr></table></td></tr></table></div>	\n';
	lsHTML += '<div id="hCover" style="position:absolute; top:'+liTop+'; left:'+liLeft+'; z-index:9; visibility:visible;"><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 style="width:'+liWidth+';height:'+liHeight+';background-color: transparent; "><TR><TD style="background-color: transparent; "></td></tr></table></div>		\n';
	if (typeof top.document!="unknown" && typeof top.hPromptDoingExt=="object") top.hPromptDoingExt.innerHTML=lsHTML;
}

function HideViewLoading() {
	if (typeof top.document!="unknown" && typeof top.hPromptDoingExt=="object") top.hPromptDoingExt.innerHTML="";
}

function bHideViewBar(pbShowMenu,pbShowViewTitle,pbShowButton){
	if (typeof top.document!="unknown"){
		var lodoc= top.document;
		HideViewLoading();
	}else{
		var lodoc= window.parent.document;
	}
	if (typeof lodoc.all.hMenuTable=="object" && pbShowMenu!=true)
		lodoc.all.hMenuTable.style.display = "none";
	if (typeof lodoc.all.hViewTitleTable=="object" && pbShowViewTitle!=true)
		lodoc.all.hViewTitleTable.style.display = "none";
	if (typeof lodoc.all.hButtonTable=="object" && pbShowButton!=true)
		lodoc.all.hButtonTable.style.display = "none";
	if (typeof lodoc.all.hFTSTable=="object" && pbShowButton!=true)
		lodoc.all.hFTSTable.style.display = "none";

}


function bSetNavClick(psURL){
	var loframe=top.NavIFrame;
	for(var i=1;i<10000;i++){
		var loHref=eval("loframe."+loframe.gsHrefPrefix+i);
		var lsTemp="";
		if(typeof loHref=="object"){
			lsTemp=loHref.outerHTML.substring(loHref.outerHTML.indexOf("href=\"")+6,loHref.outerHTML.length);
			lsTemp=sHTMLDecode(lsTemp.substring(0,lsTemp.indexOf('"')));
			if(lsTemp.toLowerCase().indexOf(psURL.toLowerCase())!=-1){
				loframe.ClickOnHref(loHref);
				break;
			}
		}
	}
}

//bIsDigital(this.value)
function bIsDigital(){
	if(bIsDigital.arguments.length < 1) return false;
	var lsValue = bIsDigital.arguments[0];
	var liType = (bIsDigital.arguments.length > 1)?bIsDigital.arguments[1]:3;
	var lsPrompt = (bIsDigital.arguments.length > 2)?bIsDigital.arguments[2]:sGetLang("P_NOTDIGITAL");
	if (lsValue+""==""){
		if(lsPrompt != "")
			alert(lsPrompt);
		return false;	
	}
	var regDecimal = /^([+-]?[0-9]+\.?[0-9]+)$/;
	var regInteger = /^[+-]?\d{1,9}$/;
	var regDecimalExt = /^([+]?[0-9]+\.?[0-9]+)$/;
	var regIntegerExt = /^[+]?\d{1,9}$/;

	var rInteger = lsValue.match(regInteger);
	var rDecimal = lsValue.match(regDecimal);
	var rIntegerExt = lsValue.match(regIntegerExt);
	var rDecimalExt = lsValue.match(regDecimalExt);
	if(liType == 1 && rInteger==null || liType == 2 && rDecimal==null || liType == 3 && rInteger==null && rDecimal==null || liType == 4 && rIntegerExt==null || liType == 5 && rDecimalExt==null || liType == 6 && rIntegerExt==null && rDecimalExt==null){
		if(lsPrompt != "")
			alert(lsPrompt);
		return false;
	}else{
		return true;
	}
}

function vPromptField(){
	var lvArguments=vPromptField.arguments;
	var lsLimit = (lvArguments.length>=1)?("&Limit="+escape(lvArguments[0])):"";
	var lbMultiChoice=(lvArguments.length>=2 && lvArguments[1]==true)? true : false;	
	var lsInitValue = (lvArguments.length>=3)?lvArguments[2]:"";
	var lsWinTitle = (lvArguments.length>=4 && lvArguments[3]!="")?lvArguments[3]:sGetLang("FIELD_PROMPTFIELDS");
	var lsURL=encodeURI(gsOAURL)+sGetLang("DB_NAME_FIELD")+"/agtFieldTree?OpenAgent"+lsLimit;
	var rsTemp=PromptTree(true,"",lsURL,lsWinTitle,lbMultiChoice);
	if (rsTemp==null) return null;
	var lsReturn,lsTemp;
	var laTemp=rsTemp.split(";");
	var raValue = new Array();
	raValue['FieldSelCNName'] = "";
	raValue['FieldSelName'] = "";
	raValue['FieldCNName']="";
	raValue['FieldName']="";
	raValue['FieldType']="";
	if (rsTemp.trim()=="") return raValue;
	for (var i=0; i<laTemp.length; i++){
		lsReturn = laTemp[i];
		lsTemp = lsReturn.substr(0,lsReturn.indexOf("|"));		
		if (raValue['FieldSelCNName']==""){
			raValue['FieldSelCNName'] = lsTemp;
			raValue['FieldCNName'] = lsTemp.substr(lsTemp.lastIndexOf("/")+1);
		}else{
			raValue['FieldSelCNName'] += ";" + lsTemp;
			raValue['FieldCNName'] += ";" + lsTemp.substr(lsTemp.lastIndexOf("/")+1);
		}
		lsReturn = lsReturn.substr(lsReturn.indexOf("|")+1);
		lsTemp = lsReturn.substr(0,lsReturn.indexOf("|"));
		if (raValue['FieldSelName']==""){
			raValue['FieldSelName'] = lsTemp;
			raValue['FieldName'] = lsTemp.substr(lsTemp.lastIndexOf("/")+1);
		}else{
			raValue['FieldSelName'] += ";" + lsTemp;
			raValue['FieldName'] += ";" + lsTemp.substr(lsTemp.lastIndexOf("/")+1);		
		}
		
		if(raValue['FieldType']=="")
			raValue['FieldType'] = lsReturn.substr(lsReturn.indexOf("|") + 1);
		else
			raValue['FieldType'] += ";"+lsReturn.substr(lsReturn.indexOf("|") + 1);
	}
	return raValue;
}

function bDateTimeValid(){
	if(bDateTimeValid.arguments.length < 1) return false;
	var lsDateTime = bDateTimeValid.arguments[0];
	var liType = (bDateTimeValid.arguments.length > 1)?bDateTimeValid.arguments[1]:1;
	
    var regDate = /^(\d{1,4})[-/](\d{1,2})[-/](\d{1,2})$/;; 
    var regTime = /^(\d{1,2}):(\d{1,2})$/;
    var regDateTime = /^(\d{1,4})[-/](\d{1,2})[-/](\d{1,2}) (\d{1,2}):(\d{1,2})$/; 
    //var regDate = /^(\d{1,2})(-|/)(\d{1,2})(-|/)(\d{1,2})$/; 
    //var regTime = /^(\d{1,2}):(\d{1,2})$/;
    //var reg2 = /^(\d{1,4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
    var d;
    if(liType == 1){
    	var r = lsDateTime.match(regDate);
    	if(r == null) return false;
    	else{
    		d= new Date(r[1], --r[2],r[3]); 
        	if(d.getFullYear()!=r[1] || d.getMonth()!=r[2] || d.getDate()!=r[3])
        		return false;
    	}
    }else if(liType == 2){    	
    	var r = lsDateTime.match(regTime);
    	if(r==null) return false;
    	if(r[1] > 23 || r[1] < 0 || r[2] > 59 || r[2] < 0) return false;
    }else if(liType == 3){
    	var r = lsDateTime.match(regDateTime);
    	if(r==null) return false;
 		else{
       		d= new Date(r[1], --r[2],r[3],r[4],r[5]); 
       		if(d.getFullYear()!=r[1] || d.getMonth()!=r[2] || d.getDate()!=r[3] || d.getHours()!=r[4] || d.getMinutes()!=r[5])
           		return false;
       	}
    }
    return true;
}

function vSelectCombox(psObjectName){
	var raValue = new Array();
	raValue['SelID']="";
	raValue['SelValue']="";
	for (var i = 0; i < goForm.elements[psObjectName].options.length; i++){
		if(goForm.elements[psObjectName].options[i].selected){
			raValue['SelID'] = goForm.elements[psObjectName].options[i].text;
			raValue['SelValue'] = goForm.elements[psObjectName].options[i].value;
		}
	}
	return raValue;
}

function vSelectCheckBox(psObjectName){	
	var raValue = new Array();
	j = 0;
	for (var i = 0; i < goForm.elements.length; i++){
		if (goForm.elements[i].type != "checkbox" && goForm.elements[i].type != "radio") continue;
		if (goForm.elements[i].name != psObjectName) continue;
		if (goForm.elements[i].checked != true) continue;		
		raValue[j++] = goForm.elements[i].value;	
	}
	return raValue;
}

function CList(){
	var lvArguments=CList.arguments
	if(lvArguments.length < 3) return false;
	//Property
	this.oShowList = goForm.elements[lvArguments[0]];
	this.oTextObject = goForm.elements[lvArguments[1]];
	this.oValueObject = goForm.elements[lvArguments[2]];
	this.bOneness = (lvArguments.length > 3)?lvArguments[3]:false;

	this.iPosition = -1;
	this.sCurValue = "";
	this.sCurText = "";
	if(typeof this.sLink == "undefined") this.sLink=";";
	
	//overload(must be)
	//this.aBuildValue = aBuildValue;	
	//this.bValidate = bValidate;
	//this.bListOnChange = bListOnChange;
	
	//private method
	this.bInsertValue = bInsertValue;
	this.bGetCurPos = bGetCurPos;
	this.bInitList = bInitList;
	this.bOneValidate = bOneValidate;
	this.bSetSelect = bSetSelect;
	
	//public method(interface)
	this.bAddField = bAddField;
	this.bInsertField = bInsertField;	
	this.bDelField = bDelField;
	this.bModifyField = bModifyField;
	this.bClearList = bClearList;
	
	this.bInitList();

	//Oneness check
	function bOneValidate(){
		var laValue = this.aBuildValue();
		if(laValue == null) return false;
		var laExist = this.oValueObject.value.split(";");
		for(i=0;i<laExist.length;i++){
			if(laExist[i] == laValue['value']){
				alert(sGetLang("P_ITEMISEXIST"));
				return false;
			}
		}
		return true;
	}

	function bSetSelect(piIndex){
		for (var i=0;i<this.oShowList.options.length;i++){
			if (i==piIndex)
				this.oShowList.options[i].selected = true;
			else
				this.oShowList.options[i].selected = false;
		}
		return true;
	}
	
	//init
	function bInitList(){
		this.bClearList();
		if(this.oTextObject.value == "" || this.oValueObject.value == "") return false;
		var laValue = new Array();
		var laText = new Array();
		laValue = this.oValueObject.value.split(this.sLink);
		laText = this.oTextObject.value.split(this.sLink);
		for(i = 0 ; i < laValue.length; i++){
			this.oShowList.options[i] = new Option("","");
			this.oShowList.options[i].text = laText[i];
			this.oShowList.options[i].value = laValue[i];
		}
	}
	
	//clear
	function bClearList(){
		if(gbIsEdit && (typeof this.oShowList == "object")){
			for(i = 0;i<this.oShowList.options.length;i++){
				if(this.oShowList.options[i].text == "" && this.oShowList.options[i].value == ""){
					this.oShowList.options[i] = null;
				}
			}
			return true;
		}else return false;
	}
	
	//add
	function bAddField(){
		if(this.bOneness && !this.bOneValidate()) return false;
		var laValue = this.aBuildValue();
		if(laValue == null) return false;
		this.iPosition = this.oShowList.options.length;
		this.bInsertValue(laValue['value'],laValue['text']);
		this.bSetSelect(this.oShowList.options.length-1);
		return true;
	}
	
	//Insert
	function bInsertField(){
		if(!this.bGetCurPos()) return false;
		if(this.bOneness && !this.bOneValidate()) return false;
		var laValue = this.aBuildValue();
		if(laValue == null) return false;
		this.bInsertValue(laValue['value'],laValue['text']);
		return true;
	}

	//delete
	function bDelField(){
		if(!this.bGetCurPos()) return false;
		var laValue = this.oValueObject.value.split(this.sLink);
		var laText = this.oTextObject.value.split(this.sLink);
		laValue.splice(this.iPosition,1);
		laText.splice(this.iPosition,1);
		this.oValueObject.value = laValue.join(this.sLink);
		this.oTextObject.value = laText.join(this.sLink);
		this.oShowList.options[this.iPosition] = null;
		if(this.oShowList.options.length != 0){
			if(this.iPosition < this.oShowList.options.length){
				this.bSetSelect(this.iPosition);
			}else{
				this.bSetSelect(this.oShowList.options.length-1);
			}
		}
		return true;
	}
	
	//modify
	function bModifyField(){
		if(!this.bGetCurPos()) return false;
		if(this.bOneness && !this.bOneValidate()) return false;
		var laValue = this.aBuildValue();
		if(laValue == null) return false;
		var liPos = this.iPosition;
		this.bDelField();
		this.iPosition = liPos;
		this.bInsertValue(laValue['value'],laValue['text']);
		this.bSetSelect(liPos);
		return true;
	}
	
	//insert
	function bInsertValue(psValue,psText){
		if(this.oValueObject.value == ""){
			this.oValueObject.value = psValue;
			this.oTextObject.value = psText;
		}else{			
			var laValue = this.oValueObject.value.split(this.sLink);
			var laText = this.oTextObject.value.split(this.sLink);		
			laValue.insert(this.iPosition,psValue);
			laText.insert(this.iPosition,psText);
			this.oValueObject.value = laValue.join(this.sLink);
			this.oTextObject.value = laText.join(this.sLink);
		}
		var liLength = this.oShowList.options.length;
		this.oShowList.options[liLength] = new Option("","");
		for(i = liLength;i > this.iPosition; i--){
			this.oShowList.options[i].text = this.oShowList.options[i-1].text;
			this.oShowList.options[i].value = this.oShowList.options[i-1].value;
		}
		this.oShowList.options[i].text = psText;
		this.oShowList.options[i].value = psValue;
		return true;
	}
	
	//get position
	function bGetCurPos(){		
		this.iPosition = this.oShowList.options.selectedIndex;
		if(this.iPosition == -1){
			alert(sGetLang("P_NORECORDSEL"));
			return false;
		}
		this.sCurValue = this.oShowList.options[this.oShowList.options.selectedIndex].value;
		this.sCurText = this.oShowList.options[this.oShowList.options.selectedIndex].text;
		return true;
	}	
}


function aSelQuery(){
	var lsType = "&QueryType=" + escape((aSelQuery.arguments.length > 0)?aSelQuery.arguments[0]:"3");
	var lsCategory = "&Category=" + escape((aSelQuery.arguments.length > 1)?aSelQuery.arguments[1]:"");
	var lsURL = encodeURI(gsCurURL)+sGetLang("DB_NAME_SCHSTAT")+"/agtQueryTree?OpenAgent" + lsType + lsCategory;
	var lsDefault = "";
	var lsReturn = PromptTree(true,lsDefault,lsURL,sGetLang("SCHSTAT_PROMPTQUERY"),0,0,"");
	var laReturn = new Array();
	if(lsReturn!=null&&lsReturn != ""){
		var lsQuery = lsReturn.substring(0,lsReturn.indexOf("|"));
		lsReturn = lsReturn.substring(lsReturn.indexOf("|") + 1);
		var lsRuntime = lsReturn.substring(0,lsReturn.indexOf("|"));
		var lsUNID = lsReturn.substring(lsReturn.indexOf("|") + 1);
		laReturn['Query'] = lsQuery;
		laReturn['Runtime'] = lsRuntime;
		laReturn['UNID'] = lsUNID;
		return laReturn;
	}else return null;
}

function aGetFormula(){
	var lsURL = encodeURI(gsCurURL)+sGetLang("DB_NAME_FIELD")+"/agtFormulaTree?OpenAgent";
	var lsDefault = "";
	var lsReturn = PromptTree(true,lsDefault,lsURL,sGetLang("FIELD_PROMPTFORMULA"),0,0,"");	
	var laReturn = new Array();
	if(lsReturn!=null&&lsReturn != ""){
		var lsName = lsReturn.substring(0,lsReturn.indexOf("|"));
		lsReturn = lsReturn.substring(lsReturn.indexOf("|") + 1);
		var lsFormula = lsReturn.substring(0,lsReturn.indexOf("|"));
		var lsParaType = lsReturn.substring(lsReturn.indexOf("|") + 1);
		laReturn['Name'] = lsName;
		laReturn['Formula'] = lsFormula;
		laReturn['ParaType'] = lsParaType;
		return laReturn;
	}else return null;
}

function aGetStat(){
	var lsCategory = "&Category=" + escape((aGetStat.arguments.length > 0)?aGetStat.arguments[0]:"");
	var lsShowAll = "&ShowAll=" + ((aGetStat.arguments.length > 1)&&aGetStat.arguments[1]==true?"1":"0");
	var lsURL = encodeURI(gsCurURL)+sGetLang("DB_NAME_SCHSTAT")+"/agtStatTree?OpenAgent" + lsCategory + lsShowAll;
	var lsDefault = "";
	var lsReturn = PromptTree(true,lsDefault,lsURL,sGetLang("SCHSTAT_PROMPTSTAT"),0,0,"");
	var laReturn = new Array();
	if(lsReturn!=null&&lsReturn != ""){
		var lsName = lsReturn.substring(0,lsReturn.indexOf("|"));
		lsReturn = lsReturn.substring(lsReturn.indexOf("|") + 1);
		var lsRuntime = lsReturn.substring(0,lsReturn.indexOf("|"));
		var lsUNID = lsReturn.substring(lsReturn.indexOf("|") + 1);
		laReturn['Name'] = lsName;
		laReturn['Runtime'] = lsRuntime;
		laReturn['UNID'] = lsUNID;
		return laReturn;
	}else return null;
}



Array.prototype.insert=function(piPos,psValue){
	for(i=this.length;i>piPos;i--){		
		this[i] = this[i-1];	
	}
	this[piPos] = psValue;
}

function bRunStat(){
	var lsVal;
	var psStatName = (bRunStat.arguments.length > 0)?bRunStat.arguments[0]:"";
	var psCategory = (bRunStat.arguments.length > 1)?bRunStat.arguments[1]:"";
	var psKeyWords = (bRunStat.arguments.length > 2)?bRunStat.arguments[2]:"";
	var lsKeyWords = "";
	var lsUNID = "";
	if (typeof top.document!="unknown"){
		var loframe= top.ViewIFrame;
	}else{
		var loframe= window.MailIframe;
	}
	if(typeof loframe.RunAgent != "object"){
		loframe = top;
		if(typeof loframe.RunAgent != "object") return false;
	}
	if(psStatName==""){
		var laValue = aGetStat(psCategory);
		if(laValue!=null&&laValue['Name'] != ""){
			lsStatName = laValue['Name'];
			lsRuntime = laValue['Runtime'];
			lsUNID = laValue['UNID'];
			if(lsRuntime == "1"){
				if(psKeyWords == ""){
					var lsTempURL = gsCurURL+sGetLang("DB_NAME_SCHSTAT")+"/agtQueryParameter?OpenAgent&RunFunc=2&QueryUNID=" + lsUNID + "&StatName=" + escape(lsStatName);
					loframe.RunAgent.location.replace(lsTempURL);
					return true;
				}else{
					lsKeyWords = psKeyWords;
				}
			}
		}else{
			return false;
		}
	}else{
		lsStatName = (psCategory == "")?psStatName:(psCategory+"/"+psStatName);
		if(psKeyWords!=""){
			lsKeyWords = psKeyWords;
		}else{
				var lsTempURL = gsCurURL+sGetLang("DB_NAME_SCHSTAT")+"/agtQueryParameter?OpenAgent&RunFunc=2&QueryUNID=" + lsUNID + "&StatName=" + escape(lsStatName);
				loframe.RunAgent.location.replace(lsTempURL);
				return true;
		}
	}
	
	var lsKeyURL = (lsKeyWords=="")?"":"&KeyWords="+escape(lsKeyWords);
	var lsURL=encodeURI(gsOAURL)+sGetLang("DB_NAME_SCHSTAT")+"/agtInterfaceStat?Openagent&StatName="+escape(lsStatName)+lsKeyURL;
	if(loframe.RunAgent){
		loframe.PromptViewLoading(sGetLang("P_CONST_STATING"));
		loframe.RunAgent.location.replace(lsURL);
	}else if(top.RunAgent){
		top.RunAgent.location.replace(lsURL);
		loframe.PromptViewLoading(sGetLang("P_CONST_STATING"));
	}
}

function bRunQuery(){
	var lsVal,lsReset;
	var lsQuery;
	var psQueryName = (bRunQuery.arguments.length > 0)?bRunQuery.arguments[0]:"";
	var psType = (bRunQuery.arguments.length > 1)?bRunQuery.arguments[1]:"5";
	var psCategory = (bRunQuery.arguments.length > 2)?bRunQuery.arguments[2]:"";
	var psKeyWords = (bRunQuery.arguments.length > 3)?bRunQuery.arguments[3]:"";
	var psReset = (bRunQuery.arguments.length > 4)?bRunQuery.arguments[4]:"";
	if (typeof top.document!="unknown"){
		var loframe= top.ViewIFrame;
	}else{
		var loframe= window.MailIframe;
	}
	if(typeof loframe.RunAgent != "object"){
		loframe = top;
		if(typeof loframe.RunAgent != "object") return false;
	}
	if(psReset == ""){
		if(typeof(window.parent.document.all.SelectAll) == 'object' && window.parent.document.all.SelectAll.style.display != 'none'){
			if(confirm(sGetLang("SCHSTAT_ISRESETRESULT"))){
				lsReset = "1";
			}else{
				lsReset = "0";
			}
		}
	}else{
		lsReset = psReset;
	}
	if(psQueryName == ""){
		var laValue = aSelQuery(psType,psCategory);
		if(laValue!=null&&laValue['Query'] != ""){
			lsQuery = laValue['Query'];
			lsRuntime = laValue['Runtime'];
			lsUNID = laValue['UNID'];
			if(lsRuntime == "1"){
				if(psKeyWords == ""){
					var lsTempURL = gsCurURL+sGetLang("DB_NAME_SCHSTAT")+"/agtQueryParameter?OpenAgent&RunFunc=1&bReset="+lsReset+"&QueryUNID=" + lsUNID;
					loframe.RunAgent.location.replace(lsTempURL);
					return true;
				}else{
					lsVal = sSetParameter("KeyWords",psKeyWords,lsVal);
				}
			}
			lsVal = sSetParameter("bReset",lsReset,lsVal);
			lsVal = sSetParameter("QueryName",lsQuery,lsVal);
			lsVal = sSetParameter("QueryUNID",lsUNID,lsVal);
		}
	}else{
		lsQuery = (psCategory == "" || psCategory == null)?psQueryName:psCategory+"/"+psQueryName;
		lsVal = sSetParameter("bReset",lsReset,lsVal);
		lsVal = sSetParameter("QueryName",lsQuery,lsVal);
		if(psKeyWords != ""){
			lsVal = sSetParameter("KeyWords",psKeyWords,lsVal);
		}else{
			var lsTempURL = gsCurURL+sGetLang("DB_NAME_SCHSTAT")+"/agtQueryParameter?OpenAgent&RunFunc=1&bReset="+lsReset+"&QueryName=" + escape(lsQuery);
			loframe.RunAgent.location.replace(lsTempURL);
			return true;
		}
	}
	if(lsQuery!=null&&lsQuery != ""){	
		if(loframe.RunAgent){
			lsURL = encodeURI(gsCurURL) + sGetLang("DB_NAME_SCHSTAT") + "/frmAutoClose?Openform";
			loframe.Action = "Search";
			loframe.argDBName = gsCurDBName;
			loframe.argVal = lsVal;
			loframe.RunAgent.location.replace(lsURL);
			loframe.PromptViewLoading(sGetLang("P_CONST_SEARCH"));
		}else if(top.RunAgent){
			lsURL = encodeURI(gsCurURL) + sGetLang("DB_NAME_SCHSTAT") + "/frmAutoClose?Openform";
			top.Action = "Search";
			top.argDBName = gsCurDBName;
			top.argVal = lsVal;
			top.RunAgent.location.replace(lsURL);
			loframe.PromptViewLoading(sGetLang("P_CONST_SEARCH"));
		}
	}
}

function vGetQueryParameter(poObject){
	var laValue,lsRet="";
	if(poObject==null) return "";
	var liWidth=500;
	if(poObject.iReturnType == 1){
		var liHeight=315;
	}else{
		var liHeight=295;
	}
	var loObject = vOpenModal('/icons/icons/getParameter.htm',poObject,liWidth,liHeight);
	if(loObject == null){
		if(poObject.iReturnType == 1) return "";
		else return null;
	}
	if(poObject.iReturnType == 1){//Query or Stat Parameter
		return loObject.sKeyWords;
	}else{//Extension FTSearch
		return loObject;
	}
}


function bViewReport(psParameter){
	if(typeof top.ViewIFrame !="object") return false;
	if (typeof top.document!="unknown"){
		var loframe= top.ViewIFrame;
	}else{
		var loframe= window.MailIframe;
	}
	var lsIDs = sGetSelected("");
	if(lsIDs==""){
		if(window.confirm(sGetLang("P_VIEWREPORT_DOCNOTFOUND"))==false) return false;	
		loframe.docIDs = "";				
	}else{
		if(window.confirm(sGetLang("P_VIEWREPORT_CONTINUE"))==false) return false;
		loframe.docIDs = lsIDs;
	}
	var lsTemplate = "";
	if (typeof (loframe.document.all.hReportTemplate)=="object")
		lsTemplate = loframe.document.all.hReportTemplate.innerText;
	var lsParameter = (psParameter!=null && psParameter!="")?("&Parameter="+escape(psParameter)):"";
	var lsURL=encodeURI(gsOAURL)+sGetLang("DB_NAME_SCHSTAT")+"/agtViewReport?Openagent&Template="+escape(lsTemplate)+lsParameter;
	loframe.RunAgent.location.replace(lsURL);
}

function bReportByTemplate(psParameter){
	if(typeof top.ContentBody != "object") return false;
	var lsTemplate = "";
	if (typeof (window.document.all.hReportTemplate)=="object")
		lsTemplate = window.document.all.hReportTemplate.innerText;
	var lsParameter = (psParameter!=null && psParameter!="")?("&Parameter="+psParameter):"";
	var lsURL=encodeURI(gsOAURL)+sGetLang("DB_NAME_SCHSTAT")+"/agtViewReport?Openagent&Template="+lsTemplate+lsParameter;
	top.gsCurDBName = gsCurDBName;
	top.docIDs = gsCurUNID;
	top.RunAgent.location.replace(lsURL);
}

function bCheckObject(psObjectName,psValue,pbChecked){	
	for (var i = 0; i < goForm.elements.length; i++){		
		if (goForm.elements[i].name != psObjectName) continue;
		switch(goForm.elements[i].type){
			case "checkbox":				
			case "radio":
				if (goForm.elements[i].value != psValue) continue;
				goForm.elements[i].checked = pbChecked;break;
			case "select-one":
			case "select-multiple":
				for(j = 0;j<goForm.elements[i].options.length;j++){
					if(goForm.elements[i].options[j].value == psValue || goForm.elements[i].options[j].text == psValue){
						goForm.elements[i].options[j].selected = pbChecked;
					}
				};break;
			default:break;
		}
	}
}

function SelectUsers(pbModal,psTarget,psStyle,psTitle,pvExistTask,pbShowUnit,pvExistDirection){
//psStyle£º[Field]/[Task]/[Flow]/[Direction]
	var lvArguments=SelectUsers.arguments;	
	if (lvArguments.length<2) return false;
	var laArg = new Array();
	var lsTarget="&ReturnTarget="+psTarget;
	if(goForm.elements[psTarget] && (goForm.elements[psTarget].id==psTarget || goForm.elements[psTarget].name==goForm.elements[psTarget])){
		laArg["InitValue"] = goForm.elements[psTarget].value;
	}else{
		laArg["InitValue"] = psTarget;
	}
	var lsStyle="&Style="+((psStyle!=null && psStyle!="")?psStyle:"");
	laArg["Style"] = psStyle;
	
	var lsWinTitle=(psTitle!=null && psTitle!="")?("&WindowTitle="+escape(psTitle)):"";
	var lsParentFlow=""
	var laExistTask = null;
	var laExistDirection = null;
	if (pvExistTask!=null){
		if (typeof pvExistTask=="string"){
			lsParentFlow="&ParentFlow=" + escape(pvExistTask);
		}else{
			laExistTask = pvExistTask;
		}
	}
	if (pvExistDirection!=null){
		if (typeof pvExistDirection=="string"){
			lsParentFlow="&ParentFlow=" + escape(pvExistDirection);
		}else{
			laExistDirection = pvExistDirection;
		}
	}

	laArg["ExistTasks"] = laExistTask;
	window.ExistTasks = laExistTask;
	laArg["ExistDirections"] = laExistDirection;
	window.ExistDirections = laExistDirection;
	
	var lbShowUnit = (pbShowUnit!=null)?pbShowUnit:true;
	if(lbShowUnit){
		lsStyle += "[UNIT]";
		laArg["Style"] += "[UNIT]";
	}

	var liWidth=420,liHeight=100;
	if(lbShowUnit) liHeight += 50;
	if(laArg["Style"].toUpperCase().indexOf("[FIELD]") != -1) liHeight += 40;
	if(laArg["Style"].toUpperCase().indexOf("[FLOW]") != -1) liHeight += 110;
	if(laArg["Style"].toUpperCase().indexOf("[TASK]") != -1) liHeight += 90;
	if(laArg["Style"].toUpperCase().indexOf("[DIRECTION]") != -1) liHeight += 100;

	var lsURL=encodeURI(gsCurURL) + sGetLang("DB_NAME_FLOW") + "/frmSelectUser?OpenForm"+lsTarget+lsStyle+lsWinTitle+lsParentFlow;
	if(pbModal)
		return vOpenModal(lsURL,laArg,liWidth,liHeight);
	else
		OpenWindow(lsURL,"SelectUser",liWidth,liHeight,"no");
}

function sMakeFlowName(psFlowType,psFlowName){
	return psFlowType + "/" + psFlowName;
}

function iGetStringByte(psMsg){
	if (psMsg==null) return 0;
	var lsMsg= escape(psMsg);
	var liCount=0;
	while (lsMsg.indexOf("%u")!=-1){
		liCount++;
		lsMsg = lsMsg.substr(lsMsg.indexOf("%u")+2);
	}
	return (psMsg.length+liCount);
}

function bShowDesktopArea(){
	if (typeof document.all.ID_AREA=="object" && document.all.ID_AREA.innerText.toLowerCase()=="right"){
		for (var i=0;i<document.images.length;i++){
			if (document.images[i].src.indexOf("ico_list_blank.gif")!=-1){
				document.images[i].src = gsImgURL+"ico_list_gray.gif";
			}
		}
	}
	if (typeof document.all.ID_AREA=="object" && document.all.ID_AREA.innerText.toLowerCase()=="left"){
		for (var i=0;i<document.images.length;i++){
			if (document.images[i].src.indexOf("ico_list_blank.gif")!=-1){
				document.images[i].src = gsImgURL+"ico_list_red.gif";
			}
		}
	}
	if (typeof document.all.ID_AREA_SN=="object" && document.all.ID_AREA_SN.innerText!=""){
		var lsSN = document.all.ID_AREA_SN.innerText;
		if (typeof document.all.ID_TITLE=="object" && typeof parent.document.all("ID_DESKTOP_TITLE_"+lsSN)=="object"){
			if (parent.document.all("ID_DESKTOP_TITLE_"+lsSN).innerText.trim()!=""){
				var lsHTML = parent.document.all("ID_DESKTOP_TITLE_"+lsSN).innerText;
				var loTitle = document.all.ID_TITLE;
				for(var i=0;i<loTitle.children.length;i++){
					if(loTitle.children[i].tagName=="A") loTitle.children[i].innerHTML = lsHTML;
				}
				if (loTitle.children.length==0) loTitle.innerHTML = lsHTML;
			}
			parent.document.all("ID_DESKTOP_TITLE_"+lsSN).innerHTML = document.all.ID_TITLE.innerHTML;
		}
		if (typeof document.all.ID_MORE=="object" && typeof parent.document.all("ID_DESKTOP_MORE_"+lsSN)=="object"){
			parent.document.all("ID_DESKTOP_MORE_"+lsSN).innerHTML = document.all.ID_MORE.innerHTML;
		}
		if (typeof parent.document.all("ID_DESKTOP_TITLEBAR_"+lsSN)=="object"){
			parent.document.all("ID_DESKTOP_TITLEBAR_"+lsSN).style.display="";
		}
	}
}


function bShowPageContent(i){
	var oPages = document.getElementsByName('ID_PageContent');
	for(j=0;j<oPages.length;j++){
		var loStyleContent=eval("document.getElementsByName('ID_PageContent')["+j+"].style");
		var loBottomLine = eval("document.all.ID_TD_"+j);
		var loStylebtn = eval("document.all.ID_BTN_"+j+".style");
		if(j==i){
			loBottomLine.className="PAGELABEL_BOTTOMLINE_SELECT";
	  		loStylebtn.height=22;
			loStyleContent.display="";
		}else{
			loBottomLine.className="PAGELABEL_BOTTOMLINE_NOSELECT";
  			loStylebtn.height=20;
			loStyleContent.display="none";
		}
	}
	window.ID_Page_Index = i;
	if (typeof(bPageChange)=="function") bPageChange();
}


function bInitPageLabel(piIndex){
	var tdBody="<table cellpadding=0 cellspacing=0 border=0 style=\"width:100%;height:100%\"><tr>";
	var oPages = document.getElementsByName('ID_PageContent');
	for(i=0;i<oPages.length;i++){
		var lsWidth = "80"
		if (oPages[i].LabelWidth!=null && oPages[i].LabelWidth!="") lsWidth = oPages[i].LabelWidth
		tdBody+="<td style='vertical-align:bottom;'>";
		tdBody+="<table cellspacing=0 cellpadding=0 border=0 style='background-color:"+document.bgcolor+";line-height:12pt;width:"+lsWidth+";' class='PAGELABEL'>";
		tdBody+="<tr>";
		tdBody+="<td style='width:1;height:1'><\/td><td style='width:1'><\/td>";
		tdBody+="<td class='PAGELABEL_LINE'><\/td><td style='width:1'></td><td style='width:1'></td>";
		tdBody+="<\/tr>";
		tdBody+="<tr><td style='height:1'><\/td><td class='PAGELABEL_LINE'><\/td>";
		tdBody+="<td></td><td style='background-color:black'><\/td><td></td>";
		tdBody+="<\/tr>";
		tdBody+="<tr><td class='PAGELABEL_LINE'><\/td><td><\/td>";
		tdBody+="<td id=ID_BTN_"+(i)+" onClick=\"bShowPageContent("+i+");\" style='height:20' nowrap><span>"+oPages[i].Label+"<\/span></td>";
		tdBody+="<td style='background-color:gray'><\/td><td style='background-color:black'><\/td>";
		tdBody+="<\/tr>";
		tdBody+="<tr><td class='PAGELABEL_LINE'><\/td><td colspan=4 class='PAGELABEL_BOTTOMLINE_NOSELECT' style='height:1' id='ID_TD_"+(i)+"'><\/td>";
		tdBody+="<\/tr>";
		tdBody+="<\/table>";
		tdBody+="<\/td>";
	}
	tdBody+="<\/tr><\/table>";
	ID_TD_BODY.innerHTML = ID_TD_BODY.innerHTML + tdBody;
	if (piIndex==null) piIndex=0;
	bShowPageContent(piIndex);
}


function bSortEntry(poField,pbUp){
	var lsTemp;
	if (poField.length == 0) return false;
	if (poField.selectedIndex == -1) return false;
	if (pbUp==true){
		for(var i=0;i<poField.options.length ; i++){
			if (poField.options[i].selected==false) continue;
			if(i==0) continue;
			lsTemp = poField.options[i].text;
			poField.options[i].text = poField.options[i-1].text;
			poField.options[i-1].text = lsTemp;
			lsTemp = poField.options[i].value;
			poField.options[i].value = poField.options[i-1].value;
			poField.options[i-1].value = lsTemp;
			poField.options[i-1].selected=true;
			poField.options[i].selected=false;
		}
	}else{
		for(var i=poField.options.length-1;i>=0; i--){
			if (poField.options[i].selected==false) continue;
			if(i==poField.options.length-1) continue;
			lsTemp = poField.options[i].text;
			poField.options[i].text = poField.options[i+1].text;
			poField.options[i+1].text = lsTemp;
			lsTemp = poField.options[i].value;
			poField.options[i].value = poField.options[i+1].value;
			poField.options[i+1].value = lsTemp;
			poField.options[i+1].selected=true;
			poField.options[i].selected=false;
		}
	}
}

function bMoveEntry(poFromField,poToField){
	var liLength=0,lsText,lsValue;

	var loFrom=poFromField;
	var loTo=poToField;

	if (loFrom.length == 0) return false;
	if (loFrom.selectedIndex == -1) return false;
	if (loTo!=null){
		liLength=loTo.options.length;
		for(var i=0;i<loFrom.options.length ; i++){
			if (loFrom.options[i].selected==false) continue;
			lsText=loFrom.options[i].text;
			lsValue=loFrom.options[i].value;
			if (lsValue=="00000" || lsValue=="") continue;
			var loEntry = new Option(lsText,lsValue);
			if (1==loTo.options.length && loTo.options[0].text==""){
				loTo.options[0]=loEntry;
			}else{
				loTo.options[liLength]=loEntry;
				liLength++;
			}
		}
	}
	var liIndex = -1;
	for(var i=loFrom.options.length-1;i>=0; i--){
		if (loFrom.options[i].selected==false) continue;
		if (loFrom.options[i].value=="00000" || loFrom.options[i].value=="") continue;
		loFrom.options[i]=null;
		liIndex = i;
	}
	if (liIndex>-1 && liIndex<loFrom.options.length)
		loFrom.options[liIndex].selected=true;
	else if (loFrom.options.length>0)
		loFrom.options[loFrom.options.length-1].selected=true;
		
}

function bAddEntry(poField,psText,psValue,pbNoSelect){
	if (poField==null || psText==null || psValue==null) return false;
	var loEntry = new Option(psText,psValue);
	if (1==poField.options.length && poField.options[0].text==""){
		poField.options[0]=loEntry;
	}else{
		poField.options[poField.options.length]=loEntry;
	}
	if(pbNoSelect!=true) poField.selectedIndex = poField.options.length-1;
	return true;
	
}

function bInsertEntry(poField,psText,psValue){
	if (poField==null || psText==null || psValue==null) return false;
	if (poField.selectedIndex==-1) return bAddEntry(poField,psText,psValue);
	var liLength = poField.options.length;
	var liIndex = poField.selectedIndex;
	poField.options[liLength] = new Option("","");
	for(var i = liLength;i > liIndex; i--){
		poField.options[i].text = poField.options[i-1].text;
		poField.options[i].value = poField.options[i-1].value;
	}
	poField.options[i].text = psText;
	poField.options[i].value = psValue;
	return true;
}

function bEditEntry(poField,psText,psValue){
	if (poField==null || psText==null || psValue==null) return false;
	if (poField.length == 0) return false;
	if (poField.selectedIndex == -1) return false;
	var loEntry = new Option(psText,psValue);
	var liIndex = poField.selectedIndex;
	poField.options[liIndex].text = psText;
	poField.options[liIndex].value = psValue;
	poField.selectedIndex=liIndex;
	return true;
}

function sGetAllEntryText(poField,pbSelect,psSeparator,pbContainValue){
	var lsReturn="",lsValue;
	var lsSeparator = (psSeparator!=null && psSeparator!="")?psSeparator:";";
	for (var i=0;i<poField.options.length;i++){
		if (poField.options[i].text=="") continue;
		if (pbSelect==true && poField.options[i].selected==false) continue;
		lsValue = poField.options[i].text;
		if (pbContainValue==true) lsValue += "|"+poField.options[i].value;
		if (lsReturn=="")
			lsReturn = lsValue;
		else
			lsReturn +=lsSeparator+lsValue;
	}
	return lsReturn;
}

function sGetAllEntryValue(poField,pbSelect,psSeparator){
	var lsReturn="";
	var lsSeparator = (psSeparator!=null && psSeparator!="")?psSeparator:";";
	for (var i=0;i<poField.options.length;i++){
		if (poField.options[i].value=="") continue;
		if (pbSelect==true && poField.options[i].selected==false) continue;
		if (lsReturn=="")
			lsReturn = poField.options[i].value;
		else
			lsReturn +=lsSeparator+poField.options[i].value;
	}
	return lsReturn;
}

function sGetFormatHTML(piApply,psTH,psData){
	var lsContent=psData;
	var lsTH = psTH;
	switch (piApply) {
	case 0 ://License history
		lsTH = sGetLang("P_FORMAT_LICENSEHISTORY");
		break;
	case 1 ://work opinions
		lsTH = sGetLang("P_FORMAT_WORKOPINION");
		lsContent = sReplaceSubstring(lsContent,"-&gt;","->");
		lsContent = sReplaceSubstring(lsContent,"&lt;-","<-");
		lsContent = sReplaceSubstring(lsContent,"->\r\n[[","</td><td>");
		lsContent = sReplaceSubstring(lsContent,"->\r\n[","</td><td>");
		lsContent = sReplaceSubstring(lsContent,"\r\n[[","</td></tr><tr><td>{NOTASK}</td><td>");
		lsContent = sReplaceSubstring(lsContent,"\r\n[","</td></tr><tr><td>{NOTASK}</td><td>");
		lsContent = sReplaceSubstring(lsContent,"]][","</td><td>");
		lsContent = sReplaceSubstring(lsContent,"][","</td><td>");
		lsContent = sReplaceSubstring(lsContent,"]\r\n","</td></tr><tr><td{BLANK}colspan=3>");
		lsContent = sReplaceSubstring(lsContent,"\r\n<-","</td></tr><tr><td>");
		lsContent = "<tr><td>" + lsContent.substring(2,lsContent.length-2) + "</td></tr>";
		var lsFlag = "</td></tr><tr><td>{NOTASK}</td><td>";
		while (lsContent.indexOf(lsFlag)>-1){
			var lsLeft = lsContent.substring(0,lsContent.indexOf(lsFlag));
			var lsRight = lsContent.substring(lsContent.indexOf(lsFlag)+lsFlag.length,lsContent.length);
			var lsTemp = lsLeft.substring(lsLeft.lastIndexOf("<tr><td>")+8,lsLeft.length);
			lsTemp = lsTemp.substring(0,lsTemp.indexOf("<"));
			lsContent = lsLeft + "</td></tr><tr><td>" + lsTemp + "</td><td>" + lsRight;
		}
		lsContent = sReplaceSubstring(lsContent, "\n", "<BR>");
		lsContent = sReplaceSubstring(lsContent, " ", "&nbsp;");
		lsContent = sReplaceSubstring(lsContent, "{BLANK}", " ");
		break;
	case 2 ://monitor opinions
		lsTH = sGetLang("P_FORMAT_MONITOROPINION");
		lsContent = sReplaceSubstring(lsContent,"]][","</td><td>");
		lsContent = sReplaceSubstring(lsContent,"][","</td><td>");
		lsContent = sReplaceSubstring(lsContent,"]\r\n","</td></tr><tr><td{BLANK}colspan=2>");
		lsContent = sReplaceSubstring(lsContent,"\r\n[[","</td></tr><tr><td>");
		lsContent = sReplaceSubstring(lsContent,"\r\n[","</td></tr><tr><td>");
		if (lsContent.substring(0,2)=="[[")
			lsContent = "<tr><td>" + lsContent.substring(2,lsContent.length) + "</td></tr>";
		else
			lsContent = "<tr><td>" + lsContent.substring(1,lsContent.length) + "</td></tr>";
		lsContent = sReplaceSubstring(lsContent, "\n", "<BR>");
		lsContent = sReplaceSubstring(lsContent, " ", "&nbsp;");
		lsContent = sReplaceSubstring(lsContent, "{BLANK}", " ");
		break;
	case 3 ://Activities;
		lsContent = sReplaceSubstring(lsContent,"\r\n","</td></tr><tr><td>");
		lsContent = "<tr><td>" + lsContent + "</td></tr>";
		break;
	default :
		return psData;
	}
	var lsHTML = '<table border="0" cellspacing="1" cellpadding="3" class="SHOW_HTML" align=center>';
	lsHTML += lsTH;
	lsHTML += lsContent;
	lsHTML += "</table>";
	return lsHTML;
}

function bPromptField(psFieldName){
	var lsURL = encodeURI(gsOAURL)+gsSRDBName+'/agtViewField?OpenAgent&DB=' + escape(gsCurURL.substr(1) + gsCurDBName) + "&UNID=" + gsCurUNID + "&FieldName=" + psFieldName;
	top.RunAgent.location.replace(lsURL);
}

/*
var laTemp = vPromptMsgFormat();
if (laTemp!=null){alert(laTemp["Name"]);alert(laTemp["ID"]);}
*/


function vPromptMsgFormat(psCategory,pbMultiChoice,psInitValue){
	var lsURL=encodeURI(gsOAURL)+gsDCDBName+"/agtFormatTree?OpenAgent&Type=MSG";
	if (psCategory!=null && psCategory!="") lsURL += "&Category=" + escape(psCategory);
	if (psInitValue==null) psInitValue="";
	var rsTemp=PromptTree(true,psInitValue,lsURL,sGetLang("DICTION_MSGFORMAT"),pbMultiChoice);
	if (rsTemp==null || rsTemp.trim()=="") return null;
	var laTemp=rsTemp.split(";");
	var raValue = new Array();
	raValue['Name']="";
	raValue['ID']="";
	for (var i=0; i<laTemp.length; i++){
		if (raValue['Name']=="")
			raValue['Name'] =  laTemp[i].substr(0,laTemp[i].indexOf("|"));
		else
			raValue['Name'] += ";"+laTemp[i].substr(0,laTemp[i].indexOf("|"));
		if (raValue['ID']=="")
			raValue['ID'] = laTemp[i].substr(laTemp[i].indexOf("|")+1);
		else
			raValue['ID'] += ";"+laTemp[i].substr(laTemp[i].indexOf("|")+1);
	}
	return raValue;
}

/*
var laTemp = vPromptSNFormat();
if (laTemp!=null){alert(laTemp["Name"]);alert(laTemp["ID"]);}
*/


function vPromptSNFormat(psCategory,pbMultiChoice,psInitValue){
	var lsURL=encodeURI(gsOAURL)+gsDCDBName+"/agtFormatTree?OpenAgent&Type=SN";
	if (psCategory!=null && psCategory!="") lsURL += "&Category=" + escape(psCategory);
	if (psInitValue==null) psInitValue="";
	var rsTemp=PromptTree(true,psInitValue,lsURL,sGetLang("DICTION_SNFORMAT"),pbMultiChoice);
	if (rsTemp==null || rsTemp.trim()=="") return null;
	var laTemp=rsTemp.split(";");
	var raValue = new Array();
	raValue['Name']="";
	raValue['ID']="";
	for (var i=0; i<laTemp.length; i++){
		if (raValue['Name']=="")
			raValue['Name'] =  laTemp[i].substr(0,laTemp[i].indexOf("|"));
		else
			raValue['Name'] += ";"+laTemp[i].substr(0,laTemp[i].indexOf("|"));
		if (raValue['ID']=="")
			raValue['ID'] = laTemp[i].substr(laTemp[i].indexOf("|")+1);
		else
			raValue['ID'] += ";"+laTemp[i].substr(laTemp[i].indexOf("|")+1);
	}
	return raValue;
}


/*
var laTemp = vPromptMenu();
if (laTemp!=null){alert(laTemp["Name"]);alert(laTemp["ID"]);}
*/


function vPromptMenu(psType,pbMultiChoice,pbAdmin,pbPrivate){
	var lsURL=encodeURI(gsOAURL)+sGetLang("DB_NAME_MENU")+"/agtMenuTree?OpenAgent";
	if (psType==null || psType=="") psType = "0123";
	lsURL += "&Type=" + psType;
	if (pbAdmin!=null && pbAdmin==true) lsURL += "&isAdmin=1";
	if (pbPrivate!=null && pbPrivate==true) lsURL += "&isPrivate=1";
	var rsTemp=PromptTree(true,"",lsURL,sGetLang("ADMIN_PROMPTMENU"),pbMultiChoice);
	if (rsTemp==null || rsTemp.trim()=="") return null;
	var laTemp=rsTemp.split(";");
	var raValue = new Array();
	raValue['Name']="";
	raValue['ID']="";
	for (var i=0; i<laTemp.length; i++){
		if (raValue['Name']=="")
			raValue['Name'] =  laTemp[i].substr(0,laTemp[i].indexOf("|"));
		else
			raValue['Name'] += ";"+laTemp[i].substr(0,laTemp[i].indexOf("|"));
		if (raValue['ID']=="")
			raValue['ID'] = laTemp[i].substr(laTemp[i].indexOf("|")+1);
		else
			raValue['ID'] += ";"+laTemp[i].substr(laTemp[i].indexOf("|")+1);
	}
	return raValue;
}

/*
var laTemp = vPromptLink();
if (laTemp!=null){alert(laTemp["Name"]);alert(laTemp["LINK"]);}
*/


function vPromptLink(pbMultiChoice){
	var lsURL=encodeURI(gsOAURL)+gsDCDBName+"/agtLinkTree?OpenAgent";
	var rsTemp=PromptTree(true,"",lsURL,sGetLang("DICTION_PROMPTLINK"),pbMultiChoice);
	if (rsTemp==null || rsTemp.trim()=="") return null;
	var laTemp=rsTemp.split(";");
	var raValue = new Array();
	raValue['Name']="";
	raValue['LINK']="";
	for (var i=0; i<laTemp.length; i++){
		if (raValue['Name']=="")
			raValue['Name'] =  laTemp[i].substr(0,laTemp[i].indexOf("|"));
		else
			raValue['Name'] += ";"+laTemp[i].substr(0,laTemp[i].indexOf("|"));
		if (raValue['LINK']=="")
			raValue['LINK'] = laTemp[i].substr(laTemp[i].indexOf("|")+1);
		else
			raValue['LINK'] += ";"+laTemp[i].substr(laTemp[i].indexOf("|")+1);
	}
	return raValue;
}

function iGetLeftPosition(obj){
	if (obj==null && event.srcElement!=null) obj = event.srcElement;
	if (obj==null) return -1;
	var liLeft=obj.offsetLeft;
	while(obj=obj.offsetParent){
		liLeft += obj.offsetLeft; 
	}
	return liLeft-document.body.scrollLeft;
}
function iGetTopPosition(obj){
	if (obj==null && event.srcElement!=null) obj = event.srcElement;
	if (obj==null) return -1;
	var liTop=obj.offsetTop;
	while(obj=obj.offsetParent){
		liTop += obj.offsetTop; 
	}
	return liTop-document.body.scrollTop;
}

function bMarkRead(psURL){
	var lsHost="";
	if (psURL==null || psURL=="" || psURL.indexOf("?")==-1) return false;
	if (psURL.indexOf("http://")>=0 || psURL.indexOf("https://")>=0){
		lsHost=psURL.substring(0,psURL.indexOf("/"))+"//";
		psURL=psURL.substring(lsHost.length,psURL.length);
		lsHost+=psURL.substring(0,psURL.indexOf("/"));
		psURL=psURL.substring(psURL.indexOf("/"),psURL.length);
	}
	var lsURL = encodeURI(psURL.substring(1,psURL.indexOf("?")));
	if (lsURL.toLowerCase().indexOf(".nsf")==-1) return false;
	var lsDBPath = lsURL.substring(0,lsURL.toLowerCase().indexOf(".nsf")+4);
	lsURL = lsURL.substr(lsURL.toLowerCase().indexOf(".nsf"));
	var laTemp = lsURL.split("/");
	var lsUNID=null;
	for (var i=0;i<laTemp.length;i++){
		if (laTemp[i].length==32){
			lsUNID = laTemp[i];
			break;
		}
	}
	if (lsUNID==null) return false;
	var lsReadURL = lsHost+gsOAURL + gsSRDBName + "/agtMarkRead?OpenAgent&DBPath=" + lsDBPath + "&NTID=" + lsUNID;
	var lsName = sGetParameter("FieldName",psURL);
	var lsValue =sGetParameter("FieldValue",psURL);
	if (lsName!=null && lsName!="") lsReadURL += "&FieldName="+lsName;
	if (lsValue!=null && lsValue!="") lsReadURL += "&FieldValue="+lsValue;
	if (top.msgDocuments==null) top.msgDocuments = new Array();
	top.msgDocuments[top.msgDocuments.length] = lsDBPath+"|"+lsUNID;
	top.RunAgent.location.replace(lsReadURL);
}

function bCheckUnique(psFieldName,psValue,psCert,psDBPath,psUNID,pbNotPrompt){
	var lsDBPath = psDBPath;
	if (lsDBPath==null) lsDBPath = encodeURI(gsCurURL.substr(1)+gsCurDBName);
	var lsUNID = psUNID;
	if (lsUNID==null) lsUNID = gsCurUNID;
	var lsValue = psValue;
	if (lsValue==null) lsValue = eval("goForm."+psFieldName+".value");
	if (lsValue.trim()=="") return false;
	var lsURL=encodeURI(gsOAURL) + gsSRDBName + "/agtCheckUnique?openagent&DB="+lsDBPath+"&UNID="+lsUNID+"&Name="+psFieldName+"&Value="+encodeURIComponent(lsValue);
	lsURL += "&Temp=" + Math.random();
	if (psCert!=null && psCert!="") lsURL += "&Cert=" + encodeURIComponent(psCert);

	var xmlhttp = oGetXmlHttpRequest();
	if (xmlhttp==null) return false;
	xmlhttp.open("GET",lsURL, false);
	xmlhttp.send();
	var lsText = xmlhttp.responseText;
	var lbReturn = false;
	if (lsText.indexOf("<UNIQUE>")!=-1 && lsText.indexOf("</UNIQUE>")!=-1 && lsText.substring(lsText.indexOf("<UNIQUE>")+8,lsText.indexOf("</UNIQUE>"))=="1")
		lbReturn = true;

	if (pbNotPrompt!=true){
		if (lbReturn == true)
			alert(sGetLang("P_CHECK_ISUNIQUE"));
		else
			alert(sGetLang("P_CHECK_ISNOTUNIQUE"));
	}
	return lbReturn;
}

function bAssistantInput(psFieldName,psValue,psCert,psDBPath,psUNID){
	var lsDBPath = psDBPath;
	if (lsDBPath==null) lsDBPath = encodeURI(gsCurURL.substr(1) + gsCurDBName);
	var lsValue = psValue;
	if (lsValue==null) lsValue = eval("goForm."+psFieldName+".value");
	var lsURL=encodeURI(gsOAURL) + gsSRDBName + "/agtAssistantInput?openagent&DB="+encodeURIComponent(lsDBPath)+"&Name="+psFieldName+"&Value="+encodeURIComponent(lsValue);
	if (psUNID!=null && psUNID!="") lsURL += "&UNID=" + psUNID;
	if (psCert!=null && psCert!="") lsURL += "&Cert=" + encodeURIComponent(psCert);
	WebAction(lsURL,"");
}

function bFormInput(poFrom,poTo){
	//ID_InputRules.innerText:name1=fromname1;name2=fromname2
	var lsName,lsValue,lsValueString,lsRule="";
	if (typeof document.all.ID_InputRules=="object") lsRule = ";"+document.all.ID_InputRules.innerText+";";
	for (var i = 0; i < poTo.elements.length; i++){
		lsName = poTo.elements[i].name;
		if (lsName==null) continue;
		if (lsRule.indexOf(";"+lsName+"=")!=-1){
			lsName = lsRule.substring(lsRule.indexOf(";"+lsName+"=")+lsName.length+2,lsRule.length);
			lsName = lsName.substring(0,lsName.indexOf(";"));
		}else if (lsRule!="") continue;
		if (lsName==null || lsName=="" || lsName.indexOf("%")!=-1) continue;
		for (var j = 0; j < poFrom.elements.length; j++){
			if (poFrom.elements[j].name.toLowerCase()==lsName.toLowerCase()){
				lsValue = poFrom.elements[j].value;
				break;
			}
		}
		if (j >= poFrom.elements.length) continue;
		lsValueString = ";" + lsValue + ";";
		switch(poTo.elements[i].type){
		case "radio":
			if (lsValueString.indexOf(";"+poTo.elements[i].value+";")!=-1)
				poTo.elements[i].checked=true;
			else
				continue;
			break;
		case "checkbox":
			if (lsValueString.indexOf(";"+poTo.elements[i].value+";")!=-1)
				poTo.elements[i].checked=true;
			else
				poTo.elements[i].checked=false;
			break;
		case "select-one":
		case "select-multiple":
			for(var j = 0;j<poTo.elements[i].options.length;j++){
				if (lsValueString.indexOf(";"+poTo.elements[i].options[j].value+";")!=-1 || lsValueString.indexOf(";"+poTo.elements[i].options[j].text+";")!=-1){
					poTo.elements[i].options[j].selected = true;
				}else{
					poTo.elements[i].options[j].selected = false;
				}
			}
			break;
		case "hidden":
		case "text":
		case "textarea":
			poTo.elements[i].value = lsValue;
			break;
		}
		if(typeof poTo.elements[i].onclick=="function") poTo.elements[i].onclick();
		if(typeof poTo.elements[i].onchange=="function") poTo.elements[i].onchange();
	}
	return true;
}

function MathRoundExt(x,y){
	x = Math.round (x*Math.pow(10,y))/Math.pow(10,y); 
	return x;
}

Array.prototype.unique=function(){
  for(var y=0;y<this.length;++y){
    for(var z=(y+1);z<=this.length;++z){
	  	if(this[y]==this[z]){
	    	this.splice(z,1);
				z--;
    	}
  	}
 	}
 	return this;
}

function bWebScan(){
	if((typeof(goForm.ScanControl)!="object") || (gbIsEdit==false))return true;
	if((typeof(goForm.UploadControl)!="object") || (gbIsEdit==false))return true;
	var lsFileUpload = goForm.ScanControl.AppStart();
	if(lsFileUpload.trim() == "") return true;
	var laFile = lsFileUpload.split("|");
	for(i=0;i<laFile.length;i++){
		goForm.UploadControl.AddLocalFile(laFile[i]);
	}
}

function bShowDesktopCategory(psDocNumber){
	var loSpan=eval("document.all.ID_Content_"+psDocNumber);
	if(typeof loSpan=="object"){
		if(loSpan.style.display!="none")
			loSpan.style.display="none";
		else
			loSpan.style.display="";
	}
	var loSpanImage=eval("document.all.ID_Image_"+psDocNumber);
	if(typeof loSpanImage=="object" && typeof loSpan=="object"){
		if(loSpan.style.display!="none")
			loSpanImage.src=gsImgURL+"ico_desktopcollapse.gif";
		else
			loSpanImage.src=gsImgURL+"ico_desktopexpand.gif";
	}
}


function bHideIndexDiv(psArea){
	var oDivs = null
	var lbRefresh=false;
	var loframe = top.ViewIFrame;
	switch(psArea){
	case "head":
		oDivs = document.getElementsByName('ID_HideHead_TR');
		break;
	case "left":
		oDivs = document.getElementsByName('ID_DIV_LEFTBODY');
		if (oDivs!=null && oDivs.length>0){
			for (var i=0;i<oDivs.length;i++){
				if (oDivs[i].style.display=="none"){
					oDivs[i].style.display="";
					lbRefresh = true
				}else{
					oDivs[i].style.display="none"
				}
			}
		}
		oDivs = document.getElementsByName('ID_HideLeft_TD');
		break;
	case "bottom":
		oDivs = document.getElementsByName('ID_HideBottom_TR');
		break;
	}
	if (oDivs!=null && oDivs.length>0){
		for (var i=0;i<oDivs.length;i++){
			if (oDivs[i].style.display=="none")
				oDivs[i].style.display="";
			else
				oDivs[i].style.display="none"
		}
	}
	if (lbRefresh == true) window.NavIFrame.location.reload(true);
	if (loframe.MaxsizeObj!=null){
		loframe.MaxsizeObj.style.width = loframe.document.body.offsetWidth;
		loframe.MaxsizeObj.style.height = top.document.all.ViewIFrame.parentElement.offsetHeight;
		loframe.setTimeout('document.body.style.overflowY="hidden"',1);
	}
}


function bDesktopDblClick(poObj){
	var liHeight,liWidth;
	if (poObj.isMaxsized=="1"){
		poObj.isMaxsized="";
		poObj.style.position = "relative";
		poObj.style.zIndex = 0;
		poObj.title=sGetLang("P_CONST_DIVMAXSIZE");
		document.body.scrollTop = poObj.originalScrollTop;
		document.body.style.overflowY = poObj.originalOverFlowY;
		liWidth="100%";
		liHeight="100%";
		parent.document.all.ViewIFrame.scrolling = "auto";
		window.MaxsizeObj = null;
	}else{
		poObj.isMaxsized="1";
		poObj.originalOverFlowY = document.body.style.overflowY;
		poObj.originalScrollTop = document.body.scrollTop;
		document.body.scrollTop = 0;
		document.body.style.overflowY="hidden";
		liWidth = document.body.offsetWidth;
		liHeight = top.document.all.ViewIFrame.parentElement.offsetHeight;
		poObj.style.position = "absolute";
		poObj.style.zIndex = 1;
		poObj.style.top = 0;
		poObj.style.left = 0;
		poObj.title=sGetLang("P_CONST_DIVRESET");
		parent.document.all.ViewIFrame.scrolling = "no";
		window.MaxsizeObj = poObj;
	}
	poObj.style.width = liWidth;
	poObj.style.height = liHeight;
}


function sAdjustDateTime(psDateTime,piYear,piMonth,piDate,piHour,piMinute,piSecond){
	var loDateTime=new Date();
	var lsDate = "",lsTime = "";;
	if (psDateTime.indexOf(" ")!=-1){
		lsDate = psDateTime.substring(0,psDateTime.indexOf(" "));
		lsTime = psDateTime.substring(psDateTime.indexOf(" ")+1,psDateTime.length);
	}else if (psDateTime.indexOf(":")!=-1){
		lsTime = psDateTime;
	}else{
		lsDate = psDateTime;
	}
	if (lsDate!=""){
		if (lsDate.indexOf("-")>0) var laDate = lsDate.split("-");
		else if (lsDate.indexOf(".")>0) var laDate = lsDate.split(".");
		else if (lsDate.indexOf("/")>0) var laDate = lsDate.split("/");
		if (Math.abs(laDate[0])<13){
			loDateTime.setFullYear(Math.abs(laDate[2]));
			loDateTime.setMonth(Math.abs(laDate[0])-1);
			loDateTime.setDate(Math.abs(laDate[1]));
		}else{
			loDateTime.setFullYear(((laDate[0].length==2)?1900:0)+Math.abs(laDate[0]));
			loDateTime.setMonth(Math.abs(laDate[1])-1);
			loDateTime.setDate(Math.abs(laDate[2]));
		}
	}
	if (lsTime!=""){
		var laTime = lsTime.split(":");
		loDateTime.setHours(Math.abs(laTime[0]));
		loDateTime.setMinutes(Math.abs(laTime[1]));
		loDateTime.setSeconds((laTime.length>2)?Math.abs(laTime[2]):0);
	}
	if (piSecond!=null) loDateTime.setSeconds(loDateTime.getSeconds()+piSecond);
	if (piMinute!=null) loDateTime.setMinutes(loDateTime.getMinutes()+piMinute);
	if (piHour!=null) loDateTime.setHours(loDateTime.getHours()+piHour);
	if (piDate!=null) loDateTime.setDate(loDateTime.getDate()+piDate);
	if (piMonth!=null) loDateTime.setMonth(loDateTime.getMonth()+piMonth);
	if (piYear!=null) loDateTime.setFullYear(loDateTime.getFullYear()+piYear);
	if (lsDate!="") lsDate = loDateTime.getFullYear()+"-"+((loDateTime.getMonth()<9)?"0"+(loDateTime.getMonth()+1):loDateTime.getMonth()+1)+"-"+((loDateTime.getDate()<10)?"0"+loDateTime.getDate():loDateTime.getDate());
	if (lsTime!="") lsTime = ((loDateTime.getHours()<10)?"0"+loDateTime.getHours():loDateTime.getHours())+":"+((loDateTime.getMinutes()<10)?"0"+loDateTime.getMinutes():loDateTime.getMinutes())+((laTime.length>2)?":"+((loDateTime.getSeconds()<10)?"0"+loDateTime.getSeconds():loDateTime.getSeconds()):"");
	var lsDateTime = (lsDate!="" && lsTime!="" || lsDate=="" && lsTime=="")?lsDate+" "+lsTime:((lsDate!="")?lsDate:lsTime);
	return lsDateTime;
}

function oGetXmlHttpRequest() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				return null;
			}
		}
	}
	else {
		return null;
	}
}

function sGetFreeTime(psDateTime,psArgument,piTimeUnit){
	//psArgument:interval or DateTime
	//piTimeUnit:1/2/3/60/3600/86400
	var xmlhttp = oGetXmlHttpRequest();
	if (xmlhttp==null) return "";
	var lsURL = encodeURI(gsOAURL)+gsSRDBName+"/agtGetFreeTime?openagent&Time="+psDateTime+"&Argument="+psArgument+"&Unit="+piTimeUnit;
	xmlhttp.open("GET",lsURL, false);
	xmlhttp.send();
	var lsText = xmlhttp.responseText;
	if (lsText.indexOf("<DATETIME>")!=-1 && lsText.indexOf("</DATETIME>")!=-1){
		lsText = lsText.substring(lsText.indexOf("<DATETIME>")+10,lsText.indexOf("</DATETIME>"));
	}else{
		lsText = null;
	}
	return lsText;
}


function QueryCloseIE(){
	var lbEdit = (top.ContentBody && top.ContentBody.gbIsEdit==true)?true:false;
	if (top.DisabledCloseIE==true || (lbEdit && top.ContentBody.bGetFormModified() && event!=null && (event.clientY<0 || event.clientX<58 && event.clientY<31))){
		var lsMsg=(top.CloseIEMsg)?top.CloseIEMsg:(lbEdit?sGetLang("P_CONST_SAVECONFIRM"):sGetLang("P_CONST_CLOSECONFIRM"));
		event.returnValue=lsMsg;
	}
	return false;
}

function bSetCloseIE(pbConfirm,psMsg){
	top.DisabledCloseIE = pbConfirm;
	top.CloseIEMsg = psMsg;
	return true;
}

function bSetFormModify(){
	if (typeof top.document!="object" || typeof top.document.all.ID_Form_MenuBar !="object") return false;
	if (typeof goForm!="object") return false;
	var fun = function(){top.FormModified=true;}
	for(var i=0;i<goForm.elements.length;i++){
		goForm.elements[i].attachEvent('onchange', fun);
		if (goForm.elements[i].onclick) goForm.elements[i].attachEvent('onclick', fun);
	}
	for(var i=0;i<document.links.length;i++){
		if (document.links[i].offsetHeight>0) document.links[i].attachEvent('onclick', fun);
	}
	return true;
}

function bGetFormModified(){
	if (top.FormModified==true) return true;
	if (bAttachmentsModified()==true) return true;
	if (bWordBodyModified()==true) return true;
	if (bWebSignatureModified()==true) return true;
	if (goForm && goForm.EditorModified && goForm.EditorModified()==true) return true;
	if(typeof gaPowerList == "object"){
		for(var i=0;i<gaPowerList.length;i++){
			if(gaPowerList[i].GetModified()) return true;
		}
	}
	return false;
}

function bSetFormModified(pbModified){
	top.FormModified = pbModified;
	return true;
}

function document.onreadystatechange(){
	if (document.readyState!="complete") return;
	bSetFormModify();
	if (typeof top.document!="unknown" && top.ViewIFrame!=null && typeof top.ViewIFrame.parent=="object" && top.ViewIFrame.MaxsizeObj!=null){
		top.ViewIFrame.setTimeout('document.body.style.overflowY="hidden"',1);
	}
}

function bPrintForm(){
	var loObjs = window.document.all;
	var laDisabled = new Array();
	for (var i=0;i<loObjs.length;i++){
		if (loObjs[i].disabled==true){
			loObjs[i].disabled=false;
			laDisabled[laDisabled.length] = loObjs[i];
		}
	}
	var lsHTML = "";
	for (var i=0;i<loObjs.length;i++){
		if (loObjs[i].tagName=="HTML"){
			lsHTML = loObjs[i].outerHTML;
			break;
		}
	}
	if (lsHTML.toLowerCase().indexOf("<\/script>")!=-1){
		lsHTML = lsHTML.substring(0,lsHTML.toLowerCase().indexOf("<\/script>"))+"<\/script><script>onerror=bHandleErr;function bHandleErr(msg,url,line){return true;}<\/script>"+lsHTML.substring(lsHTML.toLowerCase().indexOf("<\/script>")+9,lsHTML.length);
	}
	for (var i=0;i<laDisabled.length;i++){ laDisabled[i].disabled=true;}
	var loPrint = OpenWindow("","",1,1,"yes","auto","no","yes");
	loPrint.document.open();
	loPrint.document.write(lsHTML);
	loPrint.document.close();
	loPrint.document.oncontextmenu=new Function("return true");
	loPrint.status=sGetLang("ACTION_PRINTVIEW")+sGetLang("PRINT_STATUS");
}



function SetWorkStatus(psStatus,psType){
	var lsType = (psType == null)?"0":psType;
	if (typeof top.document!="unknown"){
		var loframe= top.ViewIFrame;
	}else{
		var loframe= window.MailIframe;
	}
	if(typeof loframe.RunAgent != "object"){
		loframe = top;
		if(typeof loframe.RunAgent != "object") return false;
	}
	var lsURL = encodeURI(gsCurURL)+sGetLang("DB_NAME_WORKSTATUS")+"/agtSetWorkStatus?OpenAgent&Status="+escape(psStatus)+"&Type="+lsType;
	if(loframe.RunAgent){
		loframe.RunAgent.location.replace(lsURL);
	}
}

function sHTMLEncode(psHTML){
	if(psHTML.trim() == "") return "";
	var lsOne = "";
	var lsRetHTML = ""
	for(var i = 0; i < psHTML.length; i++){
		lsOne = psHTML.substr(i,1);
		if(lsOne == "<"){
			lsRetHTML += "&lt;";
		}else if(lsOne == ">"){
			lsRetHTML += "&gt;";
		}else if(lsOne == "\""){
			lsRetHTML += "&quot;";
		}else if(lsOne == "&"){
			lsRetHTML += "&amp;";
		}else{
			lsRetHTML += lsOne;
		}
	}
	return lsRetHTML;
}

function sHTMLEncodeExt(psHTML){
	if(psHTML.trim() == "") return "";
	var lsOne = "";
	var lsRetHTML = ""
	for(var i = 0; i < psHTML.length; i++){
		lsOne = psHTML.substr(i,1);
		if(lsOne == "<"){
			lsRetHTML += "&lt;";
		}else if(lsOne == ">"){
			lsRetHTML += "&gt;";
		}else if(lsOne == "\""){
			lsRetHTML += "&quot;";
		}else if(lsOne == "&"){
			lsRetHTML += "&amp;";
		}else if(lsOne == "'"){
			lsRetHTML += "&#039;";
		}else{
			lsRetHTML += lsOne;
		}
	}
	return lsRetHTML;
}

function sHTMLDecode(psHTML){
	var re = /(&lt;)/gi;
	var rv = psHTML.replace(re,"<");
	re = /(&gt;)/gi;
	rv = rv.replace(re,">");
	re = /(&quot;)/gi;
	rv = rv.replace(re,"\"");
	re = /(&amp;)/gi;
	rv = rv.replace(re,"&");
	re = /(&#039;)/gi;
	rv = rv.replace(re,"'");
	return(rv);
}

function KQSign(psAction,psOrderID,pbAppeal){
	var xmlhttp = oGetXmlHttpRequest();
	if (xmlhttp==null) return false;
	var lbAppeal = (pbAppeal==null)?true:pbAppeal;
	if(psOrderID==null){
		var lsURL = gsCurURL + sGetLang("DB_NAME_RSKQ") +"/agtGetUnSignOrder?openagent&Action=" + psAction;
		lsURL += "&t="+((new Date()).valueOf());
		xmlhttp.open("GET",lsURL, false);
		xmlhttp.send();
		var xmlDoc = xmlhttp.responseXML;
		var lonodes = xmlDoc.selectNodes("/root/order");
		if(lonodes.length==0){
			alert(sGetLang("KQ_NOCANUSEORDER"));
			return false;
		}
		var lsOrderID = null;
		if(lonodes.length==1){
			lsOrderID = lonodes[0].selectSingleNode("id").text;
		}else{
			var lsSelValues = "";
			for(var i=0;i<lonodes.length;i++){
				if(lsSelValues!="") lsSelValues += ";";
				lsSelValues += lonodes[i].selectSingleNode("name").text + "|" + lonodes[i].selectSingleNode("id").text;
			}
			lsOrderID = sSelectArray("Single",sGetLang('KQ_SELECTORDER'),"",lsSelValues,false);
			if(lsOrderID==null) return false;
		}
	}else{
		lsOrderID = psOrderID;
	}
	if(lsOrderID==null){
		alert(sGetLang("KQ_NOCANUSEORDER"));
		return false;
	}

	var laTimeOut = (psAction.toLowerCase()=="signin")?top.inTArray:top.outTArray;
	if(typeof laTimeOut =="object"){
		if(laTimeOut[lsOrderID]!=null){
			top.clearTimeout(laTimeOut[lsOrderID]);
			laTimeOut[lsOrderID] = null;
		}
	}
	
	var lsURL = gsCurURL + sGetLang("DB_NAME_RSKQ") +"/agtAjaxSign?openagent&Order="+lsOrderID+"&Action=" + psAction;
	lsURL += "&t="+((new Date()).valueOf());
	if (psAction.toLowerCase()=="signin") 
		PromptViewLoading(sGetLang("KQ_DOINGSIGNIN"));
	else
		PromptViewLoading(sGetLang("KQ_DOINGSIGNOUT"));
	
	xmlhttp.open("GET",lsURL, false);
	xmlhttp.send();
	
	var xmlDoc = xmlhttp.responseXML;
	var lostatus = xmlDoc.selectSingleNode("/root/status");
	var lsstatus = lostatus.text;
	var lomsg = xmlDoc.selectSingleNode("/root/msg");
	var lsmsg = lomsg.text;
	var loexcept = xmlDoc.selectSingleNode("/root/exceptdo");
	var lsexcept = loexcept.text;
	if(lsstatus=="0"){
		alert(lsmsg);
	}else{
		var loid =  xmlDoc.selectSingleNode("/root/id");
		var lsid = loid.text;
		var lotime = xmlDoc.selectSingleNode("/root/time");
		var lstime = lotime.text;
		var loaction = xmlDoc.selectSingleNode("/root/action");
		var lsaction = loaction.text;

		var losignstatus = xmlDoc.selectSingleNode("/root/signstatus");
		var lssignstatus = losignstatus.text;
		var lounid = xmlDoc.selectSingleNode("/root/unid");
		var lsunid = lounid.text;
		var loTable = window.TOrder;
		if(loTable!=null){
			for(var i=0;i<loTable.rows.length;i++){
				for(var j=0;j<loTable.rows[i].cells.length;j++){
					if(loTable.rows[i].cells[j].type!=lsaction) continue;
					if(loTable.rows[i].cells[j].sOrder!=lsid) continue;
					loTable.rows[i].cells[j].className = "kqSignToday" + strGetSignClass(lssignstatus);
					loTable.rows[i].cells[j].innerText = lstime;
				}
			}
		}
		if(lsstatus=="2"){
			if(lbAppeal){
				if(lsexcept!="1"){
					if (window.confirm(lsmsg)){
						OpenDocument(gsCurURL+sGetLang("DB_NAME_RSKQ")+"/frmAppeal?OpenForm&UNID="+lsunid+"&Action="+psAction);
					}
				}else {
					OpenDocument(gsCurURL+sGetLang("DB_NAME_RSKQ")+"/0/"+lsunid+"?EditDocument");
				}
			}else{
				alert(sGetLang("KQ_SIGNINDONE",lssignstatus));
			}
		}else if(lsstatus=="-1"){
			alert(lsmsg);
		}
	}
	HideViewLoading();
}

function sGetLabel(psObjectName){
	var loElement=eval("document.all."+psObjectName);
	if(typeof(loElement)!="object") return "";

	if(typeof(loElement.type)=="undefined" && typeof(loElement.length)!="undefined"){	//checkbox or radio
		loElement=loElement[0];
	}
	var loTmp=loElement;
	while(loTmp!=null){
		if (loTmp.tagName=="TR" || loTmp.tagName=="FORM") break;
		loTmp=loTmp.parentElement;
	}
	if(loTmp==null || loTmp.tagName=="FORM") return "";
	var loTr=loTmp;
	for(var i=loTr.children.length-1;i>=0;i--){
		if (loTr.children[i].outerHTML.toLowerCase().indexOf(loElement.outerHTML.toLowerCase())!=-1) break;
	}
	if(--i<0) return "";
	var lsLabel=loTr.children[i].innerText;
	if(lsLabel!="") return(lsLabel.replace(/[:£º]$/,""));
	
	var loTd=loTr.children[i];
	for(var i=loTd.children.length-1;i>=0;i--){
		if (loTd.children[i].tagName=="INPUT" && loTd.children[i].value!="") break;
	}
	if(i<0) return "";
	return(loTd.children[i].value.replace(/[:£º]$/,""));	
}
//----------------
var gsErrorMsg="";
var goErrorObj;
var giErrorCount=0;
//----------------
function bValidNull(psFields,pbNoPrompt){
	if(psFields==null || psFields=="") return true;
	if(psFields.indexOf(";")!=-1){
		var lsSeparator=";";
	}else if(psFields.indexOf(",")!=-1){
		var lsSeparator=",";
	}
	var lvFields=psFields.split(lsSeparator);
	for(i=0;i<lvFields.length;i++){
		try{
			var loField=eval("document.all."+lvFields[i]);
			if(typeof(loField)=="object"){
				if(typeof(loField.type)=="undefined" && typeof(loField.length)!="undefined"){
					var lbDisplay = false;
					for (var n = 0; n <loField.length; n++){
						if (loField[n].offsetWidth!=null && loField[n].offsetWidth>0) lbDisplay=true;
						if(loField[n].checked==true)break;
					}
					if(n>=loField.length && lbDisplay==true){
						if (pbNoPrompt==true){
							gsErrorMsg+="\n"+(++giErrorCount)+"."+sGetLang("P_SELECTVALUE",sGetLabel(lvFields[i]));
							if(goErrorObj==null)goErrorObj=loField[0];
						}else{
							alert(sGetLang("P_SELECTVALUE",sGetLabel(lvFields[i])));
							loField[0].focus();
							return false;
						}
					}
				}else{
					if (loField.offsetWidth==null || loField.offsetWidth<=0) continue;
					if(loField.value==""){
							if (pbNoPrompt==true){
								gsErrorMsg+="\n"+(++giErrorCount)+"."+sGetLang("P_INPUTVALUE",sGetLabel(lvFields[i]));
								if(goErrorObj==null)goErrorObj=loField;
							}else{
								alert(sGetLang("P_INPUTVALUE",sGetLabel(lvFields[i])));
								loField.focus();
								return false;
							}
					}
				}
			}
		}catch(e){
			alert(sGetLang("P_INVALIDOBJECT",lvFields[i]));
		}			
	}
	return true;
}

function bValidNumber(psFields,pbNoPrompt){
	if(psFields==null || psFields=="") return true;
	if(psFields.indexOf(";")!=-1){
		var lsSeparator=";";
	}else if(psFields.indexOf(",")!=-1){
		var lsSeparator=",";
	}
	var lvFields=psFields.split(lsSeparator);
	for(i=0;i<lvFields.length;i++){
		try{
			var loField=eval("document.all."+lvFields[i]);
			if(typeof(loField)=="object"){
				if (loField.offsetWidth==null || loField.offsetWidth<=0) continue;
				if (pbNoPrompt==true){
					if(bIsDigital(loField.value,3,"")==false){
						gsErrorMsg+="\n"+(++giErrorCount)+"."+sGetLang("P_INVALIDVALUE",sGetLabel(lvFields[i]));
						if(goErrorObj==null)goErrorObj=loField;
					}
				}else{
					if(bIsDigital(loField.value,3,sGetLang("P_INVALIDVALUE",sGetLabel(lvFields[i])))==false){
						loField.focus();
						return false;
					}
				}
			}
		}catch(e){
			alert(sGetLang("P_INVALIDOBJECT",lvFields[i]));
		}			
	}
	return true;	
}
function bValidDate(psFields,pbNoPrompt){
	if(psFields==null || psFields=="") return true;
	if(psFields.indexOf(";")!=-1){
		var lsSeparator=";";
	}else if(psFields.indexOf(",")!=-1){
		var lsSeparator=",";
	}
	var lvFields=psFields.split(lsSeparator);
	for(i=0;i<lvFields.length;i++){
		try{
			var loField=eval("document.all."+lvFields[i]);
			if(typeof(loField)=="object"){
				if (loField.offsetWidth==null || loField.offsetWidth<=0) continue;
				if(bDateTimeValid(loField.value,1)==false && bDateTimeValid(loField.value,2)==false && bDateTimeValid(loField.value,3)==false){
					if (pbNoPrompt==true){
						gsErrorMsg+="\n"+(++giErrorCount)+"."+sGetLang("P_INVALIDVALUE",sGetLabel(lvFields[i]));
						if(goErrorObj==null)goErrorObj=loField;
					}else{
						alert(sGetLang("P_INVALIDVALUE",sGetLabel(lvFields[i])));
						loField.focus();
						return false;
					}
				}
			}
		}catch(e){
			alert(sGetLang("P_INVALIDOBJECT",lvFields[i]));
		}
	}
	return true;
}

function bValidCompare(psFields,pbNoPrompt){
	if(psFields==null || psFields=="") return true;
	if(psFields.indexOf(";")!=-1){
		var lsSeparator=";";
	}else if(psFields.indexOf(",")!=-1){
		var lsSeparator=",";
	}
	var lvFields=psFields.split(lsSeparator);
	for(i=0;i<lvFields.length;i++){
		var laRet=vSplitMatch(lvFields[i]);
		if(laRet!=null){
			var lsLeftLabel=laRet[1];
			try{
				var loLeft=eval("document.all."+laRet[1]);
				if(typeof(loLeft)=="object"){
					var lsLeft="document.all."+laRet[1]+".value";
					var lsLeftLabel=sGetLabel(laRet[1]);
				}
			}catch(e){
				var lsLeft=laRet[1];
			}

			var lsRightLabel=laRet[3];
			try{
				var loRight=eval("document.all."+laRet[3]);
				if(typeof(loRight)=="object"){
					var lsRight="document.all."+laRet[3]+".value";
					var lsRightLabel=sGetLabel(laRet[3]);
				}
			}catch(e){
					var lsRight=laRet[3];
			}
			try{
				if(eval(lsLeft+laRet[2]+lsRight)==false){
					if (pbNoPrompt==true) gsErrorMsg+="\n"+(++giErrorCount)+"."+sGetLang("P_INVALIDCOMPARE",lsLeftLabel+laRet[2]+lsRightLabel);

					if (pbNoPrompt!=true) alert(sGetLang("P_INVALIDCOMPARE",lsLeftLabel+laRet[2]+lsRightLabel));
					if(typeof(loLeft)=="object"){
						if (pbNoPrompt==true && goErrorObj==null)goErrorObj=loLeft;
						if (pbNoPrompt!=true) loLeft.focus();
						
					}else if(typeof(loRight)=="object"){
						if (pbNoPrompt==true && goErrorObj==null)goErrorObj=loRight;
						if (pbNoPrompt!=true) loRight.focus();
					}
					if (pbNoPrompt!=true) return false;
				}
			}catch(e){
				if (pbNoPrompt==true) gsErrorMsg+="\n"+(++giErrorCount)+"."+sGetLang("P_INVALIDCOMPARE",lsLeftLabel+laRet[2]+lsRightLabel);
				
				if (pbNoPrompt!=true) alert(sGetLang("P_INVALIDCOMPARE",lsLeftLabel+laRet[2]+lsRightLabel));
				if(typeof(loLeft)=="object"){
					if (pbNoPrompt==true && goErrorObj==null)goErrorObj=loLeft;
					if (pbNoPrompt!=true) loLeft.focus();
				}else if(typeof(loRight)=="object"){
					if (pbNoPrompt==true && goErrorObj==null)goErrorObj=loRight;
					if (pbNoPrompt!=true) loRight.focus();
				}				
				if (pbNoPrompt!=true) return false;
			}
		}
	}
	return true;
}


function vSplitMatch(psExpression){
	if(psExpression == null || psExpression == "") return null;
	var laReturn,loRex;
	loRex = /(\w+)(>|<|>=|<=|==+)(\w+)/
	laReturn = psExpression.match(loRex);   
	return(laReturn);
}

function bValidServerSession(psPromptMsg){
	var xmlhttp = oGetXmlHttpRequest();
	if (xmlhttp==null) return true;
	var lsURL = encodeURI(gsOAURL)+sGetLang("DB_NAME_INDEX")+"/TestSession?open&temp=" + Math.random();
	xmlhttp.open("GET",lsURL, false);
	xmlhttp.send();
	var lsText = xmlhttp.responseText;
	if (lsText!=null && lsText.indexOf("<VALID>")!=-1 && lsText.indexOf("</VALID>")!=-1 && lsText.substring(lsText.indexOf("<VALID>")+7,lsText.lastIndexOf("</VALID>"))=="1"){
		return true;
	}else{
		if (psPromptMsg==null) psPromptMsg=sGetLang("P_CONST_SERVERSESSIONISEXPIRED");
		alert(psPromptMsg);
		return false;
	}
}

function CreateProgress(psProgress,psPromptText,psWidth,psHeight,psProgressColor,psBackgroundColor){
	if(psProgress == null) psProgress = "0%";
	if(psWidth == null) psWidth = "100";
	if(psHeight == null) psHeight = "12";
	if(psProgressColor == null) psProgressColor = "blue";
	if(psBackgroundColor == null) psBackgroundColor = "green";
	if(psPromptText == null) psPromptText = psProgress;
	document.write("<table style='width:" + psWidth + ";height:" + psHeight+ ";' border=0 cellpadding='0' cellspacing='0'><tr>"
		+ "<td style='width:" + psProgress + ";background-color:" + psProgressColor + ";' Title='" + psPromptText + "'></td>" 
		+ "<td style='width:" + (100-parseFloat(psProgress)) + "%;background-color:" + psBackgroundColor + ";'></td>" 
		+ "</tr></table>");
}

function dRoundDbl(pdNum,piNum){
	var liMultiple = Math.pow(10,piNum);
	return Math.round(pdNum*liMultiple)/liMultiple;
}


function CheckKQSign(pbAppealNow){
	var xmlhttp = oGetXmlHttpRequest();
	var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
	var lbAppealNow = (pbAppealNow==null)?true:pbAppealNow;
	//Auto Sign Out
	var lbSignOut = true;
	var lsURL = gsOAURL+sGetLang("DB_NAME_RSKQ")+"/agtNoReasonExcept?openagent&Type=3" + "&t="+((new Date()).valueOf());
	xmlhttp.open("GET",lsURL, false);
	xmlhttp.send('');
	xmlDoc.async = false;
	xmlDoc.loadXML(xmlhttp.responseText);
	var loNodes = xmlDoc.selectNodes("/TodayOrders/OrderOut");
	if(loNodes!=null){
		for(var i=0; i < loNodes.length; i++){
			var loNode = loNodes[i];
			var loNodeName = loNode.selectSingleNode("name");
			var loNodeID = loNode.selectSingleNode("id");	
			
			var loNodeStatus = loNode.selectSingleNode("SignOutStatus");
			if(loNodeStatus!=null){
				if(loNodeStatus.text == "1" || loNodeStatus.text == "2"){
					lbSignOut = false;
					if(confirm(sGetLang("KQ_CONFIRMAUTOSIGN"))){
						lbSignOut = true;
						KQSign("signout",loNodeID.text,lbAppealNow);
					}else{
						bSignInOut5Min(2,loNodeID.text);
					}
				}else if(loNodeStatus.text == "0"){
					lbSignOut = false;
					var loNodeTime = loNode.selectSingleNode("SignOutTime");
					var loDate = new DateExt(loNodeTime.text.substr(0,loNodeTime.text.lastIndexOf(" ")));
					var loNodeNow = loNode.selectSingleNode("Now");	
					var loDateNow = new DateExt(loNodeNow.text);
					var liTID = top.setTimeout("if(confirm(sGetLang('KQ_CONFIRMAUTOSIGN'))){KQSign('signout','"+loNodeID.text+"');}else{bSignInOut5Min(2,'"+loNodeID.text+"')}", loDate-loDateNow);
					if(typeof top.outTArray!="object") top.outTArray = new Array();
					top.outTArray[loNodeID.text] = liTID;
				}else{
					lbSignOut = true;
				}
			}
		}
	}
	
	//Auto Sign In
	var lsURL = gsOAURL+sGetLang("DB_NAME_RSKQ")+"/agtNoReasonExcept?openagent&Type=2" + "&t="+((new Date()).valueOf());
	xmlhttp.open("GET",lsURL, false);
	xmlhttp.send('');
	xmlDoc.async = false;
	xmlDoc.loadXML(xmlhttp.responseText);
	var loNodes = xmlDoc.selectNodes("/TodayOrders/OrderIn");
	if(loNodes!=null){
		for(var i=0; i < loNodes.length; i++){
			var lbSignIn = false;
			var loNode = loNodes[i];
			var loNodeName = loNode.selectSingleNode("name");
			var loNodeID = loNode.selectSingleNode("id");	
			var loNodeStatus = loNode.selectSingleNode("SignInStatus");
			if(loNodeStatus!=null){
				if(loNodeStatus.text=="0"){
					var loNodeTime = loNode.selectSingleNode("SignInTime");	
					var loDate = new DateExt(loNodeTime.text.substr(0,loNodeTime.text.lastIndexOf(" ")));
					var loNodeNow = loNode.selectSingleNode("Now");	
					var loDateNow = new DateExt(loNodeNow.text);
					var liTID = top.setTimeout("if(confirm(sGetLang('KQ_CONFIRMAUTOSIGN'))){KQSign('signin','"+loNodeID.text+"');}else{bSignInOut5Min(1,'"+loNodeID.text+"')}", loDate-loDateNow);
					if(typeof top.inTArray!="object") top.inTArray = new Array();
					top.inTArray[loNodeID.text] = liTID;
				}else if(loNodeStatus.text=="1"){
					KQSign("signin",loNodeID.text,lbAppealNow);
				}else if(loNodeStatus.text=="2" || loNodeStatus.text=="3"){
					lbSignIn = confirm(sGetLang("KQ_CONFIRMLATESIGN"));
					if(lbSignIn){
						KQSign("signin",loNodeID.text,lbAppealNow);
					}else{
						bSignInOut5Min(1,loNodeID.text);
					}
				}
			}
		}
	}
}

function bGetExceptReason(){
	var xmlhttp = oGetXmlHttpRequest();
	var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
	var lsURL = gsOAURL+sGetLang("DB_NAME_RSKQ")+"/agtNoReasonExcept?openagent&Type=1" + "&t="+((new Date()).valueOf());
	xmlhttp.open("GET",lsURL, false);
	xmlhttp.send('');
	xmlDoc.async = false;
	xmlDoc.loadXML(xmlhttp.responseText);
	var loNode = xmlDoc.selectSingleNode("/YesterdayOrders/Orders");
	if(loNode!=null){
		if(loNode.childNodes.length>0){
			var laObject = new Array();
			for(var i=0; i < loNode.childNodes.length; i++){
				var loObject = new Object;
				var loNodeName = loNode.childNodes[i].selectSingleNode("name");
				loObject.name = (loNodeName == null)?"":loNodeName.text;
				var loNodeID = loNode.childNodes[i].selectSingleNode("id");
				loObject.id = (loNodeID == null)?"":loNodeID.text;
				var loNodeDate = loNode.childNodes[i].selectSingleNode("date");
				loObject.date = (loNodeDate == null)?"":loNodeDate.text;
				var loNodeUNID = loNode.childNodes[i].selectSingleNode("SignUNID");
				loObject.UNID = (loNodeUNID == null)?"":loNodeUNID.text;
				var loNodeException = loNode.childNodes[i].selectSingleNode("Exception");
				loObject.Exception = (loNodeException == null)?"":((loNodeException.text=="")?sGetLang("KQ_NOTSIGNOUT"):loNodeException.text);
				laObject.push(loObject);
			}
			var lvReturn = vOpenModal(gsOAURL + sGetLang("DB_NAME_RSKQ") + "/frmExceptReason?OpenForm",laObject);
			if(lvReturn == null){
				Logout(3);
				return false;
			}else{
				//return true;
			}
		}
	}
}

function KQOverSign(piAction){
	var liAction = (piAction=="signin"||piAction==1)?1:2;
	var xmlhttp = oGetXmlHttpRequest();
	var xmlDoc = new ActiveXObject("Msxml2.DOMDocument"); 
	var lsURL = gsOAURL+sGetLang("DB_NAME_RSKQ")+"/agtOverAjax?openagent&Type=1&Action="+liAction+"&t="+((new Date()).valueOf());
	xmlhttp.open("GET",lsURL, false);
	xmlhttp.send('');
	
	xmlDoc.async = false;
	xmlDoc.loadXML(xmlhttp.responseText);
	var loNode = xmlDoc.selectSingleNode("/Result");
	if(loNode.text!="0"){
		if(liAction==1){
			if(confirm(sGetLang("KQ_CONFIRMOVERIN"))){
				var lsURL = gsOAURL+sGetLang("DB_NAME_RSKQ")+"/agtOverSign?openagent&Action=1&t="+((new Date()).valueOf());
				xmlhttp.open("GET",lsURL, false);
				xmlhttp.send('');
			}
		}else{
			bNewWork("","PMI_XZSW_JBDJ");
		}
		return false;	
	}
	return true;
}

function bSignInOut5Min(piAction,psOrderID){
	var liTID = top.setTimeout("if(confirm(sGetLang('KQ_CONFIRMAUTOSIGN'))){KQSign('"+((piAction==1)?"signin":"signout")+"','"+psOrderID+"');}else{bSignInOut5Min("+piAction+",'"+psOrderID+"');}", 5*60*1000);
	if(piAction==1){
		if(typeof top.inTArray!="object") top.inTArray = new Array();
		top.inTArray[psOrderID] = liTID;
	}else{
		if(typeof top.outTArray!="object") top.outTArray = new Array();
		top.outTArray[psOrderID] = liTID;
	}
}

function DateExt(psValue){
	var loNow = new Date();
	if(psValue==null) return loNow;
	var strDate = psValue;
	if (strDate.length == 0) return loNow;
	var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})/; 
	var r = strDate.match(reg);
	
	if (r != null) strDate = strDate + " 00:00:00";
 	
 	reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2})/;
	var r = strDate.match(reg);
	if (r != null) strDate = strDate + ":00";
 	
	reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})/;
	r = strDate.match(reg);
	if (r == null)	return null;

 	var d = new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
	if (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()== r[7])
		return d;
	else	return null;
}

function bCheckRockey(psUserName){
	var lsUserName = (psUserName==null)?gsCurUser:psUserName;
	var loRockey = new CRockey();
	return loRockey.bVertifyUser(lsUserName);
}

function CRockey(poRockey){
	this.oRockey = poRockey;
	if(null==this.oRockey){
		this.oRockey = document.createElement('<OBJECT ID="ePass" style="display:none" WIDTH=300 HEIGHT=70 CLASSID="clsid:E1D396DC-D064-4846-8B50-A3301BDD6243" codebase="/icons/icons/epass.cab#version='+P_CONST_ROCKEYVERSION+'">');
		document.body.appendChild(this.oRockey);
		this.oRockey = document.getElementById("ePass");
	}
	this.sSerialNum = "";
	this.sRndData = "";
	this.sDigest = "";
	this.sPrvDigest = "";
	
	this.sGetRandom = function(){
		var lsRndData = "";
		var liMax = "z".charCodeAt(0);
		var liMin = "a".charCodeAt(0);
	
		for(i = 0 ; i < 20 ; i++ ){
			lsRndData += String.fromCharCode(Math.floor((liMax-liMin)*Math.random() + liMin));
		}
		return(lsRndData);
	}
	this.sRndData = this.sGetRandom();
	
	this.HexToDec = function(psHex) {
	   psHex += ""
	   if (psHex == "") {return 0;}
	   var L=psHex.length;
	   var k=0;
	   var r=0;
	   var r1=0;
	   while (k<L) {
	      r1 = iToDec(psHex.substr(k,1));
	      r1 *= Math.pow(2,(L-k-1)<<2);
	      r += r1;
	      k += 1;  
	   }
	   return r;
	}
	
	this.iToDec = function(psSource) {
		if (psSource >= "0" && psSource <= "9") {return (psSource-0);}
		if (psSource.toUpperCase() == "A") {return 10;}
		if (psSource.toUpperCase() == "B") {return 11;}
		if (psSource.toUpperCase() == "C") {return 12;}
		if (psSource.toUpperCase() == "D") {return 13;}
		if (psSource.toUpperCase() == "E") {return 14;}
		if (psSource.toUpperCase() == "F") {return 15;}
	}
	
	this.bVertifyPIN = function(psUserName,pbReset){
		var lbReset = (pbReset == null)?true:pbReset;
		if(typeof this.oRockey != "object") return false;
		try{
			this.oRockey.OpenDevice(1,"");
		}catch(e){
			return false;
		}
		try{
			this.oRockey.VerifyPIN( 0, psUserName.toLowerCase());
		}catch(e){
			var lsShort = this.sGetShortName(psUserName);
			if(lsShort != psUserName){
				try{
					this.oRockey.VerifyPIN( 0, lsShort.toLowerCase());
				}catch(e){
					this.oRockey.ResetSecurityState(0);
					this.oRockey.CloseDevice();
					return false;
				}
			}else{
				this.oRockey.ResetSecurityState(0);
				this.oRockey.CloseDevice();
				return false;
			}
		}
		if(lbReset){
			try{
				this.oRockey.ResetSecurityState(0);
			}catch(e){
				this.oRockey.CloseDevice();
				return false;
			}
		}
		this.oRockey.CloseDevice();
		return true;
	}
	
	this.sGetShortName = function(psUserName){
		var xmlhttp = oGetXmlHttpRequest();
		if(xmlhttp==null) return psUserName;
		var lsURL = encodeURI(gsOAURL) +"zSysRes.nsf/agtCheckRockey?openagent";
		lsURL += "&t="+((new Date()).valueOf());
		var lsPara = "&Type=1";
		lsPara += "&UserName=" + escape(psUserName);
		xmlhttp.open("POST",lsURL, false);
		xmlhttp.send(lsPara);
		var xmlDoc = xmlhttp.responseXML;
		if(null==xmlDoc) return psUserName;
		var lonode = xmlDoc.selectSingleNode("/root/user");
		if(null ==lonode) return psUserName;
		return lonode.text;
	}
	
	this.bInitData = function(psUserName){
		if(typeof this.oRockey != "object") return false;
		if(!this.bVertifyPIN(psUserName,false)) return false;
		try{
			this.oRockey.OpenDevice(1,"");
		}catch(e){
			this.oRockey.CloseDevice();
			return false;
		}
		try{
			this.sSerialNum = this.oRockey.GetStrProperty(7,0,0);
		}catch(e){
			this.oRockey.CloseDevice();
			return false;
		}
		try{
			this.oRockey.ChangeDir(768,0,"WELLSOFT");
		}catch(e){
			this.oRockey.CloseDevice();				
			return false;
		}
		try{
			this.oRockey.OpenFile(0,1);
		}catch(e){
			this.oRockey.CloseDevice();
			return false;
		}
		try{
			this.sDigest = this.oRockey.HashToken(1,2,this.sRndData);
		}catch(e){
			this.oRockey.CloseDevice();
			return false;
		}
		try{
			this.oRockey.OpenFile(0,3);
		}catch(e){
			this.oRockey.CloseDevice();
			return false;
		}
		try{
			this.sPrvDigest = this.oRockey.HashToken(1,4,this.sRndData);
		}catch(e){
			this.oRockey.CloseDevice();
			return false;
		}
		
		try{
			this.oRockey.ResetSecurityState(0);
		}catch(e){
			this.oRockey.CloseDevice();
			return false;
		}
		this.oRockey.CloseDevice();
		return true;
	}
	
	this.bVertifyUser = function(psUserName){
		if(typeof this.oRockey != "object") return false;
		var lbAgain = false;
		do{
			lbAgain = false;
			if(!this.bVertifyPIN(psUserName)){
				if(confirm(sGetLang("SYSRES_CONFIRMINSERTROCKEY"))){
					lbAgain = true;
				}else{
					return false;
				}
			}
		}while(lbAgain);
		if(!this.bInitData(psUserName)) return false;
		return this.bServerVertify(psUserName,2);
	}
	
	this.bServerVertify = function(psUserName,piType){
		var xmlhttp = oGetXmlHttpRequest();
		if(xmlhttp==null) return "";
		var lsURL = encodeURI(gsOAURL) +"zSysRes.nsf/agtCheckRockey?openagent";
		lsURL += "&t="+((new Date()).valueOf());
		var lsPara = "";
		if(piType==1){
			lsPara += "&Type=2";
			lsPara += "&SerialNum=" + this.sSerialNum;
		}else{
			lsPara += "&Type=3";
			lsPara += "&Random=" + this.sRndData;
			lsPara += "&Digest=" + this.sDigest;
			lsPara += "&PrvDigest=" + this.sPrvDigest;
			lsPara += "&SerialNum=" + this.sSerialNum;
		}
		xmlhttp.open("POST",lsURL, false);
		xmlhttp.send(lsPara);
		var xmlDoc = xmlhttp.responseXML;
		if(null==xmlDoc) return false;
		var lonode = xmlDoc.selectSingleNode("/root/valid");
		if(null==lonode) return false;
		if(lonode.text=="1") return true;
		else return false;		
	}
}
function oGetMembersByKey(psUnit,psKey){
	var loObject = new Object();
	loObject.users = "";
	loObject.exclude = "";
	var xmlhttp = oGetXmlHttpRequest();
	if (xmlhttp==null) return loObject;
	
	var lsURL = gsOAURL + sGetLang("DB_NAME_UNITADM") +"/agtGetMebmersByKey?openagent";
	lsURL += "&t="+((new Date()).valueOf());
	xmlhttp.open("POST",lsURL, false);
	var lsPara = "&Unit="+escape(psUnit);
	lsPara += "&Key="+escape(psKey);
	xmlhttp.send(lsPara);
	var xmlDoc = xmlhttp.responseXML;
	if(null==xmlDoc) return loObject;
	
	var lonode = xmlDoc.selectSingleNode("/root/user");
	if(null!=lonode){
		loObject.users = lonode.text;
	}
	var lonode = xmlDoc.selectSingleNode("/root/exclude");
	if(null!=lonode){
		loObject.exclude = lonode.text;
	}
	return loObject;
}

function sGetUserInform(psUserName,psItemName){
	var lsUserName = (psUserName==null)?gsCurUser:psUserName;
	var xmlhttp = oGetXmlHttpRequest();
	if (xmlhttp==null) return "";
	
	var lsURL = gsOAURL + sGetLang("DB_NAME_UNITADM") +"/agtGetUserInform?openagent";
	lsURL += "&t="+((new Date()).valueOf());
	xmlhttp.open("POST",lsURL, false);
	var lsPara = "&User="+escape(lsUserName);
	lsPara += "&Item="+psItemName;
	xmlhttp.send(lsPara);
	var xmlDoc = xmlhttp.responseXML;
	if(null==xmlDoc) return "";
	
	var lonode = xmlDoc.selectSingleNode("/root/value");
	if(null!=lonode){
		return lonode.text;
	}
	return "";
}

function bSearchAddress(){
	var lins=(window.Event)?1:0;
	var licode=(lins)?e.which:event.keyCode;
	if(licode!="13") return true;
	
	var loInput = event.srcElement;
	var lsFilter = (loInput.value.indexOf(",")!=-1)?loInput.value.substr(loInput.value.lastIndexOf(',')+1):loInput.value;
	if(lsFilter=="") return true;
	var lsServicePath = "/servlet/selectpeople?Open&Action=1&Scope=1&Filter1="+lsFilter;
	var xmlhttp = oGetXmlHttpRequest();
	if (xmlhttp==null) return null;
	xmlhttp.open("GET",lsServicePath, false);
	xmlhttp.send('');
	var loXml = new ActiveXObject("Microsoft.XMLDOM");
	loXml.async = false;
	loXml.validateOnParse = false;
	var lbReturn = loXml.loadXML(xmlhttp.responseText); 
	if(!lbReturn) return null;
	var objNodeList = loXml.documentElement.childNodes;
	var lsReturn = "";
	if(objNodeList.length!=0){
		if(objNodeList.length > 1){
			lsReturn = sSelectArray("MailMultiple",sGetLang("MAIL_TITLESELADDR"),sGetLang("MAIL_PROMPTSELADDR"),xmlhttp.responseText);
		}else{
			lsReturn = objNodeList[0].childNodes[0].text;
		}
		if(lsReturn!=null){
			var lsTempValue = loInput.value.substr(0,loInput.value.lastIndexOf(","));
			if(lsTempValue!="") lsTempValue += ",";
  			loInput.value = lsTempValue + lsReturn;
		}
	}
	loInput.value += ",";
	return false;
}

function bSetHomePage(){
	
	return true;
}



