// JavaScript Document

$(document).ready(function() {
	/**/
	$('#food-name').autocomplete({
		source: '_list_foods.php',
		minLength: 2,
		select: function(event, ui) {
			$('#food-name').val(ui.item.value);
			$('#food-name-submit').click();
			//document.location.href = '/food.php?food=' + escape(ui.item.value);
		}
	});
	/**/
	$('input[type="submit"], input[type="button"], button').button();
	/**/
	$('.carb-click').each(function() {
		$(this).attr('title', 'Click for Carbonite script');
	}).click(function() {
		var node = $(this).data('node-name');
		var zone = $(this).data('zone-name');
		var reply = prompt('Copy the following text (ctrl-C) and paste (ctrl-V) into World of Warcraft (with Carbonite installed) to add these coordinates as a targetable Note on the map:', '/carb note "' + node + '" "' + zone + '" ' + $(this).html().replace(',', ''));
	});
	/**/
	$('.popup-click').click(function() {
		alert($(this).data('message'));
	});
	/**/
	$('#buttonset').buttonset();
	/**/
	$('#logout-button').click(function(e) {
		e.preventDefault();
		jConfirm('Are you sure you want to log out?', 'YOU SURE?', function(reply) {
			if (reply) {
				window.location = '/logout.php';
			}
		});
	});
	/**/
});

// Override that incredibly stupid feature in Chrome where autofill fields have
//   an unchangeable background color of light yellow. WTF were they thinking?!
if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) {
	$(window).load(function() {
		$('input:-webkit-autofill').each(function() {
			var text = $(this).val();
			var name = $(this).attr('name');
			$(this).after(this.outerHTML).remove();
			$('input[name=' + name + ']').val(text);
		});
	});
}

function lowerCase(str)
{
	return str.toLowerCase();
}

function setupLoginValidation()
{
	$('.validity-summary-container, .validity-summary-reg-container')
		.hide();
	$.validity.setup({
		outputMode: 'summary'
	});
}

function setupRegistrationValidation()
{
	$('.validity-summary-container, .validity-summary-reg-container')
		.hide();
	$.validity.setup({
		outputMode: 'summaryreg'
	});
}

function writeEmail()
{
	document.write(String.fromCharCode(99, 111, 110, 116, 97, 99, 116, 64, 119, 111, 119, 103, 101, 101, 107, 115, 46, 99, 111, 109));
}

