// CONSTRUCTOR for the Object
function ValueListPopup() {
	var c;
	if (arguments.length>0) {
		c = new PopupWindow(arguments[0]);
	}
	else {
		c = new PopupWindow();
	}
	c.offsetX = 0;
	c.offsetY = 18;
	c.autoHide();
	c.showPopupWin = CP_showPopup;
	c.hidePopupWin = CP_hidePopup;
	c.getStyles = CP_getStyles;
	c.refreshPopup = CP_refreshPopup;
	c.getPopup = CP_getPopup;
        c.anchorname="";
	c.ValueList = "";
	c.Columns = 1;
	c.DescVal = "";
	c.HiddenCol = 0;
    c.Width = 0;
    c.ListRows = 0;
    c.scroll = false;
    return c;
}
//
// Hide object
//
function CP_hidePopup() {
	if (arguments.length > 0) { window.popupWindowObjects[arguments[0]].hidePopup(); }
	else {this.hidePopup(); }
}
//
// Refresh the contents of the display
//
function CP_refreshPopup(index) {
	var calObject = window.popupWindowObjects[index];
	if (arguments.length>1) { 
		calObject.populate(calObject.getPopup(arguments[1],arguments[2],arguments[3],arguments[4],arguments[5]));
	}
	else {
		calObject.populate(calObject.getPopup());
	}
	calObject.refresh();
}
//
// Populate the Popup and display it
//
function CP_showPopup(anchorname) {
    this.anchorname = anchorname;
	this.populate(this.getPopup());
	this.showPopup(anchorname);
}
//
// Get style block needed to display the Popup correctly
//
function CP_getStyles() {
	var result = "";
	var p = "";
	if (this!=null && typeof(this.cssPrefix)!="undefined" && this.cssPrefix!=null && this.cssPrefix!="") { p=this.cssPrefix; }
	result += "<STYLE>\n";
    result += ".valueList {font: 8pt verdana; color:#222222; background-color:#fefefe}";
    result += ".valueListh {font: 8pt verdana; color:#222222; background-color:#afcdfe}";
	result += "</STYLE>\n";
	return result;
}
//
// Return a string containing all the Popup to be displayed
//
function CP_getPopup() {
	// Reference to window
	if (this.type == "WINDOW") { var windowref = "window.opener."; }
	else { var windowref = ""; }
	var result = "";
	// If POPUP, write entire HTML document
	if (this.type == "WINDOW") {
		result += "<HTML><HEAD><TITLE>Value List</TITLE>"+this.getStyles()+"</HEAD><BODY MARGINWIDTH=0 MARGINHEIGHT=0 TOPMARGIN=0 RIGHTMARGIN=0 LEFTMARGIN=0 style='padding-bottom:0px'><CENTER>\n";
	}
    if (this.scroll) {
	  result += "  <DIV style='width:" + this.width + "px;height:" + (this.ListRows*20) + "px;overflow-y:scroll;border:1px inset silver; background-color:WhiteSmoke'><TABLE";
	} else {
	  result += "  <DIV style='border:1px solid #003255; margin-bottom:0'><TABLE";
	}
	if (this.type == "WINDOW") { result += " width=100%"; }
    result += " rules=cols CELLPADDING=3 CELLSPACING=0 BORDER=0 >\n";
//
    var WrkArr = this.ValueList.split(";");
	var WrkVal = "";
	var j = 0, k = 0;
	for (var i=1; i<=WrkArr.length/this.Columns; i++) {
      result += "    <TR class=valueList height=14px";
      result += " onMouseOver=\"this.className='valueListh'\"";
      result += " onMouseOut=\"this.className='valueList'\""
      result += " onClick=\"" + windowref + "SelFromValueList('" + this.anchorname + "','" + WrkArr[k] + "')\">";
      result += "<td width=2 bgcolor='#eeeeee'></td>";
	  for (j=1; j<=this.Columns; j++) {
	    if (this.HiddenCol == 0 || j != this.HiddenCol) {
	      if (j==1) {
	        result += "<td>";
	      } else {
	        result += "<td style='border-left:1px solid silver'>";
	      }
	      if (WrkArr[k] == " ") {
            result += String.fromCharCode(160) + "</td>";
	      } else {
            result += WrkArr[k] + "</td>";
          }
	    }
	    k++;
      }  
      result += "</TR>\n";
	}
    result += "  </TABLE></DIV>\n";    
// Common
	if (this.type == "WINDOW") {
		result += "</BODY></HTML>\n";
	}
	return result;
}
function isValueInList(PrmFld, PrmCol, PrmTotCol, PrmHiddenCol) {
    var WrkFnd = false;
	vListPop.DescValue = "";
    var WrkHiddenValue = "";
    var WrkValue = document.all(PrmFld).value
//    if (WrkValue.replace(new RegExp(" {1,}"),"") > '') {
      var WrkVList = document.all(PrmFld).getAttribute("RowSource");
      var WrkArr = WrkVList.split(";");
	  var j = 0, k = 0;
	  for (var i=1; i<=WrkArr.length/PrmTotCol; i++) {
        if (WrkFnd) {break;}
	    for (j=1; j<=PrmTotCol; j++) {
	      if (j == 1 && WrkValue == WrkArr[k]) { 
	        WrkFnd = true;
	        if (PrmCol > 0 && PrmCol <= PrmTotCol) { 
	          vListPop.DescValue = WrkArr[k+PrmCol-1];
	        } 
	        if (PrmHiddenCol > 0) {WrkHiddenValue = WrkArr[k+PrmHiddenCol-1];}
	        break;
	      }
	      k++;
        }  
      }
//    }
    document.all(PrmFld).setAttribute('DescValue', vListPop.DescValue);
	if (PrmHiddenCol > 0) {
	  document.all(PrmFld).setAttribute('HiddenValue', WrkHiddenValue);
	}
    return WrkFnd;
}

