function IsEmail(email) {
  var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  return regex.test(email);
}

$(document).ready( function() {
	$('input.qty').blur( function() {
		if ( !($(this).val() > 0) )
			$(this).val(0);
		else
			$(this).val( Math.round($(this).val()) );
	})
});

function checkForm() {
	var err = '';
	var sum = 0;
	$('.qty').each( function() {
		sum += Number($(this).val());
	});
	
	if ( !($('#name').val().length > 0) )
		err += '- Please fill in your name. \n';
	if ( !($('#email').val().length > 0) )
		err += '- Please fill in your email. \n';
	else if ( !IsEmail( $('#email').val() ) )
		err += '- Please fill in a valid email. \n';
	if ( !($('#phone').val().length > 0) )
		err += '- Please fill in your telephone number. \n';
	if ( !($('#address').val().length > 0) )
		err += '- Please fill in your address. \n';
	if ( sum == 0 ) {
		err += '- Please change the quanity to indicate the number of item you want to order. \n';
	}
	
	if ( err.length > 0 ) {
		alert(err);
		return false;
	}
}
