/*
 * Preload load indicator images
 */

new Asset.image('/phproad/resources/images/form_load_70x70.gif');

/*
 * Define admin-wide load indicator and AJAX request defaults
 */

Element.implement({
	getLoadingIndicatorDefaults: function()
	{
		return {
			overlayClass: 'formOverlay',
			pos_x: 'center',
			pos_y: 'center',
			src: '/phproad/resources/images/form_load_70x70.gif',
			injectInElement: false,
			noImage: false,
			z_index: 9999,
			absolutePosition: true,
			injectPosition: 'bottom',
			hideElement: true
		};
	}
});

Request.Phpr.implement({
	getRequestDefaults: function()
	{
		return {
			loadIndicator: {
				element: 'FormElement',
				show: true,
				hideOnSuccess: false
			},
			onFailure: Browser.Engine.trident ? this.popupError.bind(this) : this.highlightError.bind(this),
			errorHighlight: {
				backgroundFromColor: '#f00',
				backgroundToColor: '#ffffcc'
			},
			onAfterError: this.highlightFormError.bind(this)
		};
	},
	
	highlightFormError: function()
	{
		$(document.body).getElements('ul.formElements li.field').each(function(el){
			el.removeClass('error');
		});
		
		var el = $(window.phprErrorField);
		if (!el)
			return;

		var parentLi = el.getParent('li.field');
		if (parentLi)
			parentLi.addClass('error');
	}
});
