var speed = 600;
var mgr = $.manageAjax({manageType: 'abortOld', maxReq: 5, blockSameRequest: true});

function setAjaxForms(){
	
	// General function to control all forms with AJAX but default to the usual submission for users without javascript
	$("input[type='submit']").click(function(){
	
		var form = $(this).parents("form");
		var action = form.attr("action");
		var query = "?";

		if(form.hasClass("ajax")){
			
			form.find("input,select,textarea").each(function(){
				switch($(this).attr("type")){
					case "checkbox" :
						if($(this).attr("checked") === true){
							query += $(this).attr("name")+"="+$(this).attr("value")+"&";
						}
						break;
					case "radio" : 
						if($(this).attr("checked") === true){
							query += $(this).attr("name")+"="+$(this).attr("value")+"&";
						}
						break;
					default :
						query += $(this).attr("name")+"="+$(this).attr("value")+"&";
						break;
				}
			});
			
			mgr.add({
				success: function(html){
					form.fadeOut("fast",function(){
						form.html(html);
						setAjaxForms();
						form.fadeIn("slow");
						return true;
					});
				},
				url: action+query
			});
		
			return false;
			
		}
		
	});
}



$(document).ready(function(){
						   
	var $taf = $("#tell_a_friend");
	var $petition = $("#petition");
	setAjaxForms();
	
	$("#bttn_taf").click(function(){
		$petition.find("form").animate({opacity: 0}, speed);
		$taf.find("form").animate({opacity: 1}, speed);
		$taf.animate({top: "96px"}, speed, "swing");
	});
	
	$("#bttn_petition").click(function(){
		$petition.find("form").animate({opacity: 1}, speed);
		$taf.find("form").animate({opacity: 0}, speed);
		$taf.animate({top: "393px"}, speed, "swing");
	});

});

function popWin(url,id,w,h){
	window.open (url,id,"menubar=1,resizable=1,width="+w+",height="+h+""); 	
}
