
function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	}
	else {
		return document[movieName];
	}
}

function doGetById(id) {
	var e = null;
	if (typeof(document.getElementById) != 'undefined') {
		e = document.getElementById(id);
	}
	if ((e == null) && (typeof(document.all) != 'undefined')) {
		e = document.all[id];
	}
	if ((e == null) && (typeof(document.forms) != 'undefined')) {
		e = document.forms[id];
	}
	if ((e == null) && (typeof(document.images) != 'undefined')) {
		e = document.images[id];
	}
	return e;
}

function doGetUrl(args) {
	var url = args.url;
	var rt = (args.sendAs == 'text' ? 'text/plain' : (args.sendAs != null ? args.sendAs : 'text/xml'));
	var dt = (args.handleAs == 'text' ? 'text/plain' : (args.handleAs != null ? args.handleAs : 'text/xml'));
	var handler = args.load;
	var loader = new DocumentLoader(url, null, handler, rt, dt);
	loader.load();
}

/** An exception caused when loading or trying to load data.
	@constructor
	*/
function DataException(msg) {
	/** Any detailed error message (may be null)
		@type String
		*/
	this.message = msg;
	/** Always true - this is an error object!
		@type boolean
		*/
	this.isError = true;
	/** Get a simple text representation of this object.
		@return A text string of format '[object DataException message='errormessage']'
		*/
	this.toString = function() {
		return '[object DataException message=\'' + this.message + '\' ]';
	};
}

/** Generic XML loader object.
	@param url The URL of the XML file to open.
	@param request Any request data to be POSTed to the URL.
	@param callback The function to call with the data once it is loaded.
	The function should have one argument and will be called with
	either an Document object (if successful) or a {@link DataException}
	object if an error occurs. This can be tested for by calling object.isError
	on the returned object.
	@param requestContentType The request content type (optional). Can be used for 
	SOAP services for example by setting it to 'text/xml' or 'application/soap+xml'.
	@constructor
	*/
function DocumentLoader(url, request, callback, requestContentType, responseContentType) {
	/** The URL of the XML file to open */
	var path = url;
	/** Any request data to be POSTed to the URL */
	var qs = request || '';
	var ct = requestContentType || '';
	var rct = responseContentType || '';
	/** The function to call with the data once it is loaded */
	var callback = callback;
	/** Function called when the data has been loaded.
		@param xmlObject Either a XMLHttpObject or a SVGViewer data object.
		*/
	this.operationComplete = function(xmlObject, handleAsType) {
		var domDoc = null;
		if (xmlObject.success) {
			try {
				var s = xmlObject.content;
				if (handleAsType != 'text/plain')
					domDoc = parseXML(s, null);
				else
					domDoc = s;
			}
			catch (ex) {
				if (ex) {
					var e = new DataException(ex.toString());
					callback.call(null, e);
				}
				else {
					var e = new DataException('Fatal XML load error');
					callback.call(null, e);
				}
			}
		}
		else if (xmlObject.readyState) {
			if (xmlObject.readyState == 4) {
				try {
					if ((handleAsType != 'text/plain') && xmlObject.responseXML) {
						domDoc = xmlObject.responseXML;
					}
					else {
						domDoc = xmlObject;
					}
				}
				catch (ex) {
					if (ex) {
						var e = new DataException(ex.toString());
						callback.call(null, e);
					}
					else {
						var e = new DataException('Fatal XML load error');
						callback.call(null, e);
					}
				}
			}
		}
		else {
			if (xmlObject) {
				var e = new DataException('XML data object ' + xmlObject.toString() + ' is invalid');
				callback.call(null, e);
			}
			else {
				var e = new DataException('Data object is null');
				callback.call(null, e);
			}
		}
		if (domDoc) {
			callback.call(null, domDoc);
		}
	};
	/** Start the loading of the XML data.
		*/
	this.load = function() {
		var me = this;
		try {
			// SVG Viewer
			if (window.getURL) {
				if (qs && (qs != '')) {
					if (ct && (ct != '')) {
						window.postURL(path, qs, this, ct);
					}
					else {
						window.postURL(path, qs, this);
					}
				}
				else {
					window.getURL(path, this);
				}
			}
			// Mozillans
			else if (window.XMLHttpRequest) {
				var xmlhttp = new XMLHttpRequest();
				xmlhttp.onreadystatechange = function() {
					me.operationComplete(xmlhttp, rct);
				};
				if (qs && (qs != '')) {
					xmlhttp.open('POST', path, true);
					if (ct && (ct != '')) {
						xmlhttp.setRequestHeader('Content-Type', ct);
					}
					xmlhttp.send(qs);
				}
				else {
					xmlhttp.open('GET', path, true);
					xmlhttp.send(null);
				}
			}
			// IE
			else if (window.ActiveXObject) {
				// IE is fussier than the others about MIME types (!!!?!)
				if (window.location.protocol == 'http:') {
					var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
					if (xmlhttp) {
						xmlhttp.onreadystatechange = function() {
							me.operationComplete(xmlhttp, rct);
						};
						if (qs && (qs != '')) {
							xmlhttp.open('POST', path, true);
							if (ct && (ct != '')) {
								xmlhttp.setRequestHeader('Content-Type', ct);
							}
							xmlhttp.send(qs);
						}
						else {
							xmlhttp.open('GET', path, true);
							xmlhttp.send();
						}
					}
				}
				// Local file because MIME type will not be set
				else {
					var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
					xmldoc.onreadystatechange = function() {
						me.operationComplete(xmldoc, rct);
					};
					xmldoc.load(path);
				}
			}
		}
		catch (ex) {
			if (ex) {
				var e = new DataException(ex.toString());
				callback.call(null, e);
			}
			else {
				var e = new DataException('Fatal XML load error');
				callback.call(null, e);
			}
		}
	};
	/** Get a simple text representation of this object.
		@return A text string of format '[object XmlLoader url='myurl']'
		*/
	this.toString = function() {
		return '[object XmlLoader url=\'' + path + '\' ]';
	};
}
