﻿
var pos_X;
var pos_Y;
var inlinewin = null;
document.onmouseover = function (event) {
    if (!event) {
    event = window.event;
    }
    pos_X = event.clientX;
    pos_Y = event.clientY;
  
}



 //Javascript HashTable
         Hashtable.prototype.hash 	 = null;
         Hashtable.prototype.keys 	 = null;
         Hashtable.prototype.location = null;
        function Hashtable(){
	        this.hash = new Array();
	        this.keys = new Array();

	        this.location = 0;
        }
        Hashtable.prototype.get = function (key){
	        return this.hash[key];
        }

        Hashtable.prototype.put = function (key, value){
	        if (value == null)
	        return null;

	        if (this.hash[key] == null)
		        this.keys[this.keys.length] = key;

	        this.hash[key] = value;
        }
//End HashTable






var HashWord = new Hashtable();

var IsAdmin = ClickHandler.GetIsAdmin();
var myDiv = document.getElementById('myWrapper');
// var highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
//  var  highlightEndTag = "</font>";
//  
//  var highlightStartTag = "<span class='highlight' onmouseover=\"PerformMyFunction();\" onmouseout=\" javascript:dhtmlwindow.close(document.getElementById('Meaning'));\">";
//  var  highlightEndTag = "</span>";

  
if(IsAdmin != null && IsAdmin.value != null)
    if(!IsAdmin.value)
    {
        if(myDiv != null)
        {
            var WordListResult = ClickHandler.GetAllWordList();
            if(WordListResult != null && WordListResult.value != null)
            {
                var TblWordList = WordListResult.value;
                 var bodyText = myDiv.innerHTML;
                if(typeof(TblWordList) == "object")
                {
                
                     for (var i = 0; i < TblWordList.Rows.length; i++) {
                        HashWord.put(TblWordList.Rows[i].Word,TblWordList.Rows[i].Description);
                         var highlightStartTag = "<span class='highlight' onmouseover=\"PerformMyFunction('" + TblWordList.Rows[i].Word + "');\" onmouseout=\" javascript:dhtmlwindow.close(document.getElementById('Meaning'));\">";
                         var  highlightEndTag = "</span>";
                        bodyText = doHighlight(bodyText, TblWordList.Rows[i].Word, highlightStartTag, highlightEndTag);
                      }
                      

                  myDiv.innerHTML = bodyText;
                  //alert(myDiv.innerHTML);
                  //return;

                }
            }
        }
    }
    
    
    

 function PerformMyFunction(obj)
 {
     var method = "PerformMyFunction";
     var popUpContent='';
     //get the active category with color
     popUpContent += "<div><strong>" + obj + "</strong><div>" 
     popUpContent += "<div>" + HashWord.get(obj);
     popUpContent += "</div>";
     inlinewin=dhtmlwindow.open("Meaning", "inline",popUpContent, "Meaning", "width=300,height=150,left="+(pos_X)+"px,top="+pos_Y+"px,resize=0,scrolling=0", "recal");
   
 } 


 function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm;
  var lcBodyText = bodyText;
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.toLowerCase().lastIndexOf("/script>", i) >= lcBodyText.toLowerCase().lastIndexOf("<script", i) ) {
           //if(bodyText.substring(0,i) == lcBodyText.substring(i,searchTerm.length))
            //{
            if((bodyText.substr(i-1,searchTerm.length + 2) == " " + searchTerm + " ") || !(alphanumeric(bodyText.substr(i-1,searchTerm.length + 2))))
            {
           
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          
          bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText;
          i = -1;
        }
        }
      }
    }
  }
  //alert(newText);
  return newText;
}


function alphanumeric(alphane)
{
	var numaric = alphane;
	//for(var j=0; j<numaric.length; j++)
		//{
		  var alphaa = numaric.charAt(0);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh == 32 || hh == 228 || hh == 246 || hh == 196)
		  {
		    
		  }
		  else
		  {
		    return false;
		  }
		  
		  alphaa = numaric.charAt(alphane.length -1)
		  hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh == 32 || hh == 228 || hh == 246 || hh == 196)
		  {
		    
		  }
		  else
		  {
		    return false;
		  }
	
		
 return true;
}






    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


