function clsComboBox() {
	// initialize the member function references
    // for the class prototype
    if (typeof(_clsComboBox_prototype_called) == 'undefined')
    {
       _clsComboBox_prototype_called = true;
       clsComboBox.prototype.addOption = _addOption ;
	   clsComboBox.prototype.addOption_AtPosition = _addOption_AtPosition ;
	   clsComboBox.prototype.addOption_Unique = _addOption_Unique ;
       clsComboBox.prototype.clear = _clear ;	
	   clsComboBox.prototype.findValue = _findValue;
	   clsComboBox.prototype.removeOption = _removeOption;   
       clsComboBox.prototype.selectOption = _selectOption ;
	   clsComboBox.prototype.selectCollectionListOption = _selectCollectionListOption ;
	   clsComboBox.prototype.valueExists = _valueExists ;
       clsComboBox.prototype.writeDependentComboOptions = _writeDependentComboOptions ;
	   clsComboBox.prototype.writeDependentComboOptionsByMasterIDValue = _writeDependentComboOptionsByMasterIDValue;
    }
    
    function _addOption(oSelect, vText, vValue) {
    	if (oSelect) {
    		var i;
    	
    		if (oSelect.options)
    	  		i = oSelect.options.length
    		else
    	  		i = 0;
    
    		var temp = new Option(vText, vValue);
    		oSelect.options[i] = temp;
    	}
    }
	
	function _addOption_AtPosition(oSelect, vText, vValue, vPosition, arrPositions) {
		var bContinue = false;
		var intIndex = -1, intPositionIndex;
		var intPos = -1;
		var objArray, objOption, objOption_Next;
		var strText = '';
		
    	if (oSelect) {
    		if (oSelect.options) {
    			var nLen = oSelect.options.length;				
    			if (nLen > 0) {
					objArray = new clsArray();
					
					//make sure it's unique
					bContinue = true;	
					for (var i = 0; i < nLen; i++) {
						if (oSelect.options[i].value == vValue) {
							bContinue = false;
							break;
						}
					}

					if (bContinue) {					
    					var bDone = false;
       					    					
        				for (var nIndex = 0; ((nIndex < nLen) && (!bDone)); nIndex++) {																			                
							//array index of current select option in the positions array
        					intPositionIndex = objArray.findIn2DArray(oSelect.options[nIndex].value, arrPositions, objArray.DT_INT, 0);						
							if (intPositionIndex == -1) {
								bDone = true;
								intIndex = nIndex;
							}
							else {						
								//position value of the select options
        						intPos = arrPositions[intPositionIndex][2];	
								
								//if the new option has the same position as the current select option
								//then sort it alphabetically													
        						if (intPos == vPosition) {									
        							if (vText.toUpperCase() < oSelect.options[nIndex].text.toUpperCase()) {
        								bDone = true;
        								intIndex = nIndex;
        							}
        						}
							}
    						
    						if (intPos > vPosition) {
    							bDone = true;
    							intIndex = nIndex;
    						}						
        				}
						
						if ((!bDone) && (intIndex < 0)) {
							intIndex = nLen;
						}					
    
    					if (intIndex < 0) {
    						intIndex = 0;
    					}
			
    					objOption = new Option(vText, vValue);
    					objOption_Next = oSelect.options[intIndex];
    					oSelect.options[intIndex] = objOption;
    					
    					for (var iOpt = intIndex + 1; iOpt < oSelect.options.length + 1; iOpt++) {						
            				objOption = objOption_Next;
            				objOption_Next = oSelect.options[iOpt];
    						oSelect.options[iOpt] = objOption;
    					}	
					}	
//alert('end');													
    			}
    		}
    	}	
		
		//return the array index for the positions array
		return intPositionIndex;			
	}	
	
	function _addOption_Unique(oSelect, vText, vValue) {
		var intIndex = this.findValue(oSelect, vValue);
		if (intIndex == -1) {
			this.addOption(oSelect, vText, vValue);
		}
	}
    
    function _clear(oSelect) {
    	if (oSelect) {
    		if (oSelect.options) {
    			var vLen = oSelect.options.length;
    			if (vLen > 0) {
    				for (var vIndex = 0; vIndex < vLen; vIndex++)
    					oSelect.options[0] = null;
    			}
    		}
    	}
    }
    
	function _findValue(oSelect, value) {
		var intIndex = -1;
		
    	if (oSelect) {
    		if (oSelect.options) {
    			var nLen = oSelect.options.length;
    			if (nLen > 0) {
    				var bFound = false;
		
    				for (var nIndex = 0; ((nIndex < nLen) && (!bFound)); nIndex++) {																			                
    					if (oSelect.options[nIndex].value == value) {
    						bFound = true;
    						intIndex = nIndex;						
    					}
    				}
    			}
    		}
    	}		
		
		return intIndex;
	}
	
    function _removeOption(oSelect, value) {
		var intIndex = this.findValue(oSelect, value);
		if (intIndex != -1) {
			oSelect.options[intIndex] = null;
		}
    }	
	
    function _selectOption(oSelect, value) {
		var intIndex = this.findValue(oSelect, value);
		if (intIndex != -1) {
			oSelect.selectedIndex = intIndex;
		}
    }
	
	function _selectCollectionListOption(oSelect, value) {
    	if (oSelect) {
    		if (oSelect.options) {
    			var nLen = oSelect.options.length;
    			if (nLen > 0) {
    				var bFound = false;
					var arrTempValue = '';
					
					oSelect.selectedIndex = 0;
					
    				for (var nIndex = 0; ((nIndex < nLen) && (!bFound)); nIndex++) {
//alert('test=' + oSelect.options[nIndex].value);					
						arrTempValue = oSelect.options[nIndex].value.split('!');
						
						if (arrTempValue.length > 0) { 	
//alert('select option val=' + arrTempValue[1]);										                
        					if (arrTempValue[1] == value) {
        						bFound = true;
        						oSelect.selectedIndex = nIndex;						
        					}
						}
    				}
    			}
    		}
    	}
    }	
    
	function _valueExists(oSelect, value) {
		var intIndex = this.findValue(oSelect, value);
		return (intIndex != -1);
	}
	
    function _writeDependentComboOptions(elemMaster, elemDependent, aOptions, vPrevValue, bAddBlankOption)
    {
    	this.clear(elemDependent);
    
      	if (bAddBlankOption)
      	  this.addOption(elemDependent,'        ','');
        
    	if (elemMaster.options.length)
    	{
    		if (elemMaster.options[elemMaster.selectedIndex].value)
    		{
    			var strMasterValue = elemMaster.options[elemMaster.selectedIndex].value;
                
                var oArray = new clsArray;
                		
    			var nArrayIndex = oArray.findIn2DArray(strMasterValue, aOptions, oArray.DT_INT,0);
    
    			if (nArrayIndex!= -1)
    			{	
    				var vOptionMod = 0;
                    
                    if (bAddBlankOption)
                    	vOptionMod++;
                    
					for (vOption = nArrayIndex; ((vOption < aOptions.length) && (strMasterValue == aOptions[vOption][0])); vOption++) {
						this.addOption(elemDependent, aOptions[vOption][2], aOptions[vOption][1]);
    					if (vPrevValue == aOptions[vOption][1])
    						elemDependent.options[elemDependent.options.length + vOptionMod].selected=true;														
					}					
                    
    				if (vPrevValue == null)
    				{
    				  if (bAddBlankOption)
    				    elemDependent.options[1].selected = true
    				  else
    				    elemDependent.options[0].selected = true;
    				}
    			}
				
    		}
    	}
    }
	
    function _writeDependentComboOptionsByMasterIDValue(MasterIDValue, elemDependent, aOptions, vPrevValue, bAddBlankOption)
    {
    	this.clear(elemDependent);
    
      	if (bAddBlankOption) {
      	  this.addOption(elemDependent,'        ','');
        }
		
        var oArray = new clsArray;            		
		var nArrayIndex = oArray.findIn2DArray(MasterIDValue, aOptions, oArray.DT_INT,0);

        if (nArrayIndex!= -1)
        {	
        	var vOptionMod = 0;
            
            if (bAddBlankOption) {
            	vOptionMod++;
			}
            
        	for (vOption = nArrayIndex; ((vOption < aOptions.length) && (MasterIDValue == aOptions[vOption][0])); vOption++) {
        		this.addOption(elemDependent, aOptions[vOption][2], aOptions[vOption][1]);
            	if (vPrevValue == aOptions[vOption][1]) {
            		elemDependent.options[elemDependent.options.length + vOptionMod].selected=true;
				}														
        	}					
            
            if (vPrevValue == null)
            {
              if (bAddBlankOption) {
                elemDependent.options[1].selected = true
			  }
              else {
                elemDependent.options[0].selected = true;
			  }
            }
        }
    }	
}
