function checkAll(maincheck, form, field)
{
	var oCheckbox = document.getElementById(field);
	with (form)
	{
		for (var i=0; i < elements.length; i++)
		{
			if (elements[i].type == 'checkbox' && elements[i].name == field)
				elements[i].checked = maincheck.checked;
		}
	}
} // checkAll

function getRadioValue(radioBtn)
{
	for(i=0; i<radioBtn.length; i++)
	{
		if (radioBtn[i].checked)
			return radioBtn[i].value;
	}
	return false;
} // getRadioValue

function listMoveUp(elementId)
{
	listBox = document.getElementById(elementId);
	
	if (listBox.selectedIndex < 1)
		return false;
		
	tempValue = listBox.options[listBox.selectedIndex].value;
	tempText = listBox.options[listBox.selectedIndex].text
	listBox.options[listBox.selectedIndex].value = listBox.options[listBox.selectedIndex-1].value;
	listBox.options[listBox.selectedIndex].text = listBox.options[listBox.selectedIndex-1].text;
	listBox.options[listBox.selectedIndex-1].value = tempValue;
	listBox.options[listBox.selectedIndex-1].text = tempText;
	listBox.selectedIndex -= 1;
	listSelectedIndexes[elementId] = listBox.selectedIndex;
	
} // listMoveUp

function listMoveDown(elementId)
{
	listBox = document.getElementById(elementId);
	
	if (listBox.selectedIndex == -1 || listBox.selectedIndex >= listBox.length-1)
		return false;
		
	tempValue = listBox.options[listBox.selectedIndex].value;
	tempText = listBox.options[listBox.selectedIndex].text
	listBox.options[listBox.selectedIndex].value = listBox.options[listBox.selectedIndex+1].value;
	listBox.options[listBox.selectedIndex].text = listBox.options[listBox.selectedIndex+1].text;
	listBox.options[listBox.selectedIndex+1].value = tempValue;
	listBox.options[listBox.selectedIndex+1].text = tempText;
	listBox.selectedIndex += 1;
	listSelectedIndexes[elementId] = listBox.selectedIndex;
	
} // listMoveDown

function listSelectAll(elementId)
{
	listBox = document.getElementById(elementId);
	for(i = 0;i < listBox.length;i++)
	{
		listBox.options[i].selected = true;
	}
} // listSelectAll

function listGetSelectedOption(elementId)
{
	listBox = document.getElementById(elementId);
	for(i=0; i<listBox.length; i++)
	{
		if (listBox.options[i].selected)
			return listBox.options[i];
	}
} // listGetSelectedOption

var listSelectedIndexes = Array();
function listFixSingleSelect(elementId)
{
	listBox = document.getElementById(elementId);
	
	selectedCount = 0;
	selectedIndex = -1;
	for(i=0; i<listBox.length; i++)
	{
		if (listBox.options[i].selected)
		{
			selectedCount++;
			selectedIndex = i;
		}
	}
	if (selectedCount > 1)
	{
		for(i=0; i<listBox.length; i++)
		{
			if (listSelectedIndexes[elementId] != i)
				listBox.options[i].selected = false;
		}
	}
	else
	{
		listSelectedIndexes[elementId] = selectedIndex;
	}
} // listFixSingleSelect

function listSelectItem(elementId, i)
{
	listBox = document.getElementById(elementId);
	listSelectedIndexes[elementId] = i;
	listBox.selectedIndex = i;
} // listSelectItem

function tableMoveRowUp(tableId, elem)
{
	
	var row = elem;
	var table = elem;
	while (table.id != tableId)
	{
		if (table.nodeName == 'TR')
			row = table;
		table = table.parentNode;
	}

	prow = row.previousSibling;
	while (prow != null && (prow.nodeName != 'TR' || prow.id == 'tableRowMoveIgnore' || prow.style.visibility == 'hidden'))
	{
		prow = prow.previousSibling;
	}
	
	if (prow == null)
		return;
	
	row.parentNode.insertBefore(row, prow);

} // tableMoveRowUp

function tableMoveRowDown(tableId, elem)
{
	
	var row = elem;
	var table = elem;
	while (table.id != tableId)
	{
		if (table.nodeName == 'TR')
			row = table;
		table = table.parentNode;
	}
	
	nrow = row.nextSibling;
	while (nrow != null && (nrow.nodeName != 'TR' || nrow.id == 'tableRowMoveIgnore' || nrow.style.visibility == 'hidden'))
	{
		nrow = nrow.nextSibling;
	}
		
	if (nrow == null)
		return;
	
	row.parentNode.insertBefore(nrow, row);
	
} // tableMoveRowDown

function tableHideRow(tableId, elem)
{
	
	var row = elem;
	var table = elem;
	while (table.id != tableId)
	{
		if (table.nodeName == 'TR')
			row = table;
		table = table.parentNode;
	}

	row.style.display = 'none';
} // tableHideRow

var __imageButtons = new Array();
function swapImageButton(imageBtn, btnName, state)
{
	uri = baseurl+'/graphics/buttons/'+btnName+'_'+state+'.gif'
	imageBtn.src = uri;
} // swapImageButton

function loadImageButton(btnName)
{
	__imageButtons[__imageButtons.length] = new Image();
	__imageButtons[__imageButtons.length-1].src = baseurl+'/graphics/buttons/'+btnName+'_down.gif';
	__imageButtons[__imageButtons.length] = new Image();
	__imageButtons[__imageButtons.length-1].src = baseurl+'/graphics/buttons/'+btnName+'_over.gif';
} // loadImageButton

function fetchClassName(obj, count)
{
	x = 0;
	px = -1;
	n = '';
	for(i=0; i<count; i++)
	{
		x = obj.className.indexOf(' ', px+1);
		if (x == -1)
		{
			n +=  obj.className.substring(px);
			break;
		}
		
		if (i>0)
			n += ' ';
		n += obj.className.substring(px+1, x);
		px = x;
	}

	return n;
} // fetchClassName

function blackBtnOver(btn)
{
	btn.className = fetchClassName(btn, 2) + ' over';
}

function blackBtnDown(btn)
{
	btn.className = fetchClassName(btn, 2) + ' down';
}

function blackBtnOut(btn)
{
	btn.className = fetchClassName(btn, 2);
}