// ===================================================================
// Adapted from calendar pop-up code by:
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
// ===================================================================

/*************************************************************************/
function ComboBoxPopup() {
   var c;
   if (arguments.length>0) {
      c = new PopupWindow(arguments[0]);
      }
   else {
      c = new PopupWindow();
      c.setSize(202,174);
      }
   c.offsetX = -152;
   c.offsetY = 25;
   c.styles  = "";
   c.autoHide();
   c.select            = CBP_select;
   c.showList          = CBP_showList;
   c.hideList          = CBP_hideList;
   c.getList           = CBP_getList;
   c.getStyles         = CBP_getListStyles;
   c.setReturnFunction = CBP_setReturnFunction;
   c.returnFunction    = "CBP_ReturnFunction";
   return c;
   }
/*************************************************************************/
function CBP_setReturnFunction(name) {
   this.returnFunction = name;
   }
/*************************************************************************/
function CBP_ReturnFunction(itm, val) {
   if (window.CBP_itemfield != null) {
      window.CBP_itemfield.value  = itm;
      }
   if (window.CBP_valuefield != null) {
      window.CBP_valuefield.value = val;
      }
   }
/*************************************************************************/
function CBP_select(itemfield, valuefield, items, linkname){
   var selectedvalue = "";
   if (itemfield.disabled) {
      return;
      }
   window.CBP_itemfield  = itemfield;
   window.CBP_valuefield = valuefield;
   this.showList(items, linkname);
   }
/*************************************************************************/
function CBP_hideList(){
   if (arguments.length > 0){
      window.popupWindowObjects[arguments[0]].hidePopup();
      }
   else {
      this.hidePopup();
      }
   }
/*************************************************************************/
function CBP_showList(items, anchorname){
   this.populate(this.getList(items));
   this.showPopup(anchorname);
   }
/*************************************************************************/
function CBP_getListStyles() {
   var result = "";
   result += "<STYLE>\n";
   result += this.styles;
   result += "</STYLE>\n";
   return result;
   }
/*************************************************************************/
function CBP_getList(items){
   if (this.type == "WINDOW") {
      var windowref = "window.opener.";
      }
   else {
      var windowref = "";
      }
   var result = "";
   if (this.type == "WINDOW") {
      result += "<HTML><HEAD><TITLE>Combo Box</TITLE>"+this.getStyles()+"</HEAD><BODY MARGINWIDTH=0 MARGINHEIGHT=0 TOPMARGIN=0 RIGHTMARGIN=0 LEFTMARGIN=0>\n";
      result += '<CENTER><TABLE WIDTH=100% BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>\n';
      }
   else {
      result += '<TABLE CLASS="'+this.cssPrefix+'cpBorder" WIDTH=144 BORDER=1 BORDERWIDTH=1 CELLSPACING=0 CELLPADDING=1>\n';
      result += '<TR><TD ALIGN=CENTER>\n';
      result += '<CENTER>\n';
      }
   if (this.type!="WINDOW") {
      result += "<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>";
      }
   result += '<TR>\n';
   result += '<TD>\n';
   result += '<?php echo "test"; ?>\n';
   result += '<form name="cbform">';
   result += '<select class="data_text" name="cb" size="14" style="width:200" ondblclick="javascript: ' + windowref+this.returnFunction+'(this.options[this.selectedIndex].text, this.options[this.selectedIndex].value);window.close();">\n';

   var itemvaluearray=items.split("|");
   var i=0;
   while (i < itemvaluearray.length) {
      result += '<option value="' + itemvaluearray[i] + '">';
      i++;
      result += itemvaluearray[i] + '</option>\n';
      i++;
      }
//   result += '<option value="' + items + '">' + items + '</option>\n';
   result += '</select>\n';
   result += '</form>\n';
   result += '</TD>\n';
   result += '</TR>\n';
   result += '</TABLE>\n';
   result += '<script language="javascript">document.cbform.cb.focus();</script>';
   if (this.type == "WINDOW") {
      result += "</BODY></HTML>\n";
      }
   return result;
   }
/*************************************************************************/
