//global xmlhttp request object
var xmlhttp = new G6HttpReq()._xmlhttp;

//G6HttpRequest Object constructor
function G6HttpReq()
 {
		//Members
		
		//initialize xmlhttp request object to false
		this._xmlhttp=false;  
		
		if (window.ActiveXObject) {
			try	{
				this._xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)	{
				try	{
					this._xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch (ee) {
					this._xmlhttp = false; //keep it false
				}
			}
		}	
		else if (window.XMLHttpRequest) {
			try	{
				this._xmlhttp = new XMLHttpRequest()
			}
			catch (e)	{
				this._xmlhttp = false; //keep it false
			}
		}
		
		/* //may want to abort if we can't get an XMLHttp initialized
		if (!_xmlhttp)
			return;
		*/
		
		/* //old version
		try 
		{
			this._xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {
			try {
				this._xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (E) 
			{
				this._xmlhttp = false;
			}
		}
		
	
		// if unsuccessful, try to create XMLHttpRequest() object (mozilla)
		if (!this._xmlhttp && typeof XMLHttpRequest!='undefined') {
			try
			{
				this._xmlhttp = new XMLHttpRequest();
			}
			catch (e)
			{
				return; //may want to do something else
			}
		}
		*/

	/* Prototype "get" function returns response text from http request */
	G6HttpReq.prototype.get = function (url,callback){
		var request=this._xmlhttp;			//get xmlhttp object
		var result = false; 				//initialize result to false
		//obj = this;
		
		request.open("GET", url ,true);		//open the request
		
 		request.onreadystatechange=function() {
  		if (request.readyState==4) {		//if readystate changed to 4 we have data
   			
			if(request.status==200){
				result = request.responseText;
				callback(result);			//return the result
				//alert("done");
			}
			else
			{
				//request.xmlhttp.abort();
				callback(null);				//return null
			}	
			//return; //this is important otherwise processing goes on and on.
  		}
 		}
		//send null request now
		this.clear();
		
 		//request.send(null);

	}

	/* Prototypoe setCtrl function sets innerHTML of control with specified id to responseText */
	G6HttpReq.prototype.setCtrl = function(url,ctrl){
		var request = this._xmlhttp
		var result = false;
		request.open("GET", url ,true);
 		request.onreadystatechange=function() {
  		if (request.readyState==4) {
   			
			if(request.status==200){
				result = request.responseText;
				try{ 
					ctrl.innerHTML=request.responseText;
				 } 
				 catch (e) 
				 { 
					alert(e.message); 
				 }
			}
			
  		}
 		}
		
		this.clear();
 		

	}
	
	//Send null http request to clear the request.
	G6HttpReq.prototype.clear = function(){
		//send null request now
		if(typeof XMLHttpRequest!='undefined') //mozilla
			this._xmlhttp.send(null);
		else
			this._xmlhttp.send(); //ie
	}
	
}


function G6_SetHtmlFromHTTPRequest(url,ctrlId){
	try{
	new G6HttpReq().setCtrl(url,document.getElementById(ctrlId));
	}
	catch (e)
	{
		//
	}
}

/* Example usage  
// Creat a callback function that processes the result

function done(result){
	document.write(result);
}

//Instantiate object and call the get function with a local url /folder/url.aspx, etc
new G6HttpReq().get("webform.aspx",done);

*/


