﻿


function cacherdiv(anID)
{
    if ( document.getElementById(anID) != null)
    {
    var bloc = document.getElementById(anID);
    if (bloc.style.display=="none")
    {
        bloc.style.display = "block";
    }
    else
    {
        bloc.style.display = "none";
    }
    }
}

function montrerelement(anID)
{
    if ( document.getElementById(anID) != null)
    {
    var bloc = document.getElementById(anID);
    bloc.style.display = "block";
   
    }
}

function cacherelement(anID)
{
    if ( document.getElementById(anID) != null)
    {
    var bloc = document.getElementById(anID);
    bloc.style.display = "none";
    }
}
function InfosCandidatures(top,id_candidat)
{
    $("#UpdateProgressCat").show();
    $.ajax({ type: "POST", url: "afficher_candidatures.aspx", data: "id="+ id_candidat +"&top="+top , success: function(msg){ $("#infos_candidatues").html(msg); $("#infos_candidatues").show();$("#UpdateProgressCat").hide();if (top == ''){$("#plusCritere").hide();$("#moinsCritere").show();}} });	
    
}

function InfosSelection(id_candidat)
{
    $("#UpdateProgressCatSO").show();
    $.ajax({ type: "POST", url: "afficher_selection_archives.aspx", data: "", success: function(msg){ $("#infos_selection").html(msg); $("#infos_selection").show();$("#UpdateProgressCatSO").hide();} });	
    
}

function montrerSummary(message) {
    document.getElementById('validSummary').className = 'erreur';
    if(document.getElementById('validSummary').innerHTML.indexOf('Attention : Certains champs sont invalides') < 0) {
        document.getElementById('validSummary').innerHTML = 'Attention :';
    }
    
    var strLi = '<li>' + message + '</li>';
    if(document.getElementById('validSummary').innerHTML.indexOf(strLi) < 0 && document.getElementById('validSummary').innerHTML.indexOf('<LI>' + message + '</LI>') < 0) {
        if(document.getElementById('validSummary').innerHTML.indexOf('<ul>') < 0 && document.getElementById('validSummary').innerHTML.indexOf('<UL>') < 0) {
            document.getElementById('validSummary').innerHTML += '<ul>' + strLi + '</ul>';
        }else{
            document.getElementById('validSummary').innerHTML = document.getElementById('validSummary').innerHTML.replace('</ul>', strLi + '</ul>').replace('</UL>', strLi + '</UL>');
        }
    }
    document.getElementById('validSummary').style.display = 'block';
}

function montrerSummary2(message,id) {
    document.getElementById(id).className = 'erreur';
    if(document.getElementById(id).innerHTML.indexOf('Attention : Certains champs sont invalides') < 0) {
        document.getElementById(id).innerHTML = 'Attention :';
    }
    
    var strLi = '<li>' + message + '</li>';
    if(document.getElementById(id).innerHTML.indexOf(strLi) < 0 && document.getElementById(id).innerHTML.indexOf('<LI>' + message + '</LI>') < 0) {
        if(document.getElementById(id).innerHTML.indexOf('<ul>') < 0 && document.getElementById(id).innerHTML.indexOf('<UL>') < 0) {
            document.getElementById(id).innerHTML += '<ul>' + strLi + '</ul>';
        }else{
            document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.replace('</ul>', strLi + '</ul>').replace('</UL>', strLi + '</UL>');
        }
    }
    document.getElementById(id).style.display = 'block';
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}


function validateEmpty(source, arguments) {
    if (rtrim(ltrim(arguments.Value)) == "")
    {   
        $(source.controltovalidate).className = 'select_champ_erreur';
        arguments.IsValid = false;
    }
    else
    {
        arguments.IsValid = true;
	}
}

function validateEmptyChampsCourt(source, arguments) {
    if (rtrim(ltrim(arguments.Value)) == "")
    {   
        $(source.controltovalidate).className = 'court_erreur';
        arguments.IsValid = false;
    }
    else
    {
        $(source.controltovalidate).className = 'court';
        arguments.IsValid = true;
	}
}

