function check_date(fld, fieldName) {
	if (check_date.arguments.length == 3)
		bBlankValid = check_date.arguments[3];
	else
		bBlankValid = true;
		
	if (fld.value == "" && !bBlankValid) 
		if (!check_empty(fld, fieldName)) return false;
		
    if (fld.value != "") {
		re = /^\d{4}-\d{2}-\d{2}$/;
		
		if (!re.test(fld.value)) {
			alert("The valid format for this field [" + fieldName + "] is YYYY-MM-DD, please correct it.");
			fld.select();
			fld.focus();
			return false;
		}
    }

    return true;
}

function check_empty(fld, fieldName) {
	if (fld.value == "") {
		alert("This field [" + fieldName + "] cannot be empty.");
		fld.select();
		fld.focus();
		return false;	
	}
	
	return true;
}
