/**********************************************************************
	Version: cAjax version 1.0
	Description: My custom AJAX function to handle GET & POST, extremely compact
	Author: Copyright (C) 2009  Stephen Chatelain

	Function Explanation
	1st Parameter = This is the Ajax Method, case insensitive (the ajax function handles this)
	2nd Parameter = This is the remote file to send your request via AJAX
	3rd Parameter = This is the name of the callback function you want to handle the http response
	4th Parameter = This is a string of parameters for POST calls, empty string for GET (ie. POST: 'a=1&b=2&c=3' or GET: '')
**********************************************************************/

function ajaxSend(ajaxMethod, ajaxUrl, ajaxCallback, ajaxParams){
	//use all uppercase to ensure consistency
	ajaxMethod = ajaxMethod.toUpperCase();
	function ajaxObject(){
		if (document.all && !window.opera){
			obj = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			obj = new XMLHttpRequest();
		}
		return obj;
	}
	var ajaxHttp = ajaxObject();
	var params = null;
	ajaxHttp.open(ajaxMethod, ajaxUrl, true);
	
	if(ajaxMethod == "POST"){
		ajaxHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajaxHttp.setRequestHeader("Content-length", ajaxParams.length);
		ajaxHttp.setRequestHeader("Connection", "close");
		var params = ajaxParams;
	}
	ajaxHttp.onreadystatechange = function(){
		if(ajaxHttp.readyState == 4){
			var ajaxResponse = ajaxHttp.responseText;
			//call custom function to handle server response
			window[ajaxCallback](ajaxResponse);
		}
	}
	
	ajaxHttp.send(params);
}