function validateEmail(source, arguments) {
    if (arguments.Value.indexOf('ex : ') != 0)
    {
        var pattern = new RegExp(/^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,4}$/g);
        if (pattern.test(arguments.Value))
        {
            
            arguments.IsValid = true;
        }
        else
        {
            $(source.controltovalidate).className = 'select_champ_erreur';
            arguments.IsValid = false;
        }
    }
    else{
        $(source.controltovalidate).className = 'select_champ_erreur';
        arguments.IsValid = false;
    }
}

function validate6a15chiffres(source, arguments) {
    if (arguments.Value.match(/^[0-9a-zA-Z]{6,15}$/g))
    {
        if (arguments.Value.match(/\W/g))
        {
            arguments.IsValid = false;
        }
        else
        { 
            arguments.IsValid = true;
        }
    }
    else
    {
        $(source.controltovalidate).className = 'select_champ_erreur';
        arguments.IsValid = false;
    }
}


function validatecomparemotpasse(source, arguments) {
    if (arguments.Value != $('#mot_de_passe').val())
    {
        $(source.controltovalidate).className = 'select_champ_erreur';
        arguments.IsValid = false;
    }
    else
    {
        
        arguments.IsValid = true;
    }
}

function validatecomparemotpasse_modIdentite(source, arguments) {
    if ($('#modIdentite_mot_de_passeD').val() != $('#modIdentite_confirm_mot_passeD').val())
    {
        $(source.controltovalidate).className = 'select_champ_erreur';
        arguments.IsValid = false;
    }
    else
    {
        
        arguments.IsValid = true;
    }
}

function validatecomparemotpasseI(source, arguments) {
//    alert($('#confirm_mot_passeI').val());
//    alert($('#mot_de_passeI').val());
    if ($('#confirm_mot_passeI').val() != $('#mot_de_passeI').val()) {
        $(source.controltovalidate).className = 'select_champ_erreur';
        arguments.IsValid = false;
    }
    else {

        arguments.IsValid = true;
    }
}

function validedomaine(source, arguments)
{
    if (!arguments.Value.match($('#email_domaine').val()))
    {
        if (confirm('Nom de domaine inconnu'))
        {
            arguments.IsValid = true;
        }
        else
        {
           arguments.IsValid = false;
        }
    }
    else
    {
        arguments.IsValid = true;
    }
}
function validedomaineI(source, arguments) {
    if (! $('#emailI').val().match($('#email_domaineI').val())) {
        if (confirm('Nom de domaine inconnu')) {
            arguments.IsValid = true;
        }
        else {
            arguments.IsValid = false;
        }
    }
    else {
        arguments.IsValid = true;
    }
}

function validateListederourlantfonction(source, arguments) {
    if (arguments.Value.indexOf("_") == -1)
    {
        $(source.controltovalidate).className = 'select_champ_erreur';
        arguments.IsValid = false;
    }
    else
    {
        arguments.IsValid = true;
    }
}

function validatecgu(source,arguments) {
    if ($('#cgu').is(':checked'))
    {
        arguments.IsValid = true;
    }
    else
    {
        $('cgu').className = 'erreur';
        arguments.IsValid = false;
    }
}

function validateaccept_alert(source,arguments) {
    if ($('#accept_alert').is(':checked'))
    {
   
        arguments.IsValid = true;
    }
    else
    {
        $('cgu').className = 'erreur';
        arguments.IsValid = false;
    }
}

/* PARIE VALIDER TELEPHONE*/
function validate10chiffres(source, arguments) {
    if (rtrim(ltrim(arguments.Value)) != "")
    {
        if (arguments.Value.match(/[a-zA-Z]/g) == null && arguments.Value.match(/^[0-9]{10,10}$/g))
        {
            $(source.controltovalidate).className = 'court';
            arguments.IsValid = true;
        }
        else
        {
            $(source.controltovalidate).className = 'court_erreur';
            arguments.IsValid = false;
        }
    }
}

function validatelength10(source, arguments) {
    if (rtrim(ltrim(arguments.Value)) != "")
    {
        if (arguments.Value.match(/[a-zA-Z]/g) == null && arguments.Value.match(/^[0-9]{4,15}$/g))
        {
            $(source.controltovalidate).className = 'select_champ_court';
            arguments.IsValid = true;
        }
        else
        {
            $(source.controltovalidate).className = 'select_champ_court_erreur';
            arguments.IsValid = false;
        }
    }
}

