<!--//
////////////////////////////////////////////////////////////////////
// Key Investment Properties
// Usings as general filtering functions
// MODIFICATION HISTORY:
// 04/01/2003	mtb	MSA is being removed from the listing
//					The PropID array will now store the stateID rather than the MSAID
////////////////////////////////////////////////////////////////////
function FilterSubList(cboMain,cboSubAll,cboSubFilter, blnAddNone){
	var defaultSelected = true;
    var selected = false;
	var intCurrentState = cboMain.selectedIndex;
	var strMain = cboMain.options[intCurrentState].text;
	var strItem;
	
	//alert('cboMain.options[intCurrentState].text= ' + cboMain.options[intCurrentState].text);
	
	// Clear all items from the Filter list	
	if(cboSubFilter.length >0){
		removeAll(cboSubFilter);
	}
	if(blnAddNone){
		var optionName = new Option("None", 0, defaultSelected, selected)	
		cboSubFilter.options[0] = optionName;
		cboSubFilter.options[0].value = 0;
	}
	for(var intIndex = 0; intIndex <= cboSubAll.length - 1; intIndex++){
		// See if the entry matches
		//alert('cboSubAll.options[intIndex].label= ' + cboSubAll.options[intIndex].label);
		//alert('equal = ' + (cboMain.options[intIndex].text == strValue));
		strItem = cboSubAll.options[intIndex].label;
		//alert('strItem= ' + strItem + ' : strMain= ' + strMain + ' : strItem.indexOf(strMain) = ' + strItem.indexOf(strMain) );
		if(strItem != null) {
			if(strItem.indexOf(strMain) > -1){
				// Add the item
				var length = cboSubFilter.length;
				var strNewText = cboSubAll.options[intIndex].text;
				var strNewValue = cboSubAll.options[intIndex].value;
				var optionName = new Option(strNewText, length, defaultSelected, selected)	
    			cboSubFilter.options[length] = optionName;
    			cboSubFilter.options[length].value = strNewValue;
			}
		}
	
	}


}
function onChangeInvProps(frm,cboSelect,txtID, cboState, cboMSA,cboMSAFilter, txtQty, txtPropValue) {
    var intCurrent = cboSelect.selectedIndex;
	var strItem = cboSelect.options[intCurrent].text;
	var intItemValue = cboSelect.options[intCurrent].value
	var strState;
	var strMSA;
	var strQty;
	var strPropVal;
	var intPipe;
	
	// Starting item value	
	//alert('intCurrent = ' + intCurrent + ' intItemValue = ' + intItemValue + ' strItem = ' + strItem);

	// Locate the first pipe
	intPipe = strItem.indexOf('|');
	//alert('First Pipe = ' + intPipe);
	
	// Assign the State  value
	strState = strItem.substring(0,intPipe -1);
	//alert('State = ' + strState );

	// Reduce the string
	strItem = strItem.substring(intPipe + 1,strItem.length);
	//alert('strItem = ' + strItem);

	// Locate the next pipe
	//intPipe = strItem.indexOf('|');

	// Assign the MSA  value
	//strMSA = strItem.substring(0,intPipe -1);
	//alert('MSA = ' + strMSA );

	// Reduce the string
	//strItem = strItem.substring(intPipe + 1,strItem.length);	
	//alert('strItem = ' + strItem);

	// Locate the next pipe
	intPipe = strItem.indexOf('|');
	//alert('Qty (intPipe) = ' + intPipe );	
	
	// Assign the Qty value
	strQty =  strItem.substring(0,intPipe - 1);
	//alert('Qty = ' + strQty );	
	
	// Reduce the string
	strItem = strItem.substring(intPipe + 1,strItem.length);	
	//alert('strItem = ' + strItem);

	// Assign the PropValue value
	strPropVal = strItem.substring(0,strItem.length);
	//alert('PropVal = ' + strPropVal );
	
	// Asssign the values to the fields
	txtID.value = intItemValue;
	findDDEntryByText(cboState,strState);
	//FilterSubList(cboState,cboMSA,cboMSAFilter)
	//findDDEntryByText (cboMSAFilter,strMSA);	
	txtQty.value = strQty.trim();	
	txtPropValue.value = strPropVal.trim();
	// Deselect the item
	cboSelect.selectedIndex = -1;
}

