/*********************************************************************************
 * The contents of this file are subject to the AMPT License Version 1.0 
 * ("License"); You may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at http://policies.ampt.co.za
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * See full license for requirements.
 *
 * Copyright (C) 2006 AMPT cc.;
 * All Rights Reserved.
 * Contributor(s): Rohland Lablache de Charmoy.
 ********************************************************************************/
/*********************************************************************************
 * Description:  Generic class for implementation of the Asynchronous Java and XML 
 * 		 protocol (AJAX).
 *
 * Create: 2006-02-13
 *
 * Modifications:	
 *		
 *
 * TODO:	 
 ********************************************************************************/
 
 
function cAjax(dest,callback)
{
	this.xmlhttp = null;
	try 
	{ 
		// Moz supports XMLHttpRequest. IE uses ActiveX.  
		// browser detction is bad. object detection works for any browser  
		this.xmlhttp = window.XMLHttpRequest? new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	catch (e) 
	{ 
		// browser doesn't support ajax. handle however you want  
	} 
	
	// the xmlhttp object triggers an event everytime the status changes  
	// triggered() function handles the events  
	

	callbackfunction = callback;
	
	
	this.triggered = function ()
	{ 
		// if the readyState code is 4 (Completed)  
		// and http status is 200 (OK) we go ahead and get the responseText  
		// other readyState codes:  
		// 0=Uninitialised 1=Loading 2=Loaded 3=Interactive  
		if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) 
		{ 
			// xmlhttp.responseText object contains the response.  
			//alert(xmlhttp.responseText);
			callbackfunction(xmlhttp.responseText);
		} 
	}
	

	this.xmlhttp.onreadystatechange = this.triggered; // open takes in the HTTP method and url.  
	
	// We need a salt variable to make sure the request does not bring back a cached page
	if (dest.indexOf('?') == -1)
		dest = dest + '?salt=' + Math.random();
	else
		dest = dest + '&salt=' + Math.random();
	this.xmlhttp.open("GET", dest); // send the request. if this is a POST request we would have  
	
	// sent post variables: send("name=aleem&gender=male)  
	// Moz is fine with just send(); but  
	// IE expects a value here, hence we do send(null);  
	
	this.xmlhttp.send(null); 
} 



/*function cAjax(dest,callback)
{
	try 
	{ 
		// Moz supports XMLHttpRequest. IE uses ActiveX.  
		// browser detction is bad. object detection works for any browser  
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	catch (e) 
	{ 
		// browser doesn't support ajax. handle however you want  
	} 
	
	// the xmlhttp object triggers an event everytime the status changes  
	// triggered() function handles the events  
	
	xmlhttp.onreadystatechange = triggered; // open takes in the HTTP method and url.  
	xmlhttp.open("GET", dest + '?salt=' + Math.random()); // send the request. if this is a POST request we would have  
	
	// sent post variables: send("name=aleem&gender=male)  
	// Moz is fine with just send(); but  
	// IE expects a value here, hence we do send(null);  
	
	xmlhttp.send(null); 
} 

function triggered() 
{ 
	// if the readyState code is 4 (Completed)  
	// and http status is 200 (OK) we go ahead and get the responseText  
	// other readyState codes:  
	// 0=Uninitialised 1=Loading 2=Loaded 3=Interactive  
	if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) 
	{ 
		// xmlhttp.responseText object contains the response.  
		//document.getElementById("output").innerHTML = xmlhttp.responseText; 
		alert(xmlhttp.responseText);
	} 
}*/