/*checkboxlist pour la création des alertes*/
function Decoche(NumGroupe,NbItem,critere) {
	var NomChamps;
	NomChamps = critere;
	var temp =  document.getElementById("temp_" + NomChamps);
	var temp_array = "";
	var inc = 0;
	//si temp.value est vide donc premier passage
	if (temp.value == "")
	{
		for (var i = 1; i < NbItem; i++) {
				var cb = document.getElementById(NomChamps + '_' + i);
				if(cb.checked)
					{
					inc ++;
					temp_array = temp_array + "," + NomChamps + '_' + i;
					}
				}
		if (inc > 0) // donc j'ai coché des critères
			{
				var cbEnd = document.getElementById(NomChamps + '_0');
				cbEnd.checked = false;
			}
		temp.value = temp_array;
	}
	else
	{
		for (var i = 0; i < NbItem; i++) {
			var cb = document.getElementById(NomChamps + '_' + i);
			if(cb.checked)
			{
			temp_array = temp_array + "," + NomChamps + '_' + i; 
			}
			}
		if (temp_array.indexOf(NomChamps + '_0') != -1)
		{
			for (var i = 1; i < NbItem; i++) {
				var cb = document.getElementById(NomChamps + '_' + i);
				cb.checked=false; 
				}
			temp.value = "";
		}
	}
}
/*fin checkboxlist*/

    function startLytebox(id, title, data, width,height) {
        var el = document.getElementById(id);
        el.href = data;
        el.title = title;
        el.rel = "lyteframe";
        el.rev = "width: "+ width +"; height: "+ height +"; "
        myLytebox = null;
        initLytebox();
        myLytebox.start(el, false, true); 
    }
    
    /* PARIE VALIDER VILLE + CP*/
    
    function RendVisibleVille(pays)
    {
        if (pays != "France métropolitaine")
        {
            montrerelement('paysetranger');
            cacherelement('paysfrance');
            $('#ville').val("");
        }
        else
        {
            montrerelement('paysfrance');
            cacherelement('paysetranger');
            $('#villeetrangere').val("");
        }
    }
    function validateEmptyVille(source, arguments) {
    if($('#paysfrance').css("display")=="block")
    {
        if ($('#ville').val() == "")
        {   
            $(source.controltovalidate).className = 'select_champ_erreur';
            arguments.IsValid = false;
        }
        else
        {
            $(source.controltovalidate).className = 'select_champ';
            arguments.IsValid = true;
	    }
	}
	else
	{
	
	    arguments.IsValid = true;
	}
}

function validatevilleetcp(source, arguments) {

    if($('#paysfrance').css("display")=="block")
    {
        var re = new RegExp('[0-9]{5,5}');
        if (re.test( $('#ville').val()))
        {
            $(source.controltovalidate).className = 'select_champ';
            arguments.IsValid = true;
        }
         else
        {
            arguments.IsValid = false;
        }
    } 
    else
    {
        arguments.IsValid = true;
    }
}

function validateVilleEtrangere(source, arguments) {
    if($('#paysetranger').css("display")=="block")
    {
        if (rtrim(ltrim(arguments.Value)) == "")
        {   
            $(source.controltovalidate).className = 'select_champ_erreur';
            arguments.IsValid = false;
        }
        else
        {
            $(source.controltovalidate).className = 'select_champ';
            arguments.IsValid = true;
	    }
	}
	else
	{
	    arguments.IsValid = true;
	}
}



function validatevilleetcp_parcours(source, arguments) {
    var re = new RegExp('^[0-9]{5,5}$');
    if (rtrim(ltrim(arguments.Value)) != "")
    {
        if (arguments.Value.match(/[a-zA-Z]/g) == null && re.test(arguments.Value))
        {
            $(source.controltovalidate).className = 'select_champ';
            arguments.IsValid = true;
        }
        else
        {
            if (arguments.Value == "2A" || arguments.Value == "2B")
            {
                $(source.controltovalidate).className = 'select_champ';
                arguments.IsValid = true;
            }
            else
            {
                $(source.controltovalidate).className = 'select_champ_erreur';
                arguments.IsValid = false;
            }
        }
    }
}

