// START GENERIC RETURNED VALUE PROCESS
// this is the function that processes the returned value from the callback function
// and decides with function to fire based on the leading string
        var cbSendValue;
        var cbReceiveValue;
        d = new Date();
        var dayOfMonth = d.getDate();
        var iY;
        var iheight;
        var keycode;
        var locsrvID;
        var popupID;
        var popupMode;
        
        //ml options
        //0-unused; 1-ml slider; 2-ml other services; 3-ml other locations; 4-ml other display order;
        var options='111100';
         
        var smlid='';
        var sprevid='';
        
        function ReceiveServerData(arg, context)
             {
                if (arg.substring(0,15) == 'showdefinition;')
		           {
                    ProcessReceived_definition(arg);
		           }
		        else if (arg.substring(0,14) == 'showkwmatches;')
		            {
		            ProcessReceived_showKWmatches(arg);
		            }
		        else if (arg.substring(0,13) == 'showmldetail;')
		            {
		            ProcessReceived_showMLDetail(arg);
		            }
		        else if (arg.substring(0,12) == 'showdtlform;')
		            {
		            ProcessReceived_showDtlForm_New(arg);
		            }
		        		   
             }       

// END GENDERIC RETURNED VALUE PROCESS



// START DO CALLBACK FUNCTIONS


	function DoCallback_Definition(strTerm)
		{
             document.body.style.cursor = "wait";
             iY = get_pageoffset();                
             cbSendValue = strTerm;
		     CallServer('|def|' + cbSendValue, '');
		}

         
     function DoCallback_KWSearch()
        {

            cbSendValue = document.getElementById('tbWordCB').value;
            if (cbSendValue > '')
                {
                    document.body.style.cursor = "wait";
                    CallServer('|key|' + cbSendValue, '');
                }
         }         
     
     function DoCallback_ShowGroup(cbid)
         {
            set_mask_height();
            get_pageoffset();
            document.getElementById('dtl_content').style.top = (iY + 10) + 'px';
            document.getElementById('dtl_content').style.left = (screen.width - 600) / 2 + "px";
            document.getElementById('detail_panel').innerHTML = 'Service Group detail content displays here';              
            // show div with this element...
            document.getElementById('pnl_Mask').style.display = 'block';
            document.getElementById('dtl_content').style.display = 'block';

         }
     
     function DoCallback_DtlPopup(cbid, cmode, divid)
         {
              if (cbid > '') 
                {
                    locsrvID = cbid;
                    popupMode = cmode;
                    popupID = divid;
                    set_parentagency_link(cbid, cmode);
                    document.body.style.cursor = "wait";
                    CallServer('|' + cmode + '|' + cbid + '|' + divid, '');
                }
              
         
         }
           
     function DoCallback_SlideDetail(svid, statsids)
        {

            if (svid > '')
                {
                    if (document.getElementById(svid).innerHTML >'')
                        {
                            document.getElementById(svid).style.display=(document.getElementById(svid).style.display!="block")? "block" : "none";
                        }
                    else
                        {
                            document.body.style.cursor = "wait";
                            cbSendValue = svid + '|' + statsids + '|' + options.substr(2,3);
                            CallServer('|det|' + cbSendValue, '');
                         }
                    smlid = svid;
                }
         }  
// -->
// END DO CALLBACK FUNCTIONS




