alerting is a horrible way of advising that something went wrong... mostly because if you have 10 fields all required and none filled in you're going to get 10 alerts. A better design pattern would be to have a hidden div element next to each field with the same id as the field + "_error"
<input type="text" id="username" class="required" value=""><div id="username_error" style="color:#f30;display:none">error msg</div>
var error_id = elements[i].id + "_error";
var err = document.getElementById(error_id);
err.innerHTML = "This field is required";
err.style.display = "block";
a: true is 1 and false is 0 right?