// 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 sEmailValues;
        var bOK;
        
        var iStID;
        var sCity;
        var sState;
        var sZIP;
        
        var sessID;
        var searchID;
        
        function ReceiveServerData(arg, context)
             {
                if (arg.substring(0,12)== "close_email;")
                    {
                    ProcessReceived_closeEmail(arg);
                    }
                else if (arg.substring(0,15) == 'showdefinition;')
		           {
                    ProcessReceived_definition(arg);
		           }		           
		        else if (arg.substring(0,14) == 'showcitynames;')
		            {
		            ProcessReceived_showCityNames(arg);
		            }
		        else if (arg.substring(0,11) == 'showdetail;')
		            {
		            ProcessReceived_showDetail(arg);
		            }
		        else if (arg.substring(0,14) == 'showmlresults;')
		            {
		            ProcessReceived_showMLResults(arg);
		            }
		        else if (arg.substring(0,10) == 'noresults;')
		            {
		            ProcessReceived_showNoResults(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_GetCityNames(strLtrs)
         {
            
            cbSendValue = strLtrs;
            if (cbSendValue > '')
                {
                    document.body.style.cursor = "wait";
                    CallServer('|cty|' + cbSendValue, '');
                }
            else
                return;            
         } 
    
    function DoCallback_GetDetail(strKey)
        {
            cbSendValue = strKey + "|" + sessID + '|' + searchID;
            document.body.style.cursor = "wait";
            CallServer('|det|' + cbSendValue, '');
        }
             
    function DoCallback_GetMLResults(sortval)
        {
            populate_search_values();
            cbSendValue = regid + '|' + sCity + '|' + iStID + '|' + sState + '|' + sZIP + '|' + sortval + "|" + sessID;
            document.body.style.cursor = "wait";
            CallServer('|mls|' + cbSendValue, '');
        }
        
     function DoCallBack_SendEmail()
        {
            
           sEmailValues = '';           
           validate_email()
           if (bOK == true)
            {
               populate_email_string();
               if (sEmailValues > '')
                {
                    document.body.style.cursor = "wait";
                    CallServer('|eml|' + sEmailValues, '');
                }             
            }      
        }
        
// -->
// END DO CALLBACK FUNCTIONS




// START RETURNED VALUE PROCESSES

        function ProcessReceived_closeEmail(arg)
            {
            
                hideshow_element('email_content', 'none');
                hideshow_element('pnl_Mask', 'none');
                hideshow_element('ddStateList' , 'inline');
                document.body.style.cursor = "default";
            }

        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_showCityNames(arg)
            {
               arg = arg.substring(14); //start at zero for 1st character
               document.getElementById('citylist').innerHTML = arg;
               // show div with this element...
               if (arg!='') {document.getElementById('citylist').style.display = 'block';}
               //reset cursor...
               document.body.style.cursor = "default"; 
            }
            
         
        function ProcessReceived_showDetail(arg)
            {
               arg = arg.substring(11);
               
               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 = arg;
              // show div with this element...
               document.getElementById('pnl_Mask').style.display = 'block';
               document.getElementById('ddStateList').style.display = 'none';
               document.getElementById('dtl_content').style.display = 'block';
               //reset cursor...
               document.body.style.cursor = "default";            
            
            }   
            
            
        function ProcessReceived_showMLResults(arg)
            {
               var arrValue;
               arg = arg.substring(14);
               
               //split return value into parts...
               arrValue = arg.split("|");              

               document.getElementById('ml_contents').innerHTML = arrValue[0];
               document.getElementById('ml_title').style.display = 'none';
               document.getElementById('ml_title2').style.display = 'block';
               // show div with matchlist navigation bar...
               document.getElementById('ml_navbar').style.display = 'block';
               document.getElementById('ml_contents').style.display = 'block';
               // show div with this element...
               document.getElementById('mlresults').style.display = 'block';
               //reset cursor...
               document.body.style.cursor = "default"; 
               
               //set search id variable for use in detail callback routine...
               searchID = arrValue[1];           
            }
            
        function ProcessReceived_showNoResults(arg)
        {
               arg = arg.substring(10);
               document.getElementById('ml_title').innerHTML = arg;
               //hide nav bar and search results divs...
               document.getElementById('ml_navbar').style.display = 'none'; 
               document.getElementById('ml_contents').style.display = 'none';
               document.getElementById('ml_title2').style.display = 'none';              
               // show div with this element...
               document.getElementById('ml_title').style.display = 'block';
               document.getElementById('mlresults').style.display = 'block';
               //reset cursor...
               document.body.style.cursor = "default";                   
        }       
                 

// END RETURNED VALUE PROCESSES
  
    function clear_email()
        {
            document.getElementById('msg').innerHTML = '';
            document.getElementById('tbName').value='';
            document.getElementById('tbEmail').value='';
            document.getElementById('tbComments').value='';
            document.getElementById('tbOrgName').value='';
            document.getElementById('tbAddress1').value='';
            document.getElementById('tbAddress2').value='';
            document.getElementById('tbCity2').value='';
            document.getElementById('tbSt').value='';
            document.getElementById('tbZIP').value='';
            document.getElementById('tbPhn1').value='';
            document.getElementById('tbPhn2').value='';
            document.getElementById('tbPhn3').value='';
            document.getElementById('tbPhn4').value='';       
        }
         
    function getcitynames(cid)
        {
           //first initialize the ZIP Code text box and the selected state value...
           document.getElementById('tbZIPCode').value = '';
           if (document.getElementById('ddStateList').selectedIndex > 0)
                        {document.getElementById('ddStateList').selectedIndex=-1;} 
           //next clear the previous results display... 
           document.getElementById('ml_navbar').style.display = 'none';
           document.getElementById('ml_title').innerHTML = '';
           hideshow_element('ml_title2', 'none');                                    
           document.getElementById('ml_contents').innerHTML = '';
                   
           if (document.getElementById(cid).value.length > 2)
                {
                    var ltrs;
                    ltrs = document.getElementById(cid).value;
                    DoCallback_GetCityNames(ltrs);
                }
            else
                {
                    if (document.getElementById('citylist').style.display == 'block')
                         { document.getElementById('citylist').innerHTML = '';
                           document.getElementById('citylist').style.display = 'none';
                         }
                    void(0); //cancel action
                }           
        }
         
    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 populate_email_string()
        {

            sEmailValues = document.getElementById('tbName').value + '||';
            sEmailValues += document.getElementById('tbEmail').value + '||';
            sEmailValues += document.getElementById('tbComments').value + '||';
            sEmailValues += document.getElementById('tbOrgName').value + '||';
            sEmailValues += document.getElementById('tbAddress1').value + '||';
            sEmailValues += document.getElementById('tbAddress2').value + '||';
            sEmailValues += document.getElementById('tbCity2').value + '||';
            sEmailValues += document.getElementById('tbSt').value + '||';
            sEmailValues += document.getElementById('tbZIP').value + '||';
            sEmailValues += document.getElementById('tbPhn1').value + '||';
            sEmailValues += document.getElementById('tbPhn2').value + '||';
            sEmailValues += document.getElementById('tbPhn3').value + '||';
            sEmailValues += document.getElementById('tbPhn4').value;
        }
                    
    function populate_search_values()
        {
            sessID = document.getElementById('sessID').innerHTML;
            iStID = document.getElementById('ddStateList').selectedIndex;
            sCity = document.getElementById('tbCity').value;
            sState = '';
            sZIP = document.getElementById('tbZIPCode').value;
            if (iStID != 0)
                { 
                    sState = document.getElementById('ddStateList')[iStID].text;
                    iStID = document.getElementById('ddStateList')[iStID].value;
                }        
        }
    
              
    function position_panel(arg1, arg2)
        {
            var iypos;
            iH = screen.height;
            iypos = (((iH - arg1) / 2) + arg2) - (iH / 13);
            return iypos;           
        }
        
   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 showEmail()
            {
               
               
               clear_email();
               set_mask_height();

               get_pageoffset();
               document.getElementById('email_content').style.top = (iY + 10) + 'px';
               document.getElementById('email_content').style.left = (screen.width - 600) / 2 + "px";              
               
                // show divs ...
               document.getElementById('pnl_Mask').style.display = 'block';
               document.getElementById('ddStateList').style.display = 'none';
               document.getElementById('email_content').style.display = 'block';
               document.getElementById('tbName').focus();
                         
            
            } 

      function validate_email()
        {
   
            var sMsg;
            sMsg = '';
            bOK = true;
            document.getElementById('msg').innerHTML = '';
            
            if (document.getElementById('tbName').value == '')
                { sMsg = 'Your name is required.'; }
            else if (document.getElementById('tbEmail').value == '')
                {  sMsg = 'Your email address is required.';}
            else if (document.getElementById('tbComments').value == '')
                { sMsg =  'A comment is required.';}
            
            if (sMsg != '')
                {document.getElementById('msg').innerHTML = sMsg; bOK = false;}                
            else
                {
                   //now validate email format...
                    var emailStr;
                    emailStr = document.getElementById('tbEmail').value;
                    bOK = emailCheck (emailStr);
                }
        }      


  function catchKeystroke(e, elem, elem1)
        {
        var keynum;
        var keychar;      
         
        if(window.event) // IE
          {
          keynum = e.keyCode;
          }
        else if(e.which) // Netscape/Firefox/Opera
          {
          keynum = e.which;
          }
          
        keychar = String.fromCharCode(keynum);
        
        if (elem == 'tbCity')
            {
                if (keynum == 40) //dwn arrow
                    {
                    if (document.getElementById('citylist').innerHTML > '')  { document.getElementById('a_1').focus(); document.getElementById('t_1').style.backgroundColor = 'C5C7F1';}
                    }
                else
                    {getcitynames('tbCity');}
            }
        else if (elem == 'citylist')
            {
              var elemID;
              var rowcnt;
              
              elemID = elem1;
              rowcnt = document.getElementById('tblcitylist').rows.length;
              
              if (keynum == 40) //dwn arrow                 
                 {  if (elemID != rowcnt) {elemID = elemID + 1;} } 
                 
              else if (keynum == 38) //up arrow
                 { if (elemID != 1) {elemID = elemID - 1;} }
               
              document.getElementById('t_' + (elem1)).style.backgroundColor = 'ffffff';
              document.getElementById('a_' + (elemID)).focus(); 
              document.getElementById('t_' + (elemID)).style.backgroundColor = 'C5C7F1';
              //document.getElementById('citylist').scrollBy(0,0);
    
            }  
 
        else
            return;
        }
  
   // --> 

    

