<!--//

////////////////////////////////////////////////////////////////////
// Capital Uses
////////////////////////////////////////////////////////////////////
function onChangeCapitalUse(frm,cboSelect,txtID, cboCapitalUse) {
	if(cboSelect == null) return true;
    var intCurrent = cboSelect.selectedIndex;
	var intCurrValue = cboSelect.options[intCurrent].value;
	var strCapitalUse = cboSelect.options[intCurrent].text;
	
	// Asssign the values to the fields
	txtID.value = intCurrent;
	findDDEntryByValue(cboCapitalUse, intCurrValue);
	// Deselect the item
	cboSelect.selectedIndex = -1;
	
	return true;
}

function addCapitalUseOption(cboSelect,txtID, cboCapitalUse, blnClear) {
    var defaultSelected = true;
    var selected = false;
	
	// Exit if missing entries
	if(cboCapitalUse.selectedIndex < 0 ) return false;
	
	var strValue = cboCapitalUse.options[cboCapitalUse.selectedIndex].text ;
	var length = cboSelect.length;
	
	//alert('cboSelect.length =' + cboSelect.length);
	
	var intOption0;
	var strOption0 = '';
	if(length > 0) strOption0 = cboSelect.options[0].text;
	
	strOption0 = trim3(strOption0);
	strOption0.replace('nbsp;','');
	strOption0.replace(/\s/g,"");
	
	//alert('strOption0 = ' + strOption0);
	
	if(length > 0 && strOption0 != '') 
		intOption0 = cboSelect.options[0].value;
	else
		intOption0 = 1000;
	
	//alert ('strValue = ' + strValue);

	//alert('Option 0 =' + cboSelect.options[0].text);
	//alert('Index = ' + intOption0 );

	// Enable the ability to replace the first entry
	if(intOption0  == 1000) {
		length = 0;	
		txtID.value = '';
	}
	// Create a new option if there are not any or
	// if we entered new information
	// Update an existing option if we had an ID	
	//alert('txtID = ' + txtID.value);
	
	// Check to be sure that the entry does not already exist
	var blnFound = false;
	for(var x = 0; x < cboSelect.length;x++){
		if(cboSelect.options[x].text == strValue) blnFound = true;
	}	
	if(!(blnFound)){
		if (txtID.value == '') {
			var optionName = new Option(strValue, length, defaultSelected, selected)	
	    		cboSelect.options[length] = optionName;
				cboSelect.options[length].value = cboCapitalUse.options[cboCapitalUse.selectedIndex].value;			
		}else{
			var intIndex = txtID.value;
			cboSelect.options[intIndex].text = strValue;
			cboSelect.options[intIndex].value = cboCapitalUse.options[cboCapitalUse.selectedIndex].value;
		}
	}else{
		alert('You have already added this item.');
		cboCapitalUse.selectedIndex = 0; 
	}
	// Since we will reuse this same function in different areas, we don't 
	// always want the source fields cleared; however, we should always clear
	// the ID
	txtID.value = '';
	if(blnClear){
		
		cboCapitalUse.selectedIndex = 0; 
	}
	cboSelect.selectedIndex = -1;
	
	return true;
}

function removeCapitalUseOption(cboSelect,txtID, cboCapitalUse, blnClear) {


    	
	if (txtID.value != '') {
		
		var intIndex = txtID.value;
		cboSelect.options[intIndex] = null;
		
		txtID.value = '';
		if(blnClear){
			
			cboCapitalUse.selectedIndex = 0; 
			
		}
	}

}
function storeCapitalUses(cboSelect){
	var strCapitalUse = '';
	var strCapitalUseText = '';
	//alert('Storing industry drivers...');
	for(var x = 0; x < cboSelect.options.length; x++){
		if(strCapitalUse != '' ) {
			strCapitalUse += '!';
			strCapitalUseText += '!';
		}
		// Don't store the default entry
		if(cboSelect.options[x].value != 1000){
			// Store just the ID 
			strCapitalUse +=  cboSelect.options[x].value;
			// Store the ID and text
			strCapitalUseText += cboSelect.options[x].value + '^' + cboSelect.options[x].text;
		}
	}
	$('CapitalUseList').value = strCapitalUse;
	$('CapitalUseText').value = strCapitalUseText;
}



//-->