﻿//Cac ham dung chung

var globalClientWidth = chkRezWidth();

function chkRezWidth() {

	var w = screen.width;
	// translate detected width and return index
	if (w < 800) return 0;
	else if (800 == w) return 1;
	else if (1024 == w) return 2;
	else if (1024 < w) return 3;
	else return -1; // did not exit above
}





function openAppHelp(){
	var helpFilePath = "Help/WebHelp/index.htm"
	var url = getApplicationURL()+ helpFilePath;
	if (helpFilePath.search(".htm")==-1){
		//url= getApplicationURL()+"DMS/HTTPDownloader.asp?physicalPath=" +encodeURI(url)
	}
	openWindow(url, screen.availWidth,screen.availHeight);
}

function LoadCombo(objComboBox, fromValue, toValue, defaultValue, prefixValue){

	defaultValue = (new String("00000000000000")).substr(0,(toValue+"").length - (defaultValue+"").length) + defaultValue;
	if(arguments[4] != undefined){
		defaultValue = arguments[4] + defaultValue;
	}

	for (var i = fromValue; i <= toValue; i++ ){
		var oOption = document.createElement("OPTION");
		oOption.text=(new String("00000000000000")).substr(0, (toValue+"").length - (i+"").length) + i;
		if(arguments[4] != undefined){
			oOption.value = arguments[4] + (new String("00000000000000")).substr(0, (toValue+"").length - (i+"").length) + i;
		}else{
			oOption.value = (new String("00000000000000")).substr(0, (toValue+"").length - (i+"").length) + i;
		}

		if (defaultValue == oOption.value){
			oOption.selected = true;
		}
		objComboBox.add(oOption);
	}
}

///////////////////////////////////////////////////////////
//-------------------------------------------------------//
//		 Created by Le Quang Minh, date 29/08/2006		 //
//-------------------------------------------------------//
///////////////////////////////////////////////////////////
function LoadingComboGio(objCombo,startValue,defaultValue){
	var strValues = "", arrValues = new Array();
	var i, oOption;
	
	for (i=0; i<=23; i++){
		if (i<10){
			strValues = strValues + "0" + i + ":00" + ";";
			strValues = strValues + "0" + i + ":15" + ";";
			strValues = strValues + "0" + i + ":30" + ";";		
			strValues = strValues + "0" + i + ":45" + ";";							
			continue;
		}
		strValues = strValues + i + ":00" + ";";
		strValues = strValues + i + ":15" + ";";
		strValues = strValues + i + ":30" + ";";		
		strValues = strValues + i + ":45" + ";";
	}	
	strValues = strValues.substr(0,strValues.length-1);
	arrValues = strValues.toString().split(";");
	//
	if (startValue != ""){
		with (objCombo){
			while (options.length > 0){
				options.remove(0);
			}	
		}
	}
	//
	for (i=0;i<=arrValues.length-1;i++){
		if (startValue != ""){
			if (startValue != arrValues[i]){
				continue;
			}
			else{
				startValue = "";
				continue;
			}
		}
		//
		oOption = document.createElement("OPTION");
		with (oOption){
			text = arrValues[i];
			value = arrValues[i];
			if (defaultValue == value){
				selected = true;
			}
		}
		objCombo.add(oOption);
	}
}//////////////////////////////////////////////////////////


function ViewQuickSearch(obj){	

	var ViewID = document.all.item("ViewID").value;	
	var strURL = getApplicationURL()+ "Search/search.asp?ViewID=" + ViewID +"&ViewType=4&isQuickSearch=true";
	openNewWindowInDIV(strURL)
	return;
}

//-------------------------------------------------------------
//Added by lqminh, date 13/11/2007
//-------------------------------------------------------------
function ShowQuickRecall(){
	var strURL = getApplicationURL() + "DMS/Recall.asp?isQuickRecall=true";
	openNewWindowInDIV(strURL);
	
	return;
}//{End: Added by lqminh, date 13/11/2007}
//-------------------------------------------------------------

//Them thong bao cho nhung nguoi xu ly van ban hien tai
function ViewHistory(obj){	
	var DocumentID = document.all.item("DocumentID").value;	
	var ProcessInstanceID = document.all.item("ProcessInstanceID").value;
	var strURL = getApplicationURL()+ "WFS/Wfi/HistoryViewer.asp?ProcessInstanceID="+ProcessInstanceID+"&DocumentID="+DocumentID
	openNewWindowInDIV(strURL);
	SetHeight();
	return;
}

function openNewWindowInDIV(url){
	var objDocument = document;
	var divName = "DetailDocumentDIV";
	if (arguments[1] != undefined){
		divName = arguments[1];
	}
	if (arguments[2] != undefined){
		var target = arguments[2];
		objDocument = window.frames(target).document;
	}
	//var objDetailDocument = document.getElementById(divName);
	var objDetailDocument = objDocument.getElementById(divName);
	if (objDetailDocument == null){
		//objDetailDocument = document.createElement("DIV");
		objDetailDocument = objDocument.createElement("DIV");
		objDetailDocument.id = divName;
		objDetailDocument.name = divName;
		objDetailDocument.style.position = "absolute";
		objDetailDocument.style.top = 0;
		objDetailDocument.style.left = 0;
		objDetailDocument.style.width = "100%";
		//document.body.appendChild(objDetailDocument);
		objDocument.body.appendChild(objDetailDocument);
	}
	
	objDetailDocument.style.display="inline";	
	
	ShowLoading();
	showIframe(url, objDetailDocument);
	HideLoading();
}

function closeWindowInDIV(){
try{
	var objIframe;
	var objWindow = window;
	var objDiv;
	var i = 0;
	while(i <100 ) { // nccong Xu ban
		objWindow = objWindow.parent ;
		objIframe = objWindow.document.getElementsByTagName("IFRAME");
		for (var j = 0; j < objIframe.length ; j++){
			if (objIframe[j].id.search("_iframe") != -1){
				objDiv = objIframe[j].parentElement;
				break;
			}
		}
		if (objDiv != undefined){
			break;
		}
	i++;
	} 
	
	if (objDiv.tagName == "DIV"){
			objDiv.style.display="none";
			try{
				objDiv.parentElement.removeChild(objDiv);
			}catch(e){}			
	}
}catch(e){}			
	//return;
	/*
	try{
		var objDIV = parent.document.all.item(window.name);
		if (objDIV){
			if (objDIV.id.search("_iframe") == -1){
				objDIV = objDIV.parentElement;	
			}
		}

		if (objDIV.tagName == "DIV"){
			objDIV.style.display="none";
			try{
				objDIV.parentElement.removeChild(objDIV);
			}catch(e){}			
			return true;
		}
	}catch(e){
				return false;
			}
	return false;*/
}


//Add by Phan Manh Ha
//Nhin thi biet
function trimString(inputString){
	var str = new String();		
	str = inputString;
	if (str=="") return "";
	while (str.charAt(0) == " ") str = str.substring(1, str.length);
	while (str.charAt(str.length-1) == " ") str = str.substring(0, str.length-1);
	return str;
}

//Lay gia tri cua truong thuoc tinh co kieu hien thi la eDOCmanMultiCheck
function getMultiCheckValue(obj){
	var s = new String();
	s = obj.name;	
	s = s.replace("_eDOCmanMultiCheck","");
	s = document.all.item(s).value;
	//alert(s);
	if (s == undefined) s = "";	
	if (s != "") s = s.split(";_____")[1];		
	if (s == undefined) s = "";
	//alert(s);			
	return s;
}

//Add by Phan Manh Ha
//Them thong bao cho nhung nguoi xu ly van ban hien tai
function AddMessage(obj){
	var Message = "";
	if (arguments[1] != undefined){
		Message = arguments[1];		
	}
	if (Message=="") Message = "Văn bản có sự sửa đổi";
	var DocumentID = document.all.item("DocumentID").value;
	var DocTypeID = document.all.item("ViewID").value;	
	
	var url= getApplicationURL() + "Common/AjaxProcess/ajax.asp"
	var query = "TypeProcess=AddMessage&DocumentID=" + encodeURI(DocumentID) + "&DocTypeID="+ encodeURI(DocTypeID) + "&Message="+ encodeURI(Message);
		
	ajaxpack.postAjaxRequest(url,query,function(){
		var req = ajaxpack.ajaxobj;
		var myfiletype = ajaxpack.filetype;	
		if (req.readyState==4){		
		   if (req.status==200 || window.location.href.indexOf("http")==-1){
				if (myfiletype=="txt"){				
					ret = req.responseText;	
					if (ret != undefined){
						MsgBox(ret);
						try{
							obj.disabled=true;
						}catch(e){}
					}				
				}else {				
				}
			}
		}
	},"txt");
	return;
}

//---------------------------------------------------------------------------------

/**Add by PmHa
/*Them doclink
*/
function AddDocLink(obj, DocSpaceIDs){	
	
	
	var AddSrcDocToSelectedDocsFlag = arguments[2];	
	if (AddSrcDocToSelectedDocsFlag == undefined) AddSrcDocToSelectedDocsFlag = true;
	var objForm = obj;		
	while (objForm.tagName != "FORM") objForm = objForm.parentElement;
	if (document.all.item("frameAddDocLink")==null){
		objForm.appendChild(document.createElement("<IFrame name=frameAddDocLink id =frameAddDocLink style='display:none'></iframe>"));
	}
	var documentID="";
	try{
		documentID = document.all.item("DocumentID").value;		
	}catch(e){
		documentID = document.all.item("strSourceDocumentID").value;		
	}
	
	var ActivityInstanceID="";
	try{
		ActivityInstanceID = parent.document.all.item('ActivityInstanceID').value;
	}catch(e){}

	var ProcessInstanceID="";
	try{
		ProcessInstanceID = parent.document.all.item('ProcessInstanceID').value;
	}catch(e){}
	
	//var strURL= getApplicationURL()+ "/DMS/AddDocumentLink.asp?strDocSpaceIDs=" + DocSpaceIDs + "&strDocumentID=" + documentID + "&DocBrowse=true&AddSrcDocToSelectedDocsFlag="+AddSrcDocToSelectedDocsFlag+"&ProcessInstanceID="+ProcessInstanceID + "&ActivityInstanceID="+ActivityInstanceID;
	//window.open(strURL,"frameAddDocLink");
	
	//Updated by Le Quang Minh, date 19/09/2006
	//-----------------------------------------
	
		

	try{
		with (document.all){
			
			
			var strDocumentTypeID = item("txtDocType").value;
			
			
			var strResult = window.showModalDialog("../Common/CommonDialog/Dialog.asp?strURL=" + escape("DocBrowse.asp?strDocSpaceIDs=" + DocSpaceIDs + "&strDocumentTypeID=" + strDocumentTypeID + "&multiSelect=true&showDocumentList=true&showFolderList=false&DocBrowse=true"), 0 , "resizable:no;dialogWidth:630px;dialogHeight:580px;status:no");
			
			
			if (strResult == undefined) strResult = ""
			if (strResult != ""){
				item("strAction").value = "AddDocLink";
				
				AddHiddenItem(document.all.item('strAction'), "strDocumentLinkIDs",strResult);
				AddHiddenItem(document.all.item('strAction'), "ProcessInstanceID",ProcessInstanceID);
				AddHiddenItem(document.all.item('strAction'), "AddSrcDocToSelectedDocsFlag",AddSrcDocToSelectedDocsFlag);
				
				item("frmDocViewer").submit();
			}
			else
				item("strAction").value = "";
		}
	}catch(e){}//{End: Updated by Le Quang Minh, date 19/09/2006}
	/////////////------------------------------------------------				
}

//---------------------------------------------------------------------------------
/**Add by PmHa
/*Lam an thuoc tinh tren view??
*/
function HiddenMe(obj){
	var objTR = obj;
	while (objTR.tagName != "TR") objTR = objTR.parentElement;
	objTR.style.display= "none";
}

//---------------------------------------------------------------------------------
/**Add by PmHa
/*Kiem tra chuoi str la co chua ky tu dac biet khong??
*/
function isSpecialString(str){
	str = new String(str);
	for (var i = 0; i <str.length; i++){
		if ((str.charCodeAt(i) < 32)||(str.charCodeAt(i) > 127)){
			return true;
			break;
		}
	}
	return false;
}
/**Add by Phan Manh Ha*/
function ValidFileUpload(filePath){
	var DeniedFilesList = "exe,msi,avi,wmv,dat,asp,aspx,php,jsp,cgi,dll,com,bat,sys";
	var ext = filePath.substring(filePath.indexOf(".",1)+1,filePath.lenght);
	if (DeniedFilesList.search(ext) == 0) return false;
	
	if (GetFileSize(filePath)<=0) return false;
	
	if (isSpecialString(filePath)) return false;
	
	return true;
}
/**Add by Phan Manh Ha*/
function GetFileSize(strFile){
	var fso = new ActiveXObject("Scripting.FileSystemObject");	
	try{
		var f = fso.GetFile(strFile)
	}catch(e){
		return -1;
	}
	
	return (f.size/1024/1024);//MB 
}



/*dung1.add*/
function Reload(){
	window.location.reload(true);
}
function ResetForm() {	

	var elementCount;
	var i;
	var _obj;
	var _type = new String();
	var _name = new String();
	/*input type='text'*/
	var arrObj = document.getElementsByTagName('input');
	
	elementCount = 0;
	if (arrObj.length > 0 && arrObj.length != undefined)
		elementCount = arrObj.length; 
	if (elementCount == 0)
		arrObj.value = "";
	else {
		for(i=0;i<elementCount;i++) {
			_obj = arrObj[i];
			_type = _obj.type;
			_name = _obj.name;
			_name = _name.toLowerCase();
			if((_type.toLowerCase()=="text") && (_name.search("_type") == -1))
				_obj.value="";
		}	
	}
	/*textarea*/
	arrObj = document.getElementsByTagName('textarea');
	
	elementCount = 0;
	if (arrObj.length > 0 && arrObj.length != undefined)
		elementCount = arrObj.length; 
	if (elementCount == 0)
		arrObj.value = "";
	else {
		for(i=0;i<elementCount;i++) {
			_obj = arrObj[i];
			_obj.value="";
		}	
	}
	
	/*combobox*/
	arrObj = document.getElementsByTagName('select');
	
	elementCount = 0;
	if (arrObj.length > 0 && arrObj.length != undefined)
		elementCount = arrObj.length; 
	if (elementCount == 0)
		arrObj.value = "";
	else {
		for(i=0;i<elementCount;i++) {
			_obj = arrObj[i];
			_obj.value="";
		}	
	}

	/*display for suggest box*/
	arrObj = document.getElementsByTagName('div');
	
	elementCount = 0;
	if (arrObj.length > 0 && arrObj.length != undefined)
		elementCount = arrObj.length; 
	if (elementCount == 0){
			_name = arrObj.name;
			_name = _name.toLowerCase();
			if (_name.search("_display") != -1)
				arrObj.innerHTML = "";
	}
	else {
		for(i=0;i<elementCount;i++) {
			_obj = arrObj[i];
			_name = _obj.id;
			if (_name != undefined) {
				_name = _name.toLowerCase();
				if (_name.search("_display") != -1)
					_obj.innerHTML = "";
			}
		}	
	}
	

}

