var emname;
console.log("program move");
function emnamecatch(name){
    emname=name;
    console.log(emname);
}

function emcondition(command) {

var ajax=getAjax();

    if (command == "request") {
        var position1 = document.getElementById("Position");
        var SpotsizeIndex = document.getElementById("SpotsizeIndex");
        var MagIndex = document.getElementById("MagIndex");
        var Obj = document.getElementById("Obj");
        var BeamTilt = document.getElementById("BeamTilt");
        var Speed = document.getElementById("Speed");
    } else {
        var position1 = document.anchorsgetElementById("result");
    }

    if (ajax) {
        try {
            ajax.onreadystatechange = getData;
        } catch (e) {
            position1.innerHTML = "Onreadystate change error.";
        }
        try {
            ajax.open("GET", "//localhost:9090/"+encodeURIComponent(emname)+"/get", true);
            console.log("//localhost:9090/"+encodeURIComponent(emname)+"/get");
        } catch (e) {
            position1.innerHTML = "ajax open error";
        }
        try {
            ajax.send(null);
        } catch (e) {
            position1.innerHTML = "send error";
        }

    } else {
        position1.innerHTML = "you cannot use ajax....";
    }

    function getData() {
        if (ajax.readyState == 4) {
            if (ajax.status == 200) {
                console.log("Hello!");
                var resultjson = ajax.responseText;
                resultjson = JSON.parse(resultjson);
                console.log(typeof resultjson);
                /*
                 for (key in resultjson) {
                 console.log(key+":"+resultjson(key));
                 }
                 */
                //position1.innerHTML=resultjson;
                position1.innerHTML = "x=" + resultjson["GonionX"] + " y=" + resultjson['GonionY'] + " z=" + resultjson['GonionZ'] + " a=" + resultjson['GonionA'];
                SpotsizeIndex.innerHTML = "Spotsize:" + resultjson['SpotsizeIndex'];
                MagIndex.innerHTML = "MagIndex:" + resultjson['MagIndex'];
                Obj.innerHTML = "Obj:" + resultjson['Obj'];
                BeamTilt.innerHTML = "BeamTilt:" + resultjson['BeamTilt'];
                Speed.innerHTML = "Speed:" + resultjson['Speed'];
                //   result.innerHTML = ajax.responseText;
            } else {
                position1.innerHTML = "HTTP transmission....";
            }
        }
    }
}