/*============================================================================||
||       __  ___  _______    ___  ____  __         ___                        ||
||      /  \/  /_/__  __/_ _/ __\/_/  \/ /   _____/   \                       ||
||     / /\_/ / ___/ / __ `/ /  __/ __/  \  / ___/  `_/                       ||
||    / /  / / __// / /_/ / /__/ / / / /\ \/ __// /\ \                        ||
||   /_/  /_/____/_/\__,_/\___/_/_/ /_/ /_/____/_/ /_/                        ||
||                                                                            ||
||============================================================================||
|| XXML																		  ||
|| Copyright Tim Jones. All Rights Reserved.                                  ||
||============================================================================*/

var XXML = {};

//=============================================================================

XXML.HTTP = null;

//=============================================================================
/*
	Returns a XML HTTP Request Object

	@Return
		XML HTTP Request Object, or null if incapable
*/
XXML.GetHTTP = function() {
	if(XXML.HTTP != null) {
		delete XXML.HTTP;
	}

	if(window.XMLHttpRequest) {
		XXML.HTTP = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		try {
			XXML.HTTP = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				XXML.HTTP = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	return XXML.HTTP;
}

//-----------------------------------------------------------------------------
/*
	Returns the contents of a URL

	URL			The URL of the page
	Callback	Callback function for OnReadyStateChange of HTTP Request

	@Return
		HTTP Request responseText
*/
XXML.GetPage = function(URL, Callback) {
	var HTTP = XXML.SendRequest(URL, Callback, false);

	return HTTP.responseText;
}

//-----------------------------------------------------------------------------
/*
	Sends a HTTP Request to the specified URL

	URL			The URL of the page
	Callback	Callback function for OnReadyStateChange of HTTP Request
	Async		If this process is asynchronous or not

	@Return
		The HTTP Request Object
*/
XXML.SendRequest = function(URL, Callback, Async) {
	var HTTP = XXML.GetHTTP();

	if(HTTP == null) {
		return;
	}

	/*HTTP.onreadystatechange = function() { 	
		if (HTTP.readyState == 4) {
			if (HTTP.status == 200) {
				if(Callback) {
					Callback(HTTP);
				}
			} else {
				alert("ERROR : " + HTTP.status);
			}
		}

	};*/

	SplitString = function(Input, Char) {
		var Strings = new Array();

		var Index = Input.indexOf(Char);

		if(Index == -1) {
			Index = Input.length;
		}

		Strings[0] = Input.substr(0, Index);
		Strings[1] = Input.substr(Index + 1, Input.length);

		return Strings;
	}

	var Strings = SplitString(URL, "?");
	
	/*HTTP.open("POST", Strings[0], Async); 
	HTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	HTTP.setRequestHeader("Content-length", Strings[1].length);
	HTTP.setRequestHeader("Connection", "close");
	HTTP.send(Strings[1]);*/

	///*	
	HTTP.open("GET", URL, Async); 
	HTTP.send("");
	//*/

	return HTTP;
}

//-----------------------------------------------------------------------------
/*
	Returns the contents of a URL

	URL			The URL of the page
	Callback	Callback function for OnReadyStateChange of HTTP Request

	@Return
		HTTP Request responseText
*/
XXML.GetPage_POST = function(URL, Callback) {
	var HTTP = XXML.SendRequest_POST(URL, Callback, false);

	return HTTP.responseText;
}

//-----------------------------------------------------------------------------
/*
	Sends a HTTP Request to the specified URL

	URL			The URL of the page
	Callback	Callback function for OnReadyStateChange of HTTP Request
	Async		If this process is asynchronous or not

	@Return
		The HTTP Request Object
*/
XXML.SendRequest_POST = function(URL, Callback, Async) {
	var HTTP = XXML.GetHTTP();

	if(HTTP == null) {
		return;
	}

	SplitString = function(Input, Char) {
		var Strings = new Array();

		var Index = Input.indexOf(Char);

		if(Index == -1) {
			Index = Input.length;
		}

		Strings[0] = Input.substr(0, Index);
		Strings[1] = Input.substr(Index + 1, Input.length);

		return Strings;
	}

	var Strings = SplitString(URL, "?");
	
	HTTP.open("POST", Strings[0], Async); 
	HTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	HTTP.setRequestHeader("Content-length", Strings[1].length);
	HTTP.setRequestHeader("Connection", "close");
	HTTP.send(Strings[1]);

	return HTTP;
}

//=============================================================================
/*
	Cleans a variable fit for a URL string

	Input	The variable to clean (string)

	@Return
		The cleaned input
*/
XXML.CleanURLArg = function(Input) {
	/*Input = Input.replace(/&/g, "%26");
	Input = Input.replace(/=/g, "%3D");
	Input = Input.replace(/\+/g, "%2B");*/

	Input = escape(Input);

	return Input;
}

//-----------------------------------------------------------------------------
/*
	Uncleans a variable

	@Return
		The uncleaned input
*/
XXML.UncleanURLArg = function(Input) {
	/*Input = Input.replace(/%26/g, "&");
	Input = Input.replace(/%3D/g, "=");
	Input = Input.replace(/%2B/g, "+");*/

	Input = unescape(Input);

	return Input;
}
//=============================================================================
