/*
 * (c) neofonie Technologieentwicklung und Informationsmanagement GmbH
 *
 * This computer program is the sole property of neofonie GmbH
 * (http://www.neofonie.de) and is protected under the German Copyright Act
 * (paragraph 69a UrhG). All rights are reserved. Making copies,
 * duplicating, modifying, using or distributing this computer program
 * in any form, without prior written consent of neofonie, is
 * prohibited. Violation of copyright is punishable under the
 * German Copyright Act (paragraph 106 UrhG). Removing this copyright
 * statement is also a violation.
 */

/**
 * Library for site search.
 *
 * @author tilman.linden@neofonie.de
 */

/**
 * Behaviour of the "select all" checkbox in the content type checkbox group.
 *
 * @param checkbox The checkbox.
 */
function allx(checkbox) {
    if (checkbox && checkbox.form) {
        if (!checkbox.checked) {
            checkbox.checked = true;
            return false;
        } else {
            $(":checkbox", checkbox.form).filter(":not(:checkbox[name=" + checkbox.name + "])").each(function() {
                this.checked = true;
            });
            return true;
        }
    } else {
        return false;
    }
}

/**
 * Behaviour of a content type checkbox in the search box.
 *
 * @param checkbox The checkbox.
 */
function option(checkbox) {
    if (checkbox && checkbox.form) {
        var allOption = "showAll";
        var group = $(":checkbox", checkbox.form).filter(":not(:checkbox[name=" + allOption + "])");
        var checkedCount = group.filter(":checked").length;
        var changed = checkedCount;
        if (checkedCount == 0) {
            checkbox.checked = true;
            checkedCount = 1;
        }
        $(":checkbox[name=" + allOption + "]", checkbox.form).each(function() {
            this.checked = (group.length == checkedCount);
        });
        return true;
    } else {
        return false;
    }
}

