function hidePopUp(e) {
 e.parentNode.parentNode.parentNode.style.visibility = 'hidden';
}

function contratEstAccepte() {
    var a = document.getElementById("accept_contrat");
    if (a.checked == true) {
        return true;
    }
    return false;
}

function checkModificationEtudiant(a) {
    if (checkInscriptionEtudiantDepartements() && checkInscriptionEtudiantMatiereDominante() && checkInscriptionEtudiantMotDePasse() && checkInscriptionEtudiantConfirmation() && checkInscriptionEtudiantMail() && checkInscriptionEtudiantNom()) {
        a.submit()
    }
}

function checkInscriptionEtudiant(a) {
    if (!contratEstAccepte()) {
        alert('Pour pouvoir valider votre inscription, vous devez lire le "Contrat d\'inscription" et cocher la case "J\'accepte".');
        return
    }
    if (checkInscriptionEtudiantDepartements() && checkInscriptionEtudiantMatiereDominante() &&  checkInscriptionEtudiantConfirmation() && checkInscriptionEtudiantMotDePasse() && checkInscriptionEtudiantMail() && checkInscriptionEtudiantPrenom() && checkInscriptionEtudiantNom()) {
        a.submit()
    }
}

function checkInscriptionRecruteur(a) {
    if (!contratEstAccepte()) {
        alert('Pour pouvoir valider votre inscription, vous devez lire le "Contrat d\'inscription" et cocher la case "J\'accepte".');
        return
    }
    if (checkInscriptionEtudiantConfirmation() && checkInscriptionEtudiantMotDePasse() && checkInscriptionEtudiantMail() && checkInscriptionEtudiantPrenom() && checkInscriptionEtudiantNom() && checkNumeroTelephone() && checkAdresse()) {
        a.submit()
    }
}

function checkNouvelleAnnonce(a) {
    if (checkTitreAnnonce() && checkNombreDePostes() && checkDescriptifCadre() && checkDescriptifMission() &&  checkDescriptifProfil() && checkDescriptifContact() && checkDescriptifConditions()) {
        a.submit()
    }
}

function checkTitreAnnonce() {
    if (isEmpty("input_titre") || isTooShort("input_titre", 20)) {
        alert("Vous n'avez pas entre de titre assez long pour votre annonce : completez le avec la ville par exemple");
        return false;
    }
    return true;
}

function checkNombreDePostes() {
    if (isEmpty("input_nombre_postes")) {
        alert("Vous n'avez pas entre le nombre de postes que vous proposez.");
        return false;
    }
    return true;
}

function checkDescriptifCadre() {
    if (isEmpty("input_descriptif_cadre") || isDefault("input_descriptif_cadre", "Notre entreprise est ...")) {
        alert("Vous n'avez pas entre de descriptif pour le cadre: decrivez votre entreprise, votre association...");
        return false;
    }
    return true;
}

function checkDescriptifMission() {
    if (isEmpty("input_descriptif_mission") || isDefault("input_descriptif_mission", "Nous recherchons un(e) etudiant(e) pour ...")) {
        alert("Vous n'avez pas entre de descriptif pour la mission.");
        return false;
    }
    return true;
}

function checkDescriptifConditions() {
    if (isEmpty("input_descriptif_conditions") || isDefault("input_descriptif_conditions", "Vous travaillerez entre 8h et 17h sur notre lieu de vente...")) {
        alert("Vous n'avez pas entre de  conditions, entrez le salaire, les horaires...");
        return false;
    }
    return true;
}

function checkDescriptifProfil() {
    if (isEmpty("input_descriptif_profil") || isDefault("input_descriptif_profil", "Vous etes souriant accueillant avec, de preference une experience dans la vente...")) {
        alert("Vous n'avez pas entre de desciptif pour le profil type.");
        return false;
    }
    return true;
}

function checkDescriptifContact() {
    if (isEmpty("input_informations_contact")) {
        alert("Vous n'avez pas entre les informations pour postuler.");
        return false;
    }
    return true;
}

