function attivaHasOne(el){
	div_id=$('label[for='+$(el).attr('id')+']').text().replace(' ','');

	if($(el).is(':checked'))
		$('.'+div_id).slideDown();
	else
		$('.'+div_id).slideUp();
}


$(function() {
	$(".editable").editableWbw();
	
	$('.imgClose').click(function(){
		$(this).parents('.divForm').animate({opacity: 'toggle', height: 'toggle'});
	});
/*
	$('#menuSx').accordion({ 
		header: 'div.loghiWebware', 
		active: false, 
		alwaysOpen: false, 
		autoHeight: false 
	});
*/	

	$('#menuSx').bind('accordionchange', function(event, ui) {
		$('.jColumn').equalizeCols(140);
	});
/****   Attiva il nome della sezione   *****/
	$("a[href$='/"+controller+"']").parent().addClass('attivo');
/*******************************************/
	

	$('.sezioni:not(.attivo) img').mouseover(function(){
		$(this).attr('src',$(this).attr('src').replace('.gif','_on.gif'));
	}).mouseout(function(){
		$(this).attr('src',$(this).attr('src').replace('_on.gif','.gif'));
	});

	if($('.sezioni.attivo img').length>0)
		$('.sezioni.attivo img').attr('src',$('.sezioni.attivo img').attr('src').replace('.gif','_on.gif'));
	
	$('body').fontSize();


//	$(".elenco>tbody>tr:even").addClass('sfondoBianco');
//	$(".elenco>tbody>tr:odd").addClass('sfondoColore');

//	$('body').fontSize();
	
	
	$('#ricercaTrigger').click(function(){
		$('#searchBlock').animate({opacity: 'toggle', height: 'toggle'});
	});
/*
	$('#helpTrigger').click(function(){
		if($(".help").html()==''){
			$(".help").html('<img src="'+DIR+'img/indicator.gif">');
			
			$.getJSON(
				DIR+'helps/row_ajax',
				{controller:controller},
				helpCallback
			);
		}
			
		function helpCallback(data){
 			$(".help").html(data.testo);
		}
	
		$('#helpBlock').animate({opacity: 'toggle', height: 'toggle'});
	});
*/	
//	$('#aggiungiTrigger').formAjaxWbw();	
/*
/*
	$('.schedaRow').formAjaxWbw();	
	$('.editRow').formAjaxWbw();	
	$('.deleteRow').formAjaxWbw();	
	$('.previewRow').formAjaxWbw();	
*/
//	$('a[class$=Row]').formAjaxWbw();	

	if(!($.browser.msie && $.browser.version<7)){
		$('a[class$=Row]').nyroModal({
	//		debug: true,
			minWidth: 800,
			minHeight: 551,
			bgColor: '#FFFFFF',
			css: {
				content: {
					overflow: 'hidden'
				}
			}
		});
	}
//	$('#noDelete').click(function(){
//		$('#editBlock').animate({opacity: 'toggle', height: 'toggle'});
//	});
	
//	$('.jColumn').equalizeCols();
	
//	$('#TagNome').tagAjax();
//	$('#TagNome').autocompleteWbw({add:1});
	
	/***  Edit  ***/	

	$("input[name*='data_']").datepicker(
		$.extend(
			{}, 
			$.datepicker.regional["it"],
			{
				dateFormat: "dd/mm/yy",
				showStatus: true, 
				showOn: "both",
				showAnim: "fadeIn",
				buttonImage: DIR+"img/calendar.gif",
				buttonImageOnly: true,
				showButtonPanel: true,
				changeMonth: true,
				changeYear: true
			}
		)
	).addClass('embed');
	
	$("input[name*='data_di_nascita']").datepicker("destroy");
	
	$("input[name*='data_di_nascita']").datepicker(
		$.extend(
			{}, 
			$.datepicker.regional["it"],
			{
				dateFormat: "dd/mm/yy",
				showStatus: true, 
				showOn: "both",
				showAnim: "fadeIn",
				buttonImage: DIR+"img/calendar.gif",
				buttonImageOnly: true,
				showButtonPanel: true,
				changeMonth: true,
				changeYear: true,
				minDate: new Date(1985,0,1),
				maxDate: new Date(2000,0,1)
			}
		)
	).addClass('embed');
	/**************/
	
	/***  hasOne  ***/
/*
	$('.hasOne').hide();
	
	$('.hasOneSelect input:checkbox').each(function(){
		attivaHasOne(this);
			
		$(this).click(function(){
			attivaHasOne(this);	
		});
	});
*/
	/****************/
	
	/***  hasMany  ***/
/*
	$('.hasManyAdd').hasManyAdd();
	$('.hasManyDelete').hasManyDelete();
*/
	/*****************/

/*	
	$('.imgPrint').click(function(){
		$('#menuSxColonna').css('display','none');
		$('#header').css('display','none');
		$('#footer').css('display','none');

		$('.cake-sql-log').css('display','none');
		
		$('.divForm .bloccoAlto').css('display','none');
		$('.divForm .bloccoBasso').css('display','none');
		
		$('#contenuto').css('margin','0');
		$('.scheda').css('margin','0');
		$('.schedaTitolo').css('color','#000000');
		$('.schedaCampo').css('border','none');
		
		$('.imgPrint').css('display','none');
		$('.imgClose').css('top','0');

		$('.imgClose').unbind('click');
		$('.imgClose').click(function(){
			$('#menuSxColonna').css('display','block');
			$('#header').css('display','block');
			$('#footer').css('display','block');

			$('.cake-sql-log').css('display','block');
			
			$('.divForm .bloccoAlto').css('display','block');
			$('.divForm .bloccoBasso').css('display','block');
			
			$('#contenuto').css('margin','0 20px 0 210px');
			$('.scheda').css('margin','-27px 0 0 0');
			$('.schedaTitolo').css('color','#FFFFFF');
			$('.schedaCampo').css('border-left','1px solid #FF9933');
			$('.schedaCampo').css('border-right','1px solid #FF9933');
			
			$('.imgPrint').css('display','block');
			$('.imgClose').css('top','-28px');
		});
	});
*/
});

