if(typeof parkside == "undefined") var parkside = new Object();
if(typeof parkside.form == "undefined") parkside.form = new Object();

// Constructor
parkside.form = function(form_name, form_action) {
	this.form_name = form_name;
	this.form_action = form_action;
	this.$form = $("form[name=" + form_name + "]");
	this.$validation_tooltip=this.$form.find(".form-validation-tooltip");
	this.tooltip_timeout = "";
	
	var self = this;
			
	this.validateForm = function()
	{	
		var $form = this.$form;
		$form.validate();  
		
		window.clearTimeout(this.tooltip_timeout);
		if($form.valid()) 
		{		
			/*this.$validation_tooltip.hide();*/
			
			$form.find(".submit-button").stop().animate({opacity : "hide"}, 0, function() {
				var $loader = $('<img class="ajax-loader" src="images/form/ajax-loader.gif" alt="Loading" />');
				$form.find(".submit-button").before($loader);	
			}); 
		
			if(typeof form_action == "function")
				form_action();
			else
				$form.submit();
				
			
		} 
		else 
		{
			$form.find(".form-validation-tooltip").fadeIn("slow", function() { 
				this.tooltip_timeout = window.setTimeout(function() { alert(this.$form.attr("name")); /*this.$validation_tooltip.fadeOut("slow");*/ }, 5000);														   
			});
		}
		
		return false;
	};
	
	this.resetForm = function()
	{
		var $form = this.$form;
		$form.validate().resetForm();
		$form.find(".ajax-loader").remove();
		$form.find(".submit-button").stop().animate({opacity : "show"}, "fast"); 
		
		/*this.$validation_tooltip.hide();*/
	};
}
