var xmlHttp = getXmlHttpObject();

function getXmlHttpObject() {
    var xmlHttp;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        //Internet Explorer
        var XmlHttpVersions = new Array("Msxml2.XMLHTTP.6.0",
                                        "Msxml2.XMLHTTP.5.0",
                                        "Msxml2.XMLHTTP.4.0",
                                        "Msxml2.XMLHTTP.3.0",
                                        "Msxml2.XMLHTTP",
                                        "Microsoft.XMLHTTP");
        // try every prog id until one works
        for (var i = 0; i < XmlHttpVersions.length && !xmlHttp; i++) {
            try {
                xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
            }
            catch(e) {}
        }
    }
    // return the created object or display an error message
    if (!xmlHttp) {
        alert("Error creating the XMLHttpRequest object.");
        return 0
    } else {
        return xmlHttp;
    }
}

function displayMenu(str) { 
    if (xmlHttp==null) {
        alert ("Browser does not support HTTP Request")
        return
    }
    
    var url="./menu.php?language=" + str;
    
    xmlHttp.open("GET",url,true);
    // must puts xmlHttp.onreadystatechange after xmlHttp.open for it to work properly
    xmlHttp.onreadystatechange=stateChangedMenu;
    xmlHttp.send(null);
}

function stateChangedMenu() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
        document.getElementById("menuLayout").innerHTML=xmlHttp.responseText;
    } 
}


function displayBody(str) { 
    if (xmlHttp==null) {
        alert ("Browser does not support HTTP Request")
        return
    }
    
    var url="./body.php?request=" + str;
    
    xmlHttp.open("GET",url,true);
    // must puts xmlHttp.onreadystatechange after xmlHttp.open for it to work properly
    xmlHttp.onreadystatechange=stateChangedBody;
    xmlHttp.send(null);
}

function stateChangedBody() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
        document.getElementById("bodyLayout").innerHTML=xmlHttp.responseText;
    } 
}

var question_id = ""
function question(str) {
    question_id = str
    if (xmlHttp==null) {
        alert ("Browser does not support HTTP Request")
        return
    }
    
    var url="./question.php?request=" + str;
    
    xmlHttp.open("GET",url,true);
    // must puts xmlHttp.onreadystatechange after xmlHttp.open for it to work properly
    xmlHttp.onreadystatechange=stateChangedQuestion;
    xmlHttp.send(null);
}

function stateChangedQuestion() {
    document.getElementById("chir_1").innerHTML="";
    document.getElementById("chir_2").innerHTML="";
    document.getElementById("chir_3").innerHTML="";
    document.getElementById("chir_4").innerHTML="";
    document.getElementById("chir_5").innerHTML="";
    document.getElementById("chir_6").innerHTML="";
    document.getElementById("chir_7").innerHTML="";
    document.getElementById("chir_8").innerHTML="";
    document.getElementById("chir_9").innerHTML="";
    document.getElementById("acu_1").innerHTML="";
    document.getElementById("acu_2").innerHTML="";
    document.getElementById("acu_3").innerHTML="";
    
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
        document.getElementById(question_id).innerHTML=xmlHttp.responseText;
    } 
}

function cauhoi(str) {
    question_id = str
    if (xmlHttp==null) {
        alert ("Browser does not support HTTP Request")
        return
    }
    
    var url="./question.php?request=" + str;
    
    xmlHttp.open("GET",url,true);
    // must puts xmlHttp.onreadystatechange after xmlHttp.open for it to work properly
    xmlHttp.onreadystatechange=stateChangedCauHoi;
    xmlHttp.send(null);
}

function stateChangedCauHoi() {
    document.getElementById("chinh_1").innerHTML="";
    document.getElementById("chinh_2").innerHTML="";
    document.getElementById("chinh_3").innerHTML="";
    document.getElementById("chinh_4").innerHTML="";
    document.getElementById("chinh_5").innerHTML="";
    document.getElementById("chinh_6").innerHTML="";
    document.getElementById("chinh_7").innerHTML="";
    document.getElementById("chinh_8").innerHTML="";
    document.getElementById("chinh_9").innerHTML="";
    document.getElementById("cham_1").innerHTML="";
    document.getElementById("cham_2").innerHTML="";
    document.getElementById("cham_3").innerHTML="";
    
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
        document.getElementById(question_id).innerHTML=xmlHttp.responseText;
    } 
}


function article(str) {
    if (xmlHttp==null) {
        alert ("Browser does not support HTTP Request")
        return
    }
    
    var url="./article.php?lang=English&request=" + str;
    
    xmlHttp.open("GET",url,true);
    // must puts xmlHttp.onreadystatechange after xmlHttp.open for it to work properly
    xmlHttp.onreadystatechange=stateChangedArticle;
    xmlHttp.send(null);
}

function stateChangedArticle() {
    
    document.getElementById("article_display").innerHTML="";
    
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
        document.getElementById("article_display").innerHTML=xmlHttp.responseText;
    } 
}


function baiviet(str) {
    if (xmlHttp==null) {
        alert ("Browser does not support HTTP Request")
        return
    }
    
    var url="./article.php?lang=Viet&request=" + str;
    
    xmlHttp.open("GET",url,true);
    // must puts xmlHttp.onreadystatechange after xmlHttp.open for it to work properly
    xmlHttp.onreadystatechange=stateChangedBaiViet;
    xmlHttp.send(null);
}

function stateChangedBaiViet() {
    
    document.getElementById("baiviet_display").innerHTML="";
    
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
        document.getElementById("baiviet_display").innerHTML=xmlHttp.responseText;
    } 
}

