/* -*- mode: java -*- */

/*****************************************
 * Copyright (c) 2006, Emmett M. Pate, Jr.
 * emmett@epate.com
 *
 */
 
function getHTTPObject()
{
 var xmlhttp;
 /*@cc_on
 @if (@_jscript_version >= 5)
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
   try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (E) {
    xmlhttp = false;
   }
  } @else xmlhttp = false;
   @end @*/
   if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
   try {
    xmlhttp = new XMLHttpRequest();
   } catch (e) {
   xmlhttp = false;
  }
 }
 return xmlhttp;
}
var agtobj = getHTTPObject(); // We create the HTTP Object

function SearchByName()
{
    /* clear the division */
    agentsDiv = document.getElementById('agents');
    agentsDiv.innerHTML = "Searching...";

    /* call the appropriate search function */
    str = "name=" + escape(document.agentsearch.searchName.value);
    ShowAgents(str);
}

function SearchByLetter(letter)
{
    /* clear the division */
    agentsDiv = document.getElementById('agents');
    agentsDiv.innerHTML = "Searching...";

    /* call the appropriate search function */
    str = "letter=" + letter;
    ShowAgents(str);
}

function SearchBySpecialty(str)
{
    /* clear the division */
    agentsDiv = document.getElementById('agents');
    agentsDiv.innerHTML = "Searching...";

    /* call the appropriate search function */
    str = "specialty=" + escape(str.value);
    ShowAgents(str);
}

function SearchByOffice(str)
{
    /* clear the division */
    agentsDiv = document.getElementById('agents');
    agentsDiv.innerHTML = "Searching...";

    /* call the appropriate search function */
    str = "office=" + escape(str.value);
    ShowAgents(str);
}

function ShowAgents(str)
{
    agtobj.open("GET", "ShowAgents.php?"+str, true);
    agtobj.onreadystatechange = function() {
	if (agtobj.readyState == 4) {

	    agentsDiv = document.getElementById('agents');
	    agentsDiv.innerHTML = agtobj.responseText;
	}
    }
    agtobj.send(null);
}