function validateAnonyme(source, arguments) {
    if (!$('#anonyme_1').is(':checked') && !$('#anonyme_0').is(':checked')) {
        $(source.controltovalidate).className = 'select_champ_court_erreur';
        arguments.IsValid = false;
    } else {
        $(source.controltovalidate).className = 'select_champ_court';
        arguments.IsValid = true
    }
}
function validateAnonymeI(source, arguments) {

    if (!$('#anonymeI_1').is(':checked') && !$('#anonymeI_0').is(':checked')){//(!$('anonymeI_1').checked && !$('anonymeI_0').checked) {
        $(source.controltovalidate).className = 'select_champ_court_erreur';
        arguments.IsValid = false;
    } else {
        $(source.controltovalidate).className = 'select_champ_court';
        arguments.IsValid = true
    }
    
}

function validatedate_v2(source,arguments)
{
    //var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
    var RegExPattern = /^(\d{1,2}\/){2}\d{4}$/;
    if (rtrim(ltrim(arguments.Value)) != "")
    {
        if (arguments.Value.match(RegExPattern))
        {
            $(source.controltovalidate).className = 'select_champ';
            arguments.IsValid = true;
        }
        else
        {
            $(source.controltovalidate).className = 'select_champ_erreur';
            arguments.IsValid = false;
        }
    }
}

function validatedate(source,arguments)
{
    if (rtrim(ltrim(arguments.Value)) != "")
    {
     mot=arguments.Value
     Erreur=false;
     if (mot.length!=10){Erreur=true;}
     else{
     var motjour=mot.substring(0,2);var motmois=mot.substring(3,5);
     var motan=mot.substring(6,10);var motsep=mot.charAt(2)+mot.charAt(5);}
     if (isNaN(motjour+motmois+motan)|| motan>3000 ||motan<1900 || motsep!="//"){Erreur=true;}
     else {choix="";
     if (motan-(parseInt(motan/4)*4)==0){choix="bi"};
     if (motan-(parseInt(motan/4)*4)==0&&motan-(parseInt(motan/100)*100)==0)
     {choix=""};
     if (motan-(parseInt(motan/4)*4)==0&&motan-(parseInt(motan/400)*400)==0)
     {choix="bi"}
     switch (motmois){
     case "01":if(motjour<1 || motjour>31){Erreur=true;};
     break;
     case"02":if(choix=="bi"){if(motjour<1 || motjour>29){Erreur=true;}}
     else{if(motjour<1 || motjour>28){Erreur=true;}};
     break;
     case "03":if(motjour<1 || motjour>31){Erreur=true;};
     break;
     case "04":if(motjour<1 || motjour>30){Erreur=true;};
     break;
     case "05":if(motjour<1 || motjour>31){Erreur=true;};
     break;
     case "06":if(motjour<1 || motjour>30){Erreur=true;};
     break;
     case "07":if(motjour<1 || motjour>31){Erreur=true;};
     break;
     case "08":if(motjour<1 || motjour>31){Erreur=true;};
     break;
     case "09":if(motjour<1 || motjour>30){Erreur=true;};
     break;
     case "10":if(motjour<1 || motjour>31){Erreur=true;};
     break;
     case "11":if(motjour<1 || motjour>30){Erreur=true;};
     break;
     case "12":if(motjour<1 || motjour>31){Erreur=true;};
     break;
     default:Erreur=true;
     }
     }
     if (Erreur)
        {
            $(source.controltovalidate).className = 'select_champ_erreur';
            arguments.IsValid = false;
            
        }
        else
        {
            $(source.controltovalidate).className = 'select_champ';
            arguments.IsValid = true;
        }
    }
    else{arguments.IsValid = false;};
}

function validateFileCV(source, args)
{
    var argument = args.Value.toLowerCase();
    if( argument.lastIndexOf(".odt") != -1 || argument.lastIndexOf(".doc") != -1 || argument.lastIndexOf(".txt") != -1 || argument.lastIndexOf(".rtf") != -1 || argument.lastIndexOf(".pdf") != -1 || argument.lastIndexOf(".wpd") != -1 || argument.lastIndexOf(".wps") != -1 || argument.lastIndexOf(".xls") != -1 || argument.lastIndexOf(".htm") != -1 || argument.lastIndexOf(".dot") != -1 || argument.lastIndexOf(".html") != -1 || argument.lastIndexOf(".docx") != -1)
    {
        args.IsValid = true;  
    }
    else
    {
        args.IsValid = false;
    }
    ///Si ya rien je passe quand même car ce n'est pas obligatoire
    if (args.Value == "")
    {
        args.IsValid = false;
    }
}

