function comboFocus(cid){
  var t=document.getElementById(cid+"_TEXT");
  if (!t) return
  if (t.className == "readonly") return; 
  
  t.className="inputSelected"
  t.select();
  cSearch="";
};

function comboBlur(cid){
  var t=document.getElementById(cid+"_TEXT");
  if (!t) return
  
  if (t.className=="readonly") return; 
  t.className="";
};

function comboSet(cid){
  var i=document.getElementById(cid);
  var t=document.getElementById(cid+"_TEXT");
  var l=document.getElementById(cid+"_LIST");
  
  $(l).find('li').each(function(){if (i.value==this.id){ t.value=this.innerHTML;return;}; });
};

function comboSetFirst(cid){
  var i=document.getElementById(cid);
  var t=document.getElementById(cid+"_TEXT");
  var l = document.getElementById(cid + "_LIST");

  if ($(i).attr('sel')=='') return;
  i.value="0";
  t.value="";
  
  $(l).find('ul').each(function(){
    if ($(this).attr('sel')==$(i).attr('sel')) {i.value=$(this).find('li').eq(0).attr('id'); t.value=$(this).find('li').eq(0).html(); return;} 
  });
   
};  
     

function comboValue(cid, v) {  
  var i=document.getElementById(cid);
  var t=document.getElementById(cid+"_TEXT");

  var b=i.value;
  i.value=v.id;
  t.value=v.innerHTML;
  t.select();
  
  if (b!=i.value) {
    if ($(t).attr('sub')) { t.form.submit();return; }
    if ($(t).attr('chn')) { b=$(t).attr('chn').replace("#V#",i.value);eval(b);}
  };
};

function comboClick(cid, fid){
  var i=document.getElementById(cid);
  var t=document.getElementById(cid+"_TEXT");
  var l=document.getElementById(cid+"_LIST");
  var b=document.getElementById(cid+"_BUTTON");
  var fr = document.getElementById(fid);
  
  if (t.className=="readonly") return; 
  t.select(); 
  if (l.style.display=="block") {
    l.style.display="none";
    activeObject=null;
    activeDown=null;
    t.focus();
  }  
  else {      
    if (i.sel && i.sel!="") {
      var lh=0;
	  $(l).find('ul').each(function(){if ($(this).attr('sel')==$(i).attr('sel')) this.style.display="block"; else {lh++;this.style.display="none";}});     
    }
	else
	  $(l).find('ul').css('display','block');
  
    var cl=0;
	$(l).find('li').each(function(){cl++;});

    if (cl==0) return;    
    if (cl>8) cl=8;      
     
    showObject(l, t, "B", "L", "T", "L", 0, 0);
    l.style.width=(t.offsetWidth+b.offsetWidth-2)+"px";
    l.style.height=18*cl;
        
    activeObject=l;
    activeDown=b;
    l.focus();
    
    if (i.value!="") $(l).find('li').each(function(){if (this.id==i.value) $(this).addClass('selected')});
  }  
}

function comboKey(e){
  
};

function combolistKey(e) {

};

function combolistMouseOver(e) {
  var ll=$(e.target);
  if (ll.is('li')) {
    ll.parents('.comboList').find('li.selected').removeClass('selected');
	ll.addClass('selected');
  };   
}

function combolistMouseDown(e){
  var ll=$(e.target);
  if (ll.is('li')) {
    var cid=ll.parents('.comboList').eq(0).attr('id').replace('_LIST','');
    var i=document.getElementById(cid);
    var t=document.getElementById(cid+"_TEXT");
    var l=document.getElementById(cid+"_LIST");
   
    ll.removeClass('selected');
    comboValue(cid,e.target)
    l.style.display="none";
    activeObject=null;
    t.focus();
  };
};

function combomultiFocus(cid) {

  var t=document.getElementById(cid+"_TEXT");
  var l=document.getElementById(cid+"_LIST");

  if (t.className=="readonly") return; 
  l.className += " combomultiSelect"; 
}

function combomultiBlur(cid) {

  var t=document.getElementById(cid+"_TEXT");
  var l=document.getElementById(cid+"_LIST");

  if (t.className=="readonly") return;   
  l.className="combomultiList";
}

function combomultiSet(cid, rows)
{
  var i=document.getElementById(cid);
  var t=document.getElementById(cid+"_TEXT");
  var l=document.getElementById(cid+"_LIST");

  var v=new String(i.value);
  var v=", "+v+",";
  var s="";
    
  $(l).find('li').each(function(){if (v.indexOf(", "+this.id+",")>=0){$(this).addClass('selected');s=s+this.innerText+", ";}; });
  t.value=s;
  
  if (rows!="") l.style.height=18*rows;
}

function combomultiMouseDown(e) {
  var ll=$(e.target);

  if (ll.is('li')) {


  var cid=ll.parents('.combomultiList').eq(0).attr('id').replace('_LIST','');
  var i=document.getElementById(cid);
  var t=document.getElementById(cid+"_TEXT");
  var l=document.getElementById(cid+"_LIST");
   
    if (ll.hasClass('selected')) ll.removeClass('selected'); else ll.addClass('selected');

  var v='', t='';
  $(l).find('li.selected').each(function(){v+=this.id+', ';t+=this.innerText+', ';});
  i.value=v;
  t.value=t;
  };


  
};


