﻿/*********************************************************************************************************************************************
Dynamic HTML and XML: The XMLHttpRequest Object

Function to load the .NET page after connection to the other page is successful.

In .NET this also means that if the page/application is still "Compiling" (because the user is the 1st user after some changes is made),It will 
not redirect the user to the requested URL.

After the page/application is compiled, it will then redirect the user to the requested URL.

Codes is found here: http://developer.apple.com/internet/webcontent/xmlhttpreq.html

*********************************************************************************************************************************************/
var req;
var url;
function OnFinishedLoad(requestedURL)
{
    url = requestedURL;
    loadXMLDoc(requestedURL);
}


function loadXMLDoc(url) 
{
    req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) 
    {
        try 
        {
	        req = new XMLHttpRequest();
        } 
        catch(e) 
        {
	        req = false;
        }
    // branch for IE/Windows ActiveX version
    } 
    else if(window.ActiveXObject) 
    {
        try 
        {
	        req = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch(e) 
        {
	        try 
	        {
  		        req = new ActiveXObject("Microsoft.XMLHTTP");
	        } 
	        catch(e) 
	        {
  		        req = false;
	        }
        }
    }
    if(req) 
    {
        req.onreadystatechange=processReqChange;
        req.open("GET", url, true);
        req.send(null);
    }
    else
    {
        alert("Unable to connect to ECM Module.");
        alert("Please ensure that you are connected to the Internet. \nIf problem persist, please contact your System Administrator.")
    }
}

function processReqChange() 
{
    // only if req shows "loaded"
    if (req.readyState == 4) 
    {
        // only if "OK"
        if (req.status == 200) 
        {
            window.top.location.href = url;
        } else 
        {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        }
    }
}
/**********************************************************************************************************************************************/