function updateSelect(elem) {
  var go = document.getElementsByName('gamintojas');
  if (go.length > 0) {
    go = go[0];
    var gamintojas = $F(go);
  }
  
  var vo = document.getElementsByName('veikla');
  
  if (vo.length > 0) {
    vo = vo[0];
    var veikla = $F(vo);
  }
  
  var url ='/lt/grupes';
  var pars = '';
  
  if (elem == 'veikla') {
    
    pars = 'veikla='+veikla;
    if (gamintojas > 0) {
      pars = pars + '&gamintojas='+gamintojas;
    }
  } else {
    pars = 'gamintojas='+gamintojas;
  } 
  var myAjax = new Ajax.Request(
  url, 
  {
    method: 'post', 
    parameters: pars, 
    onComplete: showResponse
  });
}

function showResponse(originalRequest)
{
     var xmldoc = originalRequest.responseXML;
          
     var root = xmldoc.getElementsByTagName('veiklos');
     if (root.length > 0) {
      
      root = root.item(0);
      var count=0;
     
      var veikla = document.getElementsByName('veikla').item(0);
      veikla.options.length=count;
      for (var iNode = 0; iNode < root.childNodes.length; iNode++) {
        var node = root.childNodes.item(iNode);
        var id=node.getAttribute("value");
        
        var mytitle= node.firstChild.nodeValue;
        
        veikla.options[count] = new Option(mytitle,id);
        count+=1;
        veikla.options.length=count;
 
      }
            
    }
     
     var root = xmldoc.getElementsByTagName('rusys');
     if (root.length > 0) {
      
      root = root.item(0);
      var count=0;
     
      var rusis = document.getElementsByName('rusis').item(0);
      rusis.options.length=count;
      for (var iNode = 0; iNode < root.childNodes.length; iNode++) {
        var node = root.childNodes.item(iNode);
        var id=node.getAttribute("value");
        
        var mytitle= node.firstChild.nodeValue;
        
        rusis.options[count] = new Option(mytitle,id);
        count+=1;
        rusis.options.length=count;
 
      }
            
    }
}

