

function InetRequest() {
	this.xmlSrc = arguments.length==1 ? arguments[0] : null;
	this.xslSrc = arguments.length==2 ? arguments[1] : null;
	this.xmlDom = null;
	this.xslDom = null;
	this.httpApplet = null;
	this.httpNative = null;
	this.httpParameters = "";
	this.httpMethod = "GET";
	this.IEprefixes = ["MSXML2","Microsoft","MSXML","MSXML3"];
	this.IEprefix = null;
	this.IEendfixes = ["", ".6.0", ".3.0", ".4.0"]; //, ".5.0"
	this.IEendfix = null;
	this.isIE = /MSIE/gim.test(navigator.userAgent);
	this.isNS = /Gecko|Netscape6/gim.test(navigator.userAgent);
	this.isOP = /Opera/gim.test(navigator.userAgent);
	this.responseBody = null;
	this.responseText = null;
	this.responseXML = null;
		
	// XML/XSL METHOD'S !!
	this.loadXML = function(url) {
		this.xmlSrc = url;
		if (this.httpApplet != null) {
			this.httpApplet.setUrl(url);
			this.str2dom(this.xmlDom, this.httpApplet.execute());
		}
		else
			try { this.xmlDom.load(url); }catch(ex){};
	}
	this.loadXSL = function(url) {
		this.xslSrc = url;
		if (this.httpApplet != null) {
			this.httpApplet.setUrl(url);
			this.str2dom(this.xslDom, this.httpApplet.execute());
		}
		else
			try { this.xslDom.load(url); }catch(ex){};
	}
	this.reloadXML = function(){ this.loadXML(this.xmlSrc); }
	this.reloadXSL = function(){ this.loadXSL(this.xslSrc); }
	this.str2dom = function(dom, xml) {
		if (window.ActiveXObject)
			dom.loadXML(xml);
		else if (document.implementation && document.implementation.createDocument) {
			var nsdom = (new DOMParser()).parseFromString(xml, "text/xml");
			while (dom.hasChildNodes())
				dom.removeChild(dom.lastChild);
			for (var i=0; i < nsdom.childNodes.length; i++)
				dom.appendChild(dom.importNode(nsdom.childNodes[i], true));
		}
	}
	this.getTransformed = function() {
		var html = null;
		if (window.ActiveXObject)
			html = this.xmlDom.transformNode(this.xslDom);
		else if (document.implementation && document.implementation.createDocument) {
			var xsltProcessor = new XSLTProcessor();
			xsltProcessor.importStylesheet(this.xslDom);
			var htmlDom = xsltProcessor.transformToFragment(this.xmlDom, document);
			html = (new XMLSerializer()).serializeToString(htmlDom);
		}
		return html;
	}
	
	// REQUEST METHOD'S !!
	this.setRequestMethod = function(name) {
		this.httpMethod = name.toUpperCase();
		if (this.httpApplet != null)
			this.httpApplet.setRequestMethod(this.httpMethod);
	}
	this.addRequestParameter = function(name, value) {
		this.httpParameters +=(this.httpParameters!=""?"&":"")+window.escape(name)+"="+window.escape(value);
		//this.httpParameters +=(this.httpParameters!=""?"&":"")+window.escape(name)+"="+encodeURI(value);
		if (this.httpApplet != null)
			this.httpApplet.addRequestParameter(name, value);
	}
	this.sendRequest = function() {
		if (this.httpApplet != null)
			this.reloadXML();
		else {
			try {
				var n = this.httpNative;
				n.open("POST", this.xmlSrc, true);
				n.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				n.send(this.httpParameters);
				this.httpParameters = "";
				/*
				if (window.ActiveXObject)
					this.xmlDom.loadXML(this.responseText);
				else if (document.implementation && document.implementation.createDocument) {
					var nsdom = (new DOMParser()).parseFromString(str, "text/xml");
					while (this.xmlDom.hasChildNodes())
						this.xmlDom.removeChild(this.xmlDom.lastChild);
					for (var i=0; i < nsdom.childNodes.length; i++)
						this.xmlDom.appendChild(this.xmlDom.importNode(nsdom.childNodes[i], true));
				}
				*/
			}catch(e){}	
		}
		return true;
	}
	
	this.main = function() {
		// CREATE HTTPAPPLET-OBJECT !!
		if (!document.getElementById("httpApplet"))
			;//document.body.innerHTML += "<applet id=\"httpApplet\" code=\"xmlcomm.class\" width=\"0\" height=\"0\"></applet>\n";
		try { this.httpApplet = document.getElementById("httpApplet"); }
		catch (ex) { this.httpApplet = null; }
		// CREATE XML/XSL-OBJECT !!
		try {
			if (window.ActiveXObject) {
				if (window.ActiveXObject)
				this.httpNative = null;
				for (var i=0; i<this.IEprefixes.length; i++) {
					for (var j=0; j<this.IEendfixes.length; j++) {
						try {
							this.httpNative = new ActiveXObject(this.IEprefixes[i] + ".XMLHTTP" + this.IEendfixes[j]);
							this.IEprefix = this.IEprefixes[i];
							this.IEendfix = this.IEendfixes[j];
						}catch (ex) {};
					}
				}
				//this.xmlDom = new ActiveXObject(this.IEprefix + ".XMLDOM");
				//this.xslDom = new ActiveXObject(this.IEprefix + ".XMLDOM");
				//this.xmlDom.async = false;
				//this.xslDom.async = false;
				//this.httpNative = new ActiveXObject(this.IEprefix + ".XMLHTTP" + this.IEendfix);
			}
			else if (document.implementation && document.implementation.createDocument) {
				this.xmlDom = document.implementation.createDocument("", "", null);
				this.xslDom = document.implementation.createDocument("http://www.w3.org/1999/XSL/Transform","stylesheet",null);
				if (this.xmlDom.readyState == null) {
					this.xmlDom.readyState = 1;
					this.xmlDom.addEventListener("load", function(){
						this.xmlDom.readyState = 4;
						if (typeof this.xmlDom.onreadystatechange == "function")
							this.xmlDom.onreadystatechange();
					}, false);
				}
				this.httpNative = new XMLHttpRequest();
			}
		}catch(ex){ throw new Error("Your browser does not support XML-objects"); }
	}
	this.main();
}


