
var httpRequest = false;
var Ajax_ReturnValue;

if (window.XMLHttpRequest)  {
// Mozilla, Safari, ...
    httpRequest = new XMLHttpRequest();
    if (httpRequest.overrideMimeType)
        httpRequest.overrideMimeType('text/xml');
} else if (window.ActiveXObject)    {
// IE
    try { httpRequest = new ActiveXObject("Microsoft.XMLhttp"); }
    catch(e) {}
}

//setInterval('OnLoad()',60000);

/*************************************************************************************/

function Ajax_GetResponse(url, isASynchronous)   {

    if (httpRequest == null)   {
        alert('Cannot create a XMLHTTP instance!');
        return false;
    }
    
    httpRequest.open("GET", url, isASynchronous);
    
    httpRequest.onreadystatechange = 
        function()  {
		
            if (httpRequest.readyState == 4)    {
            // 如果狀態值為 4 代表伺服器已經傳回所有資訊了，便可以開始解析所得資訊。

                if (httpRequest.status == 200)  {
                // 萬事具備
                    Ajax_ReturnValue = httpRequest.responseText;
                }
                else    {
                // 似乎有點問題，或許伺服器傳回了 404 (查無此頁) 或者 500 (內部錯誤) 什麼的
                    alert('要求的過程中出現了錯誤！\n'
                        + '錯誤代碼:'
                        + httpRequest.status
                        + '其他訊息:'
                        + httpRequest.statusText);
                }
            }
        }
    
    httpRequest.send("");

}

function Ajax_ReplaceHTML(url, el) {
    if (httpRequest == null)   {
        alert('Cannot create a XMLHTTP instance!');
        return false;
    }
    
    httpRequest.onreadystatechange = 
        function()  {
            if (httpRequest.readyState == 4)    {
            // 如果狀態值為 4 代表伺服器已經傳回所有資訊了，便可以開始解析所得資訊。
                if (httpRequest.status == 200)  {
                // 萬事具備
                    if (el != null) el.innerHTML = httpRequest.responseText;
                }
                else    {
                // 似乎有點問題，或許伺服器傳回了 404 (查無此頁) 或者 500 (內部錯誤) 什麼的
                    alert('要求的過程中出現了錯誤！\n'
                        + '錯誤代碼:'
                        + httpRequest.status
                        + '其他訊息:'
                        + httpRequest.statusText);
                }
            }
        }
        
    httpRequest.open("GET", url, true);
    httpRequest.send("");
}
