/**
* @fileoverview This file contains the static help object.
* @author Sara Lin
* @version 0.1
*/

/**
Footer is a loosely formed namespace that contains functions for loading tabs from links on the footer.
* @namespace
*/
var Footer = {
	/**
	* closes all the tabs
	* @event
	*/
	close: function(event) {
		var elt = Event.element(event).ancestors()[2];
		Effect.BlindUp(elt);
	},

	/** loads the search tab */
	search: function() {
		var tab = Main.tabs.showTab('search');
	},
	
	/** loads help tab */
	help: function() {
		Help.load();
	},
	
	/** loads the about tab */
	about: function() {
		var tab = Main.tabs.showTab('about');
		new Ajax.Request(base_url+'footer/showAbout', {
			onSuccess: function(response) {
				tab.tabElem.innerHTML = response.responseText;
			}
		});
	},
	
	/** loads the feedback form.  Attach event handler to the submit button to sent the form to server, if status message exists, show the message.  */
	feedback: function() {
		var tab = Main.tabs.showTab('feedback');
		new Ajax.Request(base_url+'footer/showFeedbackForm', {
				onSuccess: function(response) {
					tab.tabElem.innerHTML = response.responseText;
					var statusMsg = $$('#feedback .errorMsg')[0];
					statusMsg = $(statusMsg);
					Event.observe('feedback', "submit", function() {
						new Ajax.Request(base_url+'footer/sendEmail', {
							method: 'post',
							parameters: $('feedback').serialize(true),
							onSuccess: function(response){
								statusMsg.innerHTML = response.responseText;
								if(response.responseText.match('sent')){
									$('contaname').value="";
									$('contaemail').value="";
									$('contacomments').value="";
									statusMsg.className = "status";
								} else {
									statusMsg.className = "errorMsg";
								}
								statusMsg.show();
							}
						});
					});
				}
			});
	}
}