window.addEvent('domready', function() {
	/**
	 * window size
	 *
	var size = $('container').getSize();
	var sizey = size.y - 251;
	$('main').setStyles({
		'height': sizey,
		'min-height': sizey
	});
	*/
	/**
	 * Fields
	 */
	var inputs = $$('input');
	inputs.addEvent('focus', function(){
		if(this.value == this.defaultValue && this.get('type') == 'text'){
			this.set('value', '');
		}
	});
	
    /**
     * Menu effect
     */
	var menu_item = $$('ul#menu li');
	if(menu_item){
		menu_item.addEvents({
			'mouseenter': function(){
				this.setStyle('padding-top', '0');
			},
			'mouseleave': function(){
				this.setStyle('padding-top', '5px');
			}
		}); 
	}
	
	/**
	 * Right menu
	 */
	var togglers = $$('.toggler');
	if(togglers){		
		var myAccordion = new Accordion(togglers, $$('.element'), {
			show: left_menu,
			opacity: false,
			onActive: function(toggler, element){
				toggler.getChildren('span').setStyle('background', 'url('+path+'/template/images/bg_menu2_arrow3.png) no-repeat');
			},
			onBackground: function(toggler, element){
				toggler.getChildren('span').setStyle('background', 'url('+path+'/template/images/bg_menu2_arrow2.png) no-repeat');
			}
		});
	}
	
	/**
	 * Anketa
	 */
	var parentx = $$('.anketa');
	if(parentx && $('anketa_send') && $('anketa_results')){
		var options = $$('.anketa_option');
		options.addEvent('click', function(){
			options.each(function(item){
				item.store('selected', 0);
				item.getChildren('img').set('src', path+'/template/images/radio_off.gif');
			});
			this.store('selected', 1);
			this.getChildren('img').set('src', path+'/template/images/radio_on.gif');
		});
		$('anketa_send').addEvent('click', function(){
			options.each(function(item){
				if(item.retrieve('selected') == 1){
					var tmpId = item.get('id');
					tmpId = ''+tmpId.slice(14);
					var parID = ''+parentx.get('id'); var parID = parID.slice(7);
					parentx.load(path+'/sys/anketa?action=save&id='+parID+'&option='+tmpId);
					var size = $('container').getSize();
					var sizey = size.y - 251;
					$('main').setStyles({
						//'min-height': sizey,
						//'height': sizey
						
					});
				}
			});
		});
		$('anketa_results').addEvent('click', function(){
			var parID = ''+parentx.get('id'); var parID = parID.slice(7);
			parentx.load(path+'/sys/anketa?action=results&id='+parID);
			var size = $('container').getSize();
			var sizey = size.y - 251;
			$('main').setStyles({
				'height': sizey,
				'min-height': sizey
			});
		});
	}
});

function PopupPrint() { 
	window.open(window.location.pathname+"?action=print", "_new", "status=no, scrollbars=yes, menubar=no, height=600, width=850"); 
} 
