/******************************************************************************
This is a special test-jig version of clientSideInclude().  It is used to fix
the problem where images and linked stylesheets in the headers and footers
don't work while the HTML is surfed off the network share.
******************************************************************************/

/* accepts an href or src attribute's value. */
/* returns a modified version of it. */
function fixHREF (href) {
	if (!/^\//.test(href))	// is relative, or specifies a protocol
		return href;
	return "http://www.geindustrial.com" + href;
}

/* accepts the contents of an included file in their entirety. */
/* outputs the contents with any href or src attributes modified. */
function preprocess (text) {
	text = text.replace(/\b(href|src)\s*=\s*([\"\'])(.*?)\2/ig,
			    function (fulltext, attr, quote, contents) {
				    return attr + "=" + quote +
					    fixHREF(contents) + quote;
			    });
	return text;
}

function clientSideInclude(url) {
	var req = false;
	if (window.XMLHttpRequest) {
		// For Safari, Firefox, and other non-MS browsers
		try {
			req = new XMLHttpRequest();
		} catch (e) {
			req = false;
		}
	} else if (window.ActiveXObject) {
		// For Internet Explorer on Windows
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				req = false;
			}
		}
	}
	if (req) {
		// Synchronous request, wait till we have it all
		req.open('GET', url, false);
		var failure = false;
		try {
			req.send(null);
		} catch (e) {
			failure = true;
		}
		if (!failure) {
			document.write("<div class='includedViaClientSideInclude'>");
			document.write(preprocess(req.responseText));
			document.write("</div>");
		}
	} else {
		/* compatibility warning */
		//	element.innerHTML =
		//		"Sorry, your browser does not support " +
		//		"XMLHTTPRequest objects. This page requires " +
		//		"Internet Explorer 5 or better for Windows, " +
		//		"or Firefox for any system, or Safari. " +
		//		"Other compatible browsers may also exist.";
	}
}

