/**
 * $Id: swAjax.js,v 1.1 2008/06/06 11:14:33 sudaraka Exp $
 * Created: 02/27/2008
 * $Log: swAjax.js,v $
 * Revision 1.1  2008/06/06 11:14:33  sudaraka
 * Inventory maintenance & report
 *
 *
 */

//<![CDATA[

function swAjax(url, callback, manualcall){
	var http=null;
	var fnCallback=null;
	var strUrl='';
	var strSQ='';
	var thisAjax=this;
	
	//Check borwser compatibility and create the HTTP request object
	try{thisAjax.http=new XMLHttpRequest();}
	catch(e){
		try{thisAjax.http=new ActiveXObject("Msxml2.XMLHTTP");}
		catch(e){
			try{thisAjax.http=new ActiveXObject("Microsoft.XMLHTTP");}
			catch(e){thisAjax.http=null}
		}
	}
	if(!thisAjax.http && thisAjax.http.send){
		alert('Your browser does not support AJAX funtionality used in this web site.\nSone functions will not work properly.');
		return false;
	}
	
	//Set callback function
	thisAjax.fnCallback=callback;
	
	//check query string in the url
	thisAjax.strUrl=url;
	if(thisAjax.strUrl.indexOf('?')>=0){
		thisAjax.strUrl=thisAjax.strUrl.split('?');
		thisAjax.strSQ=thisAjax.strUrl[1];
		thisAjax.strUrl=thisAjax.strUrl[0];
	}
	
	thisAjax.http.open('POST', thisAjax.strUrl, true);
	thisAjax.http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	
	thisAjax.http.onreadystatechange=function(){
		if(thisAjax.http && thisAjax.http.readyState==4 && thisAjax.fnCallback){
			thisAjax.fnCallback(
				(thisAjax.http.responseXML && thisAjax.http.getResponseHeader('Content-Type').indexOf('text/xml')==0)?thisAjax.http.responseXML:null, 
				thisAjax.http.responseText
			);
		}
	}
	
	thisAjax.call=function(queryString){
		if(queryString) thisAjax.strSQ=queryString;
		
		thisAjax.http.send(thisAjax.strSQ);
	}
	
	if(!manualcall) thisAjax.call();
}

//]]>
