inputs = new Array();
inputs_join = new Array();
labels = new Array();

function shortForm() {
    if (!document.getElementById) return false;
    if (!document.getElementsByTagName) return false;
    if (!document.getElementById(inputs[0])) return false;

    var checkBox = document.getElementById("ctl00_MainContentHolder_Main2_chkKort_lang");

    checkBoxChecked = false;

    orderBekfrP = document.getElementById("order_bekfr");
    orderBekfrLabel = orderBekfrP.getElementsByTagName("label")[0];

    checkBox.onclick = function() {

        if (checkBox.checked == true) {

            for (var i = 0; i < labels.length; i++) {
                labelID = document.getElementById(labels[i]);
                labelID.style.color = "#957315";
                orderBekfrLabel.style.color = "#957315";
            }

            var inputsToChange = new Array('4', '7', '8', '9', '10', '12', '13', '16', '17');

            for (var i = 0; i < inputs.length; i++) {

                for (var z = 0; z < inputsToChange.length; z++) {
                    if (inputsToChange[z] == i) {

                        document.getElementById(inputs[i]).style.backgroundColor = "#E4B020";
                        document.getElementById(inputs[i]).style.borderColor = "#E4B020";
                        document.getElementById(inputs[i]).style.color = "#957315";

                    }
                }
            }

            checkBoxChecked = true;

        } else {

            for (var i = 0; i < labels.length; i++) {
                labelID = document.getElementById(labels[i]);
                labelID.style.color = "#000000";
                orderBekfrLabel.style.color = "#000000";
            }
            for (var i = 0; i < inputs.length - 1; i++) {
                inputID = document.getElementById(inputs[i]);
                inputID.style.backgroundColor = "#FBD97B";
                inputID.style.borderColor = "#FBD97B";
                inputID.style.color = "#000000";
            }

            checkBoxChecked = false;
        }
    }
}

function copyInput() {
    if (!document.getElementById) return false;
    if (!document.getElementsByTagName) return false;
    if (!document.getElementById(inputs[0])) return false;

    var foretagKundNummer1 = document.getElementById(inputs[0]);
    var referens1 = document.getElementById(inputs[1]);
    var telefon1 = document.getElementById(inputs[2]);

    var fran = document.getElementById(inputs[6]);
    var referens2 = document.getElementById(inputs[7]);
    var telefon2 = document.getElementById(inputs[10]);

    var buttonCopy = document.getElementById("ctl00_MainContentHolder_Main2_btnCopy");

    buttonCopy.onclick = function() {
        fran.value = foretagKundNummer1.value;
        referens2.value = referens1.value;
        telefon2.value = telefon1.value;
        return false;
    }
}

function validateNewsletterForm() {
    if (!document.getElementById) return false;
    if (!document.getElementsByTagName) return false;
    if (!document.getElementById("ctl00_MainContentHolder_Main2_section6_txtNamn")) return false;

    var yourName = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtNamn");
    var yourCompany = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtForetag");
    var yourAdress = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtAdress");
    var yourEmail = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtEpost");
    var yourPhone = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtTelefon");

    var tips1Foretag = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtTips1Foretag");
    var tips1Kontaktperson = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtTips1Kontaktperson");
    var tips1Epost = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtTips1Epost");
    var tips1Telefon = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtTips1Telefon");

    var tips2Foretag = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtTips2Foretag");
    var tips2Kontaktperson = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtTips2Kontaktperson");
    var tips2Epost = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtTips2Epost");
    var tips2Telefon = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtTips2Telefon");

    var tips3Foretag = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtTips3Foretag");
    var tips3Kontaktperson = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtTips3Kontaktperson");
    var tips3Epost = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtTips3Epost");
    var tips3Telefon = document.getElementById("ctl00_MainContentHolder_Main2_section6_txtTips3Telefon");

    var submitButton = document.getElementById("ctl00_MainContentHolder_Main2_section6_btnSubmit");

    submitButton.onclick = function() {
        if (yourName.value != "") {
            if (yourCompany.value == "") {
                alert("Var vänlig fyll i vilket företag du representerar.");
                yourCompany.focus();
                return false;
            }
            if (yourAdress.value == "") {
                alert("Var vänlig fyll i din adress.");
                yourAdress.focus();
                return false;
            }
            if (yourEmail.value == "") {
                alert("Var vänlig fyll i din e-post.");
                yourEmail.focus();
                return false;
            }
            if (yourPhone.value == "") {
                alert("Var vänlig fyll i ditt telefonnummer.");
                yourPhone.focus();
                return false;
            }
        }
        if (tips1Foretag.value != "") {
            if (tips1Kontaktperson.value == "") {
                alert("Var vänlig fyll i kontaktpersonen för tips 1.");
                tips1Kontaktperson.focus();
                return false;
            }
            if (tips1Epost.value == "") {
                alert("Var vänlig fyll i e-post för tips 1.");
                tips1Epost.focus();
                return false;
            }
            if (tips1Telefon.value == "") {
                alert("Var vänlig fyll i telefonnummer för tips 1.");
                tips1Telefon.focus();
                return false;
            }
        }
        if (tips2Foretag.value != "") {
            if (tips2Kontaktperson.value == "") {
                alert("Var vänlig fyll i kontaktpersonen för tips 2.");
                tips2Kontaktperson.focus();
                return false;
            }
            if (tips2Epost.value == "") {
                alert("Var vänlig fyll i e-post för tips 2.");
                tips2Epost.focus();
                return false;
            }
            if (tips2Telefon.value == "") {
                alert("Var vänlig fyll i telefonnummer för tips 2.");
                tips2Telefon.focus();
                return false;
            }
        }
        if (tips3Foretag.value != "") {
            if (tips3Kontaktperson.value == "") {
                alert("Var vänlig fyll i kontaktpersonen för tips 3.");
                tips3Kontaktperson.focus();
                return false;
            }
            if (tips3Epost.value == "") {
                alert("Var vänlig fyll i e-post för tips 3.");
                tips3Epost.focus();
                return false;
            }
            if (tips3Telefon.value == "") {
                alert("Var vänlig fyll i telefonnummer för tips 3.");
                tips3Telefon.focus();
                return false;
            }
        }
    }

}

