/*# Metadata ################################### Header v.2
# $URL: http://gt-nas-1/svn/gamebase.frontend/trunk/xsl_gamebase/x__gamebase_2.0/js/GT.Request.HTML.js $
# $Rev: 1663 $
# $Date: 2011-03-01 15:41:08 +0100 (Di, 01 Mär 2011) $
# $Author: bstei $
### TOC ###################################################
#
### Description ###########################################
#	checks the HTTP response for an existing <div> tag with a success="true" attribute (on the root level)
#	and returns the containing elements to the onSuccess method.
#########################################################*/
(function ($) {
	this.GT = this.GT || {};
	this.GT.Request = this.GT.Request || {};
	this.GT.Request.HTML = this.GT.Request.HTML || new Class({
		Extends: Request.HTML,
		isSuccess: function () {
			var retVal = false;
			if ((this.status >= 200 && this.status < 300)){
				retVal = /^(?:<(?:\!|\?)[^>]*>\s*)?<div success="true">/.test(this.xhr.responseText);
			}
			return retVal;
		},
		success: function(text){
			var options = this.options, response = this.response;

			response.html = text.stripScripts(function(script){
				response.javascript = script;
			});

			response.html = response.html.replace(/^(?:<(?:\!|\?)[^>]*>\s*)?<div success="true">(\s)*/, '').replace(/(\s)*<\/div>$/, '');

			var temp = new Element('div').set('html', response.html);

			response.tree = temp.childNodes;
			response.elements = temp.getElements('*');

			if (options.filter) response.tree = response.elements.filter(options.filter);
			if (options.update) document.id(options.update).empty().set('html', response.html);
			else if (options.append) document.id(options.append).adopt(temp.getChildren());
			if (options.evalScripts) $exec(response.javascript);

			this.onSuccess(response.tree, response.elements, response.html, response.javascript);
		}
	});
})(document.id);
