// Creating a object as Ajax
var Ajax = new Object();

// Bind and assign some variable as showMessage as value 1 , Message as value blank on the object
Ajax.showMessage=1;
Ajax.Message='';

Ajax.Request = function(url, callbackMethod)
{
	// Page.getPageCenterX();
	Ajax.request = Ajax.createRequestObject();
	Ajax.request.onreadystatechange = callbackMethod;
	Ajax.request.open("POST", url, true);
	Ajax.request.send(url);
}


// Assign the value on varaible thyrough setXX() function, signature according to Ajax specification , all the function is access through object
Ajax.setMessage = function (message)
{
	Ajax.Message=message;
}
Ajax.setShowMessage = function (m)
{
	Ajax.showMessage=m;
}


// declare and define the function createRequestObject() , to get the object of XMLHttpRequest deepend upon the browser compatability
Ajax.createRequestObject = function()
{
	var obj;
	if(window.XMLHttpRequest)
	{
		obj = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		obj = new ActiveXObject("MSXML2.XMLHTTP");
	}
	return obj;
}

// Declare and Define the function CheckReadyState(),which accept XMLHttpRequest object , to check the postion of request whether it may be complete or process to check
// the value of readystate , if ready state==4 then response is loaded 

Ajax.CheckReadyState = function(obj)
{
	// Intially we set the value of variable showMessage=1 , if it is zero then the element div having id loadingbox will be set display none(not visible) else it will show with block of dashed line
	if ( Ajax.showMessage == 0 )
	{
		document.getElementById('loadingbox').style.display = "none";
	}
	else
	{
		document.getElementById('loadingbox').style.display = "block";
	}
	
	// if the readystate less than 4 then we can change the div element of id loading , we replace that div element with table and following information as Loading...
	// through innerHTML property of HTML.
	if(obj.readyState < 4) {
		
	}
	
	
	//  if readystate equal to 4 then ur request to be complete a get response then again check status if equal to 200 then div element whose id is loading change into table with some message
	if( obj.readyState == 4 )
	{
		// if response is OK 
		if(obj.status == 200)
		{
			
			// This is must if remove this line of code then tree will not display , a blank page will come
			return true;
		}
		else
		{
			document.getElementById('loadingbox').innerHTML = "HTTP " + obj.status;
		}
	}
	
}

