// <![CDATA[

/*
v1.5 - 14/02/09 - Modified to create CAPTCHA buttons on img.securityCode rather than #securityCode
                  although only one of this element can exist at a time, AJAX calls may not destroy
                  the element fully, thus allowing potential for multiple ID's of the same name
v1.62- 20/02/09 - The autocomplete disable now ignores any input elements with a class of 'autocomplete_on'
*/

window.addEvent('domready', function() {
	//$$('input[type=text]').setProperty('autocomplete','off');
	$(document.body).getElements('input[type=text]').each( function(el) {
		if( !el.hasClass('autocomplete_on') ) el.setProperty('autocomplete','off');
	} );

	$$('span').each(function(el) {
		if( el.get('text').contains('[at]') ) {
			var email = el.get('text').replace(' [at] ','@');
			el.set('html','<a href="mailto:' + email + '">' + email + '</a>');
		}
	} );

	if( document.getElement('div.error input') ) {
		//document.getElement('div.error input').focus();
	} else if( document.getElement('input') ) {
		//document.getElement('input').focus();
	}

	$$('img.securityCode').each( function(securityCode) {
		new Element('div', {
			'class':'reload'
		} ).addEvent('click',function() {
			securityCode.set('src', securityCode.get('src') + '?reload' + $time());
		} ).inject(securityCode,'before');

		if( securityCode.getParent('div').getElement('a') ) {
			var link = securityCode.getParent('div').getElement('a');
			new Element('div', {
				'class':'audio',
				'html':'<a href="' + link.get('href') + '"><span>play</span></a>'
			} ).inject(securityCode,'before');
			link.destroy();
		}
		securityCode.removeClass('securityCode');
	} );
} );

// ]]>