/*
 * source file: lookup_buffer.js
 * This does the AJAX stuff for the dynamic form.
 * The 'createRequestObject()' function needs to be expanded to include
 * more checks and a few comments too.
 */
function createRequestObject() 
{
    var request = null;
    var browser = navigator.appName;
    if ( browser == "Microsoft Internet Explorer" )
    {
        request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
        request = new XMLHttpRequest();
    }

    return request;
}


var http = createRequestObject();


/*
 * 1. The string comming in is the value parameter from the <option> tag.
 *
 * 2. You can have a full network path or a relative path for the second
 * argument of the 'http.open()' call.
 */
function sndReqHst( buffersize ) 
{
//alert( "sndReqHst  " + buffersize );

//  http.open( 'GET', 
// 'http://localhost/ajax/init_buffer.php?bytesize=' + buffersize );

    http.open( 'GET', 'init_random_buffer.php?bytesize='+buffersize );
    http.onreadystatechange = handleResponse;
    http.send( null );
}

/*
 * The callBack function --
 *
 * For debugging, you can stick an alert() call before the 'if'
 * statement below.  This will show you what HTML code will be placed
 * the tag that contains the id value, which is in the update[0] array.
 * The 'http.responseText' contains the stuff from init_buffer.php
 */
function handleResponse() 
{
   if (http.readyState == 4 || http.readyState == 'complete')
   {
      var response = http.responseText;
      var virtualform = new Array();
 //alert( response );

     /*
	* The 'response' buffer contains the text - HTML code - that
	* was generated in the init_buffer.php file.  The very very 
	* first thing in that buffer is the  ID string of the 'div' tag
	* that is the target box or target area for the generated HTML.
	* The character '^' separates this string from all of the 
	* HTML code.
	* After the split function is performed, the [0] parameter
	* contains the 'div' tag ID and the [1] parameter contains the
	* generated HTML code.
	*/
      if( response.indexOf( '^' ) != -1 )
      {
         virtualform = response.split( '^' );
	   var theElement = document.getElementById( virtualform[0] );
	   theElement.style.border = "2px solid #abcdef";
         theElement.innerHTML = virtualform[1];
      }
   }
}