function addInvPropsOption(cboInvProp, cboState, txtID, txtQty, txtPropVal, blnClear) {


    var defaultSelected = true;
    var selected = false;
	var intCurrentState = cboState.selectedIndex;
	
	//var intCurrentMSA = cboMSAFilter.selectedIndex;
	
	// Exit if no values are selected
	if(intCurrentState < 0 || txtQty.value == '' || txtPropVal.value =='') 
	{
		alert('One or more of the following are missing:\n' +
			'State\n' +
			'# of Properties\n' +
			'$ Value of Properties\n');
		return false;
	}
	// intCurrentState should not be less than 0 at this point
	var intStateID = cboState.options[intCurrentState].value;
	//if(intCurrentState < 0 || intCurrentMSA < 0 || txtQty.value == '') return false;
	
	// Exit if Qty or Property Value is not numeric
	var msg = ''
	if(!( validateNumeric(txtQty,false))) msg += 'The quantity value must be numeric.\n';
	if(!( validateNumeric(txtPropVal,false))) msg += 'The property value must be numeric.\n';
	if(msg != ''){
		alert(msg);
		return false;
	}
	
	// Exit if this ID already exits within the listing and
	// prompt user to update that entry
	if((txtID.value == '') || (txtID.value == 0)) {
		if(propAlreadyAdded(cboState.options[intCurrentState].value)) {
			alert('You have already added this location.\nSelect the entry from the list if you would like to change the values.');
			return false;
		}
	}
	
	var strValue = cboState.options[intCurrentState].text + ' | ' + txtQty.value  + ' | ' + txtPropVal.value;
	var length = cboInvProp.length;
	
	var strOption0;
	if(cboInvProp.length > 0) 
		strOption0 = cboInvProp.options[0].value;
	else
		strOption0 = 1000;
	
	//alert ('strValue = ' + strValue);

	//alert('Option 0 =' + cboSelect.options[0].text);
	//alert('s = ' + strOption0 );

	// Enable the ability to replace the first entry
	if(strOption0  == 1000) length = 0;

	// 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);
	if(txtID.value == '') txtID.value = 0;	
	if (txtID.value == 0) {
		var optionName = new Option(strValue, length, defaultSelected, selected);	
    	cboInvProp.options[length] = optionName;
		cboInvProp.options[length].value = cboState.value; 
		// Add entries to global variables
		addUpdGlobalEntryInvProps(strValue,cboState.options[intCurrentState].value,txtQty.value,txtPropVal.value);
		

	}else{
		var intIndex = findDDEntryByValue(cboInvProp,txtID.value);
		cboInvProp.options[intIndex].text = strValue;
		// Update entries to global variables
		addUpdGlobalEntryInvProps(strValue,txtID.value,txtQty.value,txtPropVal.value);
	}
	
	// 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){
		
		cboState.options[0].selected = true; 
		//removeAll(cboMSAFilter);
		txtQty.value = '';
		txtPropVal.value = '';
	}

	// Unselect any highlighted items
	cboInvProp.selectedIndex = -1;
	
	return true;
	
}

