// Javascript Start at 20070917

/******************************************************************************/
/* AJAX XMLHttpRequest Page Load Function                                     */
/* Created by: Chau Yun Pang                                                  */
/* Created Date: 17 Sep 2007                                                  */
/******************************************************************************/

// How to use?
//
// 1. Copy the following line to HTML Code before </head>
// <script language="JavaScript" src="ajaxload.js"></script>
// <script language="Javascript">
// function loadPage() {
//   AJAXLoad("LOADFILE1", "DIVID1"); // LOADFILE1 - filename, DIVID1 - DIV Layer ID
//   AJAXLoad("LOADFILE2", "DIVID2"); // LOADFILE2 - filename, DIVID2 - DIV Layer ID
//   AJAXLoad("LOADFILE3", "DIVID3"); // LOADFILE3 - filename, DIVID3 - DIV Layer ID
// }
// </script>
//
// 2. Add the following line to inside <body> Tag 
// onLoad="loadPage()"
// Example: <body onLoad="loadPage()">


// The following is the configuration. Generally, only need to modify folder and loading 
// Basic Configuration
//var protocol = location.protocol; // Protocol (http:, https:, etc)
//var protocol = ""; // Protocol (http:, https:, etc)
//var hostname = location.hostname; // Hostname (www.abc.com)
var host = location.href.substring(0, location.href.lastIndexOf('/'));
var folder = "/templates/"; // Folder, Start with '/' , 'End with '/'
// For Testing in Local Drive. Change to "/" + Your Folder Name
// Example: folder = "/D:/Palmary%20Related/projects/elinkinter/360/"

var loading = '<font size="1">Loading...</font>'; // Loading display label


// Function to load File to DIV Layer through AJAX XMLHttpRequest Call
function AJAXLoad(loadFile, divContentID) {
    // Set DIV Layer Inner HTML Content as Loading
		document.getElementById(divContentID).innerHTML = loading;

		var httpRequest = getHTTPObject(); // Create AJAX XMLHttpRequest
		var myRandom=parseInt(Math.random()*99999999);  // Cache Buster
    var loadURL = host + folder + loadFile + "?rand=" + myRandom;

		httpRequest.open("GET", loadURL, true);
		
		// Set AJAX XMLHttpRequest Response Function
		httpRequest.onreadystatechange = function(){
		  if (httpRequest.readyState == 4) { // Finish Loading
		    // Set DIV Layer Inner HTML Content as AJAX XMLHttpRequest Response Text
        document.getElementById(divContentID).innerHTML = httpRequest.responseText;
      }
    };

    // Send Request
		httpRequest.send(null);
}

// Function to Create AJAX XMLHttpRequest
function getHTTPObject() {
var xmlhttp;
/*@cc_on
 @if (@_jscript_version >= 5)
  try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
      try {
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (E) {
          xmlhttp = false;
          }
      }
 @else
  xmlhttp = false;
 @end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
 try {
   xmlhttp = new XMLHttpRequest();
   } catch (e) {
   xmlhttp = false;
   }
  }
  return xmlhttp;
}

// Javascript End at 20070917

