/* *******************************************************************
incAJAXHtmReader.js
Used for loading External HTM data from an HTM file into the current document.
-ajb 3/22/2007
******************************************************************** * Ajax Includes script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

//To include a page, invoke gbfunAjaxIncludeFile("afile.htm") in the BODY of page
//Included file MUST be from the same domain as the page displaying it.

//*************************************************************************************************************
// -- Main function syntax:  gfunAjaxIncludeFile('test.htm') 'Note htm document must be in the current domain

//*************************************************************************************************************
function gfunAjaxIncludeFile(sUrl) {
	var objRequest = false;

	// Attach a Random querystring to the URL to prevent caching
	var dRandDate = new Date();

	if (sUrl.indexOf("http://") == 0) {
		// External URL, so pass it to the ASP page to get the code
		sUrl = "/ExternalHtml.asp?rand=" + dRandDate.getTime() + "&url=" + ((encodeURI != null) ? encodeURI(sUrl) : escape(sUrl));
	}
	else {
		// Local file to be included
		sUrl += (sUrl.lastIndexOf("?") < sUrl.indexOf(".")) ? ("?rand=" + dRandDate.getTime()) : ("&rand=" + dRandDate.getTime());
	}
		
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		objRequest = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
			objRequest = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try {
				objRequest = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
		return false;
	
	objRequest.open('GET', sUrl, false); //get page synchronously 
	objRequest.send(null);

	//Write out the contents of the htm file
	if (window.location.href.indexOf("http") == -1 || objRequest.status==200) document.write(objRequest.responseText);

}
//*************************************************************************************************************