function checkNumeroTelephone() {
    var a = document.getElementById("input_telephone").value;
    if (!a.length == 10) {
        alert("Ce numero de telephone n'est pas valide.");
        return false;
    }
    return true;
}

function checkAdresse() {
    if (isEmpty("input_adresse")) {
        alert("Rentrez votre adresse.");
        return false;
    }
    return true;
}

function checkInscriptionEtudiantDepartements() {
    var b = document.getElementById("input_departements").value,
        c = b.split("-"),
        a = 0;
    if (b == "") {
        alert("Entrez au moins un departement.");
        return false;
    } else {
        while (a < c.length) {
            if (!isDep(c[a])) {
                alert(c[a] + " n'est pas un departement.");
                return false;
            }
            a++
        }
    }
    return true;
}

function checkMailContact(a) {
    if (checkSujetMailContact() && checkMessageMailcontact() && checkInscriptionEtudiantPrenom() && checkInscriptionEtudiantNom() && checkInscriptionEtudiantMail()) {
        a.submit()
    }
}

function checkSujetMailContact() {
    if (isEmpty("input_sujet")) {
        alert("Vous n'avez pas de sujet a votre message.");
        return false;
    }
    return true;
}

function checkMessageMailcontact() {
    if (isEmpty("input_message")) {
        alert("Vous n'avez pas de message pour nous contacter.");
        return false;
    }
    return true;
}

function checkInscriptionEtudiantMatiereDominante() {
    if (isEmpty("input_matiere_dominante")) {
        alert("Vous n'avez pas entre de matiere dominante.");
        return false;
    }
    return true;
}

function checkInscriptionEtudiantConfirmation() {
    var b = document.getElementById("input_mot_de_passe").value,
        a = document.getElementById("input_confirmation").value;
    if (b != a) {
        alert("Vous avez entre deux mots de passe differents.");
        return false;
    }
    return true;
}

function checkInscriptionEtudiantMotDePasse() {
    if (isEmpty("input_mot_de_passe")) {
        alert("Vous n'avez pas entre votre mot de passe.");
        return false;
    }
    return true;
}

function checkInscriptionEtudiantMail() {
    if (!VerificationEmail(document.getElementById("input_email").value)) {
        alert("Cette adresse email n'est pas valide.");
        return false;
    }
    return true;
}

function checkInscriptionEtudiantMailConfirm() {
    if (document.getElementById("input_email").value != document.getElementById("input_email_confirm").value) {
        alert("Attention, vous avez tape deux addresses emails differentes.");
        return false;
    }
    return true;
}

function checkInscriptionEtudiantPrenom() {
    if (isEmpty("input_prenom")) {
        alert("Vous n'avez pas entre votre prenom.");
        return false;
    }
    return true;
}

function checkInscriptionEtudiantNom() {
    if (isEmpty("input_nom")) {
        alert("Vous n'avez pas entre votre nom.");
        return false;
    }
    return true;
}

function isDep(a) {
    if (a == "2a" || a == "2b") {
        return true;
    } else {
        if (a > 0 && a < 96) {
            return true;
        } else {
            return false;
        }
    }
}

function isTooShort(a, size) {
    var b = document.getElementById(a).value;
    if (leftTrim(b).length < size) {
        return true;
    }
    return false;
}

function isDefault(a, def) {
    var b = document.getElementById(a).value;
    if (leftTrim(b) === leftTrim(def)) {
        return true;
    }
    return false;
}


function isEmpty(a) {
    var b = document.getElementById(a).value;
    if (leftTrim(b) == "") {
        return true;
    }
    return false;
}

function leftTrim(a) {
    while (a.substring(0, 1) == " ") {
        a = a.substring(1, a.length)
    }
    return a
}

function VerificationEmail(a) {
    if (a.indexOf("@") != "-1" && a.indexOf(".") != "-1" && a != "" && a.lastIndexOf("@") == a.indexOf("@")) {
        return true;
    }
    return false;
};
