var xmlHttp

function ajaxRequest(params) {
	xmlHttp = getXmlHttpObject();
	if (xmlHttp == null) {
		alert("Your browser does not support AJAX!");
		return;
  }
	params = params.split(",");
	var url = "ajax/php/ajax.php";
	var firstParam = true;
	var key = '';
	var value = '';
	for (var i in params) {
		urlParamId = (firstParam) ? "?" : "&";
		firstParam = false;
		paramSplit = params[i].split(':');
		key = paramSplit[0];
		delete paramSplit[0];
		value = paramSplit.join(':').substring(1);
		url = url+urlParamId+key+"="+value;
	}
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChanged() { 
	if (xmlHttp.readyState == 4) {
		var response = xmlHttp.responseText;
		//alert(response);
		ajaxActions = response.split("\n.\n.");
		if (ajaxActions[0] != null) {
			for (var i in ajaxActions) {
				if (ajaxActions[i].length >= 1) {
					responseItem = ajaxActions[i].split("~!~");
					switch(responseItem[0]){
						case "divUpdate":
							var divToUpdate = document.getElementById(responseItem[1]);
							var divInnerHTML = responseItem[2];
							divToUpdate.innerHTML = divInnerHTML;
							break;
						case "doJS":
							eval(responseItem[1]);
							break;
						case "alert":
							alert(responseItem[1]);
							break;
						default:
							alert(responseItem[1]);
							break;
					}
				}
			}
		} else {
			alert(response);
		}
	}
	Behaviour.apply();
}

function getXmlHttpObject() {
	var xmlHttp = null;
	try { xmlHttp = new XMLHttpRequest(); } // Firefox, Opera 8.0+, Safari
	catch (e) {
	  // Internet Explorer
	  try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  }
	return xmlHttp;
}