function removeInvPropsOption(cboInvProp, cboState, txtID,   txtQty, txtPropVal, blnClear) {

	if(txtID.value == '') txtID.value = 0;
    	
	if (txtID.value != 0) {
		//alert('removing txtID.value = ' + txtID.value + ' txtPropVal.value = ' + txtPropVal.value);
		var intIndex = findDDEntryByValue(cboInvProp,txtID.value);
		cboInvProp.options[intIndex] = null;
		
		
		removeGlobalEntryInvProps(txtID.value);
		
		// Clear values
		txtID.value = 0;
		if(blnClear){
			cboState.options[0].selected = true; 
			//removeAll(cboMSAFilter);
			txtQty.value = '';
			txtPropVal.value = '';
		}
		
	}

}
function addUpdGlobalEntryInvProps(strText, intID, intQty, intPropVal){
	// add / update entries to global variables
	var blnFound = false;
	
	//alert('Text = ' + strText + ' ID = ' + intID + ' Qty = ' + intQty);
	if(intID > 0){
		// Lookup the matching entry
		for (var x = 0; x < m_intInvPropsIndex; x++){
			if(m_intInvPropsID[x] == intID)  {
				blnFound = true;
				// Assign new values
				m_strInvPropsText[x] = strText;
				m_intInvPropsQty[x] = intQty;
				m_dblInvPropsValue[x] =  intPropVal;
				break;
			}
		}
	}
	// Add a new entry if either the ID = 0 or we did not find the entry
	if(!(blnFound)){
		// Assign a new entry
		m_strInvPropsText[m_intInvPropsIndex] = strText;
		m_intInvPropsID[m_intInvPropsIndex] = intID;
		m_intInvPropsQty[m_intInvPropsIndex] = intQty;
		m_dblInvPropsValue[m_intInvPropsIndex] =  intPropVal;
	}
	
	
	// Increment Index
	m_intInvPropsIndex += 1;
}
function removeGlobalEntryInvProps(intID){
	// remove entries to global variables
	// and shift all values
	var blnFound = false;
	for (var x = 0; x < m_intInvPropsIndex; x++){
		//alert('test: m_intInvPropsID[x] = ' + m_intInvPropsID[x]  + ' ID = ' + intID); 
		if(m_intInvPropsID[x] == intID) blnFound = true;
		if(blnFound) {
			// Do shifting
			// If we have reached the max of the array then just clear all values
			if(x == 300) {
				m_strInvPropsText[x] = '';
				m_intInvPropsID[x] = 0;
				m_intInvPropsQty[x] = 0;
				m_dblInvPropsValue [x] = 0;

			}else{
				m_strInvPropsText[x] = m_strInvPropsText[x+1];
				m_intInvPropsID[x] = m_intInvPropsID[x+1];
				m_intInvPropsQty[x] = m_intInvPropsQty[x+1];
				m_dblInvPropsValue[x] = m_dblInvPropsValue[x+1];
			}
		}
	}		
	// decrement counter
	m_intInvPropsIndex -= 1;
}

function clearInvPropsOption( cboState, txtID, cboSubFilter,txtQty, txtPropValue ){
	txtID.value = '';
	cboState.selectedIndex = 0;
	if(cboSubFilter.length >0){
		removeAll(cboSubFilter);
	}
	txtQty.value = '';
	txtPropValue.value = '';	
}
function propAlreadyAdded(intID){
	blnFound = false;
	//alert('intID = ' + intID);
	if(intID > 0){
		// Lookup the matching entry
		for (var x = 0; x < m_intInvPropsIndex; x++){
			//alert('m_intInvPropsID[' + x + '] = ' + m_intInvPropsID[x]);
			if(m_intInvPropsID[x] == intID)  {
				blnFound = true;
			
				break;
			}
		}
	}

	return blnFound;
}

function FilterSubList_Old(cboMain,cboSubAll,cboSubFilter, blnAddNone){
	var defaultSelected = true;
    var selected = false;
	var intCurrentState = cboMain.selectedIndex;
	var strMain = cboMain.options[intCurrentState].text;
	var strItem;
	
	//alert('cboMain.options[intCurrentState].text= ' + cboMain.options[intCurrentState].text);
	
	// Clear all items from the Filter list	
	if(cboSubFilter.length >0){
		removeAll(cboSubFilter);
	}
	if(blnAddNone){
		var optionName = new Option("None", 0, defaultSelected, selected)	
		cboSubFilter.options[0] = optionName;
		cboSubFilter.options[0].value = 0;
	}
	for(var intIndex = 0; intIndex <= cboSubAll.length - 1; intIndex++){
		// See if the entry matches
		//alert('cboSubAll.options[intIndex].label= ' + cboSubAll.options[intIndex].label);
		//alert('equal = ' + (cboMain.options[intIndex].text == strValue));
		strItem = cboSubAll.options[intIndex].label;
		//alert('strItem= ' + strItem + ' : strMain= ' + strMain + ' : strItem.indexOf(strMain) = ' + strItem.indexOf(strMain) );
		if(strItem != null) {
			if(strItem.indexOf(strMain) > -1){
				// Add the item
				var length = cboSubFilter.length;
				var strNewText = cboSubAll.options[intIndex].text;
				var strNewValue = cboSubAll.options[intIndex].value;
				var optionName = new Option(strNewText, length, defaultSelected, selected)	
    			cboSubFilter.options[length] = optionName;
    			cboSubFilter.options[length].value = strNewValue;
			}
		}
	
	}


}
function onChangeInvProps_Old(frm,cboSelect,txtID, cboState, cboMSA,cboMSAFilter, txtQty, txtPropValue) {
    var intCurrent = cboSelect.selectedIndex;
	var strItem = cboSelect.options[intCurrent].text;
	var intItemValue = cboSelect.options[intCurrent].value
	var strState;
	var strMSA;
	var strQty;
	var strPropVal;
	var intPipe;
	
	// Starting item value	
	//alert('intCurrent = ' + intCurrent + ' intItemValue = ' + intItemValue + ' strItem = ' + strItem);

	// Locate the first pipe
	intPipe = strItem.indexOf('|');
	//alert('First Pipe = ' + intPipe);
	
	// Assign the State  value
	strState = strItem.substring(0,intPipe -1);
	//alert('State = ' + strState );

	// Reduce the string
	strItem = strItem.substring(intPipe + 1,strItem.length);
	//alert('strItem = ' + strItem);

	// Locate the next pipe
	intPipe = strItem.indexOf('|');

	// Assign the MSA  value
	strMSA = strItem.substring(0,intPipe -1);
	//alert('MSA = ' + strMSA );

	// Reduce the string
	strItem = strItem.substring(intPipe + 1,strItem.length);	
	//alert('strItem = ' + strItem);

	// Locate the next pipe
	intPipe = strItem.indexOf('|');
	
	// Assign the Qty value
	strQty =  strItem.substring(0,intPipe - 1);
	//alert('Qty = ' + strQty );	
	
	// Reduce the string
	strItem = strItem.substring(intPipe + 1,strItem.length);	
	//alert('strItem = ' + strItem);

	// Assign the PropValue value
	strPropVal = strItem.substring(0,strItem.length);
	//alert('PropVal = ' + strPropVal );
	
	// Asssign the values to the fields
	txtID.value = intItemValue;
	findDDEntryByText(cboState,strState);
	FilterSubList(cboState,cboMSA,cboMSAFilter)
	findDDEntryByText (cboMSAFilter,strMSA);	
	txtQty.value = strQty.trim();	
	txtPropValue.value = strPropVal.trim();
	// Deselect the item
	cboSelect.selectedIndex = -1;
}

