var selects=[],isIE=(document.all&&window.ActiveXObject&&!window.opera)?true:false;
function initSearchSelect(){
  selects.push($("searchType"));
  rSelects();
}
function stopBubbling(A){
  A.stopPropagation();
}
function rSelects(){
  for(i=0;i<selects.length;i++){
    selects[i].style.display="none";
    select_tag=document.createElement("div");
    select_tag.id="select_"+selects[i].name;
    select_tag.className="select_box";
    selects[i].parentNode.insertBefore(select_tag,selects[i]);
    select_info=document.createElement("div");
    select_info.id="select_info_"+selects[i].name;
    select_info.className="tag_select";
    select_info.style.cursor="pointer";
    select_tag.appendChild(select_info);
    select_ul=document.createElement("ul");
    select_ul.id="options_"+selects[i].name;
    select_ul.className="tag_options";
    select_ul.style.position="absolute";
    select_ul.style.display="none";
    select_ul.style.zIndex="999";
    select_tag.appendChild(select_ul);
    rOptions(i,selects[i].name);
    mouseSelects(selects[i].name);
    if(isIE){
      selects[i].onclick=new Function("clickLabels3('"+selects[i].name+"');window.event.cancelBubble = true;");
    }else {
      if(!isIE){
        selects[i].onclick=new Function("clickLabels3('"+selects[i].name+"')");
        selects[i].addEventListener("click",stopBubbling,false);
      }
    }
  }
}
function rOptions(A,D){
  var E=selects[A].getElementsByTagName("option"),C="options_"+D,B=false;
  for(n=0;n<selects[A].options.length;n++){
    if(selects[A].options[n].selected){
      B=true;
    }
  }
  if(!B){
    selects[A].selectedIndex=0;
  }
  for(n=0;n<selects[A].options.length;n++){
    option_li=document.createElement("li");
    option_li.style.cursor="pointer";
    option_li.className="open";
    $(C).appendChild(option_li);
    option_text=document.createTextNode(selects[A].options[n].text);
    option_li.appendChild(option_text);
    option_selected=selects[A].options[n].selected;
    if(option_selected){
      option_li.className="open_selected";
      option_li.id="selected_"+D;
      $("select_info_"+D).appendChild(document.createTextNode(option_li.innerHTML));
    }
    option_li.onmouseover=function(){
      this.className="open_hover";
    };
    option_li.onmouseout=function(){
      if(this.id=="selected_"+D){
        this.className="open_selected";
      }else {
        this.className="open";
      }
    };
    option_li.onclick=new Function("clickOptions("+A+","+n+",'"+selects[A].name+"')");
  }
}
function mouseSelects(A){
  var B="select_info_"+A;
  $(B).onmouseover=function(){
    if(this.className=="tag_select"){
      this.className="tag_select_hover";
    }
  };
  $(B).onmouseout=function(){
    if(this.className=="tag_select_hover"){
      this.className="tag_select";
    }
  };
  if(isIE){
    $(B).onclick=new Function("clickSelects('"+A+"');window.event.cancelBubble = true;");
  }else {
    if(!isIE){
      $(B).onclick=new Function("clickSelects('"+A+"');");
      $("select_info_"+A).addEventListener("click",stopBubbling,false);
    }
  }
}
function clickSelects(A){
  var C="select_info_"+A,B="options_"+A;
  for(i=0;i<selects.length;i++){
    if(selects[i].name==A){
      if($(C).className=="tag_select_hover"){
        $(C).className="tag_select_open";
        $(B).style.display="";
      }else {
        if($(C).className=="tag_select_open"){
          $(C).className="tag_select_hover";
          $(B).style.display="none";
        }
      }
    }else {
      $("select_info_"+selects[i].name).className="tag_select";
      $("options_"+selects[i].name).style.display="none";
    }
  }
}
function clickOptions(A,C,D){
  var B=$("options_"+D).getElementsByTagName("li");
  $("selected_"+D).className="open";
  $("selected_"+D).id="";
  B[C].id="selected_"+D;
  B[C].className="open_hover";
  $("select_"+D).removeChild($("select_info_"+D));
  select_info=document.createElement("div");
  select_info.id="select_info_"+D;
  select_info.className="tag_select";
  select_info.style.cursor="pointer";
  $("options_"+D).parentNode.insertBefore(select_info,$("options_"+D));
  mouseSelects(D);
  $("select_info_"+D).appendChild(document.createTextNode(B[C].innerHTML));
  $("options_"+D).style.display="none";
  $("select_info_"+D).className="tag_select";
  selects[A].options[C].selected="selected";
}
Element.observe(window,"load",function(){
  $(document).observe("click",function(){
    for(i=0;i<selects.length;i++){
      $("select_info_"+selects[i].name).className="tag_select";
      $("options_"+selects[i].name).style.display="none";
    }
  });
});