$(document).ready(function () {
	var dialog = $('.dialog').dialog({
		autoOpen: false,
		draggable: false,
		minWidht: 200,
		modal: true,
		resizable: false
	});
	$('#queries.dialog').dialog('option', 'width', 800).dialog('option', 'height', 500);
	
	if ($.cookie('toggleStats') == null) {
		$.cookie('toggleStats', 'block', {expires: 365});
	}
	$('div#statBox').css('display', $.cookie('toggleStats'));
	$('a.toggle').click(toggleStats);
	$('.help').click(function () {
		var id = $(this).attr('id');
		$.getJSON('/json/getHelp/'+id, function (data) {
			$('#help.dialog').dialog('option', 'title', data.Title).dialog('open').html(data.Value);
		});
		return(false);
	});

	$('.queries').click(function () {
		$('#queries.dialog').dialog('open');
	});

	$(':input[id!=]').each(highlight);
});

function highlight()
{
	var id = $(this).attr('id');
		
	$(this).focus(function () {
		$(this).parent('#'+id+'Field').css('background-color', '#ffc');
		$('span#'+id+'Note').fadeIn('slow');
	});
	$(this).blur(function () {
		$(this).parent().css('background-color', 'inherit');
		$('span#'+id+'Note').fadeOut('fast');
	});
}

function toggleStats()
{
	if ($('div#statBox').css('display') == 'none') {
		$.cookie('toggleStats', 'block', {expires: 365});
		$('div#statBox').show('blind', {}, 500);
	} else {
		$.cookie('toggleStats', 'none', {expires: 365});
		$('div#statBox').hide('blind', {}, 500);
	}
	return false;
}
