var _ms_AJAX_Request_ActiveX = ""; // Holds type of ActiveX to instantiate

function AJAX_Update(url, obj, func)
{
  if (!url) return false;  // Don't run if missing the url parm. 
 
  // code for Mozilla, etc.
	if (window.XMLHttpRequest)
  {
  	var xmlhttp=new XMLHttpRequest();
  }
	
	// code for IE
	else if (window.ActiveXObject)
  {
      // Instantiate the latest MS ActiveX Objects
      if (_ms_AJAX_Request_ActiveX) 
			{
         xmlhttp = new ActiveXObject(_ms_AJAX_Request_ActiveX);
      } 
	  	else 
			{
	    	// loops through the various versions of XMLHTTP to ensure we're using the latest
	    	var versions = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
                       "Microsoft.XMLHTTP"];
         	for (var i = 0; i < versions.length ; i++)
					{
         	  try 
			 			{
		   	      // try to create the object
		   	      // if it doesn't work, we'll try again
		   	     // if it does work, we'll save a reference to the proper one to speed up future instantiations
              xmlhttp  = new ActiveXObject(versions[i]);
              if (xmlhttp) 
							{
                 _ms_AJAX_Request_ActiveX = versions[i];
                 break;
              }
            }
            catch (objException) 
 			      {
                  // trap -  try next one
             } 
           }
        }
	}
    if (!xmlhttp) return false;
   if (func) 
    xmlhttp.onreadystatechange = function(){
      if (xmlhttp.readyState != 4) return;
      if (xmlhttp.status == 200)
        func(obj, xmlhttp.responseText);
      else 
        alert("An error occurred" + http.status);
  };
    else
      xmlhttp.onreadystatechange = function() { return; }
    
		xmlhttp.open('GET', url, true);
    xmlhttp.send(null);
    if (func) {} else return xmlhttp.responseText;
    return false;
}


function Send_AJAX_Request(target) 
{ 
	
	if (target.value != '')
	{
	randnum = (Math.round((Math.random()*9)+1));
	mydiv = document.getElementById("username_div"); 
	mydiv.style.display = "none";
	var myurl = "AJAXUSRNAM.PGM?username="+(target.value); 
	AJAX_Update(myurl, mydiv, Receive_AJAX_Response); 
	}
} 

function Receive_AJAX_Response(mydiv, response)
{
	if (mydiv.value != '')
	{
	mydiv.innerHTML = response;
	setRespDiv(mydiv);
	} 
}

function setRespDiv(mydiv)
{
	var mydiv = document.getElementById("username_div");
	var inpbox = document.forms[0].username;
	mydiv.style.display = "inline";
	//mydiv.style.left=findPosX(inpbox)+0+"px";
	//mydiv.style.top=findPosY(inpbox)+23+"px";
}	
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 5;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

