/*--FUNCTIONS.JS--*/
/*Développements spécifique au site*/

function fieldFocus(element){
	if(element.value == element.defaultValue){
		element.value = '';
	}
}
function fieldBlur(element){
	if(element.value == ''){
		element.value = element.defaultValue;
	}
}

/*-----------  CHECK FORM  -----------*/
/*--Function check Form--*/
function checkForm(a,d){if(typeof(d.offset)=="undefined"){d.offset={left:0,top:10}}else{if(typeof(d.offset.left)=="undefined"){d.offset.left=0}if(typeof(d.offset.top)=="undefined"){d.offset.top=10}}if(typeof($(a).attr("status"))=="undefined"&&$(a).attr("status")!="initialized"){$(a).attr("status","initialized");var b=new Array();if(typeof(d.required)!="undefined"){for(var g=0;g<d.required.elements.length;g++){if(jQuery.inArray(d.required.elements[g],b)==-1){b.push(d.required.elements[g])}}}if(typeof(d.compare)!="undefined"){for(var g=0;g<d.compare.elements.length;g++){if(jQuery.inArray(d.compare.elements[g][1],b)==-1){b.push(d.compare.elements[g][1])}}}if(typeof(d.radio)!="undefined"){for(var g=0;g<d.radio.elements.length;g++){if(jQuery.inArray(d.radio.elements[g],b)==-1){b.push(d.radio.elements[g])}}}if(typeof(d.email)!="undefined"){for(var g=0;g<d.email.elements.length;g++){if(jQuery.inArray(d.email.elements[g],b)==-1){b.push(d.email.elements[g])}}}if(typeof(d.date)!="undefined"){for(var g=0;g<d.date.elements.length;g++){if(jQuery.inArray(d.date.elements[g],b)==-1){b.push(d.date.elements[g])}}}if(typeof(d.custom)!="undefined"){for(var g=0;g<d.custom.length;g++){if(jQuery.inArray(d.custom[g].element,b)==-1){b.push(d.custom[g].element)}}}for(var g=0;g<b.length;g++){var j=$("#"+b[g]);checkFormFeedback(j,{id:g,offset:d.offset,message:"",position:j.offset()})}}var l=0;if(typeof(d.email)!="undefined"){for(var g=0;g<d.email.elements.length;g++){var j=$("#"+d.email.elements[g]);updateFeedback(j,d.offset,d.email.message);var c=/^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/;if(c.exec(j.val())==null){$(j).parent().addClass("error");l++}}}if(typeof(d.date)!="undefined"){for(var g=0;g<d.date.elements.length;g++){var j=$("#"+d.date.elements[g]);updateFeedback(j,d.offset,d.date.message);var c=/^[0-9]{2}[/]{1}[0-9]{2}[/]{1}[0-9]{4}$/;if(c.exec(j.val())==null){$(j).parent().addClass("error");l++}}}if(typeof(d.compare)!="undefined"){for(var g=0;g<d.compare.elements.length;g++){var h=$("#"+d.compare.elements[g][0]);var f=$("#"+d.compare.elements[g][1]);updateFeedback(f,d.offset.top,d.compare.message);if(f.val()!=h.val()){$(f).addClass("error");l++}}}if(typeof(d.radio)!="undefined"){for(var g=0;g<d.radio.elements.length;g++){var j=$("#"+d.radio.elements[g]);var e=0;$('input[name="'+(j.attr("name"))+'"]').each(function(){if($(this).is(":checked")){e++}});if(!e){j.parent().addClass("error");updateFeedback(j,d.offset,d.radio.message);l++}}}if(typeof(d.custom)!="undefined"){for(var g=0;g<d.custom.length;g++){var j=$("#"+d.custom[g].element);updateFeedback(j,d.offset,d.custom[g].message);if(d.custom[g].reg.exec(j.val())==null){$(j).parent().addClass("error");l++}}}if(typeof(d.required)!="undefined"){for(var g=0;g<d.required.elements.length;g++){var j=$("#"+d.required.elements[g]);var k=document.getElementById(d.required.elements[g]).defaultValue;if(typeof(d.defaultValue)!="undefined"&&!d.defaultValue){k=""}if(j.is("input")){if(j.attr("type")=="text"||j.attr("type")=="password"){if(j.val()==""||j.val()==k){j.parent().addClass("error");updateFeedback(j,d.offset,d.required.message);l++}}else{if(j.attr("type")=="checkbox"||j.attr("type")=="radio"){if(!j.is(":checked")){j.parent().addClass("error");updateFeedback(j,d.offset,d.required.message);l++}}}}else{if(j.is("select")){if($("option:selected",j).val()==""){j.parent().addClass("error");updateFeedback(j,d.offset,d.required.message);l++}}else{if(j.is("textarea")){if(j.val()==""||j.val()==k){j.parent().addClass("error");updateFeedback(j,d.offset,d.required.message);l++}}}}}}if(!l){return true}else{if(typeof(d.onError)!="undefined"){d.onError()}return false}}function updateFeedback(e,f,b){$("#"+e.attr("related_to")+" .message").html(b);if(e.attr("type")!="checkbox"&&e.attr("type")!="radio"){if($("#"+e.attr("related_to")).outerWidth()>e.outerWidth()){var a=e.outerWidth()-parseFloat($("#"+e.attr("related_to")).css("paddingLeft"))-parseFloat($("#"+e.attr("related_to")).css("paddingRight"));$("#"+e.attr("related_to")).css("width",a+"px")}else{$("#"+e.attr("related_to")).css("width","auto")}}var d=Math.round(e.offset().top)-$("#"+e.attr("related_to")).outerHeight()+f.top;$("#"+e.attr("related_to")).css("top",d+"px");var c=Math.round(e.offset().left)+f.left;$("#"+e.attr("related_to")).css("left",c+"px")}function checkFormFeedback(d,a){d.attr("related_to","checkFormFeedback_"+a.id);$("body").append('<div class="errorFeedback" id="checkFormFeedback_'+a.id+'" style="display:none;"><span class="message">'+a.message+'</span><span class="appendice"></span></div>');$("#checkFormFeedback_"+a.id).attr("form_element",d.attr("id"));var c=Math.round(a.position.top)-$("#checkFormFeedback_"+a.id).outerHeight()+a.offset.top;$("#checkFormFeedback_"+a.id).css("top",c+"px");var b=Math.round(a.position.left)+a.offset.left;$("#checkFormFeedback_"+a.id).css("left",b+"px");if(d.is("input")&&(d.attr("type")=="checkbox"||d.attr("type")=="radio")){d.parent().find("label").hover(function(){if($(this).parent().hasClass("error")){$("#checkFormFeedback_"+a.id).fadeIn("fast")}},function(){if($(this).parent().hasClass("error")){$("#checkFormFeedback_"+a.id).fadeOut("fast")}})}else{d.focus(function(){if($(this).parent().hasClass("error")){$("#checkFormFeedback_"+a.id).fadeIn("fast")}});d.blur(function(){if($(this).parent().hasClass("error")){$("#checkFormFeedback_"+a.id).fadeOut("fast")}})}if(d.is("input")&&d.attr("type")=="radio"){$('input[name="'+d.attr("name")+'"]').change(function(){if($(this).parent().hasClass("error")){$("#checkFormFeedback_"+a.id).fadeOut("fast",function(){var e=$(this).attr("form_element");$("#"+e).parent().removeClass("error")})}})}else{d.change(function(){if($(this).parent().hasClass("error")){$("#checkFormFeedback_"+a.id).fadeOut("fast",function(){var e=$(this).attr("form_element");$("#"+e).parent().removeClass("error")})}})}};

