<script language="JavaScript" type="text/javascript">
<!--

function toggleAll(checked)
{
    for (i = 0; i < document.search.elements.length; i++) {
        if (document.search.elements[i].name.indexOf('search_folders') >= 0) {
            document.search.elements[i].checked = checked;
        }
    }
}

function dateCheck(field)
{
    if (document.search.elements['search_' + field + '_month'].selectedIndex == 0)
        document.search.elements['search_' + field + '_month'].selectedIndex = "<?php echo date('m') ?>";

    if (document.search.elements['search_' + field + '_day'].selectedIndex == 0)
        document.search.elements['search_' + field + '_day'].selectedIndex = "<?php echo date('d') ?>";

    if (document.search.elements['search_' + field + '_year'].value == "")
        document.search.elements['search_' + field + '_year'].value = "<?php echo date('Y') ?>";
}

function formCheck()
{
    var num_selected = 0;

    for (i = 0; i < document.search.elements.length; i++) {
        if (document.search.elements[i].name.indexOf('search_folders') >= 0) {
            if (document.search.elements[i].checked) {
                num_selected++;
            }
        }
    }

    if (num_selected == 0) {
        alert('<?php echo addslashes(_("Please select at least one folder to search.")) ?>');
        document.search.search_from.focus();
        return false;
    }

    if (document.search.search_from.value == "" &&
        document.search.search_to.value == "" &&
        document.search.search_cc.value == "" &&
        document.search.search_subject.value == "" &&
        document.search.search_body.value == "" &&
        document.search.search_on_month[0].selected &&
        document.search.search_on_day[0].selected &&
        document.search.search_on_year.value == "" &&
        document.search.search_before_month[0].selected &&
        document.search.search_before_day[0].selected &&
        document.search.search_before_year.value == "" &&
        document.search.search_since_month[0].selected &&
        document.search.search_since_day[0].selected &&
        document.search.search_since_year.value == "" &&
        document.search.search_answered[2].checked &&
        document.search.search_seen[2].checked &&
        document.search.search_flagged[2].checked &&
        document.search.search_deleted[2].checked) {
        alert('<?php echo addslashes(_("Please enter valid search criteria.")) ?>');
		document.search.search_from.focus();
		return false;
	}

	return true;
}

// -->
</script>
