var FlipArray = new Array();

function Combo_Flip(frmName, FK, Src, Dest)
{
	var Loopy;
	var ComboOptions_Dest = document.forms[frmName][Dest].options

	var FieldIndex;
	var FKIndex;
	
	var NumFields;
	var NumFK;
	var NumOptions;
	
	for (Loopy = ComboOptions_Dest.length-1; Loopy > 0; Loopy--) 
	{
		ComboOptions_Dest[Loopy] = null;						// destroy
	}



	if (document.forms[frmName][Src].value == '' || document.forms[frmName][Src].value == '0') {
		;
	}
	else {
		NumFields = FlipArray.length;

		for (Loopy = 0; Loopy < NumFields; Loopy++)					// find our combo by field name
		{
			if (FlipArray[Loopy][0] == Dest)						// if we found the key already, set the position marker
			{
				FieldIndex = Loopy;
				break;
			}
		}


		NumFK = FlipArray[FieldIndex][1].length;
		for (Loopy = 0; Loopy < NumFK; Loopy++) 
		{
			if (FlipArray[FieldIndex][1][Loopy][0] == FK)						// if we found the key already, set the position marker
			{
				FKIndex = Loopy;
				break;
			}
		}
		
		NumOptions = FlipArray[FieldIndex][1][FKIndex][1].length;

		ComboOptions_Dest[0] = new Option("", 0, false, true)

		for (Loopy = 0; Loopy < NumOptions; Loopy++) 
		{
			ComboOptions_Dest[Loopy+1] = FlipArray[FieldIndex][1][FKIndex][1][Loopy];
		}
		ComboOptions_Dest[0].selected = true
		//for (var i = 1; i<aln2; i++) document.frmMemberAdd.memberDistrict.options[i-1] = a[i];
	}
}

function Combo_StuffArray(FieldName, FK, OptValue, OptText)
{
var Loopy;
var PrevLength;
var KeyIndex;
var FKIndex;

PrevLength = FlipArray.length;
KeyIndex = PrevLength;
for (Loopy = 0; Loopy < PrevLength; Loopy++)				// go through the FieldNames
{
	if (FlipArray[Loopy][0] == FieldName)					// if we found the key, set the position marker
	{
		KeyIndex = Loopy;
		break;
	}
}

if (KeyIndex == PrevLength)							// means we didn't find the name, so we need to add a top-level array
{
	FlipArray[KeyIndex] = new Array();				// automatically resizes FlipArray to 1 bigger than before
	FlipArray[KeyIndex][0] = FieldName;
	FlipArray[KeyIndex][1] = new Array();
}

PrevLength = FlipArray[KeyIndex][1].length;
FKIndex = PrevLength;
for (Loopy = 0; Loopy < PrevLength; Loopy++)				// go through the FieldNames
{
	if (FlipArray[KeyIndex][1][Loopy][0] == FK)					// if we found the key, set the position marker
	{
		FKIndex = Loopy;
		break;
	}
}

if (FKIndex == PrevLength)									// means we didn't find the FK
{
	FlipArray[KeyIndex][1][FKIndex] = new Array();			// automatically resizes FlipArray to 1 bigger than before
	FlipArray[KeyIndex][1][FKIndex][0] = FK;				
	FlipArray[KeyIndex][1][FKIndex][1] = new Array();
}

PrevLength = FlipArray[KeyIndex][1][FKIndex][1].length;		// automatically resizes FlipArray to 1 bigger than before
FlipArray[KeyIndex][1][FKIndex][1][PrevLength] = new Option(OptText, OptValue, false, true);
}