/*-----------  GREYBOX  -----------*/
//Config générale récurente
var greyBoxDefaultConfig = {
	/*--Valeurs ci-dessous requises--*/
	top: 50,						//=> Décalage en PX du haut du document
	duration: 0.6,					//=> Durée totale de l'affichage
	opacity: 0.6					//=> Opacité du fond Overlay
	/*--Options supplémentaires--*/
	//height: 500,					//=> Fixer la hauteur
	//closeText: 'Retour',			//=> Ajouter un texte au bouton "fermer"
	//background: 'green',			//=> Modifier la couleur du fond de l'Overlay
	//style: 'background:red',		//=> Ajouter des styles CSS directement à la greyBox
	//className: 'customize',		//=> Ajouter une Classe CSS
	//data: {id: 12},				//=> Envoyer des données en POST
	/*customFunction: function(){	//=> Exécuter un fonction personnelle à l'affichage de la greyBox
		alert('test');
	}*/
};
//Variable définissant la durée de la transition
var greyBoxEffectDuration = Math.round((greyBoxDefaultConfig.duration*1000)/2);
//Fonctions GREYBOX
function greyBoxShow(b,c,d,a){if(!$("#overlay").length){$("body").append('<div id="overlay" onclick="greyBoxHide();"></div>');if(jQuery.browser.msie&&jQuery.browser.version=="6.0"){$(window).scroll(function(){$("#overlay").css("top",$(window).scrollTop()+"px")})}}if(!$("#greyBox").length){$("body").append('<div id="greyBox"><div class="content" id="greyBoxContent"></div><div onclick="greyBoxHide();" class="close"></div></div>')}if(typeof(a)!="undefined"){if(typeof(a.duration)=="undefined"){greyBoxEffectDuration=Math.round((greyBoxDefaultConfig.duration*1000)/2)}else{greyBoxEffectDuration=Math.round((a.duration*1000)/2)}if(typeof(a.top)=="undefined"){a.top=greyBoxDefaultConfig.top}if(typeof(a.opacity)=="undefined"){a.opacity=greyBoxDefaultConfig.opacity}if(typeof(a.height)=="undefined"&&typeof(greyBoxDefaultConfig.height)!="undefined"){a.height=greyBoxDefaultConfig.height}if(typeof(a.closeText)=="undefined"&&typeof(greyBoxDefaultConfig.closeText)!="undefined"){a.closeText=greyBoxDefaultConfig.closeText}if(typeof(a.title)=="undefined"&&typeof(greyBoxDefaultConfig.title)!="undefined"){a.title='<h1 class="title greybox">'+greyBoxDefaultConfig.title+"</h1>"}else{if(typeof(a.title)=="undefined"&&typeof(greyBoxDefaultConfig.title)=="undefined"){a.title=""}else{a.title='<h1 class="title greybox">'+a.title+"</h1>"}}if(typeof(a.error)=="undefined"&&typeof(greyBoxDefaultConfig.error)!="undefined"){a.error=greyBoxDefaultConfig.error}if(typeof(a.background)=="undefined"&&typeof(greyBoxDefaultConfig.background)!="undefined"){a.background=greyBoxDefaultConfig.background}if(typeof(a.style)=="undefined"&&typeof(greyBoxDefaultConfig.style)!="undefined"){a.style=greyBoxDefaultConfig.style}if(typeof(a.className)=="undefined"&&typeof(greyBoxDefaultConfig.className)!="undefined"){a.className=greyBoxDefaultConfig.className}if(typeof(a.loading)=="undefined"&&typeof(greyBoxDefaultConfig.loading)!="undefined"){a.loading=greyBoxDefaultConfig.loading}if(typeof(a.data)=="undefined"&&typeof(greyBoxDefaultConfig.data)!="undefined"){a.data=greyBoxDefaultConfig.data}if(typeof(a.customFunction)=="undefined"&&typeof(greyBoxDefaultConfig.customFunction)!="undefined"){a.customFunction=greyBoxDefaultConfig.customFunction}}else{greyBoxEffectDuration=Math.round((greyBoxDefaultConfig.duration*1000)/2);a=greyBoxDefaultConfig;a.title=""}$("#overlay").removeAttr("style");$("#greyBox .close").html("");$("#greyBox").removeAttr("class");$("#greyBoxContent").removeAttr("style");if(typeof(a.height)!="undefined"&&d!="iframe"&&d!="youtube"&&d!="dailymotion"){$("#greyBoxContent").css("overflow","auto").css("height",a.height+"px")}if(typeof(a.closeText)!="undefined"){$("#greyBox .close").html(a.closeText)}if(typeof(a.background)!="undefined"){$("#overlay").css("background",a.background)}if(typeof(a.style)!="undefined"){$("#greyBoxContent").attr("style",a.style)}if(typeof(a.className)!="undefined"){$("#greyBox").addClass(a.className)}$("#greyBoxContent").html('<div id="greyBoxLoader"></div>');if(typeof(a.loading)!="undefined"){$("#greyBoxLoader").html(a.loading)}$("#greyBox").css("width",c+"px").css("left","-"+(Math.ceil(c/2))+"px");if(typeof(a.customFunction)=="undefined"){switch(d){case"html":var e=function(){$("#greyBoxContent").html(a.title+b)};greyBoxDisplay(e,a.opacity,a.top);break;case"get":var e=function(){$.ajax({type:"GET",url:b,success:function(f){$("#greyBoxContent").html(a.title+f)},error:function(){$("#greyBoxContent").html(a.title+a.error)}})};greyBoxDisplay(e,a.opacity,a.top);break;case"post":var e=function(){$.ajax({type:"POST",url:b,data:a.data,success:function(f){$("#greyBoxContent").html(a.title+f)},error:function(){$("#greyBoxContent").html(a.title+a.error)}})};greyBoxDisplay(e,a.opacity,a.top);break;case"iframe":var e=function(){var f=400;if(typeof(a.height)!="undefined"){f=a.height}$("#greyBoxContent").html(a.title+'<iframe src="'+b+'" border="0" frameborder="0" width="100%" height="'+f+'" allowTransparency="true"></iframe>')};greyBoxDisplay(e,a.opacity,a.top);break;case"youtube":var e=function(){var f="";if(typeof(a.height)!="undefined"){f=' height="'+a.height+'"'}$("#greyBoxContent").html(a.title+'<iframe class="youtube" title="YouTube video player" style="width:100%;display:block;"'+f+' src="http://www.youtube.com/embed/'+b+'?wmode=transparent" frameborder="0" allowfullscreen></iframe>')};greyBoxDisplay(e,a.opacity,a.top);break;case"dailymotion":var e=function(){var f=400;if(typeof(a.height)!="undefined"){f=a.height}$("#greyBoxContent").html(a.title+'<object width="100%" height="'+f+'" style="display:block;"><param name="movie" value="http://www.dailymotion.com/swf/video/'+b+'"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/'+b+'" width="100%" height="'+f+'" allowfullscreen="true" allowscriptaccess="always"></embed></object>')};greyBoxDisplay(e,a.opacity,a.top);break;case"image":var e=function(){$("#greyBoxContent").html($("#greyBoxContent").html()+'<img src="'+b+'" alt="" style="display:none;" id="greyBoxImage" />');$("#greyBoxImage").load(function(){$("#greyBoxImage").fadeOut(0);$("#greyBoxLoader").remove();$("#greyBoxContent").prepend(a.title);$("#greyBoxImage").fadeIn("medium");$("#greyBoxContent").css("width",Math.floor($("#greyBoxImage").outerWidth())+"px");$("#greyBox").css("width","auto").css("left","-"+(Math.ceil($("#greyBoxContent").outerWidth()/2))+"px")})};greyBoxDisplay(e,a.opacity,a.top);break;default:break}}else{greyBoxDisplay(a.customFunction,a.opacity,a.top)}return false}function greyBoxDisplay(c,a,b){if($("#greyBox").attr("status")!="running"){$("#greyBox").attr("status","running");$("#greyBox").css("top",($(window).scrollTop()+b)+"px");if(jQuery.browser.msie&&jQuery.browser.version=="6.0"){$("#overlay").css("position","absolute").css("height",$(window).height()+"px").css("top",$(window).scrollTop()+"px");$("#greyBoxLoader").css("height","200px")}$("object:not(.keep-visible), embed").css("visibility","hidden");if(jQuery.browser.msie&&jQuery.browser.version=="6.0"){$("select").css("visibility","hidden")}$("#overlay").fadeTo(greyBoxEffectDuration,a,function(){$("#greyBox").fadeIn(greyBoxEffectDuration,function(){$("#greyBox").attr("status","done");c()})})}}function greyBoxHide(){if($("#greyBox").attr("status")!="running"){$("#greyBox").attr("status","running");$("#greyBox").fadeOut(greyBoxEffectDuration,function(){$("#greyBox").hide();$("#overlay").fadeOut(greyBoxEffectDuration,function(){$("object:not(.keep-visible), embed").css("visibility","visible");if(jQuery.browser.msie&&jQuery.browser.version=="6.0"){$("select").css("visibility","visible")}$("#greyBox").attr("status","done");$("#greyBox").remove()})})}};

