var SELECTS_URL = "/cgi-bin/selects.cgi";
var QUERY_URL = "/cgi-bin/institutions.cgi";

var xhttp = undefined;
if (window.XMLHttpRequest)
 xhttp = new XMLHttpRequest();
else xhttp=new ActiveXObject("Microsoft.XMLHTTP");

function getData(dataSource, divID){
    if(xhttp) {
     var obj = document.getElementById(divID);
     xhttp.open("GET", dataSource,false);
     xhttp.send(null);
     obj.innerHTML = xhttp.responseText;

/*     xhttp.onreadystatechange = function(){
      if (xhttp.readyState == 4 && xhttp.status == 200) {
        obj.innerHTML = xhttp.responseText;
      }
     }*/
    }
}

function get_selects(select){
    if(xhttp){
        xhttp.open("GET",SELECTS_URL+"?type="+select,false);
        xhttp.send(null);
        return xhttp.responseText;

    }
    return null;
}

function get_dbdata(table_id){
    var district,number,instype;
    var query;
    district = document.getElementById("district").value;
    number = document.getElementById("number").value;
    instype = document.getElementById("instype").value;
    query = QUERY_URL+"?district="+district+"&number="+number+"&instype="+instype;
    if(xhttp){
        xhttp.open("GET",query);
        xhttp.send(null);
        xhttp.onreadystatechange = function(){
          if (xhttp.readyState == 4 && xhttp.status == 200) {
              document.getElementById(table_id).innerHTML = xhttp.responseText;
          }
        }

    }
    form = document.getElementById("card").reset();
}

function clear_fields(){
    var obj;
    obj = document.getElementById("district");
    obj.selectedIndex = 0;
    obj = document.getElementById("instype");
    obj.selectedIndex = 0;
}

function clear_number(){
    var obj;
    obj = document.getElementById("number");
    obj.selectedIndex = 0;
}