function ResetForm_Search(){
	document.all.item("strAction").value='Reset';
	document.frmSearch.method='post';
	document.frmSearch.submit();
}

//Ham thuc hien tu dong lay so ky hieu theo objSodi, objLoaiVB, objDVST (So di, loai vb, don vi soan thao)
function FixSoKH(objSodi, objLoaiVB, objDVST, objFixed, objQPPL){
	var ret = "";
	var PropertyItemName= "Ký hiệu";
	var SelectedItemID = objLoaiVB.name;
	var SelectedItemValue = objLoaiVB.value;
	var url= getApplicationURL() + "Common/AjaxProcess/ajax.asp"
	var query = "TypeProcess=GetKH&PropertyItemName=" + encodeURI(PropertyItemName) +"&SelectedItemID="+ encodeURI(SelectedItemID) +"&SelectedItemValue="+ encodeURI(SelectedItemValue);	
	//alert(url)
	ajaxpack.getAjaxRequest(url,query,function(){
		var req = ajaxpack.ajaxobj;
		var myfiletype = ajaxpack.filetype;	
		if (req.readyState==4){		
		   if (req.status==200 || window.location.href.indexOf("http")==-1){
				if (myfiletype=="txt"){				
					ret = req.responseText;	
					if (ret != undefined){
						FixSoKH_FrontEnd(objSodi, objLoaiVB, objDVST, objFixed, ret, objQPPL);
						try{
							objFixed.onchange();						
						}catch(e){}
					}				
				}else {				
				}
			}
		}
	},"txt");
	var req = ajaxpack.ajaxobj;
	var myfiletype = ajaxpack.filetype;	
}

function FixSoKH_FrontEnd(objSodi, objLoaiVB, objDVST, objFixed, loaiVB, objQPPL){
	var bIsDonvi;
	
	bIsDonvi = true;
	
//	try{
//		if (objQPPL != undefined){
//			bIsDonvi = false;
//			
//			if (objQPPL.checked){
//				objFixed.value = objSodi.value + "/" + (new Date()).getFullYear() + "/" + loaiVB +"-BTC";
//				return;
//			}
//		}
//	}catch(e){}
	
	//if (loaiVB.search("QP") !=-1){		
	//	objFixed.value = objSodi.value + "/" + (new Date()).getFullYear() + "/" + loaiVB +"-BTC";
	//	
	//	return;
	//}
	
//	if (loaiVB.search("CV") !=-1){
		var ret = "";
		var SelectedItemValue = objDVST.value;
		var url= getApplicationURL() + "Common/AjaxProcess/ajax.asp"
		var query = "TypeProcess=GetGroupSymbol&IsDonvi="+ bIsDonvi +"&GroupName="+ encodeURI(SelectedItemValue);	
		ajaxpack.getAjaxRequest(url,query,function(){
			var req = ajaxpack.ajaxobj;
			var myfiletype = ajaxpack.filetype;	
			if (req.readyState==4){		
			   if (req.status==200 || window.location.href.indexOf("http")==-1){
					if (myfiletype=="txt"){				
						ret = req.responseText;	
						if (ret == undefined) ret = "";
						if (!bIsDonvi){
							//objFixed.value = objSodi.value + "/BTC-" + ret;
						}else{
							objFixed.value = objSodi.value + "/So TTTT-QT/" + ret;
						}
						return;						
					}else {				
					}
				}
			}		
		},"txt");
//		if (!bIsDonvi){
//			objFixed.value = objSodi.value + "/BTC-" + "";
//		}else{
//			objFixed.value = objSodi.value + "/" + "";
//		}
//		return;		
//	}
	
//	if (!bIsDonvi){
//		objFixed.value = objSodi.value + "/" + loaiVB + "-BTC";
//	}else{
//		objFixed.value = objSodi.value + "/" + loaiVB + "";
//	}

}

//-------------------------------------------------------------------------------------
//Added by lqminh, date 17/08/2007
//-------------------------------------------------------------------------------------
function GetAllValues(objDocType, objSodi, objSoKH, objDVST){
	try{
		GetNextNumValue(objDocType, objSodi);
		GetSoKH(objDocType, objSodi, objSoKH, objDVST);
	}catch(e){}
}//{End: Added by lqminh, date 17/08/2007}
//-------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------
//Added by lqminh, date 07/08/2007
//-------------------------------------------------------------------------------------
function GetSoKH(objDocType, objSodi, objSoKH){
	try{
		try{
			var DocumentTypeID = objDocType.item(objDocType.selectedIndex).value;
		}catch(e){
			var DocumentTypeID = document.all.item("ViewID").value;
		}
	
		switch (DocumentTypeID){
			case "c75fab56-e69e-431b-a976-324dfc1e8b01":	//Thong tu
			  objSoKH.value = objSodi.value + "/" + (new Date()).getFullYear() + "/TT/BTC";
			  break;
			case "e45660e8-8dae-432e-91ca-d45f00ee0747":	//Quyet dinh QPPL
			  objSoKH.value = objSodi.value + "/" + (new Date()).getFullYear() + "/QĐ/BTC";
			  break;
			default:
			  var objDVST = arguments[3];
			  if (objDVST != undefined){
				var ret = "";
				var SelectedItemValue = objDVST.value;
				var url= getApplicationURL() + "Common/AjaxProcess/ajax.asp"
				var query = "TypeProcess=GetGroupSymbol&IsDonvi=false&GroupName="+ encodeURI(SelectedItemValue);	
				ajaxpack.getAjaxRequest(url,query,function(){
					var req = ajaxpack.ajaxobj;
					var myfiletype = ajaxpack.filetype;	
					if (req.readyState==4){		
					   if (req.status==200 || window.location.href.indexOf("http")==-1){
							if (myfiletype=="txt"){				
								ret = req.responseText;	
								if (ret == undefined) ret = "";
								objSoKH.value = objSodi.value + "/BTC-" + ret;
							}
						}
					}		
				},"txt");
			  }
		}
	}catch(e){}		
}//{End: Added by lqminh, date 07/08/2007}
//-------------------------------------------------------------------------------------

//--------------------------------------------
//Added by lqminh, date 05/07/2007
//--------------------------------------------
function GetNextNumValue(objDocType, objSodi){	
	try{
		var req; //AJAX Object
		req = Initialize();
	
		var DocumentTypeID = objDocType.item(objDocType.selectedIndex).value;
		var PropertyID = "06b270f8-569b-437e-a08a-a6e813d124f0";//So di - So van ban di
		var url= getApplicationURL() + "Common/AjaxProcess/ajax.asp?TypeProcess=GetNextNumValue&PropertyID="+ PropertyID +"&DocumentTypeID="+ DocumentTypeID;
		
		if(req!=null){
			req.onreadystatechange = function(){			
				var ajaxResult = ProcessAjax(req);
				if (ajaxResult == undefined) ajaxResult = "";
				if (ajaxResult != ""){
					if (req.readyState == 4){
						if (req.status==200 || window.location.href.indexOf("http")==-1){
							objSodi.value = ajaxResult;
						}
					}		
				}
			};
			
		    req.open("GET", url, true);
		    req.send(null);
		}
	}catch(e){}			
}//{End: Added by lqminh, date 05/07/2007}
//--------------------------------------------

//--------------------------------------------
//Added by lqminh, date 02/08/2007
//--------------------------------------------
function GetNextNumValueEx(objSo){	
	try{
		var req; //AJAX Object
		req = Initialize();
	
		var DocumentTypeID = "6c56c6f0-dd05-4927-8894-1a463ad7e7a4";//To trinh bo
		var PropertyID = objSo.name
		var url= getApplicationURL() + "Common/AjaxProcess/ajax.asp?TypeProcess=GetNextNumValueEx&PropertyID="+ PropertyID +"&DocumentTypeID="+ DocumentTypeID;

		if(req!=null){
			req.onreadystatechange = function(){			
				var ajaxResult = ProcessAjax(req);
				if (ajaxResult == undefined) ajaxResult = "";
				if (ajaxResult != ""){
					if (req.readyState == 4){
						if (req.status==200 || window.location.href.indexOf("http")==-1){
							if (ajaxResult != "nothing"){
								objSo.value = ajaxResult;
							}
						}
					}		
				}
			};
			
		    req.open("GET", url, true);
		    req.send(null);
		}
	}catch(e){}			
}//{End: Added by lqminh, date 02/08/2007}
//--------------------------------------------

//-----------------------------------------------------------------
//Added by lqminh, date 17/07/2007
//-----------------------------------------------------------------
function GetDocumentTypeID(objDocTypeCode, objEDocmanDocumentType){	
	if(window.event.keyCode == 13){
		var req; //AJAX Object
		req = Initialize();
	
		//var DocumentTypeID = objDocType.item(objDocType.selectedIndex).value;
		var DocTypeCode = objDocTypeCode.value;
		var DocumentTypeIDs = document.all.item("ctl_DocumentTypeIDs").value;
		var url= getApplicationURL() + "Common/AjaxProcess/ajax.asp?TypeProcess=GetDocumentTypeID&DocTypeCode="+ DocTypeCode +"&ViewID="+ document.all.item('ViewID').value ;
	
		if(req!=null){
			req.onreadystatechange = function(){			
				var ajaxResult = ProcessAjax(req);
				if (ajaxResult == undefined) ajaxResult = "";
				if (ajaxResult != ""){
					if (req.readyState == 4){
						if (req.status==200 || window.location.href.indexOf("http")==-1){
							if (DocumentTypeIDs.search(ajaxResult + ";")!=-1){
								SoCongVan(objEDocmanDocumentType, ajaxResult);
							}else{
							//	prompt('ajaxResult',ajaxResult);
							//	alert(document.all.item('ViewID').value);
								MsgBox("Mã sổ " + DocTypeCode + " không có, hoặc bạn không được phép nhập Sổ này.<br>Hãy thực hiện nhập lại với Mã sổ khác!");
								focusToObject(objDocTypeCode);
							}
						}
					}		
				}
			};
			
		    req.open("GET", url, true);
		    req.send(null);
		}
	}			
}//{End: Added by lqminh, date 17/07/2007}
//-----------------------------------------------------------------

//--------------------------------------------
//Added by lqminh, date 06/07/2007
//--------------------------------------------
function HideShowCmdPhanGQ(obj){
	if(obj.checked){
		document.all.item("cmdPhanGQ").style.display='';
	}else{
		document.all.item("cmdPhanGQ").style.display='none';
	}
}//{End: Added by lqminh, date 06/07/2007}
//--------------------------------------------

/*Add by Phan Manh Ha*/
//11.Ham de check truong tu ngay den ngay trong man hinh search co hop le khong
function CheckForSearch(obj){
	if (doCheckRequired(obj)){	
		var inputItems  = document.getElementsByTagName("INPUT")
		for (var i = 0; i < inputItems.length; i++){			
			if ((inputItems[i].name).search("_fromdate") >0){
				var propertyID = (inputItems[i].name).split("_")[0];					
				var objFromDate = document.all.item(propertyID + "_fromdate")
				var objToDate = document.all.item(propertyID + "_todate")
				if (!(((objFromDate.value =="") && (objToDate.value =="")) ||((objFromDate.value !="") && (objToDate.value !="")))){
					if (objFromDate.value ==""){						
						MsgBox("Trường \"Từ ngày\" chưa nhập!");
						focusToObject(objFromDate);
						obj.disabled = false;
					}
					if (objToDate.value ==""){
						MsgBox("Trường \"Đến ngày\" chưa nhập!");
						focusToObject(objToDate);
						obj.disabled = false;
					}					
					return;
				}				
				if (compareDate(objFromDate.value,objToDate.value,"dd/mm/yyyy")>0){			
					MsgBox("Từ ngày phải nhỏ hơn hoặc bằng đến ngày!");
					focusToObject(objFromDate)
					obj.disabled = false;
					return false;
				}
				fillFullDate(objFromDate);
				fillFullDate(objToDate);				
			}
		}			
		doSearch(obj);
		
		//disableButton('');
		//ButtonClick(obj);			
	}
	
	return true;	
}

function SetDateForSearch(obj){
	
	var inputItems  = document.getElementsByTagName("INPUT")
	
	for (var i = 0; i < inputItems.length; i++){			
		if ((inputItems[i].name).search("_fromdate") >0){
			var propertyID = (inputItems[i].name).split("_")[0];					
			var objFromDate = document.all.item(propertyID + "_fromdate")
			var objToDate = document.all.item(propertyID + "_todate")
			
			if ((objFromDate.value =="") && (objToDate.value!="")){						
				objFromDate.value = objToDate.value ;		
			}
			if ((objToDate.value =="") && (objFromDate.value !="")){
				objToDate.value = objFromDate.value;
			}					
			//return;
			
		}
	}			
		
	return true;	
}

function SetProcessDeadline(anyDate,ProcessDeadline){
	if(compareDate(anyDate.value,ProcessDeadline.value,"dd/mm/yyyy")>0){
		ProcessDeadline.value = anyDate.value;
	}	
}

function doSearch_toPrint(obj){
	if (doCheckRequired(obj)){	
		SetDateForSearch(obj)
		var inputItems  = document.getElementsByTagName("INPUT")
		for (var i = 0; i < inputItems.length; i++){			
			if ((inputItems[i].name).search("_fromdate") >0){
				var propertyID = (inputItems[i].name).split("_")[0];					
				var objFromDate = document.all.item(propertyID + "_fromdate")
				var objToDate = document.all.item(propertyID + "_todate")
				if (!(((objFromDate.value =="") && (objToDate.value =="")) ||((objFromDate.value !="") && (objToDate.value !="")))){
					if (objFromDate.value ==""){						
						MsgBox("Trường \"Từ ngày\" chưa nhập!");
						focusToObject(objFromDate);
						obj.disabled = false;
					}
					if (objToDate.value ==""){
						MsgBox("Trường \"Đến ngày\" chưa nhập!");
						focusToObject(objToDate);
						obj.disabled = false;
					}					
					return;
				}				
				if (compareDate(objFromDate.value,objToDate.value,"dd/mm/yyyy")>0){			
					MsgBox("Từ ngày phải nhỏ hơn hoặc bằng đến ngày!");
					focusToObject(objFromDate)
					obj.disabled = false;
					return false;
				}
				fillFullDate(objFromDate);
				fillFullDate(objToDate);				
			}
		}			
		document.all.item("strAction").value='print';
		document.frmSearch.method='post';
		document.frmSearch.submit();
	}
	return true;
}

function doSearch(obj){
	//var objForm=obj;
	//while(objForm.tagName!="FORM") objForm = objForm.parentElement;	
	//query = getParametersInForm(objForm);
	//query += "&AjaxSearch=true";
	//alert(query);
	
	//ajaxpack.getAjaxRequest("Search_BackEnd.asp",query,processReqChange,"txt");	
	document.all.item("strAction").value='xml';
	document.frmSearch.method='post';
	document.frmSearch.submit();
}



