function bloc_deroulant(objet) {
	objet.next().slideToggle("normal");
	objet.toggleClass("selected");
	objet.parent().toggleClass("bloc_deroulant_selected");

	return false;
}

function document_ready() {
	if ($.browser.msie) {
		$('.exceptIe').remove();
	} else {
		$('.ieOnly').remove();
	}
    
	// Blocs déroulants
	$(".zone_deroulante").hide();

	$("a.lien_deroulant").click(function() {
		return bloc_deroulant($(this));
	});

	// Pré-dérouler un bloc si une ancre est passée dans l'url
	ancre = document.location.hash;
	if (ancre) {
		bloc_id = ancre.substr(1, ancre.length);
		obj_lien = $("#" + bloc_id).children("a.lien_deroulant");
		bloc_deroulant(obj_lien);
	}

	// Submit d'un form sur le keydown (sinon ça bug pour IE et Safari)
	$("input").keydown(function(e) {
		if (e.keyCode == 13) {
			$(this).parents("form").submit();
			return false;
		}
	});
	
	$("a.imprimer").click(function(e){
		window.print();
		e.preventDefault();
	});

	populate_inputs();

    $('.calendrier').datepicker({
        showAnim: 'fadeIn',
        dateFormat: 'yy-mm-dd',
        dayNames: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
        dayNamesMin: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
        dayNamesShort: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'],
        monthNames: ['Janvier', 'F�vrier', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Ao�t', 'Septembre', 'Octobre', 'Novembre', 'D�cembre'],
        monthNamesShort: ['Jan', 'F�vr', 'Mars', 'Avr', 'Mai', 'Juin', 'Juil', 'A�ut', 'Sept', 'Oct', 'Nov', 'D�c']
    });

    $("a.iframe").fancybox({
        'frameWidth' : 350,
        'frameHeight': 450
    });

    $("a.fancybox").fancybox({
        'zoomSpeedIn': 300,
        'zoomSpeedOut': 300,
        'overlayShow': true
    });

    $(".editeur .tmpl_colore tr:even").addClass("paire");
    
    $(".zone_deroulante p:first-child").addClass("first-child");
    $(".editeur .encadre p:first-child").addClass("first-child");
    $("#promos .editeur p:first-child").addClass("first-child");
    
    $(".zone_deroulante p:last-child").addClass("last-child");
}

function rand (min, max) {
    var argc = arguments.length;
    if (argc === 0) {
        min = 0;
        max = 2147483647;
    } else if (argc === 1) {
        throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
    }
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

/*
 * Vérifier si une valeur alt="" est fournis au champs input et textarea
 * et si le input/textarea a l'attribut value vide, mettre la valeur du
 * alt dans l'attribut value.
 *
 * Était direct dans le .ready jusqu'a se que je remarque qu'il ne
 * s'appliquait pas au formulaire loader en ajax, maintenant on n'a qu'a
 * caller populate_inputs() sur le callback du load.
 */
function populate_inputs() {
	$("input,textarea").each(function() {
		if ($(this).attr("alt") != "") {
			$(this).addClass("unfocus");
			if ($(this).val() == "") {
				$(this).val($(this).attr("alt"));
			}
		}
	});

	$("input,textarea").focus(function() {
		if ($(this).attr("alt") != "") {
			if ($(this).val() == $(this).attr("alt")) {
				$(this).val("");
				$(this).removeClass("unfocus");
			}
		}
	});

	$("input,textarea").blur(function() {
		if ($(this).attr("alt") != "") {
			if ($(this).val() == "") {
				$(this).val($(this).attr("alt"));
				$(this).addClass("unfocus");
			}
		}
	});
}

/*
 * Autoriser seulement des chiffres
 * 
 * @copyright	egzakt.com
 * @version 	2008/10/28
 * @author 		Emilie
 */
function champ_numerique(e) {
	// 48 à 58 = 0 à 9
	// 96 à 105 = 0 à 9 du numpad
	// 8 = backspace
	// 9 = tab
	// 37 = fleche gauche
	// 39 = fleche droite
	// 46 = delete
	// 13 = enter
	
	key = e.which ? e.which : e.keyCode
	if (!(((key >= 48) && (key <= 58)) || ((key >= 96) && (key <= 105)) || (key == 8) || (key == 9) || (key == 37) || (key == 39) || (key == 46) || (key == 13))) {
		return false;
	}
}
