function validate_form(the_form) {
	for (i = 0; i < the_form.elements.length; i++) {
		var the_element = the_form.elements[i];
		var the_tagName = the_element.tagName != null?the_element.tagName:'';
		var the_text = the_element.value != null?the_element.value:'';
		var the_alt = the_element.alt != null?the_element.alt.toUpperCase():'';
		var the_title = the_element.title != null?the_element.title:'';
		var the_type = the_element.type != null?the_element.type.toUpperCase():'';
		
		if (the_tagName == 'INPUT') {
			if (the_type == 'TEXT') {
				if (the_text == '' && the_alt.indexOf('REQUIRED')) {
					if(the_title != '') {
						alert(the_title + ' must not be left blank.');
					} else {
						alert('Please complete the form.');
					}
					return false;
				}
				
				
				if (isNaN(the_text) && the_alt == 'REQUIRED_NUMERIC') {
					if(the_title != '') {
						alert(the_title + ' must be a number.');
					} else {
						alert('Please complete the form.');
					}
					return false;
				}
				if ((the_alt == 'REQUIRED_EMAIL') && (!(the_text.indexOf(".") > 2) && !(the_text.indexOf("@") > 0))) {
					if(the_title != '') {
						alert(the_title + ' must be a valid email address.');
					} else {
						alert('Please complete the form.');
					}
					return false;
				}
			} else if (the_type == 'CHECKBOX') {
				if (the_alt == 'REQUIRED' && the_element.checked == false) {
					if(the_title != '') {
						alert(the_title + ' must be checked.');
					} else {
						alert('Please complete the form.');
					}
					return false;
				}
			}
		}
	}
	return true;
}

function check_pass(pass,repass) {
	if (pass.value != repass.value) {
		alert('Passwords must match.');
		return false;
	}
	return true;
}

window.onload = doLoad;

function doLoad() {
	for(var d = 0; d < document.forms.length; d++) {
	    document.forms[d].onsubmit = function() { 
    		return validate_form(this);
		}
	}
}
