function del_line(obj) {
	obj.up('div').remove();
	return false;
}
function populate(objForm,selectIndex) {
	var year = objForm.year;
	var month = objForm.month;
	var day = objForm.day;
	populateWithIDs(year,month,day);

}



function populateWithIDs(year,month,day) {
	var numDays = day.length;
	day.options.length = 1;
	if (year.options[year.selectedIndex].value && month.options[month.selectedIndex].value) {
		timeA = new Date(year.options[year.selectedIndex].text, month.options[month.selectedIndex].value,1);
		timeDifference = timeA - 86400000;
		timeB = new Date(timeDifference);
		var daysInMonth = timeB.getDate();
		for (var i = 1; i <= daysInMonth; i++) {
			day.options[i] = new Option(i,i);
		}
		day.options[0].selected = true;
	}
}


function validate(container){
	container = $(container) || $('to_be_validated');
	validate.success = true;
	var passwords = [];
	container.select('input,select,textarea').each(function(i){
		var is_blank = !(i.value && i.value.match(/\S/));
		validate.errors = 0;
		if(i.hasClassName('required')){
			if(is_blank){ validate.setError(i, "Required field."); return; }
			else validate.clearError(i);
		} else if(is_blank){ return; }

		// it won't validate blank values (eg, null, "", or all whitespace) beyond 'required' or not.
		if(i.type == 'password'){
			passwords.push(i);
			return;
		}
		if(i.hasClassName('valid-alpha'))
			if(i.value.match(/[^a-z]/)) validate.setError(i, "Letters only, please.");
		if(i.hasClassName('valid-digits'))
			if(i.value.match(/\D/)) validate.setError(i, "Digits only, please.");
		if(i.hasClassName('valid-num'))
			if(i.value.match(/[^\d\.\-]/)) validate.setError(i, "Enter a number.");
		if(i.hasClassName('valid-zip'))
			if(i.value.length < 5) validate.setError(i, "Invalid postal code.");
		if(i.hasClassName('valid-phone')) {
			var test = i.value.match(/\d/g);
			if(!test || test.length <= 9) validate.setError(i, "Invalid phone number.  Include area code.");
		}
		if(i.hasClassName('valid-email'))
			if(!i.value.match(/\w+[@][\w\-]+([.]([\w\-]+)){1,3}$/)) validate.setError(i, "Invalid email address.");
		if(!validate.errors) validate.clearError(i);
	});
	if(passwords.length>1){
		if(password[0].value == password[1].value) validate.clearError(i);
		else validate.setError(password[1], "Passwords don't match.");
	}
	return validate.success;
}
validate.setError = function(ele, msg){
	msg = msg || 'Validation failed.';
	var id = '_' + (ele.id ? ele.id : (ele.name ? ele.name : (ele.tagName + '.' + ele.className)));
	if(!$(id))
		ele.up('td,div').insert(new Element('div', {'id' : id, 'class' : 'error'}).update(msg));
	validate.success = false;
	validate.errors++;
}
validate.clearError = function(ele){
	var id = '_' + (ele.id ? ele.id : (ele.name ? ele.name : (ele.tagName + '.' + ele.className)));
	if($(id))
		$(id).remove();
}
function require_a_division(){
	var div = $('division');
	if(!div.select('input[type=checkbox]').pluck('checked').any())
		validate.setError(div, "Choose a division.");
	else validate.clearError(div);
	return validate.success;
}