function addInvPropsOption_Old(cboInvProp, cboInvPropH,txtID, cboState, cboMSAFilter, txtQty, txtPropVal, blnClear) {


    var defaultSelected = true;
    var selected = false;
	var intCurrentState = cboState.selectedIndex;
	var intCurrentMSA = cboMSAFilter.selectedIndex;
	
	// Exit if no values are selected
	if(intCurrentState < 0 || txtQty.value == '' || txtPropVal.value =='') 
	{
		alert('One or more of the following are missing:\n' +
			'State\n' +
			'# of Properties\n' +
			'$ Value of Properties\n');
		return false;
	}
	if(intCurrentState < 0 || intCurrentMSA < 0 || txtQty.value == '') return false;
	
	// Exit if Qty or Property Value is not numeric
	var msg = ''
	if(!( validateNumeric(txtQty,false))) msg += 'The quantity value must be numeric.\n';
	if(!( validateNumeric(txtPropVal,false))) msg += 'The property value must be numeric.\n';
	if(msg != ''){
		alert(msg);
		return false;
	}
	
	// Exit if this ID already exits within the listing and
	// prompt user to update that entry
	if((txtID.value == '') || (txtID.value == 0)) {
		if(propAlreadyAdded(cboMSAFilter.options[intCurrentMSA].value)) {
			alert('You have already added this location.\nSelect the entry from the list if you would like to change the values.');
			return false;
		}
	}
	
	var strValue = cboState.options[intCurrentState].text + ' | ' + cboMSAFilter.options[intCurrentMSA].text  + ' | ' + txtQty.value  + ' | ' + txtPropVal.value;
	var length = cboInvProp.length;
	
	var strOption0;
	if(cboInvProp.length > 0) 
		strOption0 = cboInvProp.options[0].value;
	else
		strOption0 = 1000;
	
	//alert ('strValue = ' + strValue);

	//alert('Option 0 =' + cboSelect.options[0].text);
	//alert('s = ' + strOption0 );

	// Enable the ability to replace the first entry
	if(strOption0  == 1000) length = 0;

	// 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);
	if(txtID.value == '') txtID.value = 0;	
	if (txtID.value == 0) {
		var optionName = new Option(strValue, length, defaultSelected, selected);	
    	cboInvProp.options[length] = optionName;
		cboInvProp.options[length].value = cboMSAFilter.value; 
		// Add entries to global variables
		addUpdGlobalEntryInvProps(strValue,cboMSAFilter.options[intCurrentMSA].value,txtQty.value,txtPropVal.value);
		

	}else{
		var intIndex = findDDEntryByValue(cboInvProp,txtID.value);
		cboInvProp.options[intIndex].text = strValue;
		// Update entries to global variables
		addUpdGlobalEntryInvProps(strValue,txtID.value,txtQty.value,txtPropVal.value);
	}
	
	// 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){
		
		cboState.options[0].selected = true; 
		removeAll(cboMSAFilter);
		txtQty.value = '';
		txtPropVal.value = '';
	}

	// Unselect any highlighted items
	cboInvProp.selectedIndex = -1;
	
	return true;
	
}

