/* Copyright (c) 2008 Marcus Derencius (marcus.derencius@surgeworks.com || http://surgeworks.com || http://derenci.us)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Version: 0.2
 * Requires jQuery 1.2.6
 * Docs: http://docs.jquery.com/Plugins/
 */

jQuery.extend({
  httpData: function( xhr, type, filter ) {
		var ct = xhr.getResponseHeader("content-type"),
			xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0,
			data = xml ? xhr.responseXML : xhr.responseText;

		if ( xml && data.documentElement.tagName == "parsererror" )
			throw "parsererror";

		// Allow a pre-filtering function to sanitize the response
		if( filter )
			data = filter( data, type );

		// If the type is "script", eval it in global context
		if ( type == "script" || (type == undefined && ct && ct.indexOf("javascript") >= 0 ))
			jQuery.globalEval( data );

		// Get the JavaScript object, if JSON is used.
		if ( type == "json" || (type == undefined && ct && ct.indexOf("json") >= 0 ))
			data = eval("(" + data + ")");

		return data;
	}
});