/*-----------  ACCORDION  -----------*/
function makeAccordion(a){$.each(a,function(c,b){$(b.cssRule+" > li:not(."+b.activeClassName+") "+b.contentRule).hide();$(b.cssRule+" > li "+b.triggerRule).click(function(){return triggerAccordionSection($(this),b)})})}function triggerAccordionSection(c,b){if($(c).parents("ul:last").attr("status")!="running"){$(c).parents("ul:last").attr("status","running");var d=$(c).parents("li:first");var e=b.speed*1000;if($(d).hasClass(b.activeClassName)){$(d).find(b.contentRule).slideUp(e,function(){$(d).removeClass(b.activeClassName);$(c).parents("ul:last").attr("status","ok")})}else{if(b.oneByOne){if($(c).parents("li:first").siblings("li."+b.activeClassName).length){var a=$(c).parents("li:first").siblings("li."+b.activeClassName);$(a).find(b.contentRule).slideUp(e,function(){$(a).removeClass(b.activeClassName);$(d).find(b.contentRule).slideDown(e,function(){$(c).parents("ul:last").attr("status","ok")});$(d).addClass(b.activeClassName)})}else{$(d).find(b.contentRule).slideDown(e,function(){$(c).parents("ul:last").attr("status","ok")});$(d).addClass(b.activeClassName)}}else{$(d).find(b.contentRule).slideDown(e,function(){$(c).parents("ul:last").attr("status","ok")});$(d).addClass(b.activeClassName)}}}return false};


















