//------------------------------------------------------------
//... GLOBAL VARIABLES ....
//------------------------------------------------------------
var httprqstObjObj;
var datafilenum;




//------------------------------------------------------------
//... EVENT ....
//... when the webpage is initially loaded with ajaxphp.js
//... referenced by script tag near bottom of the webpage,
//... the init function is called to initialize webpage with
//... specific data returned by implementing AJAX technology.
//------------------------------------------------------------
window.onload = init;




//------------------------------------------------------------------------------------------
//... FUNCTION BEGIN - init
//------------------------------------------------------------------------------------------
function init(){
	// load data
	//alert("AJAX Onload...");
	getData(1);
}
//------------------------------------------------------------------------------------------
//... FUNCTION END - init
//------------------------------------------------------------------------------------------




//------------------------------------------------------------------------------------------
//... FUNCTION BEGIN - getData
//------------------------------------------------------------------------------------------
function getData(number)
{ 
datafilenum = number;
//alert("The file number is: " + datafilenum);

//..................................................
// remove(erase) the specific data written to the
// webpage for the id="thedata" attribute.
//..................................................
if (datafilenum > 1 && datafilenum < 10) {document.getElementById("thedata").innerHTML = "";}

//.................................................
//Create new object(httprqstObj) instance by
//calling the getHTTPObject function. 
//.................................................
httprqstObj = getHTTPObject();
if (httprqstObj)
	{
	//alert("Now, initiate an AJAX request...");
	//Attach a function to the onreadystatechange event handler.
	httprqstObj.onreadystatechange = function(){
              //....................................................................
		//This passes a reference to the responseData function, it also 
		//having the object instance of above httprqstObj passed as a parameter.
              //....................................................................
		responseData(httprqstObj);
		};	
       //........................................................................
	//This is a GET request to a PHP file with the datafilenum parameter
       //from this function getData, and the request is an asynchronous request.
       //........................................................................
	//alert("GET request is issued: " + './getdata.php?datafilenum=' + datafilenum);
	httprqstObj.open("GET",'./getdata.php?datafilenum=' + datafilenum,true);
       //...................................................
	//Set this AJAX request in motion and since this is
       //a GET request, no data is being sent to the server.
	httprqstObj.send(null);
       //...................................................
	}
}
//------------------------------------------------------------------------------------------
//... FUNCTION END - getData
//------------------------------------------------------------------------------------------




//------------------------------------------------------------------------------------------
//... FUNCTION BEGIN - responseData
//------------------------------------------------------------------------------------------
function responseData(rqstObject)
{ 
//.....................................................................
//When the AJAX response comes back from the server, 
//check for a valid readyState value.
//.....................................................................
if (rqstObject.readyState == 4) 
	{
	//alert("AJAX Response Returned for the Data: ");
	//alert("Request.ReadyState: " + httprqstObj.readyState + " --- " + "Request.Status: " + httprqstObj.status);
	if (rqstObject.status == 200 || rqstObject.status == 304 || rqstObject.status == 0)
		{   //alert("AJAX Request Returned: " + rqstObject.responseText);
                  //.....................................................................
                  // Place(write) the specific data returned by the AJAX asynchronous
                  // response into the webpage for the id="thedata" attribute.
                  //.....................................................................
		    switch (datafilenum) {
                  case 0:			    
			document.getElementById("navcontainer").innerHTML = rqstObject.responseText; 
			getData(1);	
			break;
                  default:
			document.getElementById("thedata").innerHTML = rqstObject.responseText;
			break;
                  }
		} 
	}
}
//------------------------------------------------------------------------------------------
//... FUNCTION END - responseData
//------------------------------------------------------------------------------------------




//------------------------------------------------------------------------------------------
//... FUNCTION BEGIN - getHTTPObject
//------------------------------------------------------------------------------------------
function getHTTPObject(){
	var rqstObject = false;
	if (window.XMLHttpRequest){ rqstObject = new XMLHttpRequest();
	} else if (window.ActiveXObject){
		try{
			rqstObject = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
			try{
				rqstObject = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e){
				rqstObject = false;
			}
		}
	}
	return rqstObject;
}
//------------------------------------------------------------------------------------------
//... FUNCTION END - getHTTPObject
//------------------------------------------------------------------------------------------















