/*
	March 2009 by Simon Kisby.
	This script can be freely used in any way shape or form.
*/

function createXMLHttpRequest() { /*  Standard function to create an Ajax Request */
	try { return new XMLHttpRequest(); } catch(e) {}
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	return null;
}
function test(url,vars,getpost,callback) { /* Function to debug 'ajax' function below */
	alert("url= "+url+"vars= "+vars+"getpost="+getpost+"callback="+callback);
}

/*  
	------------- function variables ----------------------------
	url = target url for the server side script
	vars = variables to be sent to the server side script
	getpost = how the variables are sent to the server
	callback = the callback function to handle the response from the server

	------------ example syntax of function variables ---------
	url = test.php
	vars = var1='lala'&no=1
	getpost = 'post' OR 'get'
	callback = function(){nameOfCallBack(xmlHttp);}	
*/

function ajax(url,vars,getpost,callback) { 
	xmlHttp=createXMLHttpRequest();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	xmlHttp.onreadystatechange=callback;
	if ( getpost == "get" ) {
		xmlHttp.open("get",url+"?"+vars, true);
		xmlHttp.send(null);
	}
	if ( getpost == "post" ) {
		xmlHttp.open("post",url,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.send(vars);	
		
	}
}

function $(id) {
	return document.getElementById(id);
}
			function $$(id) {
				return document.getElementsByName(id);
			}
