auctiontools = {

	salt: '1273461100373',
	administrator: undefined,

	invalidField: function(message,field)
	{
		alert(message);
		$('#'+field).val('');
		$('#'+field).focus();
	},
	
	muddlePassword: function()
	{
		var element = $('#password');
		var codeText = element.val();
		codeText = hex_hmac_sha1(this.salt,codeText);
		$('#password').val(codeText);
	},
	
	muddleLoginCode: function()
	{
		var element = $('#logincode');
		var codeText = element.val();
		codeText = hex_hmac_sha1(this.salt,codeText);
		$('#logincode').val(codeText);
	},
	
	showRegisterForm: function()
	{
		$('#registration').show();
		$('#loginform').hide();
		$('#resetform').hide();
	},
	
	showLoginForm: function()
	{
		$('#registration').hide();
		$('#loginform').show();
		$('#resetform').hide();
	},
	
	showResetForm: function()
	{
		$('#registration').hide();
		$('#loginform').hide();
		$('#resetform').show();
	},	
	
	passwordResetMessage: function()
	{
		alert("Your password has been reset. You will receive an email message in a short while.\n\nIf you don't see the message in a few minutes\nplease check your junk folder for a Message from Christ the King Auction.");
		$('#username').val($('#emailaddress').val());
		auctiontools.showLoginForm();
	},
	
	noRegistration: function(email)
	{
		if (confirm("I'm sorry. We do not have your email address in our system.\n\nPress OK to go to registration, or\n\n Cancel to try again."))
		{
			this.showRegisterForm();
			$('#email').val(email);
			$('#first').val('');
			$('#first').focus();
		}else
		{
			$('#logincode').val('');
			$('#username').focus();
		}
	},
	
	loginError: function()
	{
		alert("I'm sorry. We were not able to log you in. Please try again.");
		$('#logincode').val('');
		$('#username').focus();
	},
	
	acknowledgeUser: function(name,admin){
		$('#tab-login').html('Welcome ' + name);
		$('#tab-login').addClass('loggedin');
		$('#tab-logout').show();
		$('#tab-history').show();
		this.showProjects();
		$('#tab-login').click(function() {return false;});
		if (admin == 1)
		{
			$('#tab-scoreboard').show();
		} else
		{
			$('#tab-scoreboard').hide();
		}
	},
	
	showLogin: function()
	{
		var element = $('#tab-login');
		if (!element.hasClass('loggedin'))
		{
			this.disablePanes();
			$('#pane-login').show();
			$('#tab-logout').hide();
			$('#tab-history').hide();
			$('#tab-scoreboard').hide();
			$('#tab-logout').click(function(){auctiontools.logoff() });
			element.click(function(){ auctiontools.showLogin() });
			element.html('Log In / Register');
			element.addClass('current');
			this.showLoginForm();
		}
	},
	
	displayProject: function()
	{
		var currentid = $('#currentproject').val();
		$('#projectinfo').load('display/item_info.cfm',{itemid:currentid});
	},
	
	logoff: function()
	{
		$.ajax({url: 'process/clearSession.cfm'});
		$('#tab-login').removeClass('loggedin');
		$('#username').val('');
		$('#logincode').val('');
		document.getElementById('form_registration').reset();
		this.showLogin();
		$('#username').focus();
	},
	
	showProjects: function()
	{
		var element = $('#tab-projects');
		this.disablePanes();
		$('#pane-projects').show();
		element.addClass('current');
		this.displayProject();
	},
	
	showHistory: function()
	{
		var element = $('#tab-history');
		$('#pane-history').load(element.attr("href"));
		this.disablePanes();
		$('#pane-history').show();
		element.addClass('current');
	},
	
	showScoreboard: function()
	{
		var element = $('#tab-scoreboard');
		$('#pane-scoreboard').load(element.attr("href"));
		this.disablePanes();
		$('#pane-scoreboard').show();
		element.addClass('current');
	},		
	
	showResults: function()
	{
		var element = $('#tab-results');
		$('#pane-results').load(element.attr("href"));
		this.disablePanes();
		$('#pane-results').show();
		element.addClass('current');
	},
	
	showRules: function()
	{
		var element = $('#tab-rules');
		$('#pane-rules').load(element.attr("href"));
		this.disablePanes();
		$('#pane-rules').show();
		element.addClass('current');
	},		
	
	disablePanes: function()
	{
		$('#tab-login').removeClass('current');
		$('#pane-login').hide();
		$('#tab-projects').removeClass('current');
		$('#pane-projects').hide();
		$('#tab-history').removeClass('current');
		$('#pane-history').hide();
		$('#tab-rules').removeClass('current');
		$('#pane-rules').hide();
		$('#tab-scoreboard').removeClass('current');
		$('#pane-scoreboard').hide();
		$('#tab-results').removeClass('current');
		$('#pane-results').hide();
	},
	
	confirmBid: function(location,bidprice,itemid, url)
	{
		if (confirm("You have chosen to bid $" + bidprice + " for this item.\nPress OK to verify your intentions"))
		{
			if (location == 'item')
			{
				$('#projectinfo').load(url,{itemid:itemid,price:bidprice,location:location});
			} else
			{
				$('#pane-history').load(url,{itemid:itemid,price:bidprice,location:location});
			}
		}
	},
	
	displayFull: function(filename)
	{
		$('#pictureholder').html('<img src="' + filename + '" />');
		$('#pictureholder').dialog({modal: true, title: 'Full Size Image', height: 675, width: 785, close: function() {}, buttons: {"Close": function() {$(this).dialog("close");}}});

	},

}

