$(function(){															// On document-ready
	$('form.ajaxform').ajaxSubmit();									// Ajaxify forms
});


 
$.fn.ajaxSubmit = function(e) {		
	/* Change a form's submission type to ajax */
	this.submit(function(){
						 
	var params = {};
	$(this)
	.find("input[@type='text']")
	.filter(":enabled")
	.each(function() {
	  params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
	});
	//$("body").addClass("curWait");
		$.post(this.getAttribute("action") + "?call=ajax&option=subscribe", params, function(xml){
			//$("body").removeClass("curWait");
			strError = "Unable to submit form. Please try again later.";
			oFocus = null;
			$("AjaxResponse", xml).each(function() {
				strRedirect = this.getAttribute("redirecturl");
				strError = this.getAttribute("error");
				oFocus = this.getAttribute("focus");
			});
			
			if (strError.length == 0) {
				$("div.formErrors").hide();
				$("div.formMessage").html("<h5>Success!<\/h5><div class=\"close\"><a href=\"javascript:void(0);\" onclick=\"$('div.formMessage').fadeOut('normal');\">X</a></div>Thank you for subscribing to our newsletter.").filter(":hidden").fadeIn("normal");
				$("#newsletter_email").val("");
				if (oFocus) $("#" + oFocus).get(0).focus();
			} else {
				$("div.formMessage").hide();
				$("div.formErrors").html("<h5>Error<\/h5><div class=\"close\"><a href=\"javascript:void(0);\" onclick=\"$('div.formErrors').fadeOut('normal');\">X</a></div><ul class=\"sm\">" + strError.replace(/(\t)(.+)/g, "<li>$2<\/li>") + "<\/ul>").filter(":hidden").fadeIn("normal");
				if (oFocus) $("#" + oFocus).get(0).focus();
			}
		});
		return false;
	});

	return this;
}

