/**============================
 diverses fonctions utilitaires
================================*/

/**
* Initialisation de shadowbox
**/
Shadowbox.init({
    // let's skip the automatic setup because we don't have any
    // properly configured link elements on the page
    skipSetup: false,
    overlayOpacity: 0.12,
    
    // include the html player because we want to display some html content
    players: ["html"]
});

/**
* Visual Website Optimizer
**/
/* Start Visual Website Optimizer Asynchronous Code */
var _vwo_code=(function(){
var account_id=10886,
settings_tolerance=1500,
library_tolerance=3000,
use_existing_jquery=false,
/* DO NOT EDIT BELOW THIS LINE */
f=false,d=document;return{use_existing_jquery:function(){return use_existing_jquery;},library_tolerance:function(){return library_tolerance;},finish:function(){if(!f){f=true;var a=d.getElementById('_vis_opt_path_hides');if(a)a.parentNode.removeChild(a);}},finished:function(){return f;},load:function(a){var b=d.createElement('script');b.src=a;b.type='text/javascript';b.innerText;b.onerror=function(){_vwo_code.finish();};d.getElementsByTagName('head')[0].appendChild(b);},init:function(){settings_timer=setTimeout('_vwo_code.finish()',settings_tolerance);this.load('//dev.visualwebsiteoptimizer.com/j.php?a='+account_id+'&u='+encodeURIComponent(d.URL)+'&r='+Math.random());var a=d.createElement('style'),b='body{display:none;}',h=d.getElementsByTagName('head')[0];a.setAttribute('id','_vis_opt_path_hides');a.setAttribute('type','text/css');if(a.styleSheet)a.styleSheet.cssText=b;else a.appendChild(d.createTextNode(b));h.appendChild(a);return settings_timer;}};}());_vwo_settings_timer=_vwo_code.init();
/* End Visual Website Optimizer Asynchronous Code */

/**================
Fonctions oldschool
===================*/

/**
* Check de présence du cookie d'identification
**/
function isIdentified() {
	var idcookie=readCookie("UFCQC_SSO");
	
	if (idcookie && idcookie != null) {
		return true;
	}
	else {
		return false;
	}
}

/**
* Lecture de cookie
**/
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/**
 * push vers newsletter
**/
function addPushNewletter(url){
	$('#frmpushType').attr('action', url);    
    $('#frmpushType').submit();
} 
/**
 * redirection vers url
**/
function redirect(url){
	if (url != "")
	  window.document.location.href = url;
} 

/**
Dropdown menu
*/
function goLink() {
	i = document.rubrique.cmb_searchtypedoc.selectedIndex;
	if (i == 0) return;
	url = document.rubrique.cmb_searchtypedoc.value;
	parent.location.href = url;
}

/**
Taille de polices 
*/
function changePoliceSize(p_action) {
	var obj = document.getElementById("ctn_tozoom");
	
	if (obj) {
		if (obj.style.fontSize == '')
			obj.style.fontSize = "11%";
		
		
		if (p_action == '+') {
			if (parseInt(obj.style.fontSize) < 17)
				obj.style.fontSize = (parseInt(obj.style.fontSize) + 2)+'px';
		} else {
			if (parseInt(obj.style.fontSize) > 7)
				obj.style.fontSize = (parseInt(obj.style.fontSize) - 2)+'px';
		}
	}
	return false;
}


/**
Controles
*/
/* contrôle d'adresse email */
function is_email_ok(p_mail) {
	var atom   = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]';
	var domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)';
	var expr = '^' + atom + '+';
	expr 	+= '(\.' + atom + '+)*';			
												
	expr 	+= '@';	
	expr 	+= '(' + domain + '{1,63}\.)+';
	expr 	+= domain + '{2,63}$';
	expression = new RegExp(expr);
	return (expression.exec(p_mail) != null);
}

/* contrôle de code postal */
function codePostalCheck( cp )
{
	if( parseInt(cp, 10) > 0 && cp.length == 5 )
	{
		return true;
	}
	else
	{
		alert( 'Veuillez saisir un code postal à 5 chiffres valide' );
		
		return false ;
	}	
}

/**
Champs de saisie
*/
function ClearField(form,champ){ 
     eval (that=window.document [form] [champ]); 
     if(form='recherche' && that.value=='Saisissez un mot')that.value='';
	 if(form='identification' && that.value=='motpasse')that.value='';
	 if(form='identification' && that.value=='Votre identifiant')that.value='';
	 if(form='recevoir' && that.value=='Saisissez votre adresse electronique')that.value='';
}

function initField(form,champ,v) {
	var f = window.document[form];
	if (f == null) return;
	var c = f.elements[champ];
	if (c == null) return;
	c.value=v;
}

/**
Tracking newsletter
*/
function trackNewsSignIn(p_mail){
	if (is_email_ok(p_mail)){
		pageTracker._trackEvent(" Newsletter", "Clic", " Inscription Newsletter ", " " );
		return true;
	}
	else{
		//alert("Vous devez indiquer une adresse e-mail valide");
		return false;
	}
}

function searchByCodePostal(url,cp){
	document.location.replace(url+'/'+cp);
}


