
var comboWidth=0;
var CHARWIDTH = 10;
var MINWIDTH = 40;
//NEW

function fill_comboRemote() {
	p_item = arguments[0];
	if (arguments[1] == null)
		p_value = "SELECT-ONE";
	else
		p_value = arguments[1];
	var s=p_item;;
  	s = s.replace(".","$");
	var command = eval("comboCommand$"+s);
	var p_header = eval("comboCaption$"+s);
	parent.zutil.location.href="/da/util?command=FILL"+command+"&item="+p_item+"&value="+p_value+"&header="+p_header;
}

function Fill_combo(p_item, p_value, p_data, p_header) {
	var fldname=p_item.substr(p_item.indexOf(".")+1);
	var formname=p_item.substr(0,p_item.indexOf("."));
  //alert("formname="+formname)
	//var fld = eval("document.forms[0]."+fldname);
	var fld = eval("document."+formname+"."+fldname);
	
	
  
  var s="";
  var offset=0;
  if ((p_data !=null)&&(p_data.length>0)){
		//alert(fld.options);
    if (fld.value==""){
      fld.options.length=p_data.length+1
      offset=1;
      fld.options[0].text="[Select-One]";
      
    }else{
      if (fld.options) fld.options.length=p_data.length
    }
    for (var i=0; i < p_data.length; i++){
      //fld.options[i].value=p_data[i];
      //alert(fld.options[i].value+"="+p_data[i]);
      fld.options[i+offset].text=p_data[i];
      fld.options[i+offset].value=p_data[i];
      if (p_data[i]==p_value) fld.options[i+offset].selected=true;
      //fld.options[i].value=p_data[i];
      //s+=p_data[i];
		}
	
	}else{
		fld.options.length=1;
      fld.options[0].text="UNDEFINED";
      fld.options[0].value="";
      
    
  }
  fld.onclick="";
  fld.onfocus="";
  //alert(s);
	
	
 
  
  
}



//
function Combo(p_item, p_value, p_data, p_header) {
	if (p_item == null)	return;

	if (p_value == null) {
		this.gValue = null;
	} else {
		this.gValue = p_value;
	}
	if (p_data == null) {
		this.gData = null;
	} else {
		this.gData = p_data;
	}
	if (p_header == null) {
		this.gHeader = "";
	} else {
		this.gHeader = p_header;
	}
//alert("gheader="+this.gHeader);

//	this.gBGColor = "white";
	this.gBGColor = "#ccccff";
	this.gFGColor = "black";
	this.gTextColor = "black";
	this.gHeaderColor = "black";
	this.gReturnItem = p_item;
		
	this.gWidth =0;
	
	if (this.gData !=null){
        this.gWidth=0;
		for (var i=0; i < this.gData.length; i++){
			var s = this.gData[i];
//alert("s="+s);			
			var len=s.length;
        	if (this.gWidth<len) this.gWidth=len;
		}
	
	}
	this.gWidth = this.gWidth*CHARWIDTH;
    
	if (this.gWidth<=MINWIDTH) {
		this.gWidth=MINWIDTH;
		this.gHeader = "";
	}

	
	
	
}


// This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.
new Combo();


Combo.prototype.show = function() {
	var vCode = "";
	vCode = this.getComboCode();
	//ggWinContent += vCode;
    //ggWinContent = "<table width=100% cellpadding=0 cellspacing=0 bgcolor='"+this.gBGColor+"' ><tr><td>"+vCode+"</td></tr></table>";
    //ggWinContent = "<table width=100% cellpadding=0 cellspacing=0 bgcolor='"+this.gBGColor+"' ><tr><td>"+vCode+"</td></tr></table>";
		ggWinContent =vCode;
}

Combo.prototype.getComboCode = function() {
	var vCode = "";
	var vData_Code = "";
	
	// Begin Table Drawing code here..
	//vCode += ("<div align=center>
	//vCode += ("<TABLE width=100% BORDER=0 BGCOLOR=\"" + this.gBGColor + "\" style='font-size:" + fontsize + "pt;'>");
	vCode += ("<TABLE BORDER=0 BGCOLOR=\"" + this.gBGColor + "\" style='font-size:" + fontsize + "pt;'>");
	
	vData_Code = this.combo_data();
	//vCode += (this.gHeader + vData_Code);
	vCode += vData_Code;
	
	//vCode += "</TABLE></div>";
	vCode += "</TABLE>";
	
	return vCode;
}


