var IFrameObj; // our IFrame object;
var IFrameDoc;
var Visable = false;

//function callToServer(URL) {
function callToServer(FrameID, URL) {
	if (!document.createElement) {return true};

	var IFrameDoc;

	if (! IFrameObj && document.createElement) {
	// create the IFrame and assign a reference to the
	// object to our global variable IFrameObj.
	// this will only happen the first time
	// callToServer() is called
		try {
			var tempIFrame=document.createElement('iframe');
			//tempIFrame.setAttribute('id','RSIFrame');
			tempIFrame.setAttribute('id',FrameID);
			tempIFrame.setAttribute('Application','yes');
			tempIFrame.style.border='0px';
			tempIFrame.style.width='0px';
			tempIFrame.style.height='0px';
			tempIFrame.style.display='none';
			IFrameObj = document.body.appendChild(tempIFrame);

			if (document.frames) {
			// this is for IE5 Mac, because it will only
			// allow access to the document object
			// of the IFrame if we access it through
			// the document.frames array
				//IFrameObj = document.frames['RSIFrame'];
				IFrameObj = document.frames[FrameID];
			}

		} catch(exception) {
		// This is for IE5 PC, which does not allow dynamic creation
		// and manipulation of an iframe object. Instead, we'll fake
		// it up by creating our own objects.
			//iframeHTML='\<div><iframe id="RSIFrame" Application="yes" style="';
			iframeHTML='\<div><iframe id="' + FrameID + '" style="';
			iframeHTML+='border:0px;';
			iframeHTML+='display:none;';
			iframeHTML+='width:0px;';
			iframeHTML+='height:0px;';
			iframeHTML+='"><\/iframe></div>';
			document.body.innerHTML+=iframeHTML;
			IFrameObj = new Object();
			IFrameObj.document = new Object();
			IFrameObj.document.location = new Object();
			IFrameObj.document.location.iframe = document.getElementById(FrameID);
			IFrameObj.document.location.replace = function(location) {
				this.iframe.src = location;
			}
		}
	}

	if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
	// we have to give NS6 a fraction of a second
	// to recognize the new IFrame
		setTimeout('callToServer(' + URL + ')',10);
		return false;
	}

	if (IFrameObj.contentDocument) {
	// For NS6
		IFrameDoc = IFrameObj.contentDocument;
	} else if (IFrameObj.contentWindow) {
	// For IE5.5 and IE6
		IFrameDoc = IFrameObj.contentWindow.document;
	} else if (IFrameObj.document) {
	// For IE5
		IFrameDoc = IFrameObj.document;
	} else {
		return true;
	}

	IFrameDoc.location.replace(URL);

	return false;
}

// handleResponse is passed two parameters when called from the onload
// event of the pages loaded in the hidden IFRAME:
//	st: a string indicating where to load
//	doc: the document object of the page loaded in the IFRAME
function handleResponse(st, doc, frame) {

	var toObj = document.getElementById(st);

	if (frame == null || ! frame ) {
		//toObj.innerHTML = doc.body.innerHTML;
		if (doc.getElementById(st)) toObj.innerHTML = doc.getElementById(st).innerHTML;
		doc.getElementById(st).innerHTML = "";
	} else {
		if (toObj.contentWindow.document != doc) {
			toObj.contentWindow.document.location = doc.location;
			Loaded = true;
		}
	}

	//provide a "success" message
	//var responseMessage = document.getElementById('responseMessage');
	//responseMessage.innerHTML = 'loaded records from <a href="'+doc.location+'">this external file<\/a>.';
}

function InsertIFrameToSection(SectionID, NewFrameID, NewFrameName, UseCSStyle, SiteURL) {

	var NewIFrameObj;
	var TargetSectionObj;

  	if (!document.createElement) { return true };

  	TargetSectionObj	= document.getElementById(SectionID);
  	NewIFrameObj		= document.getElementById(NewFrameID);

  	if (TargetSectionObj && document.createElement) {

  		if (!NewIFrameObj) {

			var iframeHTML='<iFrame id="' + NewFrameID + '" name="' + NewFrameName + '" class="' + UseCSStyle + '" ';
			iframeHTML+='Applikation="yes" ';
			iframeHTML+='Frameborder="0" ';
			iframeHTML+='Marginwidth="0" ';
			iframeHTML+='Marginheight="0" ';
			iframeHTML+='onload="resizeFrame();" ';
			iframeHTML+='src="' + SiteURL + '">';
			iframeHTML+='<\/iFrame>';

			TargetSectionObj.innerHTML+=iframeHTML;

		} else {
 			Clear(NewFrameID, "true");

			NewIFrameObj.src = SiteURL;
		}


	}
	return true;
}
