/*************************************************************************************
Class WSIFrameRequest:
	Simulate a regular ajax request through a dynamic IFrame creation.
	Compatibale with all browsers (including IE 5.5)
	Somewhat awkward to us, because script should be execute from the created IFrame.
*************************************************************************************/
function WSIFrameRequest(bInteractive) 
{
	typeof(WSIFrameRequest.counter)=='undefined' ? WSIFrameRequest.counter=0 :++WSIFrameRequest.counter; //static
	this.readyState = 0;
	this.status = 0;
	this.responseText = "";
	this.bInteractive=(typeof(bInteractive)=="undefined" || bInteractive==null || bInteractive);
	this.counter = WSIFrameRequest.counter;
}
//------------------------------------------------------------------------
WSIFrameRequest.prototype.open = function(protocol, url, async) {
	this.protocol = protocol;
	this.url = url;
}
//------------------------------------------------------------------------
WSIFrameRequest.prototype.onreadystatechange = function() { }
//------------------------------------------------------------------------
WSIFrameRequest.prototype.send = function(postBody) {
	var self = this;
	if (this.protocol.toUpperCase()=='POST') {
		if (typeof(postBody)!='undefined' && postBody!=null) {
			this.url = this.url + "&" + postBody;
		}	
	}
	var frame_id = "WSIframeReq_" + this.counter;
	var IFrameDoc = document.createElement('iframe');
	IFrameDoc.id  = frame_id;
	IFrameDoc.style.width = "0";
	IFrameDoc.style.height = "0";
	IFrameDoc.style.border = "0";
	IFrameDoc.src = this.url;
	IFrameDoc = document.body.appendChild(IFrameDoc);
	
	if (this.bInteractive) {
		this.readyState = 1;
		this.onreadystatechange();
		//WSDomUtils.addEvent(IFrameDoc,'load', function() {self.IFht(4,frame_id);});
		setTimeout(function(){self.IFht(4,frame_id);}, 4);
	}
	else {
		//give the iframe some time to initiliaze itself before removing it.
		setTimeout(function(){document.body.removeChild(IFrameDoc);},500);
		//setTimeout(function(){IFrameDoc.parentNode.removeChild(IFrameDoc);},500);
	}
}
//------------------------------------------------------------------------
WSIFrameRequest.prototype.overrideMimeType = function() { }
//------------------------------------------------------------------------
WSIFrameRequest.prototype.getResponseHeader = function (name) { return ''; }
//------------------------------------------------------------------------
WSIFrameRequest.prototype.setRequestHeader = function (name, data) { }
//------------------------------------------------------------------------
WSIFrameRequest.prototype.IFht = function (d, frame_id) {
	var self = this;
	var iframe = document.getElementById(frame_id);
	var finished_load = false;
	
	if (d<15 && (typeof iframe.readyState)!="undefined") { //For IE
		finished_load = (iframe.readyState=='complete');
	}
	else {
		finished_load =
			iframe && iframe.contentWindow &&
			iframe.contentWindow.document &&
			iframe.contentWindow.document.body &&
			iframe.contentWindow.document.body.innerHTML;
	}

	if (finished_load) {
		//self.responseText = iframe.contentWindow.document.body.innerHTML;
		var heads = iframe.contentWindow.document.getElementsByTagName('head');
		if (heads.length > 0) {
			self.responseText = heads[0].innerHTML;
		}
		//self.responseText = self.responseText.replace(/[\n\r]+/ig, "");
		iframe.parentNode.removeChild(iframe);
		self.status = 200;
		self.readyState = 4;
		self.onreadystatechange();
	}
	else {
		d*=1.5;
		setTimeout(function() {self.IFht(d,frame_id);},d);
	}
}
//------------------------------------------------------------------------