// START RETURNED VALUE PROCESSES
        function ProcessReceived_definition(arg)
            {
                iY = position_panel('300', iY);
                document.getElementById('definition_panel').style.top = iY + "px";
                
                // remove the leading ID characters from the string
               arg = arg.substring(15); //start at zero for 1st character
               document.getElementById('pnlDef').innerHTML = arg;
               // show div with this element...
               hideshow_element('definition_panel', 'block');
               document.body.style.cursor = "default";
            }
            
        function ProcessReceived_showKWmatches(arg)
            {
               arg = arg.substring(14); //start at zero for 1st character
               
               if (arg == 'nomatches')
                    {
                        hideshow_element('svsearch_results', 'none');                        
                        hideshow_element('keyword_nomatch', 'block');
                    }
               else
                 {
                   document.getElementById('keyword_panel').innerHTML = arg;
                   hideshow_element('keyword_nomatch', 'none');
                   // show div with this element...                  
                   hideshow_element('svsearch_results', 'block');
                }
                
               hideshow_element('svsearch_fulllist', 'none');  
               document.body.style.cursor = "default";            
            }
            
        function ProcessReceived_showMLDetail(arg)
            {
               reset_mltext();
               arg = arg.substring(13); //start at zero for 1st character
               sprevid = smlid;
               document.getElementById(smlid).innerHTML = arg;
               document.getElementById(smlid).style.display = 'block';
               document.body.style.cursor = "default";
               document.getElementById(smlid).focus();            
            }
            
      function ProcessReceived_showDtlForm(arg)
        {
            arg = arg.substring(12);
            if (document.getElementById('dtl_popup').style.display != 'block')
                {
                set_mask_height();
                get_pageoffset();            
                document.getElementById('dtl_popup').style.height = (screen.height - 200) + "px";
                document.getElementById('dtl_popup').style.top = (iY + 15) + 'px';
                document.getElementById('dtl_popup').style.left = (screen.width - 600) / 2 + "px";
                }
            document.getElementById('detail_panel').innerHTML = arg;  
            // show div with this element...
            document.getElementById('pnl_Mask').style.display = 'block';
            document.getElementById('dtl_popup').style.display = 'block';  
            document.body.style.cursor = "default";
            window.location.hash='dtl_nm';
            document.getElementById('dtl_popup').focus();  
        }
        
        
        
        function ProcessReceived_showDtlForm_New(arg)
        {
            var dtlPopUpTop='';
            var dtlPopUpBottom='';
            var dtlPopUpMiddle='';
            var arrPart;
            
            arg = arg.substring(12);
            
            arrPart = arg.split("|/|"); //2nd part may contain map view link
            arg = arrPart[0];
                        
            // close link for popup div...
            dtlPopUpTop = build_popup_close(''); 
            
            dtlPopUpMiddle = '<div class="detail_wrapper">';
            
            
            dtlPopUpMiddle += '<div class="navbar">';
            dtlPopUpMiddle += '<ul>';
            
            dtlPopUpMiddle += '<li>';
            dtlPopUpMiddle += '<a id="a_prt2" ';
            dtlPopUpMiddle += "href=" + '"' + "javascript:void(printsection(" + "'" + "dtlpnl_" + popupID + "', 'Detail Information'));" + '"';
            dtlPopUpMiddle += "title=" + '"' + "print this organization's information" + '"' + '>Print Page</a>';
            dtlPopUpMiddle += '</li>';             
     
            //display view map link, if any...
            if (arrPart.length>1)
             {
                dtlPopUpMiddle += '<li>';
                dtlPopUpMiddle +=  arrPart[1];
                dtlPopUpMiddle += '</li>';              
             
             }            
            //display view parent agency link if this is a location detail view...
            if (popupMode!='agy') 
                {
                    dtlPopUpMiddle += '<li>';
                    dtlPopUpMiddle += '<a id="a_agy" href="' + 'javascript:DoCallback_DtlPopup(' + "'" + locsrvID  + "', 'agy', " + "'" + popupID + "');"  + '" title="view parent agency information">View Parent Agency</a>';
                    dtlPopUpMiddle += '</li>';
                }  
                         
             //display view full page link, if any...
            if (arrPart.length>2)
             {
                dtlPopUpMiddle += '<li>';
                dtlPopUpMiddle +=  arrPart[2];
                dtlPopUpMiddle += '</li>';              
             
             }             
            //close navbar...
            dtlPopUpMiddle += '</ul></div>';
            
            //dtlPopUpMiddle += "<div id=" + '"' + 'dtlpnl_' + popupID + '">' + arg + '</div>';
            
            
            dtlPopUpMiddle += "<div id=" + '"' + 'dtlpnl_' + popupID + '" class=' + '"' + 'detail_panel' + '">';
            
            dtlPopUpMiddle +=  arg + '</div>';
            dtlPopUpMiddle += '<div class="clear"></div>';
            
            //end detail_wrapper div...
            dtlPopUpMiddle += '</div>';
                     
            dtlPopUpBottom = build_popup_close('2');
            
            dtlPopUpBottom += '<div class="clear"></div>';
            
            var dtlpanelID = 'dtl_' + popupID;

            if (document.getElementById(dtlpanelID).style.display != 'block')
                {
                set_mask_height();
                get_pageoffset();            
                document.getElementById(dtlpanelID).style.height = (screen.height - 200) + "px";
                document.getElementById(dtlpanelID).style.top = (iY + 15) + 'px';
                document.getElementById(dtlpanelID).style.left = (screen.width - 600) / 2 + "px";
                }
           
 
           // add content to the detail div...
           document.getElementById(dtlpanelID).innerHTML =  dtlPopUpTop + dtlPopUpMiddle + dtlPopUpBottom;  
 
           // show div with this element...
           document.getElementById('pnl_Mask').style.display = 'block';
           document.getElementById(dtlpanelID).style.display = 'block';  
           document.body.style.cursor = "default";
           //window.location.hash = "dtlpnl_" + popupID;
           //document.getElementById(dtlpanelID).focus();      
         
        }
        
        
