
function mozileTransportDriver_webdav() {
	this.p = new DavClient();
}

mozileTransportDriver_webdav.prototype.load = function (filename, td) {
	this.p.request.td = td;
	//backup Massnahme (sometimes td get's lost with the request...)
	bxe_config.td = td;
	this.p.request.onload = this.loadCallback;
	this.p.GET(filename);
}

mozileTransportDriver_webdav.prototype.save = function (filename, content, td) {
	this.p.request.td = td;
	this.p.request.onload = this.saveCallback;
	this.p.PUT(filename, content );
}

mozileTransportDriver_webdav.prototype.loadCallback = function (e) {
	
	var p = e.currentTarget;
	var td = p.td;
	//backup Massnahme (sometimes td get's lost with the request...)
	if (!td) {
		td = bxe_config.td;
	}
	
	var reqObj = new Object();
	// if there's no element called parsererror...
	
	if (!p.responseXML) {
		reqObj = td.container.parseResponseText(p.responseText);
	}
	else if (p.responseXML.getElementsByTagNameNS("http://www.mozilla.org/newlayout/xml/parsererror.xml","parsererror").length == 0) {
		reqObj.document = p.responseXML;
		reqObj.isError = false;
		reqObj.status = 200;
		reqObj.statusText = "OK";
	} else if (p.responseXML) {
		reqObj =  td.container.parseResponseXML(p.responseXML);
	}
	else {
		reqObj = td.container.parseResponseText(p.responseText);
	}
	td.loadCallback(reqObj);
}

mozileTransportDriver_webdav.prototype.saveCallback = function (e) {
	var p = e.currentTarget;
	var td = p.td;
	var reqObj = new Object();
	// status code = 204, then it's ok
	if (p.status == 204) {
		reqObj.document = p.responseXML;
		reqObj.isError = false;
		reqObj.status = 200;
		reqObj.statusText = "OK";
	} 
	else if (p.status == 201) {
		reqObj.document = p.responseXML;
		reqObj.isError = false;
		reqObj.status = 201;
		reqObj.statusText = "Created";
	}
	else if (p.responseXML) {
		reqObj = td.container.parseResponseXML(p.responseXML, p.status);
	} else {
		reqObj = td.container.parseResponseText(p.responseText, p.status);
	}
	reqObj.originalStatus = p.status;
	reqObj.originalStatusTest = p.statusText;
	td.saveCallback(reqObj);
}

mozileTransportDriver_webdav.prototype.parseResponseXML = function(responseXML, status) {
		var reqObj = new Object();

	// try to find parserror
		var parserErrorNode = responseXML.getElementsByTagNameNS("http://www.mozilla.org/newlayout/xml/parsererror.xml","parsererror")[0];
		if (parserErrorNode)
		{
			alerttext = parserErrorNode.firstChild.data;
			var sourceNode = parserErrorNode.getElementsByTagName("sourcetext")[0];
			if (sourceNode) {
				alerttext += "\n" + sourceNode.firstChild.data;
			}
			alerttext+= strXML;
		}
		else
		{
			alerttext="Something went wrong:\n\n" + status + "\n\n";
			var objXMLSerializer = new XMLSerializer;
			var strXML = objXMLSerializer.serializeToString(responseXML.documentElement);
			alerttext+= strXML;
		}
		reqObj.isError = true;
		reqObj.statusText = alerttext;
		reqObj.document = responseXML;
		if (status === 0) {
			reqObj.status = 400;
		} else {
			reqObj.status = status;
		}
		return reqObj;
	
}

mozileTransportDriver_webdav.prototype.parseResponseText = function(responseText, status) {

	var reqObj = new Object();

	alerttext="Something went wrong:\n\n";
	alerttext += responseText ;
	reqObj.isError = true;
	reqObj.statusText = alerttext;
	if (status === 0) {
		reqObj.status = 400;
	} else {
		reqObj.status = status;
	}
	return reqObj;
}


@@ -1154,32 +1154,485 @@
 esponseXML) %7B%0A%09%09
+%0A%09%09//looks like a parse error, try removing script tags inserted by eg. ZoneAlarm%0A%09%09var parser = new DOMParser();%0A%09%09%0A%09%09var xmlstr = p.responseText;%0A%09%09xmlstr = xmlstr.replace(/%3Cscript%5B%5E%3E%5D+%3E%5B%5E%3C%5D*%3C%5C/script%3E/g,%22%22);%0A%09%09var xmldoc = parser.parseFromString(xmlstr,%22text/xml%22);%0A%09%09if (xmldoc.documentElement.nodeName != 'parsererror') %7B%0A%09%09%09reqObj.document = xmldoc;%0A%09%09%09reqObj.isError = false;%0A%09%09%09reqObj.status = 200;%0A%09%09%09reqObj.statusText = %22OK%22;%0A%09%09%7D else %7B%0A%09%09%0A%09%09%09
 reqObj =  td.con
@@ -1671,16 +1671,20 @@
 seXML);%0A
+%09%09%7D%0A
 %09%7D%0A%09else

remove script tags, if there's a parse error. helps with shitty ZoneAlarm