Combo.prototype.combo_data = function() {
    
var vCode = "";
	for (j=0; j<this.gData.length; j++) {
		if (this.gValue == this.gData[j]){
			vCode = vCode + "<tr><TD class=ls>" ;
		}else{
			if (j%2)
				vCode = vCode + "<tr><TD class=le>" ;
			else
				vCode = vCode + "<tr><TD class=lo>" ;
		}

		vCode = vCode + "<A class='nd' HREF='javascript:void(0);' " + 
				"onMouseOver=\"window.status='set item to " + this.gData[j] + "'; return true;\" " +
				"onMouseOut=\"window.status=' '; return true;\" " +
				"onClick=\"document." + this.gReturnItem + ".value='" + 
				this.gData[j] + 
				"';document."+this.gReturnItem+".focus();nd(1);nd(1);\">";
				"';ggPosX=-1;ggPosY=-1;nd(1);nd(1);\">";




		if (this.gValue == this.gData[j]){
			vCode = vCode + "<span class=ls>"+this.gData[j]+"</span>" ;
		}else{
			vCode = vCode + this.gData[j];
		}
		vCode = vCode + "</A>" + 
			"</TD></tr>";
	}
	if (this.gData.length<=0){
			vCode = vCode + "<tr><TD align='center' bgcolor='Yellow' class='br'>" ;
			vCode = vCode + "NO VALID ITEM."+
			"</TD></tr>";
	
	
	}
	return vCode;
}
function Build_combo(p_item, p_value, p_data, p_header) {
	gCombo = new Combo(p_item, p_value,p_data,p_header);
	// initialize the content string
	ggWinContent = "";

	// Choose appropriate show function
		gCombo.show();
		//overlib(ggWinContent, STICKY, CLOSECLICK, CSSSTYLE,CLOSETEXT,"X",CLOSEWEIGHT, "bold",
		//	TEXTSIZEUNIT, "pt", TEXTSIZE, 8, CAPTIONSIZEUNIT, "pt", CAPTIONSIZE, 8, CLOSESIZEUNIT, "pt", CLOSESIZE, 8,
		//	CAPTION, gCombo.gHeader, SNAPX,10, OFFSETY, 0,WIDTH,20,HAUTO);
    //changed for use with overlibmws
    
		overlib(ggWinContent, STICKY, 
			CAPTION, gCombo.gHeader, -WRAP,CLOSETEXT,"X",OFFSETY, 0,WIDTH,20,HAUTO);
			
		//if ( (ns4) || (ie4) ) {
		if ( (OLns4) || (OLie4) ) {
		        ggPosX = parseInt(over.left);
		        ggPosY = parseInt(over.top);
		} else if (ns6) {
				ggPosX = parseInt(over.style.left);
				ggPosY = parseInt(over.style.top);
		}
		
		
}

function show_combo() {
	//	p_item	: Return Item.
	var p_item = arguments[0];
//alert("combo="+p_item);

	var p_value = "SELECT-ONE";

	if (arguments[1] != null)
		p_value = arguments[1];

	var s=p_item;;
  	s = s.replace(".","$");

	var p_header = eval("comboCaption$"+s);
//alert("p_item="+p_item);
	var p_data = eval("combo$"+s);
	Build_combo(p_item, p_value,p_data,p_header);
}
function show_comboRemote() {
	p_item = arguments[0];
//alert("rem="+p_item);
	if (arguments[1] == null)
		p_value = "SELECT-ONE";
	else
		p_value = arguments[1];
	var s=p_item;;
  	s = s.replace(".","$");
	var command = eval("comboCommand$"+s);
	var p_header = eval("comboCaption$"+s);
	parent.zutil.location.href="/da/util?command="+command+"&item="+p_item+"&value="+p_value+"&header="+p_header;
}


