function change_visibility(container,visib)
{
  try
  {
    container.style.visibility = visib;
  }
  catch(e)
  {
  }
  for(var j=0;j < container.childNodes.length; j++)
  {
    change_visibility(container.childNodes[j],visib);
  }
}
  
  
function cs_updateselector(asyncurl, currentselect, currentname, targetselect, subselects)
{
  var selectval = $F(currentselect);
  new Ajax.Request(asyncurl,
    {
      method: 'get',
      parameters: { currentselect: currentname, currentval: selectval},
      onSuccess: function(transport) {
         var json = transport.responseText.evalJSON();
         //console.dir(json);
         var subsel = $(targetselect);
         subsel.options.length = 0;
         if(json && json.values)
         {
           for(var i = 0; i < json.values.length; i++)
           {
             subsel.options[i] = new Option(json.values[i][1], json.values[i][0]);
           }
         }
         if(subselects.constructor == Array)
         {
           for(var h = 0; h < subselects.length; h++)
           { 
             var subname = subselects[h];
             var subsel = $(subname+'_container');
             if(subname == targetselect && $(subname).options.length > 0)
             {
               if($(subname).options.length == 1 && $(subname).options[0].value == "")
               {
                 change_visibility(subsel,'hidden');
               }
               else{
                 change_visibility(subsel,'visible');
               }
             }
             else
             {
               $(subname).options.length = 0;
               $(subname).options[0] = new Option("---","");
               change_visibility(subsel,'hidden');
             }
           }
         }
         //cs_checkforneededupdates();
      }
    });
}

function cs_checkforneededupdates()
{
  if(cs_valuestoset.length > 0)
  {
    e = cs_valuestoset.shift();
    f = $(e[0]);
    for(var c = 0; c < f.options.length; ++c)
    {
      if(f.options[c].value == e[1])
      {
        f.options[c].selected = true;
      }
    }
    if(f.onchange)
    {
      f.onchange();
    }
  }
}
