function complete_update_db() {
	// $('div_ajax_status').fireEvent('burn', '', '');
	// alert('completed!');
}

function update_db(pTable, pRow, pColumn, pValue) {
	// alert('in update_db');
	new Ajax('_inc/update_db.php', {
		method: 'post',
		data: { p_table: pTable, p_row: pRow, p_column: pColumn, p_value: pValue },
		update: 'div_ajax_status',
		evalScripts: false,
		onComplete: function() { complete_update_db(); }
	}).request();
}

function adjust_dyn_inputs() {
	$$('.dyn_input').each(function(element) {
		setInputSize(element);
	});
}

function setInputSize(o) {
	var t_ruler = $('ruler');

	t_ruler.setStyle('fontFamily', o.getStyle('fontFamily'));
	t_ruler.setStyle('fontSize', o.getStyle('fontSize'));
	t_ruler.innerHTML = o.value + 'M';
	
	o.setStyle('width', Number(t_ruler.offsetWidth) + 'px');	
	t_ruler.innerHTML = ''; // emptying it again prevents it from taking up space on the page
}

function complete_privs() {
	if ($('div_nav')) {
		new Request.HTML({  
			method: 'post',  
			url: '_inc/nav_body.php',  
			update: $('div_nav')
		}).send();
		/*	
		new Ajax('_inc/nav_body.php',
			{	method: 'post',
				update: 'div_nav',
				onComplete: function() {  },
				data: {  }
			}).request();
		*/
	}
	if ($('form_login')) {
		$('form_login').addEvent('submit', function(e) {
			e.stop();
			// Empty the log and show the spinning indicator.
			// var log = $('log_res').empty().addClass('ajax-loading');
			// Set the options of the form's Request handler. 
			// ("this" refers to the $('myForm') element).
			this.set(
				'send', {
					onComplete:
					function(response) {
						complete_privs(); // in case the username and password are not correct
						// log.removeClass('ajax-loading');
						// log.set('html', response);
					}
				}
			);
			//Send the form.
			this.send();
		});
		/*
		$('form_login').addEvent('submit', function(e) {
			new Event(e).stop(); // Prevent the submit event
			this.send({
				update: 'div_privs',
				onComplete: function() {
					complete_privs(); // in case the username and password are not correct
				}
			});
		});
		*/
	}
	if ($('logoutX')) {
		$('logout').addEvent('click', function(e) {
			e = new Event(e).stop();
			window.location.href='?p=home'; // send the user to the home page so that we leave any private page
			new Request.HTML({  
				method: 'post',  
				url: '_inc/privs.php',  
				update: $('div_privs'),  
				onComplete: function() { complete_privs(); },
				data: { f: 'logout' }
			}).send();
			/*
			new Ajax('_inc/privs.php',
				{	method: 'post',
					update: 'div_privs',
					onComplete: function() { complete_privs(); },
					data: { f: 'logout' }
				}).request();
			*/
		});
	}
}