function picto_treeview(id)
{
    cacherdiv('plus_'+id);
    cacherdiv('moins_'+id);
    cacherdiv(id);
}

function check_all_treeview(id)
{

    var check = false;
    picto_treeview(id);
    var bloc = document.getElementById('tout_' + id);
    if (bloc.checked)
    {
        check = true;
    }
    montrerelement(id);
    var Collection= document.getElementById(id);
    var Item= Collection.getElementsByTagName("input");
    for(var i=0;i<Item.length;i++)
    {
       Item[i].checked = check;
    }
    
            cacherelement('plus_'+id);
        montrerelement('moins_'+id);
}

function tester_abonnement()
{
    startLytebox('tester','Tester votre abonnement','/fr/abonnement/tester_abonnement.aspx','760','400');
}

function tester_abonnement_recup_paramettre()
{
    var retour = ""; //,'contrat','experience','fonction','provenance','qualification','responsabilite','secteur'
    var cpt = 0;
    document.getElementById('motclef').value = window.parent.document.getElementById('filtre').value;
    var liste_critere =new Array('ville','contrat','experience','fonction','provenance','qualification','secteur');
    for(i=0;i<liste_critere.length;i++)
    {
    
        var retour2 = "";
        var Collection= window.parent.document.getElementById(liste_critere[i]);
        var Item= Collection.getElementsByTagName("input");
        var Item2= Collection.getElementsByTagName("span");
        
        for(var c=0;c<Item.length;c++)
        {
        
            if (Item[c].checked )
            {
                retour2 += Item2[c].id + ",";
            }
           
        }
        if (retour2 == "")
        {
            retour2 = "0,";
        }
        document.getElementById(liste_critere[i]).value = retour2.substring(0,retour2.length-1);
        
        if (cpt == 6)
        {
            document.formulaire.submit();
            cacherelement('action_div');
            break;
        }
        cpt ++;
    }
     
}

function test()
{
    montrerelement('action_div');
}

function validateCheckboxListeContrat(source, args)
{
    var Collection= document.getElementById('contrat');
    var Item= Collection.getElementsByTagName("input");
    for(var i=0;i<Item.length;i++)
    {
        if(Item[i].checked)
        {
            args.IsValid = true;return;
        }
        else
        {
            args.IsValid = false;
        } 
    }
}


function validateCheckboxListeVilles(source, args)
{
    var Collection= document.getElementById('liste_regions');
    var Item= Collection.getElementsByTagName("input");
    for(var i=0;i<Item.length;i++)
    {
        if(Item[i].checked)
        {
            args.IsValid = true;return;
        }
        else
        {
            args.IsValid = false;
        } 
    }
}

function validateCheckboxListeFonctions(source, args)
{
    var Collection= document.getElementById('treeviewFonctions');
    var Item= Collection.getElementsByTagName("input");
    for(var i=0;i<Item.length;i++)
    {
        if(Item[i].checked)
        {
            args.IsValid = true;return;
        }
        else
        {
            args.IsValid = false;
        } 
    }
}

function validateListederourlant(source, arguments) {
    if (rtrim(ltrim(arguments.Value)) == "" || arguments.Value == "0")
    {
        arguments.IsValid = false;
    }
    else
    {
        arguments.IsValid = true;
    }
}

function ShowListederoulante() {
    var sel =  document.getElementById("secteur")
    if(sel.options[sel.selectedIndex].value == "22" || sel.options[sel.selectedIndex].value == "16" || sel.options[sel.selectedIndex].value == "20" || sel.options[sel.selectedIndex].value == "21")
    {
       montrerelement("div_fonctionnaire");
    }
    else
    {
        cacherelement("div_fonctionnaire");
        document.getElementById("fonctionnaire").value = "0";
    }
}

function Showhandicapdiv() {

    var sel =  document.getElementById('handicap_0'); //si hancip coché
    if(sel.checked)
    {
       montrerelement("handicape_div");
    }
    else
    {
        cacherelement("handicape_div");
    }
}

function validateprecisions(source, arguments) {
    if (rtrim(ltrim(arguments.Value)).length > 1000)
    {
        arguments.IsValid = false;
    }
    else
    {
        arguments.IsValid = true;
    }
}



