// Accuso Ajax Framework - Version 1.0.3

// Loading Box
var loadingBoxUniversal = document.createElement('div');
loadingBoxUniversal.style.position = 'absolute';
loadingBoxUniversal.style.top = '2px';
loadingBoxUniversal.style.right = '3px';
loadingBoxUniversal.style.color = '#fff';
loadingBoxUniversal.style.backgroundColor = '#b00';
loadingBoxUniversal.style.paddingTop = '1px';
loadingBoxUniversal.style.paddingRight = '3px';
loadingBoxUniversal.style.paddingBottom = '1px';
loadingBoxUniversal.style.paddingLeft = '3px';
loadingBoxUniversal.style.font = '12px Arial, Helvetica, sans-serif';
loadingBoxUniversal.style.zIndex = '99';
loadingBoxUniversal.style.display = 'none';
loadingBoxUniversal.style.id = 'loadingBoxUniversal';
loadingBoxUniversal.appendChild(document.createTextNode('Loading...'));
document.getElementsByTagName("body")[0].appendChild(loadingBoxUniversal);

// XMLHttpRequest Universal
var req;
function xmlHttpRequestGet(url, method) {
	loadingBoxUniversal.style.display = 'block';
	var branch = 0;
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		if (req) { branch = 1; }
	}
	// branch for IE/Windows ActiveX version
	else {
		try {
			if (window.ActiveXObject) {
				req = new ActiveXObject('Microsoft.XMLHTTP');
			}
		}
		catch (e) {
			//if (e) window.alert(e);
			window.alert("Fehler: Microsoft ActiveX ist deaktiviert. Die aufgerufene Funktion benoetigt jedoch ein ActiveX-Objekt. Bitte benutzen Sie entweder einen anderen Browser (z.B. Mozilla Firefox), oder aktivieren Sie die ActiveX-Unterstuetzung in den Internet Explorer Einstellungen. Fehlercode: '" + e + "'");
			branch = -1;
		}
		if (req) { branch = 2; }
	}
	// now doing the request
	if (branch > 0) {
		var initialTime = new Date();
		var timeout = initialTime.getTime() + ( 10 * 1000 );
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				if (req.status == 200) {
					var response = req.responseXML.documentElement;
					var amount = response.getElementsByTagName('amount')[0].firstChild.data
					var receivedData = new Array();
					for (i = 0; i < amount; i++) {
						receivedData[i] = response.getElementsByTagName('data')[i].firstChild.data;
					}
					var errors = response.getElementsByTagName('errors')[0].firstChild.data;
					loadingBoxUniversal.style.display = 'none';
					eval(method + '(errors, receivedData)');
				}
				else {
					alert("There was a problem retrieving the XML data:\n" + req.statusText);
				}
			}
			// Timeout
			var actualTime = new Date();
			if ( actualTime.getTime() > timeout ) {
				var errors = "Error: Connection timeout. Please try it again in a few seconds.";
				//window.alert(errors);
				var receivedData = new Array();
				loadingBoxUniversal.style.display = 'none';
				eval(method + '(errors, receivedData)');
				// Abort the request
				req.abort();
			}			
		}
		req.open('GET', url, true);
		if (branch == 1) {
			req.send(null);
		}
		else {
			req.send();
		}
	}
	// no MSIE ActiveX Error
	else if (branch == -1) {
		var errors = "Error: No ActiveX support by the Browser.";
		//window.alert(errors);
		var receivedData = new Array();
		loadingBoxUniversal.style.display = 'none';
		eval(method + '(errors, receivedData)');
	} 
	// no request - error
	else {
		var errors = "Error: No XMLHttpRequest support by the Browser.";
		window.alert(errors);
		var receivedData = new Array();
		loadingBoxUniversal.style.display = 'none';
		eval(method + '(errors, receivedData)');
	}
}
/*
Copyright (C) 2001-2007 Ulrich Mueller, Germany. All rights reserved. 
The sourcecode of this software may be edited 
and redistributed under the condition, that this copyright notice and the 
license statement must stay in the sourcecode.

Contact:  u l i @ a c c u s o . c o m

This software is OSI Certified Open Source Software.
OSI Certified is a certification mark of the Open Source Initiative.

This program is free software; you can redistribute it and/or modify it under 
the terms of the GNU General Public License as published by the Free Software 
Foundation; either version 2 of the License, or (at your option) any later 
version. This program is distributed in the hope that it will be useful, but 
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
details. You should have received a copy of the GNU General Public License 
along with this program; if not, write to the Free Software Foundation, Inc., 
59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

EOF
*/
