// Create a reference to the S.A.C.K. (Simple AJAX Component Kit) object.
var ajax = new sack();

function slientSubmit(url) {
	//alert(url); return false;
	
	if(ajax && document.getElementById && typeof(url)!='undefined') {
		// If the client supports "silent submissions" preform the action.
		return preformAction(url);
	} else {
		// Otherwise let the server to do all the work.
		return true;
	}
}

function preformAction(url) {
	// Separate the State from the URL.
	var state = url.replace(/(.)+\?(..)$/, '$2');
	var url   = url.replace('?'+state, '');
	
	// Set values to be passed.
	ajax.setVar('silent', '1');
	ajax.setVar('state', state);
	
	// Setup the request.
	ajax.requestFile = url;
	ajax.method = 'get';
	
	// Debugging settings.
	//ajax.requestFile = '/libraries/debug.asp';
	//ajax.element = 'debug-message';	
	
	// Define the function to call when the response is received.
	ajax.onCompletion = function() {
		// When a URL is returned, redirect the user.
		if (ajax.response.substring(0,4)=='url=') {
			document.location.href = ajax.response.substring(4);
		} else {
			// Otherwise display the message returned by the script.
			replaceInlineContent('notificationbox', ajax.response);
		}
	}
	
	// Execute the request.
	ajax.runAJAX();
	
	// If everything completed, cancel the old-school form submission action. ;)
	return false;
}

function replaceInlineContent(id, msg) {
	// Insert the message into the specified content block and unhide it.
	document.getElementById(id).innerHTML = msg;
	document.getElementById(id).style.display = 'block';
}