function choisirFlash(value)
{
    if('custom' == value)
    {
        dojo.style('animation-accueil-fieldset', 'display', 'block') ;
    }
    else
    {
        dojo.style('animation-accueil-fieldset', 'display', 'none') ;
    }
}

function validerFormulaire(id)
{
    var form = dijit.byId(id) ;

    if(form.isValid())
    {
        var progressBar = new dijit.ProgressBar({indeterminate: true}) ;
        dojo.style(progressBar.domNode, "width", "100%") ;

        var p = document.createElement("p") ;
        p.appendChild(document.createTextNode("Merci de bien vouloir patienter")) ;
        p.appendChild(progressBar.domNode) ;

        var dialog = new dijit.Dialog({title: "Traitement en cours..."}) ;
        dialog.onCancel = function(){} ;
        dojo.style(dialog.closeButtonNode, "visibility", "hidden") ;
        dialog.setContent(p) ;
        dialog.show() ;
    }

    return form.validate() ;
}

function dijitEditorToTextarea(id_editor, id_textarea)
{
    dojo.byId(id_textarea).value = dijit.byId(id_editor).getValue(false) ;
}

function gererAffichageDetail(id_contenu)
{
    var titre  = dojo.byId("titre-contenu-" + id_contenu) ;
    var detail = dojo.byId("detail-contenu-" + id_contenu) ;

    if(dojo.hasClass(titre, "closed"))
    {
    	dojo.removeClass(titre, "closed") ;
    	dojo.removeClass(detail, "closed") ;
    	dojo.addClass(titre, "opened") ;
    	dojo.addClass(detail, "opened") ;
    }
    else
    {
    	dojo.removeClass(titre, "opened") ;
    	dojo.removeClass(detail, "opened") ;
    	dojo.addClass(titre, "closed") ;
    	dojo.addClass(detail, "closed") ;
    }
}

function changementEtatSupprimerIllustrationSite()
{
    if(dijit.byId("supprimer_illustration_p") != undefined)
    {
        dojo.style(
            "champ_illustration_p",
            "display",
            dijit.byId("supprimer_illustration_p").getValue() ? "block" : "none"
        ) ;
    }

    if(dijit.byId("supprimer_illustration_sup1") != undefined)
    {
        dojo.style(
            "champ_illustration_sup1",
            "display",
            dijit.byId("supprimer_illustration_sup1").getValue() ? "block" : "none"
        ) ;
    }

    if(dijit.byId("supprimer_illustration_sup2") != undefined)
    {
        dojo.style(
            "champ_illustration_sup2",
            "display",
            dijit.byId("supprimer_illustration_sup2").getValue() ? "block" : "none"
        ) ;
    }

    if(dijit.byId("supprimer_illustration_sup3") != undefined)
    {
        dojo.style(
            "champ_illustration_sup3",
            "display",
            dijit.byId("supprimer_illustration_sup3").getValue() ? "block" : "none"
        ) ;
    }

    if(dijit.byId("supprimer_illustration_sup4") != undefined)
    {
        dojo.style(
            "champ_illustration_sup4",
            "display",
            dijit.byId("supprimer_illustration_sup4").getValue() ? "block" : "none"
        ) ;
    }

    if(dijit.byId("supprimer_illustration_sup5") != undefined)
    {
        dojo.style(
            "champ_illustration_sup5",
            "display",
            dijit.byId("supprimer_illustration_sup5").getValue() ? "block" : "none"
        ) ;
    }
}

function changementEtatSupprimerIllustration()
{
    dojo.style(
        "champ-illustration",
        "display",
        dijit.byId("supprimer-illustration").getValue() ? "block" : "none"
    ) ;
}

function changementEtatSupprimerAnimation()
{
    dojo.style(
        "champ-animation",
        "display",
        dijit.byId("supprimer-animation").getValue() ? "block" : "none"
    ) ;
}

function changementEtatSupprimerFichiers()
{
    if(dijit.byId("supprimer-fichier_1") != undefined)
    {
        dojo.style(
            "champ-fichier_1",
            "display",
            dijit.byId("supprimer-fichier_1").getValue() ? "block" : "none"
        ) ;
    }

    if(dijit.byId("supprimer-fichier_2") != undefined)
    {
        dojo.style(
            "champ-fichier_2",
            "display",
            dijit.byId("supprimer-fichier_2").getValue() ? "block" : "none"
        ) ;
    }
}

function changementEtatMiseEnLigne(input)
{
    switch(input.id)
    {
        case 'activer-maintenant' :
        case 'desactiver' :
            dojo.byId('activer-du').value = '' ;
            dojo.byId('activer-au').value = '' ;
            dijit.byId('activer-du').required = false ;
            dijit.byId('activer-au').required = false ;
            break ;

        case 'activer-periode' :
            dijit.byId('activer-du').required = true ;
            dijit.byId('activer-au').required = true ;
            break ;
    }
}