function getParametersInForm(objForm){
	var retPras= new String();
	var items = objForm.all;
	for (var i = 0; i < items.length; i++){
		if ((items(i).name != undefined) && (items(i).name!="") && (items(i).value !=undefined) && (items(i).type !="button"))
			retPras += items(i).name + "=" +encodeURI(items(i).value) + "&"
	}
	if (retPras != ""){
		if (retPras.charAt(retPras.length - 1)=="&")	retPras = retPras.substring(0,retPras.length - 1)
	}
	return retPras;	
}


function fillFullDate(obj)
{
	
	if (obj==null||obj.value=='') return false;
	
	var arrStr = new Array();
	var sDay='';
	var sMonth='';
	var sYear='';
	
	arrStr=obj.value.toString().split("/");
		
	for (var i=0; i<arrStr.length ; i++)
	{
		
		if (i==0)
		{
			sDay=arrStr[i];
			if (arrStr[i].length<2)
			{
				sDay='0'+arrStr[i];
			}
		}
		if (i==1)
		{
			sMonth=arrStr[i];
			if (arrStr[i].length<2)
			{
				sMonth='0'+arrStr[i];
			}
		}
		if (i==2)
		{
			sYear=arrStr[i];
		}
	}
	obj.value=sDay+"/"+sMonth+"/"+sYear;
	return true;
}
function focusToObject(obj){
	try{
		obj.select();
	}catch(e){}
	try{
		obj.focus();
	}catch(e){}
}

function SelectContent(obj){
	try{
		if(obj.value.length > 0){
			obj.select();
		}	
	}catch(e){}
}

/* Add by Phan Manh Ha */
//10. Ham de check cho truong nao can tim kiem chinh xac tu

function MatchSearch(obj){
	strValue = obj.text;	
	if (strValue ==undefined) strValue = "";
	if (strValue =="null") strValue = "";
	if (strValue =="") strValue = obj.value;
	if (strValue.length > 0){
		AddHiddenItem(obj, (obj.name+"").substr(0, 36)+"_MatchSearch", "EDOCPREFIX " + strValue + " EDOCSUFFIX")
	}
	else{
		AddHiddenItem(obj, (obj.name+"").substr(0, 36)+"_MatchSearch", " " + strValue + " ")
	}	


}


//---------------------------------------------------------------------------------
/* Add by Phan Manh Ha */
//9. Mo trang voi dia chi co dinh dang URLFormatLink trong cua so TargetLink
//   VD: OpenLink("../DMS/DMSView.asp?DocumentID=#strDocumentID#&ViewID=#strDocumentTypeID#")
//---------------------------------------------------------------------------------

function OpenLink(URLFormatLink, TargetLink){
	var arrStr = new Array();
	arrStr= URLFormatLink.split("#");
	var URLLink = ""
	for (var i = 0; i< arrStr.length; i++){
		if (arrStr[i] != ""){
			if (i % 2 == 0){
				URLLink += arrStr[i]	
			}else{
				URLLink  += escape(document.all.item(arrStr[i]).value)		
			}
		}
	}
	try{
		var objFrame = document.frames.item(TargetLink)	
		if (objFrame.document.body.innerHTML != ""){	
			//alert("Dang PT");	
			objFrame.focus(); 
		}else{
			window.open(URLLink,TargetLink);
		}
	}catch(ex){
		window.open(URLLink,TargetLink);
	}
}
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
/* Add by Phan Manh Ha */
//8. Dat focus cho object dau tien tren view
//---------------------------------------------------------------------------------

function SetFocusForFirstItem(){
	if (!document.all.item("viewid")) return;
	
	//-----------------------------------------------------------------
	//Added by lqminh, date 17/07/2007
	//-----------------------------------------------------------------	
	try{
		var objDocTypeCode = document.all.item("eDocmanDocumentTypeCode");
		if (objDocTypeCode){
			focusToObject(objDocTypeCode);
			return;
		}
	}catch(e){}//{End: Added by lqminh, date 17/07/2007}
	//-----------------------------------------------------------------
	
	var items = document.all ;
	
	for (var i = 0; i< items.length; i ++){		
		if (((items.item(i).type =="text")||(items.item(i).type =="select-one")) && (items.item(i).readOnly!=true) && (items.item(i).style.display.toString().toLowerCase() != "none")){
			focusToObject(items.item(i));
			return;
			break;
		}
	}
}

//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
/* Add by Phan Manh Ha */
//7. Ham nay can phai xac dinh day du cac quyen cua user tren tai lieu hien tai
//	 Va an hien cac nuc chuc nang tuong ung voi quyen han do
//---------------------------------------------------------------------------------

function checkPermission(permissionName){ 	
	//alert("Dang PT"+permissionName.search("FullControl"))
	var enableButtons = "Cancel;OpenFile"
	if (permissionName.search("FullControl")<0){		
		if (permissionName.search("ModifyObject")>=0){			
			enableButtons += "Edit";
		}		
		else
			ReadOnlyOnInputObject(true);
		disableButton(enableButtons);
	}
}

//---------------------------------------------------------------------------------
/**Add by Phan Manh Ha */
//---------------------------------------------------------------------------------
/**
/*7. MsgBox
*/
function MsgBox(msg){
	msg = msg.toString();
	var strURL = getApplicationURL() + "Common/MsgBox.asp?Message=" + msg + "&MsgType=0";
	
	var width = msg.length * 12;
	var height = width/100 + 130;
	if (width<300) width = 300;
	if (width > 450) width = 450;
	ShowModalWindow(strURL, width,height);
}
//---------------------------------------------------------------------------------
function eDocInput(caption){
	caption = caption.toString();
	var strURL = getApplicationURL() + "Common/MsgBox.asp?Message=" + caption + "&MsgType=2";
	var width = caption.length * 12;
	var height = width/100 + 130;
	if (width<300) width = 300;
	if (width > 450) width = 450;
	return ShowModalWindow(strURL, width,height);	
	
}
//---------------------------------------------------------------------------------

function GetCriterion2Find(obj,isFind){
	if (isFind){
		//alert(document.all.item("txtTimSao"));
		var defaultValue = document.all.item(document.all.item("txtTimSao").value).value;
		
		var value2find = eDocInput("Nhập số đề tìm và saoDEFAULTVALUE"+ defaultValue.toString());
		if (value2find !=null && value2find.length > 0 && value2find !=undefined  && value2find != false){
			try{
				document.all.item(document.all.item("txtTimSao").value).value = value2find;	
			}catch(e){}	
			CopyPropertiesFromDoc(obj);
		}
	}
	else{
		CopyPropertiesFromDoc(obj);
	}	
	
}


//---------------------------------------------------------------------------------
/**Add by Phan Manh Ha */
//---------------------------------------------------------------------------------
/**
/*7. Confirm delete action
*/
function confirmAction(obj,msg){
	var strURL = getApplicationURL() + "Common/MsgBox.asp?Message=" + msg + "&MsgType=1";
	var width = msg.length * 11;
	var height = width/100 + 130;
	if (width<300) width = 300;
	if (width > 450) width = 450;		
	var sResult = ShowModalWindow(strURL, width,height);
	if (sResult == true){
		disableButton('');
		ButtonClick(obj);		
	}
}
//---------------------------------------------------------------------------------
/**
/*. Confirm function
*/
function eDocConfirm(msg){
	var strURL = getApplicationURL() + "Common/MsgBox.asp?Message=" + msg + "&MsgType=1";
	var width = msg.length * 11;
	var height = width/100 + 130;
	if (width<300) width = 300;
	if (width > 450) width = 450;
		
	var sResult = ShowModalWindow(strURL, width,height);
	if (sResult == true) return true;
	return false;
	
}

/**Add by Phan Manh Ha */
//---------------------------------------------------------------------------------
/**
/*. alert box
*/
function eDocAlert(msg){
	MsgBox(msg)
}


//---------------------------------------------------------------------------------
/**Add by Nguyen Huu An */
//---------------------------------------------------------------------------------
/**
/*7. Confirm finish activity
*/

function confirmFinish(obj,msg,i) {
	var strURL = getApplicationURL() + "Common/MsgBox.asp?Message=" + msg + "&MsgType=1";
	var sResult = ShowModalWindow(strURL, 450,150);
	if (sResult == true){
		document.getElementsByName('chk')[i].checked=true;
		disableButton('');
		ButtonClick(obj);		
	}


}


function eDocman_confirm(msg){
	var strURL = getApplicationURL() + "Common/MsgBox.asp?Message=" + msg + "&MsgType=1";
	var sResult = ShowModalWindow(strURL, 450,150);
	if (sResult == true){	
		return "Yes";
	}
	else {
		return "No";
	}
}
	
//---------------------------------------------------------------------------------
/**Add by Phan Manh Ha */
//---------------------------------------------------------------------------------
/**
/*6. Them the Input hidden vao form hien tai
*/
function AddHiddenItem(obj, ItemName){
	var itemValue;
	if (obj.type == 0){				
		itemValue = obj.text;
	}else{
		itemValue = obj.value;	
	}
	
	if (arguments[2] != undefined){
		itemValue = arguments[2];		
	}
	/*
	Cac chuc nang get gia tri tren server dung ajax thi cho vao day	
	*/
	if (ItemName.search("CheckExistingItem_") !=-1){
		CheckExistingItem(obj.name, obj.value,itemValue);
		return;
	}
			
	var objNew =document.getElementById(ItemName);
	if (objNew==null){
		objNew = document.createElement("INPUT");
		objNew.name = ItemName;
		objNew.id= ItemName;
		objNew.style.display = "none";
		objNew.value = itemValue;
		
		var objForm=obj;
		
		while(objForm.tagName!="FORM") objForm = objForm.parentElement;
			objForm.appendChild(objNew)							
	}
	else{
		objNew.value = itemValue;
	}
	

}



//---------------------------------------------------------------------------------
/**Add by Phan Manh Ha */
//---------------------------------------------------------------------------------
/**
/*5. Check cac truong bat buoc phai nhap du lieu dung dan
*/

function CheckRequired(obj){	
	try {
		
		if (doCheckRequired(obj)){		
			if ((obj.name.toLowerCase().search("save") != -1)||(obj.name.toLowerCase().search("edit") != -1)||(obj.name.toLowerCase().search("cmdphangq") != -1)){		
				try{
					var fileScaned = "";
					try{
						//Updated by Le Quang Minh, date 19/09/2006
						//-----------------------------------------
						with (document.all){
							if ((item("ViewType").value == 1) && (item("strFolderID").value.toString().length != 36)){
								var vAutoCreateFolder;
								var vAutoCreateFolderByMe;
								
								if (item("AutoCreateFolder") == null){
									vAutoCreateFolder = "";
								}
								else{
									if (item("AutoCreateFolder").value == undefined)
										vAutoCreateFolder = "";
									else
										vAutoCreateFolder = item("AutoCreateFolder").value;							
								}
								
								if (item("AutoCreateFolderByMe") == null){
									vAutoCreateFolderByMe = "";
								}
								else{
									if (item("AutoCreateFolderByMe").value == undefined)
										vAutoCreateFolderByMe = "";
									else
										vAutoCreateFolderByMe = item("AutoCreateFolderByMe").value;							
								}
																
								if (!((vAutoCreateFolder == "1")||(vAutoCreateFolderByMe != ""))){
									var strDocSpaceIDs = item("strDocSpaceID").value;
									var strDocumentTypeID = item("ViewID").value;
									var strResult  = window.showModalDialog(getApplicationURL()+ "Common/CommonDialog/Dialog.asp?strURL=" + escape("DocBrowse.asp?strParentKey=root&strDocSpaceIDs=" +strDocSpaceIDs + "&strDocumentTypeID=" + strDocumentTypeID + "&multiSelect=false&showDocumentList=false&showFolderList=true&DocBrowse=true&CreatedDoc=true"), 0 , "resizable:no;dialogWidth:650px;dialogHeight:600px;status:no");
									if (strResult == undefined) strResult = "";
									if (strResult != ""){
										item("strFolderID").value = strResult;
										item("FolderIDFromDocBrowser").value = 'true';
									}
									else
										return;									
										//item("strFolderID").value = "";
								}
							}
						}//{End: Updated by Le Quang Minh, date 19/09/2006}
						///------------------------------------------------				
						
						fileScaned = document.all.item("fileScaned").value;
					}catch(e){}
					var HTTPUploader = document.all.item("HTTPUploaderFlag").value;
					if (HTTPUploader == undefined) HTTPUploader = "";
					if (HTTPUploader.toLowerCase() != "true"){					
						var UploadedFilePaths = doUploadFileFTP(getlistfilename() + ";" + fileScaned);
						AddHiddenItem(obj, "UploadedFilePaths", UploadedFilePaths);				
						ButtonClick(obj);
					}else{
						AddHiddenItem(obj, "UploadedFilePaths", "");					
						var hasUpload = false;
						if (fileScaned != ""){
							hasUpload = doXMLUploadFiles(obj, fileScaned)
						}else{
							hasUpload = doHTTPUpload(obj);
						}
						if (!hasUpload) ButtonClick(obj);
					}				
				}catch(e){}		
			}else{
				ButtonClick(obj);
			}
			disableButton('');
		}
	}
	catch (e) {}
}

function ValidateFileUpload(){
	try{
		var arrObj = eDocmanFileBrowserIFrame.document.all;
					
		var checkOK;
		checkOK=true;
		var tempFilePaths;
	
	
		for (var i = 0; i< arrObj.length; i++){
			var itemName = arrObj[i].name;		
			if (itemName == undefined) itemName= "";		
			var itemValue = arrObj[i].value;		
			if (itemValue == undefined) itemValue= "";
	
			if (arrObj[i].type == "file"){
				if (itemValue !=""){
				
					checkOK = ValidFileUpload(itemValue);
					if (!checkOK) return checkOK;

				}
			}
		}// for
	
		return checkOK;
	}catch(e){return true;}
}

