// SITE-WIDE CURRENCY CONVERSION HANDLER
Event.observe(window, 'load', function() {
	if ( $('currency-converter-select') ) {
		Event.observe('currency-converter-select', 'change', function() {
			$('currency-converter-form').submit();
		});
	}
	
	//new window targets
	$$('a[rel~=nofollow]').each(function(a){a.setAttribute('target', '_blank');});
	$$('a[rel~=external]').each(function(a){a.setAttribute('target', '_blank');});
});

function updateTestimonialChars(elem, maxlen)
{
	$(elem + '-chars').update($F(elem).length + ' characters');
	if ( $F(elem).length > maxlen ) 
	{	
		$(elem + '-chars').style.color = 'red';
		$(elem + '-chars').style.fontWeight = 'bold';
	}
	else
	{
		$(elem + '-chars').style.color = 'black';
		$(elem + '-chars').style.fontWeight = 'normal';	
	}
}

// SIMPLE CONVENIENCE FUNCTIONS

/**
* Find the index of a value in a given array.
* Optionally pass path as the name of a key if haystack elements are objects.
*/
function array_find(needle, haystack, path)
{
	for ( i=0; i<haystack.length; i++ )
	{
		if ( path )
		{
			value = eval('haystack[i].'+path);
		}
		else
		{
			value = haystack[i];
		}
		if ( value == needle )
		{
			return i;
		}
	} 
	return -1;
}

/**
*	Creates a help pop-up.
*/
function showHelpTip( element, msg )
{		
	var tip = new Tip( element, msg, {className:'help-tooltip'} );
}



