/*
 * Swptember 6, 2010
 * Source file: whatbrowser.js
 */

 
function createRequestObject() 
{
var errMesage = "Could not create the XmlHttp Request object.<br />";

	if ( window.XMLHttpRequest )
		return new XMLHttpRequest();
	else if ( window.ActiveXObject )
		return new ActiveXObject( "Microsoft.XMLHTTP" );
	else
		document.getElementById( 'errorMessages' ).innerHTML = errMessage;
}


http = createRequestObject();


function whatBrowser() 
{
    http.open( 'GET', 'init_whatbrowser.php' );
    http.onreadystatechange = handleResponse;
    http.send( null );
}


function handleResponse() 
{
// alert( 'at 1 - http.readyState: ' + http.readyState +  ' . . . http.status: ' + http.status );

   if (http.readyState == 4 && http.status == 200 )
   {
// alert( 'at 2 - http.readyState: ' + http.readyState +  ' . . . http.status: ' + http.status );
		var response = http.responseText;
		var virtualform = new Array();

//alert( 'response text = ' + http.responseText );
     /*
	* The 'response' buffer contains the text - HTML code - that
	* was generated in the init_userid.php file.  The very very 
	* first thing in that response buffer is the  ID string of the 
	* span or 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 tag ID - div or span and the [1] parameter contains the
	* generated HTML code.
	*/
		if( response.indexOf( '^' ) != -1 )
		{
			virtualform = response.split( '^' );
//alert( "div ID = " + virtualform[0] + ' length = ' + virtualform[0].length  );
//var divID = virtualform[0].substring(1,12);
//alert( "div ID 2 = " + divID );
//alert( 'response text = ' + response );

			var divboxID = virtualform[0];
			var theElement = document.getElementById( 'errorMessages' );
			
			if ( virtualform[1].length < 5 )
				return;
				
			if ( divboxID == 'errorMessages' )
			{
				if ( document.getElementById( 'firstparagraph' ) != null )
				{
					document.getElementById( 'firstparagraph' ).style.paddingTop = '14px';
				}
				
				theElement.style.display = "block";
				theElement.style.padding = '12px';
				//theElement.style.width   = '89%';
				theElement.style.border = '2px solid red';
				theElement.innerHTML = virtualform[1];
			}
			else
			{
				theElement.style.display = "block";
				theElement.innerHTML = virtualform[1];
			}
		}
	}
}	// end function handleResponse()