function changementModelePage()
{
    if('Annonces' == dojo.byId('modele').value)
    {
        dojo.style('champ-courriel', 'display', 'block') ;
        dijit.byId('courriel').attr('required', true) ;
    }
    else
    {
        dojo.style('champ-courriel', 'display', 'none') ;
        dijit.byId('courriel').attr('required', false) ;
    }

    if('Album photos' == dojo.byId('modele').value)
    {
        dojo.style('champ-detail', 'display', 'none') ;
    }
    else
    {
        dojo.style('champ-detail', 'display', 'block') ;
    }
}

function changementTypePageOdace()
{
    var tabContainer = dijit.byId("listeCatalogues") ;

    function removeChildren()
    {
        dojo.forEach(
            tabContainer.getChildren(),
            "dijit.byId('listeCatalogues').removeChild(item)"
        ) ;
    }

    switch(dijit.byId("type").attr("value"))
    {
        case "0" : // Aucun type selectionné
            removeChildren() ;
            dojo.style(tabContainer.domNode, "opacity", "0") ;
            break ;
        case "1" : // Page d'attribution
            dojo.style(tabContainer.domNode, "opacity", "1") ;
            removeChildren() ;
            tabContainer.addChild(dijit.byId("type1")) ;
            break ;
        case "2" : // Page d'inscription
            dojo.style(tabContainer.domNode, "opacity", "1") ;
            removeChildren() ;
            tabContainer.addChild(dijit.byId("type2")) ;
            break ;
        case "3": // Page de location
            dojo.style(tabContainer.domNode, "opacity", "1") ;
            removeChildren() ;
            tabContainer.addChild(dijit.byId("type3")) ;
            
            break ;
    }
}

function changerImageSite(imageNumber)
{
    dojo.byId("illustrationMoyen").src = illustrations[imageNumber].moyen ;
    dojo.byId("illustrationGrand").src = illustrations[imageNumber].grand ;
}

/**
* Affiche un message de confirmation avant la suppression d'un élément
**/
function confirmerSuppression()
{
	return confirm("Confirmez-vous la suppression de cet élément ?") ;
}

/**
* Affiche un message de confirmation avant la suppression de la demande de réservation en cours
**/
function confirmerSuppressionDemandeResa()
{
	return confirm("Confirmez-vous la suppression de votre demande de réservation en cours ?") ;
}

/**
* Affiche un message de confirmation avant la suppression d'un choix
**/
function confirmerSuppressionChoix(ordre)
{
	return confirm("Confirmez-vous la suppression du choix n°"+ ordre +" ?") ;
}

function verifie_saisie1(NomFormulaire)
{
	var formulaire = dojo.byId(NomFormulaire) ;

	for( i in formulaire.elements )
	{
		var id, valeur, type;
		
		if(formulaire.elements[i].id)
			id	= formulaire.elements[i].id;
		if(formulaire.elements[i].value)
			valeur = formulaire.elements[i].value;
		if(formulaire.elements[i].type)
			type = formulaire.elements[i].type;

		if(type=="text")
		{
			if(valeur!=null && !isNumeric(valeur))
			{
				alert('Les données sont entrées dans un format incorrect');
				return false;
			}

			if(id=='nbparts' && (valeur==null || valeur=='' || valeur==0))
			{
				alert('Le nombre de parts doit être indiqué et non nul');
				return false;
			}
		}
	}
	
	return true ;
}

function isNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++)
	{
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
			IsNumber = false;
	}
	
	return IsNumber;
} 

function activerPaiement()
{
    dojo.style('infos-paiement', 'display', dojo.byId('paiement_activer').checked ? 'block' : 'none') ;
}

function Check_all(container_id,state)
{
    var checkboxes = dojo.query('input[type="checkbox"]', container_id) ;
    dojo.forEach(checkboxes, function(item){dijit.byId(item.id).setValue(state) ;}) ;
}

function droitsRestreints()
{
    var select  = dijit.byId('super') ;
    var bouton  = dojo.byId('bouton-gestion-droits') ;

    dojo.style('droits-compte-restreint', 'display', select.getValue() == 0 ? 'block' : 'none') ;

    if(bouton != null)
    {
    	dojo.style('bouton-gestion-droits', 'display', select.getValue() == 0 ? 'inline' : 'none') ;
    }
}

function dateTextBoxChangeDdeb(argument, iddatedeb, iddatefin)
{
    var ddeb = dojo.byId(iddatedeb).value;
    var dfin = dojo.byId(iddatefin).value;

    if (ddeb == '') {
        return ;
    }
    if (ddeb.length != 10) {
        return ;
    }
    dijit.byId(iddatefin).constraints.min = argument ;
    var d1 = ddeb.split("/");
    var d2 = dfin.split("/");
    var int1 = d1[2] + d1[1] + d1[0];
    var int2 = d2[2] + d2[1] + d2[0];
    if (int1 > int2) {
        dojo.byId(iddatefin).value = ddeb ;
    }
    if (dfin == '') {
        dojo.byId(iddatefin).value = ddeb ;
    }
}
