<!--

//--- INTERFACE ----------------------------------------------------------------

var defaultLightOnUserSubmenu = new Array();

function echo(str, flag){
	if(flag)
		$('debug_echo').update($('debug_echo').innerHTML + "\n" + str);
	else
		$('debug_echo').update(str);
}

function showMessageBoxes(){
	if($('error_messages') && !$('error_messages').innerHTML.blank()){
		$('error_messages').up().style.display = 'block';
		$('error_messages').style.display = 'block';
	}

	if($('success_messages') && !$('success_messages').innerHTML.blank()){
		$('success_messages').up().style.display = 'block';
		$('success_messages').style.display = 'block';
	}
}

function showMessage(str, flag){
	if(str.blank()){
		$('success_messages').update('');
		$('success_messages').hide().up().hide();
		$('error_messages').update('');
		$('error_messages').hide().up().hide();
	}
	else{
	    $(flag ? 'success_messages' : 'error_messages').update(str);
		showMessageBoxes();
	}
}

function lightOnUserSubmenu(){
	defaultLightOnUserSubmenu.uniq().each(function(id){
		if($(id)){
			$(id).addClassName('menu_light_on');
		}
	});
}

function resizeImages(){
	var images = $(document.body).select('[rel="resize_image"]');
	images.each(function(el){
		el.observe('load', function(e){
			var img = Event.element(e);
			var max = new Object();

			max.w = img.readAttribute('maxwidth');
			max.h = img.readAttribute('maxheight');

			if(img.width > max.w || img.height > max.h){
				var new_h = max.h;
				var new_w = Math.floor(new_h * img.width / img.height);

				if (new_w > max.w){
					new_w = max.w;
					new_h = Math.floor(new_w * img.height / img.width);
				}
			img.width = new_w;
			img.height = new_h;
			}
		});
	});
}

Event.observe($(document), 'dom:loaded', function(e){
	showMessageBoxes();
	lightOnUserSubmenu();
	//resizeImages();
	if(typeof toolbarBonuceUpdate != 'undefined')
		toolbarBonuceUpdate();
});

//------------------------------------------------------------------------------

function textareaLimit(obj, limit, output){
	var len = obj.value.length;
	if(len >= limit){
		obj.value = obj.value.substr(0, limit);
		$(output).update(limit - obj.value.length);
	}
	else{
		$(output).update(limit - len);
	}
	$(obj.form).observe('reset', function(){
		$(output).update(limit);
	});
}

var ajax_loader_bar = new Image(); ajax_loader_bar.src = '/template/base/images/ajax/loader_bar.gif';
function ajaxLoaderBar(visible){
	var tpl = '<div id="ajax_loader"><div class="content"><div class="img"><img src="/template/base/images/ajax/loader_bar.gif" width="220" height="19" border="0"></div><div class="text">подождите...</div></div></div>';
	if(visible == true){
		var body = $$('body');
		if(body && body.length > 0)
			new Insertion.Bottom(body[0], tpl);
	}
	else{
		if($('ajax_loader'))
			$('ajax_loader').remove();
	}
	return false;
}

function confirmAdminAction(flag){
	switch(flag){
		case 0:
			return confirm('Удалить контент?');
			break;
		case 1:
			return confirm('Изменить контент?');
			break;
	}
}

function modal_window_show(flag, w, h, content){
	var template = '<div id="modal_container" style="display: none;"><div id="modal_shadow"><div id="modal_window"></div></div></div>';
	var loader = new Template('<div align="center" style="position: relative; height: 40px; top: #{styleTop};"><img src="/template/base/images/modal/loader.gif" width="24" height="24" border="0"><br>загружается...</div>.');

	if(flag === true){
		$$('body')[0].style.background_attachment = 'fixed';
		$$('iframe').invoke('hide');
		$$('select').invoke('hide');
		if($('modal_window') == null && parseInt(w) > 0 && parseInt(h) > 0){
			new Insertion.Top($$('body')[0], template);
			$('modal_window').setStyle({width: w + 'px', height: h + 'px'});
			$('modal_container').show();
		}
		if($('modal_window') && typeof content == 'string' && content.length){
			$('modal_window').update(content);
		}
		else if($('modal_window')){
			var loaderParams = { styleTop: ((h - 40) / 2 ) + 'px' };
			$('modal_window').update(loader.evaluate(loaderParams));
		}
		else{
			alert('modal window not exists!');
		}
		return true;
	}
	else if(flag === false && $('modal_container')){
		if($('modal_container'))
			$('modal_container').remove();
		$$('select').invoke('show');
		$$('iframe').invoke('show');
		$$('body')[0].style.background_attachment = 'scroll';
		return true;
	}
	else{
		return false;
	}
}

//--- SYSTEM -------------------------------------------------------------------

function inputRadioValue(obj){
	for(var i = 0; i < obj.length; i++)
		if(obj[i].checked)
			return obj[i].value;
	return null;
}

//-->
