﻿
    function checkform() {        
        // Validation optin
        var aErrMsg = new Array();
        var nbrViral = 0;
        
        if (document.OptForm.EMail.value == "") {
            document.getElementById("img_courriel").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_courriel").className = "error_td";
            document.getElementById("txt_courriel").innerHTML = "Le champ est vide.";
            aErrMsg++;
        } else if (!checkEMail(document.OptForm.EMail.value)) {
            document.getElementById("img_courriel").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_courriel").className = "error_td";
            document.getElementById("txt_courriel").innerHTML = "L'addresse courriel que vous avez entrée n'est pas valide.";
            aErrMsg++;
        } else {
            document.getElementById("img_courriel").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38113/pZ8jJo/concours_blank.gif");
            document.getElementById("td_courriel").className = "";
            document.getElementById("txt_courriel").innerHTML = "";
        }
        
        if (document.OptForm.FirstName.value == "") {
            document.getElementById("img_firstname").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_firstname").className = "error_td";
            document.getElementById("txt_firstname").innerHTML = "Le champ est vide.";
            aErrMsg++;
        } else {
            document.getElementById("img_firstname").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38113/pZ8jJo/concours_blank.gif");
            document.getElementById("td_firstname").className = "";
            document.getElementById("txt_firstname").innerHTML = "";
        }
        if (document.OptForm.LastName.value == "") {
            document.getElementById("img_lastname").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_lastname").className = "error_td";
            document.getElementById("txt_lastname").innerHTML = "Le champ est vide.";
            aErrMsg++;
        } else {
            document.getElementById("img_lastname").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38113/pZ8jJo/concours_blank.gif");
            document.getElementById("td_lastname").className = "";
            document.getElementById("txt_lastname").innerHTML = "";
        }        
        
        if (document.OptForm.Adresse.value == "") {
            document.getElementById("img_adress").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_adress").className = "error_td";
            document.getElementById("txt_adress").innerHTML = "Le champ est vide.";
            aErrMsg++;
        } else {
            document.getElementById("img_adress").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38113/pZ8jJo/concours_blank.gif");
            document.getElementById("td_adress").className = "";
            document.getElementById("txt_adress").innerHTML = "";
        }

        if (document.OptForm.Ville.value == "") {
            document.getElementById("img_city").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_city").className = "error_td";
            document.getElementById("txt_city").innerHTML = "Le champ est vide.";
            aErrMsg++;
        } else {
            document.getElementById("img_city").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38113/pZ8jJo/concours_blank.gif");
            document.getElementById("td_city").className = "";
            document.getElementById("txt_city").innerHTML = "";
        }

        if (document.OptForm.Province.value == "99") {
            document.getElementById("img_province").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_province").className = "error_td";
            document.getElementById("txt_province").innerHTML = "Vous devez choisir une province.";
            aErrMsg++;
        } else {
            document.getElementById("img_province").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38113/pZ8jJo/concours_blank.gif");
            document.getElementById("td_province").className = "";
            document.getElementById("txt_province").innerHTML = "";
        }

        if (document.OptForm.CodePostal.value == "") {
            document.getElementById("img_postalcode").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_postalcode").className = "error_td";
            document.getElementById("txt_postalcode").innerHTML = "Le champ est vide.";
            aErrMsg++;
        }
        else if (!checkPostalCode(document.OptForm.CodePostal.value)) {
            document.getElementById("img_postalcode").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_postalcode").className = "error_td";
            document.getElementById("txt_postalcode").innerHTML = "Le code postal entré n'est pas valide";
            aErrMsg++;
        } else {
            document.getElementById("img_postalcode").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38113/pZ8jJo/concours_blank.gif");
            document.getElementById("td_postalcode").className = "";
            document.getElementById("txt_postalcode").innerHTML = "";
        }

        if (document.OptForm.TelJour.value == "") {
            document.getElementById("img_phoneday").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_phoneday").className = "error_td";
            document.getElementById("txt_phoneday").innerHTML = "Le champ est vide.";
            aErrMsg++;
        }
        else if (!checkPhone(document.OptForm.TelJour.value)) {
            document.getElementById("img_phoneday").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_phoneday").className = "error_td";
            document.getElementById("txt_phoneday").innerHTML = "Le numéro de téléphone entré n'est pas valide.";
            aErrMsg++;
        } else {
            document.getElementById("img_phoneday").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38113/pZ8jJo/concours_blank.gif");
            document.getElementById("td_phoneday").className = "";
            document.getElementById("txt_phoneday").innerHTML = "";
        }

        if (document.OptForm.TelSoir.value != "" && !checkPhone(document.OptForm.TelSoir.value)) {
            document.getElementById("img_phonenight").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_phonenight").className = "error_td";
            document.getElementById("txt_phonenight").innerHTML = "Le numéro de téléphone entré n'est pas valide.";
            aErrMsg++;
        } else {
            document.getElementById("img_phonenight").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38113/pZ8jJo/concours_blank.gif");
            document.getElementById("td_phonenight").className = "";
            document.getElementById("txt_phonenight").innerHTML = "";
        }

        if (document.OptForm.AnneeNaissance.value == "") {
            document.getElementById("img_birthyear").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_birthyear").className = "error_td";
            document.getElementById("txt_birthyear").innerHTML = "Le champ est vide.";        
            aErrMsg++;
        } else if (!checkDate(document.OptForm.AnneeNaissance.value)) {
            document.getElementById("img_birthyear").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_birthyear").className = "error_td";
            document.getElementById("txt_birthyear").innerHTML = "L'année de naissance entrée n'est pas valide.";
            aErrMsg++;
        } else if (parseInt( document.OptForm.AnneeNaissance.value,10) >= 2000) {
            document.getElementById("img_birthyear").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_birthyear").className = "error_td";
            document.getElementById("txt_birthyear").innerHTML = "L'année de naissance entrée n'est pas valide.";
            aErrMsg++;
        } else {
            document.getElementById("img_birthyear").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38113/pZ8jJo/concours_blank.gif");
            document.getElementById("td_birthyear").className = "";
            document.getElementById("txt_birthyear").innerHTML = "";
        }

        if (!checkRadio(document.OptForm.Sexe)) {
            document.getElementById("img_sex").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_sex").className = "error_td";
            document.getElementById("txt_sex").innerHTML = "Votre choix n'est pas valide.";
            aErrMsg++;
        } else {
            document.getElementById("img_sex").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38113/pZ8jJo/concours_blank.gif");
            document.getElementById("td_sex").className = "";
            document.getElementById("txt_sex").innerHTML = "";
        }
        if (document.OptForm.IMAGE_Img1_id.value == "" || document.OptForm.Img1_nom.value == "" || document.OptForm.Img1_desc.value == "") {
            document.getElementById("img_image1").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_image1").className = "error_td";
            document.getElementById("txt_image1").innerHTML = "Vous devez remplir tous les champs pour au moins une photo.";
            aErrMsg++;
        } else {
            document.getElementById("img_image1").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38113/pZ8jJo/concours_blank.gif");
            document.getElementById("td_image1").className = "";
            document.getElementById("txt_image1").innerHTML = "";
        }
        
        if (document.OptForm.AcceptRules.checked == false) {
            document.getElementById("img_rules").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_rules").className = "error_td";
            document.getElementById("txt_rules").innerHTML = "Vous devez accepter le règlement.";
            aErrMsg++;
        } else {
            document.getElementById("img_rules").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38113/pZ8jJo/concours_blank.gif");
            document.getElementById("td_rules").className = "";
            document.getElementById("txt_rules").innerHTML = "";
        }

        if (document.OptForm.OFC4_Optin_CaptCha_Code.value == "") {
            document.getElementById("img_captcha").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38117/QSHf4j/concours_error.gif");
            document.getElementById("td_captcha").className = "error_td";
            document.getElementById("txt_captcha").innerHTML = "Le champ est vide.";
            aErrMsg++;
        } else {
            document.getElementById("img_captcha").setAttribute("src", "http://ofsys.com/T/OFSYS/H/38113/pZ8jJo/concours_blank.gif");
            document.getElementById("td_captcha").className = "";
            document.getElementById("txt_captcha").innerHTML = "";
        }
        if (aErrMsg > 0) {
            return false;
        }
        return true;
    }

    function checkEMail(emailAddress) {
        var re = new RegExp("([a-zA-Z0-9_\\-\\.]+)@((\\[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})");
        return emailAddress.match(re) ? true : false;
    }
    function checkPhone(telephone) {
        var re = new RegExp("[0-9]{3}-[0-9]{3}-[0-9]{4}");
        return telephone.match(re) ? true : false;
    }
    function checkDate(dateNaissance) {
        var re = new RegExp("[0-9]{4}");
        return dateNaissance.match(re) ? true : false;
    }
    function checkRadio(radio) {
        var selected = false;
        for (i = 0; i < radio.length; i++) {
            if (radio[i].checked) {
                selected = true;
                break;
            }
        }
        return selected;
    }
    function checkPostalCode(postalCode) {
        var re = new RegExp("^[A-Z]\\d[A-Z]\\d[A-Z]\\d$"); //G1G 1G1
        return postalCode.match(re) ? true : false;
    }