/*

This should be included in all documents:
		<script type="text/javascript" src="../../doc_utils.js"></script>

When loaded, this will:
1.  Add an onload listener to the window.
2.  When the data is loaded, it will send body.innerHTML to the parent window.
3.  The parent window can then display it as data.

NOTE:  Make sure that the document has a <body> tag!!!

*/

function sendData() {
	var bodyEl = document.getElementsByTagName("body")[0];
	setLinkTargets( bodyEl, 'docs' );
	if (window.parent.handleRPCData) {
		window.parent.handleRPCData( bodyEl.innerHTML );
	}
}

function setLinkTargets( el, targetWindowName ) {
	var allLinks	= el.getElementsByTagName('a');
	var u = allLinks.length;
	for (var i=0; i<u; i++) {
		allLinks[i].setAttribute( 'target', targetWindowName );
	}
}

//	Safe window onload event listener
//	Use this function to add window onload events without clobbering existing onload events.
function addLoadListener(fn) {
	if (typeof window.addEventListener != 'undefined') {
		window.addEventListener('load', fn, false);
	}
	else if (typeof document.addEventListener != 'undefined') {
		document.addEventListener('load', fn, false);
	}
	else if (typeof window.attachEvent != 'undefined') {
		window.attachEvent('onload', fn);
	}
	else {
		var oldfn = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = fn;
		} else {
			window.onload = function() {
				oldfn();
				fn();
			};
		}
	}
}


//	Init
addLoadListener( sendData );