function SelFromValueList(PrmFld, PrmVal) {
  document.all(PrmFld).value = PrmVal;
  eval(GetEventString(PrmFld, "onblur"));
  vListPop.hidePopupWin();
}
//
//=======================================================================================
//
  var vListPop = new ValueListPopup();
  document.write(vListPop.getStyles());

  function openValueListPopup(PrmFld, PrmPopup, PrmCols, PrmWidth, PrmRows, PrmHiddenCol) {
    if (!popVis || (popVis && PrmFld != vListPop.anchor)) {
      vListPop = null; 
      var WrkVList = document.all(PrmFld).getAttribute("RowSource");
      if (PrmPopup=="true") {
        vListPop = new ValueListPopup();
		var WrkArr = WrkVList.split(";");
		if (WrkArr.length/PrmCols <= PrmRows) { 
		  PrmRows = WrkArr.length/PrmCols; 
		} else {
		  vListPop.scroll = true;
		}
//		vListPop.setSize(PrmWidth,PrmRows*18-18);
	    vListPop.setSize(PrmWidth,PrmRows*19);
      } else {
        vListPop = new ValueListPopup("EtsPopDiv1");
		var WrkArr = WrkVList.split(";");
        if (WrkArr.length/PrmCols > PrmRows) { vListPop.scroll = true; }
	  
	    if (WrkArr.length/PrmCols <= PrmRows) { 
		  PrmRows = WrkArr.length/PrmCols;}
	    vListPop.setSize(PrmWidth,PrmRows*20+32);
      }
      vListPop.ValueList = WrkVList;
      vListPop.Columns = PrmCols;
      vListPop.HiddenCol = PrmHiddenCol;
      vListPop.Width = PrmWidth;
      vListPop.ListRows = PrmRows;
      vListPop.showPopupWin(PrmFld); 
    }
  }

