window.addEvent('domready', function(){
		UIloadInterface();
		if($("finance_calc_form_button")) {
			$("finance_calc_form_button").click();
		}
	});

	function UIloadInterface() {
		// FUNCTION TO LOAD THE INTERFACE COMPONENTS
		ajaxforms = new AjaxForms();
		ajaxlinks = new AjaxLinks();
	}

// AjaxForms

	// All forms with class 'ui-ajaxform' are submitted via AJAX and
	// the AJAX response is placed in the element with the ID that
	// is specified in the target attribute of the form.

	var AjaxForms = new Class({
		initialize: function(){
			// Initialize Events
			$$("form.ui-ajaxform").removeEvents('submit');
			$$("form.ui-ajaxform").addEvent('submit',this.submitform.bind(this));
		},
		submitform: function(event){

			var form = event.target;

			// Stop the form form submitting...
			event.preventDefault();
			event.stop();

			// If a user hits return in a text field, the text field is the target!
			while (form.nodeName != "FORM") { form = $(form).parentNode; }

			// Check if validation is required
			if (form.validate) {
				response = form.validate();
				if (response != true) {
					if (response != false) alert(response);
					return false;
				}
			}

			// Check if confirmation is required
			confirmation = form.getProperty('confirmation');
			if (confirmation && confirmation != "") {
				if (!confirm(confirmation)) return false;
			}

			// Figure out where the response is going (if anywhere)...
			var target_id = form.getProperty('target');
			if (target_id != "") {
				var target = $$("#"+target_id);
				target.addClass("ui-loading");
				target.fireEvent("ui-loading");
			}

			// GRAB THE FORM URL..
			url = form.get('action');

			// CONVERT THE FORM TO A QUERY...
			var querystring = form.toQueryString();

			// TURN THE QUERY STRING IN TO AN OBJECT..
			//query = querystring.parseQueryString();

			// Fire off ajax request...
			if (form.req) form.req.cancel();

			form.req = new Request.HTML({
				'url':url,
				'method':'post',
				'data':querystring,
				'evalScripts':true,
				'onComplete':function(){
					if (target_id != "") {
						// Put content in destination text...
						target.set('html',this.response.text);
						target.removeClass("ui-loading");
						target.fireEvent("ui-complete-pre-interface"); // Use this event to put things in place before the interface loads
						UIloadInterface();
						target.fireEvent("ui-complete"); // Use this event to do things after the interface loads
					}
				},
				'onFailure': function(){
					if (target_id != "") {
						// Put content in destination text...
						target.setHTML("<p class=\"ui-error\">Ajax Request Failed</p>");
						target.removeClass("ui-loading");
					}
				}

			});

			form.req.send();

			return false;

		}
	});













	// AjaxLinks

	// All links with class 'ui-ajaxlink' are submitted via AJAX and
	// the AJAX response is placed in the element with the ID that
	// is specified in the target attribute of the link.

	var AjaxLinks = new Class({
		initialize: function(){
			// Initialize Events
			$$(".ui-ajaxlink").removeEvents('click');
			$$(".ui-ajaxlink").addEvent('click',this.submitlink.bind(this));
		},
		submitlink: function(event){

			var link = $(event.target);

			if (link.tagName != "A") {
				while (!link.hasClass('ui-ajaxlink') && link.tagName != 'HTML') {
					link = $(link).getParent();
				}
			}

			url = $(link).getProperty("href");
			url = url.match(/^[^?]*/);
			url = url.toString();

			querystring = $(link).getProperty("href");
			querystring = $(link).getProperty("href");
			querystring = querystring.match(/[^?]*$/);
			querystring = querystring.toString();
			query = querystring.parseQueryString();

			// Stop the link from clicking...
			event.preventDefault();
			event.stop();

			// Check if confirmation is required
			confirmation = link.getProperty('confirmation');
			if (confirmation && confirmation != "") {
				if (!confirm(confirmation)) return false;
			}

			// Figure out where the response is going (if anywhere)...
			var target_id = link.getProperty('target');
			if (target_id != "") {
				var target = $$("#"+target_id);
				target.addClass("ui-loading");
				target.fireEvent("ui-loading");
			}

			// Fire off ajax request...
			var req = new Request.HTML({
				'url':url,
				'method':'post',
				'data':query,
				'evalScripts':true,
				'onComplete':function(){
					if (target_id != "") {
						// Put content in destination text...
						target.set('html',this.response.text);
						target.removeClass("ui-loading");
						target.fireEvent("ui-complete-pre-interface"); // Use this event to put things in place before the interface loads
						UIloadInterface();
						target.fireEvent("ui-complete"); // Use this event to do things after the interface loads
					}
				},
				'onFailure': function(){
					if (target_id != "") {
						// Put content in destination text...
						target.setHTML("<p class=\"ui-error\">Ajax Request Failed</p>");
						target.removeClass("ui-loading");
					}
				}

			});

			req.send();

			// Don't let the link click!
			return false;
		}
	});
