$(document).ready(function(){
	$("#nextButton").click(sendForm);
});

function getFormValues(formId) {
	var res=new Object();
	$("#"+formId+" :input").each(function(){
  		if($(this).is("input") && ($(this).attr("type")=="checkbox" || $(this).attr("type")=="radio")) {
  			if($(this).attr("checked")) {
  				res[$(this).attr("name")]=$(this).attr("value"); //Checkbox & radiobox
  			}
  		}
  		else if($(this).is("select")) {
  			var key=$(this).attr("name");
  			key=key.substring(0, key.lastIndexOf("[]"));
  			var count=0;
  			$.each($(this).children(), function(){
  				if($(this).attr("selected")) {
  					res[key+"["+count+"]"]=$(this).attr("value"); //Select
  					count++;
  				}
  			});
  		}
  		else {
  		  	res[$(this).attr("name")]=$(this).attr("value"); //Textarea, other inputs
  		}
	});
	return res;
}

function sendForm() {
	var res=getFormValues("supportForm");
	showSpinner(function(){
		$.post("/mediaComponents/supportRequest/ajaxForm.php", res, function(data) {
			$("#supportForm").fadeOut("slow", function(){
				$("#supportForm").html(data);
				$("#supportForm").fadeIn("slow", function(){
					$("#nextButton").click(sendForm);
					hideSpinner();
				});
			});
   		});
	}, $("#formDiv"));
}