function loadURLIntoDIV(url,id){
 xmlreqGET(url,loadURLIntoDIVResponse,id);
}
function loadURLIntoDIVResponse(status,html,id){
 var div=document.getElementById(id);
 if(!div) alert('missing '+id);
 else div.innerHTML=(status==200)?html:('error: '+status);
}

function loadActiveSearch(url){
 loadURLIntoDIV(url+"?xml=device_search",'device_search_box');
}

var pendingDev;
function loadDeviceDetail(url,dev){
 if(pendingDev!=dev){ pendingDev=dev;
 url+="?xml=device_detail;device_id="+dev;
 xmlreqGET(url,loadDetailResponse,dev);
}}
function loadDetailResponse(status,html,dev){
 if (pendingDev==dev){ pendingDev=-1;
 var div=document.getElementById('device_detail_box');
 div.innerHTML=(status==200)?html:('error: '+status);
}}

var deviceListHash = new Array();
function filterDeviceList(form){
var key=form.name;
var l=form.device_id;
var searchListData=deviceListHash[key];
if (!searchListData){ 
 searchListData=new Array();
 for (var i=0;i<l.length;i++) 
  searchListData[i] = new Option(l.options[i].text,l.options[i].value,false,false);
 deviceListHash[key]=searchListData;
}
l.options.length=0; var re=new RegExp(form.search.value,'i');
for (var i=0;i<searchListData.length;i++)
 if (searchListData[i].text.match(re)) {
  l.options[l.options.length]=new Option(searchListData[i].text,searchListData[i].value,false,false);
}
if(l.options.length&&(l.selectedIndex==-1)){
 l.selectedIndex=0; l.onchange();
}}