function doCheckRequired(obj){

	var arrObj= document.all;
	var checkOK;
	checkOK=true;	
	var tempFilePaths;
	try{
		tempFilePaths=getlistfilename();

	}
	catch(e){}
	obj.disabled = true;
	
	var valueslength = 0;
	for (var i = 0; i< arrObj.length; i++){
		
		var itemName = arrObj[i].name;		
		if (itemName == undefined) itemName= "";		
		var itemValue = arrObj[i].value;		
		if (itemValue == undefined) itemValue= "";				
		var messageRequired = arrObj[i].messageRequired;
		if (messageRequired == undefined) messageRequired = "";
		var typeRequired = (arrObj[i].typeRequired+"").toLocaleUpperCase();
		
		//Auto check: Kieu so hop le, kieu ngay thang hop le???
		/*--------------------------------------------------------------------*/
		if ((itemValue !="")&& (itemName !="")){
			if (arrObj[i].type != "hidden") valueslength += itemValue.length;
			switch (typeRequired){
				//Check error date
				case "3":{
					if (messageRequired == ""){
						messageRequired = "Kiểu thời gian không hợp lệ với định dạng ngày/tháng/năm (dd/MM/yyyy) hoặc ngày/tháng/năm giờ:phút:giây (dd/MM/yyyy hh:mm:ss)";
					}
					checkOK = isValidDate(arrObj[i]);
					//checkOK = ValidDate(arrObj[i].value,"dd/mm/yyyy");					
					
					//Kiem tra neu la Date&Time - Nguyen Huu An
					
					if (!checkOK)
						checkOK = isValidDateTime(arrObj[i]);
					
					break;
				} 
				//Check error Number
				
				case "4":{//So thuc
					if (messageRequired == ""){
						messageRequired = "Kiểu số không hợp lệ";
					}
					checkOK = !isNaN(arrObj[i].value)
					break;
				}

				case "5":{//So dinh danh				
					if (messageRequired == ""){
						messageRequired = "Kiểu số không hợp lệ";
					}
					checkOK = !isNaN(arrObj[i].value)
					break;
				}
				case "6":{	//So nguyen	
					if (messageRequired == ""){							
						messageRequired = "Kiểu số nguyên không hợp lệ";
					}
					checkOK = !isNaN(arrObj[i].value)
					if (checkOK){
						var tempNum = parseInt(arrObj[i].value);
						if ((tempNum+"").length !=  arrObj[i].value.length){							
							checkOK = false;
						}
					}
					break;
				}
				default:{	

					if (messageRequired.length > 0 ) {
						var sCheckTime = new String(messageRequired);
						sCheckTime = sCheckTime.toLowerCase();
						if (sCheckTime.length > 0 && sCheckTime.search("@time") != -1){
							checkOK = isTime(itemValue);
							messageRequired = messageRequired.substring(0,messageRequired.length - 5);
						}						
					}
					
					//if (itemValue.length > 2000){						
					//	messageRequired = "Độ dài dữ liệu quá lớn, đề nghị kiểm tra lại!";
					//	checkOK= false;
					//}	
				}
			}
		}
		
		/*--------------------------------------------------------------------*/
		//Check required: chua nhap gia tri vao truong bat buoc nhap
		if ((arrObj[i].isRequired + "").toLocaleLowerCase()=="true"){
			//nccong Update:Bat loi khi nguoi dung nhap vao cac dau cach
			//if(itemValue=="") checkOK= false;
			if(trimString(itemValue)=="") checkOK= false;						
			//-----------------------------------------
		}
		
		
		//Kiem tra gia tri da ton tai trong he thong
		try{
			if (itemName.search("CheckExistingItemResult") != -1){
				var arr = arrObj[i].value.toString().split("__");
				
				if (arr[0]=="True"){
					if (arr[1].search("|") != -1){
						messageRequired = arr[1];
					}else{					
						messageRequired = arr[1].split("|")[1];	
					}					
					checkOK = false;				
				}
			}
		}catch(e){}
		/*--------------------------------------------------------------------*/
		//Kiem tra 2 gia tri ngay thang neu gia tri 1 > gia tri 2 thi thong bao msg tren view truyen vao		
		try{
			if (itemName.toString().search("CompareDate") != -1){				
				var arrID = itemName.split("__");				
				var date1 = document.all.item(arrID[1]).value;
				var date2 = document.all.item(arrID[2]).value;				
				//alert("Dang PT: " + arrObj[i].value);	
				if (compareDate(date1, date2, "dd/MM/yyyy")==1){
					messageRequired = itemValue;					
					checkOK = false;
				}								
			}			
		}catch(e){}	
		
		/*--------------------------------------------------------------------*/
		//if (valueslength > 7000){
		//	messageRequired = "Tổng độ dài dữ liệu các trường nhập vào quá lớn, hãy kiểm tra lại!";
		//	checkOK = false;
		//}
		//Hien thi thong bao
		if (!checkOK){				
			MsgBox(messageRequired);	
			focusToObject(arrObj[i]);	
			obj.disabled = false;	
			return false;
		}	
		// kiem tra cac file upload trong iframe
		checkOK = ValidateFileUpload();
		
		if (!checkOK){
			messageRequired = "Tệp đính kèm không hợp lệ!<br>[Không chấp nhận các tệp nội dung có phần mở rộng là exe,msi,avi,wmv,dat,asp,aspx,php,jsp,cgi,dll,com,bat,sys]<br>[Có thể đường dẫn tệp có dấu tiếng Việt hoặc kích thước tệp bằng 0]";				
			MsgBox(messageRequired);	
			obj.disabled = false;
			return false;
		}	
	}

	return true;
}


//---------------------------------------------------------------------------------
/**Add by Phan Manh Ha */
//---------------------------------------------------------------------------------
/**
/*4. Chuc nang nap lai trang khi chon danh sach so cong van trong combobox so cong van tren View
*/
function SoCongVan(obj){
	var DocTypeID = arguments[1];
	if (DocTypeID==undefined){
		DocTypeID = obj.item(obj.selectedIndex).value;
	}
	try{
		document.all.item("ViewID").value = DocTypeID;
	}catch(ex){
		document.all.item("ViewID").value = obj.value;
	}
	
	var objTakeValuesFlag = document.all.item("TakeValuesFlag");
	
	var objForm = obj;
	
	while(objForm.tagName != "FORM")
		objForm = objForm.parentElement;
	
	if (objTakeValuesFlag==null){		
		objTakeValuesFlag= document.createElement("INPUT");
		objTakeValuesFlag.name = "TakeValuesFlag";
		objTakeValuesFlag.id= "TakeValuesFlag";
		objTakeValuesFlag.style.display = "none";
		objTakeValuesFlag.value = "true";
		objForm.appendChild(objTakeValuesFlag);
	}
	else{
		objTakeValuesFlag.value = "true";
	}	

	disableButton('');
	var str = window.location.href;
	if ((str.toLowerCase().search("viewid=")!=-1) && (DocTypeID!="")){
		str = str.replace(str.substr(str.toLowerCase().search("viewid=")+7,36), DocTypeID);
		objForm.action = str;
	}
	objForm.submit();
	obj.disabled=true;
}
//---------------------------------------------------------------------------------
/**
/*3. Goi chuc nang Theo doi khi nhan vao nut Theo doi tren view
*/
function TheoDoi(){
	try{
		var ProcessInstanceID = arguments[0];
		if ((ProcessInstanceID == undefined) || (ProcessInstanceID == "")){
			ProcessInstanceID =document.all.item('ProcessInstanceID').value;			
		}			
		var strURL=getApplicationURL() + "WFS/Wfi/Monitoring.asp?ProcessInstanceID=" + ProcessInstanceID;
		openWindow(strURL,screen.availWidth,screen.availHeight)
	}catch(ex){}
				
					
}
//---------------------------------------------------------------------------------
/**
/*2. Goi chuc nang noi dung cua mo tai lieu khi nhan vao nut Noi dung tren view
*/
function MoNoiDung(){
	try{
		var documentID = arguments[0];
		var retVal;
		if ((documentID == undefined) || (documentID == "")){
			documentID =document.all.item("DocumentID").value;			
		}		
		var Status = 0;
		try{
			Status = document.all.item("ActivityInstanceStatus").value;
		}catch(e){};
		if (Status==undefined) Status = 0;
		var strURL=getApplicationURL() + "DMS/OpenDocument.asp?isCheckOut_asp=false&strDocumentID=" + documentID + "&Status="+Status;		
		retVal = openWindow(strURL,620,600);
	
	}catch(ex){}				
					
}
//---------------------------------------------------------------------------------
/**
/*1. Goi chuc nang Scan khi nhan nut scan tren view
*/
function Scan(){
	if (CheckScanObject()){
		result=window.showModalDialog(getApplicationURL()+"DMS/QuetVB.asp?","","dialogHeight: 600px; dialogWidth:800px;status:no;")
		if (result!=""){
			document.all.item("fileScaned").value=result;
		}
		else {
			MsgBox("Không quét được văn bản");
		}
	}	
	else{
		MsgBox("Chưa cài đặt tiện ích quét văn bản <br> Bấm installscan để cài đặt tiện ích quét văn bản");		
		return;
	}
}


function CheckScanObject(){

	try{
		var testScan = new ActiveXObject("eDScanner.Scanner");
		
		if (testScan==undefined || testScan==null){
			return false;				
		}
		else{ // [object]
			return true;
		}
		
	}catch(e){
		return false;
	}
}


//---------------------------------------------------------------------------------
/**
/*Lay URL cua ung dung 
*/
function getApplicationURL(){
	return window.location.protocol + "//" + window.location.host + "/" + window.location.pathname.split("/")[1] + "/";
}


/** 
/*Disable cac button tren document loai tru nhung button co ten trong danh sach enableButtons
/*VD: khi goi ham disableAllButton("Cancel;OpenFile") se Disable tat ca cac button tru 2 button Cancal va OpenFile
/*Chu y co phan biet chu hoa va chu thuong
*/
function disableButton(enableButtons)
{ 	
	var arrButton = document.getElementsByTagName("INPUT");
	for (var i = 0; i< arrButton.length; i++)
		{
			
		 if ((arrButton(i).type=="button")||(arrButton(i).type=="reset")||(arrButton(i).type=="submit"))
			{	
			if (enableButtons.search(arrButton(i).name) == -1 )
				{
				arrButton(i).disabled=true;			
				}
			}
		}	
}
/** 
/*enable cac button tren document loai tru nhung button co ten trong danh sach disableButtons
/*VD: khi goi ham enableAllButton("Cancel;OpenFile") se enable tat ca cac button tru 2 button Cancal va OpenFile
/*Chu y co phan biet chu hoa va chu thuong
*/
function enableButton(disableButtons)
{ 	
	var arrButton = document.getElementsByTagName("INPUT");

	for (var i = 0; i< arrButton.length; i++)
		{
		 if ((arrButton(i).type=="button")||(arrButton(i).type=="reset")||(arrButton(i).type=="submit"))
			{	
			if (disableButtons.search(arrButton(i).name) == -1 )
				{	
				arrButton(i).disabled=false;			
				}
			}
		}	
}
/**
/*Mo mot cua so nam chinh giua man hinh voi URL va chieu rong, cao truyen vao
/*VD: openWindow("../abc/file.asp",300,200) 
/* O day cua so mo ra khong su dung Scroll (Do cua so mo ra se xau), trong trang asp, html, 
/* ta nen dung the <div class="beautyDiv1"></div> cho toan bo trang
/* va can le phai document nen de la 0px -> cua so se dep hon 
*/
function openWindow(strURL,width ,height ) {
     var winl = (screen.availWidth - width ) / 2;
     var wint = (screen.availHeight - height) / 2;
     winprops = 'height='+height+',width='+width +',top='+wint+',left='+winl+'resizable=0'
	 return window.open(strURL, "", winprops);	 
	 //var ret =  window.open(strURL, "", winprops);	 
	 //alert(ret.value);
   } 

function OpenWindowAddnewBTC(strURL,width ,height ) {
     var winl = (screen.availWidth - width ) / 2;
     var wint = (screen.availHeight - height) / 2;
     winprops = 'height='+height+',width='+width +',top='+wint+',left='+winl+',resizable=1,scrollbars=1';
     
     //prompt ("",winprops);
	 //var styleStr = 'toolbar:no;location:no;directories:no;status:no;menubar:no;scrollbars:no;resizable:no;copyhistory:yes;dialogWidth:'+width+' px;dialogHeight:'+height+' px;left:'+left+' px;top:'+top+' px;screenX:'+left+' px;screenY:'+top+'px;';
	 
	 return window.open(strURL, "", winprops);	 
	 
	 //var subwin =  window.open(strURL, "", winprops);	 
	 //subwin.max.Click();
	 //var ret =  window.open(strURL, "", winprops);	 
	 //alert(ret.value);
} 

function ShowModalWindow(url,width,height)
{  
	var left = (screen.availWidth/2) - width/2;
	var top = (screen.availWidth/2) - height/2;
	var styleStr = 'toolbar:no;location:no;directories:no;status:no;menubar:no;scrollbars:no;resizable:no;copyhistory:yes;dialogWidth:'+width+' px;dialogHeight:'+height+' px;left:'+left+' px;top:'+top+' px;screenX:'+left+' px;screenY:'+top+'px;';
	var msgWindow = window.showModalDialog(url,'', styleStr,"_self");    
	return msgWindow;
}
//Ham moi
//Add by Phan Manh Ha
function DateAdd(dateSrc , numDay){ 
     var arr = dateSrc.toString().split("/")
     var numDay = parseInt(numDay)
     var toDay = new Date(arr[1]+"/"+arr[0]+"/"+arr[2]); 
     var xDay = new Date(arr[1]+"/"+arr[0]+"/"+arr[2]); 
     xDay.setDate(toDay.getDate()+numDay ); 
     var ngay = xDay.getDate();
     var thang = xDay.getMonth()+1;
     var nam = xDay.getFullYear();
     if (ngay.toString().length==1)  ngay = "0"+ ngay.toString();
     if (thang.toString().length==1)  thang = "0"+ thang.toString();     
     return (ngay + "/" + thang + "/" + nam); 
}
    
function compareDate(strDate1,strDate2, strFormatDate){
	strDate1=FormatDate(strDate1, strFormatDate, "mm/dd/yyyy");
	strDate2=FormatDate(strDate2, strFormatDate, "mm/dd/yyyy");
	var oDate1 = new Date(strDate1);
	var oDate2 = new Date(strDate2);
	//alert(oDate1+":"+ oDate2)
	if (oDate1 < oDate2){
		return -1;
	}	
	if (oDate1 > oDate2){
	 	return(1);
	}
	return 0;
}

//Add by Phan Manh Ha
function FormatDate(strDate,strFormatSourceDate,strFormatDesDate){	
	var strDateTemp= strDate;
	var arr = strDateTemp.split("/");	
	if (arr.length < 3) return "";
	if (arr[2].length != 4) return "";
	strFormatSourceDate = strFormatSourceDate.toLocaleUpperCase();
	var month;
	var	day;
	var year;
	
	switch (strFormatSourceDate ){
		case "DD/MM/YYYY":{
			month= arr[1]; day = arr[0]; year= arr[2];			
			break;
		} 
		case "MM/DD/YYYY":{
			month= arr[0]; day = arr[1]; year= arr[2];
			break;
		} 
		case "YYYY/MM/DD":{
			month= arr[1]; day = arr[2]; year= arr[0];
			break;
		}		
	}
	
	strFormatDesDate = strFormatDesDate.toLocaleUpperCase();
	switch (strFormatDesDate ){
		case "DD/MM/YYYY":{
			strDateTemp= day + "/" + month + "/" + year;			
			break;
		} 
		case "MM/DD/YYYY":{
			strDateTemp= month + "/" + day + "/" + year;
			break;
		} 
		case "YYYY/MM/DD":{
			strDateTemp= year + "/" + month + "/" + day;
			break;
		}		
	}
	return strDateTemp;
}

    
//Add by Phan Manh Ha
function ValidDate(strDate,strFormatDate){	
	var strDateTemp= strDate;
	var arr = strDateTemp.split("/");	
	if (arr.length != 3) return false;
	if (arr[2].length != 4) return false;
	strFormatDate = strFormatDate.toLocaleUpperCase();
	var month;
	var	day;
	var year;
	switch (strFormatDate ){
		case "DD/MM/YYYY":{
			month= arr[1]; day = arr[0]; year= arr[2];						
			break;
		} 
		case "MM/DD/YYYY":{
			month= arr[0]; day = arr[1]; year= arr[2];
			break;
		} 
		case "YYYY/MM/DD":{
			month= arr[1]; day = arr[2]; year= arr[0];
			break;
		} 
		default:{
			return false;
		}				
	}
	strDateTemp= month + "/" + day + "/" + year;
	var myDate;
	try{
		myDate = new Date(strDateTemp);	
		if (isNaN(myDate)) return false;		
		if ((myDate.getMonth()+1) != parseFloat(month)) return false; 				
		if ((myDate.getDate()) != parseFloat(day)) return false;
		if ((myDate.getFullYear()) != parseFloat(year)) return false; 
	}catch(e){return false;}
	return true;
}

