    <head><title>scheduling.html</title></head>
    <script src=../window.js></script>
    <script src=../examples.js></script>

    <body>

    <input value="Send Query" type=button onclick="submitAll()">
    <br>
    <br>
    Enter filter:
    <input type=text id="filterexpr">

    <script>

    w = new win(50,100,700,400,"query window","querywindow.html")

    function submitAll() {
        s1.setVar("map_countries_class_color",
            Math.round(Math.random() * 255) + " "  +
            Math.round(Math.random() * 255) + " "  +
            Math.round(Math.random() * 255)
        )
    	var queryString = document.getElementById("filterexpr").value
    	if (queryString != "" ) s2.setVar("qstring",queryString)
    	else s2.setVar("qstring","/.*/")
        s2.submit()
    	s5.schedule()
    	s5.scheduleAfter(new Array(s3,s4))
    }

    function displayMap(s) {
    }

    function displayAll() {
        var mapimg = w.contentWindow.document.getElementsByTagName("img")[0]
        var mapurl = s3.getVar("img")
        mapimg.src = mapurl
    	var windowSpan = w.contentWindow.document.getElementsByTagName("span")[0]
    	var extentSpan = w.contentWindow.document.getElementsByTagName("span")[1]
    	var serverFrameBody =s4.contentWindow.document.body
    	windowSpan.innerHTML = serverFrameBody.innerHTML
    	extentSpan.innerHTML = "Returned extent: " + s3.getVar("mapext")
    }

    function processQuery(s) {
    	var tbl = s.contentWindow.document.getElementsByTagName("table")[0]
    	minx = miny = Number.POSITIVE_INFINITY
    	maxx = maxy = Number.NEGATIVE_INFINITY
    	for (var i=1;i<tbl.rows.length;i++) {
    		var r = tbl.rows[i].cells[1].innerHTML.split(" ")
    		for (var j=0;j<4;j++) r[j] = parseInt(r[j])
    		if (r[0]<minx) minx = r[0]
    		if (r[1]<miny) miny = r[1]
    		if (r[2]>maxx) maxx = r[2]
    		if (r[3]>maxy) maxy = r[3]
    	}
    	s1.setVar("mapext",minx + " " + miny + " " + maxx + " " + maxy)
    	s1.submit()
    }

    s1 = w.addServerFrame()
    s1.setServerURL(MSURL)
    s1.setVar("map",MSMAP)

    s2 = w.addServerFrame()
    s2.setServerURL(MSURL)
    s2.setVar("map",MSMAP)
    s2.setVar("mode","itemnquery")
    s2.setVar("qlayer","countries")
    s2.setVar("qitem","NAME")

    s3 = w.addServerFrame()

    s4 = w.addServerFrame()
    s4.setExecOnReturn(processQuery)

    s1.setTarget(s3)
    s2.setTarget(s4)

    s5 = new serverFrame()
    s5.setExecOnReturn(displayAll)

    </script>
    </body>