      var g_xmlSearchDoc = null;                   ///< xml document object, global variable.
      var g_bXmlLoaded = false;       ///< the flag of xml file finishing load.
      var g_currXmlPath = "";
      var g_listSearchRsult = null;


      function srch_ResultClass(nPage, strArea, strText)
      {
         this.nPage = nPage;
         this.strArea = strArea;
         this.strText = strText;
      }
      
      function srch_RectClass(strArea)
      {
			if (strArea == null)
				return;
			
     		var arrParam = strArea.split( ";" );
     		if (arrParam.length != 4)
     			return;
     			
			this.nLeft = parseInt(arrParam[0]);
			this.nTop = parseInt(arrParam[1]);
			this.nRight = parseInt(arrParam[2]);
			this.nBottom = parseInt(arrParam[3]);
		}
      
      /* 
         start to load the xml file.
         @param strUrl : The path of the xml file to load.
      */
      function srch_startXmlLoad(strUrl)
      {
         if (g_bXmlLoaded && g_currXmlPath == strUrl)
            return changeXmlLoadState(4);
            
         if (g_currXmlPath == strUrl)
            return;
         
         g_currXmlPath = strUrl;
         g_bXmlLoaded = false;
         g_listSearchRsult = null;
         
         g_xmlSearchDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
			g_xmlSearchDoc.async = false;          // set asyncronization mode.
			g_xmlSearchDoc.validateOnParse = false;
			g_xmlSearchDoc.resolveExternals = false;
         
         // set load state change handler function 
         g_xmlSearchDoc.onreadystatechange = srch_stateChangeHandler;
         
         // start load xml 
         g_xmlSearchDoc.load(strUrl);
      }
      
      
      function srch_getDoc()
      {
         return g_xmlSearchDoc;
      }
      
      function srch_getDocElementNode()
      {
         if (g_xmlSearchDoc == null || !g_bXmlLoaded)
            return null;
            
         return g_xmlSearchDoc.documentElement;
      }

      function srch_stateChangeHandler()
      {
         try
         {
            var state = g_xmlSearchDoc.readyState;
            if (state == 4 && g_xmlSearchDoc.parseError.errorCode == 0)
            {
               g_bXmlLoaded = true;
            }
            
            // fire change xml load state Event.
            changeXmlLoadState(g_xmlSearchDoc.readyState);
         }
         catch (stateHandle_e) {}
         /*
            switch (xmldoc.readyState)
            {
               case 1:
                  messageDIV.innerHTML += "Status: data uninitialized.<BR>";
                  break;
               case 2:
                  messageDIV.innerHTML += "Status: data loading.<BR>";
                  break;
               case 3:
                  messageDIV.innerHTML += "Status: data loaded.<BR>";
                  break;
               case 4:
                  messageDIV.innerHTML += "Status: data loading complete.<BR>";
                  if (xmldoc.parseError.errorCode != 0) {
                     messageDIV.innerHTML += "Status: error.<BR>";
                  }
                  else {
                     messageDIV.innerHTML += "Status: data loaded alright.<BR>";
                  }
                  
                  messageDIV.innerHTML += "====================================<BR>";
                  break;
            }
         */
      }
      
      /*
      	the function of making search result list by XMLDOMNodeList 
      	@param strText : the text or words to search.
      */
      function srch_makeSearchResult(strText)
      {
			g_listSearchRsult = null;

         var docElementNode = srch_getDocElementNode();
         if (docElementNode == null) 
            return false;
         
         var strXPath = "storage[@type='searchDatas']";
         var searchDatasNode = docElementNode.selectSingleNode(strXPath);
         
         if (searchDatasNode == null)
            return false;
         
         var strSearchText = strText;         
         strSearchText = strSearchText.toLowerCase();
         
         var strQuery = "contains(translate(text() , 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '" + strSearchText + "')";
         strXPath = "page/word[" + strQuery + "]";
         
         g_listSearchRsult = searchDatasNode.selectNodes(strXPath);

        	return true;
		}

	  function srch_makeSearchResult2(strText, nPageID)
      {
			g_listSearchRsult = null;

         var docElementNode = srch_getDocElementNode();
         if (docElementNode == null) 
            return false;
         
         var strXPath = "storage[@type='searchDatas']";
         var searchDatasNode = docElementNode.selectSingleNode(strXPath);
         
         if (searchDatasNode == null)
            return false;
         
         var strSearchText = strText;         
         strSearchText = strSearchText.toLowerCase();
         
         var strQuery = "contains(translate(text() , 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '" + strSearchText + "')";
         strXPath = "page["+nPageID+"]/word[" + strQuery + "]";
         
         g_listSearchRsult = searchDatasNode.selectNodes(strXPath);

        	return true;
		}		
		function srch_isEmptyResult()
		{
         if (g_listSearchRsult == null)
         	return true;
         else if (g_listSearchRsult.length == 0)
         {
				return true;
			}
			else
         	return false;
		}
      
      function srch_getCount()
      {
         if (g_listSearchRsult == null)
         	return 0;
         
         return g_listSearchRsult.length;
		}
      
      function srch_getResultFromIndex(index, resultObj, nWordCount)
      {
      	try {
	         var strPage = g_listSearchRsult.item(index).parentNode.attributes.getNamedItem("pageID").value; 
	         resultObj.nPage = parseInt(strPage);
	         resultObj.strArea = g_listSearchRsult.item(index).attributes.getNamedItem("pos").value;
	         
				var strDisplayText = ""; 
				var currResultNode = g_listSearchRsult.item(index);
				var tempNode = null;
				if (currResultNode != null)
				{
					var i = 0;
					
					// previous text =======================================
					tempNode = currResultNode;
					
					for (i=0; i<nWordCount; i++)
					{
						if (tempNode.previousSibling == null)
							break;
							
						tempNode = tempNode.previousSibling;
						strDisplayText = tempNode.text + " " + strDisplayText;
					}
					if (i >= nWordCount && tempNode.previousSibling != null)		// if it exists previous nodes  
						strDisplayText = "... " + strDisplayText;
					
					// current text =======================================
					tempNode = currResultNode;
					strDisplayText += " " + tempNode.text;
					
					// next text =======================================
					tempNode = currResultNode;
					
					for (i=0; i<nWordCount; i++)
					{
						if (tempNode.nextSibling == null)
							break;
							
						tempNode = tempNode.nextSibling;
						strDisplayText += " " + tempNode.text;
					}
					if (i >= nWordCount && tempNode.nextSibling != null)		// if it exists previous nodes  
						strDisplayText += " ...";
				}
	         //resultObj.strText = g_listSearchRsult.item(index).text;
	         resultObj.strText = strDisplayText;
	         
	      } catch (getRet_e) {
	      	return false;
			}
			
			return true;
		}

		// ¹®ÀÚ¿­¿¡¼­ Æ¯Á¤ ¹®ÀÚ¿­À» strPreTag¿Í strPostTag·Î °¨½ÎÁÖ´Â ¹®ÀÚ¿­·Î Ä¡È¯ÇÏ´Â ÇÔ¼ö.  
		function srch_convertHighlightTag2(strFullText, strHighlightText, strPreTag, strPostTag)
		{
			//var strReplace = '<B style="color:black;background-color:#ffff66">' + strHighlightText + '</B>';
			//var strPreTag = '<B style="color:black;background-color:#ffff66">';
			//var strPostTag = '</B>';
			var strReplace = strPreTag + strHighlightText + strPostTag;
			var re = new RegExp(strHighlightText, "gi");
			return strFullText.replace(re, strReplace);
		}
		
		function srch_convertHighlightTag(strFullText, strHighlightText)
		{
			var strPreTag = '<B style="color:black;background-color:#ffff66">';
			var strPostTag = '</B>';
			return srch_convertHighlightTag2(strFullText, strHighlightText, strPreTag, strPostTag);
		}
