function CG_SortMasterSlave(theMaster, theSlave, arrSlaveByMaster, sMsgNone, sMsgAll)
{
	var lstSlave = new Array();
	var lstIdx = new Array();

	if ( theMaster != null && theSlave != null )
	{
		if (theMaster.type == 'hidden')
			idx = theMaster.value;
		else
			idx = theMaster.options[theMaster.selectedIndex].value;
		
		if (idx == 0)
		{
			for (var i=0 ; i < arrSlaveByMaster.length ; i++)
			{
				if (arrSlaveByMaster[i] != null)
					lstSlave = lstSlave.concat(arrSlaveByMaster[i]);
			}
			
			lstSlave = CG_SortByTxt(lstSlave);
		}
		else
			lstSlave = arrSlaveByMaster[idx];

		while (theSlave.options.length) theSlave.options[0] = null;
	
		if (lstSlave != null)
		{
			theSlave.options[0] = new Option( sMsgNone, '-1', true, true );
			theSlave.options[1] = new Option( sMsgAll, '0' );
			for (var j = 0; j < lstSlave.length; j += 2 )
			{
				theSlave.options[(j/2)+2] = new Option( lstSlave[j], lstSlave[j+1] );
			}
		}
		else
		{
			if (sMsgNone != 'SKIP')
			{
				theSlave.options[0] = new Option( sMsgNone, '-1' );
			}
		}

	}
}

function CG_SortByTxt(arrParam)
{
	var arrTxt = new Array();
	var arrFinal = new Array();
	var idx;
	var bExists;
	var sTxtValue;

	for (var i=0 ; i<arrParam.length ; i += 2)
	{
		arrTxt.push(arrParam[i]);
	}
	
	arrTxt.sort();
	
	for (var j=0 ; j<arrTxt.length ; j++)
	{
		sTxtValue = arrTxt[j];
		bExists = CG_ExistsInArray(arrFinal, sTxtValue);
		if ( bExists == false)
		{
			idx = CG_GetIndexOf(arrParam, sTxtValue);
			arrFinal.push(sTxtValue);
			arrFinal.push(arrParam[idx+1]);
		}
	}
	
	return arrFinal;
}

function CG_GetIndexOf(arrParam, sValue)
{
	var idx;
	var sTxt;
	
	for (var i=0 ; i<arrParam.length ; i = i+2)
	{
		sTxt = arrParam[i];
		if (sTxt == sValue)
		{
			idx = i;
			break;
		}
	}
	
	return idx;
}

function CG_ExistsInArray(arrParam, sValue)
{
	var bExists = false;
	
	for (var i=0 ; i<arrParam.length ; i+=2)
	{
		if (arrParam[i] == sValue)
		{
			bExists = true;
			break;
		}
	}
	
	return bExists;
}