/*
	Lucid Creative Ltd,
	Creativestem.com

	Creativestem AJAX Interface, v 1.2

	Copyright (c) 2008 Lucid Creative Ltd. All rights 
	reserved. No portions of the code contained in this 
	file may be used without the explicit approval of 
	its sole rightholder, Lucid Creative Ltd.


	- CsAjax.js
	AJAX Interface for data transfer through the
	XMLHTTPRequest object.

*/

function CsAjax(Url, Method, Callback)
{
	this.AjaxRequestHandle = null;
	this.Callback = Callback;
	this.Method = Method;
	this.Url = Url;
	
	this.Initiate = function()
	{
		try
		{
			//Non-IE
			var XmlHTTP = new XMLHttpRequest();
		}
		catch(exception)
		{
			//MSIE
			var XmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
			if(!XmlHTTP)
			{
				var XmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
				if(!XmlHTTP)
				{
					return false;
				}
			}
		}
		
		this.AjaxRequestHandle = XmlHTTP;
		return true;
	}
	
	this.Send = function()
	{
		var csajax = this;
		this.AjaxRequestHandle.onreadystatechange = function()
		{
			if(csajax.AjaxRequestHandle == null) return false;
			
			if((csajax.AjaxRequestHandle.readyState == 4)
				&& (csajax.AjaxRequestHandle.status == 200))
			{
				eval(csajax.Callback+'(csajax.AjaxRequestHandle.responseText)');
			}
		}
		
		this.AjaxRequestHandle.open(this.Method, this.Url, true);
		this.AjaxRequestHandle.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
		this.AjaxRequestHandle.send(null);
		
	}
	
	this.Initiate();
}