/*
	Nguyen Huu An
	isValidDateTime: Ham kiem tra xem kieu du lieu ngay thang co hop le khong 
	Thuong dung cho textbox co kieu eDocmanDTPickerWithTime
	Dinh dang: dd/mm/YYY HH:MM:SS
*/
function isValidDateTime(obj){
	var regDateTime = /^\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}:\d{2}$/
	var s = obj.value
	var i = 0
	if (regDateTime.test(s)){
		var t = s.split(' ')
		
		var DateArr = t[0].split('/')
		
		if (parseInt(DateArr[0]) > 31) return false
		if (parseInt(DateArr[1]) > 12) return false
		if (parseInt(DateArr[2]) > 2099) return false
		switch(parseInt(DateArr[1])){
			case 1||3||5||7||8||10||12:if (parseInt(DateArr[0]) > 31) return false; break;
			case 4||6||9||11:if (parseInt(DateArr[0]) > 30) return false; break;
			case 2:if(parseInt(DateArr[2])%4==0)
					{
						if ((parseInt(DateArr[2])%100==0) && (parseInt(DateArr[2])%400!=0))	//Khong nhuan
							{
								if (parseInt(DateArr[0]) > 28) return false
								break;	
							}
						else 
							{
								if (parseInt(DateArr[0]) > 29) return false	//nam nhuan
								break;
							}
					}
					else 
					{
						if (DateArr[0] > 28) return false //khong nhuan
						break;
					}
			//default: alert(parseInt(DateArr[1]));
		}
		
		var TimeArr = t[1].split(':')
		if (parseInt(TimeArr[0]) > 23) return false
		if (parseInt(TimeArr[1]) > 59) return false
		if (parseInt(TimeArr[2]) > 59) return false
		
		return true;
	}
	return false;
}

function isValidDate(obj)
{
	var s = obj.value;	
	var regDate = /^\d{2}\/\d{2}\/\d{4}$/
	
	if (!regDate.test(s)) return false;
	var DateArr;
	var eDate;
	var DateArr = s.split('/')

	if (parseInt(DateArr[0]) > 31) return false
	if (parseInt(DateArr[1]) > 12) return false
	if (parseInt(DateArr[2]) > 2099) return false
	switch(parseInt(DateArr[1])){
		case 1||3||5||7||8||10||12:if (parseInt(DateArr[0]) > 31) return false; break;
		case 4||6||9||11:if (parseInt(DateArr[0]) > 30) return false; break;
		case 2:if(parseInt(DateArr[2])%4==0)
				{
					if ((parseInt(DateArr[2])%100==0) && (parseInt(DateArr[2])%400!=0))	//Khong nhuan
						{
							if (parseInt(DateArr[0]) > 28) return false
							break;	
						}
					else 
						{
							if (parseInt(DateArr[0]) > 29) return false	//nam nhuan
							break;
						}
				}
				else 
				{
					if (DateArr[0] > 28) return false //khong nhuan
					break;
				}
		//default: alert(parseInt(DateArr[1]));
	}	
	return true;
}


//end Nguyen Huu An


/**Add by Phan Manh Ha*/
function getShortString(fullString){	
	var str  = new String(fullString.charAt(0).toLocaleUpperCase());
	for(var i=0; i < fullString.length -1; i++){
		if (fullString.charAt(i)==" ") str += fullString.charAt(i+1).toLocaleUpperCase();
	}
	return str;
}
function RightClickDenied(){
	var myDiv = document.createElement("DIV") 
	var m='%3Cscript%20language%3DJavaScript%3E%3C%21--%0D%0A%0D%0Avar%20message%3D%22SORRY  : %20 %21%22%3B%0D%0A%0D%0Afunction%20clickIE%28%29%20%20%7Bif%20%28document.all%29%20%7Balert%28message%29%3Breturn%20false%3B%7D%7D%0D%0Afunction%20clickNS%28e%29%20%7Bif%20%0D%0A%28document.layers%7C%7C%28document.getElementById%26%26%21document.all%29%29%20%7B%0D%0Aif%20%28e.which%3D%3D2%7C%7Ce.which%3D%3D3%29%20%7Balert%28message%29%3Breturn%20false%3B%7D%7D%7D%0D%0Aif%20%28document.layers%29%20%0D%0A%7Bdocument.captureEvents%28Event.MOUSEDOWN%29%3Bdocument.onmousedown%3DclickNS%3B%7D%0D%0Aelse%7Bdocument.onmouseup%3DclickNS%3Bdocument.oncontextmenu%3DclickIE%3B%7D%0D%0A%0D%0Adocument.oncontextmenu%3Dnew%20Function%28%22return%20false%22%29%0D%0A%0D%0A//%20--%3E%3C/script%3E';
	
}

function MoveTop(){
	return;
	try{
		window.scrollTo(0,0);
		parent.window.scrollTo(0,0);		
		parent.parent.window.scrollTo(0,0);		
	}catch(e){}
}
/**End add by Phan Manh Ha*/
function WindowOnload(){
	if (document.all.item("ViewType") == undefined ||document.all.item("ViewType") ==null ){
		return;
	}
	
	HideLoading();
	try{
		
		var strOnclick = new String(document.all.item("Cancel").onclick);
		if (strOnclick.search("ButtonClick") != -1){						
			document.all.item("Cancel").onclick = function(){		
				//if (!closeWindowInDIV()) 
				//ButtonClick(this);
				ButtonClick(document.all.item("Cancel"));
				}
		}else{
			//document.all.item("Cancel").attachEvent("onclick", function(){if (!closeWindowInDIV()) ButtonClick(this)});
			document.all.item("Cancel").attachEvent("onclick", function(){if (!closeWindowInDIV()) ButtonClick(document.all.item("Cancel"))});
		}		
	
	}catch(e){}
	
	//alert('HeiXXX');
	//SetFocusForFirstItem();	

	//Kick hoat su kien onchange, onpropertychange, onhelp tren tung thuoc tinh trong form 
	// trong truong hop view tao moi
	var viewType;
	viewType = "";
	try{
		viewType = document.all.item("ViewType").value;

		// Thang Admin thi chi hien 2 nut
		if ((viewType == "0")||(viewType == "2")||(viewType == "1")||(viewType == "3")){
			if (document.all.item('CurrentUserID').value == "000000000000000000000000000000000001" ){
				disableButton("Cancel;OpenFile");
			}
		}		
	}catch(e){
		//alert("Dang PT: " + e.message);
	}
	
	var items;
	var items = document.all;	
	
	var itemName;
	
	var index=0;
	var arrXuBan = new Array();
	//nccong Them 3 array nay phuc vu cho viec kiem tra trung nhieu thuoc tinh tren View
	var arrCheckExisting = new Array();
	var arrExistingMsg = new Array();
	var arrForceCheck = new Array();
	//nccong:---------------------------------------------------------------------------
	for (var i=0;i<items.length;i++){
		try {
			itemName = items[i].name;			
			if (itemName==undefined) itemName = "";
			if (itemName=="") itemName = items[i].id;
			if (itemName==undefined) itemName = "";
			
			if (itemName!=""){

				
				//------------------------------------------------------------
				if(items[i].CheckExisting != undefined && items[i].CheckExisting != ""){
					//alert(items[i].ExistingMsg);
					arrCheckExisting[items[i].CheckExisting] = arrCheckExisting[items[i].CheckExisting]==undefined || arrCheckExisting[items[i].CheckExisting]==""?items[i].name:arrCheckExisting[items[i].CheckExisting] + "eDocSplitItem" + items[i].name;
					arrExistingMsg[items[i].CheckExisting] = arrExistingMsg[items[i].CheckExisting] == undefined || arrExistingMsg[items[i].CheckExisting] == ""?items[i].ExistingMsg:arrExistingMsg[items[i].CheckExisting];
					arrForceCheck[items[i].CheckExisting] = arrForceCheck[items[i].CheckExisting] == undefined || arrForceCheck[items[i].CheckExisting] == ""?items[i].ForceCheck:arrForceCheck[items[i].CheckExisting];
				}
				//------------------------------------------------------------
				
				if (items[i].tabIndex == 1){
				
					if (items[i].readOnly!=true && items[i].style.display.toString().toLowerCase() != "none" ){
					
						try{
							if (document.all.item('CustomizeHiddenControl3').value =="FocusToTxtPreside"){
								focusToObject(document.all.item('txtPreside'));
								document.all.item('CustomizeHiddenControl3').value = '';
							}else{
								focusToObject(items[i]);				
							}
							
						}catch(e){
							//alert(e.message);
							focusToObject(items[i]);
						}
					}
				}
				
				try{			
					document.all.item("IndexContainer").value = "";
					if (items[i].tabIndex != undefined){
						if(items[i].tabIndex > 0){
							arrXuBan[index++] = ("00000" + items[i].tabIndex.toString()).substr((items[i].tabIndex.toString() + "00000").length-5,5) + itemName;
						}
					}	
				}
				catch(e){}
								
				try {					
					var str = items[i].onload;
					eval(str);
				}catch(e){}						
				try {
					eval(items[i].onhelp);
					items[i].onhelp();
				}catch(e){}
				
				if (viewType == "4"){	
															
					var typeRequired = items[i].typeRequired;
					if (typeRequired == undefined) typeRequired = "";
					//if ( (typeRequired != "3")&&(typeRequired != "") && (items[i].name.search("FullTextSearch") == -1 ) ){
					
					if ( (typeRequired != "3")&&(typeRequired != "") ){  
						AddHiddenItem(items[i], items[i].name+"_type",items[i].typeRequired +'');
					}
					
					else{
						
						if (typeRequired == "3"){
							AddHiddenItem(items[i], items[i].name + "_type",items[i].typeRequired +'');
						}	
					}
					
				}
				
				if (itemName.toLowerCase() != "edocmandocumenttype") {
			
					var recalculate = items[i].ReCalculate;
					if (recalculate == undefined) recalculate = "";							
					recalculate = recalculate.toLocaleLowerCase()
					//View show	
					if ((viewType == "0")||(viewType == "2")){					
						if (recalculate =="true"){						
							try {
								items[i].onchange();
							}catch(e){}				
						
							try {
								items[i].onpropertychange();
							}catch(e){}				
						}
					}				

					//View tao moi
					
					if ((viewType == "1")||(viewType == "3")){
						try {
							items[i].onchange();
						}catch(e){}				
						
						try {
							items[i].onpropertychange();
						}catch(e){}				
					}
					
				}
				
				/*
				
				// Doan nay lao PMHA viet cuc ky vo van
				//attachEvent cho cac nut chuc nang dac biet
				//if ((viewType == "0")||(viewType == "2")||(viewType == "1")||(viewType == "3")){					
				//	if (items[i].type == "button"){				
				//		//alert(itemName)
				//		//Nut save ,edit voi ham CheckRequired(this) cho su kien onclick
				//		if ((itemName.toLowerCase().search("save") != -1)||(itemName.toLowerCase().search("edit") != -1)) {
				//			var strOnclick = new String(items[i].onclick);
				//			if (strOnclick.search("CheckRequired")== -1){						
				//				items[i].onclick = function(){CheckRequired(this)};						
				//			}
				//		}
				//	}
				//}
				*/
				
			}
		}catch(e){
			//alert(e.message)
		}
	}
	if(document.all.item("IndexContainer") != undefined){
		arrXuBan.sort();
		document.all.item("IndexContainer").value = arrXuBan.join("|");
		//prompt('dang pt:', document.all.item("IndexContainer").value);
	}
	
	var strCheckExisting = "";
	var strExistingMsg = "";
	var strForceCheck = "";
	
	for(var iTemp=0; iTemp<arrCheckExisting.length; iTemp++){
		if(arrCheckExisting[iTemp] != undefined){
			strCheckExisting = iTemp==0?arrCheckExisting[iTemp]:strCheckExisting + "eDocSplitGroup" + arrCheckExisting[iTemp];
			strExistingMsg = iTemp==0?arrExistingMsg[iTemp]:strExistingMsg + "eDocSplitGroup" + arrExistingMsg[iTemp];
			strForceCheck = iTemp==0?arrForceCheck[iTemp]:strForceCheck + "eDocSplitGroup" + arrForceCheck[iTemp]
		}
	}

	if(document.all.item("CheckExistingContainer") != undefined){
		document.all.item("CheckExistingContainer").value = strCheckExisting;
	}
	
	if(document.all.item("ExistingMsgContainer") != undefined){
		document.all.item("ExistingMsgContainer").value = strExistingMsg;
//	}else if(document.all.item("CustomizeHiddenControl1") != undefined){
//		document.all.item("CustomizeHiddenControl1").value = strExistingMsg;
	}
	
	if(document.all.item("ForceCheckContainer") != undefined){
		document.all.item("ForceCheckContainer").value = strForceCheck;
//	}else if(document.all.item("CustomizeHiddenControl2") != undefined){
//		document.all.item("CustomizeHiddenControl2").value = strForceCheck;
	}
	
	MoveTop();
}

//Add by Phan Manh Ha

// Nguyen Huu An - 23/03/2006

// Ham dat thuoc tinh ReadOnly cho cac dieu khi co hoac khong co quyen sua!
// status la true -> khong duoc nhap lieu
function ReadOnlyOnInputObject(status){
	var a = document.all.tags("input");
	var i;
	for(i=0;i<a.length;i++){
		a[i].setAttribute("readOnly",status);
	}
	a = document.all.tags("textarea");	
	for(i=0;i<a.length;i++){
		a[i].setAttribute("readOnly",status);
	}
	a = document.all.tags("select");	
	for(i=0;i<a.length;i++){
		a[i].setAttribute("readOnly",status);
	}
}


//Ham sinh 1 chuoi ngau nhien

function GenerateRandomString(Length){

	var s = new Array;
	var n,i;
	for(i=0;i<Length;i++){
		do{
		n = Math.round(Math.random()*127);
		} while (!((n>=48)&&(n<=57)||(n>=65)&&(n<=90)||(n>=97)&&(n<=122)));
		s[i] = String(String.fromCharCode(n));
	}
	var strResult = new String();
	for(i=0;i<Length;i++) strResult = strResult + s[i]
	
	return strResult
}

