$(function() {

	// highlight layout, for debug purpose only
	/*
	var hcss = {'border':'1px solid red'};
	$('#header').css(hcss);
	$('#left').css(hcss);
	$('#right').css(hcss);
	$('#footer').css(hcss);
	*/
	
	// build accordion menu
	/*
	$("#menu").accordion({
		header: "h3"
	});
	*/
	
	 function findValue(li) {
		 if( li == null ) return alert("No match!");
		 // if coming from an AJAX call, let's use the CityId as the value
		 if( !!li.extra ) var sValue = li.extra[0];
		 // otherwise, let's just display the value in the text box
		 else var sValue = li.selectValue;
		 //alert("The value you selected was: " + sValue);
	}

	 function selectItem(li) {
		 findValue(li);
	 }

	 function formatItem(row) {
		 return row[0] + " (id: " + row[1] + ")";
	 }

	 function lookupAjax(fieldName){
		 var oSuggest = $(fieldName)[0].autocompleter;
		 oSuggest.findValue();
		 return false;
	 }
	
	// apply style to all form elements
 	
	$('input[type="submit"]').addClass('submit');
	$('input[type="submit"]').hover(function(){$(this).addClass('submithover');},function(){$(this).removeClass('submithover');});
	
	$('select').addClass('input');
	$('select').focus(function(){$(this).addClass('inputhover');});
	$('select').blur(function(){$(this).removeClass('inputhover');});
	
	$('textarea').addClass('input');
	$('textarea').focus(function(){$(this).addClass('inputhover');});
	$('textarea').blur(function(){$(this).removeClass('inputhover');});
	
	$('input[type="text"]').addClass('input');
	$('input[type="text"]').focus(function(){$(this).addClass('inputhover');});
	$('input[type="text"]').blur(function(){$(this).removeClass('inputhover');});
	
	$('input[type="password"]').addClass('input');
	$('input[type="password"]').focus(function(){$(this).addClass('inputhover');});
	$('input[type="password"]').blur(function(){$(this).removeClass('inputhover');});
	
	$('input[type="checkbox"]').addClass('input');
	$('input[type="checkbox"]').focus(function(){$(this).addClass('inputhover');});
	$('input[type="checkbox"]').blur(function(){$(this).removeClass('inputhover');});
	
	$('input[type="radio"]').addClass('input');
	$('input[type="radio"]').focus(function(){$(this).addClass('inputhover');});
	$('input[type="radio"]').blur(function(){$(this).removeClass('inputhover');});
	
	// automatic adjustment right box
	/*
	$("#right").css({'width': ($(document).width()-270) +'px'})
	$(window).resize(function(){
		$("#right").css({'width': ($(document).width()-270) +'px'})
	});
	*/
	
	// set focus on first input element
	$("input:first").focus();
	
	// configure all input tooltip
	//$("input").tooltip();

	// setup datepicker widget
	/*
	$('input.datepicker').datepicker({
		dateFormat: 'dd/mm/yy',
		firstDay: 1,
		monthNames: ['Gennaio','Febbraio','Marzo', 'Aprile','Maggio','Giugno','Luglio','Agosto', 'Settembre','Ottobre','Novembre','Dicembre'],
		dayNamesMin: ['Do', 'Lu', 'Ma', 'Me', 'Gi', 'Ve', 'Sa']
	});
	*/
	
	$("#datepickerFrom").datepicker({
		dateFormat: 'dd/mm/yy'
	});
	
	$("#datepickerTo").datepicker({
		dateFormat: 'dd/mm/yy'
	});
	
	$("#datepickerSchedule").datepicker({
		dateFormat: 'dd/mm/yy'
	});
	
	$("#resizable").resizable(
		{
			minWidth: 520,
			minHeight: 170,
			maxWidth: 520,
			maxHeight: 800
		}
	);
});