﻿function ValidateCombo() {
    var form = getObjForm("RegistrationForm");
    var m_array = new Array(3);
    var i, j;
    var check;
    var obj;
    //-----------------------------------
    // Market / Application
    //-----------------------------------
    check = true
    for (i = 1; i < 3; i++) {
        m_array[i] = "";
        obj = eval("form.USREG_00_Market_Level" + i + "_1")
        if (obj) {
            if (document.layers)
                m_array[i] = m_array[i] + obj.value;
            else
                m_array[i] = m_array[i] + obj[obj.selectedIndex].value;
        }
        // check if at least one market / application is selected
        if (m_array[i] != "")
            check = false;

        // check if a market / application has been selected two times
        for (j = i - 1; j > 0; j--) {
            if (m_array[i] == m_array[j] && m_array[i] != "") {
                alert("You have entered several times the same market / application.");
                return true;
            }
        }
    }
    if (check) {
        alert("Please choose at least one market / application.");
        form.USREG_00_Market_Level1_1.focus();
        return true;
    }

    //-----------------------------------
    // Additives / Colorants
    //-----------------------------------
    check = true;
    for (i = 1; i < 3; i++) {
        m_array[i] = "";
        tmp = "";
        for (j = 1; j < 6; j++) {
            obj = eval("form.USREG_00_AdditiveColorant_Level" + i + "_" + j);
            if (obj) {
                if (document.layers)
                    m_array[i] = m_array[i] + obj.value;
                else {
                    if (obj[obj.selectedIndex].value != "") {
                        tmp = obj[obj.selectedIndex].text;
                        tmp2 = eval("form.USREG_00_AdditiveColorant_Level" + i + "_" + (j + 1));
                    }
                    m_array[i] = m_array[i] + obj[obj.selectedIndex].value;
                }
            }
        }
        // check if at least one item is selected
        if (m_array[i] != "") {
            check = false;
            // check that the selected item has not sublevel
            if (!document.layers) {
                if (tmp.indexOf(">>") != -1) {
                    alert("Please specify further the additive / colorant that you are interested in.");
                    tmp2.focus();
                    return true;
                }
            }
        }

        // check if an item has been selected two times
        for (j = i - 1; j > 0; j--) {
            if (m_array[i] == m_array[j] && m_array[i] != "") {
                alert("You have entered several times the same additive / colorant.");
                return true;
            }
        }
    }
    if (check) {
        alert("Please choose at least one additive / colorant.");
        form.USREG_00_AdditiveColorant_Level1_1.focus();
        return true;
    }
    return false;
}