// End Nguyen Huu An

//e2b48a56-8764-4fe4-a3c9-ed5d0e88a108
function GetPassword(){

document.all.item("e2b48a56-8764-4fe4-a3c9-ed5d0e88a108").value = GenerateRandomString(8);

}
window.attachEvent("onload",function(){WindowOnload()})

function ShowLoading(){
	var objLoading = document.all.item("loadingDIV");
	if (objLoading == null){
		objLoading = document.createElement("<DIV id='loadingDIV' name='loadingDIV'></DIV>")	
		objLoading.style.position = "absolute";		
		objLoading.style.backgroundColor="#CC6600";				
		document.body.appendChild(objLoading)
	}
	
	var strContent = "<img SRC='" + getApplicationURL() + "Image/UI/indicator.gif' WIDTH=16 HEIGHT=16><font color=#FFFFFF>";
	var statusMsg = "Đang xử lý...";
	if (arguments[0] != undefined){
		statusMsg = arguments[0]		
	}
	strContent += statusMsg;
	strContent += "</font>";
	//window.status = statusMsg;
	objLoading.innerHTML = strContent + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";	
	
	objLoading.style.left=0;//(document.body.offsetWidth - objLoading.style.width)/2;
	objLoading.style.top=0;//(document.body.offsetHeight-objLoading.style.height)/2;		
	
	objLoading.style.display="inline";
}

function HideLoading(){
	window.status="";
	var objLoading = document.all.item("loadingDIV");
	if (objLoading){
		objLoading.style.display="none";
	}
	objLoading= parent.document.all.item("loadingDIV");
	if (objLoading){
		objLoading.style.display="none";
	}

}
function Caps(obj){
	if ((window.event.keyCode==8) || ((window.event.keyCode>=35) && (window.event.keyCode<=39))){
		//KeyEnd=35; KeyHome=36; KeyLeft=37; KeyUp=38; KeyRight=39; KeyBack=8;
		return;
	}
	
	var s = new String(obj.value);
	obj.value = s.toUpperCase();
}
function checkValidDate(objNgayDen,objNgayVB){
	return;
	if(objNgayDen.value<objNgayVB.value) {
		alert('Ngày Đến không được nhỏ hơn Ngày Vănn Bản');		
		objNgayDen.value = '';		
	}
}

//tuan anh add
function check_songuyen(number){
	var checkOK;
	checkOK=true;
	checkOK = !isNaN(number);
	if (checkOK){
		var tempNum = parseInt(number);
		if ((tempNum+"").length !=  number.length){							
			checkOK = false;
		}
	}
	return checkOK
	
}
//end


//added by nmthuan
//Kiem tra xem ten dang nhap co hop le khong
/* 
	+ Ten dang nhap chi bao gom cac ky tu HOA, thuong, so va dau underscore "_"
	+ Ten dang nhap phai bat dau bang it nhat 1 ky tu.
	+ Neu trong ten dang nhap co dau "_", thi sau do phai la ky tu hoac so
	(Khong the ket thuc bang dau "_")
*/

function isVNUserName(obj)
{
	var s = obj.value;
	if (s=='') return false;
	regName =/^[a-zA-Z]+[0-9]*([_][a-zA-Z0-9]+)*$/;
	if (s.search(regName)==-1)
	{
		MsgBox("Tên đăng nhập không hợp lệ!<br>Chỉ chấp nhận các ký tự hoa, thường, số và _")
		obj.focus()
		return false;
	}
	return true;
}

function CalendarCancel(objButton){
	var objCalendarContainerCommands = parent.document.getElementsByName("CalendarContainerCommand");

	for (var i = 0; i < objCalendarContainerCommands.length; i++){
		objCalendarContainerCommands[i].style.display = "none";
	}	
}

//nccong Add
//Ham kiem tra nhap theo dinh dang n/m
function isFraction(obj,msg){
	obj.value = trimString(obj.value)
	if(obj.value=="")return;
	var arrData = obj.value.split("/");
	if(arrData.length != 2){
		MsgBox(msg);
		obj.focus();
		return;
	}
	if(isNaN(arrData[0])||isNaN(arrData[1])){
		MsgBox(msg);
		obj.focus();
		return;
	}
	obj.value = trimString(arrData[0]) + "/" + trimString(arrData[1]);
}

//Add by Phan Manh Ha
//Hien thi cac tep noi dung vao eDocmanBodyViewer control
function ajaxBodyViewer(){
	var ActivityStatus ="";
	try{	
		ActivityStatus= document.all.item("ActivityInstanceStatus").value;
	}catch(e){ActivityStatus = "0"}
	if(ActivityStatus == null) ActivityStatus=""
	var allowDeleteFileByFullControllUser = false;
	if(arguments[0] != undefined){
		allowDeleteFileByFullControllUser = arguments[0];
	}
	try{
		if (ActivityStatus>=16){
			//document.all.item("eDocmanFileBrowserIFrame").style.display="none"
		}
	}catch(e){}
	
	var objBodyViewer = document.all.item("eDocmanBodyViewer");
	if (objBodyViewer == null) {
		return false;
	}
	var DocumentID = document.all.item("DocumentID").value;
	var url= getApplicationURL() + "DMS/BodyViewer_backend.asp"
	var query = "strDocumentID=" + DocumentID+ "&allowDeleteFileByFullControllUser="+allowDeleteFileByFullControllUser+"&ActivityStatus="+ActivityStatus;
	
	var req = Initialize(); //AJAX Object
	if(req!=null){		
		req.onreadystatechange = function(){
			if (req.readyState == 4){	
				if (req.status == 200 || window.location.href.indexOf("http")==-1){	
					ret = req.responseText;						
					if (ret != undefined){
						try{							
							objBodyViewer.innerHTML=ret;
						}catch(e){}
					}
				}else{
					alert('error while loading body...');	
				}
			}				
		};
		req.open("GET", url + "?" + query, true);
        req.send(null);        
	}
	return;	
}

//nccong: Xoa mot DocVersionBody (Xoa tep dinh kem)
function doDeleteBodyFile(obj,DocumentID,versionID, DocVersionBodyID,activityStatus,allowEditFileByFullControlUser,allowDeleteFileByFullControllUser,showHeaderFlag){
	if (!eDocConfirm("Có thực sự muốn xóa tệp đính kèm này không?")) return;
	ShowLoading("Đang xóa tệp tin...");
	var url= getApplicationURL() + "DMS/BodyViewer_backend.asp"
	var query = "strDocumentID=" + DocumentID+"&versionID="+versionID+"&strDocVersionBodyID="+DocVersionBodyID+"&activityStatus="+activityStatus+"&allowEditFileByFullControlUser="+allowEditFileByFullControlUser+"&allowDeleteFileByFullControllUser="+allowDeleteFileByFullControllUser+"&showHeaderFlag="+showHeaderFlag+"&strAction=delete";
	//prompt("", url + "?" + query);
	ajaxpack.postAjaxRequest(url,query,function(){
		var req = ajaxpack.ajaxobj;
		var myfiletype = ajaxpack.filetype;	
		if (req.readyState==4){
		   if (req.status==200 || window.location.href.indexOf("http")==-1){
				if (myfiletype=="txt"){				
					ret = req.responseText;						
					if (ret != undefined){
						var objBodyViewer = document.all.item("eDocmanBodyViewer");					
						if (objBodyViewer==null){
							hiddenTableRow(obj);
						}else{
							objBodyViewer.innerHTML=ret;
						}
						try{
							SetHeight();
						}catch(e){}
						HideLoading();
					}				
				}else {				
				}
			}
		}
	},"txt");
	return;
}
//pmha: Lam an mot Row tren table
function hiddenTableRow(obj){
	var objTR = obj;
	while (objTR.tagName != "TR") objTR = objTR.parentElement;
	objTR.style.display = "none";
}
//pmha: Lay gia tri cuar mot thuoc tinh tren window cha
function getParentPropertyValue(ParentPropertyName){	
	var objParentProperty = parent.document.all.item(ParentPropertyName + "");
	if (objParentProperty==null) objParentProperty = parent.parent.document.all.item(ParentPropertyName + "");
	if (objParentProperty==null) return  undefined;
	return objParentProperty.value;
}

/**In an to trinh

*/
function doPrintProcessInfor(InforName, InforDescription, InforSecretLevel, InforUrgent, printType){
	var DocumentID = document.all.item("DocumentID").value;	
	var ViewID = document.all.item("ViewID").value;
	var ActivityInstanceID = document.all.item("ActivityInstanceID").value;
	var ProcessInstanceID = document.all.item("ProcessInstanceID").value;	
	var url = getApplicationURL()+"Report/ProcessInforViewer.asp?printType="+printType;
	url += "&DocumentID="+DocumentID;
	url += "&ViewID="+ViewID;
	url += "&ProcessInstanceID="+ProcessInstanceID;	
	url += "&ActivityInstanceID="+ActivityInstanceID;
	url += "&InforName="+encodeURI(InforName);
	url += "&InforDescription="+encodeURI(InforDescription);
	url += "&InforSecretLevel="+encodeURI(InforSecretLevel);
	url += "&InforUrgent="+encodeURI(InforUrgent);	
	//openWindow(url, screen.availWidth,screen.availHeight);
	
	var w  = new String(screen.availWidth-10) + 'px';
	var h = new String(screen.availHeight-10) + 'px';		
	goReport(url,h,w,'new','');	
}

function goReport(url,iHeight,iWidth,sNewWindow,sModalWinName) {
	alert('xxx');
	return;
	if(document.all) {
		var xMax = screen.width;
		var yMax = screen.height;
	}
	else {
		if (document.layers) {
			var xMax = window.outerWidth;
			var yMax = window.outerHeight;
		}
		else {
			var xMax = 640;
			var yMax=480;
		}
	}
		
	var xOffset = (xMax - iWidth)/2, yOffset = (yMax - iHeight)/2;
	if (!ModalWin || ModalWin.closed)		
		if(sModalWinName == '')
		{
			//pmhung modify			
			ModalWin = window.open(url,sModalWinName,"screenX="+xOffset+",screenY="+yOffset+",top="+yOffset+",left="+xOffset+",height=" +iHeight + ",width=" + iWidth + ",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,fullscreen=yes");			
		}
		else
		{
			ModalWin = window.showModalDialog(url,sModalWinName,"screenX="+xOffset+",screenY="+yOffset+",top="+yOffset+",left="+xOffset+",height=" +iHeight + ",width=" + iWidth + ",status=yes,toolbar=no,menubar=no,location=no");
		}
	else 
		ModalWin.focus();
		
}

function ReCalculateFormula(obj1, obj2){	
	if(arguments[2] != "BackEnd"){
		var objPro = obj1; var objDependPro= obj2;
		AddHiddenItem(objPro, objPro.name + "_ReCalculateFormula", objPro.name);
		if (objDependPro){
			AddHiddenItem(objDependPro, "DependPropertyID", objDependPro.name);
			AddHiddenItem(objDependPro, "DependPropertyID", objDependPro.value);
		}
		return;
	}
	var ret = "";
	var strFormula = obj1.Formula;
	var SelectedItemID = obj2.name;
	var strValue = obj2.text;	
	if (strValue ==undefined) strValue = "";
	if (strValue =="null") strValue = "";
	if (strValue =="") strValue = obj2.value;
	var url= getApplicationURL() + "Common/AjaxProcess/ajax.asp";
	var DependPropID = new String(obj2.name);
	DependPropID = DependPropID.substr(0,36);
	var query = "TypeProcess=ReCalculate&PropID=" + obj1.name + "&value=" + encodeURI(strValue);
	query +=  "&ViewID=" + document.all.item("ViewID").value;	 
	query +=  "&DocumentID=" + document.all.item("DocumentID").value;	 
	query +=  "&ViewType=" + document.all.item("ViewType").value;	 
	query +=  "&DependPropID=" + DependPropID;
	ajaxpack.getAjaxRequest(url,query,function(){
			var req = ajaxpack.ajaxobj;
			var myfiletype = ajaxpack.filetype;	
			if (req.readyState==4){		
			   if (req.status==200 || window.location.href.indexOf("http")==-1){
					if (myfiletype=="txt"){	
						ret = req.responseText;	
						if (ret == undefined) ret = "";
						obj1.value = ret;
						return;						
					}
				}
			}		
		},"txt");
		obj1.value = '1';

}

//nccong: Xoa 1 dong cua 1 Table
//Tham do dau vao la doi tuong TR can xoa
function DeleteRow(objTR){
	try{
		var objTable = objTR.parentElement;
		for(var i = 0; i < objTable.rows.length; i++){
			if(objTable.rows[i] == objTR){
				objTable.deleteRow(i);
				return;
			}
		}
	}catch(e){}
}


function tuyChinhOnClick(obj){
	var objForm = obj;
	while (objForm.tagName != "FORM") objForm = objForm.parentElement;
	objForm.action = "../DMS/customize.asp?ObjectType=3";
	objForm.method= "post";
	objForm.submit();
}


//Added by Nguyen Huu An
function AddnewCatalog(sID, sLookupID, sLookupDocType, isZippy){
   //Neu chua co PropertyID thi thoi  
   var sLookupIDTemp = new String(sLookupID); 
   if (sLookupIDTemp.length==0) { 
       ShowModalWindow(getApplicationURL()+'Common/MsgBox.asp?Message=Chưa có thuộc tính tham chiếu!&MsgType=0',450,150); 
       return; 
   } 
   var strRetVal = new String();
   var strURL = escape(getApplicationURL()+ 'Common/Catalog/AddnewCatalog.asp?PropertyID='+sID+'&LookupID='+sLookupID+'&LookupDocType='+sLookupDocType);
   
   strRetVal = ShowModalWindow(getApplicationURL()+ 'Common/CommonDialog/Dialog.asp?strURL=' + strURL,640,480);
   if ((strRetVal != '$')&& (strRetVal != undefined ) ){
	document.all.item(sID).value = strRetVal; 
    }     
}

//---------------------------------------------------------------------------------

//---------------------------------------------------------------------------------
/**Created by Hoang Van Huong */
//---------------------------------------------------------------------------------
/**
/*Sao chep du lieu tu 1 tai lieu, tai lieu duoc tim kiem ngay tren view
*/
function CopyPropertiesFromDoc(obj){
	
	
	var DocTypeID = ''
	
	try{
		document.all.item("ViewID").value = DocTypeID;
	}catch(ex){
		document.all.item("ViewID").value = obj.value;
	}
	
	var objCopyPropertiesFromDocFlag = document.all.item("CopyPropertiesFromDocFlag");
	
	var objForm = obj;
	
	while(objForm.tagName != "FORM")
		objForm = objForm.parentElement;
	
	if (objCopyPropertiesFromDocFlag==null){		
		objCopyPropertiesFromDocFlag= document.createElement("INPUT");
		objCopyPropertiesFromDocFlag.name = "CopyPropertiesFromDocFlag";
		objCopyPropertiesFromDocFlag.id= "CopyPropertiesFromDocFlag";
		objCopyPropertiesFromDocFlag.style.display = "none";
		objCopyPropertiesFromDocFlag.value = "true";
		objForm.appendChild(objCopyPropertiesFromDocFlag);
	}
	else{
		objCopyPropertiesFromDocFlag.value = "true";
	}	

	disableButton('');
	var str = window.location.href;
	if ((str.toLowerCase().search("viewid=")!=-1) && (DocTypeID!="")){
		str = str.replace(str.substr(str.toLowerCase().search("viewid=")+7,36), DocTypeID);
		objForm.action = str;
	}
	document.all.item("CustomizeHiddenControl3").value = "FocusToTxtPreside";
	document.all.item("CustomizeHiddenControl4").value = "FindFlag";
	objForm.submit();
	obj.disabled=true;
}