function removeInvPropsOption_Old(cboInvProp, cboInvPropH,txtID,  cboState, cboMSAFilter, txtQty, txtPropVal, blnClear) {

	if(txtID.value == '') txtID.value = 0;
    	
	if (txtID.value != 0) {
		//alert('removing txtID.value = ' + txtID.value);
		var intIndex = findDDEntryByValue(cboInvProp,txtID.value);
		cboInvProp.options[intIndex] = null;
		
		
		removeGlobalEntryInvProps(txtID.value);
		
		// Clear values
		txtID.value = 0;
		if(blnClear){
			cboState.options[0].selected = true; 
			removeAll(cboMSAFilter);
			txtQty.value = '';
			txtPropVal.value = '';
		}
		
	}

}
function addUpdGlobalEntryInvProps_Old(strText, intID, intQty, intPropVal){
	// add / update entries to global variables
	var blnFound = false;
	
	//alert('Text = ' + strText + ' ID = ' + intID + ' Qty = ' + intQty);
	if(intID > 0){
		// Lookup the matching entry
		for (var x = 0; x < m_intInvPropsIndex; x++){
			if(m_intInvPropsID[x] == intID)  {
				blnFound = true;
				// Assign new values
				m_strInvPropsText[x] = strText;
				m_intInvPropsQty[x] = intQty;
				m_dblInvPropsValue[x] =  intPropVal;
				break;
			}
		}
	}
	// Add a new entry if either the ID = 0 or we did not find the entry
	if(!(blnFound)){
		// Assign a new entry
		m_strInvPropsText[m_intInvPropsIndex] = strText;
		m_intInvPropsID[m_intInvPropsIndex] = intID;
		m_intInvPropsQty[m_intInvPropsIndex] = intQty;
		m_dblInvPropsValue[m_intInvPropsIndex] =  intPropVal;
	}
	
	
	// Increment Index
	m_intInvPropsIndex += 1;
}
function removeGlobalEntryInvProps_Old(intID){
	// remove entries to global variables
	// and shift all values
	var blnFound = false;
	for (var x = 0; x < m_intInvPropsIndex; x++){
		//alert('test: m_intInvPropsID[x] = ' + m_intInvPropsID[x]  + ' ID = ' + intID); 
		if(m_intInvPropsID[x] == intID) blnFound = true;
		if(blnFound) {
			// Do shifting
			// If we have reached the max of the array then just clear all values
			if(x == 300) {
				m_strInvPropsText[x] = '';
				m_intInvPropsID[x] = 0;
				m_intInvPropsQty[x] = 0;
				m_dblInvPropsValue [x] = 0;

			}else{
				m_strInvPropsText[x] = m_strInvPropsText[x+1];
				m_intInvPropsID[x] = m_intInvPropsID[x+1];
				m_intInvPropsQty[x] = m_intInvPropsQty[x+1];
				m_dblInvPropsValue[x] = m_dblInvPropsValue[x+1];
			}
		}
	}		
	// decrement counter
	m_intInvPropsIndex -= 1;
}

function clearInvPropsOption_Old(txtID, cboState, cboSubFilter,txtQty, txtPropValue ){
	txtID.value = '';
	cboState.selectedIndex = 0;
	if(cboSubFilter.length >0){
		removeAll(cboSubFilter);
	}
	txtQty.value = '';
	txtPropValue.value = '';	
}
function propAlreadyAdded_Old(intID){
	blnFound = false;
	//alert('intID = ' + intID);
	if(intID > 0){
		// Lookup the matching entry
		for (var x = 0; x < m_intInvPropsIndex; x++){
			//alert('m_intInvPropsID[' + x + '] = ' + m_intInvPropsID[x]);
			if(m_intInvPropsID[x] == intID)  {
				blnFound = true;
			
				break;
			}
		}
	}

	return blnFound;
}
//-->