function ReportLibrary(ObjXML){
		this.xmlDoc = document.getElementById(ObjXML).XMLDocument;
		this.xmlNodes;
		this.result = true;
		this.length = 0;
		this.xmlDoc.async="false";
		this.getAll = getAll;
		this.search = search;
		this.toHTML = toHTML;
		this.nodeValue = nodeValue;
		this.nodeValue2 = nodeValue2;
	}
	
	function getAll(){
		if (this.result){
			this.xmlNodes = this.xmlDoc.documentElement.childNodes;
			this.length = this.xmlNodes.length; 
		}
	}

	function search(tagname){
		if (this.result){
			this.xmlNodes = this.xmlDoc.getElementsByTagName(tagname);
			this.length = this.xmlNodes.length;
			//alert(this.length)
		}
	}

	function toHTML(fValue, fText, action, id, name, className, hasAction, notAllowAll, otherCaption, isMulti, rows, width){
		var actionStr = "", val = "", stt = 0, length = 0, ids = "~", id = 0, multi = "", widthStr = "";
		if ((action == null) || (action == "")) action = "--ACTION--";
		if ((id == null) || (id == "")) id = "--ID--";
		if ((name == null) || (name == "")) name = "--NAME--";
		if ((className == null) || (className == "")) className = "--CLASS--";
		if (hasAction) actionStr = " onchange='" + action + "'";
		if (isMulti) multi = " multiple size='" + rows + "'";
		if (width) widthStr = " style=\"width:" + width + "\"";
		var innerHTML = "<SELECT " + multi + " ID='" + id + "' Name='" + name + "' class='" + className + "'" + actionStr + widthStr + ">";
		if (this.result){			
			length = this.length;
			if(length > 0){
				if ((otherCaption != null) && (otherCaption != ""))
					innerHTML = innerHTML + "<OPTION VALUE='-2' selected>...</OPTION>";
				if ((length > 1) &&(!notAllowAll))
					innerHTML = innerHTML + "<OPTION VALUE='0'>T&#7845;t c&#7843;</OPTION>";
				for (stt=0; stt<length; stt++){
					id = this.xmlNodes.item(stt).attributes.getNamedItem(fValue).nodeValue;
					if (ids.indexOf("~" + id + "~") < 0){
						ids = ids + id + "~";
						val = this.xmlNodes.item(stt).attributes.getNamedItem(fText).nodeValue;
						//alert(val)
						//val = "";
						innerHTML = innerHTML + "<OPTION VALUE='" + id + "'>" + val + "</OPTION>";
					}
				}
			}
		}
		if (length == 0)
				innerHTML = innerHTML + "<OPTION VALUE='-1'>Kh&#244;ng co&#769;</OPTION>";
		innerHTML = innerHTML + "</SELECT>";
		//alert(innerHTML)
		return innerHTML;
	}
	
	function nodeValue(fName, stt, defaultValue){
		if (this.result){
			if (stt == null) stt = 0;
			if (defaultValue == null) defaultValue = "";
			var length = this.xmlNodes.length;
			if ((length > 0) &&(stt < length)){
				var xmlNode = this.xmlNodes.item(stt).attributes.getNamedItem(fName);
				if (xmlNode != null) 
					return xmlNode.nodeValue;
			}
		}
		return defaultValue;
	}
	
	function nodeValue2(fName, stt, cap, defaultValue){
		if (this.result){
			if (stt == null) stt = 0;
			if (cap == null) cap = 0;
			if (defaultValue == null) defaultValue = "";
			var length = this.xmlNodes.length;
			if ((length > 0) &&(stt < length)){
				var xmlNode = this.xmlNodes.item(stt);
				for (var stt2=0; stt2<cap; stt2++){
					if (xmlNode.hasChildNodes()){
						xmlNode = xmlNode.childNodes.item(0);
					}else{
						xmlNode = null;
						break;
					}
				}
				if (xmlNode != null){
					xmlNode = xmlNode.attributes.getNamedItem(fName);
					if (xmlNode != null) 
						return xmlNode.nodeValue;
				}
			}
		}
		return defaultValue;
	}
	
			
	/* Danh s¸ch c¸c ph­¬ng thøc cã thÓ sö dông ®èi víi c¸c danh môc
	vµ c¸c theo t¸c t×m kiÕm trªn client*/
	
	// Object CapDonVi
	function CapDonVi(xmlCapDV){
		//if (xmlCapDV != "")
		this.library = new ReportLibrary(xmlCapDV + "?AllowAll=1");
		this.toHTML = toHTMLCapDV;
	}
	
	function toHTMLCapDV(maCap, action, id, name, className, hasAction, notAllowAll, otherCaption, isMulti, rows, width){
		if ((maCap != null) &&((maCap > 0) || (maCap == -1)))
			this.library.search("LC_CAP_DON_VI_NGOAI [@ID=" + maCap + "]");
		else this.library.getAll();
		var innerHTML = this.library.toHTML("ID", "TenCap", action, id, name, className, hasAction, notAllowAll, otherCaption, isMulti, rows, width);
		return innerHTML;
	}
	
	// Object DonViHanhChinh
	function DonViHanhChinh(xmlDVHC){
		this.library = new ReportLibrary(xmlDVHC + "?AllowAll=1");
		this.toHTML = toHTMLDVHC;
	}
	
	function toHTMLDVHC(maCap, action, id, name, className, hasAction, notAllowAll, otherCaption, isMulti, rows, width){
		if ((maCap != null) &&((maCap > 0) || (maCap == -1)))
			this.library.search("LC_DON_VI_HANH_CHINH [@MaCapDV=" + maCap + "]");
		else this.library.getAll();
		var innerHTML = this.library.toHTML("ID", "TenDV", action, id, name, className, hasAction, notAllowAll, otherCaption, isMulti, rows, width);
		return innerHTML;
	}
	
	// Object DonViBaoCao
	function DonViBaoCao2(xmlDVBC){
		this.library = new ReportLibrary(xmlDVBC + "?AllowAll=1");
		this.toHTML = toHTMLDVBC;
	}
	
	function toHTMLDVBC(maDVHC, action, id, name, className, hasAction, notAllowAll, otherCaption, isMulti, rows, width){
		if ((maDVHC != null) &&((maDVHC > 0) || (maDVHC == -1)))
			this.library.search("LC_DON_VI_BAO_CAO [@MaDVHChinh=" + maDVHC + "]");
		else this.library.getAll();
		var innerHTML = this.library.toHTML("ID", "TenDV", action, id, name, className, hasAction, notAllowAll, otherCaption, isMulti, rows, width);
		return innerHTML;
	}
	
	// Object LinhVuc
	function LinhVuc(xmlLV){
		this.library = new ReportLibrary(xmlLV + "?AllowAll=1");
		this.toHTML = toHTMLLinhVuc;
	}
	
	function toHTMLLinhVuc(maLV, action, id, name, className, hasAction, notAllowAll, otherCaption, isMulti, rows, width){
		if ((maLV != null) &&((maLV > 0) || (maLV == -1)))
			this.library.search("LC_LINH_VUC_BAO_CAO [@ID=" + maLV + "]");
		else this.library.getAll();
		var innerHTML = this.library.toHTML("ID", "TenLV", action, id, name, className, hasAction, notAllowAll, otherCaption, isMulti, rows, width);
		return innerHTML;
	}
	
	// Object ChiTieu
	function ChiTieu(xmlChiTieu, CapII){
		if (CapII == null) CapII = 0;
		xmlChiTieu = xmlChiTieu + "?CapII=" + CapII + "&AllowAll=1";
		this.library = new ReportLibrary(xmlChiTieu);
		this.toHTML = toHTMLChiTieuCII;
		this.search = searchChiTieu;
		this.nodeValue = nodeValueChiTieu;
	}
	
	function toHTMLChiTieuCII(maCT, action, id, name, className, hasAction, notAllowAll, otherCaption, isMulti, rows, width){
		if ((maCT != null) &&((maCT > 0) || (maCT == -1)))
			this.library.search("LC_CHI_TIEU [@ID=" + maCT + "]");
		else this.library.getAll();
		var innerHTML = this.library.toHTML("ID", "TenChiTieu", action, id, name, className, hasAction, notAllowAll, otherCaption, isMulti, rows, width);
		return innerHTML;
	}
	
	function searchChiTieu(tag){
		this.library.search(tag);
	}
	
	function nodeValueChiTieu(name, stt, defaultValue){
		return this.library.nodeValue(name, stt, defaultValue);
	}
	
	//Object DonViBaoCao
	function DonViBaoCao(xmlDV, MaDV){
		this.library = new ReportLibrary(xmlDV + "?MaDV=" + MaDV + "&AllowAll=1");
		this.toHTML = toHTMLDonViBaoCao;
	}
	
	function toHTMLDonViBaoCao(){
		this.library.getAll();
		
		var innerHTML = this.library.nodeValue("TenDVTT");
		this.library.search("LC_DON_VI_HANH_CHINH");
		var val = this.library.nodeValue("TenDVHC");
		if (val != "") innerHTML = innerHTML + " (" + val + ")";
		return innerHTML;
	}
	
	//Object DonViTTCQN
	/*function DonViTT_CQNgoai(xmlDV, MaDVHC){
		this.library = new ReportLibrary(xmlDV + "?MaDVHC=" + MaDVHC);
		this.toHTML = toHTMLDonViTT_CQNgoai;
	}
	
	function toHTMLDonViTT_CQNgoai(){
		this.library.getAll();
		
		var innerHTML = this.library.nodeValue("TenDVTT");
		this.library.search("LC_DON_VI_HANH_CHINH");
		var val = this.library.nodeValue("TenDVHC");
		if (val != "") innerHTML = innerHTML + " (" + val + ")";
		return innerHTML;
	}*/
	
	function DonViCon(xmlDVCon, maCha){
		if ((maCha == null) || (maCha == "")) maCha = 0;
		this.library = new ReportLibrary(xmlDVCon + "?MaCha=" + maCha + "&AllowAll=1");
		this.toHTML = toHTMLDVCon;
	}
	
	function toHTMLDVCon(MaDVHC, action, id, name, className, hasAction, notAllowAll, otherCaption, isMulti, rows, width){
		if ((MaDVHC != null) &&((MaDVHC > 0) || (MaDVHC == -1)))
			this.library.search("LC_DON_VI_CON [@DVHCID=" + MaDVHC + "]");
		else this.library.getAll();
		var innerHTML = this.library.toHTML("DVTTID", "TenDVTT", action, id, name, className, hasAction, notAllowAll, otherCaption, isMulti, rows, width);
		return innerHTML;
	}
	
	function GetInfo(xmlInfo, maCQ){
		if ((maCQ == null) || (maCQ == "")) maCQ = 0;
		this.library = new ReportLibrary(xmlInfo + "?MaCQ=" + maCQ + "&AllowAll=1");
		this.toHTML = toHTMLInfo;
	}
	
	function toHTMLInfo(MaCQ, MaDVHC, MaDVTT, MaChiTieuCII, DVBCCTName, CQName){
		var innerHTML = "";
		var tagName = "LC_GET_INFO";
		if ((MaCQ != null) && (MaCQ != "") && ((MaCQ > 0) || (MaCQ == -1)))
			tagName = tagName + "[@CQNgoaiID=" + MaCQ + "]";
		if ((MaDVHC != null) && (MaDVHC != "") && ((MaDVHC > 0) || (MaDVHC == -1)))
			tagName = tagName + "[@MaDVHChinh=" + MaDVHC + "]";
		if ((MaDVTT != null) && (MaDVTT != "") && ((MaDVTT > 0) || (MaDVTT == -1)))
			tagName = tagName + "[@MaDVTThuoc=" + MaDVTT + "]";
		if ((MaChiTieuCII != null) && (MaChiTieuCII != "") && ((MaChiTieuCII > 0) || (MaChiTieuCII == -1)))
			tagName = tagName + "[@MaChiTieu=" + MaChiTieuCII + "]";
			
		this.library.search(tagName);
		var val = this.library.nodeValue("DVBCChiTieuID");
		if (val == "") val = 0;
		innerHTML = innerHTML + "<INPUT TYPE='Hidden' NAME='" + DVBCCTName + "' VALUE='" + val + "'>";
		val = this.library.nodeValue("CQNgoaiID");
		if (val == "") val = 0;
		innerHTML = innerHTML + "<INPUT TYPE='Hidden' NAME='" + CQName + "' VALUE='" + val + "'>"
		return innerHTML;
	}
