/**
*	Author		:	abaltazar@e-medhosting.com
*	Date		:	2009-08-06
*	Description	:	This file gathers a few handy functions to handle ajax communication.
*/

function GetXmlHttpObject() {
  if (window.XMLHttpRequest)        // code for IE7+, Firefox, Chrome, Opera, Safari
	return new XMLHttpRequest();
  if (window.ActiveXObject)         // code for IE6, IE5
	return new ActiveXObject("Microsoft.XMLHTTP");
  
  return null;
}


function SimpleAjaxRequest(method, url, params, func){
	this.stateChanged = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.responseXML != null){
			var response = xmlhttp.responseXML.getElementsByTagName('response')[0].childNodes[0];
			if(response != undefined){
				f(response.nodeValue);
			} else {
				f('');
			}
		}
	}
	var xmlhttp = GetXmlHttpObject();
	var f = func;
	
	url += '?ajax';
	
	if(method.toLowerCase() == "get"){
		url += params;
	}
	
	xmlhttp.onreadystatechange = this.stateChanged;
	xmlhttp.open(method, url, true);	
	
	if(method.toLowerCase() == "get"){
		xmlhttp.send(null);
	}else{
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.send(params);
	}	
}
