

function SelectBOX(id,items,w,bordercolor,style1,style2,handlefunc){
 this.maincontainer = document.getElementById(id);
 this.width = w==null ? 80:w;
 this.bordercolor = bordercolor==null ? "#7f9db9":bordercolor;
 this.items = items==null ? [[]]:items;
 this.text = items[0][1]; //selectbox 的显示文本值
 this.value = items[0][0];//selectbox 的实际值
 if(items[0][2])this.label = items[0][2];//selectbox 的显示HTML值
 this.classoverstyle = style1==null ? "":style1;
 this.classoutstyle = style2==null ? "":style2;
 if(handlefunc)
  this.handle=handlefunc;
}
SelectBOX.prototype.create=function(){ 
 var object=this;
 var container=document.createElement("DIV");
 var leftnode=document.createElement("DIV");
 leftnode.innerHTML=object.items[0][2]||object.items[0][1];
 leftnode.setAttribute("value",object.items[0][0]);
 leftnode.setAttribute("text",object.items[0][1]);
 var righttnode=document.createElement("DIV");
 righttnode.innerHTML="<img src=\"../images/sel_pic.gif\" valign=\"middle\">";
 var firstnode=document.createElement("DIV");
 var secondnode=document.createElement("DIV");
 firstnode.appendChild(leftnode);
 firstnode.appendChild(righttnode);
 container.appendChild(firstnode);
 container.appendChild(secondnode); 
 
 container.style.width=object.width;
 container.style.position="absolute";
 container.style.top="55px";
 firstnode.style.border="1px solid #8bcca9";
 firstnode.style.backgroundColor="#e3f6ea";
 firstnode.style.width="100%";
 firstnode.style.height="22px";
 firstnode.style.lineHeight="22px";
 //firstnode.style.padding="1px";
 if(document.all)
  leftnode.style.styleFloat = "left";
 else
  leftnode.style.cssFloat = "left";
 leftnode.style.paddingLeft = "8px"; 
 leftnode.style.width=(object.width-22)+"px";
 leftnode.style.height="22px";
 leftnode.style.overflow="hidden";
 leftnode.style.color="#2f2f2f";
 
 if(document.all)
  righttnode.style.styleFloat = "right";
 else
  righttnode.style.cssFloat = "right";
 //righttnode.style.fontFamily="System";
 //righttnode.style.width="15px";
 righttnode.style.height="22px";
 righttnode.style.paddingTop="4px";
 righttnode.style.paddingRight="5px";
 //righttnode.style.paddingTop=""
 //righttnode.style.lineHeight="22px";
 //righttnode.style.border="1px solid #b7caf5";
 //righttnode.style.background="#c9d8fc";
 //righttnode.style.lineHeight="16px";
 //righttnode.style.cursor="default";
 //righttnode.align="center";
 
 righttnode.onmouseover=function(){
  //righttnode.style.background='#d0e5fc'
 };
 righttnode.onmouseout=function(){
  //righttnode.style.background='#b7caf5'
 };
 
 secondnode.style.border="1px solid #000";
 secondnode.style.width="100%";
 secondnode.style.display="none";
 
 for(var i=0;i<object.items.length;i++){
  var node=document.createElement("DIV");
  node.className=object.classoutstyle;
  if(document.all)  //correted IE BUG
   node.style.width = "100%";
  node.style.paddingLeft="8px";
  node.setAttribute("value",object.items[i][0]);
  node.setAttribute("text",object.items[i][1]);
  node.innerHTML=object.items[i][2]||object.items[i][1];
  secondnode.appendChild(node);
  node.onmouseover=function(){
   for(var j=0;j<this.parentNode.childNodes.length;j++){
    this.parentNode.childNodes[j].className=object.classoutstyle;
   }
   this.className=object.classoverstyle;
  };
  node.onmouseout=function(){
   this.className=object.classoutstyle;
  }
  node.onclick=function(){
   object.DO_OPTION_CLICK_HANDLE(this);
  };
 }
 righttnode.onclick=function(){
  object.DO_CONTAINER_CLICK_HANDLE(this);
 };
 leftnode.onclick=function(){
  object.DO_CONTAINER_CLICK_HANDLE(this);
 };
 object.maincontainer.appendChild(container);
}
SelectBOX.prototype.DO_MOUSEOVER_HANDLE=function(the){
 for(var i=0;i<the.parentNode.childNodes.length;i++){
  the.parentNode.childNodes[i].className=this.classoutstyle;
 }
 the.className=this.classoverstyle;
} 
SelectBOX.prototype.DO_CONTAINER_CLICK_HANDLE=function(the){
 var parent=the.parentNode;
 var obj=parent.nextSibling;
 if(obj.style.display=='none')
  obj.style.display='';
 else
  obj.style.display='none';  
 for(var i=0;i<obj.childNodes.length;i++){
  if(obj.childNodes[i].attributes.getNamedItem("value").value==parent.firstChild.attributes.getNamedItem("value").value){
   //if(obj.style.display=='')
    //parent.firstChild.className = this.classoutstyle;
   //else
    //parent.firstChild.className = this.classoverstyle;  
   this.DO_MOUSEOVER_HANDLE(obj.childNodes[i],this); 
   break;
  }
 } 
} 
SelectBOX.prototype.DO_OPTION_CLICK_HANDLE=function(the){
 var defaultnode=the.parentNode.previousSibling.firstChild;
 //defaultnode.className=this.classoutstyle;
 the.parentNode.style.display='none';
 //this.label=the.innerHTML;
 this.value=the.attributes.getNamedItem("value").value;
 this.text=the.attributes.getNamedItem("text").value;
 defaultnode.setAttribute("value",this.value);
 defaultnode.innerHTML=this.text; 
 //defaultnode.className=this.classoverstyle;
 if(this.handle)this.handle(the);
}
