function openHelp(anID)
{
	var path = '/portal/help/index.htm';
	if (anID != null && anID != '')
	{
		path = path + '?' + anID;
	}
	window.open(path,
		'Help', 'width=700,height=600,status=no,resizable=yes,top=50,left=50,dependent=yes,alwaysRaised=yes');
}
function openFieldHelp(anID)
{
	var path = '/portal/help/';
	if (anID != null)
	{
		path = path + anID + '.htm';
	}
	else
	{
		path = path + 'index.htm';
	}
	window.open(path,
		'Help', 'width=700,height=600,status=no,resizable=yes,top=50,left=50,dependent=yes,alwaysRaised=yes');
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

/* If the first field's length is equal to firstFieldLength and the cursor position
is at the end, give the second field the focus. */
function focusNext(firstField, secondField, firstFieldLength, e)
{
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(firstField.value.length >= firstFieldLength  && !containsElement(filter,keyCode) && 
		getSelectionStart(firstField) == firstFieldLength) 
	{
		firstField.value = firstField.value.slice(0, firstFieldLength);
		secondField.focus();
	}
	return true;
}

/* check whether the array contains the item */
function containsElement(arr, item)
{
	var found = false, index = 0;
	while(!found && index < arr.length)
	{
		if(arr[index] == item)
		{
			found = true;
		}
		else
		{
			index++;
		}
	}
	return found;
}

/* return first index of item in array */
function indexOf(arr, item)
{
	var index = 0;
	while(index < arr.length)
	{
		if(arr[index] == item)
		{
			return index;
		}
		else
		{
			index++;
		}
	}
	return index;
}

/* check whether the array contains the item */
function elementStartsWith(arr, item)
{
	var found = false, index = 0;
	while(!found && index < arr.length)
	{
		if(arr[index].indexOf(item) == 0)
		{
			found = true;
		}
		else
		{
			index++;
		}
	}
	return found;
}

/* get list of items that start with the given item */
function elementsStartingWith(list, item)
{
	var newList = null;
	var newListIndex = 0;
	for (i = 0; i < list.length; i++)
	{
		if(list[i].indexOf(item) == 0)
		{
			if (newList == null)
			{
				newList = new Array(list[i]);
			}
			else
			{
				newList[newListIndex] = list[i];
			}
			newListIndex++;
		}
	}
	return newList;
}

/* Get the beginning cursor position of the selected text (if any) in the field */
function getSelectionStart(field)
{
	if (field.createTextRange)
	{
		var range = document.selection.createRange().duplicate();
		range.moveEnd('character', field.value.length);
		if (range.text == '')
		{
			return field.value.length;
		}
		return field.value.lastIndexOf(range.text)
	}
	else
	{
		return field.selectionStart;
	}
}

/* Get the end cursor position of the selected text (if any) in the field */
function getSelectionEnd(field)
{
	if (field.createTextRange)
	{
		var range = document.selection.createRange().duplicate();
		range.moveStart('character', -field.value.length);
		return range.text.length;
	}
	else
	{
		return field.selectionEnd;
	}
}

/* Submits the form if the enter key is pressed in the field */
function submitEnter(e, myForm, destination)
{
	var keycode;
	if (window.event) 
	{
		keycode = window.event.keyCode;
	}
	else if (e) 
	{
		keycode = e.which;
	}
	else 
	{
		return true;
	}


	if (keycode == 13)
	{
		submitForm(myForm, destination);
		return false;
	}
	else
	{
		return true;
	}
}

/* Function that sets a navigator and submits the form */
function submitForm(myForm, theAction)
{
	if (theAction != null)
	{
		myForm.action.value=theAction;
	}
	myForm.submit();
}

/* Open a new window */
function newWindow(theURL,winName,features)
{
	window.open(theURL, winName, features);

}

function DIV_display(divID, visibility){ 
//alert(divID+","+visibility);
try
{
	if (document.getElementById(divID)){
		if (visibility==false) { 
			document.getElementById(divID).style.display = "none";
		} else { 
			document.getElementById(divID).style.display = "";
		}
	}
}
catch (e)
{
	alert(divID+","+visibility+" caught error");
}
	
}

function doNothing()
{
}