//---------------------------------------------------------------------------------


//---------------------------------------------------------------------------------
/**Created by Hoang Van Huong */

//---------------------------------------------------------------------------------
/**
/*lay ma va ten ho du du kien tu module cua iLib cung cap (chac chi dung cho btc thoi)
*/
function GetFilingCode(){
		var sFileCode = '';
		var sFileName = '';
		var sPreservationPeriodCode ='';
		var sPreservationPeriodName ='';
		
		var objPreservationPeriodCode=document.forms.item('frmDMSView').item('b46efd71-a96c-49b7-9660-53dc1e3e0410');
		var objPreservationPeriodName = document.forms.item('frmDMSView').item('028bf530-b6f1-4ee4-b486-628492126b2f');
		
		var objFileCode = document.forms.item('frmDMSView').item('699539c9-0290-44af-8f11-5b925d4d6311');
		var objFileName = document.forms.item('frmDMSView').item('c3994628-6464-41a8-be70-0e5abd8b1f86');
		
		var objFocus =document.forms.item('frmDMSView').item('a90c9249-90d3-4593-978d-6fe36fb6f719');  //focus tai ngay mo ho so
		
		//var objPreservationPeriodCode =document.all.item('b46efd71-a96c-49b7-9660-53dc1e3e0410');
		//var objPreservationPeriodName = document.all.item('028bf530-b6f1-4ee4-b486-628492126b2f');
		
		//var objFileCode = document.all.item('699539c9-0290-44af-8f11-5b925d4d6311');
		//var objFileName = document.all.item('c3994628-6464-41a8-be70-0e5abd8b1f86');
		
		//var objFocus =document.all.item('a90c9249-90d3-4593-978d-6fe36fb6f719');  //focus tai ngay mo ho so
		
		
		var strURL = 'dialogGetFiling.asp?PageType=1'
		
		var result=window.showModalDialog(strURL,'',"dialogHeight:"+ screen.height.toString() +" px; dialogWidth:"+ screen.width.toString() +" px;status:no;scroll:yes");
		
		if (result == undefined) {		
			objFileCode.value ='';
			objFileName.value='';
			objPreservationPeriodCode.value = '';
			objPreservationPeriodName.value = '';
			return;
		}	
		
		else {		
			
			var arrResult = result.split("|");
			
			sFileCode +=  arrResult[0];
			sFileName += arrResult[1];
			
			sPreservationPeriodCode +=  arrResult[2];
			sPreservationPeriodName += arrResult[3];
			
			objFileCode.value = sFileCode;
			objFileName.value = sFileName;
			
			
			objPreservationPeriodCode.value = sPreservationPeriodCode;
			objPreservationPeriodName.value = sPreservationPeriodName;
			
			
		}
		
		//objFileCode.readOnly = true;
		//objFileName.readOnly = true;
		objFocus.focus();
}

function PrintControlValue(objName){
	window.open(getApplicationURL()+ 'included/asp/print.asp?control='+ objName,'_blank');
}

function BuiltProcessResolveInfor(){
	var NguoiTrinh = document.all.item("CurrentUserFullName")!= undefined?document.all.item("CurrentUserFullName").value:"";
	var NgayTrinh = document.all.item("NgayTrinh") != undefined?document.all.item("NgayTrinh").value:"";
	var LanhDaoTrinh = document.all.item("LanhDaoTrinh") != undefined?document.all.item("LanhDaoTrinh").value:"";
	var NgayTra = document.all.item("NgayTra") != undefined?document.all.item("NgayTra").value:"";
	var YKienLanhDao = document.all.item("YKienLanhDao") != undefined?document.all.item("YKienLanhDao").value:"";
	var objProcessResolveInfor = document.all.item("eDocmanProcessResolveInput");

	var RetVal = "";
	if(LanhDaoTrinh !=""){
		RetVal += LanhDaoTrinh + "; ";
		if(NgayTrinh != "")RetVal += "Ngày trình: " + NgayTrinh + "; ";
		if(NgayTra != ""){
			RetVal += "Ngảy trả: " + NgayTra + "; ";
			RetVal += "Ý kiến: " + YKienLanhDao;
		}
		RetVal += " [" + NguoiTrinh + "]";
	}
	objProcessResolveInfor.value = RetVal;
}
/*
nccong: Ham tra Ngay va gio hien tai theo dinh dang DD/MM/YYYY HH:mm:SS
*/
function GetCurrentDateTime(){
	var now = new Date();
	return now.getDate() + "/" + (now.getMonth()+1) + "/" + now.getFullYear() + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
}

function FillDisplayName(objCode, objName)
{

try{
if(document.all.item(objCode.name + '_ex').value.length > 0){
	objName.value = document.all.item(objCode.name + '_ex').value;
}	
}
catch(ex){}
}
//Ham lay chu tri, phoi hop, lanh dao xu ly tren NextActivityControl
/*
lanh dao xu ly: 02ebdba8-f888-4998-8804-89a94869cef7
chu tri xu ly:  798c6964-7865-4fb4-84ff-c74f8c251286
phoi hop xl: effa55cc-49c2-40a3-8120-94eca5a5893f
*/
function LayChuTriPhoiHop()
{
	try{
		// Chu tri
		var objLanhDao = document.all.item('02ebdba8-f888-4998-8804-89a94869cef7');
		var objChuTri = document.all.item('798c6964-7865-4fb4-84ff-c74f8c251286');
		var objPhoiHop = document.all.item('effa55cc-49c2-40a3-8120-94eca5a5893f');
		  	
		if(document.all.item('txtPreside_ex').value.length > 0){
			if (document.all.item('txtPreside').value=="90" ||document.all.item('txtPreside').value=="91"){
				objLanhDao.value = document.all.item('txtPreside_ex').value; // Lanh dao xu ly
				objChuTri.value	 = document.all.item('txtPreside_ex').value; // chu tri xu ly
			}else{
				objChuTri.value	 = document.all.item('txtPreside_ex').value; // phoi hop xu ly	
			}
			if (objPhoiHop.value.search(objChuTri.value) != -1 ){
			    objPhoiHop.value = objPhoiHop.value.replace(objChuTri.value,"");
			    objPhoiHop.value = objPhoiHop.value.replace(";;",";");
			    if (objPhoiHop.value.substring(0,1) == ";"){
			        objPhoiHop.value = objPhoiHop.value.substring(2,objPhoiHop.value.length)
			    }
			}
		}	
		// Phoi hop
		if(document.all.item('txtCoodinate_ex').value.length > 0){
		    if (objPhoiHop.value.length > 0){
		        var temp;
		        temp = CheckCandidateName(document.all.item('txtCoodinate_ex').value,objPhoiHop.value)
			    objPhoiHop.value = temp;
			}else{
			    objPhoiHop.value	 = document.all.item('txtCoodinate_ex').value;
			}    
			
		}	
		
	}
	catch(ex){}
}

function CheckCandidateName(sChuyenDi,sDaDanhDau){
	var arrChuyenDi = sChuyenDi.split(";");
	
	var tmp = sDaDanhDau;
	if (tmp.substr(tmp.length-1,1) ==';'){
		tmp = tmp.substr(0,tmp.length-1);
	}
	for(var i = 0 ; i <arrChuyenDi.length;i++){
		if (tmp.search(arrChuyenDi[i]) == -1 ){
			tmp += '; ' + arrChuyenDi[i] ;
		}
	}
	if (tmp.substr(tmp.length-1,1) ==';'){
		tmp = tmp.substr(0,tmp.length-1);
	}	
	return tmp;
}

// convert boolean value
function CBool(val)
{
	if(typeof(val) == "string")
		val = val.toLowerCase().replace(/false/,"");
		
	return (new Boolean(val).valueOf());
}

function GetAllComboValue(cboName){
	
	var objCombo = document.all.item(cboName);
	var ret = "((DOCUMENT_TYPE_ID contains ";
	//alert(objCombo);
	if(objCombo != undefined){
		for(var i=0; i<objCombo.length;i++){
			if (objCombo.item(i).value.trim()!= ""){				
				ret += "("+objCombo.item(i).value +"))";
				if (i<(objCombo.length-1)) ret += " or (DOCUMENT_TYPE_ID contains ";
			}
		}
		ret+=")";
	}
	return ret;
}

//nccong: 20071023
//Xu ly tra lai nguoi uy quyen
function DelegateBackward(ActivityInstanceID){
	var url= getApplicationURL() + "Common/AjaxProcess/ajax.asp"
	var query = "TypeProcess=DelegateBackward&ActivityInstanceID=" + ActivityInstanceID;
	//prompt("URL",url + "?" + query);
	var req = Initialize(); //AJAX Object 
	if(req!=null){		
		req.onreadystatechange = function(){
			if (req.readyState == 4){	
				if (req.status == 200 || window.location.href.indexOf("http")==-1){	
					ret = req.responseText;
					if (ret != undefined){
						try{
							if(ret == 'Finished'){
								var strAction = document.all.item("strAction");
								if(strAction != undefined){
									strAction.value = "cmdDelegateBackward"
									var objForm = strAction;
									while(objForm.tagName != "FORM"){
										objForm = objForm.parentElement;
									}
									objForm.submit();
								}
							}
							return;
						}catch(e){}
					}
				}else{
					eDocAlert("PublicFunction.js|DelegateBacward:Lỗi hệ thống Backend, liên hệ với nhà phát triển!");	
				}
			}				
		};		
		req.open("GET", url + "?" + query, true);
		req.send(null);
	}
	return;
}

/*
nccong: 24/10/2007
Check trung nhieu thuoc tinh tren 1 View
Ham nay truoc nccong viet trong AjaxProcess.js, khong nho la viet tu khi nao
Nhung xu ly chua tong quat
Gio viet lai tong quat hon
*/
function CheckExistingMultiItem(obj){

	var DocTypeID = document.all.item('ViewID') != undefined?document.all.item('ViewID').value:"";
	var DocTypeComboID = document.all.item('eDocmanDocumentType') != undefined?document.all.item('eDocmanDocumentType').value:""; 

	if (DocTypeID != DocTypeComboID && DocTypeComboID != ""){
		DocTypeID = DocTypeComboID;
	}
	
	DocumentID = document.all.item("DocumentID") != undefined? document.all.item("DocumentID").value:"";
	
	var arrPropertyID = "";
	var PropertyIDs = document.all.item("CheckExistingContainer")==undefined?"":document.all.item("CheckExistingContainer").value;
	var Messages = document.all.item("ExistingMsgContainer") != undefined?document.all.item("ExistingMsgContainer").value:document.all.item("CustomizeHiddenControl1").value;
	var ForceCheck = document.all.item("ForceCheckContainer") != undefined?document.all.item("ForceCheckContainer").value:document.all.item("CustomizeHiddenControl2").value;
	
	var PropertyValues = "";
	var PropertyValueTemp = "";
	var PropertyTypes = "";
	var PropertyTypeTemp = "";
	var	customizeforMOF = false;
	
	// Neu khong co thuoc tinh quy dinh check trung thi check cac thu khac	
	if(PropertyIDs==""){
		CheckRequired(obj);
		return;
	}	
	// Bat buoc phai nhap chu tri truoc
	//try{
	//	var objActivityInstanceStatus = document.all.item('ActivityInstanceStatus');
	//	if (objActivityInstanceStatus != undefined) {
	//		if (objActivityInstanceStatus.value != 16){ 
	//			CheckRequired(obj);
	//			return;
	//		}
	//	}//objActivityInstanceStatus
	//}catch(e){}
								
	/////// Customize for MOF ///////
	// Neu Chu tri, Phoi hop khong phai la 90 hoac 91
	try{
		var objPreside = document.all.item('txtPreside');
		var objCoodinate = document.all.item('txtCoodinate');
		if (objPreside != undefined){
			if (!(objPreside.value=="90"||objPreside.value=="91")||(objCoodinate.value=="90"||objCoodinate.value=="91")){			
				CheckRequired(obj);
				return;
			}
			else{
				customizeforMOF = true;
			}	
		}//objPreside 
	}catch(e){}

	// Neu la 90 hoac 91 la chu tri nhung So Hieu va Ky hieu khong nhap thi cung khong can check trung nua
	try{
		if (document.all.item('f73e808c-3000-4846-b799-5f429be35df2').value == "" && document.all.item('5c50eac0-b0be-4235-8953-eab2a1fbaf55').value == ""){
			CheckRequired(obj);
			return;
		}
	}catch(e){}
	///////// End Customize for MOF /////////
	
	var arrGroup = PropertyIDs.split("eDocSplitGroup");
	var arrItem = new Array();
	for(var i=0; i<arrGroup.length; i++){
		arrItem = arrGroup[i].split("eDocSplitItem");
		PropertyValueTemp = "";
		PropertyTypeTemp = "";
		for(var j=0; j<arrItem.length; j++){
			PropertyValueTemp = j==0?document.all.item(arrItem[j]).value:PropertyValueTemp + "eDocSplitItem" + document.all.item(arrItem[j]).value;
			PropertyTypeTemp = j==0?document.all.item(arrItem[j]).typeRequired:PropertyTypeTemp + "eDocSplitItem" + document.all.item(arrItem[j]).typeRequired;
		}
		PropertyValues = PropertyValues==""?PropertyValueTemp:PropertyValues + "eDocSplitGroup" + PropertyValueTemp;
		PropertyTypes = PropertyTypes==""?PropertyTypeTemp:PropertyTypes + "eDocSplitGroup" + PropertyTypeTemp;
	}

	var url= getApplicationURL() + "Common/AjaxProcess/ajax.asp"
	var query = "TypeProcess=checkExistingMultiItem&DocTypeID=" + DocTypeID + "&PropertyIDs=" + PropertyIDs + "&PropertyValues=" + encodeURI(PropertyValues)+"&PropertyTypes=" + PropertyTypes + "&Messages=" + encodeURI(Messages) + "&ForceCheck=" + ForceCheck + "&DocumentID=" + DocumentID +"&customizeforMOF="+ customizeforMOF;
	//prompt("URL Dang PT: ",url + "?" + query);
	//document.write(query);

//	return;
	var req = Initialize(); //AJAX Object 
	if(req!=null){		
		req.onreadystatechange = function(){
			if (req.readyState == 4){	
				if (req.status == 200 || window.location.href.indexOf("http")==-1){	
					ret = req.responseText;
					if (ret != undefined){//Backend da tra ve
						if(ret != ''){//ret !='' la bi trung
							try{
								if(ret.split("eDocSplit")[1].toLowerCase() == "false" ){
									if (eDocConfirm(ret.split("eDocSplit")[0])){
										CheckRequired(obj);
										return;
									}else{
										return;
									}
								}else{
									eDocAlert(ret.split("eDocSplit")[0]);
									return;
								}
							}catch(e){}
						}else{
							CheckRequired(obj);
							return;
						}//ret != ''
					}//ret != undefined
				}else{//status
					//eDocAlert("PublicFunction.js|CheckExistingMultiItem: L&#7895;i h&#7879; th&#7889;ng Backend, liên h&#7879; v&#7899;i nhà phát tri&#7875;n!");
					eDocAlert("Dữ liệu nhập vào không hợp lệ, yêu cầu kiểm tra lại!");
				}//status 
			}//readyState 				
		};//function	
		req.open("GET", url + "?" + query, true);
		req.send(null);
	}//req!=null
	return;
}// function








