$(document).ready(function() { 
    // bind form using ajaxForm 
    $('#frmAbbonamenti').ajaxForm( { beforeSubmit: validate } );
	   
});

function validate(formData, jqForm, options) { 
    // formData is an array of objects representing the name and value of each field 
    // that will be sent to the server;  it takes the following form: 
    // 
    // [ 
    //     { name:  username, value: valueOfUsernameInput }, 
    //     { name:  password, value: valueOfPasswordInput } 
    // ] 
    // 
    // To validate, we can examine the contents of this array to see if the 
    // username and password fields have values.  If either value evaluates 
    // to false then we return false from this method. 
 
    for (var i=0; i < formData.length; i++) { 
        switch(formData[i].name){
		  case 'nome':
		  case 'cognome':
		  case 'indirizzo':
		  case 'cap':
		  case 'citta':
		  case 'provincia':
		  case 'telefono':
		  case 'email':
		  
		    if (!formData[i].value) { 
              alert('Il campo '+formData[i].name+' è obbligatorio'); 
              return false; 
            } 
			break;
		  
		  case 'piva':
		    if (!formData[i].value) { 
              alert('Il campo P. IVA/Codice Fiscale è obbligatorio'); 
              return false; 
            } 
			break;
		}
    } 
    alert(formData[i].name); 
}

$(function() {
$('a[rel*=external]').click( function() {
window.open(this.href);
return false;
});
});