window.addEvent('domready', function() {
	var Tip = new Tips($$('.tooltip'));

	if (window.ie && !window.ie7) {
		$$('ul.dropmenu li').each(function(li) {
			li.addEvent('mouseover', function() {
				li.addClass('over');
			});
			li.addEvent('mouseout', function() {
				li.removeClass('over');
			});
		});

		$$('img[src$=png]').each(function(img) {
			var coord = img.getCoordinates();
			img.setStyles({
				width: coord.width,
				height: coord.height,
				filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+img.src+'", sizingMethod="scale")',
				visibility: 'hidden'
			});
			img.src = '/images/blank.gif';
			img.addEvent('load', function() {
				img.setStyle('visibility', 'visible');
			});
		});
	}

	$$('img[align]').each(function(img) {
		var propertyName = 'align';
		var propertyValue = img.getProperty(propertyName);
		if (propertyValue != '') {
			img.addClass(propertyValue);
		}
	});

	// Change language flag images when hovered
	$$('img.other-language').each(function(img) {
		img.addEvent('mouseover', function() {
			this.src = this.src.replace('flag_bw.jpg', 'flag.jpg');
		});
		img.addEvent('mouseout', function() {
			this.src = this.src.replace('flag.jpg', 'flag_bw.jpg');
		});
	});

	// Add target="_blank" on external links
	$$('a').each(function(a) {
		if (a.getAttribute('rel') == 'external' || (!a.toString().contains(location.host) && !a.toString().contains('javascript'))) {
			a.setAttribute('target', '_blank');
		}
	});
});

function formBlocker(e) {
	var elem;

	if (!formSubmit(this))
		return false;

	elem = document.getElementById('prev');
	if (elem)
		elem.disabled = true;

	elem = document.getElementById('save');
	if (elem)
		elem.disabled = true;

	elem = document.getElementById('next');
	if (elem)
		elem.disabled = true;

	return true;
}

function initFormBlocker(form) {
	form.onsubmit = formBlocker;
}