//Ham lay so rieng tren viewShow
function LaySoRieng(obj){
	return;
	var DocTypeID = document.all.item('ViewID') != undefined?document.all.item('ViewID').value:"";
	var DocTypeComboID = document.all.item('eDocmanDocumentType') != undefined?document.all.item('eDocmanDocumentType').value:""; 

	if (DocTypeID == DocTypeComboID ){
		obj.value = parseInt(obj.value)-1;
	}
}


function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
	    { 
	    c_start=c_start + c_name.length+1 ;
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
	    } 
	  }
	return "";
}

function setCookie(c_name,value,expiredays)
{
	try{
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	}catch(e){MsgBox('Không ghi lại được ngày mặc định. Phải cho phép ghi Cookies trên trình duyệt')}
		
}

function checkCookie(cookiesName)
{
	var retval = getCookie(cookiesName);
	if (retval!=null && retval!="" && retval!=undefined ){
		return retval;
	}
	else{
		return "";
	}
	
}
//hvhuong:
function setProcessResolveTemplate(obj) {
	try {
		if (window.event.keyCode == 13) {
				document.all('eDocmanProcessResolveInput').value=obj.value;
				obj.value='';
			}
	} catch(e) {}
}
function OpenRecall(){
	var DocumentID ;
	DocumentID = "";
	var objOptList; 
		objOptList = document.all.item("RecallSelected");
		if (objOptList != undefined){
			if (objOptList.length != undefined){ // co 2 option tro len
				for (var i = 0; i < objOptList.length ; i++){
					if (objOptList[i].checked){
						DocumentID = objOptList[i].id;		
						break;
					}
				}
			}	
			else{
				DocumentID = objOptList.id;	
			}	
			
			if(DocumentID.toString().length > 0){
				var strURL = getApplicationURL() + "Common/CommonDialog/Dialog.asp?strURL=" + getApplicationURL() + "DMS/Recall.asp?documentid=" + DocumentID ;
				ShowModalWindow(strURL,600,400);
				
			}else{
				eDocAlert("Phải chọn văn bản để thu hồi!");
			}
		}else{
			eDocAlert("Phải chọn văn bản để thu hồi!");
		}
			
		
}


//nccong: 15/02/2008

function AddWorkingdayV20(objSrc, n, objDes){

    var url= getApplicationURL() + "Admin/WorkingDayConfig_BackEnd.asp";

    var query = "sType=AddWorkingday&srcDate=" + FormatDate(objSrc.value,"DD/MM/YYYY","MM/DD/YYYY") + "&inteval=" + n;
    

    //prompt('xx',url + '?' + query);

    //return;

    ajaxpack.postAjaxRequest(url,query,function(){

                var req = ajaxpack.ajaxobj;

                var myfiletype = ajaxpack.filetype;           

                if (req.readyState==4){                

                   if (req.status==200 || window.location.href.indexOf("http")==-1){

                                        if (myfiletype=="txt"){                                          

                                                    ret = req.responseText;  

                                                    if (ret != undefined){

                                                                //objDes.value = FormatDate(ret,"MM/DD/YYYY","DD/MM/YYYY");
                                                                objDes.value = ret;

                                                    }                                               

                                        }else {

                                                    eDocAlert("CÃ³ lá»—i xáº£y ra khi cáº­p nháº­t dá»¯ liá»‡u.");

                                        }

                            }

                }

    },"txt");

    return;

}

//hvhuong modified: 08/05/2008

function AddWorkingdayV25_OLD(objSrc,objDes,ProcessDefinitionID){

    var url= getApplicationURL() + "Admin/WorkingDayConfig_BackEnd.asp";

    var query = "ProcessDefinitionID=" + ProcessDefinitionID + "&sType=AddWorkingdayFromWorkflowConfig&srcDate=" + FormatDate(objSrc.value,"DD/MM/YYYY","MM/DD/YYYY");
    

    //prompt('xx',url + '?' + query);

    //return;

    ajaxpack.postAjaxRequest(url,query,function(){

                var req = ajaxpack.ajaxobj;

                var myfiletype = ajaxpack.filetype;           

                if (req.readyState==4){                

                   if (req.status==200 || window.location.href.indexOf("http")==-1){

                                        if (myfiletype=="txt"){                                          

                                                    ret = req.responseText;  

                                                    if (ret != undefined){

                                                                //objDes.value = FormatDate(ret,"MM/DD/YYYY","DD/MM/YYYY");
                                                                objDes.value = ret;

                                                    }                                               

                                        }else {

                                                    eDocAlert("CÃ³ lá»—i xáº£y ra khi cáº­p nháº­t dá»¯ liá»‡u.");

                                        }

                            }

                }

    },"txt");

    return;

}

function AddWorkingday(objSrc,objDes,ProcessDefinitionID){	
	try{
		var req; //AJAX Object
		req = Initialize();
    	
    	if (arguments[2] == undefined || arguments[2] == '')	{
    		
    		ProcessDefinitionID = document.all.item('ProcessDefinitionID').value;
    	}
    	
		var url= getApplicationURL() + "Admin/WorkingDayConfig_BackEnd.asp?ProcessDefinitionID=" + ProcessDefinitionID + "&sType=AddWorkingdayFromWorkflowConfig&srcDate=" + FormatDate(objSrc.value,"DD/MM/YYYY","MM/DD/YYYY");
		
		if(req!=null){
			req.onreadystatechange = function(){			
				var ajaxResult = ProcessAjax(req);
				if (ajaxResult == undefined) ajaxResult = "";
				if (ajaxResult != ""){
					if (req.readyState == 4){
						if (req.status==200 || window.location.href.indexOf("http")==-1){
							objDes.value = ajaxResult;
						}
						else{
							eDocAlert("CÃ³ lá»—i xáº£y ra khi cáº­p nháº­t dá»¯ liá»‡u.");
						}
					}		
				}
			};
			
		    req.open("GET", url, true);
		    req.send(null);
		}
	}catch(e){}			
}

function AddToFavorite(isSearchView) {
	
	
	var documentID="";
	
	if (isSearchView=='false')
	{
		try{
			documentID = document.all.item("DocumentID").value;		
		}catch(e){
			documentID = document.all.item("strSourceDocumentID").value;		
		}
	}
	else
	{
		documentID = "";
		var objCheckList; 
		try {
		
			objCheckList = document.all.item("FavoriteSelected");
			
			if (objCheckList != undefined){
				if (objCheckList.length != undefined){ // co 2 check tro len
					for (var i = 0; i < objCheckList.length ; i++){
						if (objCheckList[i].checked){
							documentID = documentID + objCheckList[i].id + '_';		
						}
					}
				}	
				else{
					documentID = "";	
				}	
			}
		}
		catch(e){documentID="";}
		
		if (documentID == '')
		{
			MsgBox('De nghi chon tai lieu de dua vao hay dung');
			return;
		}
	}

	try{
		with (document.all){
			
			
			var strDocumentTypeID = "000000000000000000000000000000000003";
			var strDocSpaceIDs = "000000000000000000000000000000000003";
			var url = getApplicationURL() + "Common/CommonDialog/Dialog.asp?strURL=" + escape("DocBrowse.asp?AddToFavorite=true&strDocSpaceIDs=" + strDocSpaceIDs  + "&strDocumentTypeID=" + strDocumentTypeID + "&DocumentID=" + documentID + "&DocBrowse=true");
			
			var strResult = window.showModalDialog(url, 0 , "resizable:no;dialogWidth:650px;dialogHeight:600px;status:no");
		}
	}catch(e){}
	
	

}

function AddToBrief(isSearchView) {
	
	
	var documentID="";
	
	if (isSearchView=='false')
	{
		try{
			documentID = document.all.item("DocumentID").value;		
		}catch(e){
			documentID = document.all.item("strSourceDocumentID").value;		
		}
	}
	else
	{
		documentID = "";
		var objCheckList; 
		try {
		
			objCheckList = document.all.item("FavoriteSelected");
			
			if (objCheckList != undefined){
				if (objCheckList.length != undefined){ // co 2 check tro len
					for (var i = 0; i < objCheckList.length ; i++){
						if (objCheckList[i].checked){
							documentID = documentID + objCheckList[i].id + '_';		
						}
					}
				}	
				else{
					documentID = "";	
				}	
			}
		}
		catch(e){documentID="";}
		
		if (documentID == '')
		{
			MsgBox('De nghi chon tai lieu de dua vao ho so');
			return;
		}
	}
	
	try{
		with (document.all){
			
			
			var strDocumentTypeID = "000000000000000000000000000000000002";
			var strDocSpaceIDs = "000000000000000000000000000000000002";
			var url = getApplicationURL() + "Common/CommonDialog/Dialog.asp?strURL=" + escape("DocBrowse.asp?AddToBrief=true&strDocSpaceIDs=" + strDocSpaceIDs  + "&strDocumentTypeID=" + strDocumentTypeID + "&DocumentID=" + documentID + "&DocBrowse=true");
			
			var strResult = window.showModalDialog(url, 0 , "resizable:no;dialogWidth:650px;dialogHeight:600px;status:no");
		}
	}catch(e){}
	
	

}

function CloseCurrentDIV(){
	try{
		
		var divName = "DetailDocumentDIV";	
		if (arguments[0] != undefined){
			divName = arguments[0];
		}	
		var objDetailDocument = document.getElementById(divName);
		if (objDetailDocument != null){
			//document.body.removeChild(objDiv);
			document.body.removeChild(objDetailDocument);
		}
	}catch(e){}			
}

//nccong: lay ID cua SuggestBox
function GetSuggestBoxID(obj,strName){
	SuggestList_OnBlur(obj);
	AddHiddenItem(obj,strName,document.all.item(obj.id + "_ex").value);
	
	//-----------------------------------------------------------------
	//{Begin: lqminh: An/hien Duong chuyen Lien van phong}
	//-----------------------------------------------------------------
	var oLI = document.getElementsByTagName('LI');
	for (var i = 0; i < oLI.length ; i++){
		if (oLI[i].iname.search('InterOfficeTransition') != -1){
			if (obj.value != '')
				oLI[i].style.display='';
			else
				oLI[i].style.display='none';
				
			break;
		}
	}//{End: lqminh: An/hien Duong chuyen Lien van phong}
	//-----------------------------------------------------------------
}

function GetFaxReceive(obj){
	SuggestList_OnBlur(obj);
	AddHiddenItem(obj,"FaxRecipents",document.all.item(obj.id + "_ex").value);
}

//pmHung added
//Date: 05/09/2008
//Purpose: Expand or Collapses Report Components
function CollapsesExpands(nameDIV, sID, sVirtualPathNameImage){
	var status = document.all.item("Status").value;
	
	if (document.all.item(nameDIV).style.display=='block'){
		document.all.item(nameDIV).style.display='none';
		document.all.item("Status").value = status.replace(nameDIV + "(block)",nameDIV + "(none)");
		document.all.item(sID).src= sVirtualPathNameImage + "Collapses.gif";
	} else {
		document.all.item(nameDIV).style.display='block';
		document.all.item("Status").value = status.replace(nameDIV + "(none)",nameDIV + "(block)");
		document.all.item(sID).src= sVirtualPathNameImage + "Expands.gif";
	}
}
/*
11/04/2009: nccong add
Ham gui thong bao
*/
function AddNewAlert(SendType){
	try{
		var DocumentID = document.all.item("DocumentID").value;
		var Message = document.all.item("Message").value;

		if(DocumentID == "" || Message == ""){
			eDocAlert("Thông tin nội dung thông báo chưa đầy đủ, hãy kiểm tra lại.");
			return;
		}

		var req; //AJAX Object 
		req = Initialize();
		var url= getApplicationURL() + "Included/ASP/AddNewAlert_BackEnd.asp?SendType=" + SendType;
		url += "&DocumentID=" + encodeURI(DocumentID);
		url += "&Message=" + encodeURI(Message);

	//	prompt("",url);
	//	return;
		if(req!=null){		
			req.onreadystatechange = function(){
				var ajaxResult = ProcessAjax(req);
				if (ajaxResult != undefined){
					if (ajaxResult.toLowerCase() == "true"){
						eDocAlert("Thực hiện gửi thông báo thành công.");
					}else{
						eDocAlert("Có lỗi trong quá trình gửi thông báo, đề nghị liên hệ với quản trị để biết thông tin chi tiết.");
					}
					return;
				}
			};
			req.open("GET", url, true);
	        req.send(null);  
		}	
	}catch(e){eDocAlert("Có lỗi trong quá trình gửi thông báo, đề nghị liên hệ với quản trị để biết thông tin chi tiết.");}
}
/*
Add by nccong: 11/05/2009
Ham xu ly cho View cua Thu muc phan biet Favorite hay khac Favorite
Neu khong phai Favorite: Show Mo ta
Neu la Favorite: Show checkbox Phan quyen
*/
function CheckFavorite(objPhanQuyen, objMoTa){
	var objDocspaceID=document.all.item("strDocSpaceID");
	var IsFavorite=false;
	if(objDocspaceID != null){
		if(objDocspaceID.value=="000000000000000000000000000000000003"){
			IsFavorite = true;
		}
	}
	var objTR;
	if(IsFavorite){
		objTR = objMoTa;
	}else{
		objTR = objPhanQuyen;
	}
	while(objTR.tagName != "TR"){
		objTR = objTR.parentElement;
	}
	objTR.style.display="none";
	objPhanQuyen.checked = objMoTa.value=="ALLOW_INHERITABLE_PERMISSION";
}

/*
Add by nccong: 11/05/2009
Ham xu ly cho Checkbox Phan quyen tren View Thu muc
Neu chon Checkbox: tu Add chuoi ALLOW_INHERITABLE_PERMISSION vao Docdescription
Neu khong chon: Docdescription=""
*/
function AddAllowInheritablePermission(objPhanQuyen, objMoTa){
	objMoTa.value="";
	if(objPhanQuyen.checked){
		objMoTa.value="ALLOW_INHERITABLE_PERMISSION";
	}
}
