function getIframe( id ){
	obj = document.getElementById( id );
	if( obj ) return obj;
	
	return getIframe( id );
}


function IFrameRequest(){
	this.IFrameObj = null;
	this.onreadystatechange = function(){}
	this.IFrameId = 'RSIFrame_' + (new Date()).getTime().toString() + '_' + Math.random().toString().replace('.','');	

	this._callToServer = function( URL ){
		var tempIFrame=document.createElement('iframe');
		tempIFrame.setAttribute('id', this.IFrameId );
		tempIFrame.setAttribute('name', this.IFrameId );
		tempIFrame.style.border='0px';
		tempIFrame.style.width='0px';
		tempIFrame.style.height='0px';
		tempIFrame.style.display='none';
		/*tempIFrame.src = URL;*/
		
		var oAjaxFContainer = document.getElementById("ajaxFContainer");
		
		this.IFrameObj = tempIFrame;
		
		var selfObj = this;
		if (selfObj.IFrameObj.addEventListener){
			selfObj.IFrameObj.addEventListener('load', function(){
				selfObj._handleResponse( selfObj.IFrameObj );
			}, true);
		}
		if (selfObj.IFrameObj.attachEvent){
			selfObj.IFrameObj.attachEvent('onload', function(){
				selfObj._handleResponse( selfObj.IFrameObj );
			});
		}
		
		this.IFrameObj = tempIFrame;
		
		oAjaxFContainer.appendChild( tempIFrame );
		
		
		this.IFrameObj = document.getElementById( this.IFrameId );
		this.IFrameObj.contentWindow.location.replace( URL );
		
		
		this.readyState = 1;
		tempIFrame = null;
		return false;
	}

	this._extractIFrameBody = function( iFrameEl, returnDoc ) {
		var doc = null;
		
		if (iFrameEl.contentDocument ) { // For NS6
			doc = iFrameEl.contentDocument; 
		} else if (iFrameEl.contentWindow) { // For IE5.5 and IE6
			doc = iFrameEl.contentWindow.document;
		} else if (iFrameEl.document) { // For IE5
			doc = iFrameEl.document;
		} else {
			return null;
		}
		
		if( returnDoc ) return doc;
		return doc.body;
	}
	
	this._handleResponse = function( obj ) {
		if( this.doNotReadResponse ) return '';
	
		if( this.hasErrors( obj ) ){
			this.success = false;
			this.responseText = '';
		}else{
			this.success = true;
			this.responseText = this._extractIFrameBody( obj ).innerHTML;
		}
		
		this.responseText = this.responseText.split('&lt;').join('<');
		this.responseText = this.responseText.split('&gt;').join('>');
		this.responseText = this.responseText.split('&amp;nbsp;').join('&nbsp;');
		this.responseText = this.responseText.split('&amp;').join('&');
		this.responseText = this.responseText.replace( /^<pre>|<\/pre>$/gi, '' );
		this.responseText = unescape( this.responseText );
		this.readyState = 4;
		this.onreadystatechange();
		document.getElementById("ajaxFContainer").removeChild( this.IFrameObj );
		this.IFrameObj = null;
	}
	
	this.hasErrors = function( obj ){
		var documentTitle = this._extractIFrameBody( obj, true ).title;
		
		documentTitle = documentTitle.toLowerCase();
		documentTitle = documentTitle.replace(/(tomcat)\/[0-9\.]* /g, "$1 ");
		
		
		if( documentTitle == '404 not found' ) return true;
		if( documentTitle == 'the page cannot be found' ) return true;
		if( documentTitle == 'apache tomcat - error report' ) return true;
		if( documentTitle.match(/erro.*404/i) ) return true;
		if( documentTitle.match(/erro.*500/i) ) return true;
		
		return false;
	}
	
	this.open = function( argMethod, argURL, argAsync ){
		this.method = argMethod;
		this.url = argURL;
		this.async = argAsync;
	}
	
	this.send = function( argQueryString ){
		this.readyState = 0;
		this.responseText = null;
		this._callToServer( this.url );
	}
	
}