function validateOrderForm() {
    if (!document.getElementById) return false;
    if (!document.getElementsByTagName) return false;
    if (!document.getElementById(inputs[0])) return false;

    var submitButton = document.getElementById("ctl00_MainContentHolder_Main2_Button1");
    submitButton.onclick = function() {

        switch (checkBoxChecked) {
            case true:
                {
                    var inputsToChange = new Array('0', '1', '2', '3', '5', '6', '11', '14', '15', '18');
                    for (var i = 0; i < inputs.length; i++) {
                        for (var z = 0; z < inputsToChange.length; z++) {
                            if (inputsToChange[z] == i) {
                                inputID = document.getElementById(inputs[i]);
                                inputID.style.borderColor = "#FBD97B";
                                if (inputID.value == "") {
                                    alert("Du har glömt fylla i ett fält!");
                                    inputID.style.borderColor = "#000000";
                                    inputID.focus();
                                    return false;
                                }
                                else if (inputID.id == "ctl00_MainContentHolder_Main2_txtMail") {
                                    var RegEx = /^[a-zA-Z0-9]+([\._]?[a-zA-Z0-9]+)*@[a-zA-Z0-9]+([\.-]?[a-zA-Z]+)?(\.[a-zA-Z]{2,3})+$/;

                                    if (!RegEx.test(inputID.value)) {
                                        alert("Vänligen se till att din e-postadress är korrekt!");
                                        inputID.style.borderColor = "#000000";
                                        inputID.focus();
                                        return false;
                                    }
                                }
                            }

                        }
                    }
                    break;
                }
            case false:
                {
                    var inputsToChange = new Array('0', '1', '2', '3', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19');
                    for (var i = 0; i < inputs.length; i++) {
                        for (var z = 0; z < inputsToChange.length; z++) {
                            if (inputsToChange[z] == i) {
                                inputID = document.getElementById(inputs[i]);
                                inputID.style.borderColor = "#FBD97B";
                                if (inputID.value == "") {
                                    alert("Du har glömt fylla i ett fält!");
                                    inputID.style.borderColor = "#000000";
                                    inputID.focus();
                                    return false;
                                }
                                else if (inputID.id == "ctl00_MainContentHolder_Main2_txtMail") {
                                    alert('asd');
                                    var RegEx = /^[a-zA-Z0-9]+([\._]?[a-zA-Z0-9]+)*@[a-zA-Z0-9]+([\.-]?[a-zA-Z]+)?(\.[a-zA-Z]{2,3})+$/;

                                    if (!RegEx.test(inputID.value)) {
                                        alert("Vänligen se till att din e-postadress är korrekt!");
                                        inputID.style.borderColor = "#000000";
                                        inputID.focus();
                                        return false;
                                    }
                                }
                            }
                        }
                    }
                    break;
                }
        }
    }
}

function validateJoinForm() {
    if (!document.getElementById) return false;
    if (!document.getElementsByTagName) return false;
    if (!document.getElementById(inputs_join[0])) return false;

    var submitButtonID = document.getElementById(submitButton);
    submitButtonID.onclick = function() {
        for (var i = 0; i < inputs_join.length; i++) {
            inputID = document.getElementById(inputs_join[i]);
            inputID.style.borderColor = "#FBD97B";
            if (inputID.value == "") {
                alert("Du har glömt fylla i ett fält!");
                inputID.style.borderColor = "#000000";
                inputID.focus();
                return false;
            }
        }
    }
}
