/*global $, ActiveXObject */
/*jslint browser: true, eqeqeq: true, undef: true */

$.extend({
	cloneObject: function (o) {
		var result, i;

		result = {};
		for (i in o) {
			if (o.hasOwnProperty(i)) {
				result[i] = o[i];
			}
		}
		return result;
	},

	/* A wrapper around $.ajax() that implements a workaround
	   to work on local files in MSIE.  Code from:
	   http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests */
	ajaxXML: function (options) {
		var new_options = $.cloneObject(options);

		new_options.dataType = ($.browser.msie) ? "text" : "xml";
		if (options.success) {
			new_options.success = function (data, status) {
				var xml;
				if (typeof data === "string") {
					xml = new ActiveXObject("Microsoft.XMLDOM");
					xml.async = false;
					xml.loadXML(data);
				}
				else {
					xml = data;
				}
				return options.success(xml, status);
			};
		}
		return $.ajax(new_options);
	}
});

