/* Code to submit links from an action box drop down
 * This checks whether the link is external and if so forces the
 * browser to open it in a new window.
 *
 * Tested with IE5, IE5.5, IE6, Netscape 4.6, Opera 5 and Mozilla Firebird
 */
function runActionLink()
{
	index = document.actionForm.redirectParams.selectedIndex
	if(index > -1)
	{
		url = document.actionForm.redirectParams[index].value;

		if(url != null)
		{		
			if(url.indexOf(".businesslink.") == -1 && url.indexOf(".bdotg.") == -1)
			{
				document.actionForm.target="bgExternal";
			}
			else
			{
				document.actionForm.target="";	
			}
			document.actionForm.submit();
		}
	}
}

function getOmnitureLinkType()
{
	var linkType = "o";
	var url = "";
	var markerPos = -1;
	
	index = document.actionForm.redirectParams.selectedIndex
	if(index > -1)
	{
		url = document.actionForm.redirectParams[index].value;
		if ( url != null )
		{
			if(url.indexOf("OTHER") != -1)
			{
				linkType = "e";
			}
		}
	}
	return linkType;
}

function getTargetUrl()
{
	var url = "";
	var pos = -1;
	var str = "";
	
	index = document.actionForm.redirectParams.selectedIndex
	if(index > -1)
	{
		str = document.actionForm.redirectParams[index].value;
		url = str.substring(pos = str.lastIndexOf("; ") + 2);
	} 
	return url;
}

function popToFront()
{
	if (document.actionForm.target == "bgExternal")
	{
		var myWin = window.open(document.actionForm.action + "?redirectParams=" + document.actionForm.redirectParams[index].value);
		myWin.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function runLocalisedLink()
{
	if(document.localForm.site.selectedIndex > -1)
	{
			document.localForm.submit();
	}
}

/* Automaticaly moves cursor to next element, one the max number
 * of items have been entered into the current element. 
 * 
 * Tested with IE6, Mozilla Firefox 2.0
 */					
function autoTab(input, maxLength, nextElementID)
{

	var currentLength = input.value.length;
	
	
	if(currentLength >= maxLength) 
	{
		
		var obj = document.getElementById(nextElementID);
										
		if(obj != null)
		{
			obj.focus();
		}
		else
		{
	
			var currentElementIndex = getIndex(input) + 1;
		
			var numberOfElementsInForm = input.form.length;
		
			var nextElementIndex = currentElementIndex % numberOfElementsInForm;
		
			input.form[nextElementIndex].focus();
		
		}
	}
	
	function getIndex(input) 
	{
		var index = -1;
		var i = 0;
		var found = false;
	
		while (i < input.form.length && index == -1)
		{
			if (input.form[i] == input)
			{
				index = i;
			}
			else
			{
				i++;
			}
		}
		
		return index;
	}
	
	return true;
}
							
		
