
/* ************** */

var $message = "";
var $boolSubmit = "";

$(function(){

	$(".maskTelephone").mask("99 99 99 99 99");

	$("#jqueryUIDialogBox").dialog({
		autoOpen: false,
		width: 990,
		height: 700,
		modal: true,
		buttons: {
			"Fermer la fenêtre": function() { 
				$(this).dialog("close");
			} 
		}
	});
	
	$("#divPointsDeCollecte").dialog({
		autoOpen: false,
		width: 990,
		height: 772,
		modal: true,
		buttons: {
			"Fermer la fenêtre": function() { 
				$(this).dialog("close");
			} 
		}
	});   	

	$(".afficherBatribox").click( function() {
		//$("#divPointsDeCollecte").load("http://www.screlec.fr/points-de-collecte/?departement=01");
		$("#divPointsDeCollecte").dialog("open");
		return false;
	});

	
	/**
	 * NEWSLETTER COLLECT'INFO
	 *
	 */
	$("#newsletterCollectInfo").click( function() {
		$("#newsletterCollectInfo").val("");
	});
	$("#validInscriptionCollectInfo").click( function() {
		if ( isEmail($("#newsletterCollectInfo").val()) ) {
			$.ajax({
				cache: false,
				async: false,
				type: "POST",
				url: "/fra/collectInfo/abonner",
				data: "newsletter=" + $("#newsletterCollectInfo").val(),
				success: function(codeRetour){
					$("#kMessage").html(codeRetour);
					$("#kMessage").dialog("open");
					return false;
				}
			});
		}
		return false;
	});

});

/* ************** */

$(document).ready( function() {
	
	
	$("#qualite").change( function() {
		if ( $("#qualite").val() == "Particulier" ) {
			$("#divEntreprise").css("display", "none");
		}
		else {
			$("#divEntreprise").css("display", "");
		}
	});
	
	/**
	Mise en place du hack pour problème de Width select IE
	*/
	/*
	$(function() {

    $("#telechargements")

        .mouseover(function(){
            $(this)
                .data("origWidth", $(this).css("width"))
                .css("width", "auto");
        })

        .mouseout(function(){
            $(this).css("width", $(this).data("origWidth"));
        });

	});
	*/
	

	/**
	 * GESTION DES MENUS
	 *
	 */
	$(".niveau1").mouseenter(function(){
		$("#sous_" + $(this).attr("id")).toggle("fast");
		return true;
	});
	$(".niveau1").mouseleave(function(){
		$("#sous_" + $(this).attr("id")).toggle("fast");
		return true;
	});
	

	/**
	 * TELECHARGEMENTS POUR GOOGLE ANALYTICS
	 *
	 */
	$("#telechargements").change(function() {
		/*$(this).css("width", $(this).data("origWidth"));*/
		/*$(this).css("width", "170px");*/
		_gaq.push(["_trackEvent", "Fichiers PDF", "Téléchargements", $(this).html()]);
		window.location.href = "/fra/visualiser/" + $(this).val();	
	});
	$("#toutsavoirsur").change(function() {
		_gaq.push(["_trackEvent", "Fichiers PDF", "Téléchargements", $(this).html()]);
		window.location.href = "/fra/visualiser/" + $(this).val();	
	});

});

/* ************** */

 /** Analyse l'email */
 function isEmail(email) {
     var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
     return filter.test(email);
 }    

