
$(document).ready(function() {	
	$("#formMail").ajaxForm({
		url: '../contatti_submit.html',
		type: 'post',
		target: '#mail-response',
		beforeSubmit:  checkFields,
		success: function() {
			//$("#formMail").resetForm();
			pageTracker._trackPageview("/target/contacts");
			setTimeout(function() {$("#success").hide("slow");},2000);
		},
		async: false  	
	});
	
	var validator = $("#formMail").validate({
		rules: {
			email:{
				required: true,
				email: true
			}
		}
	});
	
	$("#formId").ajaxForm({
		url: '../order_submit.html',
		type: 'post',
		target: '#success',
		beforeSubmit:  checkFields,
		success: function() {
			$("#formId").resetForm();
						
			ricalcolaQuantitaPrezzo();

			pageTracker._trackPageview("/target/order");
			$("#requestForm div#success").show();
			setTimeout(function() {$("#success").hide("slow");},2000);
		},
		async: false  	
	});
	
	
});


function checkFields(formData, jqForm, options) {
    if(!jqForm.valid()){
		return false;
	}
}

function showResponse(responseText, statusText)  {
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.'); 
}

// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    alert('About to submit: \n\n' + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 

