﻿// JScript File
    function ClearHighlightSelected() {
        var ls_highlights = getElementsByClassName(document, "HighlightSelected");
        for(var i=0; i<ls_highlights.length; i++)
        {
            ls_highlights[i].className=ls_highlights[i].className.replace('HighlightSelected', '');
        }
    }
    
    function SetContextualText(as_text) {
        document.getElementById('ContextualHelp').innerHTML = as_text;
        ScrollToFitContext();
    }
    
    function ScrollToFitContext() {
        
       	        
        var lo_wordHelp = document.getElementById('WordHelper');
       	                    
        if (document.documentElement && document.documentElement.scrollTop)
            theTop = document.documentElement.scrollTop;
        else if (document.body)
            theTop = document.body.scrollTop
   
        var li_scrollDiff =(BrowserHeight() + theTop) -(findPosY(lo_wordHelp) + getElementHeight(lo_wordHelp));

        if (li_scrollDiff < 0)
            window.scrollBy(0, -li_scrollDiff);
    }
    
    
    var myrules = {
        '.Highlight' : function(el) {
   	        el.onmousemove = function() {

   	        }
   	        el.onclick = function(e) {
   	            ClearHighlightSelected();
   	            
   	            CancelEvents(e);
   	                
   	            var lb_profiles = this.className.indexOf('Profiles') > 0;
       	        var lb_definition = this.className.indexOf('Definition') > 0;
       	        
       	        var lo_wordHelp = document.getElementById('WordHelper');
       	        
       	        var lo_content = document.getElementById('ContextualHelp');
       	       
       	         var ls_loading = '<div style="height:100px; background-color:grey;"><img src="/i/loading.gif" align="center" height="40" width="70" alt="Loading Content" style="position:relative; top:30px; left:100px " /></div>';
                
                document.getElementById('ContextualHelp').innerHTML  = ls_loading
                
                el.className=el.className +' HighlightSelected';
       	    
       	        //alert(findPosY(el));
       	        lo_wordHelp.style.position = 'absolute';
       	        lo_wordHelp.style.display= 'block';
       	        
       	        lo_wordHelp.style.left = ''+ findPosX(el)+ '' + 'px';
       	        //alert(el.clientHeight);
       	        var li_top = findPosY(el) +  getElementHeight(el) ;// - ( lo_wordHelp.clientHeight );
       	        lo_wordHelp.style.top = li_top.toString() + 'px';
       	        
     
       	       //document.body.focus();
       	       
       	       var ls_escapedTerm = Replace(el.innerHTML, ' ', '+');
       	       
       	        //SetInnerHTMLFromAjaxResponse('http://test.pokerzone.com/pseudoservice/Contextual.aspx?term=' + ls_escapedTerm, 'ContextualHelp');
       	        PassAjaxResponseToFunction('/pseudoservice/Contextual.aspx?term=' + ls_escapedTerm, 'SetContextualText');
       	        
       	        //alert(el.className);
       	       
       	        var lo_elem = document.getElementById('WordHelperDetails');
                lo_elem.href = 'http://dictionary.pokerzone.com/' + ls_escapedTerm;
                
                //ScrollToFitContext();


       	        return false;
   	        }
        }
     }
     
     
     Behaviour.register(myrules);

