/*
 * Copyright 2011 IBeeS GmbH
 *
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * IBeeS GmbH. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with IBeeS.
 *
 * CopyrightVersion 1.0
 */

function applayModelToForm(formName, model) {
    var attribute;
    for (attribute in model) {
        var elements =
                document.forms[formName].elements[attribute];
        if ((typeof elements.length) == 'undefined') {
            document.forms[formName].elements[attribute].value = model[attribute];
        } else {
            if (elements[0].type == 'checkbox') {
                var i;
                var targetData = model[attribute];
                if ((typeof targetData) == 'string') {
                    var targetCheckbox = model[attribute];
                    for (i = 0; i < elements.length; i++) {
                        if (elements[i].value == targetCheckbox) {
                            elements[i].checked = true;
                        }
                    }
                } else {
                    for (i = 0; i < elements.length; i++) {
                        elements[i].checked = targetData[elements[i].value];
                    }
                }
            }
        }
    }
}