// END RETURNED VALUE PROCESSES
     
     
    function build_popup_close(ival)
    {
        var divClose;
        divClose = '<div class=' + '"' + 'closedetail' + ival + '"' + '>';
        divClose += '<a href="javascript:hideshow_element(';
        divClose += "'dtl_" + popupID + "', 'none');";
        divClose += "hideshow_element('pnl_Mask', 'none');" + '"';
        divClose += 'title="close this window">Close'; 
        divClose += '<img src="images/close.png" alt="close" /></a>'; 
        divClose += '</div>';
              
       return divClose;
    }
    
    
    
      
    function get_pageoffset()
        {
            if (navigator.appName == "Microsoft Internet Explorer")
                {
                if (document.documentElement && !document.documentElement.scrollTop)
                    // IE6 +4.01 but no scrolling going on
                   { iY = document.documentElement.scrollTop;}
                else if (document.documentElement && document.documentElement.scrollTop)
                    // IE6 +4.01 and user has scrolled
                   {  iY = document.documentElement.scrollTop;}
               else if (document.body && document.body.scrollTop)
                    // IE5 or DTD 3.2
                   {  iY = document.body.scrollTop;}
                }
            else
                {
                    iY = window.pageYOffset;
                }
            return iY;         
        }
                
              
    function position_panel(arg1, arg2)
        {
            var iypos;
            iH = screen.height;
            iypos = (((iH - arg1) / 2) + arg2) - (iH / 13);
            return iypos;           
        }

     function reset_mltext()
     {
       if ((options.substring(1,2)=='0') && (sprevid >'') && (sprevid != cbSendValue)) {document.getElementById(sprevid).style.display = 'none';}

     }
    function set_mask_height()
    {
         
         var winH = getWindowHeight();
         
         if (winH < screen.height) {winH = screen.height;}  
         document.getElementById('pnl_Mask').style.height = winH + "px";

    }
      

    function getWindowHeight()
     {
      var functionReturn = 0;

 
      if ( (document.body) && (document.body.offsetHeight) )
            functionReturn = document.body.offsetHeight;
      else if ( (document.documentElement) && (document.documentElement.clientHeight) )
            functionReturn = document.documentElement.clientHeight;
      else if ( (document.body) && (document.body.clientHeight) )
            functionReturn = document.body.clientHeight;
      else if ( window.innerHeight )
            functionReturn = window.innerHeight - 18;

      return functionReturn;
     }
     
     function set_parentagency_link(cbid, cmode)
        {
           var elem = document.getElementById('a_agy');
           if (cmode=='agy') 
                {
                    elem.href = '';
                    elem.style.display='none';
                } 
           else
                {
                    elem.href = "javascript:DoCallback_DtlPopup('" + cbid + "', 'agy')";
                    elem.style.display='inline';
                }            
        }
        
     function validatekey()
        {
            if (window.event) {keycode = window.event.keyCode;}
            else if (e) {keycode = e.which;}
            if (keycode == 13) { DoCallback_KWSearch(); return false; }
        }
   // -->      
